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

  1.  
  2. #include "ui/cntroler.h"
  3. #include "ui/dsplsurf.h"
  4. #include "ui/label.h"
  5.  
  6. #include "appwin.h"
  7.  
  8. const char* MESSAGE = "Click and hold mouse to begin drawing";
  9.  
  10. AppWindow::AppWindow()
  11. : UI_CompositeVObject (NULL, NULL, FALSE, UI_Rectangle (50, 50, 500, 300))
  12. {
  13.     Title() = "YACL Graphics Demo 1";
  14.     _status = new UI_Label (this, UI_Rectangle (50, 50, 400, 30));
  15.     _status->Title() = MESSAGE;
  16.     _inDrag = FALSE;
  17. }
  18.  
  19. AppWindow::~AppWindow()
  20. {
  21.     DestroyDisplaySurface ();
  22. }
  23.  
  24.  
  25. void AppWindow::Initialize ()
  26. {
  27.     UI_CompositeVObject::Initialize();
  28.     _bgColor = UIColor_White; // The Canvas class sets up its own background
  29.                               // color, but this sample program does not use
  30.                               // the Canvas class.
  31.     CreateDisplaySurface ();
  32. }
  33.  
  34.  
  35.  
  36. bool AppWindow::ButtonDown (const UI_Point& p, UI_MouseButton m,
  37.                             bool, bool)
  38. {
  39.     if (m != UIM_Left)
  40.         return FALSE;
  41.     _startPt = p;
  42.     _inDrag = TRUE;
  43.     _Controller->GiveMouseTo (*this);
  44.     _displaySurface->Pen().Pattern (UIPen_Dot);
  45.     _displaySurface->Pen().Color   (UIColor_Red);
  46.     _displaySurface->Mode (UI_DisplaySurface::GMode_Xor);
  47.     return TRUE;
  48. }
  49.  
  50.  
  51. bool AppWindow::MouseMove (const UI_Point& p)
  52. {
  53.     if (!_inDrag)
  54.         return TRUE;
  55.     long wd = p.XCoord() - _startPt.XCoord();
  56.     long ht = p.YCoord() - _startPt.YCoord();
  57.     _displaySurface->DrawRectangle (_rect); // Erase the old rectangle
  58.     UI_Rectangle r (_startPt, wd, ht);
  59.     _displaySurface->DrawRectangle (r);        // Draw the new rectangle
  60.     _rect = r;
  61.     (_status->Model()) = CL_String (wd) + " x " + CL_String(ht);
  62.     return TRUE;
  63. }
  64.  
  65.  
  66.  
  67. bool AppWindow::ButtonUp (const UI_Point& p, UI_MouseButton m)
  68. {
  69.     if (m != UIM_Left)
  70.         return FALSE;
  71.     _inDrag = FALSE;
  72.     _Controller->ReleaseMouse();
  73.     _displaySurface->DrawRectangle (_rect);   // Erase the old rectangle
  74.     _displaySurface->Pen().Pattern (UIPen_Solid);
  75.     _displaySurface->Mode (UI_DisplaySurface::GMode_Copy);
  76.     UI_Rectangle s (_startPt, p.XCoord() - _startPt.XCoord(),
  77.                     p.YCoord() - _startPt.YCoord());
  78.     _displaySurface->DrawRectangle (s);       // Draw a solid rectangle
  79.     _rect = UI_Rectangle (0, 0, 0, 0);
  80.     _status->Title() = MESSAGE;
  81.     return TRUE;
  82. }
  83.  
  84.