diff options
Diffstat (limited to 'uisimulator/win32/uisw32.cpp')
-rw-r--r-- | uisimulator/win32/uisw32.cpp | 259 |
1 files changed, 259 insertions, 0 deletions
diff --git a/uisimulator/win32/uisw32.cpp b/uisimulator/win32/uisw32.cpp new file mode 100644 index 0000000000..6bc1bedb00 --- /dev/null +++ b/uisimulator/win32/uisw32.cpp | |||
@@ -0,0 +1,259 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2002 by Felix Arends | ||
10 | * | ||
11 | * All files in this archive are subject to the GNU General Public License. | ||
12 | * See the file COPYING in the source tree root for full license agreement. | ||
13 | * | ||
14 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
15 | * KIND, either express or implied. | ||
16 | * | ||
17 | ****************************************************************************/ | ||
18 | |||
19 | #include <windows.h> | ||
20 | #include <process.h> | ||
21 | #include "uisw32.h" | ||
22 | #include "resource.h" | ||
23 | |||
24 | // extern functions | ||
25 | extern void main (void *); // mod entry point | ||
26 | |||
27 | // variables | ||
28 | HWND hGUIWnd; // the GUI window handle | ||
29 | unsigned int uThreadID; // id of mod thread | ||
30 | PBYTE lpKeys; | ||
31 | |||
32 | // GUIWndProc | ||
33 | // window proc for GUI simulator | ||
34 | LRESULT GUIWndProc ( | ||
35 | HWND hWnd, | ||
36 | UINT uMsg, | ||
37 | WPARAM wParam, | ||
38 | LPARAM lParam | ||
39 | ) | ||
40 | { | ||
41 | static HBITMAP hBkgnd; | ||
42 | static lpBmp [UI_WIDTH * UI_HEIGHT * 3]; | ||
43 | static HDC hMemDc; | ||
44 | |||
45 | switch (uMsg) | ||
46 | { | ||
47 | case WM_CREATE: | ||
48 | // load background image | ||
49 | hBkgnd = (HBITMAP)LoadImage (GetModuleHandle (NULL), MAKEINTRESOURCE(IDB_UI), | ||
50 | IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); | ||
51 | hMemDc = CreateCompatibleDC (GetDC (hWnd)); | ||
52 | SelectObject (hMemDc, hBkgnd); | ||
53 | return TRUE; | ||
54 | case WM_SIZING: | ||
55 | { | ||
56 | LPRECT r = (LPRECT)lParam; | ||
57 | RECT r2; | ||
58 | char s[256]; | ||
59 | int v; | ||
60 | |||
61 | switch (wParam) | ||
62 | { | ||
63 | case WMSZ_BOTTOM: | ||
64 | v = (r->bottom - r->top) / (UI_HEIGHT / 5); | ||
65 | r->bottom = r->top + v * UI_HEIGHT / 5; | ||
66 | r->right = r->left + v * UI_WIDTH / 5; | ||
67 | r->right += GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
68 | r->bottom += GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
69 | break; | ||
70 | case WMSZ_RIGHT: | ||
71 | v = (r->right - r->left) / (UI_WIDTH / 5); | ||
72 | r->bottom = r->top + v * UI_HEIGHT / 5; | ||
73 | r->right = r->left + v * UI_WIDTH / 5; | ||
74 | r->right += GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
75 | r->bottom += GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
76 | break; | ||
77 | case WMSZ_TOP: | ||
78 | v = (r->bottom - r->top) / (UI_HEIGHT / 5); | ||
79 | r->top = r->bottom - v * UI_HEIGHT / 5; | ||
80 | r->right = r->left + v * UI_WIDTH / 5; | ||
81 | r->right += GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
82 | r->top -= GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
83 | break; | ||
84 | case WMSZ_LEFT: | ||
85 | v = (r->right - r->left) / (UI_WIDTH / 5); | ||
86 | r->bottom = r->top + v * UI_HEIGHT / 5; | ||
87 | r->left = r->right - v * UI_WIDTH / 5; | ||
88 | r->left -= GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
89 | r->bottom += GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
90 | break; | ||
91 | case WMSZ_BOTTOMRIGHT: | ||
92 | GetWindowRect (hWnd, &r2); | ||
93 | if (abs(r2.right - r->right) > abs(r2.bottom - r->bottom)) | ||
94 | v = (r->right - r->left) / (UI_WIDTH / 5); | ||
95 | else | ||
96 | v = (r->bottom - r->top) / (UI_HEIGHT / 5); | ||
97 | r->bottom = r->top + v * UI_HEIGHT / 5; | ||
98 | r->right = r->left + v * UI_WIDTH / 5; | ||
99 | r->right += GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
100 | r->bottom += GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
101 | break; | ||
102 | case WMSZ_BOTTOMLEFT: | ||
103 | GetWindowRect (hWnd, &r2); | ||
104 | if (abs(r2.left - r->left) > abs(r2.bottom - r->bottom)) | ||
105 | v = (r->right - r->left) / (UI_WIDTH / 5); | ||
106 | else | ||
107 | v = (r->bottom - r->top) / (UI_HEIGHT / 5); | ||
108 | r->bottom = r->top + v * UI_HEIGHT / 5; | ||
109 | r->left = r->right - v * UI_WIDTH / 5; | ||
110 | r->left -= GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
111 | r->bottom += GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
112 | break; | ||
113 | case WMSZ_TOPRIGHT: | ||
114 | GetWindowRect (hWnd, &r2); | ||
115 | if (abs(r2.right - r->right) > abs(r2.top - r->top)) | ||
116 | v = (r->right - r->left) / (UI_WIDTH / 5); | ||
117 | else | ||
118 | v = (r->bottom - r->top) / (UI_HEIGHT / 5); | ||
119 | r->top = r->bottom - v * UI_HEIGHT / 5; | ||
120 | r->right = r->left + v * UI_WIDTH / 5; | ||
121 | r->right += GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
122 | r->top -= GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
123 | break; | ||
124 | case WMSZ_TOPLEFT: | ||
125 | GetWindowRect (hWnd, &r2); | ||
126 | if (abs(r2.left - r->left) > abs(r2.top - r->top)) | ||
127 | v = (r->right - r->left) / (UI_WIDTH / 5); | ||
128 | else | ||
129 | v = (r->bottom - r->top) / (UI_HEIGHT / 5); | ||
130 | r->top = r->bottom - v * UI_HEIGHT / 5; | ||
131 | r->left = r->right - v * UI_WIDTH / 5; | ||
132 | r->left -= GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
133 | r->top -= GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
134 | break; | ||
135 | } | ||
136 | |||
137 | wsprintf (s, "RockBox Simulator @%d%%", | ||
138 | (r->right - r->left - GetSystemMetrics (SM_CXSIZEFRAME) * 2) | ||
139 | * 100 / UI_WIDTH); | ||
140 | SetWindowText (hWnd, s); | ||
141 | |||
142 | return TRUE; | ||
143 | } | ||
144 | case WM_ERASEBKGND: | ||
145 | { | ||
146 | PAINTSTRUCT ps; | ||
147 | HDC hDc = BeginPaint (hWnd, &ps); | ||
148 | RECT r; | ||
149 | |||
150 | GetClientRect (hWnd, &r); | ||
151 | // blit to screen | ||
152 | StretchBlt (hDc, 0, 0, r.right, r.bottom, | ||
153 | hMemDc, 0, 0, UI_WIDTH, UI_HEIGHT, SRCCOPY); | ||
154 | EndPaint (hWnd, &ps); | ||
155 | return TRUE; | ||
156 | } | ||
157 | case WM_PAINT: | ||
158 | { | ||
159 | PAINTSTRUCT ps; | ||
160 | RECT r; | ||
161 | HDC hDc = BeginPaint (hWnd, &ps); | ||
162 | |||
163 | GetClientRect (hWnd, &r); | ||
164 | // draw lcd screen | ||
165 | StretchDIBits (hDc, | ||
166 | UI_LCD_POSX * r.right / UI_WIDTH, UI_LCD_POSY * r.bottom / UI_HEIGHT, | ||
167 | DISP_X * r.right / UI_WIDTH, DISP_Y * r.bottom / UI_HEIGHT, | ||
168 | 0, 0, DISP_X, DISP_Y, | ||
169 | bitmap, (BITMAPINFO *) &bmi, DIB_RGB_COLORS, SRCCOPY); | ||
170 | |||
171 | EndPaint (hWnd, &ps); | ||
172 | return TRUE; | ||
173 | } | ||
174 | case WM_CLOSE: | ||
175 | // close simulator | ||
176 | hGUIWnd = NULL; | ||
177 | PostQuitMessage (0); | ||
178 | break; | ||
179 | } | ||
180 | |||
181 | return DefWindowProc (hWnd, uMsg, wParam, lParam); | ||
182 | } | ||
183 | |||
184 | // GUIStartup | ||
185 | // register window class, show window, init GUI | ||
186 | BOOL GUIStartup () | ||
187 | { | ||
188 | WNDCLASS wc; | ||
189 | |||
190 | // create window class | ||
191 | ZeroMemory (&wc, sizeof(wc)); | ||
192 | wc.hbrBackground = GetSysColorBrush (COLOR_WINDOW); | ||
193 | wc.hCursor = LoadCursor (NULL, IDC_ARROW); | ||
194 | wc.hInstance = GetModuleHandle (NULL); | ||
195 | wc.lpfnWndProc = (WNDPROC)GUIWndProc; | ||
196 | wc.lpszClassName = "RockBoxUISimulator"; | ||
197 | wc.style = CS_HREDRAW | CS_VREDRAW; | ||
198 | |||
199 | if (RegisterClass (&wc) == 0) | ||
200 | return FALSE; | ||
201 | |||
202 | // create window | ||
203 | hGUIWnd = CreateWindowEx ( | ||
204 | WS_EX_TOOLWINDOW | WS_EX_PALETTEWINDOW, | ||
205 | "RockBoxUISimulator", "ARCHOS JukeBox", | ||
206 | WS_VISIBLE | WS_SYSMENU | WS_OVERLAPPEDWINDOW, | ||
207 | CW_USEDEFAULT, CW_USEDEFAULT, | ||
208 | UI_WIDTH + GetSystemMetrics (SM_CXSIZEFRAME) * 2, | ||
209 | UI_HEIGHT + GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION), | ||
210 | NULL, NULL, GetModuleHandle (NULL), NULL); | ||
211 | |||
212 | if (hGUIWnd == NULL) | ||
213 | return FALSE; | ||
214 | |||
215 | return TRUE; | ||
216 | } | ||
217 | |||
218 | // GUIDown | ||
219 | // destroy window, unregister window class | ||
220 | int GUIDown () | ||
221 | { | ||
222 | DestroyWindow (hGUIWnd); | ||
223 | _endthreadex (uThreadID); | ||
224 | return 0; | ||
225 | } | ||
226 | |||
227 | // GUIMessageLoop | ||
228 | // standard message loop for GUI window | ||
229 | void GUIMessageLoop () | ||
230 | { | ||
231 | MSG msg; | ||
232 | while (GetMessage (&msg, hGUIWnd, 0, 0) && hGUIWnd != NULL) | ||
233 | { | ||
234 | TranslateMessage (&msg); | ||
235 | DispatchMessage (&msg); | ||
236 | } | ||
237 | } | ||
238 | |||
239 | |||
240 | // WinMain | ||
241 | // program entry point | ||
242 | int WINAPI WinMain ( | ||
243 | HINSTANCE hInstance, // current instance | ||
244 | HINSTANCE hPrevInstance, // previous instance | ||
245 | LPSTR lpCmd, // command line | ||
246 | int nShowCmd // show command | ||
247 | ) | ||
248 | { | ||
249 | if (!GUIStartup ()) | ||
250 | return 0; | ||
251 | |||
252 | uThreadID = _beginthread (main, 0, NULL); | ||
253 | if (uThreadID == -0L) | ||
254 | return MessageBox (NULL, "Error creating mod thread!", "Error", MB_OK); | ||
255 | |||
256 | GUIMessageLoop (); | ||
257 | |||
258 | return GUIDown (); | ||
259 | } \ No newline at end of file | ||