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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [mw/] [src/] [demos/] [mwobjects/] [mwo-test.cc] - Blame information for rev 673

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * Copyright (c) 1999 Greg Haerr <greg@censoft.com>
3
 *
4
 * Demo program for Micro-Windows
5
 */
6
 
7
#define MWINCLUDECOLORS
8
#include <mwobjects.h>
9
#include <iostream>
10
 
11
extern MWIMAGEHDR image_microwin;
12
extern MWIMAGEHDR image_zion208;
13
 
14
PMWIMAGEHDR image  = &image_zion208;
15
 
16
using namespace MicroWindowsObjects;
17
 
18
class TestWindowClass
19
  : public WindowClass
20
{
21
public:
22
 
23
  TestWindowClass (LPCSTR lpszClassName);
24
 
25
};
26
 
27
class TestChildWindow
28
  : public Window
29
{
30
public:
31
 
32
  TestChildWindow ();
33
 
34
  HWND create (LPCSTR lpszClassName,
35
               HWND parent,
36
               int x, int y,
37
               int nWidth, int nHeight);
38
 
39
  void set_trace (bool t)
40
    { trace = t; }
41
 
42
protected:
43
 
44
  virtual LRESULT message_handler (UINT   msg,
45
                                   WPARAM wParam,
46
                                   LPARAM lParam);
47
private:
48
 
49
  bool trace;
50
 
51
};
52
 
53
class TestWindow
54
  : public Window
55
{
56
public:
57
 
58
  TestWindow (LPCSTR lpszClassName, bool trace = false);
59
 
60
private:
61
 
62
  bool            trace;
63
  Window          button;
64
  TestChildWindow image[3];
65
 
66
};
67
 
68
class Test3dWindow
69
  : public Window
70
{
71
public:
72
 
73
  Test3dWindow (LPCSTR lpszChild);
74
 
75
protected:
76
 
77
  virtual LRESULT message_handler (UINT   msg,
78
                                   WPARAM wParam,
79
                                   LPARAM lParam);
80
private:
81
 
82
  vec1 gx;
83
  vec1 gy;
84
 
85
  vec1 last_gx;
86
  vec1 last_gy;
87
 
88
};
89
 
90
class TestRoseWindow
91
  : public TestWindow
92
{
93
public:
94
 
95
  TestRoseWindow (LPCSTR lpszClassName, bool trace = false);
96
 
97
protected:
98
 
99
  virtual LRESULT message_handler (UINT   msg,
100
                                   WPARAM wParam,
101
                                   LPARAM lParam);
102
};
103
 
104
class TestCircleWindow
105
  : public TestWindow
106
{
107
public:
108
 
109
  TestCircleWindow (LPCSTR lpszClassName, bool trace = false);
110
 
111
protected:
112
 
113
  virtual LRESULT message_handler (UINT   msg,
114
                                   WPARAM wParam,
115
                                   LPARAM lParam);
116
};
117
 
118
class TestDaisyWindow
119
  : public TestWindow
120
{
121
public:
122
 
123
  TestDaisyWindow (LPCSTR lpszClass, bool trace = false);
124
 
125
protected:
126
 
127
  virtual LRESULT message_handler (UINT   msg,
128
                                   WPARAM wParam,
129
                                   LPARAM lParam);
130
};
131
 
132
class TestFileDescriptor
133
  : public FileDescriptor
134
{
135
public:
136
 
137
  void do_fd_test ();
138
 
139
protected:
140
 
141
  LRESULT read ();
142
  LRESULT write ();
143
  LRESULT except ();
144
};
145
 
146
class TestApplication
147
  : public Application
148
{
149
  enum { GROUPS = 2 };
150
 
151
public:
152
 
153
  TestApplication ();
154
 
155
protected:
156
 
157
  virtual int initialise ();
158
  virtual int shutdown ();
159
 
160
private:
161
 
162
  TestWindowClass    main_class;
163
 
164
  Test3dWindow       *t3d [GROUPS];
165
  TestRoseWindow     *tr [GROUPS];
166
  TestCircleWindow   *tc [GROUPS];
167
  TestDaisyWindow    *td [GROUPS];
168
 
169
  TestFileDescriptor *fd;
170
 
171
};
172
 
173
TestWindowClass::TestWindowClass (LPCSTR lpszClassName)
174
  : WindowClass (lpszClassName,
175
                 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW)
176
{
177
  set_background ((HBRUSH) GetStockObject (LTGRAY_BRUSH));
178
}
179
 
180
TestChildWindow::TestChildWindow ()
181
{
182
}
183
 
184
HWND
185
TestChildWindow::create (LPCSTR lpszClassName,
186
                         HWND parent,
187
                         int x, int y,
188
                         int nWidth, int nHeight)
