home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / examp / mycanvas.cpp < prev    next >
C/C++ Source or Header  |  1998-07-03  |  4KB  |  164 lines

  1. //=======================================================================
  2. //  mycanvas.cxx -- myCanvasPane class defintion
  3. //  Copyright (C) 1995  Bruce E. Wampler
  4. //
  5. //  This program is part of the V C++ GUI Framework example programs.
  6. //
  7. //  This program is free software; you can redistribute it and/or modify
  8. //  it under the terms of the GNU General Public License as published by
  9. //  the Free Software Foundation; either version 2 of the License, or
  10. //  (at your option) any later version.
  11. //
  12. //  This program is distributed in the hope that it will be useful,
  13. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. //  GNU General Public License for more details.
  16. //
  17. //  You should have received a copy of the GNU General Public License
  18. //  (see COPYING) along with this program; if not, write to the Free
  19. //  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. //=======================================================================
  21.  
  22. #include "mycanvas.h"
  23.  
  24. //===================>>> myCanvasPane::myCanvasPane <<<====================
  25.   myCanvasPane::myCanvasPane()
  26.   {
  27.     _mouseDown = 0;
  28.     _begx = -1;
  29.     _begy = -1;
  30.     _curx = -1;
  31.     _cury = -1;
  32.     pt = new point[200];        // 200 lines
  33.     nextpt = 0;
  34.   }
  35.  
  36. //===================>>> myCanvasPane::myCanvasPane <<<====================
  37.   myCanvasPane::~myCanvasPane()
  38.   {
  39.     delete [] pt;        // Zap the point array
  40.   }
  41.  
  42. //======================>>> myCanvasPane::Clear <<<========================
  43.   void myCanvasPane::Clear()
  44.   {
  45.     point *np;
  46.  
  47.     vCanvasPane::Clear();
  48.  
  49.     nextpt = 0;
  50.  
  51.   }
  52.  
  53. //======================>>> myCanvasPane::HPage <<<========================
  54.   void myCanvasPane::HPage(int shown, int top)
  55.   {
  56.     vCanvasPane::HPage(shown, top);
  57.   }
  58.  
  59. //======================>>> myCanvasPane::VPage <<<========================
  60.   void myCanvasPane::VPage(int shown, int top)
  61.   {
  62.     vCanvasPane::VPage(shown, top);
  63.   }
  64.  
  65. //=======================>>> myCanvasPane::HScroll <<<======================
  66.   void myCanvasPane::HScroll(int step)
  67.   {
  68.     vCanvasPane::HScroll(step);
  69.   }
  70.  
  71. //======================>>> myCanvasPane::VScroll <<<======================
  72.   void myCanvasPane::VScroll(int step)
  73.   {
  74.     vCanvasPane::VScroll(step);
  75.   }
  76.  
  77. //======================>>> myCanvasPane::MouseDown <<<======================
  78.   void myCanvasPane::MouseDown(int X, int Y, int button)
  79.   {
  80.     _mouseDown = 1;
  81.     _begx = _curx = X;
  82.     _begy = _cury = Y;
  83.  
  84.     pt[nextpt].x = X;
  85.     pt[nextpt].y = Y;
  86.     pt[nextpt].pPen = GetPen();
  87.     ++nextpt;
  88.     if (nextpt >= 200)        // really dumb!
  89.     nextpt = 0;
  90.   }
  91.  
  92. //========================>>> myCanvasPane::MouseUp <<<======================
  93.   void myCanvasPane::MouseUp(int X, int Y, int button)
  94.   {
  95.     _mouseDown = 0;
  96.     if (_begx != X || _begy != Y)
  97.       {
  98.     DrawLine(_begx, _begy, X, Y);
  99.       }
  100.  
  101.     pt[nextpt].x = X;
  102.     pt[nextpt].y = Y;
  103.     pt[nextpt].pPen = GetPen();
  104.     ++nextpt;
  105.  
  106.     if (nextpt >= 200)        // really dumb!
  107.     nextpt = 0;
  108.  
  109.     _mouseDown = 0;
  110.     _begx = -1;
  111.     _begy = -1;
  112.     _curx = -1;
  113.     _cury = -1;
  114.   }
  115.  
  116. //======================>>> myCanvasPane::MouseMove <<<======================
  117.   void myCanvasPane::MouseMove(int x, int y, int button)
  118.   {
  119.     if (_begx != _curx || _begy != _cury)
  120.       {
  121.     DrawRubberLine(_begx, _begy, _curx, _cury);    // erase old one
  122.       }
  123.  
  124.     if (_begx != x || _begy != y)
  125.       {
  126.     DrawRubberLine(_begx, _begy, x, y);
  127.       }
  128.     
  129.     _curx = x;
  130.     _cury = y;
  131.   }
  132.  
  133. //=========================>>> myCanvasPane::Redraw <<<======================
  134.   void myCanvasPane::Redraw(int x, int y, int w, int h)
  135.   {
  136.  
  137.     // This is a stupid Redraw that just redraws everything.
  138.     // It also starts losing things after 200 points. This
  139.     // is just sample code, remember!
  140.  
  141.     int x1, y1, x2, y2;
  142.  
  143.     for (int i = 0 ; i < nextpt ; i += 2)
  144.       {
  145.     if (i == 0 || pt[i].pPen != pt[i-2].pPen)
  146.         SetPen(pt[i].pPen);
  147.     x1 = pt[i].x;
  148.     y1 = pt[i].y;
  149.     x2 = pt[i+1].x;
  150.     y2 = pt[i+1].y;
  151.  
  152.     int xlim = x + w;
  153.     int ylim = y + h;
  154.  
  155.     DrawLine(x1, y1, x2, y2);
  156.       }
  157.   }
  158.  
  159. //======================>>> myCanvasPane::Resize <<<======================
  160.   void myCanvasPane::Resize(int w, int h)
  161.   {
  162.     vCanvasPane::Resize(w,h);
  163.   }
  164.