Changeset 1225:4401e1aeafcf in lemon0.x
 Timestamp:
 03/17/05 18:20:37 (18 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1645
 Location:
 src/work/peter
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

src/work/peter/Makefile
r1224 r1225 1 1 triangle: canvastest.cc 2 2 g++ canvastest.cc W Wall ansi pedantic o triangle `pkgconfig libgnomecanvasmm2.6 cflags libs` 3 4 run: triangle 5 ./triangle 100 100 100 100 0 100 6 7 .PHONY: run 
src/work/peter/canvastest.cc
r1224 r1225 19 19 20 20 ///Event handler function that handles dragging nodes of triangle 21 bool event_handler(GdkEvent* e, boolb);21 bool event_handler(GdkEvent* e, int b); 22 22 23 23 ///Event handler function that handles dragging triangle 24 bool tri_mover(GdkEvent* e , bool b);24 bool tri_mover(GdkEvent* e); 25 25 26 26 ///Coordinates of Weight Point of tirangle … … 39 39 int noe; 40 40 41 ///Array of coordinates 42 double * coordinates; 43 41 44 ///At this location was the mousebutton pressed. 42 45 ///It helps to calculate the distance of dragging. … … 53 56 54 57 ///When we click on the weight point we can drag the whole triangle. This function resolves it. 55 bool CanvasExample::tri_mover(GdkEvent* e, bool b) 56 { 57 b=b; 58 bool CanvasExample::tri_mover(GdkEvent* e) 59 { 58 60 switch(e>type) 59 61 { … … 72 74 double dx=e>motion.xclicked_x; 73 75 double dy=e>motion.yclicked_y; 76 77 Gnome::Canvas::Points coos; 78 74 79 for(int i=0;i<=noe;i++) 75 80 { 76 81 nodes[i]>move(dx,dy); 82 83 double x=(coordinates[2*i]+=dx); 84 double y=(coordinates[2*i+1]+=dy); 85 86 if(i!=noe)coos.push_back(Gnome::Art::Point(x,y)); 87 77 88 } 89 78 90 clicked_x=e>motion.x; 79 91 clicked_y=e>motion.y; 80 92 81 Gnome::Canvas::Points coos;82 for(int i=0;i<noe;i++)83 {84 double x1,y1,x2,y2;85 nodes[i]>get_bounds(x1,y1,x2,y2);86 double x=(x1+x2)/2;87 double y=(y1+y2)/2;88 coos.push_back(Gnome::Art::Point(x, y));89 }90 93 sides>property_points().set_value(coos); 91 92 94 } 93 95 default: break; … … 99 101 ///but recalculate the location of wight point, 100 102 ///and also redraw the sides of the planefigure. 101 bool CanvasExample::event_handler(GdkEvent* e, bool b) 102 { 103 b=b; 103 bool CanvasExample::event_handler(GdkEvent* e, int b) 104 { 104 105 switch(e>type) 105 106 { … … 125 126 active_item>move(dx, dy); 126 127 128 coordinates[2*b]+=dx; 129 coordinates[2*b+1]+=dy; 130 127 131 Gnome::Canvas::Points coos; 128 132 … … 132 136 for(int i=0;i<noe;i++) 133 137 { 134 double x1,y1,x2,y2; 135 nodes[i]>get_bounds(x1,y1,x2,y2); 136 double x=(x1+x2)/2; 137 double y=(y1+y2)/2; 138 coos.push_back(Gnome::Art::Point(x, y)); 139 140 x_wp+=x; 141 y_wp+=y; 138 coos.push_back(Gnome::Art::Point(coordinates[2*i], coordinates[2*i+1])); 139 140 x_wp+=coordinates[2*i]; 141 y_wp+=coordinates[2*i+1]; 142 142 } 143 143 … … 147 147 y_wp/=noe; 148 148 149 double x1,y1,x2,y2; 150 nodes[noe]>get_bounds(x1,y1,x2,y2); 151 double x=(x1+x2)/2; 152 double y=(y1+y2)/2; 153 154 dx=x_wpx; 155 dy=y_wpy; 149 dx=x_wpcoordinates[noe*2]; 150 dy=y_wpcoordinates[noe*2+1]; 156 151 nodes[noe]>move(dx, dy); 152 153 coordinates[noe*2]+=dx; 154 coordinates[noe*2+1]+=dy; 157 155 158 156 clicked_x=e>motion.x; … … 168 166 noe=numofcoos/2; 169 167 168 coordinates=new double [numofcoos+2]; 169 170 170 double x_wp=0; 171 171 double y_wp=0; … … 174 174 for(int i=0;i<numofcoos;i++) 175 175 { 176 double x=coosarray[i++];177 double y=coosarray[i];178 coos.push_back(Gnome::Art::Point( x, y));179 180 x_wp+= x;181 y_wp+= y;176 coordinates[i]=coosarray[i++]; 177 coordinates[i]=coosarray[i]; 178 coos.push_back(Gnome::Art::Point(coordinates[i1], coordinates[i])); 179 180 x_wp+=coordinates[i1]; 181 y_wp+=coordinates[i]; 182 182 183 183 } … … 194 194 *(nodes[i]) << Gnome::Canvas::Properties::fill_color("blue"); 195 195 *(nodes[i]) << Gnome::Canvas::Properties::outline_color("black"); 196 (nodes[i])>signal_event().connect(sigc::bind(sigc::mem_fun(*this, &CanvasExample::event_handler),true)); 197 } 198 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); 196 (nodes[i])>signal_event().connect(sigc::bind(sigc::mem_fun(*this, &CanvasExample::event_handler),i)); 197 } 198 199 coordinates[numofcoos]=x_wp/noe; 200 coordinates[numofcoos+1]=y_wp/noe; 201 202 wp=new Gnome::Art::Point(coordinates[numofcoos],coordinates[numofcoos+1]); 203 204 nodes[noe]= new Gnome::Canvas::Ellipse 205 ( 206 triangle, 207 coordinates[numofcoos]20, 208 coordinates[numofcoos+1]20, 209 coordinates[numofcoos]+20, 210 coordinates[numofcoos+1]+20 211 ); 202 212 *(nodes[noe]) << Gnome::Canvas::Properties::fill_color("blue"); 203 213 *(nodes[noe]) << Gnome::Canvas::Properties::outline_color("black"); 204 (nodes[noe])>signal_event().connect(sigc::bind(sigc::mem_fun(*this, &CanvasExample::tri_mover),true)); 214 (nodes[noe])>signal_event().connect(sigc::mem_fun(*this, &CanvasExample::tri_mover)); 215 205 216 206 217
Note: See TracChangeset
for help on using the changeset viewer.