# HG changeset patch # User hegyi # Date 1111080037 0 # Node ID 4401e1aeafcfc9462763b8ca3a757eb9f24ee95d # Parent 7f4f2855fa11e305f9a57fcc01900f417350d95a Magic anyangle is Faster, harder, Blumchen diff -r 7f4f2855fa11 -r 4401e1aeafcf src/work/peter/Makefile --- a/src/work/peter/Makefile Thu Mar 17 11:45:05 2005 +0000 +++ b/src/work/peter/Makefile Thu Mar 17 17:20:37 2005 +0000 @@ -1,2 +1,7 @@ triangle: canvas-test.cc g++ canvas-test.cc -W -Wall -ansi -pedantic -o triangle `pkg-config libgnomecanvasmm-2.6 --cflags --libs` + +run: triangle + ./triangle 100 100 -100 100 0 -100 + +.PHONY: run diff -r 7f4f2855fa11 -r 4401e1aeafcf src/work/peter/canvas-test.cc --- a/src/work/peter/canvas-test.cc Thu Mar 17 11:45:05 2005 +0000 +++ b/src/work/peter/canvas-test.cc Thu Mar 17 17:20:37 2005 +0000 @@ -18,10 +18,10 @@ private: ///Event handler function that handles dragging nodes of triangle - bool event_handler(GdkEvent* e, bool b); + bool event_handler(GdkEvent* e, int b); ///Event handler function that handles dragging triangle - bool tri_mover(GdkEvent* e, bool b); + bool tri_mover(GdkEvent* e); ///Coordinates of Weight Point of tirangle Gnome::Art::Point * wp; @@ -38,6 +38,9 @@ ///Number Of Elements - the number of nodes int noe; + ///Array of coordinates + double * coordinates; + ///At this location was the mousebutton pressed. ///It helps to calculate the distance of dragging. double clicked_x, clicked_y; @@ -52,9 +55,8 @@ }; ///When we click on the weight point we can drag the whole triangle. This function resolves it. -bool CanvasExample::tri_mover(GdkEvent* e, bool b) +bool CanvasExample::tri_mover(GdkEvent* e) { - b=b; switch(e->type) { case GDK_BUTTON_PRESS: @@ -71,24 +73,24 @@ { double dx=e->motion.x-clicked_x; double dy=e->motion.y-clicked_y; + + Gnome::Canvas::Points coos; + for(int i=0;i<=noe;i++) { nodes[i]->move(dx,dy); + + double x=(coordinates[2*i]+=dx); + double y=(coordinates[2*i+1]+=dy); + + if(i!=noe)coos.push_back(Gnome::Art::Point(x,y)); + } + clicked_x=e->motion.x; clicked_y=e->motion.y; - Gnome::Canvas::Points coos; - for(int i=0;iget_bounds(x1,y1,x2,y2); - double x=(x1+x2)/2; - double y=(y1+y2)/2; - coos.push_back(Gnome::Art::Point(x, y)); - } sides->property_points().set_value(coos); - } default: break; } @@ -98,9 +100,8 @@ ///This function moves only one node of triangle, ///but recalculate the location of wight point, ///and also redraw the sides of the planefigure. -bool CanvasExample::event_handler(GdkEvent* e, bool b) +bool CanvasExample::event_handler(GdkEvent* e, int b) { - b=b; switch(e->type) { case GDK_BUTTON_PRESS: @@ -124,6 +125,9 @@ double dy=e->motion.y-clicked_y; active_item->move(dx, dy); + coordinates[2*b]+=dx; + coordinates[2*b+1]+=dy; + Gnome::Canvas::Points coos; double x_wp=0; @@ -131,14 +135,10 @@ for(int i=0;iget_bounds(x1,y1,x2,y2); - double x=(x1+x2)/2; - double y=(y1+y2)/2; - coos.push_back(Gnome::Art::Point(x, y)); + coos.push_back(Gnome::Art::Point(coordinates[2*i], coordinates[2*i+1])); - x_wp+=x; - y_wp+=y; + x_wp+=coordinates[2*i]; + y_wp+=coordinates[2*i+1]; } sides->property_points().set_value(coos); @@ -146,14 +146,12 @@ x_wp/=noe; y_wp/=noe; - double x1,y1,x2,y2; - nodes[noe]->get_bounds(x1,y1,x2,y2); - double x=(x1+x2)/2; - double y=(y1+y2)/2; + dx=x_wp-coordinates[noe*2]; + dy=y_wp-coordinates[noe*2+1]; + nodes[noe]->move(dx, dy); - dx=x_wp-x; - dy=y_wp-y; - nodes[noe]->move(dx, dy); + coordinates[noe*2]+=dx; + coordinates[noe*2+1]+=dy; clicked_x=e->motion.x; clicked_y=e->motion.y; @@ -167,18 +165,20 @@ { noe=numofcoos/2; + coordinates=new double [numofcoos+2]; + double x_wp=0; double y_wp=0; Gnome::Canvas::Points coos; for(int i=0;isignal_event().connect(sigc::bind(sigc::mem_fun(*this, &CanvasExample::event_handler),true)); + (nodes[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &CanvasExample::event_handler),i)); } - wp=new Gnome::Art::Point(x_wp/noe,y_wp/noe); + coordinates[numofcoos]=x_wp/noe; + coordinates[numofcoos+1]=y_wp/noe; - nodes[noe]= new Gnome::Canvas::Ellipse(triangle, wp->get_x()-20, wp->get_y()-20, wp->get_x()+20, wp->get_y()+20); + wp=new Gnome::Art::Point(coordinates[numofcoos],coordinates[numofcoos+1]); + + nodes[noe]= new Gnome::Canvas::Ellipse + ( + triangle, + coordinates[numofcoos]-20, + coordinates[numofcoos+1]-20, + coordinates[numofcoos]+20, + coordinates[numofcoos+1]+20 + ); *(nodes[noe]) << Gnome::Canvas::Properties::fill_color("blue"); *(nodes[noe]) << Gnome::Canvas::Properties::outline_color("black"); - (nodes[noe])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &CanvasExample::tri_mover),true)); + (nodes[noe])->signal_event().connect(sigc::mem_fun(*this, &CanvasExample::tri_mover)); + }