Sat, 04 May 2013 18:31:03 +0300
Mass renaming and cleanup. GLRenderer's and ForgeWindow's members made private. Names of common identifiers shortened, moved logVA to ForgeWindow since it's a GUI-related function (though logf remains under main.cpp for ubiquitous usage)
--- a/bbox.cpp Sat May 04 13:52:47 2013 +0300 +++ b/bbox.cpp Sat May 04 18:31:03 2013 +0300 @@ -34,10 +34,10 @@ void bbox::calculate () { reset (); - if (!g_CurrentFile) + if (!g_curfile) return; - for (LDObject* obj : g_CurrentFile->objects) + for (LDObject* obj : g_curfile->m_objs) calcObject (obj); }
--- a/common.h Sat May 04 13:52:47 2013 +0300 +++ b/common.h Sat May 04 18:31:03 2013 +0300 @@ -16,6 +16,10 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +// ============================================================================= +// This file is included one way or another in every source file of LDForge. +// Stuff defined and included here is universally included. + #ifndef COMMON_H #define COMMON_H @@ -41,12 +45,15 @@ // ============--- // #define RELEASE +// Version string identifier static const str versionString = format ("%d.%d", VERSION_MAJOR, VERSION_MINOR); #ifdef __GNUC__ - #define FORMAT_PRINTF(M,N) __attribute__ ((format (printf, M, N))) +# define FORMAT_PRINTF(M,N) __attribute__ ((format (printf, M, N))) +# define ATTR(N) __attribute__ ((N)) #else - #define FORMAT_PRINTF(M,N) +# define FORMAT_PRINTF(M,N) +# define ATTR(N) #endif // __GNUC__ #ifdef WIN32 @@ -63,7 +70,10 @@ #undef null #endif // null +// Null pointer static const std::nullptr_t null = nullptr; + +// Main and edge color identifiers static const short maincolor = 16; static const short edgecolor = 24; @@ -119,8 +129,7 @@ static const double pi = 3.14159265358979323846f; // ----------------------------------------------------------------------------- -// main.cpp -enum logtype_e { +enum LogType { LOG_Normal, LOG_Success, LOG_Info, @@ -129,16 +138,19 @@ LOG_Dev, }; -void logf (const char* fmt, ...) FORMAT_PRINTF (1, 2); -void logf (logtype_e eType, const char* fmt, ...) FORMAT_PRINTF (2, 3); +// logf - universal access to the message log. Defined here so that I don't have +// to include gui.h here and recompile everything every time that file changes. +// logf is defined in main.cpp +void logf (const char* fmtstr, ...) FORMAT_PRINTF (1, 2); +void logf (LogType type, const char* fmtstr, ...) FORMAT_PRINTF (2, 3); // ----------------------------------------------------------------------------- // Vertex at (0, 0, 0) -extern const vertex g_Origin; +extern const vertex g_origin; // ----------------------------------------------------------------------------- // Pointer to the OpenFile which is currently being edited by the user. -extern OpenFile* g_CurrentFile; +extern OpenFile* g_curfile; // ----------------------------------------------------------------------------- // Pointer to the bounding box. @@ -146,14 +158,14 @@ // ----------------------------------------------------------------------------- // Vector of all currently opened files. -extern vector<OpenFile*> g_LoadedFiles; +extern vector<OpenFile*> g_loadedFiles; // ----------------------------------------------------------------------------- // Pointer to the main application. -extern const QApplication* g_qMainApp; +extern const QApplication* g_app; // ----------------------------------------------------------------------------- // Identity matrix -extern const matrix g_mIdentity; +extern const matrix g_identity; #endif // COMMON_H \ No newline at end of file
--- a/file.cpp Sat May 04 13:52:47 2013 +0300 +++ b/file.cpp Sat May 04 18:31:03 2013 +0300 @@ -32,18 +32,18 @@ // ============================================================================= OpenFile::OpenFile () { - implicit = true; + m_implicit = true; savePos = -1; } // ============================================================================= OpenFile::~OpenFile () { // Clear everything from the model - for (LDObject* obj : objects) + for (LDObject* obj : m_objs) delete obj; // Clear the cache as well - for (LDObject* obj : objCache) + for (LDObject* obj : m_objCache) delete obj; } @@ -51,8 +51,8 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= OpenFile* findLoadedFile (str zName) { - for (OpenFile* file : g_LoadedFiles) - if (file->zFileName == zName) + for (OpenFile* file : g_loadedFiles) + if (file->m_filename == zName) return file; return null; @@ -166,15 +166,15 @@ } OpenFile* load = new OpenFile; - load->zFileName = path; + load->m_filename = path; ulong numWarnings; std::vector<LDObject*> objs = loadFileContents (fp, &numWarnings); for (LDObject* obj : objs) - load->objects.push_back (obj); + load->m_objs.push_back (obj); fclose (fp); - g_LoadedFiles.push_back (load); + g_loadedFiles.push_back (load); logf (LOG_Success, "File %s parsed successfully (%lu warning%s).\n", path.chars(), numWarnings, PLURAL (numWarnings)); @@ -189,17 +189,17 @@ setlocale (LC_ALL, "C"); // If we have unsaved changes, warn and give the option of saving. - if (!implicit && History::pos () != savePos) { - switch (QMessageBox::question (g_ForgeWindow, "Unsaved Changes", - format ("There are unsaved changes to %s. Should it be saved?", zFileName.chars ()), + if (!m_implicit && History::pos () != savePos) { + switch (QMessageBox::question (g_win, "Unsaved Changes", + format ("There are unsaved changes to %s. Should it be saved?", m_filename.chars ()), (QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel), QMessageBox::Cancel)) { case QMessageBox::Yes: if (!save ()) { str errormsg = format ("Failed to save %s: %s\nDo you still want to close?", - zFileName.chars (), strerror (lastError)); + m_filename.chars (), strerror (lastError)); - if (QMessageBox::critical (g_ForgeWindow, "Save Failure", errormsg, + if (QMessageBox::critical (g_win, "Save Failure", errormsg, (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) == QMessageBox::No) { return false; @@ -223,18 +223,18 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void closeAll () { - if (!g_LoadedFiles.size()) + if (!g_loadedFiles.size()) return; // Remove all loaded files and the objects they contain - for (OpenFile* file : g_LoadedFiles) + for (OpenFile* file : g_loadedFiles) delete file; // Clear the array - g_LoadedFiles.clear(); - g_CurrentFile = NULL; + g_loadedFiles.clear(); + g_curfile = NULL; - g_ForgeWindow->refresh (); + g_win->refresh (); } // ============================================================================= @@ -245,12 +245,12 @@ closeAll (); OpenFile* f = new OpenFile; - f->zFileName = ""; - g_LoadedFiles.push_back (f); - g_CurrentFile = f; + f->m_filename = ""; + g_loadedFiles.push_back (f); + g_curfile = f; g_BBox.calculate(); - g_ForgeWindow->refresh (); + g_win->refresh (); } // ============================================================================= @@ -281,7 +281,7 @@ io_recentfiles += zPath; config::save (); - g_ForgeWindow->updateRecentFilesMenu (); + g_win->updateRecentFilesMenu (); } // ============================================================================= @@ -295,22 +295,22 @@ if (!pFile) { // Tell the user loading failed. setlocale (LC_ALL, "C"); - QMessageBox::critical (g_ForgeWindow, "Load Failure", + QMessageBox::critical (g_win, "Load Failure", format ("Failed to open %s\nReason: %s", zPath.chars(), strerror (errno)), (QMessageBox::Close), QMessageBox::Close); return; } - pFile->implicit = false; - g_CurrentFile = pFile; + pFile->m_implicit = false; + g_curfile = pFile; // Recalculate the bounding box g_BBox.calculate(); // Rebuild the object tree view now. - g_ForgeWindow->refresh (); - g_ForgeWindow->setTitle (); + g_win->refresh (); + g_win->setTitle (); // Add it to the recent files list. addRecentFile (zPath); @@ -321,7 +321,7 @@ // ============================================================================= bool OpenFile::save (str path) { if (!~path) - path = zFileName; + path = m_filename; FILE* fp = fopen (path, "w"); @@ -331,7 +331,7 @@ } // Write all entries now - for (LDObject* obj : objects) { + for (LDObject* obj : m_objs) { // LDraw requires lines to have DOS line endings str zLine = format ("%s\r\n", obj->getContents ().chars ()); @@ -343,7 +343,7 @@ // We have successfully saved, update the save position now. savePos = History::pos (); - g_ForgeWindow->setTitle (); + g_win->setTitle (); return true; } @@ -573,19 +573,19 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void reloadAllSubfiles () { - if (!g_CurrentFile) + if (!g_curfile) return; // First, close all but the current open file. - for (OpenFile* file : g_LoadedFiles) - if (file != g_CurrentFile) + for (OpenFile* file : g_loadedFiles) + if (file != g_curfile) delete file; - g_LoadedFiles.clear (); - g_LoadedFiles.push_back (g_CurrentFile); + g_loadedFiles.clear (); + g_loadedFiles.push_back (g_curfile); // Go through all objects in the current file and reload the subfiles - for (LDObject* obj : g_CurrentFile->objects) { + for (LDObject* obj : g_curfile->m_objs) { if (obj->getType() == OBJ_Subfile) { // Note: ref->pFile is invalid right now since all subfiles were closed. LDSubfile* ref = static_cast<LDSubfile*> (obj); @@ -610,21 +610,21 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= ulong OpenFile::addObject (LDObject* obj) { - objects.push_back (obj); + m_objs.push_back (obj); - if (this == g_CurrentFile) + if (this == g_curfile) g_BBox.calcObject (obj); - return objects.size() - 1; + return m_objs.size() - 1; } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void OpenFile::insertObj (const ulong pos, LDObject* obj) { - objects.insert (objects.begin () + pos, obj); + m_objs.insert (m_objs.begin () + pos, obj); - if (this == g_CurrentFile) + if (this == g_curfile) g_BBox.calcObject (obj); } @@ -634,18 +634,18 @@ void OpenFile::forgetObject (LDObject* obj) { // Find the index for the given object ulong ulIndex; - for (ulIndex = 0; ulIndex < (ulong)objects.size(); ++ulIndex) - if (objects[ulIndex] == obj) + for (ulIndex = 0; ulIndex < (ulong)m_objs.size(); ++ulIndex) + if (m_objs[ulIndex] == obj) break; // found it - if (ulIndex >= objects.size ()) + if (ulIndex >= m_objs.size ()) return; // was not found // Erase it from memory - objects.erase (objects.begin() + ulIndex); + m_objs.erase (m_objs.begin() + ulIndex); // Update the bounding box - if (this == g_CurrentFile) + if (this == g_curfile) g_BBox.calculate (); }
--- a/file.h Sat May 04 13:52:47 2013 +0300 +++ b/file.h Sat May 04 18:31:03 2013 +0300 @@ -31,15 +31,15 @@ // ============================================================================= class OpenFile { public: - str zFileName, zTitle; - vector<LDObject*> objects; - vector<LDObject*> objCache; // Cache of this file's contents, if desired + str m_filename, m_title; + vector<LDObject*> m_objs; + vector<LDObject*> m_objCache; // Cache of this file's contents, if desired int lastError; // Is this file implicit? Implicit files are opened automatically for // caching purposes and are hidden from the user. - bool implicit; + bool m_implicit; OpenFile (); ~OpenFile (); @@ -60,7 +60,7 @@ long savePos; LDObject* object (ulong pos) const { - return objects[pos]; + return m_objs[pos]; } void insertObj (const ulong pos, LDObject* obj); @@ -103,7 +103,7 @@ std::vector< LDObject* > loadFileContents (FILE* fp, ulong* numWarnings); -extern vector<OpenFile*> g_LoadedFiles; +extern vector<OpenFile*> g_loadedFiles; extern vector<partListEntry> g_PartList; #endif // FILE_H \ No newline at end of file
--- a/gldraw.cpp Sat May 04 13:52:47 2013 +0300 +++ b/gldraw.cpp Sat May 04 18:31:03 2013 +0300 @@ -84,20 +84,20 @@ // ============================================================================= GLRenderer::GLRenderer (QWidget* parent) : QGLWidget (parent) { resetAngles (); - picking = rangepick = false; + m_picking = m_rangepick = false; m_camera = (GLRenderer::Camera) gl_camera.value; - drawToolTip = false; + m_drawToolTip = false; - pulseTimer = new QTimer (this); - connect (pulseTimer, SIGNAL (timeout ()), this, SLOT (slot_timerUpdate ())); + m_pulseTimer = new QTimer (this); + connect (m_pulseTimer, SIGNAL (timeout ()), this, SLOT (slot_timerUpdate ())); - toolTipTimer = new QTimer (this); - toolTipTimer->setSingleShot (true); - connect (toolTipTimer, SIGNAL (timeout ()), this, SLOT (slot_toolTipTimer ())); + m_toolTipTimer = new QTimer (this); + m_toolTipTimer->setSingleShot (true); + connect (m_toolTipTimer, SIGNAL (timeout ()), this, SLOT (slot_toolTipTimer ())); - thickBorderPen = QPen (QColor (0, 0, 0, 208), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); - thinBorderPen = thickBorderPen; - thinBorderPen.setWidth (1); + m_thickBorderPen = QPen (QColor (0, 0, 0, 208), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + m_thinBorderPen = m_thickBorderPen; + m_thinBorderPen.setWidth (1); // Init camera icons for (const GLRenderer::Camera cam : g_Cameras) { @@ -125,7 +125,7 @@ ushort i = 0; for (CameraIcon& info : g_CameraIcons) { - const long x1 = (width - (info.cam != Free ? 48 : 16)) + ((i % 3) * 16) - 1, + const long x1 = (m_width - (info.cam != Free ? 48 : 16)) + ((i % 3) * 16) - 1, y1 = ((i / 3) * 16) + 1; info.srcRect = QRect (0, 0, 16, 16); @@ -138,10 +138,10 @@ // ============================================================================= void GLRenderer::resetAngles () { - rotX = 30.0f; - rotY = 325.f; - panX = panY = rotZ = 0.0f; - zoom = 5.0f; + m_rotX = 30.0f; + m_rotY = 325.f; + m_panX = m_panY = m_rotZ = 0.0f; + m_zoom = 5.0f; } // ============================================================================= @@ -191,7 +191,7 @@ if (!col.isValid ()) return; - darkbg = luma (col) < 80; + m_darkbg = luma (col) < 80; col.setAlpha (255); qglClearColor (col); @@ -204,17 +204,17 @@ void GLRenderer::setObjectColor (LDObject* obj) { QColor qCol; - if (picking) { + if (m_picking) { // Make the color by the object's index color if we're picking, so we can // make the index from the color we get from the picking results. - long i = obj->getIndex (g_CurrentFile); + long i = obj->getIndex (g_curfile); // If we couldn't find the index, this object must not be from this file, // therefore it must be an object inlined from a subfile reference or // decomposed from a radial. Find the top level parent object and use // its index. if (i == -1) - i = obj->topLevelParent ()->getIndex (g_CurrentFile); + i = obj->topLevelParent ()->getIndex (g_curfile); // We should have the index now. assert (i != -1); @@ -283,7 +283,7 @@ a = qCol.alpha (); // If it's selected, brighten it up, also pulse flash it if desired. - if (g_ForgeWindow->isSelected (obj)) { + if (g_win->isSelected (obj)) { short tick, numTicks; if (gl_selflash) { @@ -329,8 +329,8 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void GLRenderer::resizeGL (int w, int h) { - width = w; - height = h; + m_width = w; + m_height = h; calcCameraIconRects (); @@ -350,8 +350,8 @@ { QColor (0, 160, 192), vertex (0, 0, 10000) }, }; -void GLRenderer::drawGLScene () { - if (g_CurrentFile == null) +void GLRenderer::drawGLScene () const { + if (g_curfile == null) return; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -362,8 +362,8 @@ glPushMatrix (); glLoadIdentity (); - glOrtho (-vw, vw, -vh, vh, -100.0f, 100.0f); - glTranslatef (panX, panY, 0.0f); + glOrtho (-m_virtWidth, m_virtWidth, -m_virtHeight, m_virtHeight, -100.0f, 100.0f); + glTranslatef (m_panX, m_panY, 0.0f); glRotatef (90.0f, g_staticCameras[m_camera].glrotate[0], g_staticCameras[m_camera].glrotate[1], g_staticCameras[m_camera].glrotate[2]); @@ -379,17 +379,17 @@ glLoadIdentity (); glTranslatef (0.0f, 0.0f, -2.0f); - glTranslatef (panX, panY, -zoom); - glRotatef (rotX, 1.0f, 0.0f, 0.0f); - glRotatef (rotY, 0.0f, 1.0f, 0.0f); - glRotatef (rotZ, 0.0f, 0.0f, 1.0f); + glTranslatef (m_panX, m_panY, -m_zoom); + glRotatef (m_rotX, 1.0f, 0.0f, 0.0f); + glRotatef (m_rotY, 0.0f, 1.0f, 0.0f); + glRotatef (m_rotZ, 0.0f, 0.0f, 1.0f); } - for (LDObject* obj : g_CurrentFile->objects) - glCallList (picking == false ? obj->uGLList : obj->uGLPickList); + for (LDObject* obj : g_curfile->m_objs) + glCallList (m_picking == false ? obj->uGLList : obj->uGLPickList); - if (gl_axes && !picking) - glCallList (axeslist); + if (gl_axes && !m_picking) + glCallList (m_axeslist); glPopMatrix (); glMatrixMode (GL_MODELVIEW); @@ -400,15 +400,15 @@ // ============================================================================= void GLRenderer::paintEvent (QPaintEvent* ev) { Q_UNUSED (ev) - vw = zoom; - vh = (height * vw) / width; + m_virtWidth = m_zoom; + m_virtHeight = (m_height * m_virtWidth) / m_width; drawGLScene (); QPainter paint (this); QFontMetrics metrics = QFontMetrics (QFont ()); paint.setRenderHint (QPainter::Antialiasing); - m_hoverpos = g_Origin; + m_hoverpos = g_origin; if (m_camera != Free) { const staticCameraMeta* cam = &g_staticCameras[m_camera]; @@ -418,9 +418,9 @@ negYFac = cam->negY ? -1 : 1; // Calculate cx and cy - these are the LDraw unit coords the cursor is at. - double cx = Grid::snap ((-vw + ((2 * mouseX * vw) / width) - panX) * g_storedBBoxSize - + double cx = Grid::snap ((-m_virtWidth + ((2 * m_pos.x () * m_virtWidth) / m_width) - m_panX) * g_storedBBoxSize - (negXFac * g_objOffset[axisX]), (Grid::Config) axisX); - double cy = Grid::snap ((vh - ((2 * mouseY * vh) / height) - panY) * g_storedBBoxSize - + double cy = Grid::snap ((m_virtHeight - ((2 * m_pos.y () * m_virtHeight) / m_height) - m_panY) * g_storedBBoxSize - (negYFac * g_objOffset[axisY]), (Grid::Config) axisY); cx *= negXFac; cy *= negYFac; @@ -435,16 +435,16 @@ ftoa (m_hoverpos[Y]).chars (), ftoa (m_hoverpos[Z]).chars ()); QFontMetrics metrics = QFontMetrics (font ()); - QRect textSize = metrics.boundingRect (0, 0, width, height, Qt::AlignCenter, text); + QRect textSize = metrics.boundingRect (0, 0, m_width, m_height, Qt::AlignCenter, text); - paint.drawText (width - textSize.width (), height - 16, textSize.width (), + paint.drawText (m_width - textSize.width (), m_height - 16, textSize.width (), textSize.height (), Qt::AlignCenter, text); } // Camera icons - if (!picking) { + if (!m_picking) { // Draw a background for the selected camera - paint.setPen (thinBorderPen); + paint.setPen (m_thinBorderPen); paint.setBrush (QBrush (QColor (0, 128, 160, 128))); paint.drawRect (g_CameraIcons[camera ()].selRect); @@ -463,31 +463,31 @@ } // Tool tips - if (drawToolTip) { - if (g_CameraIcons[toolTipCamera].destRect.contains (QPoint (mouseX, mouseY)) == false) - drawToolTip = false; + if (m_drawToolTip) { + if (g_CameraIcons[m_toolTipCamera].destRect.contains (m_pos) == false) + m_drawToolTip = false; else { - QPen bord = thinBorderPen; + QPen bord = m_thinBorderPen; bord.setBrush (Qt::black); const ushort margin = 2; - ushort x0 = mouseX, - y0 = mouseY; + ushort x0 = m_pos.x (), + y0 = m_pos.y (); str label; - label.format ("%s Camera", g_CameraNames[toolTipCamera]); + label.format ("%s Camera", g_CameraNames[m_toolTipCamera]); const ushort textWidth = metrics.width (label), textHeight = metrics.height (), fullWidth = textWidth + (2 * margin), fullHeight = textHeight + (2 * margin); - QRect area (mouseX, mouseY, fullWidth, fullHeight); + QRect area (m_pos.x (), m_pos.y (), fullWidth, fullHeight); - if (x0 + fullWidth > width) + if (x0 + fullWidth > m_width) x0 -= fullWidth; - if (y0 + fullHeight > height) + if (y0 + fullHeight > m_height) y0 -= fullHeight; paint.setBrush (QColor (0, 128, 255, 208)); @@ -501,17 +501,17 @@ } // If we're range-picking, draw a rectangle encompassing the selection area. - if (rangepick && !picking) { - const short x0 = rangeStart.x (), - y0 = rangeStart.y (), - x1 = pos.x (), - y1 = pos.y (); + if (m_rangepick && !m_picking) { + const short x0 = m_rangeStart.x (), + y0 = m_rangeStart.y (), + x1 = m_pos.x (), + y1 = m_pos.y (); QRect rect (x0, y0, x1 - x0, y1 - y0); - QColor fillColor = (addpick ? "#80FF00" : "#00CCFF"); + QColor fillColor = (m_addpick ? "#80FF00" : "#00CCFF"); fillColor.setAlphaF (0.2f); - paint.setPen (thickBorderPen); + paint.setPen (m_thickBorderPen); paint.setBrush (QBrush (fillColor)); paint.drawRect (rect); } @@ -521,19 +521,17 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void GLRenderer::compileObjects () { - objLists.clear (); - g_objOffset[0] = -(g_BBox.v0[X] + g_BBox.v1[X]) / 2; g_objOffset[1] = -(g_BBox.v0[Y] + g_BBox.v1[Y]) / 2; g_objOffset[2] = -(g_BBox.v0[Z] + g_BBox.v1[Z]) / 2; g_storedBBoxSize = g_BBox.size (); - if (!g_CurrentFile) { + if (!g_curfile) { printf ("renderer: no files loaded, cannot compile anything\n"); return; } - for (LDObject* obj : g_CurrentFile->objects) { + for (LDObject* obj : g_curfile->m_objs) { GLuint* upaLists[2] = { &obj->uGLList, &obj->uGLPickList @@ -543,20 +541,18 @@ GLuint uList = glGenLists (1); glNewList (uList, GL_COMPILE); - picking = (upMemberList == &obj->uGLPickList); + m_picking = (upMemberList == &obj->uGLPickList); compileOneObject (obj); - picking = false; + m_picking = false; glEndList (); *upMemberList = uList; } - - objLists.push_back (obj->uGLList); } // Compile axes - axeslist = glGenLists (1); - glNewList (axeslist, GL_COMPILE); + m_axeslist = glGenLists (1); + glNewList (m_axeslist, GL_COMPILE); glBegin (GL_LINES); for (const GLAxis& ax : g_GLAxes) { qglColor (ax.col); @@ -570,14 +566,13 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -template<class T> void GLRenderer::compileSubObject (LDObject* obj, - const GLenum eGLType, const short dVerts) -{ - T* newobj = static_cast<T*> (obj); - glBegin (eGLType); +void GLRenderer::compileSubObject (LDObject* obj, const GLenum gltype) { + glBegin (gltype); - for (short i = 0; i < dVerts; ++i) - compileVertex (newobj->vaCoords[i]); + const short numverts = (obj->getType () != OBJ_CondLine) ? obj->vertices () : 2; + + for (short i = 0; i < numverts; ++i) + compileVertex (obj->vaCoords[i]); glEnd (); } @@ -590,24 +585,24 @@ switch (obj->getType ()) { case OBJ_Line: - compileSubObject<LDLine> (obj, GL_LINES, 2); + compileSubObject (obj, GL_LINES); break; case OBJ_CondLine: glLineStipple (1, 0x6666); glEnable (GL_LINE_STIPPLE); - compileSubObject<LDCondLine> (obj, GL_LINES, 2); + compileSubObject (obj, GL_LINES); glDisable (GL_LINE_STIPPLE); break; case OBJ_Triangle: - compileSubObject<LDTriangle> (obj, GL_TRIANGLES, 3); + compileSubObject (obj, GL_TRIANGLES); break; case OBJ_Quad: - compileSubObject<LDQuad> (obj, GL_QUADS, 4); + compileSubObject (obj, GL_QUADS); break; case OBJ_Subfile: @@ -697,15 +692,15 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void GLRenderer::mouseReleaseEvent (QMouseEvent* ev) { - if ((lastButtons & Qt::LeftButton) && !(ev->buttons() & Qt::LeftButton)) { - if (!rangepick) - addpick = (keymods & Qt::ControlModifier); + if ((m_lastButtons & Qt::LeftButton) && !(ev->buttons() & Qt::LeftButton)) { + if (!m_rangepick) + m_addpick = (m_keymods & Qt::ControlModifier); - if (totalmove < 10 || rangepick) + if (m_totalmove < 10 || m_rangepick) pick (ev->x (), ev->y ()); - rangepick = false; - totalmove = 0; + m_rangepick = false; + m_totalmove = 0; } } @@ -714,48 +709,45 @@ // ============================================================================= void GLRenderer::mousePressEvent (QMouseEvent* ev) { if (ev->buttons () & Qt::LeftButton) - totalmove = 0; + m_totalmove = 0; if (ev->modifiers () & Qt::ShiftModifier) { - rangepick = true; - rangeStart.setX (ev->x ()); - rangeStart.setY (ev->y ()); + m_rangepick = true; + m_rangeStart.setX (ev->x ()); + m_rangeStart.setY (ev->y ()); - addpick = (keymods & Qt::ControlModifier); + m_addpick = (m_keymods & Qt::ControlModifier); } - lastButtons = ev->buttons (); + m_lastButtons = ev->buttons (); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void GLRenderer::mouseMoveEvent (QMouseEvent* ev) { - mouseX = pos.x (); - mouseY = pos.y (); - - int dx = ev->x () - pos.x (); - int dy = ev->y () - pos.y (); - totalmove += abs (dx) + abs (dy); + int dx = ev->x () - m_pos.x (); + int dy = ev->y () - m_pos.y (); + m_totalmove += abs (dx) + abs (dy); - if (ev->buttons () & Qt::LeftButton && !rangepick) { - rotX = rotX + (dy); - rotY = rotY + (dx); + if (ev->buttons () & Qt::LeftButton && !m_rangepick) { + m_rotX = m_rotX + (dy); + m_rotY = m_rotY + (dx); - clampAngle (rotX); - clampAngle (rotY); + clampAngle (m_rotX); + clampAngle (m_rotY); } if (ev->buttons () & Qt::MidButton) { - panX += 0.03f * dx * (zoom / 7.5f); - panY -= 0.03f * dy * (zoom / 7.5f); + m_panX += 0.03f * dx * (m_zoom / 7.5f); + m_panY -= 0.03f * dy * (m_zoom / 7.5f); } // Start the tool tip timer - if (!drawToolTip) - toolTipTimer->start (1000); + if (!m_drawToolTip) + m_toolTipTimer->start (1000); - pos = ev->pos (); + m_pos = ev->pos (); update (); } @@ -763,17 +755,17 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void GLRenderer::keyPressEvent (QKeyEvent* ev) { - keymods = ev->modifiers (); + m_keymods = ev->modifiers (); } void GLRenderer::keyReleaseEvent (QKeyEvent* ev) { - keymods = ev->modifiers (); + m_keymods = ev->modifiers (); } // ============================================================================= void GLRenderer::wheelEvent (QWheelEvent* ev) { - zoom *= (ev->delta () < 0) ? 1.2f : (1.0f / 1.2f); - zoom = clamp (zoom, 0.01, 100.0); + m_zoom *= (ev->delta () < 0) ? 1.2f : (1.0f / 1.2f); + m_zoom = clamp (m_zoom, 0.01, 100.0); update (); ev->accept (); @@ -782,14 +774,14 @@ // ============================================================================= void GLRenderer::leaveEvent (QEvent* ev) { Q_UNUSED (ev); - drawToolTip = false; - toolTipTimer->stop (); + m_drawToolTip = false; + m_toolTipTimer->stop (); update (); } // ============================================================================= void GLRenderer::contextMenuEvent (QContextMenuEvent* ev) { - g_ForgeWindow->spawnContextMenu (ev->globalPos ()); + g_win->spawnContextMenu (ev->globalPos ()); } // ============================================================================= @@ -802,11 +794,11 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void GLRenderer::updateSelFlash () { - if (gl_selflash && g_ForgeWindow->sel.size() > 0) { - pulseTimer->start (g_pulseInterval); + if (gl_selflash && g_win->sel ().size() > 0) { + m_pulseTimer->start (g_pulseInterval); g_pulseTick = 0; } else - pulseTimer->stop (); + m_pulseTimer->stop (); } // ============================================================================= @@ -814,7 +806,7 @@ // ============================================================================= void GLRenderer::pick (uint mouseX, uint mouseY) { // Check if we selected a camera icon - if (!rangepick) { + if (!m_rangepick) { QPoint pos (mouseX, mouseY); for (CameraIcon& info : g_CameraIcons) { @@ -830,16 +822,16 @@ LDObject* removedObject = null; // Clear the selection if we do not wish to add to it. - if (!addpick) { - std::vector<LDObject*> paOldSelection = g_ForgeWindow->sel; - g_ForgeWindow->sel.clear (); + if (!m_addpick) { + std::vector<LDObject*> paOldSelection = g_win->sel (); + g_win->sel ().clear (); // Recompile the prior selection to remove the highlight color for (LDObject* obj : paOldSelection) recompileObject (obj); } - picking = true; + m_picking = true; // Paint the picking scene glDisable (GL_DITHER); @@ -854,9 +846,9 @@ // 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 (); + if (m_rangepick) { + x1 = m_rangeStart.x (); + y1 = m_rangeStart.y (); } else { x1 = x0 + 1; y1 = y0 + 1; @@ -872,8 +864,8 @@ // Clamp the values to ensure they're within bounds x0 = max<short> (0, x0); y0 = max<short> (0, y0); - x1 = min<short> (x1, width); - y1 = min<short> (y1, height); + x1 = min<short> (x1, m_width); + y1 = min<short> (y1, m_height); const short areawidth = (x1 - x0); const short areaheight = (y1 - y0); @@ -883,7 +875,7 @@ uchar* const pixeldata = new uchar[4 * numpixels]; uchar* pixelptr = &pixeldata[0]; - assert (viewport[3] == height); + assert (viewport[3] == m_height); // Read pixels from the color buffer. glReadPixels (x0, viewport[3] - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixeldata); @@ -899,16 +891,16 @@ if (idx == 0xFFFFFF) continue; // White is background; skip - LDObject* obj = g_CurrentFile->object (idx); + LDObject* obj = g_curfile->object (idx); // If this is an additive single pick and the object is currently selected, // we remove it from selection instead. - if (!rangepick && addpick) { + if (!m_rangepick && m_addpick) { bool removed = false; - for (ulong i = 0; i < g_ForgeWindow->sel.size(); ++i) { - if (g_ForgeWindow->sel[i] == obj) { - g_ForgeWindow->sel.erase (g_ForgeWindow->sel.begin () + i); + for (ulong i = 0; i < g_win->sel ().size(); ++i) { + if (g_win->sel ()[i] == obj) { + g_win->sel ().erase (g_win->sel ().begin () + i); removedObject = obj; removed = true; } @@ -918,29 +910,29 @@ break; } - g_ForgeWindow->sel.push_back (obj); + g_win->sel ().push_back (obj); } delete[] pixeldata; // Remove duplicate entries. For this to be effective, the vector must be // sorted first. - std::vector<LDObject*>& sel = g_ForgeWindow->sel; + std::vector<LDObject*>& sel = g_win->sel (); 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 (); + g_win->buildObjList (); - picking = false; - rangepick = false; + m_picking = false; + m_rangepick = false; glEnable (GL_DITHER); setBackground (); updateSelFlash (); - for (LDObject* obj : g_ForgeWindow->sel) + for (LDObject* obj : g_win->sel ()) recompileObject (obj); if (removedObject != null) @@ -956,29 +948,24 @@ // ========================================================================= // void GLRenderer::recompileObject (LDObject* obj) { // Replace the old list with the new one. - for (ulong i = 0; i < objLists.size(); ++i) - if (objLists[i] == obj->uGLList) - objLists.erase (objLists.begin() + i); - GLuint uList = glGenLists (1); glNewList (uList, GL_COMPILE); compileOneObject (obj); glEndList (); - objLists.push_back (uList); obj->uGLList = uList; } // ============================================================================= uchar* GLRenderer::screencap (ushort& w, ushort& h) { - w = width; - h = height; + w = m_width; + h = m_height; uchar* cap = new uchar[4 * w * h]; - screencapping = true; + m_screencap = true; update (); - screencapping = false; + m_screencap = false; // Capture the pixels glReadPixels (0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, cap); @@ -993,7 +980,7 @@ void GLRenderer::slot_timerUpdate () { ++g_pulseTick %= g_numPulseTicks; - for (LDObject* obj : g_ForgeWindow->sel) + for (LDObject* obj : g_win->sel ()) recompileObject (obj); update (); @@ -1005,9 +992,9 @@ // a second. Check if we're holding it over a camera icon - if so, draw // a tooltip. for (CameraIcon& icon : g_CameraIcons) { - if (icon.destRect.contains (QPoint (mouseX, mouseY))) { - toolTipCamera = icon.cam; - drawToolTip = true; + if (icon.destRect.contains (m_pos)) { + m_toolTipCamera = icon.cam; + m_drawToolTip = true; update (); break; }
--- a/gldraw.h Sat May 04 13:52:47 2013 +0300 +++ b/gldraw.h Sat May 04 18:31:03 2013 +0300 @@ -29,7 +29,7 @@ // // The main renderer object, draws the brick on the screen, manages the camera // and selection picking. The instance of GLRenderer is accessible as -// g_ForgeWindow->R +// g_win->R () // ============================================================================= class GLRenderer : public QGLWidget { Q_OBJECT @@ -58,13 +58,10 @@ void updateSelFlash (); void resetAngles (); uchar* screencap (ushort& w, ushort& h); - + void beginPlaneDraw (); GLRenderer::Camera camera () { return m_camera; } void setCamera (const GLRenderer::Camera cam); - - bool picking; - short width, height; - ushort mouseX, mouseY; + bool picking () { return m_picking; } protected: void initializeGL (); @@ -81,29 +78,28 @@ void contextMenuEvent (QContextMenuEvent* ev); private: - std::vector<GLuint> objLists; - QTimer* pulseTimer, *toolTipTimer; - Qt::MouseButtons lastButtons; - Qt::KeyboardModifiers keymods; - ulong totalmove; - bool darkbg; - double vw, vh; + QTimer* m_pulseTimer, *m_toolTipTimer; + Qt::MouseButtons m_lastButtons; + Qt::KeyboardModifiers m_keymods; + ulong m_totalmove; + bool m_darkbg; + double m_virtWidth, m_virtHeight; Camera m_camera; vertex m_hoverpos; - double rotX, rotY, rotZ, panX, panY, zoom; - bool rangepick, addpick, drawToolTip, screencapping; - QPoint pos, rangeStart; - QPen thinBorderPen, thickBorderPen; - Camera toolTipCamera; - uint axeslist; + double m_rotX, m_rotY, m_rotZ, m_panX, m_panY, m_zoom; + bool m_picking, m_rangepick, m_addpick, m_drawToolTip, m_screencap; + QPoint m_pos, m_rangeStart; + QPen m_thinBorderPen, m_thickBorderPen; + Camera m_toolTipCamera; + uint m_axeslist; + short m_width, m_height; void compileOneObject (LDObject* obj); - template<class T> void compileSubObject (LDObject* obj, const GLenum eGLType, - const short dVerts); + void compileSubObject (LDObject* obj, const GLenum gltype); void compileVertex (const vertex& vrt); - void clampAngle (double& fAngle); + void clampAngle (double& angle); void setObjectColor (LDObject* obj); - void drawGLScene (); + void drawGLScene () const; void calcCameraIconRects (); private slots:
--- a/gui.cpp Sat May 04 13:52:47 2013 +0300 +++ b/gui.cpp Sat May 04 18:31:03 2013 +0300 @@ -115,29 +115,29 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= ForgeWindow::ForgeWindow () { - g_ForgeWindow = this; - R = new GLRenderer; + g_win = this; + m_renderer = new GLRenderer; - objList = new ObjectList; - objList->setSelectionMode (QListWidget::ExtendedSelection); - objList->setAlternatingRowColors (true); - connect (objList, SIGNAL (itemSelectionChanged ()), this, SLOT (slot_selectionChanged ())); + m_objList = new ObjectList; + m_objList->setSelectionMode (QListWidget::ExtendedSelection); + m_objList->setAlternatingRowColors (true); + connect (m_objList, SIGNAL (itemSelectionChanged ()), this, SLOT (slot_selectionChanged ())); - qMessageLog = new QTextEdit; - qMessageLog->setReadOnly (true); - qMessageLog->setMaximumHeight (96); + m_msglog = new QTextEdit; + m_msglog->setReadOnly (true); + m_msglog->setMaximumHeight (96); - hsplit = new QSplitter; - hsplit->addWidget (R); - hsplit->addWidget (objList); + m_hsplit = new QSplitter; + m_hsplit->addWidget (m_renderer); + m_hsplit->addWidget (m_objList); - vsplit = new QSplitter (Qt::Vertical); - vsplit->addWidget (hsplit); - vsplit->addWidget (qMessageLog); + m_vsplit = new QSplitter (Qt::Vertical); + m_vsplit->addWidget (m_hsplit); + m_vsplit->addWidget (m_msglog); - setCentralWidget (vsplit); + setCentralWidget (m_vsplit); - quickColorMeta = parseQuickColorMeta (); + m_colorMeta = parseQuickColorMeta (); createMenuActions (); createMenus (); @@ -156,8 +156,8 @@ // ============================================================================= void ForgeWindow::slot_lastSecondCleanup () { - R->setParent (null); - delete R; + m_renderer->setParent (null); + delete m_renderer; } // ============================================================================= @@ -197,15 +197,15 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ForgeWindow::createMenus () { - qRecentFilesMenu = new QMenu (tr ("Open &Recent")); - qRecentFilesMenu->setIcon (getIcon ("open-recent")); + m_recentFilesMenu = new QMenu (tr ("Open &Recent")); + m_recentFilesMenu->setIcon (getIcon ("open-recent")); updateRecentFilesMenu (); // File menu - qFileMenu = menuBar ()->addMenu (tr ("&File")); + QMenu* qFileMenu = menuBar ()->addMenu (tr ("&File")); qFileMenu->addAction (ACTION (newFile)); // New qFileMenu->addAction (ACTION (open)); // Open - qFileMenu->addMenu (qRecentFilesMenu); // Open Recent + qFileMenu->addMenu (m_recentFilesMenu); // Open Recent qFileMenu->addAction (ACTION (save)); // Save qFileMenu->addAction (ACTION (saveAs)); // Save As qFileMenu->addSeparator (); // ------- @@ -214,7 +214,7 @@ qFileMenu->addAction (ACTION (exit)); // Exit // View menu - qViewMenu = menuBar ()->addMenu (tr ("&View")); + QMenu* qViewMenu = menuBar ()->addMenu (tr ("&View")); qViewMenu->addAction (ACTION (resetView)); // Reset View qViewMenu->addAction (ACTION (axes)); // Draw Axes qViewMenu->addSeparator (); // ----- @@ -222,7 +222,7 @@ qViewMenu->addAction (ACTION (showHistory)); // Edit History // Insert menu - qInsertMenu = menuBar ()->addMenu (tr ("&Insert")); + QMenu* qInsertMenu = menuBar ()->addMenu (tr ("&Insert")); qInsertMenu->addAction (ACTION (insertFrom)); // Insert from File qInsertMenu->addAction (ACTION (insertRaw)); // Insert Raw qInsertMenu->addSeparator (); // ------- @@ -237,7 +237,7 @@ qInsertMenu->addAction (ACTION (newRadial)); // New Radial // Edit menu - qEditMenu = menuBar ()->addMenu (tr ("&Edit")); + QMenu* qEditMenu = menuBar ()->addMenu (tr ("&Edit")); qEditMenu->addAction (ACTION (undo)); // Undo qEditMenu->addAction (ACTION (redo)); // Redo qEditMenu->addSeparator (); // ----- @@ -264,7 +264,7 @@ toolsMenu->addAction (ACTION (uncolorize)); // Uncolorize // Move menu - qMoveMenu = menuBar ()->addMenu (tr ("&Move")); + QMenu* qMoveMenu = menuBar ()->addMenu (tr ("&Move")); qMoveMenu->addAction (ACTION (moveUp)); // Move Up qMoveMenu->addAction (ACTION (moveDown)); // Move Down qMoveMenu->addSeparator (); // ----- @@ -288,13 +288,13 @@ #ifndef RELEASE // Debug menu - qDebugMenu = menuBar ()->addMenu (tr ("&Debug")); + QMenu* qDebugMenu = menuBar ()->addMenu (tr ("&Debug")); qDebugMenu->addAction (ACTION (addTestQuad)); // Add Test Quad qDebugMenu->addAction (ACTION (addTestRadial)); // Add Test Radial #endif // RELEASE // Help menu - qHelpMenu = menuBar ()->addMenu (tr ("&Help")); + QMenu* qHelpMenu = menuBar ()->addMenu (tr ("&Help")); qHelpMenu->addAction (ACTION (help)); // Help qHelpMenu->addSeparator (); // ----- qHelpMenu->addAction (ACTION (about)); // About @@ -306,9 +306,9 @@ // ============================================================================= void ForgeWindow::updateRecentFilesMenu () { // First, clear any items in the recent files menu - for (QAction* qRecent : qaRecentFiles) + for (QAction* qRecent : m_recentFiles) delete qRecent; - qaRecentFiles.clear (); + m_recentFiles.clear (); std::vector<str> zaFiles = io_recentfiles.value / "@"; for (long i = zaFiles.size() - 1; i >= 0; --i) { @@ -317,8 +317,8 @@ QAction* qRecent = new QAction (getIcon ("open-recent"), zFile, this); connect (qRecent, SIGNAL (triggered ()), this, SLOT (slot_recentFile ())); - qRecentFilesMenu->addAction (qRecent); - qaRecentFiles.push_back (qRecent); + m_recentFilesMenu->addAction (qRecent); + m_recentFiles.push_back (qRecent); } } @@ -331,7 +331,7 @@ void ForgeWindow::initSingleToolBar (const char* sName) { QToolBar* toolbar = new QToolBar (sName); addToolBar (g_ToolBarArea, toolbar); - qaToolBars.push_back (toolbar); + m_toolBars.push_back (toolbar); g_CurrentToolBar = toolbar; } @@ -406,8 +406,8 @@ // ========================================== // Color toolbar - qColorToolBar = new QToolBar ("Quick Colors"); - addToolBar (Qt::RightToolBarArea, qColorToolBar); + m_colorToolBar = new QToolBar ("Quick Colors"); + addToolBar (Qt::RightToolBarArea, m_colorToolBar); // ========================================== // Left area toolbars @@ -451,21 +451,21 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ForgeWindow::updateToolBars () { - for (QToolBar* qBar : qaToolBars) + for (QToolBar* qBar : m_toolBars) qBar->setIconSize (QSize (gui_toolbar_iconsize, gui_toolbar_iconsize)); // Update the quick color toolbar. - for (QPushButton* qButton : qaColorButtons) + for (QPushButton* qButton : m_colorButtons) delete qButton; - qaColorButtons.clear (); + m_colorButtons.clear (); // Clear the toolbar to remove separators - qColorToolBar->clear (); + m_colorToolBar->clear (); - for (quickColorMetaEntry& entry : quickColorMeta) { + for (quickColorMetaEntry& entry : m_colorMeta) { if (entry.bSeparator) - qColorToolBar->addSeparator (); + m_colorToolBar->addSeparator (); else { QPushButton* qColorButton = new QPushButton; qColorButton->setAutoFillBackground (true); @@ -473,8 +473,8 @@ qColorButton->setToolTip (entry.col->zName); connect (qColorButton, SIGNAL (clicked ()), this, SLOT (slot_quickColor ())); - qColorToolBar->addWidget (qColorButton); - qaColorButtons.push_back (qColorButton); + m_colorToolBar->addWidget (qColorButton); + m_colorButtons.push_back (qColorButton); entry.btn = qColorButton; } @@ -501,18 +501,18 @@ title += versionString; // Append our current file if we have one - if (g_CurrentFile) { - title += format (": %s", basename (g_CurrentFile->zFileName.chars())); + if (g_curfile) { + title += format (": %s", basename (g_curfile->m_filename.chars())); - if (g_CurrentFile->objects.size() > 0 && - g_CurrentFile->objects[0]->getType() == OBJ_Comment) + if (g_curfile->m_objs.size() > 0 && + g_curfile->m_objs[0]->getType() == OBJ_Comment) { // Append title - LDComment* comm = static_cast<LDComment*> (g_CurrentFile->objects[0]); + LDComment* comm = static_cast<LDComment*> (g_curfile->m_objs[0]); title += format (": %s", comm->zText.chars()); } - if (History::pos () != g_CurrentFile->savePos) + if (History::pos () != g_curfile->savePos) title += '*'; } @@ -549,19 +549,19 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ForgeWindow::deleteSelection (vector<ulong>* ulapIndices, std::vector<LDObject*>* papObjects) { - if (sel.size () == 0) + if (m_sel.size () == 0) return; - std::vector<LDObject*> selCopy = sel; + std::vector<LDObject*> selCopy = m_sel; // Delete the objects that were being selected for (LDObject* obj : selCopy) { if (papObjects && ulapIndices) { papObjects->push_back (obj->clone ()); - ulapIndices->push_back (obj->getIndex (g_CurrentFile)); + ulapIndices->push_back (obj->getIndex (g_curfile)); } - g_CurrentFile->forgetObject (obj); + g_curfile->forgetObject (obj); delete obj; } @@ -572,7 +572,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ForgeWindow::buildObjList () { - if (!g_CurrentFile) + if (!g_curfile) return; // Lock the selection while we do this so that refreshing the object list @@ -580,9 +580,9 @@ // while this is done. g_bSelectionLocked = true; - objList->clear (); + m_objList->clear (); - for (LDObject* obj : g_CurrentFile->objects) { + for (LDObject* obj : g_curfile->m_objs) { str zText; switch (obj->getType ()) { case OBJ_Comment: @@ -704,7 +704,7 @@ } obj->qObjListEntry = item; - objList->insertItem (objList->count (), item); + m_objList->insertItem (m_objList->count (), item); } g_bSelectionLocked = false; @@ -715,18 +715,18 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ForgeWindow::scrollToSelection () { - if (sel.size() == 0) + if (m_sel.size() == 0) return; - LDObject* obj = sel[sel.size () - 1]; - objList->scrollToItem (obj->qObjListEntry); + LDObject* obj = m_sel[m_sel.size () - 1]; + m_objList->scrollToItem (obj->qObjListEntry); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ForgeWindow::slot_selectionChanged () { - if (g_bSelectionLocked == true) + if (g_bSelectionLocked == true || g_curfile == null) return; /* @@ -737,22 +737,35 @@ ACTION (splitQuads)->setEnabled (qObjList->selectedItems().size() > 0); */ - // Update the shared selection array, unless this was called during GL picking, - // in which case the GL renderer takes care of the selection. - if (R->picking == false) { - std::vector<LDObject*> paPriorSelection = sel; - sel = getSelectedObjects (); - - // Update the GL renderer - for (LDObject* obj : sel) - R->recompileObject (obj); - - for (LDObject* obj : paPriorSelection) - R->recompileObject (obj); - - R->updateSelFlash (); - R->refresh (); + // Update the shared selection array, though don't do this if this was + // called during GL picking, in which case the GL renderer takes care + // of the selection. + if (m_renderer->picking ()) + return; + + std::vector<LDObject*> priorSelection = m_sel; + + // Get the objects from the object list selection + m_sel.clear (); + const QList<QListWidgetItem*> items = m_objList->selectedItems (); + + for (LDObject* obj : g_curfile->m_objs) + for (QListWidgetItem* qItem : items) { + if (qItem == obj->qObjListEntry) { + m_sel.push_back (obj); + break; + } } + + // Update the GL renderer + for (LDObject* obj : m_sel) + m_renderer->recompileObject (obj); + + for (LDObject* obj : priorSelection) + m_renderer->recompileObject (obj); + + m_renderer->updateSelFlash (); + m_renderer->refresh (); } // ============================================================================= @@ -768,7 +781,7 @@ QPushButton* button = static_cast<QPushButton*> (sender ()); color* col = null; - for (quickColorMetaEntry entry : quickColorMeta) { + for (quickColorMetaEntry entry : m_colorMeta) { if (entry.btn == button) { col = entry.col; break; @@ -782,11 +795,11 @@ std::vector<short> colors; short newColor = col->index (); - for (LDObject* obj : sel) { + for (LDObject* obj : m_sel) { if (obj->dColor == -1) continue; // uncolored object - indices.push_back (obj->getIndex (g_CurrentFile)); + indices.push_back (obj->getIndex (g_curfile)); colors.push_back (obj->dColor); obj->dColor = newColor; @@ -800,13 +813,13 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= ulong ForgeWindow::getInsertionPoint () { - if (sel.size () > 0) { + if (m_sel.size () > 0) { // If we have a selection, put the item after it. - return (sel[sel.size() - 1]->getIndex (g_CurrentFile)) + 1; + return (m_sel[m_sel.size() - 1]->getIndex (g_curfile)) + 1; } // Otherwise place the object at the end. - return g_CurrentFile->objects.size(); + return g_curfile->m_objs.size(); } // ============================================================================= @@ -814,29 +827,7 @@ // ============================================================================= void ForgeWindow::refresh () { buildObjList (); - R->hardRefresh (); -} - -// ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= -std::vector<LDObject*> ForgeWindow::getSelectedObjects () { - std::vector<LDObject*> objs; - - if (g_CurrentFile == nullptr) - return objs; - - QList<QListWidgetItem*> const qaItems = objList->selectedItems (); - - for (LDObject* obj : g_CurrentFile->objects) - for (QListWidgetItem* qItem : qaItems) { - if (qItem == obj->qObjListEntry) { - objs.push_back (obj); - break; - } - } - - return objs; + m_renderer->hardRefresh (); } // ============================================================================= @@ -845,8 +836,8 @@ void ForgeWindow::updateSelection () { g_bSelectionLocked = true; - objList->clearSelection (); - for (LDObject* obj : sel) + m_objList->clearSelection (); + for (LDObject* obj : m_sel) obj->qObjListEntry->setSelected (true); g_bSelectionLocked = false; @@ -857,21 +848,22 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= bool ForgeWindow::isSelected (LDObject* obj) { - LDObject* pNeedle = obj->topLevelParent (); + LDObject* needle = obj->topLevelParent (); + + if (needle == null) + needle = obj; - if (pNeedle == null) - pNeedle = obj; + for (LDObject* hay : m_sel) + if (hay == needle) + return true; - for (LDObject* pHay : sel) - if (pHay == pNeedle) - return true; return false; } short ForgeWindow::getSelectedColor() { short result = -1; - for (LDObject* obj : sel) { + for (LDObject* obj : m_sel) { if (obj->dColor == -1) continue; // doesn't use color @@ -891,7 +883,7 @@ LDObjectType_e ForgeWindow::uniformSelectedType () { LDObjectType_e eResult = OBJ_Unidentified; - for (LDObject* obj : sel) { + for (LDObject* obj : m_sel) { if (eResult != OBJ_Unidentified && obj->dColor != eResult) return OBJ_Unidentified; @@ -907,7 +899,7 @@ // ============================================================================= void ForgeWindow::closeEvent (QCloseEvent* ev) { // Check whether it's safe to close all files. - for (OpenFile* f : g_LoadedFiles) { + for (OpenFile* f : g_loadedFiles) { if (!f->safeToClose ()) { ev->ignore (); return; @@ -925,7 +917,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ForgeWindow::spawnContextMenu (const QPoint pos) { - const bool single = (g_ForgeWindow->sel.size () == 1); + const bool single = (g_win->sel ().size () == 1); QMenu* contextMenu = new QMenu; @@ -949,7 +941,7 @@ // ============================================================================= void ObjectList::contextMenuEvent (QContextMenuEvent* ev) { - g_ForgeWindow->spawnContextMenu (ev->globalPos ()); + g_win->spawnContextMenu (ev->globalPos ()); } // ============================================================================= @@ -965,12 +957,69 @@ } bool confirm (str title, str msg) { - return QMessageBox::question (g_ForgeWindow, title, msg, + return QMessageBox::question (g_win, title, msg, (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) == QMessageBox::Yes; } // ============================================================================= void critical (str msg) { - QMessageBox::critical (g_ForgeWindow, APPNAME_DISPLAY ": Critical Error", msg, + QMessageBox::critical (g_win, APPNAME_DISPLAY ": Critical Error", msg, (QMessageBox::Close), QMessageBox::Close); +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +// Print to message log +void ForgeWindow::logVA (LogType type, const char* fmtstr, va_list va) { + return; // FIXME: crashes for some reason o_O + + char* buf = vdynformat (fmtstr, va, 128); + str zText (buf); + delete[] buf; + + // Log it to standard output + printf ("%s", zText.chars ()); + + // Replace some things out with HTML entities + zText.replace ("<", "<"); + zText.replace (">", ">"); + zText.replace ("\n", "<br />"); + + str& log = m_msglogHTML; + + switch (type) { + case LOG_Normal: + log.append (zText); + break; + + case LOG_Error: + log.appendformat ("<span style=\"color: #F8F8F8; background-color: #800\"><b>[ERROR]</b> %s</span>", + zText.chars()); + break; + + case LOG_Info: + log.appendformat ("<span style=\"color: #0AC\"><b>[INFO]</b> %s</span>", + zText.chars()); + break; + + case LOG_Success: + log.appendformat ("<span style=\"color: #6A0\"><b>[SUCCESS]</b> %s</span>", + zText.chars()); + break; + + case LOG_Warning: + log.appendformat ("<span style=\"color: #C50\"><b>[WARNING]</b> %s</span>", + zText.chars()); + break; + + case LOG_Dev: +#ifndef RELEASE + log.appendformat ("<span style=\"color: #0AC\"><b>[DEV]</b> %s</span>", + zText.chars()); +#endif // RELEASE + break; + } + + m_msglog->setHtml (log); } \ No newline at end of file
--- a/gui.h Sat May 04 13:52:47 2013 +0300 +++ b/gui.h Sat May 04 18:31:03 2013 +0300 @@ -118,39 +118,10 @@ Q_OBJECT public: - GLRenderer* R; - - // Object list view - ObjectList* objList; - QTextEdit* qMessageLog; - QMenu* qFileMenu, *qEditMenu, *qViewMenu, *qInsertMenu, *qMoveMenu, - *qHelpMenu, *qControlMenu; - QMenu* qRecentFilesMenu; - std::vector<QAction*> qaRecentFiles; - QSplitter* hsplit, *vsplit; - -#ifndef RELEASE - QMenu* qDebugMenu; - QToolBar* qDebugToolBar; -#endif // RELEASE - - std::vector<QToolBar*> qaToolBars; - - // Quick color buttons - std::vector<QPushButton*> qaColorButtons; - QToolBar* qColorToolBar; - std::vector<quickColorMetaEntry> quickColorMeta; - - // Selected objects - std::vector<LDObject*> sel; - - str zMessageLogHTML; - ForgeWindow (); void buildObjList (); void setTitle (); void refresh (); - std::vector<LDObject*> getSelectedObjects (); ulong getInsertionPoint (); void deleteSelection (vector<ulong>* ulapIndices, std::vector<LDObject*>* papObjects); void updateToolBars (); @@ -162,11 +133,33 @@ LDObjectType_e uniformSelectedType (); void scrollToSelection (); void spawnContextMenu (const QPoint pos); + GLRenderer* R () { return m_renderer; } + std::vector<LDObject*>& sel () { return m_sel; } + void setQuickColorMeta (std::vector<quickColorMetaEntry>& quickColorMeta) { + m_colorMeta = quickColorMeta; + } protected: void closeEvent (QCloseEvent* ev); + void logVA (LogType eType, const char* fmtstr, va_list va); + + friend void logf (const char* fmt, ...); + friend void logf (LogType eType, const char* fmt, ...); private: + GLRenderer* m_renderer; + ObjectList* m_objList; + QTextEdit* m_msglog; + QMenu* m_recentFilesMenu; + QSplitter* m_hsplit, *m_vsplit; + str m_msglogHTML; + QToolBar* m_colorToolBar; + std::vector<QToolBar*> m_toolBars; + std::vector<LDObject*> m_sel; + std::vector<quickColorMetaEntry> m_colorMeta; + std::vector<QPushButton*> m_colorButtons; + std::vector<QAction*> m_recentFiles; + void createMenuActions (); void createMenus (); void createToolbars (); @@ -190,7 +183,7 @@ // ----------------------------------------------------------------------------- // Pointer to the instance of ForgeWindow. -extern ForgeWindow* g_ForgeWindow; +extern ForgeWindow* g_win; // Is this still needed? enum {
--- a/gui_actions.cpp Sat May 04 13:52:47 2013 +0300 +++ b/gui_actions.cpp Sat May 04 18:31:03 2013 +0300 @@ -39,7 +39,7 @@ // ============================================================================= MAKE_ACTION (open, "&Open", "file-open", "Load a part model from a file.", CTRL (O)) { str zName; - zName += QFileDialog::getOpenFileName (g_ForgeWindow, "Open File", + zName += QFileDialog::getOpenFileName (g_win, "Open File", "", "LDraw files (*.dat *.ldr)"); if (~zName) @@ -50,10 +50,10 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void doSave (bool saveAs) { - str path = g_CurrentFile->zFileName; + str path = g_curfile->m_filename; if (~path == 0 || saveAs) { - path = QFileDialog::getSaveFileName (g_ForgeWindow, "Save As", + path = QFileDialog::getSaveFileName (g_win, "Save As", "", "LDraw files (*.dat *.ldr)"); if (~path == 0) { @@ -63,9 +63,9 @@ } } - if (g_CurrentFile->save (path)) { - g_CurrentFile->zFileName = path; - g_ForgeWindow->setTitle (); + if (g_curfile->save (path)) { + g_curfile->m_filename = path; + g_win->setTitle (); logf ("Saved successfully to %s\n", path.chars ()); } else { @@ -73,8 +73,8 @@ // Tell the user the save failed, and give the option for saving as with it. QMessageBox dlg (QMessageBox::Critical, "Save Failure", - format ("Failed to save to %s\nReason: %s", path.chars(), strerror (g_CurrentFile->lastError)), - QMessageBox::Close, g_ForgeWindow); + format ("Failed to save to %s\nReason: %s", path.chars(), strerror (g_curfile->lastError)), + QMessageBox::Close, g_win); QPushButton* saveAsBtn = new QPushButton ("Save As"); saveAsBtn->setIcon (getIcon ("file-save-as")); @@ -155,10 +155,10 @@ } MAKE_ACTION (editObject, "Edit Object", "edit-object", "Edits this object.", 0) { - if (g_ForgeWindow->sel.size () != 1) + if (g_win->sel ().size () != 1) return; - LDObject* obj = g_ForgeWindow->sel[0]; + LDObject* obj = g_win->sel ()[0]; AddObjectDialog::staticDialog (obj->getType (), obj); } @@ -177,46 +177,46 @@ } MAKE_ACTION (aboutQt, "About Qt", "qt", "Shows information about Qt.", CTRL_SHIFT (F1)) { - QMessageBox::aboutQt (g_ForgeWindow); + QMessageBox::aboutQt (g_win); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= MAKE_ACTION (selectAll, "Select All", "select-all", "Selects all objects.", CTRL (A)) { - g_ForgeWindow->sel.clear (); + g_win->sel ().clear (); - for (LDObject* obj : g_CurrentFile->objects) - g_ForgeWindow->sel.push_back (obj); + for (LDObject* obj : g_curfile->m_objs) + g_win->sel ().push_back (obj); - g_ForgeWindow->updateSelection (); + g_win->updateSelection (); } // ============================================================================= MAKE_ACTION (selectByColor, "Select by Color", "select-color", "Select all objects by the given color.", CTRL_SHIFT (A)) { - short dColor = g_ForgeWindow->getSelectedColor (); + short dColor = g_win->getSelectedColor (); if (dColor == -1) return; // no consensus on color - g_ForgeWindow->sel.clear (); - for (LDObject* obj : g_CurrentFile->objects) + g_win->sel ().clear (); + for (LDObject* obj : g_curfile->m_objs) if (obj->dColor == dColor) - g_ForgeWindow->sel.push_back (obj); + g_win->sel ().push_back (obj); - g_ForgeWindow->updateSelection (); + g_win->updateSelection (); } // ============================================================================= MAKE_ACTION (selectByType, "Select by Type", "select-type", "Select all objects by the given type.", (0)) { - if (g_ForgeWindow->sel.size () == 0) + if (g_win->sel ().size () == 0) return; - LDObjectType_e eType = g_ForgeWindow->uniformSelectedType (); + LDObjectType_e eType = g_win->uniformSelectedType (); if (eType == OBJ_Unidentified) return; @@ -226,25 +226,25 @@ str zRefName; if (eType == OBJ_Subfile) { - zRefName = static_cast<LDSubfile*> (g_ForgeWindow->sel[0])->zFileName; + zRefName = static_cast<LDSubfile*> (g_win->sel ()[0])->zFileName; - for (LDObject* pObj : g_ForgeWindow->sel) + for (LDObject* pObj : g_win->sel ()) if (static_cast<LDSubfile*> (pObj)->zFileName != zRefName) return; } - g_ForgeWindow->sel.clear (); - for (LDObject* obj : g_CurrentFile->objects) { + g_win->sel ().clear (); + for (LDObject* obj : g_curfile->m_objs) { if (obj->getType() != eType) continue; if (eType == OBJ_Subfile && static_cast<LDSubfile*> (obj)->zFileName != zRefName) continue; - g_ForgeWindow->sel.push_back (obj); + g_win->sel ().push_back (obj); } - g_ForgeWindow->updateSelection (); + g_win->updateSelection (); } // ============================================================================= @@ -252,25 +252,25 @@ // ============================================================================= MAKE_ACTION (gridCoarse, "Coarse Grid", "grid-coarse", "Set the grid to Coarse", CTRL (1)) { grid = Grid::Coarse; - g_ForgeWindow->updateGridToolBar (); + g_win->updateGridToolBar (); } MAKE_ACTION (gridMedium, "Medium Grid", "grid-medium", "Set the grid to Medium", CTRL (2)) { grid = Grid::Medium; - g_ForgeWindow->updateGridToolBar (); + g_win->updateGridToolBar (); } MAKE_ACTION (gridFine, "Fine Grid", "grid-fine", "Set the grid to Fine", CTRL (3)) { grid = Grid::Fine; - g_ForgeWindow->updateGridToolBar (); + g_win->updateGridToolBar (); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= MAKE_ACTION (resetView, "Reset View", "reset-view", "Reset view angles, pan and zoom", CTRL (0)) { - g_ForgeWindow->R->resetAngles (); - g_ForgeWindow->R->update (); + g_win->R ()->resetAngles (); + g_win->R ()->update (); } // ============================================================================= @@ -278,7 +278,7 @@ // ============================================================================= MAKE_ACTION (insertFrom, "Insert from File", "insert-from", "Insert LDraw data from a file.", (0)) { str fname = QFileDialog::getOpenFileName (); - ulong idx = g_ForgeWindow->getInsertionPoint (); + ulong idx = g_win->getInsertionPoint (); if (!~fname) return; @@ -293,21 +293,21 @@ std::vector<ulong> historyIndices; std::vector<LDObject*> objs = loadFileContents (fp, null); - g_ForgeWindow->sel.clear (); + g_win->sel ().clear (); for (LDObject* obj : objs) { historyCopies.push_back (obj->clone ()); historyIndices.push_back (idx); - g_CurrentFile->insertObj (idx, obj); - g_ForgeWindow->sel.push_back (obj); + g_curfile->insertObj (idx, obj); + g_win->sel ().push_back (obj); idx++; } if (historyCopies.size() > 0) { History::addEntry (new AddHistory (historyIndices, historyCopies)); - g_ForgeWindow->refresh (); - g_ForgeWindow->scrollToSelection (); + g_win->refresh (); + g_win->scrollToSelection (); } } @@ -315,7 +315,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= MAKE_ACTION (insertRaw, "Insert Raw", "insert-raw", "Type in LDraw code to insert.", (0)) { - ulong idx = g_ForgeWindow->getInsertionPoint (); + ulong idx = g_win->getInsertionPoint (); QDialog* const dlg = new QDialog; QVBoxLayout* const layout = new QVBoxLayout; @@ -334,22 +334,22 @@ if (dlg->exec () == false) return; - g_ForgeWindow->sel.clear (); + g_win->sel ().clear (); for (str line : str (te_edit->toPlainText ()).split ("\n")) { LDObject* obj = parseLine (line); - g_CurrentFile->insertObj (idx, obj); + g_curfile->insertObj (idx, obj); historyIndices.push_back (idx); historyCopies.push_back (obj->clone ()); - g_ForgeWindow->sel.push_back (obj); + g_win->sel ().push_back (obj); idx++; } if (historyCopies.size () > 0) { History::addEntry (new AddHistory (historyIndices, historyCopies)); - g_ForgeWindow->refresh (); - g_ForgeWindow->scrollToSelection (); + g_win->refresh (); + g_win->scrollToSelection (); } } @@ -360,17 +360,17 @@ setlocale (LC_ALL, "C"); ushort w, h; - uchar* imagedata = g_ForgeWindow->R->screencap (w, h); + uchar* imagedata = g_win->R ()->screencap (w, h); // GL and Qt formats have R and B swapped. Also, GL flips Y - correct it as well. QImage img = QImage (imagedata, w, h, QImage::Format_ARGB32).rgbSwapped ().mirrored (); - str root = basename (g_CurrentFile->zFileName.chars ()); + str root = basename (g_curfile->m_filename.chars ()); if (root.substr (~root - 4, -1) == ".dat") root -= 4; str defaultname = (~root > 0) ? format ("%s.png", root.chars ()) : ""; - str fname = QFileDialog::getSaveFileName (g_ForgeWindow, "Save Screencap", defaultname, + str fname = QFileDialog::getSaveFileName (g_win, "Save Screencap", defaultname, "PNG images (*.png);;JPG images (*.jpg);;BMP images (*.bmp);;All Files (*.*)"); if (~fname > 0 && !img.save (fname)) @@ -386,7 +386,7 @@ MAKE_ACTION (axes, "Draw Axes", "axes", "Toggles drawing of axes", (0)) { gl_axes = !gl_axes; ACTION (axes)->setChecked (gl_axes); - g_ForgeWindow->R->update (); + g_win->R ()->update (); } // ============================================================================= @@ -402,24 +402,24 @@ pQuad->vaCoords[2] = {-1.0f, 0.0f, -1.0f}; pQuad->vaCoords[3] = { 1.0f, 0.0f, -1.0f}; - g_CurrentFile->insertObj (g_ForgeWindow->getInsertionPoint (), pQuad); - History::addEntry (new AddHistory ({(ulong)pQuad->getIndex (g_CurrentFile)}, {pQuad->clone ()})); - g_ForgeWindow->refresh (); + g_curfile->insertObj (g_win->getInsertionPoint (), pQuad); + History::addEntry (new AddHistory ({(ulong)pQuad->getIndex (g_curfile)}, {pQuad->clone ()})); + g_win->refresh (); } MAKE_ACTION (addTestRadial, "Add Test Radial", "add-radial", "Adds a test radial.", (0)) { LDRadial* pRad = new LDRadial; pRad->eRadialType = LDRadial::Cone; - pRad->mMatrix = g_mIdentity; + pRad->mMatrix = g_identity; pRad->vPosition = vertex (0, 0, 0); pRad->dColor = rand () % 24; pRad->dDivisions = 16; pRad->dRingNum = 2; pRad->dSegments = 16; - g_CurrentFile->insertObj (g_ForgeWindow->getInsertionPoint (), pRad); - History::addEntry (new AddHistory ({(ulong)pRad->getIndex (g_CurrentFile)}, {pRad->clone ()})); - g_ForgeWindow->refresh (); + g_curfile->insertObj (g_win->getInsertionPoint (), pRad); + History::addEntry (new AddHistory ({(ulong)pRad->getIndex (g_curfile)}, {pRad->clone ()})); + g_win->refresh (); } #endif // RELEASE \ No newline at end of file
--- a/gui_editactions.cpp Sat May 04 13:52:47 2013 +0300 +++ b/gui_editactions.cpp Sat May 04 18:31:03 2013 +0300 @@ -34,7 +34,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= static bool copyToClipboard () { - vector<LDObject*> objs = g_ForgeWindow->sel; + vector<LDObject*> objs = g_win->sel (); if (objs.size() == 0) return false; @@ -65,7 +65,7 @@ if (!copyToClipboard ()) return; - g_ForgeWindow->deleteSelection (&ulaIndices, &copies); + g_win->deleteSelection (&ulaIndices, &copies); History::addEntry (new DelHistory (ulaIndices, copies, DelHistory::Cut)); } @@ -83,21 +83,21 @@ vector<ulong> historyIndices; vector<LDObject*> historyCopies; - ulong idx = g_ForgeWindow->getInsertionPoint (); - g_ForgeWindow->sel.clear (); + ulong idx = g_win->getInsertionPoint (); + g_win->sel ().clear (); for (LDObject* obj : g_Clipboard) { historyIndices.push_back (idx); historyCopies.push_back (obj->clone ()); LDObject* copy = obj->clone (); - g_CurrentFile->insertObj (idx, copy); - g_ForgeWindow->sel.push_back (copy); + g_curfile->insertObj (idx, copy); + g_win->sel ().push_back (copy); } History::addEntry (new AddHistory (historyIndices, historyCopies, AddHistory::Paste)); - g_ForgeWindow->refresh (); - g_ForgeWindow->scrollToSelection (); + g_win->refresh (); + g_win->scrollToSelection (); } // ============================================================================= @@ -107,7 +107,7 @@ vector<ulong> ulaIndices; vector<LDObject*> copies; - g_ForgeWindow->deleteSelection (&ulaIndices, &copies); + g_win->deleteSelection (&ulaIndices, &copies); if (copies.size ()) History::addEntry (new DelHistory (ulaIndices, copies)); @@ -117,7 +117,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= static void doInline (bool bDeep) { - vector<LDObject*> sel = g_ForgeWindow->sel; + vector<LDObject*> sel = g_win->sel (); // History stuff vector<LDSubfile*> paRefs; @@ -127,14 +127,14 @@ if (obj->getType() != OBJ_Subfile) continue; - ulaRefIndices.push_back (obj->getIndex (g_CurrentFile)); + ulaRefIndices.push_back (obj->getIndex (g_curfile)); paRefs.push_back (static_cast<LDSubfile*> (obj)->clone ()); } for (LDObject* obj : sel) { // Get the index of the subfile so we know where to insert the // inlined contents. - long idx = obj->getIndex (g_CurrentFile); + long idx = obj->getIndex (g_curfile); if (idx == -1) continue; @@ -154,16 +154,16 @@ // This object is now inlined so it has no parent anymore. inlineobj->parent = null; - g_CurrentFile->insertObj (idx++, inlineobj); + g_curfile->insertObj (idx++, inlineobj); } // Delete the subfile now as it's been inlined. - g_CurrentFile->forgetObject (obj); + g_curfile->forgetObject (obj); delete obj; } History::addEntry (new InlineHistory (ulaBitIndices, ulaRefIndices, paRefs, bDeep)); - g_ForgeWindow->refresh (); + g_win->refresh (); } MAKE_ACTION (inlineContents, "Inline", "inline", "Inline selected subfiles.", CTRL (I)) { @@ -180,7 +180,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= MAKE_ACTION (splitQuads, "Split Quads", "quad-split", "Split quads into triangles.", (0)) { - vector<LDObject*> objs = g_ForgeWindow->sel; + vector<LDObject*> objs = g_win->sel (); vector<ulong> ulaIndices; vector<LDQuad*> paCopies; @@ -190,7 +190,7 @@ if (obj->getType() != OBJ_Quad) continue; - ulaIndices.push_back (obj->getIndex (g_CurrentFile)); + ulaIndices.push_back (obj->getIndex (g_curfile)); paCopies.push_back (static_cast<LDQuad*> (obj)->clone ()); } @@ -199,7 +199,7 @@ continue; // Find the index of this quad - long lIndex = obj->getIndex (g_CurrentFile); + long lIndex = obj->getIndex (g_curfile); if (lIndex == -1) return; @@ -208,25 +208,25 @@ // Replace the quad with the first triangle and add the second triangle // after the first one. - g_CurrentFile->objects[lIndex] = triangles[0]; - g_CurrentFile->insertObj (lIndex + 1, triangles[1]); + g_curfile->m_objs[lIndex] = triangles[0]; + g_curfile->insertObj (lIndex + 1, triangles[1]); // Delete this quad now, it has been split. delete obj; } History::addEntry (new QuadSplitHistory (ulaIndices, paCopies)); - g_ForgeWindow->refresh (); + g_win->refresh (); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= MAKE_ACTION (setContents, "Set Contents", "set-contents", "Set the raw code of this object.", KEY (F9)) { - if (g_ForgeWindow->objList->selectedItems().size() != 1) + if (g_win->sel ().size() != 1) return; - LDObject* obj = g_ForgeWindow->sel[0]; + LDObject* obj = g_win->sel ()[0]; SetContentsDialog::staticDialog (obj); } @@ -234,26 +234,26 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= MAKE_ACTION (setColor, "Set Color", "palette", "Set the color on given objects.", KEY (F10)) { - if (g_ForgeWindow->objList->selectedItems().size() <= 0) + if (g_win->sel ().size() <= 0) return; short dColor; short dDefault = -1; - std::vector<LDObject*> objs = g_ForgeWindow->sel; + std::vector<LDObject*> objs = g_win->sel (); // If all selected objects have the same color, said color is our default // value to the color selection dialog. - dDefault = g_ForgeWindow->getSelectedColor (); + dDefault = g_win->getSelectedColor (); // Show the dialog to the user now and ask for a color. - if (ColorSelectDialog::staticDialog (dColor, dDefault, g_ForgeWindow)) { + if (ColorSelectDialog::staticDialog (dColor, dDefault, g_win)) { std::vector<ulong> ulaIndices; std::vector<short> daColors; for (LDObject* obj : objs) { if (obj->dColor != -1) { - ulaIndices.push_back (obj->getIndex (g_CurrentFile)); + ulaIndices.push_back (obj->getIndex (g_curfile)); daColors.push_back (obj->dColor); obj->dColor = dColor; @@ -261,7 +261,7 @@ } History::addEntry (new SetColorHistory (ulaIndices, daColors, dColor)); - g_ForgeWindow->refresh (); + g_win->refresh (); } } @@ -271,7 +271,7 @@ MAKE_ACTION (makeBorders, "Make Borders", "make-borders", "Add borders around given polygons.", CTRL_SHIFT (B)) { - vector<LDObject*> objs = g_ForgeWindow->sel; + vector<LDObject*> objs = g_win->sel (); vector<ulong> ulaIndices; vector<LDObject*> paObjs; @@ -301,10 +301,10 @@ } for (short i = 0; i < dNumLines; ++i) { - ulong idx = obj->getIndex (g_CurrentFile) + i + 1; + ulong idx = obj->getIndex (g_curfile) + i + 1; lines[i]->dColor = edgecolor; - g_CurrentFile->insertObj (idx, lines[i]); + g_curfile->insertObj (idx, lines[i]); ulaIndices.push_back (idx); paObjs.push_back (lines[i]->clone ()); @@ -312,7 +312,7 @@ } History::addEntry (new AddHistory (ulaIndices, paObjs)); - g_ForgeWindow->refresh (); + g_win->refresh (); } // ============================================================================= @@ -324,17 +324,17 @@ vector<ulong> ulaIndices; vector<LDObject*> paObjs; - for (LDObject* obj : g_ForgeWindow->sel) { + for (LDObject* obj : g_win->sel ()) { if (obj->vertices () < 2) continue; - ulong idx = obj->getIndex (g_CurrentFile); + ulong idx = obj->getIndex (g_curfile); for (short i = 0; i < obj->vertices(); ++i) { LDVertex* vert = new LDVertex; vert->vPosition = obj->vaCoords[i]; vert->dColor = obj->dColor; - g_CurrentFile->insertObj (++idx, vert); + g_curfile->insertObj (++idx, vert); ulaIndices.push_back (idx); paObjs.push_back (vert->clone ()); } @@ -342,7 +342,7 @@ if (ulaIndices.size() > 0) { History::addEntry (new AddHistory (ulaIndices, paObjs)); - g_ForgeWindow->refresh (); + g_win->refresh (); } } @@ -350,16 +350,16 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= static void doMoveSelection (const bool bUp) { - vector<LDObject*> objs = g_ForgeWindow->sel; + vector<LDObject*> objs = g_win->sel (); // Get the indices of the objects for history archival vector<ulong> ulaIndices; for (LDObject* obj : objs) - ulaIndices.push_back (obj->getIndex (g_CurrentFile)); + ulaIndices.push_back (obj->getIndex (g_curfile)); LDObject::moveObjects (objs, bUp); History::addEntry (new ListMoveHistory (ulaIndices, bUp)); - g_ForgeWindow->buildObjList (); + g_win->buildObjList (); } MAKE_ACTION (moveUp, "Move Up", "arrow-up", "Move the current selection up.", SHIFT (Up)) { @@ -397,13 +397,13 @@ vVector[Y] *= currentGrid ().confs[Grid::Y]->value; vVector[Z] *= currentGrid ().confs[Grid::Z]->value; - for (LDObject* obj : g_ForgeWindow->sel) { - ulaIndices.push_back (obj->getIndex (g_CurrentFile)); + for (LDObject* obj : g_win->sel ()) { + ulaIndices.push_back (obj->getIndex (g_curfile)); obj->move (vVector); } History::addEntry (new MoveHistory (ulaIndices, vVector)); - g_ForgeWindow->refresh (); + g_win->refresh (); } MAKE_ACTION (moveXNeg, "Move -X", "move-x-neg", "Move selected objects negative on the X axis.", KEY (Left)) { @@ -443,7 +443,7 @@ // History. // ============================================================================= MAKE_ACTION (invert, "Invert", "invert", "Reverse the winding of given objects.", CTRL_SHIFT (W)) { - std::vector<LDObject*> paSelection = g_ForgeWindow->sel; + std::vector<LDObject*> paSelection = g_win->sel (); std::vector<HistoryEntry*> paHistory; for (LDObject* obj : paSelection) { @@ -451,7 +451,7 @@ // variables and we store them into an EditHistory after the switch // block. Subfile and radial management is stored into the history // list immediately. - ulong ulHistoryIndex = obj->getIndex (g_CurrentFile); + ulong ulHistoryIndex = obj->getIndex (g_curfile); LDObject* pOldCopy, *pNewCopy; bool bEdited = false; @@ -513,10 +513,10 @@ // Food for thought... bool inverted = false; - ulong idx = obj->getIndex (g_CurrentFile); + ulong idx = obj->getIndex (g_curfile); if (idx > 0) { - LDObject* prev = g_CurrentFile->object (idx - 1); + LDObject* prev = g_curfile->object (idx - 1); LDBFC* bfc = dynamic_cast<LDBFC*> (prev); if (bfc && bfc->eStatement == LDBFC::InvertNext) { @@ -524,7 +524,7 @@ paHistory.push_back (new DelHistory ({idx - 1}, {bfc->clone ()})); inverted = true; - g_CurrentFile->forgetObject (bfc); + g_curfile->forgetObject (bfc); delete bfc; } } @@ -532,7 +532,7 @@ if (!inverted) { // Not inverted, thus prefix it with a new invertnext. LDBFC* bfc = new LDBFC (LDBFC::InvertNext); - g_CurrentFile->insertObj (idx, bfc); + g_curfile->insertObj (idx, bfc); paHistory.push_back (new AddHistory ({idx}, {bfc->clone ()})); } @@ -551,7 +551,7 @@ if (paHistory.size () > 0) { History::addEntry (new ComboHistory (paHistory)); - g_ForgeWindow->refresh (); + g_win->refresh (); } } @@ -559,7 +559,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= static void doRotate (const short l, const short m, const short n) { - std::vector<LDObject*> sel = g_ForgeWindow->sel; + std::vector<LDObject*> sel = g_win->sel (); bbox box; vertex origin; std::vector<vertex*> queue; @@ -613,11 +613,11 @@ for (vertex* v : queue) { v->move (-origin); - v->transform (transform, g_Origin); + v->transform (transform, g_origin); v->move (origin); } - g_ForgeWindow->refresh (); + g_win->refresh (); } MAKE_ACTION (rotateXPos, "Rotate +X", "rotate-x-pos", "Rotate objects around X axis", CTRL (Right)) { @@ -650,12 +650,12 @@ MAKE_ACTION (roundCoords, "Round Coordinates", "round-coords", "Round coordinates down to 3/4 decimals", (0)) { setlocale (LC_ALL, "C"); - for (LDObject* obj : g_ForgeWindow->sel) + for (LDObject* obj : g_win->sel ()) for (short i = 0; i < obj->vertices (); ++i) for (const Axis ax : g_Axes) obj->vaCoords[i][ax] = atof (format ("%.3f", obj->vaCoords[i][ax])); - g_ForgeWindow->refresh (); + g_win->refresh (); } // ============================================================================= @@ -665,11 +665,11 @@ vector<LDObject*> oldCopies, newCopies; vector<ulong> indices; - for (LDObject* obj : g_ForgeWindow->sel) { + for (LDObject* obj : g_win->sel ()) { if (obj->isColored () == false) continue; - indices.push_back (obj->getIndex (g_CurrentFile)); + indices.push_back (obj->getIndex (g_curfile)); oldCopies.push_back (obj->clone ()); obj->dColor = (obj->getType () == OBJ_Line || obj->getType () == OBJ_CondLine) ? edgecolor : maincolor; @@ -678,6 +678,6 @@ if (indices.size () > 0) { History::addEntry (new EditHistory (indices, oldCopies, newCopies)); - g_ForgeWindow->refresh (); + g_win->refresh (); } } \ No newline at end of file
--- a/history.cpp Sat May 04 13:52:47 2013 +0300 +++ b/history.cpp Sat May 04 18:31:03 2013 +0300 @@ -29,64 +29,69 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= namespace History { - std::vector<HistoryEntry*> entries; - - static long m_pos = -1; + std::vector<HistoryEntry*> s_entries; + static long s_pos = -1; // ========================================================================= void addEntry (HistoryEntry* entry) { - // If there's any entries after our current position, we need to remove them now - for (ulong i = m_pos + 1; i < entries.size(); ++i) { - delete entries[i]; - entries.erase (entries.begin() + i); + // If there's any entries ahead the current position, we need to + // remove them now + for (ulong i = s_pos + 1; i < s_entries.size(); ++i) { + delete s_entries[i]; + s_entries.erase (s_entries.begin() + i); } - entries.push_back (entry); - m_pos++; + s_entries.push_back (entry); + s_pos++; updateActions (); } // ========================================================================= void undo () { - if (m_pos == -1) + if (s_pos == -1) return; // nothing to undo - entries[m_pos--]->undo (); + s_entries[s_pos--]->undo (); updateActions (); } // ========================================================================= void redo () { - if (m_pos == (long) entries.size () - 1) + if (s_pos == (long) s_entries.size () - 1) return; // nothing to redo; - entries[++m_pos]->redo (); + s_entries[++s_pos]->redo (); updateActions (); } // ========================================================================= void clear () { - for (HistoryEntry* entry : entries) + for (HistoryEntry* entry : s_entries) delete entry; - entries.clear (); - m_pos = -1; + s_entries.clear (); + s_pos = -1; updateActions (); } // ========================================================================= void updateActions () { - ACTION (undo)->setEnabled (m_pos > -1); - ACTION (redo)->setEnabled (m_pos < (long) entries.size () - 1); + ACTION (undo)->setEnabled (s_pos > -1); + ACTION (redo)->setEnabled (s_pos < (long) s_entries.size () - 1); // Update the window title as well - g_ForgeWindow->setTitle (); + g_win->setTitle (); } // ========================================================================= long pos () { - return m_pos; + return s_pos; + } + + // ========================================================================= + std::vector<HistoryEntry*>& entries () { + return s_entries; } } @@ -97,22 +102,22 @@ for (ulong i = 0; i < cache.size(); ++i) { ulong idx = cache.size() - i - 1; LDObject* obj = cache[idx]->clone (); - g_CurrentFile->insertObj (indices[idx], obj); + g_curfile->insertObj (indices[idx], obj); } - g_ForgeWindow->refresh (); + g_win->refresh (); } // ============================================================================= void DelHistory::redo () { for (ulong i = 0; i < cache.size(); ++i) { - LDObject* obj = g_CurrentFile->objects[indices[i]]; + LDObject* obj = g_curfile->m_objs[indices[i]]; - g_CurrentFile->forgetObject (obj); + g_curfile->forgetObject (obj); delete obj; } - g_ForgeWindow->refresh (); + g_win->refresh (); } // ============================================================================= @@ -127,17 +132,17 @@ void SetColorHistory::undo () { // Restore colors for (ulong i = 0; i < ulaIndices.size (); ++i) - g_CurrentFile->objects[ulaIndices[i]]->dColor = daColors[i]; + g_curfile->m_objs[ulaIndices[i]]->dColor = daColors[i]; - g_ForgeWindow->refresh (); + g_win->refresh (); } void SetColorHistory::redo () { // Re-set post color for (ulong i = 0; i < ulaIndices.size (); ++i) - g_CurrentFile->objects[ulaIndices[i]]->dColor = dNewColor; + g_curfile->m_objs[ulaIndices[i]]->dColor = dNewColor; - g_ForgeWindow->refresh (); + g_win->refresh (); } SetColorHistory::~SetColorHistory () {} @@ -147,16 +152,16 @@ // ============================================================================= void EditHistory::undo () { for (ulong idx : ulaIndices) - g_CurrentFile->object (idx)->replace (paOldObjs[idx]->clone ()); + g_curfile->object (idx)->replace (paOldObjs[idx]->clone ()); - g_ForgeWindow->refresh (); + g_win->refresh (); } void EditHistory::redo () { for (ulong idx : ulaIndices) - g_CurrentFile->object (idx)->replace (paNewObjs[idx]->clone ()); + g_curfile->object (idx)->replace (paNewObjs[idx]->clone ()); - g_ForgeWindow->refresh (); + g_win->refresh (); } EditHistory::~EditHistory () { @@ -173,7 +178,7 @@ std::vector<LDObject*> objs; for (ulong idx : ulaIndices) - objs.push_back (g_CurrentFile->objects[idx + ofs]); + objs.push_back (g_curfile->m_objs[idx + ofs]); return objs; } @@ -181,13 +186,13 @@ void ListMoveHistory::undo () { std::vector<LDObject*> objs = getObjects (bUp ? -1 : 1); LDObject::moveObjects (objs, !bUp); - g_ForgeWindow->buildObjList (); + g_win->buildObjList (); } void ListMoveHistory::redo () { std::vector<LDObject*> objs = getObjects (0); LDObject::moveObjects (objs, bUp); - g_ForgeWindow->buildObjList (); + g_win->buildObjList (); } ListMoveHistory::~ListMoveHistory() {} @@ -203,13 +208,13 @@ void AddHistory::undo () { for (ulong i = 0; i < paObjs.size(); ++i) { ulong idx = ulaIndices[ulaIndices.size() - i - 1]; - LDObject* obj = g_CurrentFile->objects[idx]; + LDObject* obj = g_curfile->m_objs[idx]; - g_CurrentFile->forgetObject (obj); + g_curfile->forgetObject (obj); delete obj; } - g_ForgeWindow->refresh (); + g_win->refresh (); } void AddHistory::redo () { @@ -217,10 +222,10 @@ ulong idx = ulaIndices[i]; LDObject* obj = paObjs[i]->clone (); - g_CurrentFile->insertObj (idx, obj); + g_curfile->insertObj (idx, obj); } - g_ForgeWindow->refresh (); + g_win->refresh (); } // ============================================================================= @@ -238,31 +243,31 @@ // the first with a copy of the quad. ulong idx = ulaIndices[i]; - LDTriangle* tri1 = static_cast<LDTriangle*> (g_CurrentFile->objects[idx]), - *tri2 = static_cast<LDTriangle*> (g_CurrentFile->objects[idx + 1]); + LDTriangle* tri1 = static_cast<LDTriangle*> (g_curfile->m_objs[idx]), + *tri2 = static_cast<LDTriangle*> (g_curfile->m_objs[idx + 1]); LDQuad* pCopy = paQuads[i]->clone (); tri1->replace (pCopy); - g_CurrentFile->forgetObject (tri2); + g_curfile->forgetObject (tri2); delete tri2; } - g_ForgeWindow->refresh (); + g_win->refresh (); } void QuadSplitHistory::redo () { for (long i = paQuads.size() - 1; i >= 0; --i) { ulong idx = ulaIndices[i]; - LDQuad* pQuad = static_cast<LDQuad*> (g_CurrentFile->objects[idx]); + LDQuad* pQuad = static_cast<LDQuad*> (g_curfile->m_objs[idx]); std::vector<LDTriangle*> paTriangles = pQuad->splitToTriangles (); - g_CurrentFile->objects[idx] = paTriangles[0]; - g_CurrentFile->insertObj (idx + 1, paTriangles[1]); + g_curfile->m_objs[idx] = paTriangles[0]; + g_curfile->insertObj (idx + 1, paTriangles[1]); delete pQuad; } - g_ForgeWindow->refresh (); + g_win->refresh (); } // ============================================================================= @@ -270,35 +275,35 @@ // ============================================================================= void InlineHistory::undo () { for (long i = ulaBitIndices.size() - 1; i >= 0; --i) { - LDObject* obj = g_CurrentFile->objects [ulaBitIndices[i]]; - g_CurrentFile->forgetObject (obj); + LDObject* obj = g_curfile->m_objs [ulaBitIndices[i]]; + g_curfile->forgetObject (obj); delete obj; } for (ulong i = 0; i < ulaRefIndices.size(); ++i) { LDSubfile* obj = paRefs[i]->clone (); - g_CurrentFile->insertObj (ulaRefIndices[i], obj); + g_curfile->insertObj (ulaRefIndices[i], obj); } - g_ForgeWindow->refresh (); + g_win->refresh (); } void InlineHistory::redo () { for (long i = ulaRefIndices.size() - 1; i >= 0; --i) { ulong idx = ulaRefIndices[i]; - assert (g_CurrentFile->object (idx)->getType () == OBJ_Subfile); - LDSubfile* ref = static_cast<LDSubfile*> (g_CurrentFile->object (idx)); + assert (g_curfile->object (idx)->getType () == OBJ_Subfile); + LDSubfile* ref = static_cast<LDSubfile*> (g_curfile->object (idx)); vector<LDObject*> objs = ref->inlineContents (bDeep, false); for (LDObject* obj : objs) - g_CurrentFile->insertObj (idx++, obj); + g_curfile->insertObj (idx++, obj); - g_CurrentFile->forgetObject (ref); + g_curfile->forgetObject (ref); delete ref; } - g_ForgeWindow->refresh (); + g_win->refresh (); } InlineHistory::~InlineHistory () { @@ -315,14 +320,14 @@ const vertex vInverse = -vVector; for (ulong i : ulaIndices) - g_CurrentFile->object (i)->move (vInverse); - g_ForgeWindow->refresh (); + g_curfile->object (i)->move (vInverse); + g_win->refresh (); } void MoveHistory::redo () { for (ulong i : ulaIndices) - g_CurrentFile->object (i)->move (vVector); - g_ForgeWindow->refresh (); + g_curfile->object (i)->move (vVector); + g_win->refresh (); } // =============================================================================
--- a/history.h Sat May 04 13:52:47 2013 +0300 +++ b/history.h Sat May 04 18:31:03 2013 +0300 @@ -198,14 +198,13 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= namespace History { - extern std::vector<HistoryEntry*> entries; - void addEntry (HistoryEntry* entry); void undo (); void redo (); void clear (); void updateActions (); long pos (); + std::vector<HistoryEntry*>& entries (); }; #endif // HISTORY_H \ No newline at end of file
--- a/ldtypes.cpp Sat May 04 13:52:47 2013 +0300 +++ b/ldtypes.cpp Sat May 04 18:31:03 2013 +0300 @@ -220,7 +220,7 @@ // ============================================================================= void LDObject::replace (LDObject* replacement) { // Replace all instances of the old object with the new object - for (LDObject*& obj : g_CurrentFile->objects) + for (LDObject*& obj : g_curfile->m_objs) if (obj == this) obj = replacement; @@ -232,7 +232,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void LDObject::swap (LDObject* other) { - for (LDObject*& obj : g_CurrentFile->objects) { + for (LDObject*& obj : g_curfile->m_objs) { if (obj == this) obj = other; else if (obj == other) @@ -247,9 +247,9 @@ LDObject::~LDObject () { // Remove this object from the selection array if it is there. - for (ulong i = 0; i < g_ForgeWindow->sel.size(); ++i) - if (g_ForgeWindow->sel[i] == this) - g_ForgeWindow->sel.erase (g_ForgeWindow->sel.begin() + i); + for (ulong i = 0; i < g_win->sel ().size(); ++i) + if (g_win->sel ()[i] == this) + g_win->sel ().erase (g_win->sel ().begin() + i); } LDComment::~LDComment () {} @@ -302,14 +302,14 @@ vector<LDObject*> objs, cache; // If we have this cached, just clone that - if (bDeepInline && pFile->objCache.size ()) { - for (LDObject* obj : pFile->objCache) + if (bDeepInline && pFile->m_objCache.size ()) { + for (LDObject* obj : pFile->m_objCache) objs.push_back (obj->clone ()); } else { if (!bDeepInline) bCache = false; - for (LDObject* obj : pFile->objects) { + for (LDObject* obj : pFile->m_objs) { // Skip those without schemantic meaning switch (obj->getType ()) { case OBJ_Comment: @@ -353,7 +353,7 @@ } if (bCache) - pFile->objCache = cache; + pFile->m_objCache = cache; } // Transform the objects @@ -371,8 +371,8 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= long LDObject::getIndex (OpenFile* pFile) { - for (ulong i = 0; i < pFile->objects.size(); ++i) - if (pFile->objects[i] == this) + for (ulong i = 0; i < pFile->m_objs.size(); ++i) + if (pFile->m_objs[i] == this) return i; return -1; @@ -390,11 +390,11 @@ for (long i = start; i != end; i += incr) { LDObject* obj = objs[i]; - const long lIndex = obj->getIndex (g_CurrentFile), + const long lIndex = obj->getIndex (g_curfile), lTarget = lIndex + (bUp ? -1 : 1); if ((bUp == true and lIndex == 0) or - (bUp == false and lIndex == (long)(g_CurrentFile->objects.size() - 1))) + (bUp == false and lIndex == (long)(g_curfile->m_objs.size() - 1))) { // One of the objects hit the extrema. If this happens, this should be the first // object to be iterated on. Thus, nothing has changed yet and it's safe to just @@ -403,7 +403,7 @@ return; } - obj->swap (g_CurrentFile->objects[lTarget]); + obj->swap (g_curfile->m_objs[lTarget]); } }
--- a/main.cpp Sat May 04 13:52:47 2013 +0300 +++ b/main.cpp Sat May 04 18:31:03 2013 +0300 @@ -25,14 +25,14 @@ #include "colors.h" #include "types.h" -vector<OpenFile*> g_LoadedFiles; -OpenFile* g_CurrentFile = null; -ForgeWindow* g_ForgeWindow = null; +vector<OpenFile*> g_loadedFiles; +OpenFile* g_curfile = null; +ForgeWindow* g_win = null; bbox g_BBox; -const QApplication* g_qMainApp = null; +const QApplication* g_app = null; -const vertex g_Origin (0.0f, 0.0f, 0.0f); -const matrix g_mIdentity (1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f); +const vertex g_origin (0.0f, 0.0f, 0.0f); +const matrix g_identity (1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f); // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -53,7 +53,7 @@ const QApplication app (dArgc, saArgv); ForgeWindow* win = new ForgeWindow; - g_qMainApp = &app; + g_app = &app; newFile (); @@ -64,70 +64,18 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -// Common code for the two logfs -static void logVA (logtype_e eType, const char* fmt, va_list va) { - return; - - char* sBuffer = vdynformat (fmt, va, 128); - printf ("buffer: %s\n", sBuffer); - str zText (sBuffer); - delete[] sBuffer; - - // Log it to standard output - printf ("%s", zText.chars ()); - - // Replace some things out with HTML entities - zText.replace ("<", "<"); - zText.replace (">", ">"); - zText.replace ("\n", "<br />"); - - str& zLog = g_ForgeWindow->zMessageLogHTML; - - switch (eType) { - case LOG_Normal: - printf ("appending \"%s\"\n", zText.chars ()); - zLog.append (zText); - break; - - case LOG_Error: - zLog.appendformat ("<span style=\"color: #F8F8F8; background-color: #800\"><b>[ERROR]</b> %s</span>", - zText.chars()); - break; - - case LOG_Info: - zLog.appendformat ("<span style=\"color: #04F\"><b>[INFO]</b> %s</span>", - zText.chars()); - break; - - case LOG_Success: - zLog.appendformat ("<span style=\"color: #6A0\"><b>[SUCCESS]</b> %s</span>", - zText.chars()); - break; - - case LOG_Warning: - zLog.appendformat ("<span style=\"color: #C50\"><b>[WARNING]</b> %s</span>", - zText.chars()); - break; - } - - g_ForgeWindow->qMessageLog->setHtml (zLog); -} - -// ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= -void logf (const char* fmt, ...) { +void logf (const char* fmtstr, ...) { va_list va; - va_start (va, fmt); - logVA (LOG_Normal, fmt, va); + va_start (va, fmtstr); + g_win->logVA (LOG_Normal, fmtstr, va); va_end (va); } -void logf (logtype_e eType, const char* fmt, ...) { +void logf (LogType type, const char* fmtstr, ...) { va_list va; - va_start (va, fmt); - logVA (eType, fmt, va); + va_start (va, fmtstr); + g_win->logVA (type, fmtstr, va); va_end (va); }
--- a/types.cpp Sat May 04 13:52:47 2013 +0300 +++ b/types.cpp Sat May 04 18:31:03 2013 +0300 @@ -19,9 +19,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= str vertex::stringRep (const bool mangled) { - const char* fmt = mangled ? "(%s, %s, %s)" : "%s %s %s"; - - return format (fmt, + return format (mangled ? "(%s, %s, %s)" : "%s %s %s", ftoa (coord (X)).chars(), ftoa (coord (Y)).chars(), ftoa (coord (Z)).chars()); @@ -45,48 +43,45 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= matrix::matrix (vector<double> vals) { - assert (vals.size() == (sizeof faValues / sizeof *faValues)); - memcpy (&faValues[0], &(*vals.begin ()), sizeof faValues); + assert (vals.size() == (sizeof m_vals / sizeof *m_vals)); + memcpy (&m_vals[0], &(*vals.begin ()), sizeof m_vals); } // ----------------------------------------------------------------------------- -matrix::matrix (double fVal) { +matrix::matrix (double fillval) { for (short i = 0; i < 9; ++i) - faValues[i] = fVal; + m_vals[i] = fillval; } // ----------------------------------------------------------------------------- matrix::matrix (double a, double b, double c, double d, double e, double f, double g, double h, double i) { - faValues[0] = a; faValues[1] = b; faValues[2] = c; - faValues[3] = d; faValues[4] = e; faValues[5] = f; - faValues[6] = g; faValues[7] = h; faValues[8] = i; + m_vals[0] = a; m_vals[1] = b; m_vals[2] = c; + m_vals[3] = d; m_vals[4] = e; m_vals[5] = f; + m_vals[6] = g; m_vals[7] = h; m_vals[8] = i; } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void matrix::zero () { - memset (&faValues[0], 0, sizeof faValues); + memset (&m_vals[0], 0, sizeof m_vals); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -matrix matrix::mult (matrix mOther) { - matrix mVal; - matrix& mThis = *this; +matrix matrix::mult (matrix other) { + matrix val; + val.zero (); - mVal.zero (); - - // arrrrrrrrrrrgh for (short i = 0; i < 3; ++i) for (short j = 0; j < 3; ++j) for (short k = 0; k < 3; ++k) - mVal[(i * 3) + j] += mThis[(i * 3) + k] * mOther[(k * 3) + j]; + val[(i * 3) + j] += m_vals[(i * 3) + k] * other[(k * 3) + j]; - return mVal; + return val; } // ============================================================================= @@ -95,7 +90,7 @@ void matrix::testOutput () { for (short i = 0; i < 3; ++i) { for (short j = 0; j < 3; ++j) - printf ("%*f\t", 10, faValues[(i * 3) + j]); + printf ("%*f\t", 10, m_vals[(i * 3) + j]); printf ("\n"); } @@ -110,7 +105,7 @@ if (i > 0) val += ' '; - val.appendformat ("%s", ftoa (faValues[i]).chars()); + val.appendformat ("%s", ftoa (m_vals[i]).chars()); } return val;
--- a/types.h Sat May 04 13:52:47 2013 +0300 +++ b/types.h Sat May 04 18:31:03 2013 +0300 @@ -48,8 +48,8 @@ // ============================================================================= // vertex // -// Vertex class. Not to be confused with LDVertex, which is a vertex used in an -// LDraw code file. +// Vertex class, contains a single point in 3D space. Not to be confused with +// LDVertex, which is a vertex used in an LDraw part file. // ============================================================================= class vertex { public: @@ -105,8 +105,6 @@ return coord (n); } - // ========================================================================= - // Midpoint between this vertex and another vertex. vertex midpoint (vertex& other); str stringRep (const bool mangled); void transform (matrix mMatrix, vertex pos); @@ -121,12 +119,10 @@ // ============================================================================= class matrix { public: - double faValues[9]; - // Constructors matrix () {} matrix (std::vector<double> vals); - matrix (double fVal); + matrix (double fillval); matrix (double a, double b, double c, double d, double e, double f, double g, double h, double i); @@ -134,7 +130,7 @@ matrix mult (matrix mOther); matrix& operator= (matrix mOther) { - memcpy (&faValues[0], &mOther.faValues[0], sizeof faValues); + memcpy (&m_vals[0], &mOther.m_vals[0], sizeof m_vals); return *this; } @@ -143,12 +139,15 @@ } inline double& operator[] (const uint uIndex) { - return faValues[uIndex]; + return m_vals[uIndex]; } void zero (); void testOutput (); str stringRep (); + +private: + double m_vals[9]; }; #endif // TYPES_H \ No newline at end of file
--- a/zz_aboutDialog.cpp Sat May 04 13:52:47 2013 +0300 +++ b/zz_aboutDialog.cpp Sat May 04 18:31:03 2013 +0300 @@ -67,7 +67,7 @@ layout->addWidget (memorial); // Align everything to the center. - for (QLabel* label : {icon, title, info, memorial}) + for (QLabel* label : vector<QLabel*> ({icon, title, info, memorial})) label->setAlignment (Qt::AlignCenter); mainTab->setLayout (layout); @@ -136,12 +136,11 @@ } QDialogButtonBox* buttons = new QDialogButtonBox (QDialogButtonBox::Close); + QPushButton* helpButton = new QPushButton; - QPushButton* helpButton = new QPushButton; helpButton->setText ("Mail Author"); helpButton->setIcon (getIcon ("mail")); - - buttons->addButton (dynamic_cast<QAbstractButton*> (helpButton), QDialogButtonBox::HelpRole); + buttons->addButton (static_cast<QAbstractButton*> (helpButton), QDialogButtonBox::HelpRole); connect (buttons, SIGNAL (helpRequested ()), this, SLOT (slot_mail ())); connect (buttons, SIGNAL (rejected ()), this, SLOT (reject ()));
--- a/zz_addObjectDialog.cpp Sat May 04 13:52:47 2013 +0300 +++ b/zz_addObjectDialog.cpp Sat May 04 18:31:03 2013 +0300 @@ -423,7 +423,7 @@ pRad->dSegments = min<short> (dlg.sb_radSegments->value (), pRad->dDivisions); pRad->eRadialType = (LDRadial::Type) dlg.rb_radType->value (); pRad->dRingNum = dlg.sb_radRingNum->value (); - pRad->mMatrix = g_mIdentity; + pRad->mMatrix = g_identity; } break; @@ -440,7 +440,7 @@ ref->vPosition[ax] = dlg.dsb_coords[ax]->value (); ref->zFileName = name; - ref->mMatrix = g_mIdentity; + ref->mMatrix = g_identity; ref->pFile = loadSubfile (name); } break; @@ -450,12 +450,12 @@ } if (newObject) { - ulong idx = g_ForgeWindow->getInsertionPoint (); - g_CurrentFile->insertObj (idx, obj); + ulong idx = g_win->getInsertionPoint (); + g_curfile->insertObj (idx, obj); History::addEntry (new AddHistory ({(ulong) idx}, {obj->clone ()})); } else { - History::addEntry (new EditHistory ({(ulong) obj->getIndex (g_CurrentFile)}, {backup}, {obj->clone ()})); + History::addEntry (new EditHistory ({(ulong) obj->getIndex (g_curfile)}, {backup}, {obj->clone ()})); } - g_ForgeWindow->refresh (); + g_win->refresh (); } \ No newline at end of file
--- a/zz_addObjectDialog.h Sat May 04 13:52:47 2013 +0300 +++ b/zz_addObjectDialog.h Sat May 04 18:31:03 2013 +0300 @@ -40,7 +40,7 @@ QLabel* lb_typeIcon; - // -- COMMENT -- + // Comment line edit QLineEdit* le_comment; // Coordinate edits for.. anything with coordinates, really.
--- a/zz_colorSelectDialog.cpp Sat May 04 13:52:47 2013 +0300 +++ b/zz_colorSelectDialog.cpp Sat May 04 18:31:03 2013 +0300 @@ -43,14 +43,14 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -ColorSelectDialog::ColorSelectDialog (short dDefault, QWidget* parent) : QDialog (parent) { +ColorSelectDialog::ColorSelectDialog (short int defval, QWidget* parent) : QDialog (parent) { // Remove the default color if it's invalid - if (!getColor (dDefault)) - dDefault = -1; + if (!getColor (defval)) + defval = -1; gs_scene = new QGraphicsScene; gv_view = new QGraphicsView (gs_scene); - selColor = dDefault; + selColor = defval; // not really an icon but eh gs_scene->setBackgroundBrush (getIcon ("checkerboard")); @@ -72,8 +72,8 @@ // If we have a default color selected, scroll down so that it is visible. // TODO: find a better way to do this - if (dDefault >= ((g_dNumColumns * g_dNumRows) - 2)) { - ulong ulNewY = ((dDefault / g_dNumColumns) - 3) * g_dSquareSize; + if (defval >= ((g_dNumColumns * g_dNumRows) - 2)) { + ulong ulNewY = ((defval / g_dNumColumns) - 3) * g_dSquareSize; gv_view->verticalScrollBar ()->setSliderPosition (ulNewY); } @@ -108,25 +108,24 @@ const double y = (i / g_dNumColumns) * g_dSquareSize; const double w = (g_dSquareSize) - (fPenWidth / 2); - QColor qColor = meta->qColor; + QColor col = meta->qColor; if (i == maincolor) { // Use the user preferences for main color here - qColor = gl_maincolor.value.chars (); - qColor.setAlpha (gl_maincolor_alpha * 255.0f); + col = gl_maincolor.value.chars (); + col.setAlpha (gl_maincolor_alpha * 255.0f); } - bool dark = (luma (qColor) < 80); + bool dark = (luma (col) < 80); - gs_scene->addRect (x, y, w, w, qPen, qColor); + gs_scene->addRect (x, y, w, w, qPen, col); QGraphicsTextItem* qText = gs_scene->addText (format ("%lu", i).chars()); qText->setDefaultTextColor ((dark) ? Qt::white : Qt::black); qText->setPos (x, y); if (i == selColor) { - QGraphicsPixmapItem* qCursorPic; - qCursorPic = gs_scene->addPixmap (getIcon ("colorcursor")); - qCursorPic->setPos (x, y); + auto curspic = gs_scene->addPixmap (getIcon ("colorcursor")); + curspic->setPos (x, y); } } } @@ -168,8 +167,8 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -bool ColorSelectDialog::staticDialog (short& dValue, short dDefault, QWidget* parent) { - ColorSelectDialog dlg (dDefault, parent); +bool ColorSelectDialog::staticDialog (short int& dValue, short int defval, QWidget* parent) { + ColorSelectDialog dlg (defval, parent); if (dlg.exec () && dlg.selColor != -1) { dValue = dlg.selColor;
--- a/zz_colorSelectDialog.h Sat May 04 13:52:47 2013 +0300 +++ b/zz_colorSelectDialog.h Sat May 04 18:31:03 2013 +0300 @@ -29,8 +29,8 @@ Q_OBJECT public: - explicit ColorSelectDialog (short dDefault = -1, QWidget* parent = null); - static bool staticDialog (short& dValue, short dDefault = -1, QWidget* parent = null); + explicit ColorSelectDialog (short defval = -1, QWidget* parent = null); + static bool staticDialog (short& val, short defval = -1, QWidget* parent = null); QGraphicsScene* gs_scene; QGraphicsView* gv_view;
--- a/zz_configDialog.cpp Sat May 04 13:52:47 2013 +0300 +++ b/zz_configDialog.cpp Sat May 04 18:31:03 2013 +0300 @@ -613,7 +613,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ConfigDialog::staticDialog () { - ConfigDialog dlg (g_ForgeWindow); + ConfigDialog dlg (g_win); if (dlg.exec ()) { io_ldpath = dlg.le_LDrawPath->text(); @@ -629,7 +629,7 @@ gui_toolbar_iconsize = (dlg.sl_iconSize->value () * 4) + 12; // Manage the quick color toolbar - g_ForgeWindow->quickColorMeta = dlg.quickColorMeta; + g_win->setQuickColorMeta (dlg.quickColorMeta); gui_colortoolbar = dlg.makeColorToolBarString (); // Set the grid settings @@ -643,9 +643,9 @@ // Reload all subfiles reloadAllSubfiles (); - g_ForgeWindow->R->setBackground (); - g_ForgeWindow->refresh (); - g_ForgeWindow->updateToolBars (); + g_win->R ()->setBackground (); + g_win->refresh (); + g_win->updateToolBars (); } }
--- a/zz_historyDialog.cpp Sat May 04 13:52:47 2013 +0300 +++ b/zz_historyDialog.cpp Sat May 04 18:31:03 2013 +0300 @@ -79,7 +79,7 @@ qItem->setIcon (getIcon ("empty")); historyList->addItem (qItem); - for (HistoryEntry* entry : History::entries) { + for (HistoryEntry* entry : History::entries ()) { str zText; QIcon qEntryIcon;
--- a/zz_newPartDialog.cpp Sat May 04 13:52:47 2013 +0300 +++ b/zz_newPartDialog.cpp Sat May 04 18:31:03 2013 +0300 @@ -84,13 +84,13 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void NewPartDialog::StaticDialog () { - NewPartDialog dlg (g_ForgeWindow); + NewPartDialog dlg (g_win); if (dlg.exec ()) { newFile (); short idx; str zAuthor = dlg.le_author->text (); - vector<LDObject*>& objs = g_CurrentFile->objects; + vector<LDObject*>& objs = g_curfile->m_objs; idx = dlg.rb_BFC->value (); const LDBFC::Type eBFCType = @@ -116,6 +116,6 @@ objs.push_back (new LDBFC (eBFCType)); objs.push_back (new LDEmpty); - g_ForgeWindow->refresh (); + g_win->refresh (); } } \ No newline at end of file
--- a/zz_setContentsDialog.cpp Sat May 04 13:52:47 2013 +0300 +++ b/zz_setContentsDialog.cpp Sat May 04 18:31:03 2013 +0300 @@ -86,7 +86,7 @@ if (!obj) return; - SetContentsDialog dlg (obj, g_ForgeWindow); + SetContentsDialog dlg (obj, g_win); if (dlg.exec () == false) return; @@ -97,11 +97,11 @@ // Mark down the history now before we perform the replacement (which // destroys the old object) - History::addEntry (new EditHistory ({(ulong) oldobj->getIndex (g_CurrentFile)}, + History::addEntry (new EditHistory ({(ulong) oldobj->getIndex (g_curfile)}, {oldobj->clone ()}, {obj->clone ()})); oldobj->replace (obj); // Rebuild stuff after this - g_ForgeWindow->refresh (); + g_win->refresh (); } \ No newline at end of file