home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / uidemo / graphic1 / appwin.old < prev    next >
Text File  |  1994-10-14  |  2KB  |  89 lines

  1.  
  2.  
  3. #include "ui/ui.h"
  4. #include "appwin.h"
  5.  
  6. #define ID_MESSAGE 10
  7.  
  8. #define 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.     _status = new UI_Label (this, UI_Rectangle (50, 50, 400, 30));
  14.     *(_status->Model()) = CL_String (MESSAGE);
  15.     _inDrag = FALSE;
  16. }
  17.  
  18. AppWindow::~AppWindow()
  19. {
  20.     DestroyDisplaySurface ();
  21. }
  22.  
  23.  
  24. void AppWindow::Initialize ()
  25. {
  26.     UI_CompositeVObject::Initialize();
  27.     CreateDisplaySurface ();
  28. }
  29.  
  30.  
  31. bool AppWindow::ButtonDown (const UI_Point& p, UI_MouseButton m,
  32.                             bool, bool)
  33. {
  34.     if (m != UIM_Left)
  35.         return FALSE;
  36.     _inDrag = TRUE;
  37.     _Controller->GiveMouseTo (*this);
  38.     _startPt = p;
  39.     _oldRect.Origin (p);
  40.     _displaySurface->Pen().Pattern (UIPen_DashDot);
  41.     _displaySurface->Mode (UI_DisplaySurface::GMode_Xor);
  42.     return TRUE;
  43. }
  44.  
  45.  
  46. bool AppWindow::MouseMove (const UI_Point& p)
  47. {
  48.     if (!_inDrag)
  49.         return TRUE;
  50.     long wd = p.XCoord() - _startPt.XCoord();
  51.     long ht = p.YCoord() - _startPt.YCoord();
  52.     _displaySurface->DrawRectangle (_oldRect); // Erase the old rectangle
  53.     UI_Rectangle r (_startPt, wd, ht);
  54.     _displaySurface->DrawRectangle (r); // Draw the new rectangle
  55.     _oldRect = r;
  56.     *(_status->Model()) = CL_String (wd) + " x " + CL_String(ht);
  57.     return TRUE;
  58. }
  59.  
  60.  
  61.  
  62. bool AppWindow::ButtonUp (const UI_Point& p, UI_MouseButton m)
  63. {
  64.     if (m != UIM_Left)
  65.         return FALSE;
  66.     _inDrag = FALSE;
  67.     _Controller->ReleaseMouse();
  68.     _displaySurface->Pen().Pattern (UIPen_Solid);
  69.     _displaySurface->Mode (UI_DisplaySurface::GMode_Copy);
  70.     UI_Rectangle s (_startPt, p.XCoord() - _startPt.XCoord(),
  71.                     p.YCoord() - _startPt.YCoord());
  72.     _displaySurface->DrawRectangle (s);
  73.     _oldRect = UI_Rectangle (0, 0, 0, 0);
  74.     *(_status->Model()) = CL_String (MESSAGE);
  75.     return TRUE;
  76. }
  77.  
  78.  
  79. bool AppWindow::DoubleClick (const UI_Point& p, UI_MouseButton m)
  80. {
  81.     
  82.     UI_SimpleDialog ("Double click button " + CL_String ((long) m) +
  83.                      " at " + CL_String (p.XCoord ())
  84.                      + " x " + CL_String (p.YCoord ()));
  85.     return TRUE;
  86. }
  87.  
  88.  
  89.