source: svn/trunk/zasc/app_c/DST_Window.c @ 27

Last change on this file since 27 was 2, checked in by jglee, 11 years ago

first commit

File size: 27.5 KB
Line 
1#include "DST_WinManager.h"
2#include "DST_OSDImage.h"
3
4DS_U32* DST_UTF82Uni(DS_U8 *utf);
5
6void CFont_CFont(CWindow* this, DS_U8 nSize, OSD_PIXEL_T Color, DS_U8 hor_align, DS_U8 ver_align)
7{
8        this->FontSetSize(this, nSize);
9        this->FontSetColor(this, Color);                //256ÀÌ»óÀÏ °æ¿ì default : white
10        this->FontSetHorAlign(this, hor_align);         //(0: Left, 1: Center, 2: Right)
11        this->FontSetVerAlign(this, ver_align);         //(0: Top, 1: Middle, 2: Bottom)
12}
13
14void CFont_SetSize(CWindow* this, DS_U8 Size)
15{
16    if (Size == this->font.nSize)
17        return;
18
19        this->font.nSize = Size;
20    this->font.dot1_width = DST_GetTextWidth((char*)".", Size);
21    this->font.dot2_width = DST_GetTextWidth((char*)"..", Size);
22    this->font.dot3_width = DST_GetTextWidth((char*)"...", Size);
23}
24
25int CFont_GetDot1Width(CWindow* this)
26{
27    return this->font.dot1_width;
28}
29
30int CFont_GetDot2Width(CWindow* this)
31{
32    return this->font.dot2_width;
33}
34
35int CFont_GetDot3Width(CWindow* this)
36{
37    return this->font.dot3_width;
38}
39
40DS_U8 CFont_GetSize(CWindow* this)
41{
42        if (this->font.nSize < 5) return 5;
43        return this->font.nSize;
44}
45
46void CFont_SetColor(CWindow* this, OSD_PIXEL_T nColor)
47{
48        this->font.Color = nColor;
49}
50
51OSD_PIXEL_T CFont_GetColor(CWindow* this)
52{
53        return this->font.Color;
54}
55
56void CFont_SetHorAlign(CWindow* this, DS_U8 hor)
57{
58        this->font.hor_align = hor;
59}
60
61DS_U8 CFont_GetHorAlign(CWindow* this)
62{
63        switch (this->font.hor_align)
64        {
65                case ALIGN_LEFT: return ALIGN_LEFT;
66                case ALIGN_RIGHT: return ALIGN_RIGHT;
67        }
68        return ALIGN_CENTER;
69}
70
71void CFont_SetVerAlign(CWindow* this, DS_U8 ver)
72{
73        this->font.ver_align = ver;
74}
75
76DS_U8 CFont_GetVerAlign(CWindow* this)
77{
78        switch (this->font.ver_align)
79        {
80                case ALIGN_TOP: return ALIGN_TOP;
81                case ALIGN_BOTTOM: return ALIGN_BOTTOM;
82        }
83        return ALIGN_MIDDLE;
84}
85       
86// ÀÚ±â ÀÚ½ÅÀ» Æ÷ÇÔÇÑ ÇÏÀ§ À©µµ¿ì¸¦ ¸ðµÎ ´Ý´Â´Ù.
87void CWin_Close(CWindow* this)
88{
89        int i = 0;
90        for (i = 0; i < WIN_ID_MAX; i++)
91        {
92                CWindow *pWin = DST_GetWin((WinID)i);
93                if (pWin == 0) continue;
94                if (pWin->GetParentWinID(pWin) == this->GetWinID(this)) {
95                    pWin->Close(pWin);
96                }
97        }
98
99        this->nWinState = 2;
100        this->UpdateScreen(this);
101}
102
103void CWin_RegisterAllKey(CWindow* this)
104{
105        int i = 0;
106        for (i = 0; i <= KEY_ID_MAX; i++)
107        {
108                this->bRegisterKey[i] = true;
109                this->nKeyDelay[i] = 0;
110                this->nKeyRepeat[i] = 0;
111        }
112}
113
114void CWin_UnRegisterAllKey(CWindow* this)
115{
116        int i = 0;
117        for (i = 0; i <= KEY_ID_MAX; i++)
118        {
119                this->bRegisterKey[i] = false;
120                this->nKeyDelay[i] = 0;
121                this->nKeyRepeat[i] = 0;
122        }
123}
124
125void CWin_RegisterKey(CWindow* this, DS_U8 nKeyCode, bool bState, int nDelay, int nRepeat)
126{
127        this->bRegisterKey[nKeyCode] = bState;
128        if (nDelay < 10 || nRepeat < 10)
129        {
130                this->nKeyDelay[nKeyCode] = 0;
131                this->nKeyRepeat[nKeyCode] = 0;
132        }
133        this->nKeyDelay[nKeyCode] = nDelay/10;
134        this->nKeyRepeat[nKeyCode] = nRepeat/10;
135}
136
137bool CWin_IsRegisterKey(CWindow* this, DS_U8 nKeyCode)
138{
139        return this->bRegisterKey[nKeyCode];
140}
141
142void CWin_SetWinName(CWindow* this, const char* strName)
143{
144        strcpy(this->strWinName, strName);
145}
146
147OSD_PIXEL_T *CWin_GetImgBuff(CWindow* this)
148{
149        return this->imgBuff;
150}
151
152void CWin_SetVisible(CWindow* this, bool bValue)
153{
154        this->bVisible = bValue;
155        this->UpdateScreen(this);
156}
157
158void CWin_Move(CWindow* this, int x, int y)
159{
160        if (this->rect.x == x && this->rect.y == y) return;
161        this->UpdateScreen(this);
162        this->rect.x = x;
163        this->rect.y = y;
164        this->UpdateScreen(this);
165}
166
167void CWin_UpdateScreen(CWindow* this)
168{
169        this->UpdateScreenEx(this, 0, 0, this->rect.w, this->rect.h);
170}
171
172void CWin_UpdateScreenEx(CWindow* this, int x, int y, int w, int h)
173{
174        DST_RECT rectTemp;
175        rectTemp.x = this->rect.x + x;
176        rectTemp.y = this->rect.y + y;
177        rectTemp.w = w;
178        rectTemp.h = h;
179        DST_AddUpdateRegion(rectTemp);
180}
181
182void CWin_DrawPixel(CWindow* this, int x, int y, OSD_PIXEL_T color)
183{
184        if (this->imgBuff == 0) return;
185        if (x < 0) return;
186        if (y < 0) return;
187        if (x > this->rect.w) return;
188        if (y > this->rect.h) return;
189        *((this->imgBuff) + (y * (this->rect.w)) + x) = color;
190}
191
192void CWin_DrawBox32(CWindow* this, int x, int y, int w, int h, OSD_PIXEL_T color)
193{
194        if (this->imgBuff == 0) return;
195        if (w == 0 || h == 0) return;
196        OSD_PIXEL_T* des = (this->imgBuff) + ((this->rect.w)*y+x);
197        int hh = h;
198        while (hh--)
199        {
200                int ww = w;
201                while (ww--) *des++ = color;
202                des += ((this->rect.w) - w);
203        }
204        this->UpdateScreenEx(this, x,y,w,h);
205}
206
207// ¾ÐÃà¾È µÈ 16ºñÆ® 32 ºñÆ® À̹ÌÁö
208void CWin_DrawImage4(CWindow* this, int x, int y, DS_U8 *image, bool bProcessTransparent)
209{
210        DS_U16 nWidth = image[1] * 256 + image[2];
211        DS_U16 nHeight = image[3] * 256 + image[4];
212
213        if (x+nWidth > (this->rect.w)) return;
214        if (y+nHeight > (this-> rect.h)) return;
215
216        this->UpdateScreenEx(this, x, y, nWidth, nHeight);
217
218        if (bProcessTransparent == true)
219        {
220                int yy = nHeight;
221                OSD_PIXEL_T *tmpSrc = (OSD_PIXEL_T *)& image[8];
222                OSD_PIXEL_T *tmpDes = (this->imgBuff) + y * (this->rect.w) + x;
223                int nStep = (this->rect.w)-nWidth;
224                while (yy--)
225                {
226                        int xx = nWidth;
227                        while (xx--)
228                        {
229                                OSD_PIXEL_T max = (sizeof(OSD_PIXEL_T) == 2) ? 0x0F : 0xFF;
230                                OSD_PIXEL_T sa,sr,sg,sb;
231                                DST_GetColor(*tmpSrc, &sa, &sr, &sg, &sb);
232                                OSD_PIXEL_T da,dr,dg,db;
233                                DST_GetColor(*tmpDes, &da, &dr, &dg, &db);
234
235                                if (sa != 0) // Åõ¸íÀÌ ¾Æ´Ñ °æ¿ì¸¸ ±×¸°´Ù.
236                                {
237                                        if (sa == max || da == 0) // ¼Ò½º°¡ ¿ÏÀüºÒÅõ¸íÀ̰ųª ¹è°æÀÌ Åõ¸íÀΰæ¿ì
238                                        {
239                                                *tmpDes = *tmpSrc;
240                                        }
241                                        else // ¹ÝÅõ¸í
242                                        {
243                                                // http://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
244                                                OSD_PIXEL_T t = (da * (max-sa) + (max/2)) / max;
245                                                OSD_PIXEL_T a = sa + t;
246                                                if (a > max) a = max;
247                                                OSD_PIXEL_T r = ((sr * sa + dr * t) + (a/2)) / a;
248                                                OSD_PIXEL_T g = ((sg * sa + dg * t) + (a/2)) / a;
249                                                OSD_PIXEL_T b = ((sb * sa + db * t) + (a/2)) / a;
250                                                *tmpDes = DST_SetColor(a, r, g, b);
251                                        }
252                                }
253                                tmpSrc++;
254                                tmpDes++;
255                        }
256                        tmpDes += nStep;
257                }
258        }
259        else
260        {
261                int yy = nHeight;
262                OSD_PIXEL_T *tmpSrc = (OSD_PIXEL_T *)& image[image[0]==2? 6:8];
263                OSD_PIXEL_T *tmpDes = (this->imgBuff) + y * (this->rect.w) + x;
264                while (yy--)
265                {
266                        memcpy(tmpDes, tmpSrc, sizeof(OSD_PIXEL_T) * nWidth);
267                        tmpSrc += nWidth;
268                        tmpDes += (this->rect.w);
269                }
270        }
271}
272
273void CWin_DrawImage5(CWindow* this, int x, int y, DS_U8 *image, bool bProcessTransparent)
274{
275        DS_U16 nWidth = image[1] * 256 + image[2];
276        DS_U16 nHeight = image[3] * 256 + image[4];
277
278        if (x+nWidth > (this->rect.w)) return;
279        if (y+nHeight > (this->rect.h)) return;
280
281        this->UpdateScreenEx(this, x, y, nWidth, nHeight);
282       
283        DS_U16 nPallette = image[6] * 256 + image[7];
284        DS_U32 *pPallette = (DS_U32*)&image[8];
285        //DST_Printf("nPallette = %d\n", nPallette);
286        DS_U32* pDes = (DS_U32*)(this->imgBuff) + y * (this->rect.w) + x;
287        if (bProcessTransparent == true)
288        {
289                OSD_PIXEL_T max = (sizeof(OSD_PIXEL_T) == 2) ? 0x0F : 0xFF;
290                if (nPallette > 256)
291                {
292                        DS_U16* pSrc = (DS_U16*)&image[8 + nPallette*4];
293                        int yy = 0;
294                        for (yy = 0; yy < nHeight; yy++)
295                        {
296                                DS_U32* pDes1 = pDes;
297                                int xx = 0;
298                                for (xx =0; xx < nWidth; xx++)
299                                {
300                                        OSD_PIXEL_T c = pPallette[*pSrc];
301                                        OSD_PIXEL_T sa,sr,sg,sb;
302                                        DST_GetColor(c, &sa, &sr, &sg, &sb);
303                                        OSD_PIXEL_T da,dr,dg,db;
304                                        DST_GetColor(*pDes1, &da, &dr, &dg, &db);
305       
306                                        if (sa != 0) // Åõ¸íÀÌ ¾Æ´Ñ °æ¿ì¸¸ ±×¸°´Ù.
307                                        {
308                                                if (sa == max || da == 0) // ¼Ò½º°¡ ¿ÏÀüºÒÅõ¸íÀ̰ųª ¹è°æÀÌ Åõ¸íÀΰæ¿ì
309                                                {
310                                                        *pDes1 = c;
311                                                }
312                                                else // ¹ÝÅõ¸í
313                                                {
314                                                        // http://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
315                                                        OSD_PIXEL_T t = (da * (max-sa) + (max/2)) / max;
316                                                        OSD_PIXEL_T a = sa + t;
317                                                        if (a > max) a = max;
318                                                        OSD_PIXEL_T r = ((sr * sa + dr * t) + (a/2)) / a;
319                                                        OSD_PIXEL_T g = ((sg * sa + dg * t) + (a/2)) / a;
320                                                        OSD_PIXEL_T b = ((sb * sa + db * t) + (a/2)) / a;
321                                                        *pDes1 = DST_SetColor(a, r, g, b);
322                                                }
323                                        }
324                                        pSrc++;
325                                        pDes1++;
326                                }
327                                pDes += (this->rect.w);
328                        }
329                }
330                else if (nPallette > 1)
331                {
332                        DS_U8* pSrc = (DS_U8*)&image[8 + nPallette*4];
333                        int yy = 0;
334                        for (yy = 0; yy < nHeight; yy++)
335                        {
336                                DS_U32* pDes1 = pDes;
337                                int xx = 0;
338                                for (xx =0; xx < nWidth; xx++)
339                                {
340                                        OSD_PIXEL_T c = pPallette[*pSrc];
341                                        OSD_PIXEL_T sa,sr,sg,sb;
342                                        DST_GetColor(c, &sa, &sr, &sg, &sb);
343                                        OSD_PIXEL_T da,dr,dg,db;
344                                        DST_GetColor(*pDes1, &da, &dr, &dg, &db);
345       
346                                        if (sa != 0) // Åõ¸íÀÌ ¾Æ´Ñ °æ¿ì¸¸ ±×¸°´Ù.
347                                        {
348                                                if (sa == max || da == 0) // ¼Ò½º°¡ ¿ÏÀüºÒÅõ¸íÀ̰ųª ¹è°æÀÌ Åõ¸íÀΰæ¿ì
349                                                {
350                                                        *pDes1 = c;
351                                                }
352                                                else // ¹ÝÅõ¸í
353                                                {
354                                                        // http://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
355                                                        OSD_PIXEL_T t = (da * (max-sa) + (max/2)) / max;
356                                                        OSD_PIXEL_T a = sa + t;
357                                                        if (a > max) a = max;
358                                                        OSD_PIXEL_T r = ((sr * sa + dr * t) + (a/2)) / a;
359                                                        OSD_PIXEL_T g = ((sg * sa + dg * t) + (a/2)) / a;
360                                                        OSD_PIXEL_T b = ((sb * sa + db * t) + (a/2)) / a;
361                                                        *pDes1 = DST_SetColor(a, r, g, b);
362                                                }
363                                        }
364                                        pSrc++;
365                                        pDes1++;
366                                }
367                                pDes += (this->rect.w);
368                        }
369                }
370                else // ´Ü »ö
371                {
372                        OSD_PIXEL_T c = pPallette[0];
373                        OSD_PIXEL_T sa,sr,sg,sb;
374                        DST_GetColor(c, &sa, &sr, &sg, &sb);
375                        int yy = 0;
376                        for (yy = 0; yy < nHeight; yy++)
377                        {
378                                DS_U32* pDes1 = pDes;
379                                int xx = 0;
380                                for (xx =0; xx < nWidth; xx++)
381                                {
382                                        OSD_PIXEL_T da,dr,dg,db;
383                                        DST_GetColor(*pDes1, &da, &dr, &dg, &db);
384                                        if (sa != 0) // Åõ¸íÀÌ ¾Æ´Ñ °æ¿ì¸¸ ±×¸°´Ù.
385                                        {
386                                                if (sa == max || da == 0) // ¼Ò½º°¡ ¿ÏÀüºÒÅõ¸íÀ̰ųª ¹è°æÀÌ Åõ¸íÀΰæ¿ì
387                                                {
388                                                        *pDes1 = c;
389                                                }
390                                                else // ¹ÝÅõ¸í
391                                                {
392                                                        // http://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
393                                                        OSD_PIXEL_T t = (da * (max-sa) + (max/2)) / max;
394                                                        OSD_PIXEL_T a = sa + t;
395                                                        if (a > max) a = max;
396                                                        OSD_PIXEL_T r = ((sr * sa + dr * t) + (a/2)) / a;
397                                                        OSD_PIXEL_T g = ((sg * sa + dg * t) + (a/2)) / a;
398                                                        OSD_PIXEL_T b = ((sb * sa + db * t) + (a/2)) / a;
399                                                        *pDes1 = DST_SetColor(a, r, g, b);
400                                                }
401                                        }
402                                        pDes1++;
403                                }
404                                pDes += (this->rect.w);
405                        }
406                }
407        }
408        else
409        {
410                if (nPallette > 256)
411                {
412                        DS_U16* pSrc = (DS_U16*)&image[8 + nPallette*4];
413                        int yy= 0;
414                        for (yy = 0; yy < nHeight; yy++)
415                        {
416                                DS_U32* pDes1 = pDes;
417                                int xx = 0;
418                                for (xx =0; xx < nWidth; xx++)
419                                {
420                                        *pDes1 = pPallette[*pSrc];
421                                        pSrc++;
422                                        pDes1++;
423                                }
424                                pDes += (this->rect.w);
425                        }
426                }
427                else if (nPallette > 1)
428                {
429                        DS_U8* pSrc = (DS_U8*)&image[8 + nPallette*4];
430                        int yy =0;
431                        for (yy = 0; yy < nHeight; yy++)
432                        {
433                                DS_U32* pDes1 = pDes;
434                                int xx = 0;
435                                for (xx =0; xx < nWidth; xx++)
436                                {
437                                        *pDes1 = pPallette[*pSrc];
438                                        pSrc++;
439                                        pDes1++;
440                                }
441                                pDes += (this->rect.w);
442                        }
443                }
444                else // ÆÈ·¹Æ® °¹¼ö°¡ 1°³ÀÎ °æ¿ì
445                {
446                        T();
447                        this->DrawBox32(this, x, y, nWidth, nHeight, pPallette[0]);
448                }
449        }
450}
451
452#if OSD_PIXEL_BPP==16
453// 256°³ ÀÌÇÏÀÇ ÆÈ·¹Æ®¸¦ °¡Áø 16ºñÆ® À̹ÌÁö
454void CWin_DrawImage6(CWindow* this, int x, int y, DS_U8 *image, bool bProcessTransparent)
455{
456        DS_U16 nWidth = image[1] * 256 + image[2];
457        DS_U16 nHeight = image[3] * 256 + image[4];
458
459        if (x+nWidth > (this->rect.w)) return;
460        if (y+nHeight > (this->rect.h)) return;
461
462        this->UpdateScreenEx(this, x, y, nWidth, nHeight);
463       
464        DS_U16 nPallette = image[5]+1;
465        OSD_PIXEL_T *pPallette = (DS_U16*)&image[6];
466        //DST_Printf("nPallette = %d\n", nPallette);
467        DS_U8* pSrc = (DS_U8*)&image[6 + nPallette*2];
468        OSD_PIXEL_T* pDes = (this->imgBuff) + y * (this->rect.w) + x;
469        if (bProcessTransparent == true)
470        {
471                OSD_PIXEL_T max = (sizeof(OSD_PIXEL_T) == 2) ? 0x0F : 0xFF;
472                if (nPallette <= 16)
473                {
474                        bool bUpper = true;
475                        int yy = 0;
476                        for (yy = 0; yy < nHeight; yy++)
477                        {
478                                OSD_PIXEL_T* pDes1 = pDes;
479                                int xx = 0;
480                                for (xx =0; xx < nWidth; xx++)
481                                {
482                                        OSD_PIXEL_T c = 0;
483                                        if (bUpper)
484                                        {
485                                                c = pPallette[(*pSrc>>4)&0x0F];
486                                                bUpper = false;
487                                        }
488                                        else
489                                        {
490                                                c = pPallette[(*pSrc)&0x0F];
491                                                pSrc++;
492                                                bUpper = true;
493                                        }
494                                        OSD_PIXEL_T sa,sr,sg,sb;
495                                        DST_GetColor(c, &sa, &sr, &sg, &sb);
496                                        OSD_PIXEL_T da,dr,dg,db;
497                                        DST_GetColor(*pDes1, &da, &dr, &dg, &db);
498       
499                                        if (sa != 0) // Åõ¸íÀÌ ¾Æ´Ñ °æ¿ì¸¸ ±×¸°´Ù.
500                                        {
501                                                if (sa == max || da == 0) // ¼Ò½º°¡ ¿ÏÀüºÒÅõ¸íÀ̰ųª ¹è°æÀÌ Åõ¸íÀΰæ¿ì
502                                                {
503                                                        *pDes1 = c;
504                                                }
505                                                else // ¹ÝÅõ¸í
506                                                {
507                                                        // http://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
508                                                        OSD_PIXEL_T t = (da * (max-sa) + (max/2)) / max;
509                                                        OSD_PIXEL_T a = sa + t;
510                                                        if (a > max) a = max;
511                                                        OSD_PIXEL_T r = ((sr * sa + dr * t) + (a/2)) / a;
512                                                        OSD_PIXEL_T g = ((sg * sa + dg * t) + (a/2)) / a;
513                                                        OSD_PIXEL_T b = ((sb * sa + db * t) + (a/2)) / a;
514                                                        *pDes1 = DST_SetColor(a, r, g, b);
515                                                }
516                                        }
517                                        //pSrc++;
518                                        pDes1++;
519                                }
520                                pDes += (this->rect.w);
521                        }
522                }
523                else
524                {
525                        int yy=0;
526                        for (yy = 0; yy < nHeight; yy++)
527                        {
528                                OSD_PIXEL_T* pDes1 = pDes;
529                                int xx = 0;
530                                for (xx =0; xx < nWidth; xx++)
531                                {
532                                        OSD_PIXEL_T c = pPallette[*pSrc];
533                                        OSD_PIXEL_T sa,sr,sg,sb;
534                                        DST_GetColor(c, &sa, &sr, &sg, &sb);
535                                        OSD_PIXEL_T da,dr,dg,db;
536                                        DST_GetColor(*pDes1, &da, &dr, &dg, &db);
537       
538                                        if (sa != 0) // Åõ¸íÀÌ ¾Æ´Ñ °æ¿ì¸¸ ±×¸°´Ù.
539                                        {
540                                                if (sa == max || da == 0) // ¼Ò½º°¡ ¿ÏÀüºÒÅõ¸íÀ̰ųª ¹è°æÀÌ Åõ¸íÀΰæ¿ì
541                                                {
542                                                        *pDes1 = c;
543                                                }
544                                                else // ¹ÝÅõ¸í
545                                                {
546                                                        // http://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
547                                                        OSD_PIXEL_T t = (da * (max-sa) + (max/2)) / max;
548                                                        OSD_PIXEL_T a = sa + t;
549                                                        if (a > max) a = max;
550                                                        OSD_PIXEL_T r = ((sr * sa + dr * t) + (a/2)) / a;
551                                                        OSD_PIXEL_T g = ((sg * sa + dg * t) + (a/2)) / a;
552                                                        OSD_PIXEL_T b = ((sb * sa + db * t) + (a/2)) / a;
553                                                        *pDes1 = DST_SetColor(a, r, g, b);
554                                                }
555                                        }
556                                        pSrc++;
557                                        pDes1++;
558                                }
559                                pDes += (this->rect.w);
560                        }               
561                }
562        }
563        else
564        {
565                if (nPallette <= 16)
566                {
567                        bool bUpper = true;
568                        int yy=0;
569                        for (yy = 0; yy < nHeight; yy++)
570                        {
571                                OSD_PIXEL_T* pDes1 = pDes;
572                                int xx = 0;
573                                for (xx =0; xx < nWidth; xx++)
574                                {
575                                        if (bUpper)
576                                        {
577                                                *pDes1 = pPallette[(*pSrc>>4)&0x0F];
578                                                bUpper = false;
579                                        }
580                                        else
581                                        {
582                                                *pDes1 = pPallette[(*pSrc)&0x0F];
583                                                pSrc++;
584                                                bUpper = true;
585                                        }
586                                        pDes1++;
587                                }
588                                pDes += (this->rect.w);
589                        }
590                }
591                else
592                {
593                        int yy = 0;
594                        for (yy = 0; yy < nHeight; yy++)
595                        {
596                                OSD_PIXEL_T* pDes1 = pDes;
597                                int xx = 0;
598                                for (xx =0; xx < nWidth; xx++)
599                                {
600                                        *pDes1 = pPallette[*pSrc];
601                                        pSrc++;
602                                        pDes1++;
603                                }
604                                pDes += (this->rect.w);
605                        }
606                }
607        }
608}
609#endif
610
611void CWin_DrawImage(CWindow* this, int x, int y, DS_U8 *image, bool bProcessTransparent)
612{
613        if (image == 0) return;
614        if (this->imgBuff == 0) return;
615               
616        switch (image[0])
617        {
618                case 2:
619                case 4:
620                        CWin_DrawImage4(this, x,y,image, bProcessTransparent);
621                        break;
622                case 5:
623                        CWin_DrawImage5(this, x,y,image, bProcessTransparent);
624                        break;
625#if OSD_PIXEL_BPP==16
626                case 6: // ¾ÐÃàµÈ 16ºñÆ® À̹ÌÁö
627                        CWin_DrawImage6(this, x,y,image, bProcessTransparent);
628                        break;
629#endif
630                default:
631                        break;
632        }       
633}
634
635
636void CWin_DrawText(CWindow* this, int start_x, int start_y, int width, int height, char *strText, CFont* font)
637{
638        if (strText == 0) return;
639        if (strlen(strText) == 0) return;
640        DS_U16* strText16 = (DS_U16*)DST_OS_Malloc((strlen(strText)+1) * sizeof(DS_U16));
641        memset(strText16, 0,(strlen(strText)+1) * sizeof(DS_U16));
642        unsigned i = 0;
643        for (i= 0; i < strlen(strText); i++) strText16[i] = (DS_U16)(DS_U8)strText[i];
644        this->DrawTextUni(this, start_x, start_y, width, height, strText16, font);
645        DST_OS_Free(&strText16);
646}
647
648void CWin_DrawTextUTF8(CWindow* this, int start_x, int start_y, int width, int height, DS_U8* strText, CFont* font)
649{
650        if (strText == 0) return;
651        int nLen = 0;
652        int i = 0;
653        for (i = 0; i < 4096; i++) // 4096ÀÌÇÏ·Î Á¦ÇѵÊ
654        {
655                if (strText[i] == 0) break;
656                nLen++;
657        }
658//      DST_Printf("nLen = %d\n", nLen);
659        if (nLen == 0) return;
660        DS_U32 *strText32 = DST_UTF82Uni(strText); // È£ÃâÇÑ ÂÊ¿¡¼­ ¸Þ¸ð¸® ÇØÁ¦
661        if (strText32 == 0) return;
662        this->DrawText32(this, start_x, start_y,width,  height, strText32, font);
663        //DST_OS_Free(&strText32);
664//      T();
665}
666
667void CWin_DrawTextUni(CWindow* this, int start_x, int start_y, int width, int height, DS_U16* strText, CFont* font)
668{
669        // ¹®ÀÚ¿­ÀÇ ±æÀ̸¦ ±¸ÇÑ´Ù.
670        if (strText == 0) return;
671        int nStrLen = 0;
672        int i = 0;
673        for (i = 0; i < 4096; i++) // 4096ÀÌÇÏ·Î Á¦ÇѵÊ
674        {
675                if (strText[i] == 0) break;
676                nStrLen++;
677        }
678        if (nStrLen == 0) return;
679        DS_U32* strText32 = (DS_U32*)DST_OS_Malloc((nStrLen+1) * sizeof(DS_U32));
680        memset(strText32, 0, (nStrLen+1) * sizeof(DS_U32));
681        // int i=0;
682        for (i = 0; i < nStrLen; i++) strText32[i] = (DS_U32)strText[i];
683        this->DrawText32(this, start_x, start_y,width,  height, strText32, font);
684        DST_OS_Free(&strText32);
685}
686
687void CWin_DrawText32(CWindow* this, int start_x, int start_y, int width, int height, DS_U32* strText, CFont* font)
688{
689        if (strText == 0) return;
690        // ¹®ÀÚ¿­ÀÇ ±æÀ̸¦ ±¸ÇÑ´Ù.
691        int nStrLen = 0;
692        int i = 0;
693        for (i = 0; i < 4096; i++) // 4096ÀÌÇÏ·Î Á¦ÇѵÊ
694        {
695                if (strText[i] == 0) break;
696                nStrLen++;
697        }
698        if (nStrLen == 0) return;
699       
700        if (this->GetImgBuff(this) == 0) return;
701        if (width < 1) return;
702        if (height < 1) return;
703        if (start_x < 0) start_x = 0;
704        if (start_y < 0) start_y = 0;
705        if (width > this->rect.w) width = this->rect.w;
706        if (height > this->rect.h) height = this->rect.h;
707        if (start_x + width > this->rect.w) start_x = (this->rect.w)-width;
708        if (start_y + height > this->rect.h) start_y = (this->rect.h)-height;
709
710        // ¹®ÀÚ¿­ÀÌ ÅØ½ºÆ® ¹Ú½ºº¸´Ù Å©´Ù¸é ...À» Ãß°¡ÇÑ´Ù.
711        if (width < this->FontGetDot1Width(this)) return; // ÆøÀÌ Á¼À¸¸é ±Û¾¾¸¦ ¾²Áö ¾Ê´Â´Ù.
712       
713        static DS_U32 strBuff[4096];
714        DS_U16 nBuffLen = 0;
715        int iActualStringWidth = DST_GetTextWidth32(strText, nStrLen, this->FontGetSize(this));
716
717        if (width >= iActualStringWidth)
718        {
719                memcpy(strBuff, strText, nStrLen * sizeof(DS_U32));
720                nBuffLen = nStrLen;
721        }
722        else if (width >= this->FontGetDot3Width(this))
723        {
724                int i =1;
725                for (i = 1; i < nStrLen; i++)
726                {
727                        memcpy(strBuff, strText, i * sizeof(DS_U32));
728                        strBuff[i] = (DS_U32)'.';
729                        strBuff[i + 1] = (DS_U32)'.';
730                        strBuff[i + 2] = (DS_U32)'.';
731                        nBuffLen = i + 3;
732                        if (width < DST_GetTextWidth32(strBuff, nBuffLen, this->FontGetSize(this)))
733                        {
734                                strBuff[i - 1] = (DS_U32)'.';
735                                nBuffLen--;
736                                break;
737                        }
738                }
739        }
740        else if (this->rect.w >= this->FontGetDot2Width(this))
741        {
742                        strBuff[0] = (DS_U32)'.';
743                        strBuff[1] = (DS_U32)'.';
744                        nBuffLen = 2;
745        }
746        else
747        {
748                        strBuff[0] = (DS_U32)'.';
749                        nBuffLen = 1;
750        }
751
752        int nWidth;
753
754        // Align 󸮸¦ ÇÑ´Ù.
755        if (nBuffLen == nStrLen)
756            nWidth = iActualStringWidth;
757        else
758        nWidth = DST_GetTextWidth32(strBuff, nBuffLen, this->FontGetSize(this));
759
760  int nHeight = DST_GetTextHeight(this->FontGetSize(this));
761
762  if (nWidth > width) width = nWidth;
763  if (nHeight > height) 
764  {
765        start_y = start_y - (nHeight - height) / 2;
766        if (start_y < 0) start_y =0;
767        height = nHeight;
768  }
769  if (width > this->rect.w) return;
770  if (height > this->rect.h) return;
771  int x_pos = start_x;
772  int y_pos = start_y;
773  switch (this->FontGetHorAlign(this))
774        {
775                case ALIGN_CENTER: x_pos = start_x + (width - nWidth) / 2; break;
776                case ALIGN_RIGHT: x_pos = start_x + width - nWidth; break;
777        }
778        switch (this->FontGetVerAlign(this))
779        {
780                case ALIGN_MIDDLE: y_pos = start_y + (height - nHeight) / 2; break;
781                case ALIGN_BOTTOM: y_pos = start_y + height - nHeight; break;
782        }
783        // ±Û¾¾´Â Ç×»ó ºÒÅõ¸í »öÀ¸·Î
784        OSD_PIXEL_T Color = this->FontGetColor(this);
785        switch(sizeof(OSD_PIXEL_T))
786        {
787                case 2:
788                        Color |= 0xF000;
789                        break;
790                case 4:
791                        Color |= 0xFF000000; // ±Û¾¾´Â Ç×»ó ºÒÅõ¸í »öÀ¸·Î
792                        break;
793        }
794        DST_PrintText(this->GetImgBuff(this), this->rect.w, this->rect.h, x_pos, y_pos,
795                strBuff, nBuffLen, this->FontGetSize(this), Color);
796}
797
798// »ý¼ºÀÚ
799void CWin_CWindow(CWindow* this, SWinEventMsg event)
800{
801        this->eventInit = event;
802        this->rect.x = 0;
803        this->rect.y = 0;
804        this->rect.w = 0;
805        this->rect.h = 0;
806        sprintf(this->strWinName, "No name");
807        this->UnRegisterAllKey(this);
808        this->imgBuff = 0;
809        this->bVisible = true;
810        this->nWinState = 0;
811        this->m_WinIDParent = (WinID)event.data[1];
812        int i = 0;
813        for (i =0; i < TIMER_ID_MAX; i++)
814        {
815                this->TimerTickCount[i] = 0;
816                this->TimerInterval[i] = 0;
817        }
818        this->SetTimeOut(this, 100); // À©µµ¿ì ±âº» ŸÀӾƿô 30ÃÊ
819        this->bTransparentWindow = true;
820        this->bFocus = false;
821//      SetPallette(DST_GetPallette(1));
822       
823        this->FontFont(this,  15, DST_COLOR_BLACK, ALIGN_CENTER, ALIGN_MIDDLE); // ÆùÆ® ÃʱâÈ­
824}
825
826//¼Ò¸êÀÚ
827void CWin_Destructor(CWindow* this)
828{
829        if (this->imgBuff) DST_OS_Free(&this->imgBuff);
830        this->imgBuff = 0;
831        this->UpdateScreen(this);
832}
833
834void CWin_SetTimeOut(CWindow* this, int nSecond)
835{
836        this->SetTimer(this, 0, nSecond * 1000);
837}
838
839DS_U32 CWin_GetTimeOut(CWindow* this)
840{
841        if (this->TimerInterval[0] == 0) return 0;
842        return this->TimerInterval[0] / DST_OS_GetTicksPerSecond();
843}
844
845void CWin_SetTimer(CWindow* this, char nID, int ms)
846{
847        this->ResetTimer(this, nID);
848        if (ms >= 1 && ms <= 9) ms = 10; // 10ms ÀÌÇÏÀÇ ½Ã°£ÀÌ µé¾î¿Â °æ¿ì
849        this->TimerInterval[(int)nID] = ms * DST_OS_GetTicksPerSecond()/1000;
850}
851
852void CWin_ResetTimer(CWindow* this, char nID)
853{
854        this->TimerTickCount[(int)nID] = DST_OS_GetTickCount();
855}
856
857void CWin_KillTimer(CWindow* this, char nID)
858{
859        this->TimerTickCount[(int)nID] = 0;
860}
861
862bool CWin_ProcessTimer(CWindow* this)
863{
864        char i = 0;
865        for (i =0; i < TIMER_ID_MAX; i++)
866        {
867                if (i == 0) // ÀÚ½Ä À©µµ¿ì°¡ ÀÖ´Ù¸é ÀÚ±â ÀÚ½ÅÀÇ Å¸ÀӾƿôÀÌ °è¼Ó ¿¬ÀåµÈ´Ù.
868                {
869                        int j=0;
870                        for (j = 0; j < WIN_ID_MAX; j++)
871                        {
872                                CWindow *pWin = DST_GetWin((WinID)j);
873                                if (pWin == 0) continue;
874                                if (pWin->GetParentWinID(pWin) != this->GetWinID(this)) continue;
875                                this->TimerTickCount[0] = DST_OS_GetTickCount();
876                                break;
877                        }
878                }
879                if (this->TimerTickCount[(int)i]== 0) continue;
880                if (this->TimerInterval[(int)i]== 0) continue;
881                if (DST_OS_GetTickCount() < this->TimerTickCount[(int)i]) this->TimerTickCount[(int)i] = DST_OS_GetTickCount();
882                if (this->TimerTickCount[(int)i] + this->TimerInterval[(int)i] > DST_OS_GetTickCount()) continue;
883                this->DoOnTimer(this, i);
884                return true;
885        }
886        return false;
887}
888
889void CWin_CloseParents(CWindow* this, CWindow* pWin)
890{
891        CWindow *pWinParent = DST_GetWin(pWin->GetParentWinID(pWin));
892        if (pWinParent)
893        {
894                this->CloseParents(this, pWinParent);
895        }
896        pWin->Close(pWin);
897}
898
899void CWin_DoOnTimer(CWindow* this, char nID)
900{
901        if (nID == 0) //0¹ø ŸÀ̸Ӵ À©µµ¿ì ŸÀÓ ¾Æ¿ô ¿ëµµ·Î »ç¿ëÇÑ´Ù.
902        {
903                this->CloseParents(this, this);
904        }
905        else
906        {
907                this->OnTimer(this, nID);
908                if (this->TimerTickCount[(int)nID] != 0) // KillTimer·Î ÀÌ Å¸À̸Ӹ¦ ²ôÁö ¾Ê¾Ò´Ù¸é ¸®¼Â½ÃŲ´Ù.
909                {
910                        this->ResetTimer(this, nID);
911                }
912        }
913}
914
915void CWin_SetParentWinID(CWindow* this, WinID nID)
916{
917        this->m_WinIDParent = nID;
918}
919
920WinID CWin_GetParentWinID(CWindow* this)
921{
922        return this->m_WinIDParent;
923}
924
925WinID CWin_GetWinID(CWindow* this)
926{
927        return (WinID)(this->eventInit.data[0]);
928}
929
930void CWin_DoFocus(CWindow* this, bool bVal)
931{
932        this->bFocus = bVal;
933        this->Focus(this, bVal);
934}
935
936void CWin_SetSize(CWindow* this, int x, int y, int w, int h)
937{
938        this->rect.x = x;
939        this->rect.y = y;
940        this->rect.w = w;
941        this->rect.h = h;
942}
943
944int CWin_GetState(CWindow* this)
945{
946        return this->nWinState;
947}
948
949void CWin_SetState(CWindow* this, int n)
950{
951        this->nWinState = n;
952}
953
954void CWin_DoOnMessage(CWindow* this, SWinEventMsg event)
955{
956        return this->OnMessage(this, event);
957}
958
959void CWin_DoShow(CWindow* this)
960{
961        if (this->rect.w == 0) return;
962        if (this->rect.h == 0) return;
963        if (this->imgBuff != 0) DST_OS_Free(&this->imgBuff);
964        this->imgBuff = (OSD_PIXEL_T*)DST_OS_Malloc(sizeof(OSD_PIXEL_T) * ((this->rect.w) * (this->rect.h)));
965        memset(this->imgBuff, 0, (this->rect.w) * (this->rect.h)*sizeof(OSD_PIXEL_T));
966        this->bVisible = true;
967        this->Show(this);
968        this->UpdateScreen(this);
969}
970
971bool CWin_GetVisible(CWindow* this)
972{
973        return this->bVisible;
974}
975
976void CWin_FocusToParent(CWindow* this)
977{
978        this->FocusToChild(this, this->GetParentWinID(this));
979}
980
981void CWin_FocusToChild(CWindow* this, WinID nID)
982{
983        CWindow *pWin = DST_GetWin(nID);
984        if (pWin == 0) return;
985        this->DoFocus(this, false);
986        pWin->DoFocus(pWin, true);
987}
988
989void CWin_setFontStyle(CWindow* this, DS_U8 size, DS_U32 color, DS_U8 ver_align, DS_U8 hor_align)
990{
991        this->FontSetHorAlign(this, hor_align);
992        this->FontSetVerAlign(this, ver_align);
993        this->FontSetSize(this, size);
994        this->FontSetColor(this, CONV32_16(color));
995}
996
997void CWin_SetTransparent(CWindow* this, bool bValue)
998{
999        this->bTransparentWindow = bValue;
1000}
1001
1002bool CWin_GetTransparent(CWindow* this)
1003{
1004        return this->bTransparentWindow;
1005}
1006
1007void CWin_OnMessage(CWindow* this, SWinEventMsg event)
1008{
1009       
1010}
1011
1012void CWin_Show(CWindow* this)
1013{
1014       
1015}
1016
1017void CWin_ShowWindow(CWindow* this, WinID id)
1018{
1019       
1020}
1021
1022        // Hide
1023void CWin_Hide(CWindow* this, WinID id)
1024{
1025       
1026}
1027
1028void CWin_Focus(CWindow* this, bool bFocus)
1029{
1030       
1031}
1032
1033        // ±×¸®±â
1034DST_RECT CWin_GetSize(CWindow* this)
1035{
1036        return this->rect;
1037}
1038
1039DS_U32 CWin_GetKeyDelay(CWindow* this, DS_U8 KeyCode)
1040{
1041        return this->nKeyDelay[KeyCode];
1042}
1043
1044DS_U32 CWin_GetKeyRepeat(CWindow* this, DS_U8 KeyCode)
1045{
1046        return this->nKeyRepeat[KeyCode];
1047}
1048
1049void CWin_KeyInput(CWindow* this, DS_U8 key, bool bRepeat)
1050{
1051       
1052}
1053       
1054void CWin_OnTimer(CWindow* this, char nID)
1055{
1056       
1057}
1058
1059// ±âº» À©µµ¿ì¸¦ »ý¼ºÇÑ´Ù.
1060CWindow* NewCWindow(SWinEventMsg event)
1061{
1062        CWindow* pWin= (CWindow *)DST_OS_Calloc(sizeof(CWindow), 1);
1063        pWin->FontFont = CFont_CFont; 
1064        pWin->FontSetSize = CFont_SetSize;
1065        pWin->FontGetDot1Width = CFont_GetDot1Width;
1066        pWin->FontGetDot2Width = CFont_GetDot2Width;
1067        pWin->FontGetDot3Width = CFont_GetDot3Width;
1068        pWin->FontGetSize = CFont_GetSize;
1069        pWin->FontSetColor = CFont_SetColor;
1070        pWin->FontGetColor = CFont_GetColor;
1071        pWin->FontSetHorAlign = CFont_SetHorAlign;
1072        pWin->FontGetHorAlign = CFont_GetHorAlign;
1073        pWin->FontSetVerAlign = CFont_SetVerAlign;
1074        pWin->FontGetVerAlign = CFont_GetVerAlign;
1075       
1076        pWin->Constructor = CWin_CWindow;
1077//      pWin->Destructor = CWin_Destructor;  // CWindow ÀÚ½Ä À©µµ¿ìÀÇ ¼Ò¸êÀÚ
1078        pWin->DestructorMother = CWin_Destructor; // CWindow ÀÇ ¼Ò¸êÀÚ
1079        pWin->SetParentWinID = CWin_SetParentWinID;
1080        pWin->GetParentWinID = CWin_GetParentWinID;
1081        pWin->GetWinID = CWin_GetWinID;
1082        pWin->SetSize = CWin_SetSize;
1083        pWin->GetState = CWin_GetState;
1084        pWin->SetState = CWin_SetState;
1085        pWin->SetWinName = CWin_SetWinName;
1086        pWin->SetTransparent = CWin_SetTransparent;
1087        pWin->GetTransparent = CWin_GetTransparent;
1088        pWin->DoOnMessage = CWin_DoOnMessage;
1089        pWin->OnMessage = CWin_OnMessage;
1090        pWin->DoShow = CWin_DoShow;
1091        pWin->Show = CWin_Show;
1092        pWin->ShowWindow = CWin_ShowWindow;
1093        pWin->Hide = CWin_Hide;
1094        pWin->Close = CWin_Close;
1095        pWin->CloseParents = CWin_CloseParents;
1096        pWin->SetVisible = CWin_SetVisible;
1097        pWin->GetVisible = CWin_GetVisible;
1098        pWin->Move = CWin_Move;
1099        pWin->FocusToParent = CWin_FocusToParent;
1100        pWin->FocusToChild = CWin_FocusToChild;
1101        pWin->DoFocus = CWin_DoFocus;
1102        pWin->Focus = CWin_Focus;
1103        pWin->GetSize = CWin_GetSize;
1104        pWin->GetImgBuff = CWin_GetImgBuff;
1105        pWin->UpdateScreen = CWin_UpdateScreen;
1106        pWin->UpdateScreenEx = CWin_UpdateScreenEx;
1107        pWin->DrawPixel = CWin_DrawPixel;
1108        pWin->DrawBox32 = CWin_DrawBox32;
1109        pWin->DrawImage = CWin_DrawImage;
1110//      pWin->DrawImage4 = CWin_DrawImage4;
1111//      pWin->DrawImage5 = CWin_DrawImage5;
1112//      pWin->DrawImage6 = CWin_DrawImage6;
1113        pWin->setFontStyle = CWin_setFontStyle;
1114        pWin->DrawText = CWin_DrawText;
1115        pWin->DrawTextUTF8 = CWin_DrawTextUTF8;
1116        pWin->DrawTextUni = CWin_DrawTextUni;
1117        pWin->DrawText32 = CWin_DrawText32;
1118        pWin->RegisterAllKey = CWin_RegisterAllKey;
1119        pWin->UnRegisterAllKey = CWin_UnRegisterAllKey;
1120//      pWin->RegisterAllNumKey = CWin_RegisterAllNumKey;
1121//      pWin->UnRegisterAllNumKey = CWin_UnRegisterAllNumKey;
1122        pWin->RegisterKey = CWin_RegisterKey;
1123        pWin->IsRegisterKey = CWin_IsRegisterKey;
1124        pWin->GetKeyDelay = CWin_GetKeyDelay;
1125        pWin->GetKeyRepeat = CWin_GetKeyRepeat;
1126        pWin->KeyInput = CWin_KeyInput;
1127        pWin->SetTimeOut = CWin_SetTimeOut;
1128        pWin->GetTimeOut = CWin_GetTimeOut;
1129        pWin->SetTimer = CWin_SetTimer;
1130        pWin->ResetTimer = CWin_ResetTimer;
1131        pWin->KillTimer = CWin_KillTimer;
1132        pWin->ProcessTimer = CWin_ProcessTimer;
1133        pWin->DoOnTimer = CWin_DoOnTimer;
1134        pWin->OnTimer = CWin_OnTimer; 
1135       
1136        // »ý¼ºÀÚ È£Ãâ
1137        pWin->Constructor(pWin, event);
1138        return pWin;
1139}
1140
1141// ¼Ò¸êÀÚ È£Ãâ
1142void DeleteCWindow(CWindow*pWin)
1143{
1144        if (pWin == 0) return;
1145        if (pWin->Destructor) pWin->Destructor(pWin);
1146        if (pWin->DestructorMother) pWin->DestructorMother(pWin);
1147        DST_OS_Free(&pWin);
1148}
Note: See TracBrowser for help on using the repository browser.