Rev 1157 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1157 | andrew_pro | 1 | /* |
2 | control ProgressBar |
||
3 | */ |
||
4 | |||
5 | void ProgressBarDrawProgress(struct ControlProgressBar *ProgressBar) |
||
6 | { |
||
7 | int x; |
||
8 | int y; |
||
9 | int pos_progress; |
||
10 | int sizex; |
||
11 | int sizey; |
||
12 | char v; |
||
13 | struct FINITION *fin; |
||
14 | gui_message_t message; |
||
15 | gui_text_size_t size; |
||
16 | gui_text_t *Text; |
||
17 | |||
18 | if ((ProgressBar->flags & FLAG_SHOW_CONTROL)==FALSE) return; |
||
19 | |||
20 | x=ProgressBar->ctrl_x; |
||
21 | y=ProgressBar->ctrl_y; |
||
22 | sizex=ProgressBar->ctrl_sizex; |
||
23 | sizey=ProgressBar->ctrl_sizey; |
||
24 | fin=(struct FINITION*)ProgressBar->finition; |
||
25 | |||
26 | if (ProgressBar->progress<0.0) ProgressBar->progress=0.0; |
||
27 | if (ProgressBar->progress>1.0) ProgressBar->progress=1.0; |
||
28 | |||
29 | v=ProgressBar->prb_flags & FLAG_PB_HORIZONTAL_ORIENTATION_ON; |
||
30 | if (v!=FALSE) |
||
31 | { |
||
32 | pos_progress=(int)(ProgressBar->progress*(sizex-2)); |
||
33 | |||
34 | if (ProgressBar->prb_flags & FLAG_PB_FROM_LEFT_TO_RIGHT_ON) |
||
35 | { |
||
36 | Draw(fin,TOOL_GRADIENT_UP_FILLED_RECTANGLE,x+1,y+1,pos_progress,sizey-2,COLOR_FON,COLOR_MIDDLE_LIGHT); |
||
37 | Draw(fin,TOOL_GRADIENT_UP_FILLED_RECTANGLE,x+1+pos_progress,y+1,sizex-2-pos_progress, |
||
38 | sizey-2,COLOR_MIDDLE_LIGHT,COLOR_LIGHT); |
||
39 | if (ProgressBar->prb_flags & FLAG_PB_TEXT_ON) |
||
40 | { |
||
41 | if (fin->flags & FINITION_ON) |
||
42 | { |
||
43 | message.type=MESSAGE_FULL_REDRAW_ALL_WITH_FINITION; |
||
44 | message.arg1=fin->x; |
||
45 | message.arg2=fin->y; |
||
46 | message.arg3=fin->sizex; |
||
47 | message.arg4=fin->sizey; |
||
48 | } |
||
49 | else |
||
50 | { |
||
51 | message.type=MESSAGE_FULL_REDRAW_ALL; |
||
52 | } |
||
53 | Text=(gui_text_t*)ProgressBar->child_bk; |
||
54 | size=GetStringSize((font_t*)Text->font,Text->text); |
||
55 | Text->ctrl_sizex=(DWORD)size.sizex; |
||
56 | Text->ctrl_sizey=(DWORD)size.sizey; |
||
57 | Text->ctrl_x=x+(sizex/2)-(Text->ctrl_sizex/2); |
||
58 | Text->ctrl_y=y+(sizey/2)-(Text->ctrl_sizey/2); |
||
59 | |||
60 | SendMessage((struct HEADER*)ProgressBar,&message); |
||
61 | } |
||
62 | } |
||
63 | |||
64 | if (ProgressBar->prb_flags & FLAG_PB_FROM_RIGHT_TO_LEFT_ON) |
||
65 | { |
||
66 | //Draw(fin,"filled_rectangle",x+sizex-pos_progress-1,y+1,x+sizex-1,sizey-2,0xff0000); |
||
67 | } |
||
68 | |||
69 | } |
||
70 | } |
||
71 | |||
72 | void DrawProgressBar(struct ControlProgressBar *ProgressBar) |
||
73 | { |
||
1163 | andrew_pro | 74 | int x,y,sizex,sizey; |
75 | char c; |
||
76 | char *save_buf,*buf; |
||
77 | int save_size_x,save_size_y; |
||
78 | DWORD draw_output,flags; |
||
79 | finition_t *fin; |
||
1157 | andrew_pro | 80 | |
81 | x=ProgressBar->ctrl_x; |
||
82 | y=ProgressBar->ctrl_y; |
||
83 | sizex=ProgressBar->ctrl_sizex; |
||
84 | sizey=ProgressBar->ctrl_sizey; |
||
85 | fin=(struct FINITION*)ProgressBar->finition; |
||
86 | |||
1163 | andrew_pro | 87 | //alocate a buffer for draw text |
88 | c=screen.bits_per_pixel >> 3; |
||
89 | buf=malloc(sizex*sizey*c); |
||
90 | |||
91 | //save current screen parameters |
||
92 | save_buf=screen.buffer; |
||
93 | save_size_x=screen.size_x; |
||
94 | save_size_y=screen.size_y; |
||
95 | draw_output=screen.draw_output; |
||
96 | |||
97 | //load parameters of local buffer |
||
98 | screen.buffer=buf; |
||
99 | screen.size_x=sizex; |
||
100 | screen.size_y=sizey; |
||
101 | screen.draw_output=DRAW_OUTPUT_BUFFER; |
||
102 | |||
103 | //move control |
||
104 | SetControlNewPosition(ProgressBar,0,0); |
||
105 | //save finition parameters |
||
106 | flags=fin->flags; |
||
107 | fin->flags &=FINITION_OFF; |
||
108 | |||
109 | //draw progress bar in buffer |
||
110 | Draw(fin,TOOL_RECTANGLE,0,0,sizex,sizey,COLOR_ABSOLUTE_DARK); |
||
1157 | andrew_pro | 111 | ProgressBarDrawProgress(ProgressBar); |
1163 | andrew_pro | 112 | |
113 | //restore last position of control |
||
114 | SetControlNewPosition(ProgressBar,x,y); |
||
115 | //restore finition |
||
116 | fin->flags=flags; |
||
117 | |||
118 | //restore screen parameters |
||
119 | screen.buffer=save_buf; |
||
120 | screen.size_x=save_size_x; |
||
121 | screen.size_y=save_size_y; |
||
122 | screen.draw_output=draw_output; |
||
123 | |||
124 | //move rendered objects from local buffer to screen |
||
125 | if (fin->flags & FINITION_ON) |
||
126 | DrawImageFinit(fin,x,y,sizex,sizey,screen.bits_per_pixel,buf); |
||
127 | else |
||
128 | DrawImage(x,y,sizex,sizey,screen.bits_per_pixel,buf); |
||
129 | |||
130 | //free local buffer |
||
131 | free(buf); |
||
1157 | andrew_pro | 132 | } |
133 | |||
134 | void SetProgressBarPulse(struct ControlProgressBar *ProgressBar,int time_tick) |
||
135 | { |
||
136 | struct TIMER *timer; |
||
137 | struct HEADERPARENT *main_parent; |
||
138 | |||
139 | main_parent=(struct HEADERPARENT*)ProgressBar->main_parent; |
||
140 | if (main_parent!=(struct HEADERPARENT*)NULL) |
||
141 | { |
||
142 | main_parent->number_timers_for_controls++; |
||
143 | |||
1163 | andrew_pro | 144 | ProgressBar->timer=(DWORD*)SetTimerCallbackForControl(time_tick,&DrawProgressBar,ProgressBar); |
1157 | andrew_pro | 145 | timer=(struct TIMER*)ProgressBar->timer; |
146 | timer->flags=timer->flags | FLAG_TIMER_ON; |
||
147 | } |
||
148 | } |
||
149 | |||
150 | //--------------------------------------------------------------------------------- |
||
151 | // control ProgressBar |
||
152 | //--------------------------------------------------------------------------------- |
||
153 | void ProgressBarProc(struct ControlProgressBar *ProgressBar,struct MESSAGE *message) |
||
154 | { |
||
155 | int btn_state; |
||
156 | char v; |
||
157 | struct TIMER *timer; |
||
158 | struct FINITION *fin; |
||
159 | |||
160 | switch(message->type) |
||
161 | { |
||
162 | case MESSAGE_FULL_REDRAW_ALL: |
||
163 | { |
||
164 | //draw ProgressBar |
||
165 | if (ProgressBar->flags & FLAG_SHOW_CONTROL) DrawProgressBar(ProgressBar); |
||
166 | break; |
||
167 | } |
||
168 | case MESSAGE_FULL_REDRAW_ALL_WITH_FINITION: |
||
169 | { |
||
170 | fin=(struct FINITION*)ProgressBar->finition; |
||
171 | fin->flags=fin->flags | FINITION_ON; |
||
172 | fin->x=message->arg1; |
||
173 | fin->y=message->arg2; |
||
174 | fin->sizex=message->arg3; |
||
175 | fin->sizey=message->arg4; |
||
176 | DrawProgressBar(ProgressBar); |
||
177 | break; |
||
178 | } |
||
179 | case MESSAGE_SPECIALIZED: |
||
180 | { //redraw bar of progress |
||
181 | if (ProgressBar->flags & FLAG_GET_SPECIALIZED_MESSAGE_ON) |
||
182 | { |
||
183 | if (ProgressBar->flags & FLAG_SHOW_CONTROL) ProgressBarDrawProgress(ProgressBar); |
||
184 | ProgressBar->flags=ProgressBar->flags & FLAG_GET_SPECIALIZED_MESSAGE_OFF; |
||
185 | } |
||
186 | break; |
||
187 | } |
||
188 | case MESSAGE_CHANGE_POSITION_EVENT: |
||
189 | { |
||
190 | ProgressBar->ctrl_x=ProgressBar->ctrl_x+message->arg1; |
||
191 | ProgressBar->ctrl_y=ProgressBar->ctrl_y+message->arg2; |
||
1163 | andrew_pro | 192 | SendMessage((struct HEADER*)ProgressBar,message); |
1157 | andrew_pro | 193 | break; |
194 | } |
||
195 | case MESSAGE_CALL_TIMER_EVENT: |
||
196 | { |
||
197 | if (ProgressBar->timer!=(DWORD*)NULL) |
||
198 | { |
||
199 | timer=(struct TIMER*)ProgressBar->timer; |
||
200 | if (timer->flags & FLAG_TIMER_ON) Timer(timer); |
||
201 | } |
||
1163 | andrew_pro | 202 | SendMessage((struct HEADER*)ProgressBar,message); |
1157 | andrew_pro | 203 | break; |
204 | } |
||
205 | case MESSAGE_DESTROY_CONTROL: |
||
206 | { |
||
207 | if (ProgressBar->timer!=(DWORD*)NULL) free(ProgressBar->timer); |
||
208 | free(ProgressBar->finition); |
||
1163 | andrew_pro | 209 | SendMessage((struct HEADER*)ProgressBar,message); |
1157 | andrew_pro | 210 | break; |
211 | } |
||
212 | case MESSAGE_SET_MAIN_PARENT: |
||
213 | { |
||
214 | SendMessage((struct HEADER*)ProgressBar,message); |
||
215 | ProgressBar->main_parent=(DWORD*)message->arg1; |
||
1163 | andrew_pro | 216 | SendMessage((struct HEADER*)ProgressBar,message); |
1157 | andrew_pro | 217 | break; |
218 | } |
||
219 | |||
220 | default: break; |
||
221 | } |
||
222 | } |
||
223 | |||
224 | //--------------------------------------------------------------------------------- |
||
225 | // create control ProgressBar |
||
226 | //--------------------------------------------------------------------------------- |
||
227 | void* CreateProgressBarEmpty(struct ProgressBarData *info_for_control) |
||
228 | { |
||
229 | struct ControlProgressBar *ProgressBar; |
||
230 | struct FINITION *fin; |
||
231 | |||
232 | ProgressBar=malloc(sizeof(struct ControlProgressBar)); |
||
233 | ProgressBar->finition=malloc(sizeof(struct FINITION)); |
||
234 | fin=(struct FINITION*)ProgressBar->finition; |
||
235 | fin->flags=0; |
||
236 | |||
237 | ID++; |
||
238 | #ifdef DEBUG |
||
239 | printf("\ncreated progress bar with ID=%d",(int)ID); |
||
240 | #endif |
||
241 | ProgressBar->child_bk=(DWORD*)NULL; |
||
242 | ProgressBar->child_fd=(DWORD*)NULL; |
||
243 | ProgressBar->active_control_for_keys=(DWORD*)NULL; |
||
244 | ProgressBar->active_control_for_mouse=(DWORD*)NULL; |
||
245 | ProgressBar->callback=(DWORD*)NULL; |
||
246 | ProgressBar->timer=(DWORD*)NULL; |
||
247 | ProgressBar->ctrl_proc=(DWORD*)&ProgressBarProc; |
||
248 | ProgressBar->ctrl_x=(DWORD)info_for_control->x; |
||
249 | ProgressBar->ctrl_y=(DWORD)info_for_control->y; |
||
250 | ProgressBar->ctrl_sizex=(DWORD)info_for_control->width; |
||
251 | ProgressBar->ctrl_sizey=(DWORD)info_for_control->height; |
||
252 | ProgressBar->ctrl_ID=ID; |
||
253 | ProgressBar->progress=info_for_control->progress; |
||
254 | ProgressBar->flags=0; |
||
255 | ProgressBar->flags=ProgressBar->flags | FLAG_SHOW_CONTROL; |
||
256 | |||
257 | ProgressBar->prb_flags=0; |
||
258 | ProgressBar->prb_flags=ProgressBar->prb_flags | FLAG_PB_HORIZONTAL_ORIENTATION_ON; |
||
259 | ProgressBar->prb_flags=ProgressBar->prb_flags | FLAG_PB_FROM_LEFT_TO_RIGHT_ON; |
||
260 | |||
261 | return(ProgressBar); |
||
262 | } |
||
263 | |||
264 | void* CreateProgressBar(gui_progress_bar_data_t *info) |
||
265 | { |
||
266 | gui_text_t *text; |
||
267 | gui_text_data_t txtdata; |
||
268 | gui_progress_bar_t *pbar; |
||
269 | |||
270 | pbar=CreateProgressBarEmpty(info); |
||
271 | |||
272 | txtdata.x=0; |
||
273 | txtdata.y=0; |
||
274 | txtdata.font=NULL; |
||
275 | txtdata.background=FALSE; |
||
276 | txtdata.color=0; |
||
277 | txtdata.text=malloc(1024); |
||
278 | txtdata.text[0]=0; |
||
279 | text=CreateText(&txtdata); |
||
280 | |||
281 | text->ctrl_x=(pbar->ctrl_sizex/2)-(text->ctrl_sizex/2); |
||
282 | text->ctrl_y=(pbar->ctrl_sizey/2)-(text->ctrl_sizey/2); |
||
283 | PackControls(pbar,text); |
||
284 | |||
285 | text->flags &=FLAG_HIDE_CONTROL; |
||
286 | |||
287 | return(pbar); |
||
288 | } |
||
289 | |||
290 | void ProgressBarSetText(gui_progress_bar_t *pbar,char *txt) |
||
291 | { |
||
292 | gui_text_t *text; |
||
293 | |||
294 | text=(gui_text_t*)pbar->child_bk; |
||
295 | |||
296 | if (*txt!='\0') |
||
297 | { |
||
298 | pbar->prb_flags|=FLAG_PB_TEXT_ON; |
||
299 | memmove(text->text,txt,strlen(txt)); |
||
300 | text->flags |=FLAG_SHOW_CONTROL; |
||
301 | } |
||
302 | } |
||
303 | |||
304 | char *ProgressBarGetText(gui_progress_bar_t *pbar) |
||
305 | { |
||
306 | gui_text_t *text; |
||
307 | |||
308 | text=(gui_text_t*)pbar->child_bk; |
||
309 | |||
310 | return(text->text); |
||
311 | }0.0)> |