|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T t
Length: 16657 (0x4111) Types: TextFile Names: »tile.c.orig«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/X/Dragon/tile.c.orig«
/****************************************************************************** * Dragon - a version of Mah-Jongg for X Windows * * Author: Gary E. Barnes March 1989 * * tile.c - Deals with the individual Mah-Jongg tiles. ******************************************************************************/ #include "main.h" /*--SEASONS */ extern XImage spring; extern XImage summer; extern XImage fall; extern XImage winter; /*--FLOWERS */ extern XImage bamboo; extern XImage mum; extern XImage orchid; extern XImage plum; /*--DRAGONS */ extern XImage gdragon; extern XImage rdragon; extern XImage wdragon; /*--WINDS */ extern XImage east; extern XImage west; extern XImage north; extern XImage south; /*--NUMBERS */ extern XImage one; extern XImage two; extern XImage three; extern XImage four; extern XImage five; extern XImage six; extern XImage seven; extern XImage eight; extern XImage nine; /*--OTHER */ extern XImage bam; extern XImage crak; extern XImage dot; extern XImage_Init Sizes[5][28]; static int Tile_X11 = 28 / 2; /* one column */ static int Tile_X21 = 28 / 3; /* two columns */ static int Tile_X22 = 28 * 2 / 3; static int Tile_X31 = 28 / 4; /* three columns */ static int Tile_X32 = 28 * 2 / 4; static int Tile_X33 = 28 * 3 / 4; static int Tile_Y11 = 32 / 2; /* one row */ static int Tile_Y21 = 32 / 3; /* two rows */ static int Tile_Y22 = 32 * 2 / 3; static int Tile_Y31 = 32 / 5; /* three rows */ static int Tile_Y32 = 32 * 2 / 5; static int Tile_Y33 = 32 * 3 / 5; static int Number_X = 28 - 7; static int Number_Y = 0; static int SubTile_X = 7 / 2; static int SubTile_Y = 8 / 2; \f static void Setup_Image( image, bits, width, height ) XImage *image; char *bits; int width; int height; /****************************************************************************** * image - Specifies the XImage object to initialize * bits - Specifies the image data * width - Specifies the width of the image * height - Specifies the height of the image * * Called to init an XImage so that it points at a particular bitmap image. ******************************************************************************/ { image->width = width; image->height = height; image->depth = 1; image->xoffset = 0; image->format = XYBitmap; image->data = bits; image->byte_order = LSBFirst; image->bitmap_bit_order = LSBFirst; image->bitmap_unit = 8; image->bitmap_pad = 8; image->bytes_per_line = (width + 7) / 8; } /* Setup_Image */ \f void Configure_Tiles( size ) int size; /****************************************************************************** * size - Specifies the tile size to use; 1..5 * * Called when the Board receives a ConfigureNotify event. We check to see if * the size of the board/tiles have changed. If so then we reconfigure the * images of the tiles. ******************************************************************************/ { XImage_Init *table; int w; int h; /*--Make sure that our caller is rational. */ if (size < 1 || size > 5) { fprintf( stderr, "Bad size given to Configure_Tiles in tile.c [%d].\n", size ); size = 1; } /*--Set up all of the various images. */ for (table = &Sizes[size-1][0]; table->image != (XImage*)NULL; ++table) { Setup_Image( table->image, table->bits, table->width, table->height ); } /*--Set up the sub-tile positions. */ w = spring.width; h = spring.height; Tile_X11 = w / 2; /* one column */ Tile_X21 = w / 3; /* two columns */ Tile_X22 = w - Tile_X21; Tile_X31 = w / 4; /* three columns */ while (Tile_X31 + bam.width/2 + bam.width*2 >= spring.width) { --Tile_X31; } Tile_X32 = Tile_X31 + bam.width; Tile_X33 = Tile_X32 + bam.width; Tile_Y11 = h / 2; /* one row */ Tile_Y21 = h / 3; /* two rows */ Tile_Y22 = h - Tile_Y21; Tile_Y31 = h * 2 / 5; /* three rows */ while (Tile_Y31 + bam.height/2 + bam.height*2 >= spring.height) { --Tile_Y31; } Tile_Y32 = Tile_Y31 + bam.height; Tile_Y33 = Tile_Y32 + bam.height; Number_X = w - one.width - 1; Number_Y = 1; SubTile_X = bam.width / 2; SubTile_Y = bam.height / 2; } /* Configure_Tiles */ \f static void Draw_Image( image, x, y ) XImage *image; int x; int y; /****************************************************************************** * Do an XPutImage on the image. ******************************************************************************/ { XPutImage( XtDisplay(Board), XtWindow(Board), Normal_GC, image, 0, 0, x, y, (unsigned int)image->width, (unsigned int)image->height ); } /* Draw_Image */ \f static void Draw_Blank( x, y ) int x; int y; /****************************************************************************** * Draw an empty tile; our caller will fill it in with little images. ******************************************************************************/ { XFillRectangle( XtDisplay(Board), XtWindow(Board), Reverse_GC, x, y, (unsigned int)spring.width, (unsigned int)spring.height ); } /* Draw_Blank */ \f static void Draw_Number( image, x, y ) XImage *image; int x; int y; /****************************************************************************** * Called to draw the number in the upper right corner of a numbered tile. ******************************************************************************/ { XPutImage( XtDisplay(Board), XtWindow(Board), Over_GC, image, 0, 0, x + Number_X, y + Number_Y, (unsigned int)image->width, (unsigned int)image->height ); } /* Draw_Number */ \f void Draw_Spring( x, y ) int x; int y; { Draw_Image( &spring, x, y ); } /* Draw_Spring */ void Draw_Summer( x, y ) int x; int y; { Draw_Image( &summer, x, y ); } /* Draw_Summer */ void Draw_Fall( x, y ) int x; int y; { Draw_Image( &fall, x, y ); } /* Draw_Fall */ void Draw_Winter( x, y ) int x; int y; { Draw_Image( &winter, x, y ); } /* Draw_Winter */ \f void Draw_Bamboo( x, y ) int x; int y; { Draw_Image( &bamboo, x, y ); } /* Draw_Bamboo */ void Draw_Mum( x, y ) int x; int y; { Draw_Image( &mum, x, y ); } /* Draw_Mum */ void Draw_Orchid( x, y ) int x; int y; { Draw_Image( &orchid, x, y ); } /* Draw_Orchid */ void Draw_Plum( x, y ) int x; int y; { Draw_Image( &plum, x, y ); } /* Draw_Plum */ \f void Draw_GDragon( x, y ) int x; int y; { Draw_Image( &gdragon, x, y ); } /* Draw_GDragon */ void Draw_RDragon( x, y ) int x; int y; { Draw_Image( &rdragon, x, y ); } /* Draw_RDragon */ void Draw_WDragon( x, y ) int x; int y; { Draw_Image( &wdragon, x, y ); } /* Draw_WDragon */ \f void Draw_East( x, y ) int x; int y; { Draw_Image( &east, x, y ); } /* Draw_East */ void Draw_West( x, y ) int x; int y; { Draw_Image( &west, x, y ); } /* Draw_West */ void Draw_North( x, y ) int x; int y; { Draw_Image( &north, x, y ); } /* Draw_North */ void Draw_South( x, y ) int x; int y; { Draw_Image( &south, x, y ); } /* Draw_South */ \f void Draw_Bam1( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &bam, bx + Tile_X11, by + Tile_Y11 ); Draw_Number( &one, x, y ); } /* Draw_Bam1 */ void Draw_Bam2( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &bam, bx + Tile_X11, by + Tile_Y21 ); Draw_Image( &bam, bx + Tile_X11, by + Tile_Y22 ); Draw_Number( &two, x, y ); } /* Draw_Bam2 */ void Draw_Bam3( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &bam, bx + Tile_X11, by + Tile_Y21 ); Draw_Image( &bam, bx + Tile_X21, by + Tile_Y22 ); Draw_Image( &bam, bx + Tile_X22, by + Tile_Y22 ); Draw_Number( &three, x, y ); } /* Draw_Bam3 */ void Draw_Bam4( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &bam, bx + Tile_X21, by + Tile_Y21 ); Draw_Image( &bam, bx + Tile_X22, by + Tile_Y21 ); Draw_Image( &bam, bx + Tile_X21, by + Tile_Y22 ); Draw_Image( &bam, bx + Tile_X22, by + Tile_Y22 ); Draw_Number( &four, x, y ); } /* Draw_Bam4 */ void Draw_Bam5( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &bam, bx + Tile_X11, by + Tile_Y31 ); Draw_Image( &bam, bx + Tile_X21, by + Tile_Y32 ); Draw_Image( &bam, bx + Tile_X22, by + Tile_Y32 ); Draw_Image( &bam, bx + Tile_X21, by + Tile_Y33 ); Draw_Image( &bam, bx + Tile_X22, by + Tile_Y33 ); Draw_Number( &five, x, y ); } /* Draw_Bam5 */ void Draw_Bam6( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &bam, bx + Tile_X21, by + Tile_Y31 ); Draw_Image( &bam, bx + Tile_X22, by + Tile_Y31 ); Draw_Image( &bam, bx + Tile_X21, by + Tile_Y32 ); Draw_Image( &bam, bx + Tile_X22, by + Tile_Y32 ); Draw_Image( &bam, bx + Tile_X21, by + Tile_Y33 ); Draw_Image( &bam, bx + Tile_X22, by + Tile_Y33 ); Draw_Number( &six, x, y ); } /* Draw_Bam6 */ void Draw_Bam7( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &bam, bx + Tile_X21, by + Tile_Y31 ); Draw_Image( &bam, bx + Tile_X22, by + Tile_Y31 ); Draw_Image( &bam, bx + Tile_X21, by + Tile_Y32 ); Draw_Image( &bam, bx + Tile_X22, by + Tile_Y32 ); Draw_Image( &bam, bx + Tile_X31, by + Tile_Y33 ); Draw_Image( &bam, bx + Tile_X32, by + Tile_Y33 ); Draw_Image( &bam, bx + Tile_X33, by + Tile_Y33 ); Draw_Number( &seven, x, y ); } /* Draw_Bam7 */ void Draw_Bam8( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &bam, bx + Tile_X21, by + Tile_Y31 ); Draw_Image( &bam, bx + Tile_X22, by + Tile_Y31 ); Draw_Image( &bam, bx + Tile_X31, by + Tile_Y32 ); Draw_Image( &bam, bx + Tile_X32, by + Tile_Y32 ); Draw_Image( &bam, bx + Tile_X33, by + Tile_Y32 ); Draw_Image( &bam, bx + Tile_X31, by + Tile_Y33 ); Draw_Image( &bam, bx + Tile_X32, by + Tile_Y33 ); Draw_Image( &bam, bx + Tile_X33, by + Tile_Y33 ); Draw_Number( &eight, x, y ); } /* Draw_Bam8 */ void Draw_Bam9( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &bam, bx + Tile_X31, by + Tile_Y31 ); Draw_Image( &bam, bx + Tile_X32, by + Tile_Y31 ); Draw_Image( &bam, bx + Tile_X33, by + Tile_Y31 ); Draw_Image( &bam, bx + Tile_X31, by + Tile_Y32 ); Draw_Image( &bam, bx + Tile_X32, by + Tile_Y32 ); Draw_Image( &bam, bx + Tile_X33, by + Tile_Y32 ); Draw_Image( &bam, bx + Tile_X31, by + Tile_Y33 ); Draw_Image( &bam, bx + Tile_X32, by + Tile_Y33 ); Draw_Image( &bam, bx + Tile_X33, by + Tile_Y33 ); Draw_Number( &nine, x, y ); } /* Draw_Bam9 */ \f void Draw_Dot1( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &dot, bx + Tile_X11, by + Tile_Y11 ); Draw_Number( &one, x, y ); } /* Draw_Dot1 */ void Draw_Dot2( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &dot, bx + Tile_X11, by + Tile_Y21 ); Draw_Image( &dot, bx + Tile_X11, by + Tile_Y22 ); Draw_Number( &two, x, y ); } /* Draw_Dot2 */ void Draw_Dot3( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &dot, bx + Tile_X11, by + Tile_Y21 ); Draw_Image( &dot, bx + Tile_X21, by + Tile_Y22 ); Draw_Image( &dot, bx + Tile_X22, by + Tile_Y22 ); Draw_Number( &three, x, y ); } /* Draw_Dot3 */ void Draw_Dot4( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &dot, bx + Tile_X21, by + Tile_Y21 ); Draw_Image( &dot, bx + Tile_X22, by + Tile_Y21 ); Draw_Image( &dot, bx + Tile_X21, by + Tile_Y22 ); Draw_Image( &dot, bx + Tile_X22, by + Tile_Y22 ); Draw_Number( &four, x, y ); } /* Draw_Dot4 */ void Draw_Dot5( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &dot, bx + Tile_X11, by + Tile_Y31 ); Draw_Image( &dot, bx + Tile_X21, by + Tile_Y32 ); Draw_Image( &dot, bx + Tile_X22, by + Tile_Y32 ); Draw_Image( &dot, bx + Tile_X21, by + Tile_Y33 ); Draw_Image( &dot, bx + Tile_X22, by + Tile_Y33 ); Draw_Number( &five, x, y ); } /* Draw_Dot5 */ void Draw_Dot6( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &dot, bx + Tile_X21, by + Tile_Y31 ); Draw_Image( &dot, bx + Tile_X22, by + Tile_Y31 ); Draw_Image( &dot, bx + Tile_X21, by + Tile_Y32 ); Draw_Image( &dot, bx + Tile_X22, by + Tile_Y32 ); Draw_Image( &dot, bx + Tile_X21, by + Tile_Y33 ); Draw_Image( &dot, bx + Tile_X22, by + Tile_Y33 ); Draw_Number( &six, x, y ); } /* Draw_Dot6 */ void Draw_Dot7( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &dot, bx + Tile_X21, by + Tile_Y31 ); Draw_Image( &dot, bx + Tile_X22, by + Tile_Y31 ); Draw_Image( &dot, bx + Tile_X21, by + Tile_Y32 ); Draw_Image( &dot, bx + Tile_X22, by + Tile_Y32 ); Draw_Image( &dot, bx + Tile_X31, by + Tile_Y33 ); Draw_Image( &dot, bx + Tile_X32, by + Tile_Y33 ); Draw_Image( &dot, bx + Tile_X33, by + Tile_Y33 ); Draw_Number( &seven, x, y ); } /* Draw_Dot7 */ void Draw_Dot8( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &dot, bx + Tile_X21, by + Tile_Y31 ); Draw_Image( &dot, bx + Tile_X22, by + Tile_Y31 ); Draw_Image( &dot, bx + Tile_X31, by + Tile_Y32 ); Draw_Image( &dot, bx + Tile_X32, by + Tile_Y32 ); Draw_Image( &dot, bx + Tile_X33, by + Tile_Y32 ); Draw_Image( &dot, bx + Tile_X31, by + Tile_Y33 ); Draw_Image( &dot, bx + Tile_X32, by + Tile_Y33 ); Draw_Image( &dot, bx + Tile_X33, by + Tile_Y33 ); Draw_Number( &eight, x, y ); } /* Draw_Dot8 */ void Draw_Dot9( x, y ) int x; int y; { int bx = x - SubTile_X; int by = y - SubTile_Y; Draw_Blank( x, y ); Draw_Image( &dot, bx + Tile_X31, by + Tile_Y31 ); Draw_Image( &dot, bx + Tile_X32, by + Tile_Y31 ); Draw_Image( &dot, bx + Tile_X33, by + Tile_Y31 ); Draw_Image( &dot, bx + Tile_X31, by + Tile_Y32 ); Draw_Image( &dot, bx + Tile_X32, by + Tile_Y32 ); Draw_Image( &dot, bx + Tile_X33, by + Tile_Y32 ); Draw_Image( &dot, bx + Tile_X31, by + Tile_Y33 ); Draw_Image( &dot, bx + Tile_X32, by + Tile_Y33 ); Draw_Image( &dot, bx + Tile_X33, by + Tile_Y33 ); Draw_Number( &nine, x, y ); } /* Draw_Dot9 */ \f void Draw_Crak1( x, y ) int x; int y; { Draw_Image( &crak, x, y ); Draw_Number( &one, x, y ); } /* Draw_Crak1 */ void Draw_Crak2( x, y ) int x; int y; { Draw_Image( &crak, x, y ); Draw_Number( &two, x, y ); } /* Draw_Crak2 */ void Draw_Crak3( x, y ) int x; int y; { Draw_Image( &crak, x, y ); Draw_Number( &three, x, y ); } /* Draw_Crak3 */ void Draw_Crak4( x, y ) int x; int y; { Draw_Image( &crak, x, y ); Draw_Number( &four, x, y ); } /* Draw_Crak4 */ void Draw_Crak5( x, y ) int x; int y; { Draw_Image( &crak, x, y ); Draw_Number( &five, x, y ); } /* Draw_Crak5 */ void Draw_Crak6( x, y ) int x; int y; { Draw_Image( &crak, x, y ); Draw_Number( &six, x, y ); } /* Draw_Crak6 */ void Draw_Crak7( x, y ) int x; int y; { Draw_Image( &crak, x, y ); Draw_Number( &seven, x, y ); } /* Draw_Crak7 */ void Draw_Crak8( x, y ) int x; int y; { Draw_Image( &crak, x, y ); Draw_Number( &eight, x, y ); } /* Draw_Crak8 */ void Draw_Crak9( x, y ) int x; int y; { Draw_Image( &crak, x, y ); Draw_Number( &nine, x, y ); } /* Draw_Crak9 */