OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [mw/] [src/] [demos/] [mwin/] [mdemo.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * Copyright (c) 1999, 2000, 2001 Greg Haerr <greg@censoft.com>
3
 *
4
 * Demo program for Microwindows
5
 */
6
#define MWINCLUDECOLORS
7
#include "windows.h"
8
#include "wintern.h"            /* for MwSetDesktopWallpaper*/
9
 
10
#include "device.h"
11
 
12
#if DOS_TURBOC
13
unsigned _stklen = 4096;
14
#endif
15
 
16
#define CLIPDEMO        0        /* set for region clipping demo*/
17
 
18
#ifndef ELKS
19
#define TIMERDEMO       1       /* set for WM_TIMER demo*/
20
#define GRAPH3D         0        /* 3d graphics demo*/
21
#define IMAGE           0        /* 256 color image demo*/
22
#endif
23
#define ARCDEMO         1       /* arc drawing demo*/
24
#define CHILD           1       /* child window demo*/
25
#define CLIENT3D        0        /* old client draw test*/
26
#define USEBLIT         1       /* use blit rather than DrawDIB()*/
27
 
28
#if GRAPH3D
29
#include "graph3d.h"
30
#endif
31
 
32
extern MWIMAGEHDR image_car8;
33
extern MWIMAGEHDR image_zion208;
34
extern MWIMAGEHDR image_penguin;
35
extern MWIMAGEHDR image_under4;
36
extern MWIMAGEHDR image_microwin;
37
extern MWIMAGEHDR image_cs1;
38
extern MWIMAGEHDR image_rle8;
39
 
40
#if CHILD
41
#if ELKS | MSDOS
42
PMWIMAGEHDR image = &image_cs1;         /* 2 color bitmap for 16 color systems*/
43
#else
44
PMWIMAGEHDR image = &image_penguin;
45
#endif
46
#endif
47
 
48
#if IMAGE
49
PMWIMAGEHDR image2 = &image_zion208;
50
#endif
51
 
52
#define APPCLASS        "test"
53
#define APPCHILD        "test2"
54
 
55
/* forward decls*/
56
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wp,LPARAM lp);
57
LRESULT CALLBACK ChildWndProc(HWND hwnd,UINT uMsg,WPARAM wp,LPARAM lp);
58
 
59
int
60
MwUserInit(int ac, char **av)
61
{
62
        /* test user init procedure - do nothing*/
63
        return 0;
64
}
65
 
66
int
67
RegisterAppClass(void)
68
{
69
        WNDCLASS        wc;
70
 
71
#if !ELKS
72
        MwRegisterButtonControl(NULL);
73
        MwRegisterEditControl(NULL);
74
        MwRegisterListboxControl(NULL);
75
        MwRegisterProgressBarControl(NULL);
76
        /*MwRegisterComboboxControl(NULL);*/
77
#endif
78
        wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;
79
        wc.lpfnWndProc = (WNDPROC)WndProc;
80
        wc.cbClsExtra = 0;
81
        wc.cbWndExtra = 0;
82
        wc.hInstance = 0;
83
        wc.hIcon = 0; /*LoadIcon(GetHInstance(), MAKEINTRESOURCE( 1));*/
84
        wc.hCursor = 0; /*LoadCursor(NULL, IDC_ARROW);*/
85
        wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
86
        wc.lpszMenuName = NULL;
87
        wc.lpszClassName =  APPCLASS;
88
        RegisterClass( &wc);
89
 
90
#if CHILD
91
        wc.lpfnWndProc = (WNDPROC)ChildWndProc;
92
        wc.lpszClassName =  APPCHILD;
93
        return RegisterClass( &wc);
94
#endif
95
        return 1;
96
}
97
 
