source: svn/trunk/zasc/app/DST_WinPowerDownCaution.cpp @ 2

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

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 2.8 KB
Line 
1#include "DST_WinManager.h"
2#include "DST_OSDImage.h"
3#include "DST_UserInterface.h"
4#include "DST_DataStrings.h"
5
6#if 0
7____CPowerDownCautionWin___()
8#endif
9
10#define MAX_SECONDS 60
11class CPowerDownCautionWin : public CWindow
12{
13private:
14        bool needShutDown;
15        int nMaxWidth;
16        int nCoundDown;
17public:
18        CPowerDownCautionWin(SWinEventMsg event):CWindow(event)
19        {
20                setFontStyle(20, 0xFFC8C8C8, ALIGN_MIDDLE,ALIGN_LEFT);
21                needShutDown = false;
22                nMaxWidth = 0;
23                nCoundDown = MAX_SECONDS;
24                GetTextNWidth(&nMaxWidth,nCoundDown,font.GetSize());
25
26                rect.w = 9+DST_GetImageWidth(bracon_gui_caution)+10+nMaxWidth+10;
27                rect.h = 92;
28                rect.x = (DST_GetScreenWidth() - rect.w) / 2;
29                rect.y = DST_GetScreenHeight()*9/10 - rect.h;
30
31                SetTimeOut(0);
32        }
33        virtual void OnMessage(SWinEventMsg event)
34        {
35                switch (event.cmd)
36                {
37                        case WM_POWER_OFF:
38                                Close();
39                                break;
40                }
41        }
42        virtual ~CPowerDownCautionWin()
43        {
44                if(needShutDown) DST_SendWindowEventWithOnlyCmd(WM_POWER_OFF);
45        }
46       
47        DS_U16* GetTextNWidth(int *textWidth, int countDown, int fontSize)
48        {
49                static DS_U16   final[100];
50                memset(final,0,sizeof(final));
51                strcpy16(final, (countDown>1)?pz_PowerDownCountDown_P1[OSD_Lang]:pz_PowerDownCountDown_S1[OSD_Lang]);
52                char  tmpStr[10];
53                memset(tmpStr,0,sizeof(tmpStr));
54                sprintf(tmpStr," %d ", countDown);
55                str2uni(&final[strlen16(final)], (char *)tmpStr);
56                strcpy16(&final[strlen16(final)], (countDown>1)?pz_PowerDownCountDown_P2[OSD_Lang]:pz_PowerDownCountDown_S2[OSD_Lang]);
57
58                *textWidth = DST_GetTextWidthUni(final,fontSize);
59
60                int nStrLen = 0;
61                for(int i=0;i<100;i++)
62                {
63                        if(final[i]==0) break;
64                        nStrLen++;
65                }
66                DS_U16* fianlStr = (DS_U16*)DST_OS_Malloc((nStrLen+1) * sizeof(DS_U16));
67                memset(fianlStr, 0, (nStrLen+1) * sizeof(DS_U16));
68                memcpy(fianlStr,final,(nStrLen+1) * sizeof(DS_U16));
69                return fianlStr;
70       
71        }
72       
73        virtual void Show(WinID id)
74        {
75                DST_Printf("id=%d\n",id);
76                switch(id)
77                {
78                        case WIN_ERROR:
79                        case WIN_POWER_DOWN_CAUTION:
80                                break;
81                        default:
82                                KillTimer(1);
83                                Close();
84                                break;
85                }
86        }
87
88        virtual void Show()
89        {
90
91                DrawBox32(0, 0, rect.w, rect.h, CONV32_16(0xFF262626));
92                DrawImage(9, 9, bracon_gui_caution,true);
93               
94                int nWidth = 0;
95                DS_U16* str = GetTextNWidth(&nWidth, nCoundDown, font.GetSize());               
96                DrawTextUni(9+DST_GetImageWidth(bracon_gui_caution)+10, 0, nMaxWidth, rect.h, str, &font); 
97                DST_OS_Free(&str);
98                SetTimer(1, 1000);
99
100        }       
101
102        virtual void OnTimer(char nID)
103        {
104                switch(nID)
105                {
106                        case 1:
107                                KillTimer(1);
108                                UpdateScreen();
109                                nCoundDown--;
110                                if(nCoundDown == 0)
111                                {
112                                        needShutDown = true;
113                                        Close();
114                                        return;
115                                }
116                                Show();
117                                UpdateScreen();
118                                break;
119                }
120        }       
121
122};
123
124
125void DST_CreatePowerDownCautionWin(SWinEventMsg event)
126{
127        DST_AddWin((WinID)(event.data[0]), new CPowerDownCautionWin(event));
128}
129
Note: See TracBrowser for help on using the repository browser.