Sun, 19 May 2013 01:31:13 +0300
Added auto-coloring, this colors objects with the first found unused color
src/file.h | file | annotate | diff | comparison | revisions | |
src/gui.cpp | file | annotate | diff | comparison | revisions | |
src/gui_editactions.cpp | file | annotate | diff | comparison | revisions | |
src/history.cpp | file | annotate | diff | comparison | revisions |
--- a/src/file.h Sun May 19 00:47:07 2013 +0300 +++ b/src/file.h Sun May 19 01:31:13 2013 +0300 @@ -40,6 +40,9 @@ // ============================================================================= class OpenFile { public: + typedef std::vector<LDObject*>::iterator it; + typedef std::vector<LDObject*>::const_iterator c_it; + str m_filename, m_title; vector<LDObject*> m_objs; vector<LDObject*> m_objCache; // Cache of this file's contents, if desired @@ -73,6 +76,11 @@ } void insertObj (const ulong pos, LDObject* obj); + + it begin () { return m_objs.begin (); } + it end () { return m_objs.end (); } + c_it cbegin () const { return m_objs.cbegin (); } + c_it cend () const { return m_objs.cend (); } }; // Close all current loaded files and start off blank.
--- a/src/gui.cpp Sun May 19 00:47:07 2013 +0300 +++ b/src/gui.cpp Sun May 19 01:31:13 2013 +0300 @@ -215,16 +215,19 @@ initMenu ("&Tools"); addMenuAction ("setColor"); // Set Color + addMenuAction ("autoColor"); // Auto-color + addMenuAction ("uncolorize"); // Uncolorize + menu->addSeparator (); // ----- addMenuAction ("invert"); // Invert addMenuAction ("inlineContents"); // Inline addMenuAction ("deepInline"); // Deep Inline addMenuAction ("radialResolution"); // Radial Resolution + menu->addSeparator (); // ----- addMenuAction ("splitQuads"); // Split Quads addMenuAction ("setContents"); // Set Contents addMenuAction ("makeBorders"); // Make Borders addMenuAction ("makeCornerVerts"); // Make Corner Vertices addMenuAction ("roundCoords"); // Round Coordinates - addMenuAction ("uncolorize"); // Uncolorize addMenuAction ("visibility"); // Toggle Visibility addMenuAction ("replaceCoords"); // Replace Coordinates addMenuAction ("flip"); // Flip @@ -386,6 +389,8 @@ // ========================================== initSingleToolBar ("Tools"); addToolBarAction ("setColor"); + addToolBarAction ("autoColor"); + addToolBarAction ("uncolorize"); addToolBarAction ("invert"); addToolBarAction ("inlineContents"); addToolBarAction ("deepInline"); @@ -396,7 +401,6 @@ addToolBarAction ("makeCornerVerts"); addToolBarAction ("roundCoords"); addToolBarAction ("screencap"); - addToolBarAction ("uncolorize"); addToolBarAction ("visibility"); addToolBarAction ("replaceCoords"); addToolBarAction ("flip");
--- a/src/gui_editactions.cpp Sun May 19 00:47:07 2013 +0300 +++ b/src/gui_editactions.cpp Sun May 19 01:31:13 2013 +0300 @@ -31,6 +31,7 @@ #include "extprogs.h" #include "gldraw.h" #include "dialogs.h" +#include "colors.h" vector<LDObject*> g_Clipboard; @@ -761,6 +762,7 @@ g_win->fullRefresh (); } +// ========================================================================================================================================= MAKE_ACTION (demote, "Demote conditional lines", "demote", "Demote conditional lines down to normal lines.", (0)) { EditHistory* history = new EditHistory; @@ -780,4 +782,41 @@ History::addEntry (history); g_win->refresh (); +} + +// ========================================================================================================================================= +static bool isColorUsed (short colnum) { + for (LDObject* obj : g_curfile->m_objs) + if (obj->isColored () && obj->color == colnum) + return true; + + return false; +} + +MAKE_ACTION (autoColor, "Auto-color", "auto-color", "Set the color of the given object to the first found unused color.", (0)) { + short colnum = 0; + vector<ulong> indices; + vector<short> colors; + + while (colnum < 512 && (getColor (colnum) == null || isColorUsed (colnum))) + colnum++; + + if (colnum >= 512) { + critical ("Out of unused colors! What are you doing?!"); + return; + } + + for (LDObject* obj : g_win->sel ()) { + if (obj->isColored () == false) + continue; + + indices.push_back (obj->getIndex (g_curfile)); + colors.push_back (obj->color); + + obj->color = colnum; + g_win->R ()->compileObject (obj); + } + + History::addEntry (new SetColorHistory (indices, colors, colnum)); + g_win->refresh (); } \ No newline at end of file
--- a/src/history.cpp Sun May 19 00:47:07 2013 +0300 +++ b/src/history.cpp Sun May 19 01:31:13 2013 +0300 @@ -77,8 +77,14 @@ // ========================================================================= void updateActions () { +#ifndef RELEASE ACTION (undo)->setEnabled (s_pos > -1); ACTION (redo)->setEnabled (s_pos < (long) s_entries.size () - 1); +#else + // These are kinda unstable so they're disabled for release builds + ACTION (undo)->setEnabled (false); + ACTION (redo)->setEnabled (false); +#endif // RELEASE // Update the window title as well g_win->setTitle ();