# HG changeset patch # User Santeri Piippo # Date 1368916273 -10800 # Node ID 1f368f0a323b49ec6e4ca9b99dd05edfec50d56a # Parent 70eb948a2b028178bca93f4d15e058565e746f4f Added auto-coloring, this colors objects with the first found unused color diff -r 70eb948a2b02 -r 1f368f0a323b src/file.h --- 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::iterator it; + typedef std::vector::const_iterator c_it; + str m_filename, m_title; vector m_objs; vector 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. diff -r 70eb948a2b02 -r 1f368f0a323b src/gui.cpp --- 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"); diff -r 70eb948a2b02 -r 1f368f0a323b src/gui_editactions.cpp --- 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 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 indices; + vector 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 diff -r 70eb948a2b02 -r 1f368f0a323b src/history.cpp --- 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 ();