Added ability to load the overlay meta

Tue, 02 Jul 2013 22:53:20 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 02 Jul 2013 22:53:20 +0300
changeset 317
e41ab239ed28
parent 316
b4fefda58f43
child 318
de051d2bd80b

Added ability to load the overlay meta

src/file.cpp file | annotate | diff | comparison | revisions
src/gldraw.cpp file | annotate | diff | comparison | revisions
src/gldraw.h file | annotate | diff | comparison | revisions
src/gui_actions.cpp file | annotate | diff | comparison | revisions
--- a/src/file.cpp	Tue Jul 02 21:39:47 2013 +0300
+++ b/src/file.cpp	Tue Jul 02 22:53:20 2013 +0300
@@ -532,6 +532,7 @@
 	g_win->updateTitle();
 	g_win->R()->setFile( file );
 	g_win->R()->resetAngles();
+	g_win->R()->overlaysFromObjects();
 	
 	// Add it to the recent files list.
 	addRecentFile( path );
@@ -674,16 +675,16 @@
 				}
 				elif( tokens[2] == "OVERLAY" )
 				{
-					CHECK_TOKEN_COUNT( 8 );
-					CHECK_TOKEN_NUMBERS( 4, 7 )
+					CHECK_TOKEN_COUNT( 9 );
+					CHECK_TOKEN_NUMBERS( 5, 8 )
 					
 					LDOverlay* obj = new LDOverlay;
-					obj->setFilename( tokens[2] );
-					obj->setCamera( tokens[3].toLong() );
-					obj->setX( tokens[4].toLong() );
-					obj->setY( tokens[5].toLong() );
-					obj->setWidth( tokens[6].toLong() );
-					obj->setHeight( tokens[7].toLong() );
+					obj->setFilename( tokens[3] );
+					obj->setCamera( tokens[4].toLong() );
+					obj->setX( tokens[5].toLong() );
+					obj->setY( tokens[6].toLong() );
+					obj->setWidth( tokens[7].toLong() );
+					obj->setHeight( tokens[8].toLong() );
 					return obj;
 				}
 			}
--- a/src/gldraw.cpp	Tue Jul 02 21:39:47 2013 +0300
+++ b/src/gldraw.cpp	Tue Jul 02 22:53:20 2013 +0300
@@ -1354,59 +1354,54 @@
 }
 
 // =============================================================================
-void GLRenderer::setupOverlay () {
-	if (camera () == Free)
-		return;
-	
-	OverlayDialog dlg;
+bool GLRenderer::setupOverlay ( GL::Camera cam, str file, int x, int y, int w, int h )
+{
+	QImage* img = new QImage( file );
+	overlayMeta& info = getOverlay( cam );
 	
-	if (!dlg.exec ())
-		return;
-	
-	QImage* img = new QImage (dlg.fpath ());
-	overlayMeta& info = getOverlay (camera ());
-	
-	if (img->isNull ()) {
+	if( img->isNull() )
+	{
 		critical ("Failed to load overlay image!");
 		delete img;
-		return;
+		return false;
 	}
 	
 	delete info.img; // delete the old image
 	
-	info.fname = dlg.fpath ();
-	info.lw = dlg.lwidth ();
-	info.lh = dlg.lheight ();
-	info.ox = dlg.ofsx ();
-	info.oy = dlg.ofsy ();
+	info.fname = file;
+	info.lw = w;
+	info.lh = h;
+	info.ox = x;
+	info.oy = y;
 	info.img = img;
 	
-	if (info.lw == 0)
-		info.lw = (info.lh * img->width ()) / img->height ();
-	else if (info.lh == 0)
-		info.lh = (info.lw * img->height ()) / img->width ();
+	if( info.lw == 0 )
+		info.lw = ( info.lh * img->width() ) / img->height();
+	else if( info.lh == 0 )
+		info.lh = ( info.lw * img->height() ) / img->width();
 	
-	const Axis x2d = cameraAxis (false),
-		y2d = cameraAxis (true);
+	const Axis x2d = cameraAxis( false ),
+		y2d = cameraAxis( true );
 	
 	double negXFac = g_staticCameras[m_camera].negX ? -1 : 1,
 		negYFac = g_staticCameras[m_camera].negY ? -1 : 1;
 	
 	info.v0 = info.v1 = g_origin;
-	info.v0[x2d] = -(info.ox * info.lw * negXFac) / img->width ();
-	info.v0[y2d] = (info.oy * info.lh * negYFac) / img->height ();
+	info.v0[x2d] = -( info.ox * info.lw * negXFac ) / img->width();
+	info.v0[y2d] = ( info.oy * info.lh * negYFac ) / img->height();
 	info.v1[x2d] = info.v0[x2d] + info.lw;
 	info.v1[y2d] = info.v0[y2d] + info.lh;
-	info.fname = dlg.fpath ();
 	
 	// Set alpha of all pixels to 0.5
-	for (long i = 0; i < img->width (); ++i)
-	for (long j = 0; j < img->height (); ++j) {
-		uint32 pixel = img->pixel (i, j);
-		img->setPixel (i, j, 0x80000000 | (pixel & 0x00FFFFFF));
+	for( long i = 0; i < img->width(); ++i )
+	for( long j = 0; j < img->height(); ++j )
+	{
+		uint32 pixel = img->pixel( i, j );
+		img->setPixel( i, j, 0x80000000 | ( pixel & 0x00FFFFFF ));
 	}
 	
 	updateOverlayObjects();
+	return true;
 }
 
 void GLRenderer::clearOverlay () {
@@ -1604,10 +1599,8 @@
 			delete meta.img;
 			meta.img = null;
 		}
-		elif( ovlobj && !meta.img )
-		{
-			
-		}
+		elif( ovlobj && ( !meta.img || meta.fname != ovlobj->filename() ))
+			setupOverlay( cam, ovlobj->filename(), ovlobj->x(), ovlobj->y(), ovlobj->width(), ovlobj->height() );
 	}
 }
 
--- a/src/gldraw.h	Tue Jul 02 21:39:47 2013 +0300
+++ b/src/gldraw.h	Tue Jul 02 22:53:20 2013 +0300
@@ -45,9 +45,6 @@
 	QImage* img;
 };
 
