1 /* 2 * =========================== 3 * VDK Visual Develeopment Kit 4 * Version 2.0.0 5 * november 2000 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-1307, USA. 25 */ 26 27 #ifndef _canvascompo_h 28 #define _canvascompo_h 29 #include <vdk/vdk.h> 30 #define MAX_SHAPES 10 31 typedef VDKValueList<VDKPoint> PointList; 32 typedef VDKValueListIterator<VDKPoint> PointListIterator; 33 /* 34 */ 35 class CanvasShape; 36 class CanvasComponent : public VDKBox 37 { 38 VDKCanvas *canvas; 39 VDKLabel *label; 40 VDKCustomButton *mlButton; 41 VDKCustomButton *clearButton; 42 CanvasShape* shape_array[MAX_SHAPES]; 43 PointList plist; 44 public: CanvasComponent(VDKForm * owner)45 CanvasComponent(VDKForm* owner): VDKBox(owner){} 46 ~CanvasComponent(); 47 void Setup(); 48 bool OnMotion(VDKObject* sender, GdkEvent* event); 49 bool OnExpose(VDKObject*, GdkEvent* event); 50 bool Clear(VDKObject*); 51 bool OnButtonPress(VDKObject*, GdkEvent* ev); 52 bool OnButtonRelease(VDKObject*, GdkEvent* ev); 53 DECLARE_SIGNAL_MAP(CanvasComponent); 54 DECLARE_EVENT_LIST(CanvasComponent); 55 }; 56 57 /* 58 some shapes 59 */ 60 class CanvasShape 61 { 62 protected: 63 VDKCanvas* canvas; 64 VDKRgb color; 65 bool filled; 66 public: 67 VDKRect bound; 68 CanvasShape(VDKCanvas* owner, 69 int x, int y, int w, int h, 70 VDKRgb color, bool filled = false): canvas(owner)71 canvas(owner),color(color),filled(filled),bound(x,y,w,h) {} ~CanvasShape()72 virtual ~CanvasShape() {} 73 virtual void Draw() = 0; 74 }; 75 76 class 77 CanvasRectangle: public CanvasShape 78 { 79 80 public: 81 CanvasRectangle(VDKCanvas* owner, 82 int x, int y, int w, int h, 83 VDKRgb color, 84 bool filled = false): CanvasShape(owner,x,y,w,h,color,filled)85 CanvasShape(owner,x,y,w,h,color,filled) {} ~CanvasRectangle()86 virtual ~CanvasRectangle() {} Draw()87 void Draw() 88 { 89 canvas->Foreground = color; 90 canvas->DrawRect(filled,bound.Origin().x, 91 bound.Origin().y, 92 bound.w,bound.h); 93 } 94 }; 95 96 /* 97 Arc constructor is probably one that needs more 98 explanation becaues it has quite a few parameters: 99 x,y origin of arc bounding rect 100 w,h width and height of arc bounding rect 101 start_angle,end_angle are a bit more complicated to explain 102 since unlike most arc function aren't expressed in radians 103 or degrees. The angles should be converted into degrees and 104 multiplied by 64 (which is done by the Draw() method itself). 105 So pass start_angle and end_angle in degrees with angle 0 at 106 12 o'clock and counting clockwise. 107 */ 108 class 109 CanvasArc: public CanvasShape 110 { 111 private: 112 int start_angle, end_angle; 113 public: 114 CanvasArc(VDKCanvas* owner, 115 int x, int y, int w, int h, 116 int start_angle, int end_angle, 117 VDKRgb color, 118 bool filled = false): CanvasShape(owner,x,y,w,h,color,filled)119 CanvasShape(owner,x,y,w,h,color,filled), 120 start_angle(start_angle),end_angle(end_angle) {} ~CanvasArc()121 virtual ~CanvasArc() {} Draw()122 virtual void Draw() 123 { 124 canvas->Foreground = color; 125 canvas->DrawArc(filled, 126 bound.Origin().x, 127 bound.Origin().y, 128 bound.w,bound.h, 129 start_angle*64,end_angle*64); 130 } 131 }; 132 133 class 134 CanvasCircle: public CanvasArc 135 { 136 public: 137 CanvasCircle(VDKCanvas* owner, 138 int x,int y, 139 int radius, 140 VDKRgb color, 141 bool filled = false): 142 CanvasArc(owner,x-radius,y-radius,radius*2,radius*2, 143 0,360*64,color,filled) {} ~CanvasCircle()144 ~CanvasCircle() {} 145 146 }; 147 148 class 149 CanvasPixmap: public CanvasShape 150 { 151 private: 152 char pixfile[256]; 153 VDKRawPixmap* pixmap; 154 public: CanvasPixmap(VDKCanvas * owner,int x,int y,char * pixfile)155 CanvasPixmap(VDKCanvas* owner, int x, int y, char* pixfile): 156 CanvasShape(owner,x,y,0,0,VDKRgb(-1,-1,-1)) 157 { 158 pixmap = new VDKRawPixmap(owner,pixfile); 159 VDKRect local(bound.left,bound.top, pixmap->Width(), pixmap->Height()); 160 bound = local; 161 } ~CanvasPixmap()162 virtual ~CanvasPixmap(){ pixmap->Destroy(); } Draw()163 void Draw() 164 { 165 canvas->DrawPixmap(bound.Origin().x,bound.Origin().y,pixmap); 166 } 167 }; 168 169 typedef VDKArray<VDKPoint> PointArray; 170 class 171 CanvasPolygon: public CanvasShape 172 { 173 private: 174 GdkPoint *points; 175 int npoints; 176 public: 177 CanvasPolygon(VDKCanvas *owner, 178 PointArray& array, 179 VDKRgb color, 180 bool filled = false); ~CanvasPolygon()181 virtual ~CanvasPolygon() { delete[] points; } Draw()182 void Draw() 183 { 184 canvas->Foreground = color; 185 canvas->DrawPolygon(filled,points,npoints); 186 } 187 188 }; 189 #endif 190