[Gtkradiant] r4810 - in GtkRadiant/trunk: plugins/entity radiant

svn-noreply at zerowing.idsoftware.com svn-noreply at zerowing.idsoftware.com
Sun Sep 26 11:25:24 CDT 2004


Author: spog
Date: 2004-09-26 11:25:18 -0500 (Sun, 26 Sep 2004)
New Revision: 4810

Modified:
   GtkRadiant/trunk/plugins/entity/static.cpp
   GtkRadiant/trunk/radiant/surfacedialog.cpp
Log:
fixed textool window updates; added undo for textool operations

Modified: GtkRadiant/trunk/plugins/entity/static.cpp
===================================================================
--- GtkRadiant/trunk/plugins/entity/static.cpp	2004-09-26 10:38:53 UTC (rev 4809)
+++ GtkRadiant/trunk/plugins/entity/static.cpp	2004-09-26 16:25:18 UTC (rev 4810)
@@ -435,7 +435,7 @@
 
   void tesselate()
   {
-    const std::size_t numSegments = m_controlPoints.size() * 16;
+    const std::size_t numSegments = (m_controlPoints.size() - 1) * 16;
     m_renderCurve.m_vertices.resize(numSegments + 1);
     m_renderCurve.m_vertices[0].vertex = vertex3f_for_vector3(m_controlPoints[0]);
     for(std::size_t i = 1; i < numSegments; ++i)
@@ -520,7 +520,7 @@
 
   void tesselate()
   {
-    const std::size_t numSegments = m_controlPoints.size() * 16;
+    const std::size_t numSegments = (m_controlPoints.size() - 1) * 16;
     m_renderCurve.m_vertices.resize(numSegments + 1);
     m_renderCurve.m_vertices[0].vertex = vertex3f_for_vector3(m_controlPoints[0]);
     for(std::size_t i = 1; i < numSegments; ++i)

Modified: GtkRadiant/trunk/radiant/surfacedialog.cpp
===================================================================
--- GtkRadiant/trunk/radiant/surfacedialog.cpp	2004-09-26 10:38:53 UTC (rev 4809)
+++ GtkRadiant/trunk/radiant/surfacedialog.cpp	2004-09-26 16:25:18 UTC (rev 4810)
@@ -79,23 +79,31 @@
 
 #if TEXTOOL_ENABLED
 
+namespace TexTool
+{
+
 //Shamus: Textool function prototypes
-gboolean Textool_size_allocate(GtkWidget *, GtkAllocation *, gpointer);
-gboolean Textool_expose(GtkWidget *, GdkEventExpose *, gpointer);
-gboolean Textool_button_press(GtkWidget *, GdkEventButton *, gpointer);
-gboolean Textool_button_release(GtkWidget *, GdkEventButton *, gpointer);
-gboolean Textool_motion(GtkWidget *, GdkEventMotion *, gpointer);
-void Textool_flipX(GtkToggleButton *, gpointer);
-void Textool_flipY(GtkToggleButton *, gpointer);
+gboolean size_allocate(GtkWidget *, GtkAllocation *, gpointer);
+gboolean expose(GtkWidget *, GdkEventExpose *, gpointer);
+gboolean button_press(GtkWidget *, GdkEventButton *, gpointer);
+gboolean button_release(GtkWidget *, GdkEventButton *, gpointer);
+gboolean motion(GtkWidget *, GdkEventMotion *, gpointer);
+void flipX(GtkToggleButton *, gpointer);
+void flipY(GtkToggleButton *, gpointer);
 
-void Textool_Initialize(void);
 //End Textool function prototypes
 
 //Shamus: Textool globals
 GtkWidget * g_textoolWin;
-bool g_flipX, g_flipY;
 //End Textool globals
 
+void queueDraw()
+{
+  gtk_widget_queue_draw(g_textoolWin);
+}
+
+}
+
 #endif
 
 inline gdouble entry_value_as_float(GtkWidget* entry)
@@ -266,17 +274,19 @@
   s_texture_selection_dirty = true;
   SurfaceInspector_queueDraw();
   PatchInspector_queueDraw();
+
+#if TEXTOOL_ENABLED
+  if (g_bp_globals.m_bBrushPrimitMode)
+  {
+    TexTool::queueDraw();
+    //globalOutputStream() << "textool texture changed..\n";
+  }
+#endif
 }
 
 void SurfaceInspector_SelectionChanged(const SelectableInstance& selectable)
 {
   SurfaceInspector_updateSelection();
-#if TEXTOOL_ENABLED
-  //Shamus:
-  Textool_Initialize();							// Set up textool for the new texture
-//globalOutputStream() << "--> [SurfaceInspector_SelectionChanged] Queue...\n";
-  gtk_widget_queue_draw(g_textoolWin);			// & update the window
-#endif
 }
 
 void SurfaceInspector_SetCurrent_FromSelected()
@@ -301,14 +311,6 @@
       {
         SurfaceInspector_SetSelectedShader(name.c_str());
       }
-#if TEXTOOL_ENABLED
-  //Shamus:
-//This doesn't do crap either!
-//This really doesn't seem to do anything. :-(
-/*  Textool_Initialize();							// Set up textool for the new texture
-globalOutputStream() << "--> [SurfaceInspector_SetCurrent_FromSelected] Queue...\n";
-  gtk_widget_queue_draw(g_textoolWin);			// & update the window//*/
-#endif
     }
     else
     {
@@ -421,18 +423,6 @@
   g_SurfaceInspector.Update();
   g_SurfaceInspector.importData();
   g_SurfaceInspector.ShowDlg();
-
-#if TEXTOOL_ENABLED
-  if(g_bp_globals.m_bBrushPrimitMode)
-  {
-  //Shamus:
-//This doesn't do crap either!
-//Actually, this does work... Whenever the SI appears, this gets called...
-    Textool_Initialize();							// Set up textool for the new texture
-//    globalOutputStream() << "--> [DoSurface] Queue...\n";
-    gtk_widget_queue_draw(g_textoolWin);			// & update the window
-  }
-#endif
 }
 
 void SurfaceInspector_toggleShown()
