File: mycanvas.cpp

package info (click to toggle)
v1 1.20-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 6,240 kB
  • ctags: 9,439
  • sloc: cpp: 48,033; ansic: 8,939; makefile: 1,369; sh: 30
file content (163 lines) | stat: -rw-r--r-- 4,251 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//=======================================================================
//  mycanvas.cxx -- myCanvasPane class defintion
//  Copyright (C) 1995  Bruce E. Wampler
//
//  This program is part of the V C++ GUI Framework example programs.
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  (see COPYING) along with this program; if not, write to the Free
//  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=======================================================================

#include "mycanvas.h"

//===================>>> myCanvasPane::myCanvasPane <<<====================
  myCanvasPane::myCanvasPane()
  {
    _mouseDown = 0;
    _begx = -1;
    _begy = -1;
    _curx = -1;
    _cury = -1;
    pt = new point[200];		// 200 lines
    nextpt = 0;
  }

//===================>>> myCanvasPane::myCanvasPane <<<====================
  myCanvasPane::~myCanvasPane()
  {
    delete [] pt;		// Zap the point array
  }

//======================>>> myCanvasPane::Clear <<<========================
  void myCanvasPane::Clear()
  {
    point *np;

    vCanvasPane::Clear();

    nextpt = 0;

  }

//======================>>> myCanvasPane::HPage <<<========================
  void myCanvasPane::HPage(int shown, int top)
  {
    vCanvasPane::HPage(shown, top);
  }

//======================>>> myCanvasPane::VPage <<<========================
  void myCanvasPane::VPage(int shown, int top)
  {
    vCanvasPane::VPage(shown, top);
  }

//=======================>>> myCanvasPane::HScroll <<<======================
  void myCanvasPane::HScroll(int step)
  {
    vCanvasPane::HScroll(step);
  }

//======================>>> myCanvasPane::VScroll <<<======================
  void myCanvasPane::VScroll(int step)
  {
    vCanvasPane::VScroll(step);
  }

//======================>>> myCanvasPane::MouseDown <<<======================
  void myCanvasPane::MouseDown(int X, int Y, int button)
  {
    _mouseDown = 1;
    _begx = _curx = X;
    _begy = _cury = Y;

    pt[nextpt].x = X;
    pt[nextpt].y = Y;
    pt[nextpt].pPen = GetPen();
    ++nextpt;
    if (nextpt >= 200)		// really dumb!
	nextpt = 0;
  }

//========================>>> myCanvasPane::MouseUp <<<======================
  void myCanvasPane::MouseUp(int X, int Y, int button)
  {
    _mouseDown = 0;
    if (_begx != X || _begy != Y)
      {
	DrawLine(_begx, _begy, X, Y);
      }

    pt[nextpt].x = X;
    pt[nextpt].y = Y;
    pt[nextpt].pPen = GetPen();
    ++nextpt;

    if (nextpt >= 200)		// really dumb!
	nextpt = 0;

    _mouseDown = 0;
    _begx = -1;
    _begy = -1;
    _curx = -1;
    _cury = -1;
  }

//======================>>> myCanvasPane::MouseMove <<<======================
  void myCanvasPane::MouseMove(int x, int y, int button)
  {
    if (_begx != _curx || _begy != _cury)
      {
	DrawRubberLine(_begx, _begy, _curx, _cury);	// erase old one
      }

    if (_begx != x || _begy != y)
      {
	DrawRubberLine(_begx, _begy, x, y);
      }
    
    _curx = x;
    _cury = y;
  }

//=========================>>> myCanvasPane::Redraw <<<======================
  void myCanvasPane::Redraw(int x, int y, int w, int h)
  {

    // This is a stupid Redraw that just redraws everything.
    // It also starts losing things after 200 points. This
    // is just sample code, remember!

    int x1, y1, x2, y2;

    for (int i = 0 ; i < nextpt ; i += 2)
      {
	if (i == 0 || pt[i].pPen != pt[i-2].pPen)
	    SetPen(pt[i].pPen);
	x1 = pt[i].x;
	y1 = pt[i].y;
	x2 = pt[i+1].x;
	y2 = pt[i+1].y;

	int xlim = x + w;
	int ylim = y + h;

	DrawLine(x1, y1, x2, y2);
      }
  }

//======================>>> myCanvasPane::Resize <<<======================
  void myCanvasPane::Resize(int w, int h)
  {
    vCanvasPane::Resize(w,h);
  }