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