[Lemon-commits] [lemon_svn] hegyi: r1645 - hugo/trunk/src/work/peter

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:46:46 CET 2006


Author: hegyi
Date: Thu Mar 17 18:20:37 2005
New Revision: 1645

Modified:
   hugo/trunk/src/work/peter/Makefile
   hugo/trunk/src/work/peter/canvas-test.cc

Log:
Magic anyangle is Faster, harder, Blumchen

Modified: hugo/trunk/src/work/peter/Makefile
==============================================================================
--- hugo/trunk/src/work/peter/Makefile	(original)
+++ hugo/trunk/src/work/peter/Makefile	Thu Mar 17 18:20:37 2005
@@ -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

Modified: hugo/trunk/src/work/peter/canvas-test.cc
==============================================================================
--- hugo/trunk/src/work/peter/canvas-test.cc	(original)
+++ hugo/trunk/src/work/peter/canvas-test.cc	Thu Mar 17 18:20:37 2005
@@ -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;i<noe;i++)
-				{
-					double x1,y1,x2,y2;
-					nodes[i]->get_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;i<noe;i++)
 				{
-					double x1,y1,x2,y2;
-					nodes[i]->get_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,15 +146,13 @@
 				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-x;
-				dy=y_wp-y;
+				dx=x_wp-coordinates[noe*2];
+				dy=y_wp-coordinates[noe*2+1];
 				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;i<numofcoos;i++)
 	{
-		double x=coosarray[i++];
-		double y=coosarray[i];
-		coos.push_back(Gnome::Art::Point(x, y));
+		coordinates[i]=coosarray[i++];
+		coordinates[i]=coosarray[i];
+		coos.push_back(Gnome::Art::Point(coordinates[i-1], coordinates[i]));
 
-		x_wp+=x;
-		y_wp+=y;
+		x_wp+=coordinates[i-1];
+		y_wp+=coordinates[i];
 
 	}
 
@@ -193,15 +193,26 @@
 		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);
 		*(nodes[i]) << Gnome::Canvas::Properties::fill_color("blue");
 		*(nodes[i]) << Gnome::Canvas::Properties::outline_color("black");
-		(nodes[i])->signal_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));
+
 
 
 }



More information about the Lemon-commits mailing list