Wed, 24 Apr 2013 20:33:06 +0300
Save the configuration before exiting so that grid choice is preserved.
gldraw.cpp | file | annotate | diff | comparison | revisions | |
gui.cpp | file | annotate | diff | comparison | revisions | |
ldtypes.cpp | file | annotate | diff | comparison | revisions |
--- a/gldraw.cpp Wed Apr 24 19:59:41 2013 +0300 +++ b/gldraw.cpp Wed Apr 24 20:33:06 2013 +0300 @@ -558,8 +558,8 @@ void GLRenderer::pick (uint mx, uint my, bool add) { GLint viewport[4]; + // Clear the selection if we do not wish to add to it. if (add == false) { - // Clear the selection if we don't wish to add to it. std::vector<LDObject*> paOldSelection = g_ForgeWindow->paSelection; g_ForgeWindow->paSelection.clear (); @@ -581,6 +581,8 @@ y0 = my; short x1, y1; + // Determine how big an area to read - with range picking, we pick by + // the area given, with single pixel picking, we use an 1 x 1 area. if (rangepick) { x1 = rangeStart.x (); y1 = rangeStart.y (); @@ -589,6 +591,7 @@ y1 = y0 + 1; } + // x0 and y0 must be less than x1 and y1, respectively. if (x0 > x1) dataswap (x0, x1); @@ -601,17 +604,20 @@ x1 = min<short> (x1, width); y1 = min<short> (y1, height); - short areawidth = (x1 - x0); - short areaheight = (y1 - y0); + const short areawidth = (x1 - x0); + const short areaheight = (y1 - y0); + const long numpixels = areawidth * areaheight; - const long numpixels = areawidth * areaheight; + // Allocate space for the pixel data. uchar* const pixeldata = new uchar[4 * numpixels]; uchar* pixelptr = &pixeldata[0]; assert (viewport[3] == height); + // Read pixels from the color buffer. glReadPixels (x0, viewport[3] - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixeldata); + // Go through each pixel read and add them to the selection. for (long i = 0; i < numpixels; ++i) { uint32 idx = (*(pixelptr) * 0x10000) + @@ -628,11 +634,14 @@ delete[] pixeldata; + // Remove duplicate entries. For this to be effective, the vector must be + // sorted first. std::vector<LDObject*>& sel = g_ForgeWindow->paSelection; std::sort (sel.begin(), sel.end ()); std::vector<LDObject*>::iterator pos = std::unique (sel.begin (), sel.end ()); sel.resize (std::distance (sel.begin (), pos)); + // Update everything now. g_ForgeWindow->buildObjList (); picking = false;
--- a/gui.cpp Wed Apr 24 19:59:41 2013 +0300 +++ b/gui.cpp Wed Apr 24 20:33:06 2013 +0300 @@ -878,6 +878,10 @@ } } + // Save the configuration before leaving so that, for instance, grid choice + // is preserved across instances. + config::save (); + ev->accept (); }
--- a/ldtypes.cpp Wed Apr 24 19:59:41 2013 +0300 +++ b/ldtypes.cpp Wed Apr 24 20:33:06 2013 +0300 @@ -267,52 +267,32 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -template<class T> static void transformSubObject (LDObject* obj, matrix mMatrix, - vertex vPos, short dColor) -{ - T* newobj = static_cast<T*> (obj); - for (short i = 0; i < (short)(sizeof newobj->vaCoords / sizeof *newobj->vaCoords); ++i) - newobj->vaCoords[i].transform (mMatrix, vPos); - - if (newobj->dColor == dMainColor) - newobj->dColor = dColor; -} - -// ----------------------------------------------------------------------------- -static void transformObject (LDObject* obj, matrix mMatrix, vertex vPos, - short dColor) -{ +static void transformObject (LDObject* obj, matrix transform, vertex pos, short parentcolor) { switch (obj->getType()) { case OBJ_Line: - transformSubObject<LDLine> (obj, mMatrix, vPos, dColor); - break; - case OBJ_CondLine: - transformSubObject<LDCondLine> (obj, mMatrix, vPos, dColor); - break; - case OBJ_Triangle: - transformSubObject<LDTriangle> (obj, mMatrix, vPos, dColor); - break; - case OBJ_Quad: - transformSubObject<LDQuad> (obj, mMatrix, vPos, dColor); + for (short i = 0; i < obj->vertices (); ++i) + obj->vaCoords[i].transform (transform, pos); break; case OBJ_Subfile: { LDSubfile* ref = static_cast<LDSubfile*> (obj); - matrix mNewMatrix = mMatrix * ref->mMatrix; - ref->vPosition.transform (mMatrix, vPos); + matrix mNewMatrix = transform * ref->mMatrix; + ref->vPosition.transform (transform, pos); ref->mMatrix = mNewMatrix; } - break; default: break; } + + if (obj->dColor == dMainColor) + obj->dColor = parentcolor; } // =============================================================================