189
{
190
  return Window::create (0,
191
                         lpszClassName,
192
                         "",
193
                         WS_BORDER | WS_CHILD | WS_VISIBLE,
194
                         x, y, nWidth, nHeight,
195
                         parent, 0, 0, 0);
196
}
197
 
198
LRESULT
199
TestChildWindow::message_handler (UINT   msg,
200
                                  WPARAM wParam,
201
                                  LPARAM lParam)
202
{
203
  Paint paint (*this);
204
 
205
  switch (msg)
206
  {
207
    case WM_PAINT:
208
      paint.begin ();
209
 
210
      DrawDIB (paint, paint.left (), paint.top (), image);
211
 
212
      paint.end ();
213
      break;
214
 
215
    default:
216
      return Window::message_handler (msg, wParam, lParam);
217
  }
218
  return 0;
219
}
220
 
221
TestWindow::TestWindow (LPCSTR lpszClassName, bool trace)
222
  : trace (trace)
223
{
224
  Rect rc (GetDesktopWindow ());
225
  int  width;
226
  int  height;
227
 
228
  width = height = rc.right () / 2;
229
 
230
  if (trace)
231
    cout << "create: hwnd=" << get_handle ()
232
         << " " << rc << endl;
233
 
234
  create (0, lpszClassName, "Micro C++ Application",
235
          WS_OVERLAPPEDWINDOW | WS_VISIBLE,
236
          CW_USEDEFAULT, CW_USEDEFAULT,
237
          width, height,
238
          0, 0, 0, 0);
239
 
240
  button.create (0, "BUTTON", "Ok",
241
                 WS_CHILD | WS_VISIBLE,
242
                 width * 5 / 8, 10, 50, 14,
243
                 *this, 0, 0, 0);
244
 
245
  image[0].create (lpszClassName, *this,
246
                   4, 4,
247
                   width / 3, height / 3);
248
  image[1].create (lpszClassName, *this,
249
                   width / 3, height / 3,
250
                   width / 3, height / 3);
251
  image[2].create (lpszClassName, *this,
252
                   width * 3 / 5, height * 3 / 5,
253
                   width * 2 / 3, height * 2 / 3);
254
 
255
  image[0].set_trace (trace);
256
  image[1].set_trace (trace);
257
  image[2].set_trace (trace);
258
 
259
}
260
 
261
Test3dWindow::Test3dWindow (LPCSTR lpszClassName)
262
  : gx (0),
263
    gy (0),
264
    last_gx (0),
265
    last_gy (0)
266
{
267
  Rect rect (GetDesktopWindow ());
268
  int  width;
269
  int  height;
270
 
271
  width = height = rect.right () / 2;
272
 
273
  create (0, lpszClassName, "Micro C++ Application",
274
          WS_OVERLAPPEDWINDOW | WS_VISIBLE,
275
          CW_USEDEFAULT, CW_USEDEFAULT,
276
          width, height,
277
          0, 0, 0, 0);
278
}
279
 
280
LRESULT
281
Test3dWindow::message_handler (UINT   msg,
282
                               WPARAM wParam,
283
                               LPARAM lParam)
284
{
285
  Paint paint (*this, lParam);
286
  Rect  rc;
287
 
288
  switch (msg)
289
  {
290
    case WM_PAINT:
291
      paint.begin (true);
292
 
293
      look3 (-2 * gx, -2 * gy, 1.2);
294
      drawgrid (-8.0, 8.0, 10, -8.0, 8.0, 10);
295
 
296
      last_gx = gx;
297
      last_gy = gy;
298
 
299
      paint.end ();
300
      break;
301
 
302
    case WM_MOUSEMOVE:
303
 
304
      rc.get_client (*this);
305
      gx = (vec1) paint.get_point_x () / rc.right ();
306
      gy = (vec1) paint.get_point_y () / rc.bottom ();
307
 
308
      if (gx > last_gx || gy > last_gy)
309
        invalidate_rect (0, FALSE);
310
      break;
311
 
312
    default:
313
      return Window::message_handler (msg, wParam, lParam);
314
  }
315
  return 0;
316
}
317
 
318
TestRoseWindow::TestRoseWindow (LPCSTR lpszClassName, bool trace)
319
  : TestWindow (lpszClassName, trace)
320
{
321
}
322
 
323
LRESULT
324
TestRoseWindow::message_handler (UINT   msg,
325
                                 WPARAM wParam,
326
                                 LPARAM lParam)
327
{
328
  Paint paint (*this);
329
 
330
  switch (msg)
331
  {
332
    case WM_PAINT:
333
      paint.begin (true);
334
 
335
      rose (1.0, 7, 13);
336
 
337
      paint.end ();
338
      break;
339
 
340
    default:
341
      return Window::message_handler (msg, wParam, lParam);
342
  }
343
  return 0;
344
}
345
 
