home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / MDBS.ZIP / BEZIER.CLS < prev    next >
Text File  |  1990-01-15  |  4KB  |  155 lines

  1. /*
  2. **  (C) Copyright 1989, 1990
  3. **  Micro Data Base Systems Inc.
  4. **  Lafayette, Indiana
  5. */
  6. subclass(Window,
  7.          #Bezier,
  8.          #(isButton1Down,
  9.            isButton2Down,
  10.            end1,
  11.            control1,
  12.            end2,
  13.            control2),
  14.          true, true, false);
  15. $
  16.  
  17. /* Initialize the window. */
  18. method Bezier::init(self)
  19. {
  20.         isButton1Down =
  21.         isButton2Down = false;
  22.         return init(super, HWND_DESKTOP, nil, "Bezier",
  23.                         0, nil);
  24. }
  25.  
  26. /* Create a new instance of the Bezier window. */
  27. method BezierClass::new(self)
  28. {
  29.         return init(basicNew(self));
  30. }
  31.  
  32. /* Answer the frame window control flags */
  33. method Bezier::controlFlagsOf(self)
  34. {
  35.         return FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER |
  36.                FCF_MINMAX;
  37. }
  38.  
  39. /* Answer the style of the desired window. */
  40. method Bezier::windowStyleOf(self)
  41. {
  42.         return WS_VISIBLE | FS_SIZEBORDER;
  43. }
  44.  
  45. /* Process a left button press in the window.*/
  46. method Bezier::button1Down(self, mousePosition, hitTest)
  47. {
  48.         if(!isButton1Down) {
  49.                 capture(self);
  50.                 isButton1Down = true;
  51.         } else
  52.                 alarm(self, WA_ERROR);
  53.         return button1Down(super, mousePosition, hitTest);
  54. }
  55.  
  56. /* Process a left button release in the window. */
  57. method Bezier::button1Up(self, mousePosition, hitTest)
  58. {
  59.         if(isButton1Down) {
  60.                 releaseCapture(self);
  61.                 isButton1Down = false;
  62.         }
  63.         return button1Up(super, mousePosition, hitTest);
  64. }
  65.  
  66. /* Process a right button press in the window. */
  67. method Bezier::button2Down(self, mousePosition, hitTest)
  68. {
  69.         if(!isButton2Down) {
  70.                 capture(self);
  71.                 isButton2Down = true;
  72.         } else
  73.                 alarm(self, WA_ERROR);
  74.         return button2Down(super, mousePosition, hitTest);
  75. }
  76.  
  77. /* Process a right button release in the window. */
  78. method Bezier::button2Up(self, mousePosition, hitTest)
  79. {
  80.         if(isButton2Down) {
  81.                 releaseCapture(self);
  82.                 isButton2Down = false;
  83.         }
  84.         return button2Up(super, mousePosition, hitTest);
  85. }
  86.  
  87. /* Process a mouse movement in the window. */
  88. method Bezier::mouseMove(self, mousePosition, hitTest)
  89. {
  90.         local hps;
  91.  
  92.         if(!isButton1Down && !isButton2Down)
  93.                 return nil;
  94.  
  95.         hps = getPS(self);
  96.         GpiSetColor(hps, CLR_BACKGROUND);
  97.         paintWindow(self, hps, nil);
  98.  
  99.         if(isButton1Down)
  100.                 control1 = mousePosition;
  101.         else
  102.                 control2 = mousePosition;
  103.  
  104.         GpiSetColor(hps, CLR_NEUTRAL);
  105.         paintWindow(self, hps, nil);
  106.         releasePS(self, hps);
  107.         return mouseMove(super, mousePosition, hitTest);
  108. }
  109.  
  110. /* Draw the display. */
  111. method Bezier::paintWindow(self, hps, shape)
  112. {
  113.         local pointBlock;
  114.  
  115.         pointBlock = new(Struct, 8 * 3);
  116.         longPut(pointBlock,  0, x(control1));
  117.         longPut(pointBlock,  4, y(control1));
  118.         longPut(pointBlock,  8, x(control2));
  119.         longPut(pointBlock, 12, y(control2));
  120.         longPut(pointBlock, 16, x(end2));
  121.         longPut(pointBlock, 20, y(end2));
  122.  
  123.         GpiSetLineType(hps, LINETYPE_ALTERNATE);
  124.  
  125.         /* Draw the dotted straight lines. */
  126.         moveTo(end1,     hps);
  127.         lineTo(control1, hps);
  128.         moveTo(end2,     hps);
  129.         lineTo(control2, hps);
  130.  
  131.         /* Draw the spline. */
  132.         GpiSetLineType(hps, LINETYPE_SOLID);
  133.         moveTo(end1, hps);
  134.         GpiPolySpline(hps, 3, pointBlock);
  135.         return self;
  136. }
  137.  
  138. /* Size the window. */
  139. method Bezier::sizeWindow(self, oldSize, newSize)
  140. {
  141.         end1     =     x(newSize) / 3 @     y(newSize) / 2;
  142.         end2     = 2 * x(newSize) / 3 @     y(newSize) / 2;
  143.         control1 =     x(newSize) / 2 @ 3 * y(newSize) / 4;
  144.         control2 =     x(newSize) / 2 @     y(newSize) / 4;
  145.         return sizeWindow(super, oldSize, newSize);
  146. }
  147.  
  148. /*
  149. ** Answer the name of the demo application
  150. ** to be used by the demo start list box.
  151. */
  152. method BezierClass::demoNameOf(self)
  153. {
  154.         return "Bezier Curves";
  155. }