@@ -509,34 +499,12 @@
 #endif
 
   Select_SetTexdef(texdef, brushprimit_texdef);
-
-#if TEXTOOL_ENABLED
-
-  //Shamus:
-  if (g_bp_globals.m_bBrushPrimitMode)
-  {
-    g_selectedBrushPrimitTexdef = brushprimit_texdef;
-    Textool_Initialize();						// Set up textool for the change
-    gtk_widget_queue_draw(g_textoolWin);		// & update the window
-  }
-#endif
 }
 
 static void OnBtnFaceFit(GtkWidget *widget, gpointer data) 
 {
   g_SurfaceInspector.exportData();
   SurfaceInspector_FitTexture();
-
-#if TEXTOOL_ENABLED
-
-  //Shamus:
-  if (g_bp_globals.m_bBrushPrimitMode)
-  {
-    SurfaceInspector_GetSelectedBPTexdef();		// Refresh g_selectedBrushPrimitTexdef...
-    Textool_Initialize();						// Set up textool for the change
-    gtk_widget_queue_draw(g_textoolWin);		// & update the window
-  }
-#endif
 }
 
 // =============================================================================
@@ -967,21 +935,21 @@
       gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
       {
         //Prolly should make this a member or global var, so the SI can draw on it...
-        g_textoolWin = gtk_glwidget_new(FALSE);
+        TexTool::g_textoolWin = gtk_glwidget_new(FALSE);
         // --> Dunno, but this stuff may be necessary... (Looks like it!)
-        gtk_widget_ref(g_textoolWin);
-        gtk_widget_set_events(g_textoolWin, GDK_DESTROY | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK);
-        GTK_WIDGET_SET_FLAGS(g_textoolWin, GTK_CAN_FOCUS);
+        gtk_widget_ref(TexTool::g_textoolWin);
+        gtk_widget_set_events(TexTool::g_textoolWin, GDK_DESTROY | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK);
+        GTK_WIDGET_SET_FLAGS(TexTool::g_textoolWin, GTK_CAN_FOCUS);
         // <-- end stuff...
-        gtk_widget_show(g_textoolWin);
-        gtk_widget_set_usize(g_textoolWin, -1, 240);	//Yeah!
-        gtk_container_add(GTK_CONTAINER(frame), g_textoolWin);
+        gtk_widget_show(TexTool::g_textoolWin);
+        gtk_widget_set_usize(TexTool::g_textoolWin, -1, 240);	//Yeah!
+        gtk_container_add(GTK_CONTAINER(frame), TexTool::g_textoolWin);
 
-        g_signal_connect(G_OBJECT(g_textoolWin), "size_allocate", G_CALLBACK(Textool_size_allocate), NULL);
-        g_signal_connect(G_OBJECT(g_textoolWin), "expose_event", G_CALLBACK(Textool_expose), NULL);
-        g_signal_connect(G_OBJECT(g_textoolWin), "button_press_event", G_CALLBACK(Textool_button_press), NULL);
-        g_signal_connect(G_OBJECT(g_textoolWin), "button_release_event", G_CALLBACK(Textool_button_release), NULL);
-        g_signal_connect(G_OBJECT(g_textoolWin), "motion_notify_event", G_CALLBACK(Textool_motion), NULL);
+        g_signal_connect(G_OBJECT(TexTool::g_textoolWin), "size_allocate", G_CALLBACK(TexTool::size_allocate), NULL);
+        g_signal_connect(G_OBJECT(TexTool::g_textoolWin), "expose_event", G_CALLBACK(TexTool::expose), NULL);
+        g_signal_connect(G_OBJECT(TexTool::g_textoolWin), "button_press_event", G_CALLBACK(TexTool::button_press), NULL);
+        g_signal_connect(G_OBJECT(TexTool::g_textoolWin), "button_release_event", G_CALLBACK(TexTool::button_release), NULL);
+        g_signal_connect(G_OBJECT(TexTool::g_textoolWin), "motion_notify_event", G_CALLBACK(TexTool::motion), NULL);
       }
       {
         GtkWidget * hbox = gtk_hbox_new(FALSE, 5);
@@ -1000,11 +968,11 @@
 //        gtk_container_add(GTK_CONTAINER(frame), hbox);
 
 //Hmm. Do we really need g_object_set_data? Mebbe not... And we don't! :-)
-//        g_object_set_data(G_OBJECT(flipX), "handler", gint_to_pointer(g_signal_connect(G_OBJECT(flipX), "toggled", G_CALLBACK(Textool_flipX), 0)));
-//        g_object_set_data(G_OBJECT(flipY), "handler", gint_to_pointer(g_signal_connect(G_OBJECT(flipY), "toggled", G_CALLBACK(Textool_flipY), 0)));
+//        g_object_set_data(G_OBJECT(flipX), "handler", gint_to_pointer(g_signal_connect(G_OBJECT(flipX), "toggled", G_CALLBACK(TexTool::flipX), 0)));
+//        g_object_set_data(G_OBJECT(flipY), "handler", gint_to_pointer(g_signal_connect(G_OBJECT(flipY), "toggled", G_CALLBACK(TexTool::flipY), 0)));
 //Instead, just do:
-        g_signal_connect(G_OBJECT(flipX), "toggled", G_CALLBACK(Textool_flipX), NULL);
-        g_signal_connect(G_OBJECT(flipY), "toggled", G_CALLBACK(Textool_flipY), NULL);
+        g_signal_connect(G_OBJECT(flipX), "toggled", G_CALLBACK(TexTool::flipX), NULL);
+        g_signal_connect(G_OBJECT(flipY), "toggled", G_CALLBACK(TexTool::flipY), NULL);
       }
     }
 #endif
