vdk 2.4.0
vdkutils.h
1 /*
2  * ===========================
3  * VDK Visual Development Kit
4  * Version 0.4
5  * October 1998
6  * ===========================
7  *
8  * Copyright (C) 1998, Mario Motta
9  * Developed by Mario Motta <mmotta@guest.net>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  * 02111-130
25  */
26 
27 #ifndef VDKUTILS_H
28 #define VDKUTILS_H
29 #include <gdk/gdk.h>
30 /*
31 VDKRgb
32 */
37 class VDKRgb
38 {
39  public:
40  int red,green,blue;
47  VDKRgb(int r = 0, int g = 0, int b = 0): red(r),green(g),blue(b)
48  {
49  }
54  {
55  }
61  VDKRgb(char* name)
62  {
63  red = green = blue = -1;
64  GdkColor color;
65  if(gdk_color_parse(name, &color))
66  {
67  red = color.red >> 8;
68  green = color.green >> 8;
69  blue = color.blue >> 8;
70  }
71  }
75  bool IsValid() const { return red != -1 && green != -1 && blue != -1 ; }
79  bool operator==(VDKRgb& c) const
80  {
81  return ( (red == c.red) && (green == c.green) && (blue == c.blue) );
82  }
83 };
84 
85 /*
86  ------------
87  point class
88  ------------
89 */
94 class VDKPoint {
95  public:
99  int x,y;
100  public:
101  // Constructors
105  VDKPoint(): x(0),y(0)
106  {
107  }
113  VDKPoint(int _x, int _y)
114  {
115  x = _x; y = _y;
116  }
120  virtual
122  {
123  }
124 
128  int
129  operator ==(VDKPoint& p) const{ return (x == p.x ) && (y == p.y); }
133  int
134  operator !=(VDKPoint& p) const{ return ! (*this == p) ; }
140  VDKPoint
141  OffsetBy(int dx, int dy) const { return VDKPoint(x+dx, y+dy); }
145  VDKPoint
146  operator -() const{ return VDKPoint(-x, -y); }
152  VDKPoint&
153  Offset(int dx, int dy);
154 
155  int
156  X() const { return x; }
157  int
158  Y() const { return y; }
159 };
160 
161 /*
162  ----------
163  rect class
164  ----------
165 */
170 class VDKRect
171 {
172 
173  public:
177  int left,top,right,bottom;
181  int w,h;
182  public:
183 
184 
189  {
190  left = top = right = bottom = w = h = 0;
191  }
199  VDKRect(int x, int y, int _w, int _h):w(_w),h(_h)
200  {
201  left = x; top = y; right = x+_w; bottom = y+_h;
202  }
206  VDKRect(VDKRect& r):w(r.w),h(r.h)
207  {
208  left = r.left; right = r.right; top = r.top; bottom = r.bottom;
209  }
214  {
215  }
219  VDKPoint
220  Origin() const { return VDKPoint(left,top); }
224  int
225  W() const { return w; }
229  int
230  H() const { return h; }
235  int
236  Contains(const VDKPoint& point) const
237  {
238  return point.X() >= left && point.X() < right
239  && point.Y() >= top && point.Y() < bottom;
240  }
245  int
246  Contains( const VDKRect& r) const {
247  return r.left >= left && r.right <= right
248  && r.top >= top && r.bottom <= bottom;
249  }
250 };
251 
264 {
265  private:
267  VDKNotCopyAble& operator=(VDKNotCopyAble const&);
268  protected:
269  VDKNotCopyAble(){}
270  ~VDKNotCopyAble(){}
271 };
272 
273 #endif
274 
275 
276 
277 
278 
279 
280