Subversion Repositories Kolibri OS

Rev

Rev 8379 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8379 Rev 8610
Line 1... Line 1...
1
// Includes //
1
// Includes //
2
#include 
2
#include 
3
#include 
3
#include 
4
#include 
4
#include 
5
#include 
5
#include 
6
#include 
6
#include 
Line 7... Line 7...
7
 
7
 
8
#include 
8
#include 
Line 9... Line -...
9
// #include "mp3.h"
-
 
10
 
-
 
11
 
-
 
12
// C-- event defines //
-
 
13
#define evReDraw  1
-
 
14
#define evKey     2
-
 
15
#define evButton  3
-
 
16
#define evExit    4
-
 
17
#define evDesktop 5
-
 
18
#define evMouse   6
-
 
19
#define evIPC     7
-
 
20
#define evNetwork 8
-
 
21
#define evDebug   9
-
 
22
 
9
// #include "mp3.h"
23
 
10
 
24
// Code //
11
// Code //
Line 25... Line 12...
25
#define button_color 0xbbbbbb
12
#define button_color 0xbbbbbb
Line 39... Line 26...
39
 
26
 
Line 40... Line 27...
40
short victory = 0;
27
short victory = 0;
41
 
28
 
42
// Load pictures //
29
// Load pictures //
43
char temp_path[4096];
30
char temp_path[4096];
Line 44... Line 31...
44
char* HORIZONTAL_IMAGE;
31
Image* HORIZONTAL_IMAGE;
45
char* VERTICAL_IMAGE;
32
Image* VERTICAL_IMAGE;
46
 
33
 
47
char* load_file_inmem(char* fname, int32_t* read_sz)
34
char* load_file_inmem(char* fname, int32_t* read_sz)
Line 68... Line 55...
68
		return fdata;
55
		return fdata;
69
}
56
}
Line 70... Line 57...
70
 
57
 
71
void load_pictures() {
58
void load_pictures() {
72
		const int icon_rgb_field_size = button_size*button_size;
59
		const int icon_rgb_field_size = button_size*button_size;
73
		char *image_data,
60
		Image *image_data;
Line 74... Line 61...
74
			 *filedata;
61
		char *filedata;
Line 75... Line 62...
75
		
62
		
76
		strcpy(temp_path, "h.png");
63
		strcpy(temp_path, "h.png");
Line 97... Line 84...
97
		free(filedata);
84
		free(filedata);
98
}
85
}
Line 99... Line 86...
99
 
86
 
100
 
87
 