@@ -1134,17 +1102,6 @@
 
   UndoableCommand undo("textureProjectionSetSelected");
   Select_SetTexdef(texdef, brushprimit_texdef);
-
-#if TEXTOOL_ENABLED
-
-  //Shamus:
-  if (g_bp_globals.m_bBrushPrimitMode)
-  {
-    SurfaceInspector_GetSelectedBPTexdef();		// Refresh g_selectedBrushPrimitTexdef...
-    Textool_Initialize();						// Set up textool for the change
-    gtk_widget_queue_draw(g_textoolWin);		// & update the window
-  }
-#endif
 }
 
 
@@ -1212,6 +1169,8 @@
 }
 
 #if TEXTOOL_ENABLED
+
+namespace TexTool { // namespace hides these symbols from other object-files
 //
 //Shamus: Textool functions, including GTK+ callbacks
 //
@@ -1224,10 +1183,10 @@
 	float width(void) { return fabs(maxX - minX); }
 	float height(void) { return fabs(maxY - minY); }
 };
+
 //This seems to control the texture scale... (Yep! ;-)
 Extent extents = { -2.0f, -2.0f, +2.0f, +2.0f };
 brushprimit_texdef_t tm;						// Texture transform matrix
-Vector2 origPts[MAX_POINTS_ON_WINDING];
 Vector2 pts[MAX_POINTS_ON_WINDING];
 Vector2 center;
 int numPts;