-// Alias for short namespaces
-typedef GLRenderer GL;
-
 // =============================================================================
 // GLRenderer
 // 
@@ -91,7 +88,7 @@
 	void           setBackground       ();
 	void           setCamera           (const Camera cam);
 	void           setDepthValue       (double depth);
-	void           setupOverlay        ();
+	bool           setupOverlay        ( GLRenderer::Camera cam, str file, int x, int y, int w, int h );
 	void           updateOverlayObjects();
 	void           zoomNotch           (bool inward);
 	void           zoomToFit           ();
@@ -151,7 +148,7 @@
 	void           compileVertex        (const vertex& vrt);                     // Compile a single vertex to a list
 	vertex         coordconv2_3         (const QPoint& pos2d, bool snap) const;  // Convert a 2D point to a 3D point
 	QPoint         coordconv3_2         (const vertex& pos3d) const;             // Convert a 3D point to a 2D point
-	LDOverlay*     findOverlayObject    ( GL::Camera cam );
+	LDOverlay*     findOverlayObject    ( Camera cam );
 	void           updateRectVerts      ();
 	void           pick                 (uint mouseX, uint mouseY);              // Perform object selection
 	void           setObjectColor       (LDObject* obj, const ListType list);    // Set the color to an object list
@@ -160,6 +157,9 @@
 	void           slot_toolTipTimer    ();
 };
 
+// Alias for short namespaces
+typedef GLRenderer GL;
+
 static const GLRenderer::ListType g_glListTypes[] = {
 	GL::NormalList,
 	GL::PickList,
--- a/src/gui_actions.cpp	Tue Jul 02 21:39:47 2013 +0300
+++ b/src/gui_actions.cpp	Tue Jul 02 22:53:20 2013 +0300
@@ -35,6 +35,7 @@
 #include "dialogs.h"
 #include "primitives.h"
 #include "ui_newpart.h"
+#include "widgets.h"
 
 extern_cfg (bool, gl_wireframe);
 
@@ -424,8 +425,15 @@
 	g_win->R ()->refresh ();
 }
 
-MAKE_ACTION (setOverlay, "Set Overlay Image", "overlay", "Set an overlay image", (0)) {
-	g_win->R ()->setupOverlay ();
+MAKE_ACTION( setOverlay, "Set Overlay Image", "overlay", "Set an overlay image", 0 )
+{
+	OverlayDialog dlg;
+	
+	if (!dlg.exec ())
+		return;
+	
+	g_win->R ()->setupOverlay( (GL::Camera) dlg.camera(), dlg.fpath(), dlg.ofsx(),
+		dlg.ofsy(), dlg.width(), dlg.height() );
 }
 
 MAKE_ACTION (clearOverlay, "Clear Overlay Image", "overlay-clear", "Clear the overlay image.", (0)) {

mercurial