home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / uidemo / animate / appwin.cxx next >
C/C++ Source or Header  |  1995-04-08  |  2KB  |  67 lines

  1.  
  2. #include "ui/dsplsurf.h"
  3. #include "appwin.h"
  4.  
  5. #if defined(__GNUC__)
  6. template class CL_Binding<AppWindow>;
  7. #endif
  8.  
  9. typedef CL_Binding<AppWindow> Bind;
  10. const short _BallDiameter = 20;
  11.  
  12. AppWindow::AppWindow()
  13. : UI_CompositeVObject (NULL, NULL, FALSE, UI_Rectangle (10, 50, 250, 150)),
  14.   _timer (Bind (this, &AppWindow::_Draw))
  15. {
  16.     Title () = "YACL Bouncing Ball";
  17.     _xInc = _yInc = 5;
  18. }
  19.  
  20. AppWindow::~AppWindow ()
  21. {
  22.     _timer.Stop ();
  23. }
  24.  
  25. void AppWindow::Initialize ()
  26. {
  27.     _bgColor = UI_Color (UIColor_White);
  28.     UI_DisplaySurface& sfc = CreateDisplaySurface ();
  29.     sfc.ClearDisplay ();
  30.     UI_Rectangle bgRect (1, 1, _BallDiameter+4, _BallDiameter+4);
  31.     _bgMap.CopyFrom (sfc, bgRect);
  32.     sfc.Pen().Color (UIColor_Black);
  33.     sfc.Brush().Color   (UIColor_Red);
  34.     sfc.Brush().Pattern (UIBrush_Solid);
  35.     sfc.DrawEllipse (UI_Rectangle (3, 3, _BallDiameter, _BallDiameter),
  36.                      UID_Outline | UID_Fill);
  37.     _ballMap.CopyFrom (sfc, bgRect);
  38.     _position = UI_Point (1, 1);
  39.     _timer.Start (25);
  40. }
  41.  
  42.  
  43. bool AppWindow::_Draw (CL_Object&, long)
  44. {
  45.     UI_DisplaySurface& sfc = *DisplaySurface ();
  46.     sfc.DrawBitmap (_bgMap, _position);
  47.     _position += UI_Point (_xInc, _yInc);
  48.     long x = _position.XCoord(), y = _position.YCoord();
  49.     if (x < 0 || x > ClientArea().Width() - _BallDiameter)
  50.         _xInc = -_xInc;
  51.     if (y < 0 || y > ClientArea().Height() - _BallDiameter)
  52.         _yInc = -_yInc;
  53.     sfc.DrawBitmap (_ballMap, _position);
  54.     return TRUE;
  55. }
  56.  
  57.  
  58. bool AppWindow::Reconfigure (const UI_Rectangle&)
  59. {
  60.     _position = UI_Point (1, 1);
  61.     UI_DisplaySurface* sfc = DisplaySurface ();
  62.     if (sfc)
  63.         sfc->ClearDisplay();
  64.     return TRUE;
  65. }
  66.  
  67.