Rev 4438 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4438 | Rev 5372 | ||
---|---|---|---|
1 | #include |
1 | #include |
2 | #include |
2 | #include |
3 | #include |
3 | #include |
4 | #include |
4 | #include |
5 | #include "winlib.h" |
5 | #include "winlib.h" |
6 | 6 | ||
7 | extern int res_level[]; |
7 | extern int res_level[]; |
8 | extern int res_slider[]; |
8 | extern int res_slider[]; |
9 | extern int res_vol_slider[]; |
9 | extern int res_vol_slider[]; |
10 | extern int res_progress_bar[]; |
10 | extern int res_progress_bar[]; |
11 | extern int res_prg_level[]; |
11 | extern int res_prg_level[]; |
12 | 12 | ||
13 | extern ctrl_t *mouse_capture; |
13 | extern ctrl_t *mouse_capture; |
14 | uint32_t main_cursor; |
14 | uint32_t main_cursor; |
15 | 15 | ||
16 | static int button_proc(ctrl_t *btn, uint32_t msg, uint32_t arg1, uint32_t arg2); |
16 | static int button_proc(ctrl_t *btn, uint32_t msg, uint32_t arg1, uint32_t arg2); |
17 | static int spinbtn_proc(ctrl_t *btn, uint32_t msg, uint32_t arg1, uint32_t arg2); |
17 | static int spinbtn_proc(ctrl_t *btn, uint32_t msg, uint32_t arg1, uint32_t arg2); |
18 | 18 | ||
19 | ctrl_t *create_control(size_t size, int id, int x, int y, |
19 | ctrl_t *create_control(size_t size, int id, int x, int y, |
20 | int w, int h, ctrl_t *parent) |
20 | int w, int h, ctrl_t *parent) |
21 | { |
21 | { |
22 | 22 | ctrl_t *ctrl; |
|
23 | ctrl_t *ctrl; |
- | |
24 | 23 | ||
25 | if( !parent ) |
24 | if( !parent ) |
26 | return NULL; |
25 | return NULL; |
27 | 26 | ||
28 | ctrl = (ctrl_t*)malloc(size); |
27 | ctrl = (ctrl_t*)malloc(size); |
29 | 28 | ||
30 | link_initialize(&ctrl->link); |
29 | link_initialize(&ctrl->link); |
31 | list_initialize(&ctrl->child); |
30 | list_initialize(&ctrl->child); |
32 | 31 | ||
33 | ctrl->parent = parent; |
32 | ctrl->parent = parent; |
34 | 33 | ||
35 | ctrl->ctx = parent->ctx; |
34 | ctrl->ctx = parent->ctx; |
36 | ctrl->id = id; |
35 | ctrl->id = id; |
37 | 36 | ||
38 | ctrl->rc.l = x; |
37 | ctrl->rc.l = x; |
39 | ctrl->rc.t = y ; |
38 | ctrl->rc.t = y ; |
40 | 39 | ||
41 | ctrl->rc.r = x + w; |
40 | ctrl->rc.r = x + w; |
42 | ctrl->rc.b = y + h; |
41 | ctrl->rc.b = y + h; |
43 | 42 | ||
44 | ctrl->w = w; |
43 | ctrl->w = w; |
45 | ctrl->h = h; |
44 | ctrl->h = h; |
46 | 45 | ||
47 | list_append(&ctrl->link, &parent->child); |
46 | list_append(&ctrl->link, &parent->child); |
48 | 47 | ||
49 | return ctrl; |
48 | return ctrl; |
50 | }; |
49 | }; |
51 | 50 | ||
52 | 51 | ||
53 | button_t *create_button(char *caption, int id, int x, int y, |
52 | button_t *create_button(char *caption, int id, int x, int y, |
54 | int w, int h, ctrl_t *parent) |
53 | int w, int h, ctrl_t *parent) |
55 | { |
54 | { |
56 | button_t *btn; |
55 | button_t *btn; |
57 | int len; |
56 | int len; |
58 | 57 | ||
59 | if( !parent ) |
58 | if( !parent ) |
60 | return NULL; |
59 | return NULL; |
61 | 60 | ||
62 | btn = (button_t*)create_control(sizeof(button_t), id, x, y, w, h, parent); |
61 | btn = (button_t*)create_control(sizeof(button_t), id, x, y, w, h, parent); |
63 | btn->ctrl.handler = button_proc; |
62 | btn->ctrl.handler = button_proc; |
64 | btn->state = 0; |
63 | btn->state = 0; |
65 | btn->caption = caption; |
64 | btn->caption = caption; |
66 | 65 | ||
67 | if( !caption ) |
66 | if( !caption ) |
68 | btn->capt_len = 0; |
67 | btn->capt_len = 0; |
69 | else |
68 | else |
70 | { |
69 | { |
71 | len = strlen(caption); |
70 | len = strlen(caption); |
72 | btn->capt_len = len; |
71 | btn->capt_len = len; |
73 | if( len ) |
72 | if( len ) |
74 | btn->caption = strdup(caption); |
73 | btn->caption = strdup(caption); |
75 | else |
74 | else |
76 | btn->caption = NULL; |
75 | btn->caption = NULL; |
77 | } |
76 | } |
78 | 77 | ||
79 | btn->img_default = NULL; |
78 | btn->img_default = NULL; |
80 | btn->img_hilite = NULL; |
79 | btn->img_hilite = NULL; |
81 | btn->img_pressed = NULL; |
80 | btn->img_pressed = NULL; |
82 | 81 | ||
83 | return btn; |
82 | return btn; |
84 | }; |
83 | }; |
85 | 84 | ||
86 | #if 0 |
85 | #if 0 |
87 | int draw_button(button_t *btn) |
86 | int draw_button(button_t *btn) |
88 | { |
87 | { |
89 | void *bitmap; |
88 | void *bitmap; |
90 | 89 | ||
91 | bitmap = btn->img_default; |
90 | bitmap = btn->img_default; |
92 | 91 | ||
93 | if(btn->state & bPressed) |
92 | if(btn->state & bPressed) |
94 | bitmap = btn->img_pressed; |
93 | bitmap = btn->img_pressed; |
95 | else if(btn->state & bHighlight) |
94 | else if(btn->state & bHighlight) |
96 | bitmap = btn->img_hilite; |
95 | bitmap = btn->img_hilite; |
97 | 96 | ||
98 | if( bitmap ) |
97 | if( bitmap ) |
99 | draw_bitmap(bitmap, btn->rc.l, btn->rc.t, btn->w, btn->h); |
98 | draw_bitmap(bitmap, btn->rc.l, btn->rc.t, btn->w, btn->h); |
100 | 99 | ||
101 | if( btn->caption && btn->capt_len) |
100 | if( btn->caption && btn->capt_len) |
102 | { |
101 | { |
103 | int txt_w; |
102 | int txt_w; |
104 | int txt_x, txt_y; |
103 | int txt_x, txt_y; |
105 | txt_w = btn->capt_len*8-2; |
104 | txt_w = btn->capt_len*8-2; |
106 | 105 | ||
107 | txt_x = btn->rc.l + 1 + (btn->w - txt_w)/2; |
106 | txt_x = btn->rc.l + 1 + (btn->w - txt_w)/2; |
108 | txt_y = btn->rc.t + 9; |
107 | txt_y = btn->rc.t + 9; |
109 | 108 | ||
110 | if(btn->state & bPressed){ |
109 | if(btn->state & bPressed){ |
111 | txt_x++; |
110 | txt_x++; |
112 | txt_y++; |
111 | txt_y++; |
113 | }; |
112 | }; |
114 | draw_text(btn->caption, txt_x, txt_y, btn->capt_len, 0x10000000); |
113 | draw_text(btn->caption, txt_x, txt_y, btn->capt_len, 0x10000000); |
115 | }; |
114 | }; |
116 | return 0; |
115 | return 0; |
117 | }; |
116 | }; |
118 | #endif |
117 | #endif |
119 | 118 | ||
120 | int draw_button_cairo(button_t *btn) |
119 | int draw_button_cairo(button_t *btn) |
121 | { |
120 | { |
122 | int *src; |
121 | int *src; |
123 | ctx_t *ctx; |
122 | ctx_t *ctx; |
124 | int x, y; |
123 | int x, y; |
125 | 124 | ||
126 | ctx = btn->ctrl.ctx; |
125 | ctx = btn->ctrl.ctx; |
127 | 126 | ||
128 | lock_bitmap(ctx->pixmap); |
- | |
129 | - | ||
130 | x = btn->ctrl.rc.l - ctx->offset_x; |
127 | x = btn->ctrl.rc.l - ctx->offset_x; |
131 | y = btn->ctrl.rc.t - ctx->offset_y; |
128 | y = btn->ctrl.rc.t - ctx->offset_y; |
132 | 129 | ||
133 | src = btn->img_default; |
130 | src = btn->img_default; |
134 | 131 | ||
135 | if(btn->state & bPressed) |
132 | if(btn->state & bPressed) |
136 | src = btn->img_pressed; |
133 | src = btn->img_pressed; |
137 | else if(btn->state & bHighlight) |
134 | else if(btn->state & bHighlight) |
138 | src = btn->img_hilite; |
135 | src = btn->img_hilite; |
139 | 136 | ||
140 | blit_raw(ctx, src, x, y, btn->ctrl.w, btn->ctrl.h, btn->ctrl.w*4); |
137 | blit_raw(ctx, src, x, y, btn->ctrl.w, btn->ctrl.h, btn->ctrl.w*4); |
141 | 138 | ||
142 | return 0; |
139 | return 0; |
143 | }; |
140 | }; |
144 | 141 | ||
145 | 142 | ||
146 | int draw_spin_cairo(button_t *btn) |
143 | int draw_spin_cairo(button_t *btn) |
147 | { |
144 | { |
148 | void *ctx; |
145 | void *ctx; |
149 | 146 | ||
150 | return 0; |
147 | return 0; |
151 | }; |
148 | }; |
152 | 149 | ||
153 | 150 | ||
154 | int button_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
151 | int button_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
155 | { |
152 | { |
156 | int x, y; |
153 | int x, y; |
157 | int state; |
154 | int state; |
158 | int old_state; |
155 | int old_state; |
159 | int action=0; |
156 | int action=0; |
160 | 157 | ||
161 | button_t *btn = (button_t*)ctrl; |
158 | button_t *btn = (button_t*)ctrl; |
162 | 159 | ||
163 | switch( msg ) |
160 | switch( msg ) |
164 | { |
161 | { |
165 | case MSG_PAINT: |
162 | case MSG_PAINT: |
166 | draw_button_cairo(btn); |
163 | draw_button_cairo(btn); |
167 | update_rect((ctrl_t*)btn); |
164 | update_rect((ctrl_t*)btn); |
168 | break; |
165 | break; |
169 | 166 | ||
170 | case MSG_MOUSEENTER: |
167 | case MSG_MOUSEENTER: |
171 | // printf("mouse enter\n"); |
168 | // printf("mouse enter\n"); |
172 | btn->state|= bHighlight; |
169 | btn->state|= bHighlight; |
173 | send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
170 | send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
174 | break; |
171 | break; |
175 | 172 | ||
176 | case MSG_MOUSELEAVE: |
173 | case MSG_MOUSELEAVE: |
177 | // printf("mouse leave\n"); |
174 | // printf("mouse leave\n"); |
178 | if( (ctrl_t*)btn != mouse_capture) { |
175 | if( (ctrl_t*)btn != mouse_capture) { |
179 | btn->state &= ~bHighlight; |
176 | btn->state &= ~bHighlight; |
180 | send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
177 | send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
181 | }; |
178 | }; |
182 | break; |
179 | break; |
183 | 180 | ||
184 | case MSG_LBTNDOWN: |
181 | case MSG_LBTNDOWN: |
185 | case MSG_LBTNDBLCLK: |
182 | case MSG_LBTNDBLCLK: |
186 | // printf("push button\n"); |
183 | // printf("push button\n"); |
187 | capture_mouse((ctrl_t*)btn); |
184 | capture_mouse((ctrl_t*)btn); |
188 | btn->state|= bPressed; |
185 | btn->state|= bPressed; |
189 | send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
186 | send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
190 | break; |
187 | break; |
191 | 188 | ||
192 | case MSG_LBTNUP: |
189 | case MSG_LBTNUP: |
193 | 190 | ||
194 | // printf("button action\n"); |
191 | // printf("button action\n"); |
195 | if(btn->state & bPressed) |
192 | if(btn->state & bPressed) |
196 | action = MSG_COMMAND; |
193 | action = MSG_COMMAND; |
197 | 194 | ||
198 | release_mouse(); |
195 | release_mouse(); |
199 | 196 | ||
200 | x = ((pos_t)arg2).x; |
197 | x = ((pos_t)arg2).x; |
201 | y = ((pos_t)arg2).y; |
198 | y = ((pos_t)arg2).y; |
202 | 199 | ||
203 | if( pt_in_rect( &btn->ctrl.rc, x, y) ) |
200 | if( pt_in_rect( &btn->ctrl.rc, x, y) ) |
204 | state = bHighlight; |
201 | state = bHighlight; |
205 | else |
202 | else |
206 | state = 0; |
203 | state = 0; |
207 | 204 | ||
208 | if(action) |
205 | if(action) |
209 | send_message(btn->ctrl.parent,MSG_COMMAND,btn->ctrl.id,(int)btn); |
206 | send_message(btn->ctrl.parent,MSG_COMMAND,btn->ctrl.id,(int)btn); |
210 | 207 | ||
211 | btn->state = state; |
208 | btn->state = state; |
212 | send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
209 | send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
213 | break; |
210 | break; |
214 | 211 | ||
215 | case MSG_MOUSEMOVE: |
212 | case MSG_MOUSEMOVE: |
216 | 213 | ||
217 | if(main_cursor != 0) |
214 | if(main_cursor != 0) |
218 | { |
215 | { |
219 | set_cursor(0); |
216 | set_cursor(0); |
220 | main_cursor = 0; |
217 | main_cursor = 0; |
221 | } |
218 | } |
222 | 219 | ||
223 | if( ! (btn->state & bHighlight)) |
220 | if( ! (btn->state & bHighlight)) |
224 | { |
221 | { |
225 | btn->state|= bHighlight; |
222 | btn->state|= bHighlight; |
226 | send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
223 | send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
227 | }; |
224 | }; |
228 | 225 | ||
229 | if( (ctrl_t*)btn != mouse_capture) |
226 | if( (ctrl_t*)btn != mouse_capture) |
230 | return 0; |
227 | return 0; |
231 | 228 | ||
232 | x = ((pos_t)arg2).x; |
229 | x = ((pos_t)arg2).x; |
233 | y = ((pos_t)arg2).y; |
230 | y = ((pos_t)arg2).y; |
234 | 231 | ||
235 | old_state = btn->state; |
232 | old_state = btn->state; |
236 | 233 | ||
237 | if( pt_in_rect(&btn->ctrl.rc, x, y) ) |
234 | if( pt_in_rect(&btn->ctrl.rc, x, y) ) |
238 | btn->state |= bPressed; |
235 | btn->state |= bPressed; |
239 | else |
236 | else |
240 | btn->state &= ~bPressed; |
237 | btn->state &= ~bPressed; |
241 | 238 | ||
242 | if( old_state ^ btn->state) |
239 | if( old_state ^ btn->state) |
243 | send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
240 | send_message(&btn->ctrl, MSG_PAINT, 0, 0); |
244 | } |
241 | } |
245 | return 0; |
242 | return 0; |
246 | }; |
243 | }; |
247 | 244 | ||
248 | 245 | ||
249 | int draw_progress(progress_t *prg, int background) |
246 | int draw_progress(progress_t *prg, int background) |
250 | { |
247 | { |
251 | int *pixmap, *src; |
248 | int *pixmap, *src; |
252 | ctx_t *ctx; |
249 | ctx_t *ctx; |
253 | int i, j; |
250 | int i, j; |
254 | int x, y; |
251 | int x, y; |
255 | rect_t rc = prg->ctrl.rc; |
252 | rect_t rc = prg->ctrl.rc; |
256 | 253 | ||
257 | int len = prg->ctrl.w; |
254 | int len = prg->ctrl.w; |
258 | 255 | ||
259 | ctx = prg->ctrl.ctx; |
256 | ctx = prg->ctrl.ctx; |
260 | 257 | ||
261 | lock_bitmap(ctx->pixmap); |
- | |
262 | - | ||
263 | x = prg->ctrl.rc.l - ctx->offset_x; |
258 | x = prg->ctrl.rc.l - ctx->offset_x; |
264 | y = prg->ctrl.rc.t - ctx->offset_y; |
259 | y = prg->ctrl.rc.t - ctx->offset_y; |
265 | 260 | ||
266 | if( background ) |
261 | if( background ) |
267 | { |
262 | { |
268 | src = res_progress_bar; |
263 | src = res_progress_bar; |
269 | 264 | ||
270 | pixmap = (int*)ctx->pixmap->data; |
265 | pixmap = (int*)ctx->pixmap_data; |
271 | pixmap+= y * ctx->pixmap->pitch/4 + x; |
266 | pixmap+= y * ctx->pixmap_pitch/4 + x; |
272 | 267 | ||
273 | for(i=0; i < 10; i++) |
268 | for(i=0; i < 10; i++) |
274 | { |
269 | { |
275 | for(j = 0; j < len; j++) |
270 | for(j = 0; j < len; j++) |
276 | pixmap[j] = *src; |
271 | pixmap[j] = *src; |
277 | 272 | ||
278 | pixmap+= ctx->pixmap->pitch/4; |
273 | pixmap+= ctx->pixmap_pitch/4; |
279 | src++; |
274 | src++; |
280 | }; |
275 | }; |
281 | }; |
276 | }; |
282 | 277 | ||
283 | - | ||
284 | len = prg->current*prg->ctrl.w/(prg->max - prg->min); |
278 | len = prg->current*prg->ctrl.w/(prg->max - prg->min); |
285 | 279 | ||
286 | src = res_prg_level; |
280 | src = res_prg_level; |
287 | 281 | ||
288 | pixmap = (int*)ctx->pixmap->data; |
282 | pixmap = (int*)ctx->pixmap_data; |
289 | pixmap+= y*ctx->pixmap->pitch/4 + x; |
283 | pixmap+= y*ctx->pixmap_pitch/4 + x; |
290 | 284 | ||
291 | for(i=0; i < prg->ctrl.h ;i++) |
285 | for(i=0; i < prg->ctrl.h ;i++) |
292 | { |
286 | { |
293 | for(j=0; j < len; j++) |
287 | for(j=0; j < len; j++) |
294 | pixmap[j] = *src; |
288 | pixmap[j] = *src; |
295 | pixmap+= ctx->pixmap->pitch/4; |
289 | pixmap+= ctx->pixmap_pitch/4; |
296 | src++; |
290 | src++; |
297 | }; |
291 | }; |
298 | 292 | ||
299 | return 0; |
293 | return 0; |
300 | }; |
294 | }; |
301 | 295 | ||
302 | 296 | ||
303 | int prg_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
297 | int prg_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
304 | { |
298 | { |
305 | progress_t *prg = (progress_t*)ctrl; |
299 | progress_t *prg = (progress_t*)ctrl; |
306 | int pos; |
300 | int pos; |
307 | 301 | ||
308 | switch( msg ) |
302 | switch( msg ) |
309 | { |
303 | { |
310 | case MSG_PAINT: |
304 | case MSG_PAINT: |
311 | draw_progress(prg, 1); |
305 | draw_progress(prg, 1); |
312 | update_rect(ctrl); |
306 | update_rect(ctrl); |
313 | break; |
307 | break; |
314 | 308 | ||
315 | case MSG_LBTNDOWN: |
309 | case MSG_LBTNDOWN: |
316 | prg->pos = ((pos_t)arg2).x - ctrl->rc.l; |
310 | prg->pos = ((pos_t)arg2).x - ctrl->rc.l; |
317 | send_message(ctrl->parent,MSG_COMMAND,ctrl->id,(int)ctrl); |
311 | send_message(ctrl->parent,MSG_COMMAND,ctrl->id,(int)ctrl); |
318 | break; |
312 | break; |
319 | 313 | ||
320 | case PRG_PROGRESS: |
314 | case PRG_PROGRESS: |
321 | draw_progress(prg, 0); |
315 | draw_progress(prg, 0); |
322 | update_rect(ctrl); |
316 | update_rect(ctrl); |
323 | break; |
317 | break; |
324 | 318 | ||
325 | default: |
319 | default: |
326 | break; |
320 | break; |
327 | } |
321 | } |
328 | return 0; |
322 | return 0; |
329 | }; |
323 | }; |
330 | 324 | ||
331 | 325 | ||
332 | progress_t *create_progress(char *caption, int id, int x, int y, |
326 | progress_t *create_progress(char *caption, int id, int x, int y, |
333 | int w, int h, ctrl_t *parent) |
327 | int w, int h, ctrl_t *parent) |
334 | { |
328 | { |
335 | progress_t *prg; |
329 | progress_t *prg; |
336 | int len; |
330 | int len; |
337 | 331 | ||
338 | if( !parent ) |
332 | if( !parent ) |
339 | return NULL; |
333 | return NULL; |
340 | 334 | ||
341 | prg = (progress_t*)create_control(sizeof(progress_t), id, x, y, w, h, parent); |
335 | prg = (progress_t*)create_control(sizeof(progress_t), id, x, y, w, h, parent); |
342 | 336 | ||
343 | prg->ctrl.handler = prg_proc; |
337 | prg->ctrl.handler = prg_proc; |
344 | 338 | ||
345 | prg->min = 0; |
339 | prg->min = 0; |
346 | prg->max = 1; |
340 | prg->max = 1; |
347 | prg->current = 0; |
341 | prg->current = 0; |
348 | prg->pos = 0; |
342 | prg->pos = 0; |
349 | 343 | ||
350 | return prg; |
344 | return prg; |
351 | }; |
345 | }; |
352 | 346 | ||
353 | int draw_level(level_t *lvl) |
347 | int draw_level(level_t *lvl) |
354 | { |
348 | { |
355 | int *pixmap; |
349 | int *pixmap; |
356 | ctx_t *ctx; |
350 | ctx_t *ctx; |
357 | int i, j; |
351 | int i, j; |
358 | int x, y; |
352 | int x, y; |
359 | 353 | ||
360 | int len; |
354 | int len; |
361 | double level; |
355 | double level; |
362 | 356 | ||
363 | ctx = lvl->ctrl.ctx; |
357 | ctx = lvl->ctrl.ctx; |
364 | 358 | ||
365 | lock_bitmap(ctx->pixmap); |
- | |
366 | - | ||
367 | x = lvl->ctrl.rc.l - ctx->offset_x; |
359 | x = lvl->ctrl.rc.l - ctx->offset_x; |
368 | y = lvl->ctrl.rc.t - ctx->offset_y; |
360 | y = lvl->ctrl.rc.t - ctx->offset_y; |
369 | 361 | ||
370 | level = (log2(lvl->current+1)-7)*12 + lvl->vol/50 ; |
362 | level = (log2(lvl->current+1)-7)*12 + lvl->vol/50 ; |
371 | 363 | ||
372 | len = level; |
364 | len = level; |
373 | 365 | ||
374 | if(len < 0) |
366 | if(len < 0) |
375 | len = 0; |
367 | len = 0; |
376 | if(len > 96) |
368 | if(len > 96) |
377 | len = 96; |
369 | len = 96; |
378 | 370 | ||
379 | pixmap = (int*)ctx->pixmap->data; |
371 | pixmap = (int*)ctx->pixmap_data; |
380 | 372 | ||
381 | pixmap+= y*ctx->pixmap->pitch/4 + x; |
373 | pixmap+= y*ctx->pixmap_pitch/4 + x; |
382 | 374 | ||
383 | for(i=0; i < 10; i++) |
375 | for(i=0; i < 10; i++) |
384 | { |
376 | { |
385 | for(j = 0; j < 96; j++) |
377 | for(j = 0; j < 96; j++) |
386 | pixmap[j] = 0xFF1C1C1C; |
378 | pixmap[j] = 0xFF1C1C1C; |
387 | pixmap+= ctx->pixmap->pitch/4; |
379 | pixmap+= ctx->pixmap_pitch/4; |
388 | }; |
380 | }; |
389 | 381 | ||
390 | blit_raw(ctx, lvl->img_level, x, y, len, 10, 96*4); |
382 | blit_raw(ctx, lvl->img_level, x, y, len, 10, 96*4); |
391 | 383 | ||
392 | return 0; |
384 | return 0; |
393 | }; |
385 | }; |
394 | 386 | ||
395 | 387 | ||
396 | int lvl_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
388 | int lvl_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
397 | { |
389 | { |
398 | level_t *lvl = (level_t*)ctrl; |
390 | level_t *lvl = (level_t*)ctrl; |
399 | // int pos; |
391 | |
400 | - | ||
401 | switch( msg ) |
392 | switch( msg ) |
402 | { |
393 | { |
403 | case MSG_PAINT: |
394 | case MSG_PAINT: |
404 | if(lvl->visible) |
395 | if(lvl->visible) |
405 | { |
396 | { |
406 | draw_level(lvl); |
397 | draw_level(lvl); |
407 | update_rect(ctrl); |
398 | update_rect(ctrl); |
408 | }; |
399 | }; |
409 | break; |
400 | break; |
410 | 401 | ||
411 | // case MSG_LBTNDOWN: |
402 | // case MSG_LBTNDOWN: |
412 | // prg->pos = ((pos_t)arg2).x - ctrl->rc.l; |
403 | // prg->pos = ((pos_t)arg2).x - ctrl->rc.l; |
413 | // send_message(ctrl->parent,MSG_COMMAND,ctrl->id,(int)ctrl); |
404 | // send_message(ctrl->parent,MSG_COMMAND,ctrl->id,(int)ctrl); |
414 | // break; |
405 | // break; |
415 | 406 | ||
416 | default: |
407 | default: |
417 | break; |
408 | break; |
418 | } |
409 | } |
419 | return 0; |
410 | return 0; |
420 | }; |
411 | }; |
421 | 412 | ||
422 | level_t *create_level(char *caption, int id, int x, int y, |
413 | level_t *create_level(char *caption, int id, int x, int y, |
423 | int w, int h, ctrl_t *parent) |
414 | int w, int h, ctrl_t *parent) |
424 | { |
415 | { |
425 | level_t *lvl; |
416 | level_t *lvl; |
426 | 417 | ||
427 | if( !parent ) |
418 | if( !parent ) |
428 | return NULL; |
419 | return NULL; |
429 | 420 | ||
430 | lvl = (level_t*)create_control(sizeof(level_t), id, x, y, w, h, parent); |
421 | lvl = (level_t*)create_control(sizeof(level_t), id, x, y, w, h, parent); |
431 | lvl->ctrl.handler = lvl_proc; |
422 | lvl->ctrl.handler = lvl_proc; |
432 | 423 | ||
433 | lvl->min = 0; |
424 | lvl->min = 0; |
434 | lvl->max = 1; |
425 | lvl->max = 1; |
435 | lvl->current = 0; |
426 | lvl->current = 0; |
436 | lvl->pos = 0; |
427 | lvl->pos = 0; |
437 | lvl->visible = 0; |
428 | lvl->visible = 0; |
438 | lvl->img_level = res_level; |
429 | lvl->img_level = res_level; |
439 | 430 | ||
440 | return lvl; |
431 | return lvl; |
441 | }; |
432 | }; |
442 | 433 | ||
443 | 434 | ||
444 | int draw_slider(slider_t *sld) |
435 | int draw_slider(slider_t *sld) |
445 | { |
436 | { |
446 | int *pixmap; |
437 | int *pixmap; |
447 | ctx_t *ctx; |
438 | ctx_t *ctx; |
448 | int i, j; |
439 | int i, j; |
449 | int x, y; |
440 | int x, y; |
450 | 441 | ||
451 | int32_t len; |
442 | int32_t len; |
452 | double level; |
443 | double level; |
453 | 444 | ||
454 | ctx = sld->ctrl.ctx; |
445 | ctx = sld->ctrl.ctx; |
455 | 446 | ||
456 | lock_bitmap(ctx->pixmap); |
- | |
457 | - | ||
458 | x = sld->ctrl.rc.l - ctx->offset_x; |
447 | x = sld->ctrl.rc.l - ctx->offset_x; |
459 | y = sld->ctrl.rc.t - ctx->offset_y; |
448 | y = sld->ctrl.rc.t - ctx->offset_y; |
460 | 449 | ||
461 | len = 96 + 12; |
450 | len = 96 + 12; |
462 | 451 | ||
463 | pixmap = (int*)ctx->pixmap->data; |
452 | pixmap = (int*)ctx->pixmap_data; |
464 | pixmap+= y*ctx->pixmap->pitch/4 + x; |
453 | pixmap+= y*ctx->pixmap_pitch/4 + x; |
465 | 454 | ||
466 | for(i=0; i < 11; i++) |
455 | for(i=0; i < 11; i++) |
467 | { |
456 | { |
468 | for(j = 0; j < len; j++) |
457 | for(j = 0; j < len; j++) |
469 | pixmap[j] = 0xFF1C1C1C; |
458 | pixmap[j] = 0xFF1C1C1C; |
470 | pixmap+= ctx->pixmap->pitch/4; |
459 | pixmap+= ctx->pixmap_pitch/4; |
471 | }; |
460 | }; |
472 | 461 | ||
473 | blit_raw(ctx, sld->img_vol_slider, x+6, y+4, 96, 4, 96*4); |
462 | blit_raw(ctx, sld->img_vol_slider, x+6, y+4, 96, 4, 96*4); |
474 | 463 | blit_raw(ctx, res_slider, x+sld->pos, y, 12, 11, 12*4); |
|
475 | blit_raw(ctx, res_slider, x+sld->pos, y, 12, 11, 12*4); |
- | |
476 | 464 | ||
477 | return 0; |
465 | return 0; |
478 | }; |
466 | }; |
479 | 467 | ||
480 | 468 | ||
481 | int sld_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
469 | int sld_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
482 | { |
470 | { |
483 | slider_t *sld = (slider_t*)ctrl; |
471 | slider_t *sld = (slider_t*)ctrl; |
484 | int pos; |
472 | int pos; |
485 | 473 | ||
486 | switch( msg ) |
474 | switch( msg ) |
487 | { |
475 | { |
488 | case MSG_PAINT: |
476 | case MSG_PAINT: |
489 | draw_slider(sld); |
477 | draw_slider(sld); |
490 | update_rect(ctrl); |
478 | update_rect(ctrl); |
491 | break; |
479 | break; |
492 | 480 | ||
493 | case MSG_LBTNDOWN: |
481 | case MSG_LBTNDOWN: |
494 | capture_mouse(ctrl); |
482 | capture_mouse(ctrl); |
495 | sld->mode = 1; |
483 | sld->mode = 1; |
496 | 484 | ||
497 | pos = ((pos_t)arg2).x - ctrl->rc.l - 6; |
485 | pos = ((pos_t)arg2).x - ctrl->rc.l - 6; |
498 | if( pos < 0 ) |
486 | if( pos < 0 ) |
499 | pos = 0; |
487 | pos = 0; |
500 | else if(pos > 96) |
488 | else if(pos > 96) |
501 | pos = 96; |
489 | pos = 96; |
502 | if( sld->pos != pos) |
490 | if( sld->pos != pos) |
503 | { |
491 | { |
504 | sld->pos = pos; |
492 | sld->pos = pos; |
505 | send_message(ctrl->parent,MSG_COMMAND,ctrl->id,(int)ctrl); |
493 | send_message(ctrl->parent,MSG_COMMAND,ctrl->id,(int)ctrl); |
506 | }; |
494 | }; |
507 | break; |
495 | break; |
508 | 496 | ||
509 | case MSG_LBTNUP: |
497 | case MSG_LBTNUP: |
510 | if(sld->mode) |
498 | if(sld->mode) |
511 | { |
499 | { |
512 | release_mouse(); |
500 | release_mouse(); |
513 | sld->mode = 0; |
501 | sld->mode = 0; |
514 | }; |
502 | }; |
515 | break; |
503 | break; |
516 | 504 | ||
517 | case MSG_MOUSEMOVE: |
505 | case MSG_MOUSEMOVE: |
518 | if(sld->mode) |
506 | if(sld->mode) |
519 | { |
507 | { |
520 | pos = ((pos_t)arg2).x - ctrl->rc.l - 6; |
508 | pos = ((pos_t)arg2).x - ctrl->rc.l - 6; |
521 | if( pos < 0 ) |
509 | if( pos < 0 ) |
522 | pos = 0; |
510 | pos = 0; |
523 | else if(pos > 96) |
511 | else if(pos > 96) |
524 | pos = 96; |
512 | pos = 96; |
525 | if( sld->pos != pos) |
513 | if( sld->pos != pos) |
526 | { |
514 | { |
527 | sld->pos = pos; |
515 | sld->pos = pos; |
528 | // printf("slider pos %d\n", sld->pos); |
516 | // printf("slider pos %d\n", sld->pos); |
529 | send_message(ctrl->parent,MSG_COMMAND,ctrl->id,(int)ctrl); |
517 | send_message(ctrl->parent,MSG_COMMAND,ctrl->id,(int)ctrl); |
530 | } |
518 | } |
531 | }; |
519 | }; |
532 | break; |
520 | break; |
533 | 521 | ||
534 | case MSG_MOUSEENTER: |
522 | case MSG_MOUSEENTER: |
535 | panel_set_layout(ctrl->parent, 1); |
523 | panel_set_layout(ctrl->parent, 1); |
536 | // printf("level on\n"); |
524 | // printf("level on\n"); |
537 | break; |
525 | break; |
538 | 526 | ||
539 | case MSG_MOUSELEAVE: |
527 | case MSG_MOUSELEAVE: |
540 | panel_set_layout(ctrl->parent, 0); |
528 | panel_set_layout(ctrl->parent, 0); |
541 | // printf("level off\n"); |
529 | // printf("level off\n"); |
542 | break; |
530 | break; |
543 | 531 | ||
544 | 532 | ||
545 | default: |
533 | default: |
546 | break; |
534 | break; |
547 | } |
535 | } |
548 | return 0; |
536 | return 0; |
549 | }; |
537 | }; |
550 | 538 | ||
551 | 539 | ||
552 | slider_t *create_slider(char *caption, int id, int x, int y, |
540 | slider_t *create_slider(char *caption, int id, int x, int y, |
553 | int w, int h, ctrl_t *parent) |
541 | int w, int h, ctrl_t *parent) |
554 | { |
542 | { |
555 | 543 | ||
556 | slider_t *sld; |
544 | slider_t *sld; |
557 | 545 | ||
558 | if( !parent ) |
546 | if( !parent ) |
559 | return NULL; |
547 | return NULL; |
560 | 548 | ||
561 | sld = (slider_t*)create_control(sizeof(slider_t), id, x, y, w, h, parent); |
549 | sld = (slider_t*)create_control(sizeof(slider_t), id, x, y, w, h, parent); |
562 | sld->ctrl.handler = sld_proc; |
550 | sld->ctrl.handler = sld_proc; |
563 | 551 | ||
564 | sld->min = -5000; |
552 | sld->min = -5000; |
565 | sld->max = 0; |
553 | sld->max = 0; |
566 | sld->current = 0; |
554 | sld->current = 0; |
567 | sld->pos = 60; |
555 | sld->pos = 60; |
568 | sld->mode = 0; |
556 | sld->mode = 0; |
569 | sld->img_vol_slider = res_vol_slider; |
557 | sld->img_vol_slider = res_vol_slider; |
570 | 558 | ||
571 | return sld; |
559 | return sld; |
572 | };>>>>>>>>>>> |
560 | };>>>>>>>>>>> |