@@ -1243,6 +1202,7 @@
 //int dragPoint;
 //int anchorPoint;
 bool haveAnchor = false;
+brushprimit_texdef_t currentBP;
 brushprimit_texdef_t origBP;					// Original brush primitive (before we muck it up)
 float controlRadius = 5.0f;
 float rotationAngle = 0.0f;
@@ -1259,6 +1219,7 @@
 float origAngle, origScaleX, origScaleY;
 Vector2 oldCenter;
 
+
 // Function prototypes (move up to top later...)
 
 void DrawCircularArc(Vector2 ctr, float startAngle, float endAngle, float radius);
@@ -1280,40 +1241,28 @@
 	textureSize.y() = face.shader().m_state->shader()->getTexture()->height;
 //globalOutputStream() << "--> Texture #" << textureNum << ": " << textureSize.x() << " x " << textureSize.y() << "...\n";
 
-	origBP = g_selectedBrushPrimitTexdef;
+	currentBP = SurfaceInspector_GetSelectedBPTexdef();
 
+  face.EmitTextureCoordinates();
 	winding_t & w = face.winding();
 	int count = 0;
 
 	for(winding_t::const_iterator i=w.begin(); i!=w.end(); i++)
 	{
-		origPts[count].x() = pts[count].x() = (*i).texcoord.x(),
-		origPts[count].y() = pts[count].y() = (*i).texcoord.y();
+    //globalOutputStream() << (*i).texcoord.x() << " " << (*i).texcoord.y() << ", ";
+		pts[count].x() = (*i).texcoord.x();
+		pts[count].y() = (*i).texcoord.y();
 		count++;
 	}
 
 	numPts = count;
-//globalOutputStream() << "--> Original BP: [" << origBP.coords[0][0] << "][" << origBP.coords[0][1] << "][" << origBP.coords[0][2] << "]\n";
-//globalOutputStream() << "                 [" << origBP.coords[1][0] << "][" << origBP.coords[1][1] << "][" << origBP.coords[1][2] << "]\n";
-//float angle = atan2(origBP.coords[0][1], origBP.coords[0][0]) * 180.0f / 3.141592653589f;
-	origAngle = (origBP.coords[0][1] > 0 ? PI : -PI);	// Could also be -PI... !!! FIX !!! [DONE]
 
-	if (origBP.coords[0][0] != 0.0f)
-		origAngle = atan(origBP.coords[0][1] / origBP.coords[0][0]);
-
-	origScaleX = origBP.coords[0][0] / cos(origAngle);
-	origScaleY = origBP.coords[1][1] / cos(origAngle);
-	rotationAngle = origAngle;
-	oldCenter[0] = oldCenter[1] = 0;
-
-globalOutputStream() << "--> BP stats: ang=" << origAngle * RAD_TO_DEG << ", scale=" << origScaleX << "/" << origScaleY << "\n";
-//Should also set the Flip X/Y checkboxes here as well... !!! FIX !!!
-//Also: should reverse texture left/right up/down instead of flipping the points...
+  //globalOutputStream() << " ..copied points\n";
 }
 
 	brushprimit_texdef_t bp;
 //This approach is probably wrongheaded and just not right anyway. So, !!! FIX !!! [DONE]
