Changeset 1224:7f4f2855fa11 in lemon0.x
 Timestamp:
 03/17/05 12:45:05 (19 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1644
 Location:
 src/work/peter
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

src/work/peter/Makefile
r1221 r1224 1 1 triangle: canvastest.cc 2 g++ canvastest.cc  o triangle `pkgconfig libgnomecanvasmm2.6 cflags libs`2 g++ canvastest.cc W Wall ansi pedantic o triangle `pkgconfig libgnomecanvasmm2.6 cflags libs` 
src/work/peter/canvastest.cc
r1221 r1224 17 17 18 18 private: 19 20 ///Event handler function that handles dragging nodes of triangle 21 bool event_handler(GdkEvent* e, bool b); 22 23 ///Event handler function that handles dragging triangle 24 bool tri_mover(GdkEvent* e, bool b); 25 26 ///Coordinates of Weight Point of tirangle 27 Gnome::Art::Point * wp; 28 ///Array of nodes of planefigure 29 Gnome::Canvas::Ellipse ** nodes; 30 ///Sides of planefigure 31 Gnome::Canvas::Polygon * sides; 32 ///Group of graphical elements of triangle 33 Gnome::Canvas::Group triangle; 34 35 ///Indicates whether the button of mouse is pressed or not 36 bool isbutton; 37 38 ///Number Of Elements  the number of nodes 19 39 int noe; 20 40 21 bool isbutton; 41 ///At this location was the mousebutton pressed. 42 ///It helps to calculate the distance of dragging. 22 43 double clicked_x, clicked_y; 23 44 45 ///Remembers which Gnome::Canvas::Item was pressed. 24 46 ///this variable is needed, because 25 47 ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault … … 27 49 Gnome::Canvas::Item * active_item; 28 50 29 bool event_handler(GdkEvent* e, bool b); 30 bool tri_mover(GdkEvent* e, bool b); 31 Gnome::Art::Point * wp; 32 Gnome::Canvas::Ellipse ** nodes; 33 Gnome::Canvas::Polygon * sides; 34 Gnome::Canvas::Group triangle; 51 35 52 }; 36 53 54 ///When we click on the weight point we can drag the whole triangle. This function resolves it. 37 55 bool CanvasExample::tri_mover(GdkEvent* e, bool b) 38 56 { 57 b=b; 39 58 switch(e>type) 40 59 { … … 51 70 if(isbutton) 52 71 { 53 //double x1, y1, x2, y2;54 //(get_item_at(e>motion.x, e>motion.y))>get_bounds(x1, y1, x2, y2);55 //printf("Item coos: %d %d %d %d\n", (int)x1, (int)y1, (int)x2, (int)y2);56 //printf("Mouse is moved! %d %d\n",(int)e>motion.x,(int)e>motion.y);57 72 double dx=e>motion.xclicked_x; 58 73 double dy=e>motion.yclicked_y; 59 for(int i=0;i<=noe /2;i++)74 for(int i=0;i<=noe;i++) 60 75 { 61 76 nodes[i]>move(dx,dy); … … 65 80 66 81 Gnome::Canvas::Points coos; 67 for(int i=0;i<noe /2;i++)82 for(int i=0;i<noe;i++) 68 83 { 69 84 double x1,y1,x2,y2; … … 78 93 default: break; 79 94 } 80 } 81 95 return true; 96 } 97 98 ///This function moves only one node of triangle, 99 ///but recalculate the location of wight point, 100 ///and also redraw the sides of the planefigure. 82 101 bool CanvasExample::event_handler(GdkEvent* e, bool b) 83 102 { 103 b=b; 84 104 switch(e>type) 85 105 { … … 110 130 double y_wp=0; 111 131 112 for(int i=0;i<noe /2;i++)132 for(int i=0;i<noe;i++) 113 133 { 114 134 double x1,y1,x2,y2; … … 118 138 coos.push_back(Gnome::Art::Point(x, y)); 119 139 120 if(i<3) 121 { 122 x_wp+=x; 123 y_wp+=y; 124 } 140 x_wp+=x; 141 y_wp+=y; 125 142 } 126 143 127 144 sides>property_points().set_value(coos); 128 145 129 x_wp/= 3;130 y_wp/= 3;146 x_wp/=noe; 147 y_wp/=noe; 131 148 132 149 double x1,y1,x2,y2; 133 nodes[noe /2]>get_bounds(x1,y1,x2,y2);150 nodes[noe]>get_bounds(x1,y1,x2,y2); 134 151 double x=(x1+x2)/2; 135 152 double y=(y1+y2)/2; … … 137 154 dx=x_wpx; 138 155 dy=y_wpy; 139 nodes[noe /2]>move(dx, dy);156 nodes[noe]>move(dx, dy); 140 157 141 158 clicked_x=e>motion.x; … … 144 161 default: break; 145 162 } 146 } 147 148 CanvasExample::CanvasExample(double * coosarray, int numofels):triangle(*(root()), 0, 0),isbutton(false),active_item(NULL) 149 { 150 noe=numofels; 151 152 int j=0; 153 double ax=coosarray[j++]; 154 double ay=coosarray[j++]; 155 double bx=coosarray[j++]; 156 double by=coosarray[j++]; 157 double cx=coosarray[j++]; 158 double cy=coosarray[j++]; 163 return true; 164 } 165 166 CanvasExample::CanvasExample(double * coosarray, int numofcoos):triangle(*(root()), 0, 0),isbutton(false),active_item(NULL) 167 { 168 noe=numofcoos/2; 169 170 double x_wp=0; 171 double y_wp=0; 159 172 160 173 Gnome::Canvas::Points coos; 161 for(int i=0;i<n oe;i++)174 for(int i=0;i<numofcoos;i++) 162 175 { 163 176 double x=coosarray[i++]; 164 177 double y=coosarray[i]; 165 178 coos.push_back(Gnome::Art::Point(x, y)); 179 180 x_wp+=x; 181 y_wp+=y; 182 166 183 } 167 184 … … 170 187 sides>property_width_pixels().set_value(10); 171 188 172 nodes=new ( Gnome::Canvas::Ellipse * ) [noe/2+1];173 174 for(int i=0; i<noe /2;i++)189 nodes=new Gnome::Canvas::Ellipse* [noe+1]; 190 191 for(int i=0; i<noe;i++) 175 192 { 176 193 nodes[i]= new Gnome::Canvas::Ellipse(triangle, coos[i].get_x()20, coos[i].get_y()20, coos[i].get_x()+20, coos[i].get_y()+20); … … 180 197 } 181 198 182 wp=new Gnome::Art::Point( (ax+bx+cx)/3,(ay+by+cy)/3);183 184 nodes[noe /2]= new Gnome::Canvas::Ellipse(triangle, wp>get_x()20, wp>get_y()20, wp>get_x()+20, wp>get_y()+20);185 *(nodes[noe /2]) << Gnome::Canvas::Properties::fill_color("blue");186 *(nodes[noe /2]) << Gnome::Canvas::Properties::outline_color("black");187 (nodes[noe /2])>signal_event().connect(sigc::bind(sigc::mem_fun(*this, &CanvasExample::tri_mover),true));199 wp=new Gnome::Art::Point(x_wp/noe,y_wp/noe); 200 201 nodes[noe]= new Gnome::Canvas::Ellipse(triangle, wp>get_x()20, wp>get_y()20, wp>get_x()+20, wp>get_y()+20); 202 *(nodes[noe]) << Gnome::Canvas::Properties::fill_color("blue"); 203 *(nodes[noe]) << Gnome::Canvas::Properties::outline_color("black"); 204 (nodes[noe])>signal_event().connect(sigc::bind(sigc::mem_fun(*this, &CanvasExample::tri_mover),true)); 188 205 189 206 … … 206 223 }; 207 224 208 MainWin::MainWin(const std::string& title, double * coosarray, int no e):m_canvas(coosarray, noe)225 MainWin::MainWin(const std::string& title, double * coosarray, int noc):m_canvas(coosarray, noc) 209 226 { 210 227 set_title (title); … … 235 252 } 236 253 237 printf("Usage:\n./triangle x1 y1 x2 y2 x3 y3\nWhere xi and yi are the coordinates of the points of the triangle\n");238 239 254 return 0; 240 255 }
Note: See TracChangeset
for help on using the changeset viewer.