Rev 4438 | Go to most recent revision | Only display areas with differences | Ignore 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 "winlib.h" |
4 | #include "winlib.h" |
5 | 5 | ||
6 | #define CAPTION_CORNER_W 8 |
6 | #define CAPTION_CORNER_W 8 |
7 | 7 | ||
8 | extern int res_caption_left[]; |
8 | extern int res_caption_left[]; |
9 | extern int res_caption_right[]; |
9 | extern int res_caption_right[]; |
10 | extern int res_caption_body[]; |
10 | extern int res_caption_body[]; |
11 | 11 | ||
12 | extern int res_close_btn[]; |
12 | extern int res_close_btn[]; |
13 | extern int res_close_btn_hl[]; |
13 | extern int res_close_btn_hl[]; |
14 | extern int res_close_btn_pressed[]; |
14 | extern int res_close_btn_pressed[]; |
15 | 15 | ||
16 | extern int res_minimize_btn[]; |
16 | extern int res_minimize_btn[]; |
17 | extern int res_minimize_btn_hl[]; |
17 | extern int res_minimize_btn_hl[]; |
18 | extern int res_minimize_btn_pressed[]; |
18 | extern int res_minimize_btn_pressed[]; |
19 | 19 | ||
20 | extern int res_full_btn[]; |
20 | extern int res_full_btn[]; |
21 | extern int res_full_btn_hl[]; |
21 | extern int res_full_btn_hl[]; |
22 | extern int res_full_btn_pressed[]; |
22 | extern int res_full_btn_pressed[]; |
23 | 23 | ||
24 | extern uint32_t main_cursor; |
24 | extern uint32_t main_cursor; |
25 | 25 | ||
26 | void update_caption_size(window_t *win); |
26 | void update_caption_size(window_t *win); |
27 | 27 | ||
28 | int caption_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2); |
28 | int caption_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2); |
29 | 29 | ||
30 | 30 | ||
31 | int init_caption(window_t *win) |
31 | int init_caption(window_t *win) |
32 | { |
32 | { |
33 | button_t *btn; |
33 | button_t *btn; |
34 | 34 | ||
35 | caption_t *cpt = &win->caption; |
35 | caption_t *cpt = &win->caption; |
36 | ctx_t *ctx = &cpt->ctx; |
36 | ctx_t *ctx = &cpt->ctx; |
37 | 37 | ||
38 | link_initialize(&cpt->ctrl.link); |
38 | link_initialize(&cpt->ctrl.link); |
39 | list_initialize(&cpt->ctrl.child); |
39 | list_initialize(&cpt->ctrl.child); |
40 | 40 | ||
41 | cpt->ctrl.handler = caption_proc; |
41 | cpt->ctrl.handler = caption_proc; |
42 | cpt->ctrl.parent = (ctrl_t*)win; |
42 | cpt->ctrl.parent = (ctrl_t*)win; |
43 | 43 | ||
44 | cpt->text = win->caption_txt; |
44 | cpt->text = win->caption_txt; |
45 | 45 | ||
46 | cpt->bitmap.width = 1920; |
- | |
47 | cpt->bitmap.height = CAPTION_HEIGHT; |
46 | ctx->pixmap_data = user_alloc(1920*CAPTION_HEIGHT*4); |
48 | cpt->bitmap.flags = 0; |
- | |
49 | - | ||
50 | if( create_bitmap(&cpt->bitmap) ) |
- | |
51 | { |
- | |
52 | printf("not enough memory for caption bitmap\n"); |
- | |
53 | return 0; |
- | |
54 | } |
- | |
55 | - | ||
56 | - | ||
57 | // printf("win_w %d win_h %d\n", win->w, win->h); |
- | |
58 | ctx->pixmap = &cpt->bitmap; |
47 | ctx->pixmap_pitch= 1920*4; |
59 | ctx->offset_x = 0; |
48 | ctx->offset_x = 0; |
60 | ctx->offset_y = 0; |
49 | ctx->offset_y = 0; |
61 | 50 | ||
62 | cpt->ctrl.ctx = ctx; |
51 | cpt->ctrl.ctx = ctx; |
63 | 52 | ||
64 | btn = create_button(NULL, ID_CLOSE,0,5,18,18,(ctrl_t*)cpt); |
53 | btn = create_button(NULL, ID_CLOSE,0,5,18,18,(ctrl_t*)cpt); |
65 | cpt->close_btn = btn; |
54 | cpt->close_btn = btn; |
66 | 55 | ||
67 | btn->img_default = res_close_btn; |
56 | btn->img_default = res_close_btn; |
68 | btn->img_hilite = res_close_btn_hl; |
57 | btn->img_hilite = res_close_btn_hl; |
69 | btn->img_pressed = res_close_btn_pressed; |
58 | btn->img_pressed = res_close_btn_pressed; |
70 | 59 | ||
71 | btn = create_button(NULL, ID_MINIMIZE,0,5,18,18,(ctrl_t*)cpt); |
60 | btn = create_button(NULL, ID_MINIMIZE,0,5,18,18,(ctrl_t*)cpt); |
72 | cpt->minimize_btn = btn; |
61 | cpt->minimize_btn = btn; |
73 | 62 | ||
74 | btn->img_default = res_minimize_btn; |
63 | btn->img_default = res_minimize_btn; |
75 | btn->img_hilite = res_minimize_btn_hl; |
64 | btn->img_hilite = res_minimize_btn_hl; |
76 | btn->img_pressed = res_minimize_btn_pressed; |
65 | btn->img_pressed = res_minimize_btn_pressed; |
77 | 66 | ||
78 | btn = create_button(NULL, ID_FULLSCREEN,0,5,18,18,(ctrl_t*)cpt); |
67 | btn = create_button(NULL, ID_FULLSCREEN,0,5,18,18,(ctrl_t*)cpt); |
79 | cpt->full_btn = btn; |
68 | cpt->full_btn = btn; |
80 | 69 | ||
81 | btn->img_default = res_full_btn; |
70 | btn->img_default = res_full_btn; |
82 | btn->img_hilite = res_full_btn_hl; |
71 | btn->img_hilite = res_full_btn_hl; |
83 | btn->img_pressed = res_full_btn_pressed; |
72 | btn->img_pressed = res_full_btn_pressed; |
84 | 73 | ||
85 | update_caption_size(win); |
74 | update_caption_size(win); |
86 | 75 | ||
87 | return 1; |
76 | return 1; |
88 | }; |
77 | }; |
89 | 78 | ||
90 | 79 | ||
91 | void update_caption_size(window_t *win) |
80 | void update_caption_size(window_t *win) |
92 | { |
81 | { |
93 | caption_t *cpt = &win->caption; |
82 | caption_t *cpt = &win->caption; |
94 | bitmap_t *bitmap = &cpt->bitmap; |
83 | ctx_t *ctx = &cpt->ctx; |
95 | 84 | ||
96 | bitmap->width = win->w; |
85 | ctx->pixmap_pitch = win->w * 4; |
97 | resize_bitmap(bitmap); |
- | |
98 | 86 | ||
99 | cpt->ctrl.rc.l = 0; |
87 | cpt->ctrl.rc.l = 0; |
100 | cpt->ctrl.rc.t = 0; |
88 | cpt->ctrl.rc.t = 0; |
101 | cpt->ctrl.rc.r = win->w; |
89 | cpt->ctrl.rc.r = win->w; |
102 | cpt->ctrl.rc.b = CAPTION_HEIGHT; |
90 | cpt->ctrl.rc.b = CAPTION_HEIGHT; |
103 | cpt->ctrl.w = win->w; |
91 | cpt->ctrl.w = win->w; |
104 | cpt->ctrl.h = CAPTION_HEIGHT; |
92 | cpt->ctrl.h = CAPTION_HEIGHT; |
105 | win->client.t = CAPTION_HEIGHT; |
93 | win->client.t = CAPTION_HEIGHT; |
106 | 94 | ||
107 | cpt->close_btn->ctrl.rc.l = win->w - 27; |
95 | cpt->close_btn->ctrl.rc.l = win->w - 27; |
108 | cpt->close_btn->ctrl.rc.r = cpt->close_btn->ctrl.rc.l + |
96 | cpt->close_btn->ctrl.rc.r = cpt->close_btn->ctrl.rc.l + |
109 | cpt->close_btn->ctrl.w; |
97 | cpt->close_btn->ctrl.w; |
110 | 98 | ||
111 | cpt->minimize_btn->ctrl.rc.l = win->w - 27 - 18 - 5; |
99 | cpt->minimize_btn->ctrl.rc.l = win->w - 27 - 18 - 5; |
112 | cpt->minimize_btn->ctrl.rc.r = cpt->minimize_btn->ctrl.rc.l + |
100 | cpt->minimize_btn->ctrl.rc.r = cpt->minimize_btn->ctrl.rc.l + |
113 | cpt->minimize_btn->ctrl.w; |
101 | cpt->minimize_btn->ctrl.w; |
114 | 102 | ||
115 | cpt->full_btn->ctrl.rc.l = win->w - 27 - 18 -18 - 5 - 5; |
103 | cpt->full_btn->ctrl.rc.l = win->w - 27 - 18 -18 - 5 - 5; |
116 | cpt->full_btn->ctrl.rc.r = cpt->full_btn->ctrl.rc.l + |
104 | cpt->full_btn->ctrl.rc.r = cpt->full_btn->ctrl.rc.l + |
117 | cpt->full_btn->ctrl.w; |
105 | cpt->full_btn->ctrl.w; |
118 | 106 | }; |
|
119 | }; |
- | |
120 | 107 | ||
121 | - | ||
122 | extern int win_font; |
108 | extern int win_font; |
123 | 109 | ||
124 | void draw_caption(caption_t *cpt) |
110 | void draw_caption(caption_t *cpt) |
125 | { |
111 | { |
126 | int *pixmap, *src; |
112 | ctx_t *ctx = &cpt->ctx; |
- | 113 | int *pixmap, *src; |
|
127 | rect_t rc; |
114 | rect_t rc; |
128 | int i, j, w; |
115 | int i, j, w; |
129 | 116 | ||
130 | lock_bitmap(&cpt->bitmap); |
- | |
131 | - | ||
132 | blit_raw(&cpt->ctx, res_caption_left, 0, 0, |
117 | blit_raw(ctx, res_caption_left, 0, 0, |
133 | CAPTION_CORNER_W, CAPTION_HEIGHT, CAPTION_CORNER_W*4); |
118 | CAPTION_CORNER_W, CAPTION_HEIGHT, CAPTION_CORNER_W*4); |
134 | 119 | ||
135 | w = cpt->ctrl.w - (2*CAPTION_CORNER_W); |
120 | w = cpt->ctrl.w - (2*CAPTION_CORNER_W); |
136 | if( w > 0) |
121 | if( w > 0) |
137 | { |
122 | { |
138 | pixmap = (int*)cpt->ctx.pixmap->data; |
123 | pixmap = (int*)ctx->pixmap_data; |
139 | pixmap+= CAPTION_CORNER_W; |
124 | pixmap+= CAPTION_CORNER_W; |
140 | src = res_caption_body; |
125 | src = res_caption_body; |
141 | 126 | ||
142 | for(i = 0; i < CAPTION_HEIGHT; i++) |
127 | for(i = 0; i < CAPTION_HEIGHT; i++) |
143 | { |
128 | { |
144 | for(j = 0; j < w; j++) |
129 | for(j = 0; j < w; j++) |
145 | pixmap[j] = src[i]; |
130 | pixmap[j] = src[i]; |
146 | pixmap+= cpt->ctx.pixmap->pitch/4; |
131 | pixmap+= ctx->pixmap_pitch/4; |
147 | } |
132 | } |
148 | 133 | }; |
|
149 | // blit_raw(&cpt->ctx,res_caption_body, CAPTION_CORNER_W, 0, |
- | |
150 | // w, CAPTION_HEIGHT, 0); |
- | |
151 | - | ||
152 | }; |
- | |
153 | 134 | ||
154 | - | ||
155 | blit_raw(&cpt->ctx,res_caption_right, cpt->ctrl.w - CAPTION_CORNER_W, 0, |
135 | blit_raw(ctx,res_caption_right, cpt->ctrl.w - CAPTION_CORNER_W, 0, |
156 | CAPTION_CORNER_W, CAPTION_HEIGHT,CAPTION_CORNER_W*4); |
136 | CAPTION_CORNER_W, CAPTION_HEIGHT,CAPTION_CORNER_W*4); |
157 | 137 | ||
158 | rc.l = 8; |
138 | rc.l = 8; |
159 | rc.t = 0; |
139 | rc.t = 0; |
160 | rc.r = cpt->ctrl.w - 27 - 18 - 18 - 5 - 5 - 8; |
140 | rc.r = cpt->ctrl.w - 27 - 18 - 18 - 5 - 5 - 8; |
161 | rc.b = 18; |
141 | rc.b = 18; |
162 | 142 | ||
163 | draw_text_ext(cpt->ctx.pixmap, win_font, cpt->text, &rc, 0xFFFFFFFF); |
143 | draw_text_ext(ctx->pixmap_data, ctx->pixmap_pitch, win_font, cpt->text, &rc, 0xFFFFFFFF); |
164 | 144 | ||
165 | ctrl_t *child; |
145 | ctrl_t *child; |
166 | child = (ctrl_t*)cpt->ctrl.child.next; |
146 | child = (ctrl_t*)cpt->ctrl.child.next; |
167 | 147 | ||
168 | while( &child->link != &cpt->ctrl.child) |
148 | while( &child->link != &cpt->ctrl.child) |
169 | { |
149 | { |
170 | send_message(child, 1, 0, 0); |
150 | send_message(child, 1, 0, 0); |
171 | child = (ctrl_t*)child->link.next; |
151 | child = (ctrl_t*)child->link.next; |
172 | }; |
152 | }; |
173 | }; |
153 | }; |
174 | 154 | ||
175 | 155 | ||
176 | int caption_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
156 | int caption_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2) |
177 | { |
157 | { |
178 | caption_t *cpt = (caption_t*)ctrl; |
158 | caption_t *cpt = (caption_t*)ctrl; |
179 | window_t *win = (window_t*)ctrl->parent; |
159 | window_t *win = (window_t*)ctrl->parent; |
180 | 160 | ||
181 | ctrl_t *child; |
161 | ctrl_t *child; |
182 | int x, y; |
162 | int x, y; |
183 | 163 | ||
184 | x = ((pos_t)arg2).x; |
164 | x = ((pos_t)arg2).x; |
185 | y = ((pos_t)arg2).y; |
165 | y = ((pos_t)arg2).y; |
186 | 166 | ||
187 | switch( msg ) |
167 | switch( msg ) |
188 | { |
168 | { |
189 | case 1: |
169 | case 1: |
190 | break; |
170 | break; |
191 | 171 | ||
192 | 172 | ||
193 | case MSG_MOUSEMOVE: |
173 | case MSG_MOUSEMOVE: |
194 | child = get_child(ctrl, x, y); |
174 | child = get_child(ctrl, x, y); |
195 | if( win->child_over ) |
175 | if( win->child_over ) |
196 | { |
176 | { |
197 | if(child == win->child_over) |
177 | if(child == win->child_over) |
198 | send_message(child, msg, 0, arg2); |
178 | send_message(child, msg, 0, arg2); |
199 | else |
179 | else |
200 | send_message(win->child_over, MSG_MOUSELEAVE, 0, arg2); |
180 | send_message(win->child_over, MSG_MOUSELEAVE, 0, arg2); |
201 | }; |
181 | }; |
202 | 182 | ||
203 | win->child_over = child; |
183 | win->child_over = child; |
204 | if( child ) |
184 | if( child ) |
205 | { |
185 | { |
206 | send_message(child, MSG_MOUSEENTER, 0, arg2); |
186 | send_message(child, MSG_MOUSEENTER, 0, arg2); |
207 | send_message(child,msg,0,arg2); |
187 | send_message(child,msg,0,arg2); |
208 | } |
188 | } |
209 | else if(main_cursor != 0) |
189 | else if(main_cursor != 0) |
210 | { |
190 | { |
211 | set_cursor(0); |
191 | set_cursor(0); |
212 | main_cursor = 0; |
192 | main_cursor = 0; |
213 | } |
193 | } |
214 | break; |
194 | break; |
215 | 195 | ||
216 | 196 | ||
217 | case MSG_COMMAND: |
197 | case MSG_COMMAND: |
218 | switch((short)arg1) |
198 | switch((short)arg1) |
219 | { |
199 | { |
220 | case ID_CLOSE: |
200 | case ID_CLOSE: |
221 | win->win_command = WIN_CLOSED; |
201 | win->win_command = WIN_CLOSED; |
222 | break; |
202 | break; |
223 | 203 | ||
224 | case ID_MINIMIZE: |
204 | case ID_MINIMIZE: |
225 | __asm__ __volatile__( |
205 | __asm__ __volatile__( |
226 | "int $0x40" |
206 | "int $0x40" |
227 | ::"a"(18),"b"(10)); |
207 | ::"a"(18),"b"(10)); |
228 | win->win_state = MINIMIZED; |
208 | win->win_state = MINIMIZED; |
229 | send_message((ctrl_t*)win, MSG_SIZE, 0, 0); |
209 | send_message((ctrl_t*)win, MSG_SIZE, 0, 0); |
230 | break; |
210 | break; |
231 | case ID_FULLSCREEN: |
211 | case ID_FULLSCREEN: |
232 | { |
212 | { |
233 | int screensize; |
213 | int screensize; |
234 | 214 | ||
235 | win->saved = win->rc; |
215 | win->saved = win->rc; |
236 | win->saved_state = win->win_state; |
216 | win->saved_state = win->win_state; |
237 | screensize = GetScreenSize(); |
217 | screensize = GetScreenSize(); |
238 | __asm__ __volatile__( |
218 | __asm__ __volatile__( |
239 | "int $0x40" |
219 | "int $0x40" |
240 | ::"a"(67), "b"(0), "c"(0), |
220 | ::"a"(67), "b"(0), "c"(0), |
241 | "d"((screensize >> 16)-1),"S"((screensize & 0xFFFF)-1) ); |
221 | "d"((screensize >> 16)-1),"S"((screensize & 0xFFFF)-1) ); |
242 | win->win_state = FULLSCREEN; |
222 | win->win_state = FULLSCREEN; |
243 | window_update_layout(win); |
223 | window_update_layout(win); |
244 | }; |
224 | }; |
245 | break; |
225 | break; |
246 | 226 | ||
247 | default: |
227 | default: |
248 | break; |
228 | break; |
249 | }; |
229 | }; |
250 | 230 | ||
251 | default: |
231 | default: |
252 | child = get_child(ctrl, x, y); |
232 | child = get_child(ctrl, x, y); |
253 | if(child) |
233 | if(child) |
254 | return send_message(child, msg, 0, arg2); |
234 | return send_message(child, msg, 0, arg2); |
255 | } |
235 | } |
256 | return 1; |
236 | return 1; |
257 | }; |
237 | }; |
258 | 238 | ||
259 | 239 | ||
260 | 240 | ||
261 | void blit_caption(caption_t *cpt) |
241 | void blit_caption(caption_t *cpt) |
262 | { |
242 | { |
263 | // printf("%s w:%d h:%d stride: %d\n",__FUNCTION__, |
243 | // printf("%s w:%d h:%d stride: %d\n",__FUNCTION__, |
264 | // cpt->ctrl.w, cpt->ctrl.h, cpt->ctx.stride); |
244 | // cpt->ctrl.w, cpt->ctrl.h, cpt->ctx.stride); |
265 | 245 | ||
266 | lock_bitmap(&cpt->bitmap); |
- | |
267 | 246 | ||
268 | Blit(cpt->ctx.pixmap->data, 0, 0, 0, 0, cpt->ctrl.w, cpt->ctrl.h, |
247 | Blit(cpt->ctx.pixmap_data, 0, 0, 0, 0, cpt->ctrl.w, cpt->ctrl.h, |
269 | cpt->ctrl.w, cpt->ctrl.h, cpt->ctx.pixmap->pitch); |
248 | cpt->ctrl.w, cpt->ctrl.h, cpt->ctx.pixmap_pitch); |
270 | };>> |
249 | };>> |