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

Subversion Repositories or1k_old

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

powered by: WebSVN 2.1.0

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