void ChangeColorCommand::onExecute(Context* context) { ColorBar* colorbar = ColorBar::instance(); app::Color color = m_background ? colorbar->getBgColor(): colorbar->getFgColor(); switch (m_change) { case None: // do nothing break; case IncrementIndex: if (color.getType() == app::Color::IndexType) { int index = color.getIndex(); if (index < get_current_palette()->size()-1) color = app::Color::fromIndex(index+1); } else color = app::Color::fromIndex(0); break; case DecrementIndex: if (color.getType() == app::Color::IndexType) { int index = color.getIndex(); if (index > 0) color = app::Color::fromIndex(index-1); } else color = app::Color::fromIndex(0); break; } if (m_background) colorbar->setBgColor(color); else colorbar->setFgColor(color); }
void ChangeColorCommand::onExecute(Context* context) { ColorBar* colorbar = app_get_colorbar(); Color color = m_background ? colorbar->getBgColor(): colorbar->getFgColor(); switch (m_change) { case None: // do nothing break; case IncrementIndex: if (color.getType() == Color::IndexType) { int index = color.getIndex(); if (index < 255) // TODO use sprite palette limit color = Color::fromIndex(index+1); } else color = Color::fromIndex(0); break; case DecrementIndex: if (color.getType() == Color::IndexType) { int index = color.getIndex(); if (index > 0) color = Color::fromIndex(index-1); } else color = Color::fromIndex(0); break; } if (m_background) colorbar->setBgColor(color); else colorbar->setFgColor(color); }
void SwitchColorsCommand::onExecute(Context* context) { ColorBar* colorbar = ColorBar::instance(); app::Color fg = colorbar->getFgColor(); app::Color bg = colorbar->getBgColor(); colorbar->setFgColor(bg); colorbar->setBgColor(fg); }
tools::ToolLoop* create_tool_loop_preview( Editor* editor, Image* image, const gfx::Point& celOrigin) { tools::Tool* current_tool = editor->getCurrentEditorTool(); tools::Ink* current_ink = editor->getCurrentEditorInk(); if (!current_tool || !current_ink) return NULL; Layer* layer = editor->layer(); if (!layer || !layer->isVisible() || !layer->isEditable()) { return nullptr; } // Get fg/bg colors ColorBar* colorbar = ColorBar::instance(); app::Color fg = colorbar->getFgColor(); app::Color bg = colorbar->getBgColor(); if (!fg.isValid() || !bg.isValid()) return nullptr; // Create the new tool loop try { return new PreviewToolLoopImpl( editor, current_tool, current_ink, editor->document(), fg, bg, image, celOrigin); } catch (const std::exception&) { return nullptr; } }
void SwitchColorsCommand::onExecute(Context* context) { ASSERT(current_editor); if (!current_editor) return; tools::Tool* tool = current_editor->getCurrentEditorTool(); if (tool) { const auto& toolPref(Preferences::instance().tool(tool)); if (toolPref.ink() == tools::InkType::SHADING) { App::instance()->contextBar()->reverseShadeColors(); } } ColorBar* colorbar = ColorBar::instance(); app::Color fg = colorbar->getFgColor(); app::Color bg = colorbar->getBgColor(); // Change the background and then the foreground color so the color // spectrum and color wheel shows the foreground color as the // selected one. colorbar->setBgColor(fg); colorbar->setFgColor(bg); }
tools::ToolLoop* create_tool_loop(Editor* editor, Context* context) { tools::Tool* current_tool = editor->getCurrentEditorTool(); tools::Ink* current_ink = editor->getCurrentEditorInk(); if (!current_tool || !current_ink) return NULL; Layer* layer = editor->layer(); if (!layer) { StatusBar::instance()->showTip(1000, "There is no active layer"); return NULL; } // If the active layer is not visible. if (!layer->isVisible()) { StatusBar::instance()->showTip(1000, "Layer '%s' is hidden", layer->name().c_str()); return NULL; } // If the active layer is read-only. else if (!layer->isEditable()) { StatusBar::instance()->showTip(1000, "Layer '%s' is locked", layer->name().c_str()); return NULL; } // Get fg/bg colors ColorBar* colorbar = ColorBar::instance(); app::Color fg = colorbar->getFgColor(); app::Color bg = colorbar->getBgColor(); ASSERT(fg.isValid()); ASSERT(bg.isValid()); if (!fg.isValid() || !bg.isValid()) { Alert::show(PACKAGE "<<The current selected foreground and/or background color" "<<is out of range. Select a valid color in the color-bar." "||&Close"); return NULL; } // Create the new tool loop try { return new ToolLoopImpl( editor, context, current_tool, current_ink, editor->document(), !editor->isSecondaryButton() ? tools::ToolLoop::Left: tools::ToolLoop::Right, fg, bg); } catch (const std::exception& ex) { Alert::show(PACKAGE "<<Error drawing ink:" "<<%s" "||&Close", ex.what()); return NULL; } }