346
TestCircleWindow::TestCircleWindow (LPCSTR lpszClassName, bool trace)
347
  : TestWindow (lpszClassName, trace)
348
{
349
}
350
 
351
LRESULT
352
TestCircleWindow::message_handler (UINT   msg,
353
                                   WPARAM wParam,
354
                                   LPARAM lParam)
355
{
356
  Paint paint (*this);
357
 
358
  switch (msg)
359
  {
360
    case WM_PAINT:
361
      paint.begin (true);
362
 
363
      setcolor3 (BLACK);
364
      circle3 (1.0);
365
 
366
      paint.end ();
367
      break;
368
 
369
    default:
370
      return Window::message_handler (msg, wParam, lParam);
371
  }
372
  return 0;
373
}
374
 
375
TestDaisyWindow::TestDaisyWindow (LPCSTR lpszClassName, bool trace)
376
  : TestWindow (lpszClassName, trace)
377
{
378
}
379
 
380
LRESULT
381
TestDaisyWindow::message_handler (UINT   msg,
382
                                  WPARAM wParam,
383
                                  LPARAM lParam)
384
{
385
  Paint paint (*this);
386
 
387
  switch (msg)
388
  {
389
    case WM_PAINT:
390
      paint.begin (true);
391
 
392
      setcolor3 (BLUE);
393
      daisy (1.0, 20);
394
 
395
      paint.paint_3d ();
396
 
397
      paint.text_out (10, 250, "Date built : %s", __DATE__);
398
 
399
      paint.end ();
400
      break;
401
 
402
    case WM_LBUTTONDOWN:
403
      cout << "left down : " << *this << endl;
404
      SendMessage (*this, WM_FDINPUT, 200, 0);
405
      return Window::message_handler (msg, wParam, lParam);
406
      break;
407
 
408
    case WM_RBUTTONDOWN:
409
      cout << "right down : " << *this << endl;
410
      SendMessage (*this, WM_FDOUTPUT, 200, 0);
411
      return Window::message_handler (msg, wParam, lParam);
412
      break;
413
 
414
    case WM_LBUTTONDBLCLK:
415
      cout << "double left : " << *this << endl;
416
      SendMessage (*this, WM_FDEXCEPT, 200, 0);
417
      return Window::message_handler (msg, wParam, lParam);
418
      break;
419
 
420
    default:
421
      return Window::message_handler (msg, wParam, lParam);
422
  }
423
  return 0;
424
}
425
 
426
void
427
TestFileDescriptor::do_fd_test ()
428
{
429
}
430
 
431
LRESULT
432
TestFileDescriptor::read ()
433
{
434
  cout << "test read fd for `" << *get_window () << "' and fd " << *this << endl;
435
  return 0;
436
}
437
 
438
LRESULT
439
TestFileDescriptor::write ()
440
{
441
  cout << "test write fd for `" << *get_window () << "' and fd " << *this << endl;
442
  return 0;
443
}
444
 
445
LRESULT
446
TestFileDescriptor::except ()
447
{
448
  cout << "test except fd for `" << *get_window () << "' and fd " << *this << endl;
449
  return 0;
450
}
451
 
452
TestApplication::TestApplication ()
453
  : Application (image_microwin),
454
    main_class ("test")
455
{
456
  for (int i = 0; i < GROUPS; i++)
457
  {
458
    t3d [i] = 0;
459
    tr [i] = 0;
460
    tc [i] = 0;
461
    td [i] = 0;
462
  }
463
}
464
 
465
int
466
TestApplication::initialise ()
467
{
468
  main_class.register_class ();
469
 
470
  for (int i = 0; i < GROUPS; i++)
471
  {
472
    t3d [i] = new Test3dWindow ("test");
473
    tr [i] = new TestRoseWindow ("test");
474
    tc [i] = new TestCircleWindow ("test");
475
    td [i] = new TestDaisyWindow ("test");
476
  }
477
 
478
  fd = new TestFileDescriptor ();
479
 
480
  cout << "attach to " << *td[GROUPS - 1] << endl;
481
 
482
  td[GROUPS - 1]->attach (200, *fd);
483
 
484
  return 0;
485
}
486
 
487
int
488
TestApplication::shutdown ()
489
{
490
  for (int i = 0; i < GROUPS; i++)
491
  {
492
    if (t3d [i])
493
      delete t3d [i];
494
    t3d [i] = 0;
495
 
496
    if (tr [i])
497
      delete tr [i];
498
    tr [i] = 0;
499
 
500
    if (tc [i])
501
      delete tc [i];
502
    tc [i] = 0;
503
 
504
    if (td [i])
505
      delete td [i];
506
    td [i] = 0;
507
  }
508
 
509
  return 0;
510
}
511
 
512
TestApplication test_application;

powered by: WebSVN 2.1.0

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