OSDN Git Service

AI003:config.txt, words.txtを追加。
[chnosproject/CHNOSProject.git] / CHNOSProject / chnos / tolset_chn_000 / chnos_009 / chnos / sheet.c
1 \r
2 #include "core.h"\r
3 \r
4 extern IO_MemoryControl sys_mem_ctrl;\r
5 \r
6 UI_Sheet_Control sys_sheet_ctrl;\r
7 \r
8 void Sheet_Initialise(UI_Sheet_Control *sheetctrl, IO_MemoryControl *memctrl, void *vram, uint xsize, uint ysize, uint bpp)\r
9 {\r
10         uint x, y;\r
11 \r
12         sheetctrl->memctrl = memctrl;\r
13 \r
14         sheetctrl->mainvram = vram;\r
15         sheetctrl->map = MemoryBlock_Allocate_User(xsize * ysize * 4, sheetctrl->memctrl);\r
16         MemoryBlock_Write_Description(sheetctrl->map, "SHTCTRL_MAP");\r
17         for(y = 0; y < ysize; y++){\r
18                 for(x = 0; x < xsize; x++){\r
19                         sheetctrl->map[(y * xsize) + x] = 0;\r
20                 }\r
21         }\r
22         sheetctrl->mainvramsize.x = xsize;\r
23         sheetctrl->mainvramsize.y = ysize;\r
24         sheetctrl->mainvrambpp = bpp;\r
25 \r
26         sheetctrl->base.vram = 0;\r
27         sheetctrl->base.position.x = 0;\r
28         sheetctrl->base.position.y = 0;\r
29         sheetctrl->base.size.x = 0;\r
30         sheetctrl->base.size.y = 0;\r
31         sheetctrl->base.bpp = 0;\r
32         sheetctrl->base.invcol = 0;\r
33         sheetctrl->base.next = 0;\r
34         sheetctrl->base.before = 0;\r
35         sheetctrl->base.Refresh = 0;\r
36         sheetctrl->base.WriteMap = 0;\r
37         sheetctrl->base.visible = false;\r
38         sheetctrl->base.mouse_movable = false;\r
39         sheetctrl->base.myctrl = sheetctrl;\r
40         sheetctrl->base.fifo = 0;\r
41         sheetctrl->base.msignal_flags = 0;\r
42         sheetctrl->base.ksignal_flags = 0;\r
43 \r
44         sheetctrl->sheets = 0;\r
45         return;\r
46 }\r
47 \r
48 UI_Sheet *Sheet_Get(UI_Sheet_Control *ctrl, uint xsize, uint ysize, uint bpp, uint invcol)\r
49 {\r
50         UI_Sheet *sheet;\r
51 \r
52         if(bpp == 0){\r
53                 bpp = ctrl->mainvrambpp;\r
54         }\r
55 \r
56         sheet = MemoryBlock_Allocate_User(sizeof(UI_Sheet), ctrl->memctrl);\r
57         MemoryBlock_Write_Description(sheet, "UI_Sheet");\r
58         sheet->vram = MemoryBlock_Allocate_User(xsize * ysize * (bpp >> 3), ctrl->memctrl);\r
59         MemoryBlock_Write_Description(sheet->vram, "UI_Sheet_VRAM");\r
60         sheet->position.x = 0;\r
61         sheet->position.y = 0;\r
62         sheet->size.x = xsize;\r
63         sheet->size.y = ysize;\r
64         sheet->bpp = bpp;\r
65         sheet->invcol = invcol;\r
66         if(sheet->invcol == 0){\r
67                 sheet->WriteMap = Sheet_Write_Map_NoInvisible;\r
68         } else if(sheet->bpp == 32){\r
69                 sheet->WriteMap = Sheet_Write_Map_32;\r
70         } else if(sheet->bpp == 16){\r
71                 sheet->WriteMap = Sheet_Write_Map_16;\r
72                 sheet->invcol = RGB_32_To_16(sheet->invcol);\r
73         } else if(sheet->bpp == 8){\r
74                 sheet->WriteMap = Sheet_Write_Map_08;\r
75                 sheet->invcol = RGB_32_To_08(sheet->invcol);\r
76         }\r
77         sheet->next = 0;\r
78         sheet->before = 0;\r
79 \r
80         sheet->Refresh = Sheet_Refresh_Invalid;\r
81         sheet->myctrl = ctrl;\r
82 \r
83         sheet->visible = false;\r
84         sheet->mouse_movable = false;\r
85         sheet->MouseEventProcedure = 0;\r
86         sheet->fifo = 0;\r
87         sheet->msignal_flags = 0;\r
88         sheet->ksignal_flags = 0;\r
89 \r
90         return sheet;\r
91 }\r
92 \r
93 uint Sheet_Show(UI_Sheet *sheet, int px, int py, uint height)\r
94 {\r
95         uint i;\r
96         UI_Sheet *now;\r
97         UI_Sheet_Control *ctrl;\r
98         uint eflags;\r
99 \r
100         eflags = IO_Load_EFlags();\r
101         IO_CLI();\r
102 \r
103         ctrl = sheet->myctrl;\r
104 \r
105         now = &ctrl->base;\r
106         for(i = 0; i <= height; i++){\r
107                 if(now->next == 0){\r
108                         break;\r
109                 }\r
110                 if(i == height){\r
111                         break;\r
112                 }\r
113                 now = now->next;\r
114         }\r
115         now->next->before = sheet;\r
116         sheet->next = now->next;\r
117         sheet->before = now;\r
118         now->next = sheet;\r
119 \r
120         ctrl->sheets++;\r
121         sheet->position.x = px;\r
122         sheet->position.y = py;\r
123         sheet->visible = true;\r
124 \r
125         if(ctrl->mainvrambpp == 32){\r
126                 if(sheet->bpp == 32){\r
127                         sheet->Refresh = Sheet_Refresh_32from32;\r
128 //              } else if(sheet->bpp == 16){\r
129 \r
130 //              } else if(sheet->bpp == 8){\r
131 \r
132                 }\r
133         } else if(ctrl->mainvrambpp == 16){\r
134                 if(sheet->bpp == 32){\r
135                         sheet->Refresh = Sheet_Refresh_16from32;\r
136                 } else if(sheet->bpp == 16){\r
137                         sheet->Refresh = Sheet_Refresh_16from16;\r
138 //              } else if(sheet->bpp == 8){\r
139 \r
140                 }\r
141         } else if(ctrl->mainvrambpp == 8){\r
142                 if(sheet->bpp == 32){\r
143                         sheet->Refresh = Sheet_Refresh_08from32;\r
144 //              } else if(sheet->bpp == 16){\r
145 \r
146                 } else if(sheet->bpp == 8){\r
147                         sheet->Refresh = Sheet_Refresh_08from08;\r
148                 }\r
149         }\r
150         IO_Store_EFlags(eflags);\r
151 \r
152         Sheet_Refresh_Map(sheet, sheet->position.x, sheet->position.y, sheet->position.x + sheet->size.x - 1, sheet->position.y + sheet->size.y - 1);\r
153         sheet->Refresh(sheet, 0, 0, sheet->size.x - 1, sheet->size.y - 1);\r
154 \r
155         return i;\r
156 }\r
157 \r
158 void Sheet_Set_Movable(UI_Sheet *sheet, bool movable)\r
159 {\r
160         sheet->mouse_movable = movable;\r
161         return;\r
162 }\r
163 \r
164 void Sheet_Set_MouseEventProcedure(UI_Sheet *sheet, void (*procedure)(UI_MouseEventArguments *e), uint flags)\r
165 {\r
166         sheet->MouseEventProcedure = procedure;\r
167         sheet->msignal_flags = flags;\r
168         return;\r
169 }\r
170 \r
171 void Sheet_Set_FIFO(UI_Sheet *sheet, DATA_FIFO *fifo, uint flags)\r
172 {\r
173         sheet->fifo = fifo;\r
174         sheet->ksignal_flags = flags;\r
175         return;\r
176 }\r
177 \r
178 void Sheet_Slide(UI_Sheet *sheet, int px, int py)\r
179 {\r
180         int movex, movey;\r
181         DATA_Position2D target0, target1;\r
182         UI_Sheet_Control *ctrl;\r
183 \r
184         ctrl = sheet->myctrl;\r
185         movex = px - sheet->position.x;\r
186         movey = py - sheet->position.y;\r
187 \r
188         if(movex == 0 && movey == 0){   //\93®\82©\82È\82¢\r
189                 return;\r
190         }\r
191         if(movey == 0){ //\89¡\82É\83X\83\89\83C\83h\82·\82é\82¾\82¯\r
192                 target0.y = sheet->position.y;\r
193                 target1.y = sheet->position.y + sheet->size.y - 1;\r
194                 if(movex > 0){  //\89E\95û\8cü\r
195                         target0.x = sheet->position.x;\r
196                         target1.x = sheet->position.x + sheet->size.x - 1 + movex;\r
197                 } else{ //\8d\95û\8cü\r
198                         target0.x = sheet->position.x + movex;\r
199                         target1.x = sheet->position.x + sheet->size.x - 1;\r
200                 }\r
201         } else if(movex == 0){  //\8fc\82É\83X\83\89\83C\83h\82·\82é\82¾\82¯\r
202                 target0.x = sheet->position.x;\r
203                 target1.x = sheet->position.x + sheet->size.x - 1;\r
204                 if(movey > 0){  //\89º\95û\8cü\r
205                         target0.y = sheet->position.y;\r
206                         target1.y = sheet->position.y + sheet->size.y - 1 + movey;\r
207                 } else{ //\8fã\95û\8cü\r
208                         target0.y = sheet->position.y + movey;\r
209                         target1.y = sheet->position.y + sheet->size.y - 1;\r
210                 }\r
211         } else if(movex > 0 && movey > 0){      //\89E\89º\82Ö\83X\83\89\83C\83h\r
212                 target0.x = sheet->position.x;\r
213                 target0.y = sheet->position.y;\r
214                 target1.x = sheet->position.x + sheet->size.x - 1 + movex;\r
215                 target1.y = sheet->position.y + sheet->size.y - 1 + movey;\r
216         } else if(movex > 0 && movey < 0){      //\89E\8fã\82Ö\83X\83\89\83C\83h\r
217                 target0.x = sheet->position.x;\r
218                 target0.y = sheet->position.y + movey;\r
219                 target1.x = sheet->position.x + sheet->size.x - 1 + movex;\r
220                 target1.y = sheet->position.y + sheet->size.y - 1;\r
221         } else if(movex < 0 && movey > 0){      //\8d\89º\82Ö\83X\83\89\83C\83h\r
222                 target0.x = sheet->position.x + movex;\r
223                 target0.y = sheet->position.y;\r
224                 target1.x = sheet->position.x + sheet->size.x - 1;\r
225                 target1.y = sheet->position.y + sheet->size.y - 1 + movey;\r
226         } else if(movex < 0 && movey < 0){      //\8d\8fã\82Ö\83X\83\89\83C\83h\r
227                 target0.x = sheet->position.x + movex;\r
228                 target0.y = sheet->position.y + movey;\r
229                 target1.x = sheet->position.x + sheet->size.x - 1;\r
230                 target1.y = sheet->position.y + sheet->size.y - 1;\r
231         }\r
232 \r
233         sheet->visible = false;\r
234         Sheet_Refresh_Map(sheet, sheet->position.x, sheet->position.y, sheet->position.x + sheet->size.x - 1, sheet->position.y + sheet->size.y - 1);\r
235         sheet->position.x = px;\r
236         sheet->position.y = py;\r
237         sheet->visible = true;\r
238         Sheet_Refresh_Map(sheet, sheet->position.x, sheet->position.y, sheet->position.x + sheet->size.x - 1, sheet->position.y + sheet->size.y - 1);\r
239         Sheet_Refresh_All(ctrl->base.next, sheet->next, target0.x, target0.y, target1.x, target1.y);\r
240         return;\r
241 }\r
242 \r
243 uint Sheet_UpDown(UI_Sheet *sheet, uint height)\r
244 {\r
245         uint i;\r
246         UI_Sheet *now;\r
247 \r
248         if(sheet->before == 0){\r
249                 return 0;\r
250         }\r
251 \r
252         now = &sheet->myctrl->base;\r
253 \r
254         for(i = 0; now != sheet; i++){\r
255                 now = now->next;\r
256         }\r
257         if(i == height){\r
258                 return i;\r
259         }\r
260         Sheet_Remove(sheet);\r
261         return Sheet_Show(sheet, sheet->position.x, sheet->position.y, height - 1);\r
262 }\r
263 \r
264 void Sheet_Remove(UI_Sheet *sheet)\r
265 {\r
266         UI_Sheet_Control *ctrl;\r
267         uint eflags;\r
268 \r
269         eflags = IO_Load_EFlags();\r
270         IO_CLI();\r
271 \r
272         ctrl = sheet->myctrl;\r
273 \r
274         ctrl->sheets--;\r
275         sheet->visible = false;\r
276         Sheet_Refresh_Map(sheet, sheet->position.x, sheet->position.y, sheet->position.x + sheet->size.x - 1, sheet->position.y + sheet->size.y - 1);\r
277         sheet->before->next = sheet->next;\r
278         sheet->next->before = sheet->before;\r
279         Sheet_Refresh_All(ctrl->base.next, sheet->next, sheet->position.x, sheet->position.y, sheet->position.x + sheet->size.x - 1, sheet->position.y + sheet->size.y - 1);\r
280         sheet->next = 0;\r
281         sheet->before = 0;\r
282 \r
283         IO_Store_EFlags(eflags);\r
284         return;\r
285 }\r
286 \r
287 void Sheet_Refresh_Map(UI_Sheet *sheet, int x0, int y0, int x1, int y1)\r
288 {\r
289         UI_Sheet **before;\r
290         uint i, x, y;\r
291         DATA_Position2D target0, target1;\r
292         UI_Sheet_Control *ctrl;\r
293 \r
294         ctrl = sheet->myctrl;\r
295         if(x0 >= ctrl->mainvramsize.x || y0 >= ctrl->mainvramsize.y || x1 < 0 || y1 < 0){\r
296                 return;\r
297         }\r
298         if(x0 < 0){\r
299                 x0 = 0;\r
300         }\r
301         if(y0 < 0){\r
302                 y0 = 0;\r
303         }\r
304         if(x1 >= ctrl->mainvramsize.x){\r
305                 x1 = ctrl->mainvramsize.x - 1;\r
306         }\r
307         if(y1 >= ctrl->mainvramsize.y){\r
308                 y1 = ctrl->mainvramsize.y - 1;\r
309         }\r
310 \r
311         before = &ctrl->base.next;\r
312         for(i = 0; i < ctrl->sheets; i++){\r
313                 for(y = y0; y <= y1; y++){\r
314                         for(x = x0; x <= x1; x++){\r
315                                 if(ctrl->map[(y * ctrl->mainvramsize.x) + x] == (uint)*before){\r
316                                         ctrl->map[(y * ctrl->mainvramsize.x) + x] = 0;\r
317                                 }\r
318                         }\r
319                 }\r
320                 if(*before == sheet){\r
321                         break;\r
322                 }\r
323                 before = &(*before)->next;\r
324         }\r
325 \r
326         i++;\r
327 \r
328         for(; i > 0; i--){\r
329                 target0.x = (*before)->position.x;\r
330                 target0.y = (*before)->position.y;\r
331                 target1.x = (*before)->position.x + (*before)->size.x - 1;\r
332                 target1.y = (*before)->position.y + (*before)->size.y - 1;\r
333 \r
334                 if(target0.x <= x1 && target0.y <= y1 && target1.x >= x0 && target1.y >= y0 && (*before)->visible){\r
335                         if(target0.x < x0){\r
336                                 target0.x = x0;\r
337                         }\r
338                         if(target0.y < y0){\r
339                                 target0.y = y0;\r
340                         }\r
341                         if(target1.x > x1){\r
342                                 target1.x = x1;\r
343                         }\r
344                         if(target1.y > y1){\r
345                                 target1.y = y1;\r
346                         }\r
347                         (*before)->WriteMap(*before, target0.x, target0.y, target1.x, target1.y);\r
348                 }\r
349                 before = &(*before)->before;\r
350         }\r
351         return;\r
352 }\r
353 \r
354 void Sheet_Write_Map_32(UI_Sheet *sheet, int x0, int y0, int x1, int y1)\r
355 {\r
356         int x, y;\r
357         UI_Sheet_Control *ctrl;\r
358 \r
359         ctrl = sheet->myctrl;\r
360         for(y = y0; y <= y1; y++){\r
361                 for(x = x0; x <= x1; x++){\r
362                         if(ctrl->map[(y * ctrl->mainvramsize.x) + x] == 0 && ((uint *)sheet->vram)[((y - sheet->position.y) * sheet->size.x) + (x - sheet->position.x)] != sheet->invcol){\r
363                                 ctrl->map[(y * ctrl->mainvramsize.x) + x] = (uint)sheet;\r
364                         }\r
365                 }\r
366         }\r
367         return;\r
368 }\r
369 \r
370 void Sheet_Write_Map_16(UI_Sheet *sheet, int x0, int y0, int x1, int y1)\r
371 {\r
372         int x, y;\r
373         UI_Sheet_Control *ctrl;\r
374 \r
375         ctrl = sheet->myctrl;\r
376         for(y = y0; y <= y1; y++){\r
377                 for(x = x0; x <= x1; x++){\r
378                         if(ctrl->map[(y * ctrl->mainvramsize.x) + x] == 0 && ((ushort *)sheet->vram)[((y - sheet->position.y) * sheet->size.x) + (x - sheet->position.x)] != (ushort)sheet->invcol){\r
379                                 ctrl->map[(y * ctrl->mainvramsize.x) + x] = (uint)sheet;\r
380                         }\r
381                 }\r
382         }\r
383         return;\r
384 }\r
385 \r
386 void Sheet_Write_Map_08(UI_Sheet *sheet, int x0, int y0, int x1, int y1)\r
387 {\r
388         int x, y;\r
389         UI_Sheet_Control *ctrl;\r
390 \r
391         ctrl = sheet->myctrl;\r
392         for(y = y0; y <= y1; y++){\r
393                 for(x = x0; x <= x1; x++){\r
394                         if(ctrl->map[(y * ctrl->mainvramsize.x) + x] == 0 && ((uchar *)sheet->vram)[((y - sheet->position.y) * sheet->size.x) + (x - sheet->position.x)] != (uchar)sheet->invcol){\r
395                                 ctrl->map[(y * ctrl->mainvramsize.x) + x] = (uint)sheet;\r
396                         }\r
397                 }\r
398         }\r
399         return;\r
400 }\r
401 \r
402 void Sheet_Write_Map_NoInvisible(UI_Sheet *sheet, int x0, int y0, int x1, int y1)\r
403 {\r
404         int x, y;\r
405         UI_Sheet_Control *ctrl;\r
406 \r
407         ctrl = sheet->myctrl;\r
408         for(y = y0; y <= y1; y++){\r
409                 for(x = x0; x <= x1; x++){\r
410                         if(ctrl->map[(y * ctrl->mainvramsize.x) + x] == 0){\r
411                                 ctrl->map[(y * ctrl->mainvramsize.x) + x] = (uint)sheet;\r
412                         }\r
413                 }\r
414         }\r
415         return;\r
416 }\r
417 \r
418 void Sheet_Refresh_All(UI_Sheet *sheet0, UI_Sheet *sheet1, int x0, int y0, int x1, int y1)\r
419 {\r
420         UI_Sheet *now;\r
421         uint i;\r
422         DATA_Position2D target0, target1;\r
423         UI_Sheet_Control *ctrl;\r
424 \r
425         ctrl = sheet0->myctrl;\r
426         now = sheet0;\r
427         for(i = 0; i < ctrl->sheets; i++){\r
428                 target0.x = now->position.x;\r
429                 target0.y = now->position.y;\r
430                 target1.x = now->position.x + now->size.x - 1;\r
431                 target1.y = now->position.y + now->size.y - 1;\r
432 \r
433                 if(target0.x <= x1 && target0.y <= y1 && target1.x >= x0 && target1.y >= y0 && now->visible){\r
434                         if(target0.x < x0){\r
435                                 target0.x = x0;\r
436                         }\r
437                         if(target0.y < y0){\r
438                                 target0.y = y0;\r
439                         }\r
440                         if(target1.x > x1){\r
441                                 target1.x = x1;\r
442                         }\r
443                         if(target1.y > y1){\r
444                                 target1.y = y1;\r
445                         }\r
446                         now->Refresh(now, target0.x - now->position.x, target0.y - now->position.y, target1.x - now->position.x, target1.y - now->position.y);\r
447                 }\r
448                 if(now->next == sheet1 || now->next == 0){\r
449                         break;\r
450                 }\r
451                 now = now->next;\r
452         }\r
453         return;\r
454 }\r
455 \r
456 void Sheet_Refresh_32from32(UI_Sheet *sheet, int px0, int py0, int px1, int py1)\r
457 {\r
458         int x, y;\r
459         UI_Sheet_Control *ctrl;\r
460 \r
461         ctrl = sheet->myctrl;\r
462         px0 = px0 + sheet->position.x;\r
463         py0 = py0 + sheet->position.y;\r
464         px1 = px1 + sheet->position.x;\r
465         py1 = py1 + sheet->position.y;\r
466 \r
467         if(px0 >= ctrl->mainvramsize.x || py0 >= ctrl->mainvramsize.y || px1 < 0 || py1 < 0){\r
468                 return;\r
469         }\r
470         if(px0 < 0){\r
471                 px0 = 0;\r
472         }\r
473         if(py0 < 0){\r
474                 py0 = 0;\r
475         }\r
476         if(px1 >= ctrl->mainvramsize.x){\r
477                 px1 = ctrl->mainvramsize.x - 1;\r
478         }\r
479         if(py1 >= ctrl->mainvramsize.y){\r
480                 py1 = ctrl->mainvramsize.y - 1;\r
481         }\r
482 \r
483         for(y = py0; y <= py1; y++){\r
484                 for(x = px0; x <= px1; x++){\r
485                         if(ctrl->map[(y * ctrl->mainvramsize.x) + x] == (uint)sheet){\r
486                                 ((uint *)ctrl->mainvram)[(y * ctrl->mainvramsize.x) + x] = ((uint *)sheet->vram)[((y - sheet->position.y) * sheet->size.x) + (x - sheet->position.x)];\r
487                         }\r
488                 }\r
489         }\r
490         return;\r
491 }\r
492 \r
493 void Sheet_Refresh_16from32(UI_Sheet *sheet, int px0, int py0, int px1, int py1)\r
494 {\r
495         int x, y;\r
496         UI_Sheet_Control *ctrl;\r
497 \r
498         ctrl = sheet->myctrl;\r
499         px0 = px0 + sheet->position.x;\r
500         py0 = py0 + sheet->position.y;\r
501         px1 = px1 + sheet->position.x;\r
502         py1 = py1 + sheet->position.y;\r
503 \r
504         if(px0 >= ctrl->mainvramsize.x || py0 >= ctrl->mainvramsize.y || px1 < 0 || py1 < 0){\r
505                 return;\r
506         }\r
507         if(px0 < 0){\r
508                 px0 = 0;\r
509         }\r
510         if(py0 < 0){\r
511                 py0 = 0;\r
512         }\r
513         if(px1 >= ctrl->mainvramsize.x){\r
514                 px1 = ctrl->mainvramsize.x - 1;\r
515         }\r
516         if(py1 >= ctrl->mainvramsize.y){\r
517                 py1 = ctrl->mainvramsize.y - 1;\r
518         }\r
519 \r
520         for(y = py0; y <= py1; y++){\r
521                 for(x = px0; x <= px1; x++){\r
522                         if(ctrl->map[(y * ctrl->mainvramsize.x) + x] == (uint)sheet){\r
523                                 ((ushort *)ctrl->mainvram)[(y * ctrl->mainvramsize.x) + x] = RGB_32_To_16(((uint *)sheet->vram)[((y - sheet->position.y) * sheet->size.x) + (x - sheet->position.x)]);\r
524                         }\r
525                 }\r
526         }\r
527         return;\r
528 }\r
529 \r
530 void Sheet_Refresh_08from32(UI_Sheet *sheet, int px0, int py0, int px1, int py1)\r
531 {\r
532         int x, y;\r
533         UI_Sheet_Control *ctrl;\r
534 \r
535         ctrl = sheet->myctrl;\r
536         px0 = px0 + sheet->position.x;\r
537         py0 = py0 + sheet->position.y;\r
538         px1 = px1 + sheet->position.x;\r
539         py1 = py1 + sheet->position.y;\r
540 \r
541         if(px0 >= ctrl->mainvramsize.x || py0 >= ctrl->mainvramsize.y || px1 < 0 || py1 < 0){\r
542                 return;\r
543         }\r
544         if(px0 < 0){\r
545                 px0 = 0;\r
546         }\r
547         if(py0 < 0){\r
548                 py0 = 0;\r
549         }\r
550         if(px1 >= ctrl->mainvramsize.x){\r
551                 px1 = ctrl->mainvramsize.x - 1;\r
552         }\r
553         if(py1 >= ctrl->mainvramsize.y){\r
554                 py1 = ctrl->mainvramsize.y - 1;\r
555         }\r
556 \r
557         for(y = py0; y <= py1; y++){\r
558                 for(x = px0; x <= px1; x++){\r
559                         if(ctrl->map[(y * ctrl->mainvramsize.x) + x] == (uint)sheet){\r
560                                 ((uchar *)ctrl->mainvram)[(y * ctrl->mainvramsize.x) + x] = RGB_32_To_08_xy(((uint *)sheet->vram)[((y - sheet->position.y) * sheet->size.x) + (x - sheet->position.x)], x, y);\r
561                         }\r
562                 }\r
563         }\r
564         return;\r
565 }\r
566 \r
567 void Sheet_Refresh_16from16(UI_Sheet *sheet, int px0, int py0, int px1, int py1)\r
568 {\r
569         int x, y;\r
570         UI_Sheet_Control *ctrl;\r
571 \r
572         ctrl = sheet->myctrl;\r
573         px0 = px0 + sheet->position.x;\r
574         py0 = py0 + sheet->position.y;\r
575         px1 = px1 + sheet->position.x;\r
576         py1 = py1 + sheet->position.y;\r
577 \r
578         if(px0 >= ctrl->mainvramsize.x || py0 >= ctrl->mainvramsize.y || px1 < 0 || py1 < 0){\r
579                 return;\r
580         }\r
581         if(px0 < 0){\r
582                 px0 = 0;\r
583         }\r
584         if(py0 < 0){\r
585                 py0 = 0;\r
586         }\r
587         if(px1 >= ctrl->mainvramsize.x){\r
588                 px1 = ctrl->mainvramsize.x - 1;\r
589         }\r
590         if(py1 >= ctrl->mainvramsize.y){\r
591                 py1 = ctrl->mainvramsize.y - 1;\r
592         }\r
593 \r
594         for(y = py0; y <= py1; y++){\r
595                 for(x = px0; x <= px1; x++){\r
596                         if(ctrl->map[(y * ctrl->mainvramsize.x) + x] == (uint)sheet){\r
597                                 ((ushort *)ctrl->mainvram)[(y * ctrl->mainvramsize.x) + x] = ((ushort *)sheet->vram)[((y - sheet->position.y) * sheet->size.x) + (x - sheet->position.x)];\r
598                         }\r
599                 }\r
600         }\r
601         return;\r
602 }\r
603 \r
604 void Sheet_Refresh_08from08(UI_Sheet *sheet, int px0, int py0, int px1, int py1)\r
605 {\r
606         int x, y;\r
607         UI_Sheet_Control *ctrl;\r
608 \r
609         ctrl = sheet->myctrl;\r
610         px0 = px0 + sheet->position.x;\r
611         py0 = py0 + sheet->position.y;\r
612         px1 = px1 + sheet->position.x;\r
613         py1 = py1 + sheet->position.y;\r
614 \r
615         if(px0 >= ctrl->mainvramsize.x || py0 >= ctrl->mainvramsize.y || px1 < 0 || py1 < 0){\r
616                 return;\r
617         }\r
618         if(px0 < 0){\r
619                 px0 = 0;\r
620         }\r
621         if(py0 < 0){\r
622                 py0 = 0;\r
623         }\r
624         if(px1 >= ctrl->mainvramsize.x){\r
625                 px1 = ctrl->mainvramsize.x - 1;\r
626         }\r
627         if(py1 >= ctrl->mainvramsize.y){\r
628                 py1 = ctrl->mainvramsize.y - 1;\r
629         }\r
630 \r
631         for(y = py0; y <= py1; y++){\r
632                 for(x = px0; x <= px1; x++){\r
633                         if(ctrl->map[(y * ctrl->mainvramsize.x) + x] == (uint)sheet){\r
634                                 ((uchar *)ctrl->mainvram)[(y * ctrl->mainvramsize.x) + x] = ((uchar *)sheet->vram)[((y - sheet->position.y) * sheet->size.x) + (x - sheet->position.x)];\r
635                         }\r
636                 }\r
637         }\r
638         return;\r
639 }\r
640 \r
641 void Sheet_Refresh_Invalid(UI_Sheet *sheet, int px0, int py0, int px1, int py1)\r
642 {\r
643         return;\r
644 }\r
645 \r
646 void Sheet_Draw_Put_String(UI_Sheet *sheet, uint x, uint y, uint c, const uchar *s)\r
647 {\r
648         uint i;\r
649 \r
650         for(i = 0; s[i] != 0x00; i++){\r
651 \r
652         }\r
653 \r
654         if(y > sheet->size.y - 16){\r
655                 return;\r
656         }\r
657 \r
658         if(sheet->bpp == 32){\r
659                 Draw_Put_String_32(sheet->vram, sheet->size.x, x, y, c, s);\r
660         } else if(sheet->bpp == 16){\r
661                 Draw_Put_String_16(sheet->vram, sheet->size.x, x, y, c, s);\r
662         } else if(sheet->bpp == 8){\r
663                 Draw_Put_String_08(sheet->vram, sheet->size.x, x, y, c, s);\r
664         }\r
665 \r
666         sheet->Refresh(sheet, x, y, x + (i * 8), y + 16);\r
667         return;\r
668 }\r
669 \r
670 void Sheet_Draw_Put_String_With_BackColor(UI_Sheet *sheet, uint x, uint y, uint c, uint bc, const uchar *s)\r
671 {\r
672         uint i;\r
673 \r
674         for(i = 0; s[i] != 0x00; i++){\r
675 \r
676         }\r
677 \r
678         Sheet_Draw_Fill_Rectangle(sheet, bc, x, y, x + (i * 8) - 1,  y + 16 - 1);\r
679 \r
680         if(y > sheet->size.y - 16){\r
681                 return;\r
682         }\r
683 \r
684         if(sheet->bpp == 32){\r
685                 Draw_Put_String_32(sheet->vram, sheet->size.x, x, y, c, s);\r
686         } else if(sheet->bpp == 16){\r
687                 Draw_Put_String_16(sheet->vram, sheet->size.x, x, y, c, s);\r
688         } else if(sheet->bpp == 8){\r
689                 Draw_Put_String_08(sheet->vram, sheet->size.x, x, y, c, s);\r
690         }\r
691 \r
692         sheet->Refresh(sheet, x, y, x + (i * 8), y + 16);\r
693         return;\r
694 }\r
695 \r
696 void Sheet_Draw_Fill_Rectangle(UI_Sheet *sheet, uint c, uint x0, uint y0, uint x1, uint y1)\r
697 {\r
698         if(x1 >= sheet->size.x || y1 >= sheet->size.y){\r
699                 return;\r
700         }\r
701 \r
702         if(sheet->bpp == 32){\r
703                 Draw_Fill_Rectangle_32(sheet->vram, sheet->size.x, c, x0, y0, x1, y1);\r
704         } else if(sheet->bpp == 16){\r
705                 Draw_Fill_Rectangle_16(sheet->vram, sheet->size.x, c, x0, y0, x1, y1);\r
706         } else if(sheet->bpp == 8){\r
707                 Draw_Fill_Rectangle_08(sheet->vram, sheet->size.x, c, x0, y0, x1, y1);\r
708         }\r
709         sheet->Refresh(sheet, x0, y0, x1, y1);\r
710         return;\r
711 }\r
712 \r
713 void Sheet_Draw_Fill_Rectangle_Gradation_Vertical(UI_Sheet *sheet, uint c0, uint c1, uint x0, uint y0, uint x1, uint y1)\r
714 {\r
715         int nowcol, nowcol_R, nowcol_G, nowcol_B, add_R, add_G, add_B;\r
716         uint x, y;\r
717 \r
718         if(x1 >= sheet->size.x || y1 >= sheet->size.y){\r
719                 return;\r
720         }\r
721 \r
722         if(y1 == y0){\r
723                 return;\r
724         }\r
725 \r
726         c0 &= 0x00ffffff;\r
727         c1 &= 0x00ffffff;\r
728 \r
729         add_R = (((int)((c1 & 0x00ff0000) >> 16) << 10) - ((int)((c0 & 0x00ff0000) >> 16) << 10)) / (int)(y1 - y0);\r
730         add_G = (((int)((c1 & 0x0000ff00) >> 8) << 10) - ((int)((c0 & 0x0000ff00) >> 8) << 10)) / (int)(y1 - y0);\r
731         add_B = (((int)(c1 & 0x000000ff) << 10) - ((int)(c0 & 0x000000ff) << 10)) / (int)(y1 - y0);\r
732 \r
733         nowcol_R = ((c0 & 0x00ff0000) >> 16) << 10;\r
734         nowcol_G = ((c0 & 0x0000ff00) >> 8) << 10;\r
735         nowcol_B = (c0 & 0x000000ff) << 10;\r
736 \r
737         for(y = y0; y <= y1; y++){\r
738                 nowcol = ((nowcol_R >> 10) << 16) | ((nowcol_G >> 10) << 8) | (nowcol_B >> 10);\r
739                 for(x = x0; x <= x1; x++){\r
740                         Sheet_Draw_Point(sheet, (uint)nowcol, x, y);\r
741                 }\r
742                 nowcol_R += add_R;\r
743                 nowcol_G += add_G;\r
744                 nowcol_B += add_B;\r
745         }\r
746 \r
747         return;\r
748 }\r
749 void Sheet_Draw_Point(UI_Sheet *sheet, uint c, uint x, uint y)\r
750 {\r
751         if(sheet->bpp == 32){\r
752                 ((uint *)sheet->vram)[y * sheet->size.x + x] = c;\r
753         } else if(sheet->bpp == 16){\r
754                 c = RGB_32_To_16(c);\r
755                 ((ushort *)sheet->vram)[y * sheet->size.x + x] = (ushort)c;\r
756         } else if(sheet->bpp == 8){\r
757 //              c = RGB_32_To_08(c);\r
758                 c = RGB_32_To_08_xy(c, x, y);\r
759                 ((uchar *)sheet->vram)[y * sheet->size.x + x] = (uchar)c;\r
760         }\r
761         sheet->Refresh(sheet, x, y, x, y);\r
762         return;\r
763 }\r
764 \r
765 void System_Sheet_Initialise(void *vram, uint xsize, uint ysize, uint bpp)\r
766 {\r
767         Sheet_Initialise(&sys_sheet_ctrl, &sys_mem_ctrl, vram, xsize, ysize, bpp);\r
768         return;\r
769 }\r
770 \r
771 UI_Sheet *System_Sheet_Get(uint xsize, uint ysize, uint bpp, uint invcol)\r
772 {\r
773         return Sheet_Get(&sys_sheet_ctrl, xsize, ysize, bpp, invcol);\r
774 }\r
775 \r
776 UI_Sheet *Sheet_Get_From_Position(UI_Sheet_Control *ctrl, int x, int y)\r
777 {\r
778         if(x < 0 || y < 0 || x > ctrl->mainvramsize.x || y > ctrl->mainvramsize.y){\r
779                 return 0;\r
780         }\r
781         return (UI_Sheet *)ctrl->map[(y * ctrl->mainvramsize.x) + x];\r
782 }\r
783 \r
784 uint Sheet_Get_Top_Of_Height(UI_Sheet_Control *ctrl)\r
785 {\r
786         if(ctrl->sheets < 1){\r
787                 return 0;\r
788         }\r
789         return ctrl->sheets - 1;\r
790 }\r
791 \r
792 uint System_Sheet_Get_Top_Of_Height(void)\r
793 {\r
794         return Sheet_Get_Top_Of_Height(&sys_sheet_ctrl);\r
795 }\r