-void Textool_CommitChanges(void)
+void CommitChanges(void)
 {
 	texdef_t t;									// Throwaway, since this is BP only
 
@@ -1345,25 +1294,12 @@
 
 void UpdateControlPoints(void)
 {
-//This is all wrong--it doesn't take the BP scaling into account... Or the ST scaling... !!! FIX !!!
-	for(int i=0; i<numPts; i++)
-/*		pts[i].x() = origPts[i].x() * tm.coords[0][0] + origPts[i].y() * tm.coords[0][1] + tm.coords[0][2],
-		pts[i].y() = origPts[i].x() * tm.coords[1][0] + origPts[i].y() * tm.coords[1][1] + tm.coords[1][2];//*/
-		// Kludge (& doesn't work correctly for non-square textures... !!! FIX !!!)
-		pts[i].x() = origPts[i].x() * tm.coords[0][0] + origPts[i].y() * tm.coords[0][1] + (tm.coords[0][2] / textureSize.x()),
-		pts[i].y() = origPts[i].x() * tm.coords[1][0] + origPts[i].y() * tm.coords[1][1] + (tm.coords[1][2] / textureSize.y());//*/
+	CommitChanges();
 
-	Textool_CommitChanges();
+  // Init texture transform matrix
 
-//Disnowok...
-// NOTE FROM THE FUTURE: The reason we don't do the following is that the points *have already
-// been run through origBP*! Doing it again only screws things up worse!
-/*
-//	brushprimit_texdef_t bp = g_selectedBrushPrimitTexdef;
-
-	for(int i=0; i<numPts; i++)
-		pts[i].x() = origPts[i].x() * bp.coords[0][0] + origPts[i].y() * bp.coords[0][1] + bp.coords[0][2],
-		pts[i].y() = origPts[i].x() * bp.coords[1][0] + origPts[i].y() * bp.coords[1][1] + bp.coords[1][2];//*/
+	tm.coords[0][0] = 1.0f; tm.coords[0][1] = 0.0f; tm.coords[0][2] = 0.0f;
+	tm.coords[1][0] = 0.0f; tm.coords[1][1] = 1.0f; tm.coords[1][2] = 0.0f;
 }
 /*
 Fit texture code calls this:
@@ -1419,12 +1355,13 @@
 
 //Small problem with this thing: It's scaled to the texture which is all screwed up... !!! FIX !!! [DONE]
 //Prolly should separate out the grid drawing so that we can draw it behind the polygon.
-float gridWidth = 1.3f;// Let's try an absolute height... WORKS!!!
+const float gridWidth = 1.3f;// Let's try an absolute height... WORKS!!!
 // NOTE that 2.0 is the height of the viewport. Dunno why... Should make collision
 //      detection easier...
-float gridRadius = gridWidth * 0.5f;
+const float gridRadius = gridWidth * 0.5f;
 
-float widgetColor[10][3] = {
+typedef const float WidgetColor[3];
+const WidgetColor widgetColor[10] = {
 	{ 1.0000f, 0.2000f, 0.0000f },			// Red
 	{ 0.9137f, 0.9765f, 0.4980f },			// Yellow
 	{ 0.0000f, 0.6000f, 0.3216f },			// Green
@@ -1465,22 +1402,9 @@
 //account the transforms that we toss with the new identity matrix. Dunno which is better.
 	qglLoadIdentity();
 	qglScalef(xScale, 1.0, 1.0);				// Will that square it up? Yup.
-	qglRotatef(rotationAngle * RAD_TO_DEG, 0.0, 0.0, -1.0);
+	qglRotatef(static_cast<float>(radians_to_degrees(atan2(-currentBP.coords[0][1], currentBP.coords[0][0]))), 0.0, 0.0, -1.0);
 	qglTranslatef(-center.x(), -center.y(), 0.0);
 
-	qglColor3fv(widgetColor[COLOR_GREY]);
-	qglBegin(GL_LINES);
-
-	for(int i=0; i<11; i++)
-	{
-		qglVertex2f(xStart, yStart + i * (gridWidth / 10.0f));
-		qglVertex2f(xStart + gridWidth, yStart + i * (gridWidth / 10.0f));
-		qglVertex2f(xStart + i * (gridWidth / 10.0f), yStart);
-		qglVertex2f(xStart + i * (gridWidth / 10.0f), yStart + gridWidth);
-	}
-
-	qglEnd();
-
 	// Circle
 	qglColor3fv(translatingX && translatingY ? widgetColor[COLOR_LT_YELLOW] : widgetColor[COLOR_YELLOW]);
 	qglBegin(GL_LINE_LOOP);
@@ -1560,6 +1484,7 @@
 
 void DrawControlPoints(void)
 {
+	qglColor3f(1, 1, 1);
 	qglBegin(GL_LINE_LOOP);
 	
 	for(int i=0; i<numPts; i++)
@@ -1595,28 +1520,27 @@
 		qglVertex2f(ctr.x() + radius * cos(angle), ctr.y() + radius * sin(angle));
 }
 
-void Textool_Initialize(void)
-{
-	CopyPointsFromSelectedFace();
 
+void focus()
+{
 	if (numPts == 0)
 		return;
 
 	// Find selected texture's extents...
 
-	extents.minX = extents.maxX = origPts[0].x(),
-	extents.minY = extents.maxY = origPts[0].y();
+	extents.minX = extents.maxX = pts[0].x(),
+	extents.minY = extents.maxY = pts[0].y();
 
 	for(int i=1; i<numPts; i++)
 	{
-		if (origPts[i].x() < extents.minX)
-			extents.minX = origPts[i].x();
-		if (origPts[i].x() > extents.maxX)
-			extents.maxX = origPts[i].x();
-		if (origPts[i].y() < extents.minY)
-			extents.minY = origPts[i].y();
-		if (origPts[i].y() > extents.maxY)
-			extents.maxY = origPts[i].y();
+		if (pts[i].x() < extents.minX)
+			extents.minX = pts[i].x();
+		if (pts[i].x() > extents.maxX)
+			extents.maxX = pts[i].x();
+		if (pts[i].y() < extents.minY)
+			extents.minY = pts[i].y();
+		if (pts[i].y() > extents.maxY)
+			extents.maxY = pts[i].y();
 	}
 
 	// Do some viewport fitting stuff...
@@ -1657,30 +1581,20 @@
 	extents.minY = center.y() - 0.5f * TSize, extents.maxY = center.y() + 0.5f * TSize;
 //globalOutputStream() << "--> Extents (stage 3): " << extents.minX << ", "
 //	<< extents.maxX << ", " << extents.minY << ", " << extents.maxY << "\n";
-
-	// Init texture transform matrix
-
-	tm.coords[0][0] = 1.0f, tm.coords[0][1] = 0.0f, tm.coords[0][2] = 0.0f,
-	tm.coords[1][0] = 0.0f, tm.coords[1][1] = 1.0f, tm.coords[1][2] = 0.0f;
-
-	// Probably should init button/anchor states here as well...
-//	rotationAngle = 0.0f;
 }
 
-gboolean Textool_size_allocate(GtkWidget * win, GtkAllocation * a, gpointer)
+gboolean size_allocate(GtkWidget * win, GtkAllocation * a, gpointer)
 {
 	windowSize.x() = a->width;
 	windowSize.y() = a->height;
 //  Camera_updateProjection(camwnd->getCamera());
-	Textool_Initialize();
+	queueDraw();
 //  camwnd->m_window_observer->SetSize(camwnd->getCamera().width, camwnd->getCamera().height);
 //  camwnd->queue_draw();
-	gtk_widget_queue_draw(g_textoolWin);
-
 	return false;
 }
 
-gboolean Textool_expose(GtkWidget * win, GdkEventExpose * e, gpointer)
+gboolean expose(GtkWidget * win, GdkEventExpose * e, gpointer)
 {
 //	globalOutputStream() << "--> Textool Window was exposed!\n";
 //	globalOutputStream() << "    (window width/height: " << cc << "/" << e->area.height << ")\n";
@@ -1695,6 +1609,15 @@
 		return true;
 	}
 	
+	CopyPointsFromSelectedFace();
+
+  if(!lButtonDown)
+  {
+    focus();
+  }
+
+	// Probably should init button/anchor states here as well...
+//	rotationAngle = 0.0f;
 	qglClearColor(0, 0, 0, 0);
 	qglViewport(0, 0, e->area.width, e->area.height);
 	qglMatrixMode(GL_PROJECTION);
@@ -1725,6 +1648,25 @@
 	qglEnd();
 	qglDisable(GL_TEXTURE_2D);
 
+  // draw the texture-space grid
+	qglColor3fv(widgetColor[COLOR_GREY]);
+	qglBegin(GL_LINES);
+
+  const int gridSubdivisions = 8;
+  const float gridExtents = 4.0f;
+
+	for(int i = 0; i < gridSubdivisions + 1; ++i)
+	{
+    float y = i * (gridExtents / float(gridSubdivisions));
+    float x = i * (gridExtents / float(gridSubdivisions));
+		qglVertex2f(0, y);
+		qglVertex2f(gridExtents, y);
+		qglVertex2f(x, 0);
+		qglVertex2f(x, gridExtents);
+	}
+
+	qglEnd();
+
 	DrawControlPoints();
 	DrawControlWidgets();
 //???
@@ -1754,13 +1696,34 @@
 Vector2 trans2;
 Vector2 dragPoint;	// Defined in terms of window space (+x/-y)
 Vector2 oldTrans;
-gboolean Textool_button_press(GtkWidget * win, GdkEventButton * e, gpointer)
+gboolean button_press(GtkWidget * win, GdkEventButton * e, gpointer)
 {
 //	globalOutputStream() << "--> Textool button press...\n";
 
 	if (e->button == 1)
 	{
 		lButtonDown = true;
+    GlobalUndoSystem().start();
+
+    origBP = currentBP;
+
+  //globalOutputStream() << "--> Original BP: [" << origBP.coords[0][0] << "][" << origBP.coords[0][1] << "][" << origBP.coords[0][2] << "]\n";
+  //globalOutputStream() << "                 [" << origBP.coords[1][0] << "][" << origBP.coords[1][1] << "][" << origBP.coords[1][2] << "]\n";
+  //float angle = atan2(origBP.coords[0][1], origBP.coords[0][0]) * 180.0f / 3.141592653589f;
+	  origAngle = (origBP.coords[0][1] > 0 ? PI : -PI);	// Could also be -PI... !!! FIX !!! [DONE]
+
+	  if (origBP.coords[0][0] != 0.0f)
+		  origAngle = atan(origBP.coords[0][1] / origBP.coords[0][0]);
+
+	  origScaleX = origBP.coords[0][0] / cos(origAngle);
+	  origScaleY = origBP.coords[1][1] / cos(origAngle);
+	  rotationAngle = origAngle;
+	  oldCenter[0] = oldCenter[1] = 0;
+
+    //globalOutputStream() << "--> BP stats: ang=" << origAngle * RAD_TO_DEG << ", scale=" << origScaleX << "/" << origScaleY << "\n";
+    //Should also set the Flip X/Y checkboxes here as well... !!! FIX !!!
+    //Also: should reverse texture left/right up/down instead of flipping the points...
+
 //disnowok
 //float nx = windowSize.x() * (e->x - extents.minX) / (extents.maxX - extents.minX);
 //float ny = windowSize.y() * (e->y - extents.minY) / (extents.maxY - extents.minY);
@@ -1782,7 +1745,7 @@
 		oldCenter.x() = center.x();
 		oldCenter.y() = center.y();
 
-		gtk_widget_queue_draw(g_textoolWin);
+	  queueDraw();
 
 		return true;
 	}
@@ -1796,7 +1759,7 @@
 	return false;
 }
 
-gboolean Textool_button_release(GtkWidget * win, GdkEventButton * e, gpointer)
+gboolean button_release(GtkWidget * win, GdkEventButton * e, gpointer)
 {
 //	globalOutputStream() << "--> Textool button release...\n";
 
@@ -1811,10 +1774,32 @@
 			center.x() = ptx, center.y() = pty;//*/
 
 		lButtonDown = false;
+
+    if(translatingX || translatingY)
+    {
+      GlobalUndoSystem().finish("translateTexture");
+    }
+    else if(rotating)
+    {
+      GlobalUndoSystem().finish("rotateTexture");
+    }
+    else if(scalingX || scalingY)
+    {
+      GlobalUndoSystem().finish("scaleTexture");
+    }
+    else if(resizingX || resizingY)
+    {
+      GlobalUndoSystem().finish("resizeTexture");
+    }
+    else
+    {
+      GlobalUndoSystem().finish("textoolUnknown");
+    }
+
 		rotating = translatingX = translatingY = scalingX = scalingY
 			= resizingX = resizingY = false;
 
-		gtk_widget_queue_draw(g_textoolWin);
+	  queueDraw();
 	}
 	else if (e->button == 3)
 	{
@@ -1843,7 +1828,7 @@
   c[1] = ((float)(y))/((float)(m_rect.bottom-m_rect.top))*(m_Maxs[1]-m_Mins[1])+m_Mins[1];
 }
 */
