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