home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / uidemo / invert / appwin.cxx next >
C/C++ Source or Header  |  1995-03-21  |  5KB  |  173 lines

  1.  
  2.  
  3. #include "ui/ui.h"
  4. #include "appwin.h"
  5.  
  6.  
  7. AppWindow::AppWindow()
  8. : UI_CompositeVObject (NULL, NULL, FALSE, UI_Rectangle (10, 50, 425, 400))
  9. {
  10.     Title () = "YACL graphics demo 3";
  11. }
  12.  
  13.  
  14. bool AppWindow::Paint ()
  15. {
  16.     Draw ();
  17.     return TRUE;
  18. }
  19.  
  20. #include <iostream.h> // DEBUG
  21.  
  22.  
  23. char mask[] = {
  24.     0x00, 0x01, 0x00, 0x00,
  25.     0x00, 0x01, 0x80, 0x00,
  26.     0x00, 0x03, 0xc0, 0x00,
  27.     0x00, 0x07, 0xe0, 0x00,
  28.     0x00, 0x0f, 0xf0, 0x00,
  29.     0x00, 0x1f, 0xf8, 0x00,
  30.     0x00, 0x3f, 0xfc, 0x00,
  31.     0x00, 0x7f, 0xfe, 0x00,
  32.     0x00, 0xff, 0xff, 0x00,
  33.     0x01, 0xff, 0xff, 0x80,
  34.     0x03, 0xff, 0xff, 0xc0,
  35.     0x07, 0xff, 0xff, 0xe0,
  36.     0x0f, 0xff, 0xff, 0xf0,
  37.     0x1f, 0xff, 0xff, 0xf8,
  38.     0x3f, 0xff, 0xff, 0xfc,
  39.     0x7f, 0xff, 0xff, 0xfe
  40. };
  41.  
  42. const short WIDTH = 32, HEIGHT = 16;
  43.  
  44.  
  45. void AppWindow::Initialize ()
  46. {
  47.     CreateDisplaySurface ();
  48. }
  49.  
  50. void AppWindow::Draw ()
  51. {
  52.     Background (UIColor_White);
  53.     //    CreateDisplaySurface ();
  54.  
  55.     UI_Rectangle r;
  56.     UI_DisplaySurface& sfc = *(DisplaySurface());
  57.  
  58.     UI_Rectangle area = sfc.DrawingArea ();
  59.     area.Origin (UI_Point (0, 0));
  60.     sfc.ColorRectangle (area, UIColor_White);
  61.     UI_Pen& pen = sfc.Pen ();
  62.     UI_Brush& brush = sfc.Brush();
  63.     UI_Font& font = sfc.Font();
  64.  
  65.     brush.Color (UIColor_Blue); brush.Pattern (UIBrush_Solid);
  66.     pen.Color (UIColor_Red);
  67.     sfc.DrawEllipse   (UI_Rectangle (150, 20,  100, 60),
  68.                        (UID_DrawOptions) (UID_Outline | UID_Fill));
  69.  
  70.     pen.Thickness (1);
  71.     pen.Color (UIColor_Black);
  72.     pen.Pattern (UIPen_Dot);
  73.     sfc.DrawLine (UI_Point (20,  20), UI_Point (80,  20));
  74.     pen.Pattern (UIPen_Dash);
  75.     sfc.DrawLine (UI_Point (20,  40), UI_Point (80,  40));
  76.     pen.Pattern (UIPen_Solid);
  77.     sfc.DrawLine (UI_Point (20,  60), UI_Point (80,  60));
  78.  
  79.     font = UI_FontDesc (UIFont_Courier, 12, UIFont_Underline);
  80.     sfc.WriteString ("An ellipse", UI_Rectangle (270, 20, 145, 30));
  81.  
  82.     brush.Color   (UI_Color (0, 1, 1)); // Cyan
  83.     sfc.DrawRectangle (UI_Rectangle (150, 90, 100, 60),
  84.                        (UID_DrawOptions) (UID_Outline | UID_Fill));
  85.     font = UI_FontDesc (UIFont_Times,   12, UIFont_Italic | UIFont_BoldFace);
  86.     sfc.WriteString ("A rectangle", UI_Rectangle (270, 100, 145, 40));
  87.  
  88.  
  89.     pen.Thickness (2);
  90.     pen.Color (UIColor_Green); 
  91.     sfc.DrawLine (UI_Point (20,  90), UI_Point (80,  90));
  92.     pen.Color (UIColor_Red);
  93.     sfc.DrawLine (UI_Point (20, 110), UI_Point (80, 110));
  94.     pen.Color (UIColor_Blue);
  95.     sfc.DrawLine (UI_Point (20, 130), UI_Point (80, 130));
  96.  
  97.     //  pen.Color (UIColor_MediumGray);
  98.     font = UI_FontDesc (UIFont_Helvetica, 12, UIFont_BoldFace);
  99.     sfc.WriteString ("A few lines", UI_Rectangle (20, 150, 120, 40));
  100.  
  101.     font = UI_FontDesc (UIFont_Times, 12, UIFont_StrikeOut |
  102.                         UIFont_BoldFace);
  103.     sfc.WriteString ("Struck out text", UI_Rectangle (20, 200, 130, 40));
  104.  
  105.     pen.Thickness (1);
  106.  
  107.     brush.Color (UI_Color (UIColor_Green)); 
  108.     pen.Color   (UI_Color (UIColor_Red));
  109.     r = UI_Rectangle (150, 180, 100, 60);
  110.     UI_PieWedge p (r, 60*64, 100*64);
  111.     sfc.DrawPieWedge (p, (UID_DrawOptions) (UID_Outline | UID_Fill));
  112.     font = UI_FontDesc (UIFont_Times, 14, UIFont_BoldFace);
  113.     sfc.WriteString ("A PieWedge", UI_Rectangle (270, 200, 145, 40));
  114.  
  115.     brush.Color   (UI_Color (UIColor_MediumGray)); 
  116.     pen.Color   (UI_Color (UIColor_Red));
  117.     r = UI_Rectangle (150, 240, 100, 60);
  118.     UI_Chord c (r, 60*64, 110*64);
  119.     sfc.DrawChord (c, (UID_DrawOptions) (UID_Outline | UID_Fill));
  120.     sfc.WriteString ("A Chord", UI_Rectangle (270, 250, 145, 40));
  121.  
  122.     r = UI_Rectangle (150, 300, 100, 60);
  123.     UI_Arc arc (r, 60*64, 249*64);
  124.     arc.DrawOn (sfc);
  125.     sfc.WriteString ("An arc", UI_Rectangle (270, 320, 145, 40));
  126.  
  127.  
  128.     {
  129.         UI_Bitmap bm;
  130.         UI_Stencil s (mask, WIDTH, HEIGHT);
  131.         bm.CopyFrom (*_displaySurface, UI_Rectangle (270, 250, 32, 16));
  132.         _displaySurface->Draw (bm, s, UI_Point (30, 300));
  133.     }
  134.     //    DestroyDisplaySurface ();
  135. }
  136.  
  137. bool AppWindow::ButtonDown (const UI_Point& p, UI_MouseButton m,
  138.                             bool, bool)
  139. {
  140.     if (m != UIM_Left)
  141.         return FALSE;
  142.     _oldP = p;
  143.     _inDrag = TRUE;
  144.     UI_Stencil s (mask, WIDTH, HEIGHT);
  145.     _displaySurface->Invert (s, p + UI_Point (-WIDTH, -HEIGHT));
  146.     return TRUE;
  147. }
  148.  
  149.  
  150. bool AppWindow::MouseMove (const UI_Point& p)
  151. {
  152.     if (!_inDrag)
  153.         return TRUE;
  154.     UI_Stencil s (mask, WIDTH, HEIGHT);
  155.     _displaySurface->Invert (s, _oldP + UI_Point (-WIDTH, -HEIGHT));
  156.     _displaySurface->Invert (s, p + UI_Point (-WIDTH, -HEIGHT));
  157.     _oldP = p;
  158.     return TRUE;
  159. }
  160.  
  161.  
  162.  
  163. bool AppWindow::ButtonUp (const UI_Point& p, UI_MouseButton m)
  164. {
  165.     if (m != UIM_Left)
  166.         return FALSE;
  167.     _inDrag = FALSE;
  168.     UI_Stencil s (mask, WIDTH, HEIGHT);
  169.     _displaySurface->Invert (s, p + UI_Point (-WIDTH, -HEIGHT));
  170.     _Controller->ReleaseMouse();
  171.     return TRUE;
  172. }
  173.