-gboolean Textool_motion(GtkWidget * win, GdkEventMotion * e, gpointer)
+gboolean motion(GtkWidget * win, GdkEventMotion * e, gpointer)
 {
 //	globalOutputStream() << "--> Textool motion...\n";
 
@@ -1957,12 +1942,9 @@
 //And this is the wrong place for this anyway (I'm pretty sure).
 /*tm.coords[0][2] += oldCenter.x();
 tm.coords[1][2] += oldCenter.y();//*/
-			UpdateControlPoints();
+			UpdateControlPoints(); // will cause a redraw
 		}
 
-//globalOutputStream() << "--> [Textool_motion] Queue...\n";
-		gtk_widget_queue_draw(g_textoolWin);
-
 		return true;
 	}
 	else									// Check for widget mouseovers
@@ -2021,7 +2003,7 @@
 			rotating = true;
 		}
 
-		gtk_widget_queue_draw(g_textoolWin);
+	  queueDraw();
 
 		return true;
 	}
@@ -2031,12 +2013,11 @@
 
 //It seems the fake tex coords conversion is screwing this stuff up... !!! FIX !!!
 //This is still wrong... Prolly need to do something with the oldScaleX/Y stuff...
-void Textool_flipX(GtkToggleButton *, gpointer)
+void flipX(GtkToggleButton *, gpointer)
 {
 //	globalOutputStream() << "--> Flip X...\n";
 	//Shamus:
 //	SurfaceInspector_GetSelectedBPTexdef();		// Refresh g_selectedBrushPrimitTexdef...
-//	Textool_Initialize();						// Set up textool for the change
 //	tm.coords[0][0] = -tm.coords[0][0];
 //	tm.coords[1][0] = -tm.coords[1][0];
 //	tm.coords[0][0] = -tm.coords[0][0];			// This should be correct now...Nope.
@@ -2045,10 +2026,9 @@
 	tm.coords[1][0] = -tm.coords[1][0];
 //	tm.coords[2][0] = -tm.coords[2][0];//wil wok? no.
 	UpdateControlPoints();
-	gtk_widget_queue_draw(g_textoolWin);		// & update the window
 }
 
-void Textool_flipY(GtkToggleButton *, gpointer)
+void flipY(GtkToggleButton *, gpointer)
 {
 //	globalOutputStream() << "--> Flip Y...\n";
 //	tm.coords[0][1] = -tm.coords[0][1];
@@ -2059,7 +2039,8 @@
 	tm.coords[1][1] = -tm.coords[1][1];
 //	tm.coords[2][1] = -tm.coords[2][1];//wil wok? no.
 	UpdateControlPoints();
-	gtk_widget_queue_draw(g_textoolWin);		// & update the window
 }
 
+} // end namespace TexTool
+
 #endif




More information about the Gtkradiant mailing list