1 /*                                */
2 /* xemeraldia   ------ graphics.h */
3 /*                                */
4 
5 #include <stdio.h>
6 
7 #define GTK_DISABLE_DEPRECATED
8 #define GDK_PIXBUF_DISABLE_DEPRECATED
9 #define G_DISABLE_DEPRECATED
10 
11 #include <gtk/gtk.h>
12 #include <unistd.h>
13 #include <gettext.h>
14 
15 #define _(x) gettext(x)
16 
17 typedef enum {
18 	EMPTY = 0,
19 	COLOR_1 = 1,
20 	COLOR_2 = 2,
21 	COLOR_3 = 3,
22 	COLOR_4 = 4,
23 	COLOR_5 = 5,
24 	COLOR_6 = 6,
25 	CHECKED = 10,
26 	OBSTACLE = 32,
27 	STAR = 44
28 } cellstatus_t;
29 
30 typedef enum {
31 	EMPTY_SUB = 0,
32 	CRACKED = 1,
33 	DELETE = 2,
34 	NEW_CRACKED = 5
35 } cellsubstatus_t;
36 
37 #define BLOCK_VARIETY  6
38 #define BLOCK_WIDTH  32
39 #define BLOCK_HEIGHT 32
40 #define CRUSH_ANIME_FRAMES  5
41 
42 #define BOARD_WIDTH  7
43 #define BOARD_HEIGHT 14
44 
45 #define WIN_WIDTH   (BLOCK_WIDTH * (BOARD_WIDTH + 1))
46 #define WIN_HEIGHT  (BLOCK_HEIGHT * (BOARD_HEIGHT + 1))
47 #define DIFF_X       (BLOCK_WIDTH / 2)
48 #define DIFF_Y       (BLOCK_HEIGHT / 2)
49 
50 #define MAX_DELAY   920
51 
52 
53 extern GdkGC   *draw_gc, *delete_gc;
54 extern GdkPixmap  *board_pix, *block[BLOCK_VARIETY * 2 + 1], *saved_screen, *background;
55 extern GdkPixmap  *crush[CRUSH_ANIME_FRAMES];
56 extern GdkPixmap  *star;
57 extern GtkWidget  *board_w, *quit, *start, *scores, *nextItem_w, *score_disp, *level_disp, *about;
58 extern GtkWidget  *score_frame, *score_text, *high_sc_w, *topLevel;
59 extern int     colored;
60 extern guint timer;
61 extern PangoFontDescription *animated_score_font;
62 extern PangoFontDescription *game_over_font;
63 extern PangoFontDescription *pause_font;
64 extern FILE *f_scores;
65 extern int errno_scores;
66 
67 
68 typedef struct {
69   gboolean  usescorefile;
70   const char *scorefile;
71   GdkColor    block1pixel;
72   GdkColor    block2pixel;
73   GdkColor    block3pixel;
74   GdkColor    block4pixel;
75   GdkColor    block5pixel;
76   GdkColor    block6pixel;
77   GdkColor    starpixel;
78 } AppData, *AppDataPtr;
79 
80 extern AppData app_data;
81 
82 /* In graphics.c */
83 gboolean expose_board(GtkWidget *widget, GdkEventExpose *event, gpointer data);
84 void RedrawNextItem(void);
85 void deleteCell(int xcoord, int ycoord);
86 void delete_1_block(int x, int y);
87 void printNextItem(void);
88 void drawCell(int xcoord, int ycoord, cellstatus_t color, cellsubstatus_t sub);
89 void printBlock(int x, int y, cellstatus_t color);
90 void crack_1_block(int x, int y);
91 void crushAnimate(int x, int y, int num);
92 void printScore(void);
93 void printItem(void);
94 void printLevel(void);
95 void clearScreen(void);
96 void clearNextItem(void);
97 void startTimer(void);
98 void stopTimer(void);
99 void showTmpScore(long tmp_sc, int sc_x, int sc_y, long ch_s);
100 void Done(void);
101 
102 /* In move.c */
103 void Rotation(void);
104 void CCRotation(void);
105 void MoveLeft(void);
106 void MoveRight(void);
107 void MoveDown(void);
108 void moveItem(int vx, int vy);
109 gboolean CanItemMove(int vx, int vy, int vrot) /* G_GNUC_PURE */ ;
110 gboolean CanStarMove(int vx, int vy) G_GNUC_PURE;
111 
112 /* In games.c */
113 void StartGame(void);
114 void addScore(int sc_x, int sc_y);
115 void makeNext(void);
116 
117 /* In crack.c */
118 gboolean canMoveDown(void) G_GNUC_PURE;
119 gboolean DropItem(void);
120 
121 void Quit(void);
122 
123 /* In score.c */
124 void update_highscore_table(void);
125 void open_high_scores_file(void);
126 void read_high_scores(void);
127 void write_high_scores(void);
128 void PrintHighScores(void);
129 
130 /* In init-graphics */
131 void  initGTK (GtkWidget *w);
132 void  initXlib (void);
133 
134 #ifndef HIGH_SCORE_TABLE
135 #define HIGH_SCORE_TABLE ".xemeraldia.scores"
136 #endif
137 
138 #ifndef HAVE_USLEEP
139 void usleep(unsigned);
140 #endif
141