98
HWND
99
CreateAppWindow(void)
100
{
101
        HWND    hwnd, hlist;
102
        static int nextid = 1;
103
        int width, height;
104
        RECT r;
105
        GetWindowRect(GetDesktopWindow(), &r);
106
        width = height = r.right / 2;
107
 
108
        hwnd = CreateWindowEx(0L, APPCLASS,
109
                "Microwindows Application",
110
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
111
                CW_USEDEFAULT, CW_USEDEFAULT,
112
                width, height,
113
                NULL, (HMENU)nextid++, NULL, NULL);
114
 
115
#if CHILD
116
        if(hwnd
117
#if GRAPH3D
118
                        && (nextid & 03)!=2
119
#endif
120
                                                                ) {
121
                CreateWindowEx(0L, APPCHILD,
122
                        "",
123
                        WS_BORDER | WS_CHILD | WS_VISIBLE,
124
                        4, 4, width / 3-6, height / 3,
125
                        hwnd, (HMENU)2, NULL, NULL);
126
                CreateWindowEx(0L, APPCHILD,
127
                        "",
128
                        WS_BORDER | WS_CHILD | WS_VISIBLE,
129
                        width / 3, height / 3, width / 3-6, height / 3,
130
                        hwnd, (HMENU)3, NULL, NULL);
131
                CreateWindowEx(0L, APPCHILD,
132
                        "",
133
                        WS_BORDER | WS_CHILD | WS_VISIBLE,
134
                        width * 3 / 5, height * 3 / 5,
135
                        width * 2 / 3, height * 2 / 3,
136
                        hwnd, (HMENU)4, NULL, NULL);
137
                CreateWindowEx(0L, "EDIT",
138
                        "OK",
139
                        WS_BORDER|WS_CHILD | WS_VISIBLE,
140
                        width * 5 / 8, 10, 100, 18,
141
                        hwnd, (HMENU)5, NULL, NULL);
142
                CreateWindowEx(0L, "PROGBAR",
143
                        "OK",
144
                        WS_BORDER|WS_CHILD | WS_VISIBLE,
145
                        width * 5 / 8, 32, 100, 18,
146
                        hwnd, (HMENU)6, NULL, NULL);
147
 
148
                hlist = CreateWindowEx(0L, "LISTBOX",
149
                        "OK",
150
                        WS_HSCROLL|WS_VSCROLL|WS_BORDER|WS_CHILD | WS_VISIBLE,
151
                        width * 5 / 8, 54, 100, 48,
152
                        hwnd, (HMENU)7, NULL, NULL);
153
                SendMessage(hlist, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Cherry");
154
                SendMessage(hlist, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Apple");
155
                SendMessage(hlist, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"Orange");
156
 
157
                CreateWindowEx(0L, "BUTTON",
158
                        "Cancel",
159
                        BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE,
160
                        width * 5 / 8 + 50, 106, 50, 14,
161
                        hwnd, (HMENU)8, NULL, NULL);
162
        }
163
#endif
164
        return hwnd;
165
}
166
 
167
#if CHILD
168
LRESULT CALLBACK
169
ChildWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
170
{
171
        RECT            rc;
172
        PAINTSTRUCT     ps;
173
 
174
        switch(msg) {
175
        case WM_PAINT:
176
                BeginPaint(hwnd, &ps);
177
                GetClientRect(hwnd, &rc);
178
#if USEBLIT
179
{
180
                HDC             hdcMem;
181
                HBITMAP         hbmp, hbmpOrg;
182
 
183
                /* redirect painting to offscreen dc, then use blit function*/
184
                hdcMem = CreateCompatibleDC(ps.hdc);
185
                hbmp = CreateCompatibleBitmap(hdcMem, rc.right, rc.bottom);
186
                hbmpOrg = SelectObject(hdcMem, hbmp);
187
 
188
                /* draw onto offscreen dc*/
189
                DrawDIB(hdcMem, 0, 0, image);
190
 
191
                /* blit offscreen with physical screen*/
192
                BitBlt(ps.hdc, 0, 0, rc.right, rc.bottom, hdcMem,
193
                        0, 0, MWROP_SRCCOPY);
194
                /*StretchBlt(ps.hdc, 0, 0, rc.right, rc.bottom, hdcMem,
195
                        0, 0, image->width/3*5, image->height/3*4, MWROP_SRCCOPY);*/
196
                DeleteObject(SelectObject(hdcMem, hbmpOrg));
197
                DeleteDC(hdcMem);
198
}
199
#else
200
                DrawDIB(ps.hdc, rc.left, rc.top, image);
201
#endif
202
                EndPaint(hwnd, &ps);
203
                break;
204
        default:
205
                return DefWindowProc( hwnd, msg, wp, lp);
206
        }
207
        return( 0);
208
}
209
#endif
210
 
211
LRESULT CALLBACK
212
WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
213
{
214
        PAINTSTRUCT     ps;
215
        HDC             hdc;
216
#if CLIENT3D | IMAGE | GRAPH3D
217
        RECT            rc;
218
#endif
219
#if GRAPH3D
220
        static int      countup = 1;
221
        int             id;
222
        static vec1     gx, gy;
223
#endif
224
#if TIMERDEMO
225
        static POINT    mousept;
226
#endif
227
#if ARCDEMO
228
        static int      startdegrees = 0;
229
        static int      enddegrees = 30;
230
#endif
231
 
232
        switch( msg) {
233
#if TIMERDEMO
234
        case WM_CREATE:
235
                SetTimer(hwnd, 1, 100, NULL);
236
                mousept.x = 60;
237
                mousept.y = 20;
238
                break;
239
 
240
        case WM_TIMER:
241
#if GRAPH3D
242
                GetClientRect(hwnd, &rc);
243
                if(countup) {
244
                        mousept.y += 20;
245
                        if(mousept.y >= rc.bottom) {
246
                                mousept.y -= 20;
247
                                countup = 0;
248
                        }
249
                } else {
250
                        mousept.y -= 20;
251
                        if(mousept.y < 20) {
252
                                mousept.y += 20;
253
                                countup = 1;
254
                        }
255
                }
256
                SendMessage(hwnd, WM_MOUSEMOVE, 0,
257
                        MAKELONG(mousept.x, mousept.y));
258
#endif
259
#if ARCDEMO
260
                startdegrees += 10;
261
                if(startdegrees >= 360)
262
                        startdegrees = 0;
263
                enddegrees += 15;
264
                if(enddegrees >= 360)
265
                        enddegrees = 0;
266
                InvalidateRect(hwnd, NULL, TRUE);
267
#endif
268
                break;
269
 
270
        case WM_DESTROY:
271
                KillTimer(hwnd, 1);
272
                break;
273
#endif /* TIMERDEMO*/
274
        case WM_SIZE:
275
                break;
276
 
277
        case WM_MOVE:
278
                break;
279
 
280
#if CLIENT3D
281
        case WM_SETFOCUS:
282
                PostMessage((HWND)wp, WM_PAINT, 0, 0L);
283
                break;
284
 
285
        case WM_KILLFOCUS:
286
                PostMessage((HWND)wp, WM_PAINT, 0, 0L);
287
                break;
288
        case WM_ERASEBKGND:
289
                if(GetFocus() != hwnd)
290
                        return DefWindowProc(hwnd, msg, wp, lp);
291
                return 1;
292
#endif
293
#if GRAPH3D
294
        case WM_ERASEBKGND:
295
                if((GetWindowLong(hwnd, GWL_ID) & 03) == 1)
296
                        return 1;
297
                return DefWindowProc(hwnd, msg, wp, lp);
298
#endif
299
        case WM_PAINT:
300
                hdc = BeginPaint(hwnd, &ps);
301
 
302
#if CLIENT3D
303
                if(GetFocus() == hwnd) {
304
                        GetClientRect(hwnd, &rc);
305
                        Draw3dShadow(hdc, rc.left, rc.top,
306
                                rc.right-rc.left, rc.bottom-rc.top,
307
                                GetSysColor(COLOR_3DDKSHADOW),
308
                                GetSysColor(COLOR_3DLIGHT));
309
                        InflateRect(&rc, -1, -1);
310
                        FillRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
311
                }
312
#endif
313
#if IMAGE
314
                GetClientRect(hwnd, &rc);
315
                DrawDIB(hdc, rc.left+2, rc.top+2, image2);
316
#endif
317
#if ARCDEMO
318
{
319
        int x, y, w, h;
320
        RECT rc;
321
 
322
        if(hdc != NULL) {
323
                GetWindowRect(hwnd, &rc);
324
                rc.top += 13;
325
                InflateRect(&rc, -3, -3);
326
                /*Ellipse(hdc, 0, 0, rc.right-rc.left, rc.bottom-rc.top);*/
327
                /*Arc(hdc, 0, 0, rc.right-rc.left, rc.bottom-rc.top, 0,0, 0,0);*/
328
                /*Pie(hdc, 0, 0, rc.right-rc.left, rc.bottom-rc.top, 0,0, 0,0);*/
329
 
330
                x = rc.left;
331
                y = rc.top;
332
                w = rc.right - rc.left;
333
                h = rc.bottom - rc.top;
334
                w += 10;
335
                GdSetForeground(GdFindColor(RGB(0,255,0)));
336
                GdArcAngle(hdc->psd, x+w/2, y+h/2, w/2, h/2, startdegrees*64,
337
                        enddegrees*64, MWPIE);
338
                GdSetForeground(GdFindColor(RGB(0,0,0)));
339
                GdArcAngle(hdc->psd, x+w/2, y+h/2, w/2, h/2, startdegrees*64,
340
                        enddegrees*64, MWARCOUTLINE);
341
                /*GdSetForeground(GdFindColor(RGB(255,255,255)));*/
342
                /*GdPoint(hdc->psd, x+w/2, y+h/2);*/
343
        }
344
        EndPaint(hwnd, &ps);
345
        break;
346
}
347
#endif /* ARCDEMO*/
348
#if GRAPH3D
349
                id = (int)GetWindowLong(hwnd, GWL_ID) & 03;
350
                init3(hdc, id == 1? hwnd: NULL);
351
                switch(id) {
352
                case 0:
353
                        rose(1.0, 7, 13);
354
                        break;
355
                case 1:
356
                        /*look3(0.5, 0.7, 1.5);*/
357
                        /*look3(0.2, -2 * gy, 1.0+gx);*/
358
                        look3(-2 * gx, -2 * gy, 1.2);
359
                        drawgrid(-8.0, 8.0, 10, -8.0, 8.0, 10);
360
                        break;
361
                case 2:
362
                        setcolor3(BLACK);
363
                        circle3(1.0);
364
                        break;
365
                case 3:
366
                        setcolor3(BLUE);
367
                        daisy(1.0, 20);
368
                        break;
369
                }
370
 
371
#if CLIPDEMO
372
                if(id == 1) {
373
                        HRGN    hrgn, hrgn2;
374
 
375
                        /* create circular clip region for effect*/
376
                        GetClientRect(hwnd, &rc);
377
                        InflateRect(&rc, -80, -80);
378
                        switch((int)GetWindowLong(hwnd, GWL_ID)) {
379
                        default:
380
                                hrgn = CreateEllipticRgnIndirect(&rc);
381
                                break;
382
                        case 5:
383
                                hrgn = CreateRoundRectRgn(rc.left, rc.top,
384
                                        rc.right, rc.bottom, 100, 100);
385
                                break;
386
                        case 1:
387
                                hrgn = CreateRectRgnIndirect(&rc);
388
                                break;
389
                        }
390
 
391
                        /* erase background, clip out blit area*/
392
                        GetClientRect(hwnd, &rc);
393
                        hrgn2 = CreateRectRgnIndirect(&rc);
394
                        SelectClipRgn(hdc, hrgn2);
395
                        ExtSelectClipRgn(hdc, hrgn, RGN_XOR);
396
                        DeleteObject(hrgn2);
397
 
398
                        GetClientRect(hwnd, &rc);
399
                        FillRect(hdc, &rc, GetStockObject(BLACK_BRUSH));
400
 
401
                        /* clip in only blit area*/
402
                        SelectClipRgn(hdc, hrgn);
403
                        DeleteObject(hrgn);
404
                }
405
#endif /* CLIPDEMO*/
406
 
407
                paint3(hdc);
408
 
409
#endif /* GRAPH3D*/
410
                EndPaint(hwnd, &ps);
411
                break;
412
 
413
        case WM_LBUTTONDOWN:
414
                break;
415
 
416
        case WM_MOUSEMOVE:
417
#if GRAPH3D
418
                if((GetWindowLong(hwnd, GWL_ID) & 03) == 1) {
419
                        POINT pt;
420
 
421
                        POINTSTOPOINT(pt, lp);
422
                        GetClientRect(hwnd, &rc);
423
                        gx = (vec1)pt.x / rc.right;
424
                        gy = (vec1)pt.y / rc.bottom;
425
                        InvalidateRect(hwnd, NULL, FALSE);
426
                        mousept.x = pt.x;
427
                        mousept.y = pt.y;
428
                }
429
#endif
430
                break;
431
 
432
        case WM_LBUTTONUP:
433
                break;
434
 
435
        case WM_RBUTTONDOWN:
436
                break;
437
 
438
        default:
439
                return DefWindowProc( hwnd, msg, wp, lp);
440
        }
441
        return( 0);
442
}
443
 
444
int WINAPI
445
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
446
        int nShowCmd)
447
{
448
        MSG     msg;
449
        HWND    hwnd;
450
        RECT    rc;
451
 
452
        RegisterAppClass();
453
        GetWindowRect(GetDesktopWindow(), &rc);
454
#if !(ELKS | MSDOS)
455
        /* create penguin window*/
456
        CreateWindowEx(0L, APPCHILD, "", WS_BORDER | WS_VISIBLE,
457
                rc.right-130-1, rc.bottom-153-1, 130, 153,
458
                GetDesktopWindow(), (HMENU)1000, NULL, NULL);
459
#endif
460
        CreateAppWindow();
461
        CreateAppWindow();
462
        CreateAppWindow();
463
#if !(ELKS | MSDOS)
464
        CreateAppWindow();
465
        CreateAppWindow();
466
        CreateAppWindow();
467
        CreateAppWindow();
468
        CreateAppWindow();
469
        hwnd = CreateAppWindow();
470
        GetWindowRect(hwnd, &rc);
471
        OffsetRect(&rc, 50, 50);
472
        MoveWindow(hwnd, rc.left, rc.top, rc.bottom-rc.top,
473
                rc.right-rc.left, TRUE);
474
#endif
475
#if !(ELKS | MSDOS)
476
        /* set background wallpaper*/
477
        MwSetDesktopWallpaper(&image_microwin);
478
        /*MwSetDesktopWallpaper(&image_under4);*/
479
        /*MwSetDesktopWallpaper(&image_car8);*/
480
#endif
481
 
482
        /* type ESC to quit...*/
483
        while( GetMessage(&msg, NULL, 0, 0)) {
484
                TranslateMessage(&msg);
485
                DispatchMessage(&msg);
486
        }
487
        return 0;
488
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.