101
// GUI functions //
88
// GUI functions //
102
void redraw_buttons() {
89
void RedrawButtons() {
103
		for (int j = 5, x = 0; x
90
		for (int j = 5, x = 0; x
104
				for (int i = 15, y = 0; y
91
				for (int i = 15, y = 0; y
105
				{
92
				{
106
					// 0x50 mean button without drawing, but with border when press
93
					// 0x50 mean button without drawing, but with border when press
Line 107... Line 94...
107
					// ((y+1)*10)+x+1 mean button id
94
					// ((y+1)*10)+x+1 mean button id
108
					define_button(65536 * i + (button_size), 65536 * j + (button_size), (0x50 << 24) | ((y+1)*10)+x+1, 0);
95
					kos_DrawButton(i, j, button_size, button_size, (0x50 << 24) | ((y+1)*10)+x+1, 0);
109
					
96
					
110
					if (field[x][y]) draw_bitmap(VERTICAL_IMAGE, i, j, button_size, button_size);
97
					if (field[x][y]) kos_DrawBitmap(VERTICAL_IMAGE, i, j, button_size, button_size);
Line 111... Line 98...
111
					else draw_bitmap(HORIZONTAL_IMAGE, i, j, button_size, button_size);
98
					else kos_DrawBitmap(HORIZONTAL_IMAGE, i, j, button_size, button_size);
112
				}
99
				}
113
}
100
}
114
 
101
 
115
void draw_game_window(){
102
void draw_game_window(){
116
		BeginDraw(); 
103
		kos_BeginDraw(); 
Line 117... Line 104...
117
		DrawWindow(215, 100, 220, 220, title, button_color, 0x34);
104
		kos_DrawWindow(215, 100, 220, 220, title, button_color, 0x34);
118
		redraw_buttons();
105
		RedrawButtons();
Line 140... Line 127...
140
			}
127
			}
141
}
128
}
Line 142... Line 129...
142
 
129
 
143
// Need refactoring:
130
// Need refactoring:
144
void draw_victory_window() {
131
void draw_victory_window() {
145
		BeginDraw(); 
132
		kos_BeginDraw(); 
Line 146... Line 133...
146
		DrawWindow(215,100,220, 220,title,button_color,0x34);
133
		kos_DrawWindow(215,100,220, 220,title,button_color,0x34);
147
		
134
		
148
		draw_text_sysNEW("Ну вы, и", 10, 10, strlen("Ну вы, и"), 0xB1, 0x000000);
135
		draw_text_sysNEW("Ну вы, и", 10, 10, strlen("Ну вы, и"), 0xB1, 0x000000);
Line 149... Line 136...
149
		draw_text_sysNEW("медвежатник,", 10, 50, strlen("Ну вы, и медвежатник,"), 0xB1, 0x000000);
136
		draw_text_sysNEW("медвежатник,", 10, 50, strlen("Ну вы, и медвежатник,"), 0xB1, 0x000000);
150
		draw_text_sysNEW("Шеф!", 12, 90, strlen("Шеф!"), 0xB1, 0x000000);
137
		draw_text_sysNEW("Шеф!", 12, 90, strlen("Шеф!"), 0xB1, 0x000000);
151
		
138
		
152
		define_button(65536 * ((220/2)-(50)) + 140, 65536 * 140 + 25+12, BUTTON_RESTART, 0x9A9A9A);
139
		kos_DrawButton(((220/2)-(50)), 140, 140, 25+12, BUTTON_RESTART, 0x9A9A9A);
Line 153... Line -...
153
		draw_text_sysNEW("Заново", 80, 145, strlen("Заново"), 0xB1, 0x000000);
-
 
154
		EndDraw();
-
 
155
}
140
		draw_text_sysNEW("Заново", 80, 145, strlen("Заново"), 0xB1, 0x000000);
156
 
141
		kos_EndDraw();
157
 
142
}
158
 
143
 
159
void Button() {
144
void Button() {
160
		int id = get_os_button();
145
		int id = kos_GetButtonID();
161
		if (id == 1) exit(0); else
146
		if (id == 1) exit(0); else
Line 176... Line 161...
176
			for (int i = 0; i
161
			for (int i = 0; i
177
				if (field[y][i]) field[y][i] = 0; else field[y][i] = 1;
162
				if (field[y][i]) field[y][i] = 0; else field[y][i] = 1;
Line 178... Line 163...
178
				
163
				
Line 179... Line 164...
179
			if (field[y][x]) field[y][x] = 0; else field[y][x] = 1;
164
			if (field[y][x]) field[y][x] = 0; else field[y][x] = 1;
180
			
165
			
181
			redraw_buttons();
166
			RedrawButtons();
Line 182... Line 167...
182
		}
167
		}
183
}
168
}
184
 
169
 
185
 
170
 
186
int fridge_opened() {
171
int FridgeOpened() {
187
		int fr_op = 0;
172
		int fr_op = 0;
Line 199... Line 184...
199
{
184
{
200
		srand(time(0));
185
		srand(time(0));
Line 201... Line 186...
201
		
186
		
202
		if (kolibri_libimg_init() == -1) 
187
		if (kolibri_libimg_init() == -1) 
203
		{
188
		{
204
			printf("Can not load libimg.obj!\n");
189
			printf("Can not load libimg!\n");
205
			exit(1);
190
			exit(1);
Line 206... Line 191...
206
		}
191
		}
Line 207... Line -...
207
		
-
 
208
		load_pictures();
192
		
209
		
193
		load_pictures();
210
		draw_game_window();
194
		
211
		while(1)
195
		while(1)
212
		{
196
		{
213
			switch(get_os_event())
197
			switch(kos_WaitForEvent())
214
			{
198
			{
215
				case evButton:
199
				case evButton:
216
					Button();
200
					Button();
217
					if (fridge_opened()) {
201
					if (FridgeOpened()) {
218
						victory = 1;
202
						victory = 1;
219
						draw_victory_window();
-
 
220
					}
-
 
221
					break;
-
 
222
			  
-
 
223
				case evKey:
-
 
224
					get_key();
203
						draw_victory_window();
225
					break;
204
					}
226
				 
205
					break;
227
				case evReDraw:
206
				case evReDraw:
228
					if (!victory) draw_game_window();
207
					if (!victory) draw_game_window();