Skip to content

Commit

Permalink
Fix issue 188: Pick foreground color with right mouse button
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Aug 19, 2014
1 parent d0a7831 commit 9a15126
Show file tree
Hide file tree
Showing 16 changed files with 251 additions and 140 deletions.
18 changes: 11 additions & 7 deletions data/widgets/options.xml
Expand Up @@ -17,23 +17,27 @@
<panel id="panel">
<vbox id="section_general">
<separator text="General" horizontal="true" />
<grid columns="2">
<hbox>
<label text="Screen Scale:" />
<combobox id="screen_scale" expansive="true" />
</grid>
<check text="Zoom with Scroll Wheel" id="wheel_zoom" />
<combobox id="screen_scale" />
</hbox>
<check text="Show timeline automatically" id="autotimeline" tooltip="Show the timeline automatically&#10;when a new frame or layer is added." />
</vbox>

<!-- Editor -->
<vbox id="section_editor">
<separator text="Editor" horizontal="true" />
<check text="Zoom with Scroll Wheel" id="wheel_zoom" />
<check text="Smooth auto-scroll" id="smooth" />
<check text="Show scroll-bars in sprite editor" id="show_scrollbars" tooltip="Show scroll-bars in all sprite editors." />
<grid columns="2">
<label text="Cursor:" />
<hbox>
<label text="Right-click:" />
<combobox id="right_click_behavior" expansive="true" />
</hbox>
<hbox>
<label text="Cursor Color:" />
<box id="cursor_color_box" /><!-- custom widget -->
</grid>
</hbox>
</vbox>

<!-- Grid & background -->
Expand Down
7 changes: 7 additions & 0 deletions src/app/commands/cmd_options.cpp
Expand Up @@ -87,6 +87,12 @@ class OptionsWindow : public app::gen::Options {
screenScale()->addItem("4:1");
screenScale()->setSelectedItemIndex(get_screen_scaling()-1);

// Right-click
rightClickBehavior()->addItem("Paint with background color");
rightClickBehavior()->addItem("Pick foreground color");
rightClickBehavior()->addItem("Erase");
rightClickBehavior()->setSelectedItemIndex((int)m_settings->getRightClickMode());

// Zoom with Scroll Wheel
wheelZoom()->setSelected(m_settings->getZoomWithScrollWheel());

Expand Down Expand Up @@ -135,6 +141,7 @@ class OptionsWindow : public app::gen::Options {

m_settings->setShowSpriteEditorScrollbars(showScrollbars()->isSelected());
m_settings->setZoomWithScrollWheel(wheelZoom()->isSelected());
m_settings->setRightClickMode(static_cast<RightClickMode>(rightClickBehavior()->getSelectedItemIndex()));

RenderEngine::setCheckedBgType((RenderEngine::CheckedBgType)checkedBgSize()->getSelectedItemIndex());
RenderEngine::setCheckedBgZoom(checkedBgZoom()->isSelected());
Expand Down
3 changes: 3 additions & 0 deletions src/app/settings/settings.h
Expand Up @@ -25,6 +25,7 @@
#include "app/settings/ink_type.h"
#include "app/settings/rotation_algorithm.h"
#include "app/settings/selection_mode.h"
#include "app/settings/right_click_mode.h"
#include "doc/settings.h"
#include "gfx/point.h"
#include "gfx/rect.h"
Expand Down Expand Up @@ -62,6 +63,7 @@ namespace app {
// General settings
virtual bool getZoomWithScrollWheel() = 0;
virtual bool getShowSpriteEditorScrollbars() = 0;
virtual RightClickMode getRightClickMode() = 0;
virtual bool getGrabAlpha() = 0;
virtual app::Color getFgColor() = 0;
virtual app::Color getBgColor() = 0;
Expand All @@ -70,6 +72,7 @@ namespace app {

virtual void setZoomWithScrollWheel(bool state) = 0;
virtual void setShowSpriteEditorScrollbars(bool state) = 0;
virtual void setRightClickMode(RightClickMode mode) = 0;
virtual void setGrabAlpha(bool state) = 0;
virtual void setFgColor(const app::Color& color) = 0;
virtual void setBgColor(const app::Color& color) = 0;
Expand Down
13 changes: 13 additions & 0 deletions src/app/settings/ui_settings_impl.cpp
Expand Up @@ -216,6 +216,8 @@ UISettingsImpl::UISettingsImpl()
, m_zoomWithScrollWheel(get_config_bool("Options", "ZoomWithMouseWheel", true))
, m_showSpriteEditorScrollbars(get_config_bool("Options", "ShowScrollbars", true))
, m_grabAlpha(get_config_bool("Options", "GrabAlpha", false))
, m_rightClickMode(static_cast<RightClickMode>(get_config_int("Options", "RightClickMode",
static_cast<int>(RightClickMode::Default))))
{
m_colorSwatches = new app::ColorSwatches("Default");
for (size_t i=0; i<16; ++i)
Expand All @@ -229,6 +231,7 @@ UISettingsImpl::~UISettingsImpl()
set_config_bool("Options", "ZoomWithMouseWheel", m_zoomWithScrollWheel);
set_config_bool("Options", "ShowScrollbars", m_showSpriteEditorScrollbars);
set_config_bool("Options", "GrabAlpha", m_grabAlpha);
set_config_int("Options", "RightClickMode", static_cast<int>(m_rightClickMode));

// Delete all tool settings.
for (std::map<std::string, IToolSettings*>::iterator
Expand Down Expand Up @@ -277,6 +280,11 @@ bool UISettingsImpl::getShowSpriteEditorScrollbars()
return m_showSpriteEditorScrollbars;
}

RightClickMode UISettingsImpl::getRightClickMode()
{
return m_rightClickMode;
}

bool UISettingsImpl::getGrabAlpha()
{
return m_grabAlpha;
Expand Down Expand Up @@ -317,6 +325,11 @@ void UISettingsImpl::setShowSpriteEditorScrollbars(bool state)
notifyObservers<bool>(&GlobalSettingsObserver::onSetShowSpriteEditorScrollbars, state);
}

void UISettingsImpl::setRightClickMode(RightClickMode mode)
{
m_rightClickMode = mode;
}

void UISettingsImpl::setGrabAlpha(bool state)
{
m_grabAlpha = state;
Expand Down
3 changes: 3 additions & 0 deletions src/app/settings/ui_settings_impl.h
Expand Up @@ -49,6 +49,7 @@ namespace app {
// ISettings implementation
bool getZoomWithScrollWheel() override;
bool getShowSpriteEditorScrollbars() override;
RightClickMode getRightClickMode() override;
bool getGrabAlpha() override;
app::Color getFgColor() override;
app::Color getBgColor() override;
Expand All @@ -57,6 +58,7 @@ namespace app {

void setZoomWithScrollWheel(bool state) override;
void setShowSpriteEditorScrollbars(bool state) override;
void setRightClickMode(RightClickMode mode) override;
void setGrabAlpha(bool state) override;
void setFgColor(const app::Color& color) override;
void setBgColor(const app::Color& color) override;
Expand Down Expand Up @@ -93,6 +95,7 @@ namespace app {
bool m_zoomWithScrollWheel;
bool m_showSpriteEditorScrollbars;
bool m_grabAlpha;
RightClickMode m_rightClickMode;
};

} // namespace app
Expand Down
3 changes: 3 additions & 0 deletions src/app/tools/ink.h
Expand Up @@ -46,6 +46,9 @@ namespace app {
// is a effect so the Editor can display the cursor bounds)
virtual bool isEffect() const { return false; }

// Returns true if this ink acts like an eraser
virtual bool isEraser() const { return false; }

// Returns true if this ink picks colors from the image
virtual bool isEyedropper() const { return false; }

Expand Down
1 change: 1 addition & 0 deletions src/app/tools/inks.h
Expand Up @@ -173,6 +173,7 @@ class EraserInk : public Ink {

bool isPaint() const { return true; }
bool isEffect() const { return true; }
bool isEraser() const { return true; }

void prepareInk(ToolLoop* loop)
{
Expand Down
2 changes: 2 additions & 0 deletions src/app/tools/tool_box.cpp
Expand Up @@ -51,6 +51,8 @@ namespace tools {
using namespace gfx;

const char* WellKnownTools::RectangularMarquee = "rectangular_marquee";
const char* WellKnownTools::Eraser = "eraser";
const char* WellKnownTools::Eyedropper = "eyedropper";

const char* WellKnownInks::Selection = "selection";
const char* WellKnownInks::Paint = "paint";
Expand Down
2 changes: 2 additions & 0 deletions src/app/tools/tool_box.h
Expand Up @@ -33,6 +33,8 @@ namespace app {

namespace WellKnownTools {
extern const char* RectangularMarquee;
extern const char* Eraser;
extern const char* Eyedropper;
};

namespace WellKnownInks {
Expand Down
41 changes: 17 additions & 24 deletions src/app/ui/editor/cursor.cpp
Expand Up @@ -85,7 +85,7 @@ static int saved_pixel_n;
static gfx::Region clipping_region;
static gfx::Region old_clipping_region;

static void generate_cursor_boundaries();
static void generate_cursor_boundaries(Editor* editor);

static void trace_thincross_pixels(ui::Graphics* g, Editor* editor, int x, int y, gfx::Color color, Editor::PixelDelegate pixel);
static void trace_thickcross_pixels(ui::Graphics* g, Editor* editor, int x, int y, gfx::Color color, int thickness, Editor::PixelDelegate pixel);
Expand Down Expand Up @@ -156,16 +156,13 @@ static void on_brush_after_change()
}
}

static Brush* editor_get_current_brush()
static Brush* editor_get_current_brush(Editor* editor)
{
// Create the current brush from settings
tools::Tool* current_tool = UIContext::instance()
->settings()
->getCurrentTool();

tools::Tool* tool = editor->getCurrentEditorTool();
IBrushSettings* brush_settings = UIContext::instance()
->settings()
->getToolSettings(current_tool)
->getToolSettings(tool)
->getBrush();

ASSERT(brush_settings != NULL);
Expand Down Expand Up @@ -235,22 +232,20 @@ void Editor::drawBrushPreview(int x, int y, bool refresh)
screenToEditor(x, y, &x, &y);

// Get the current tool
tools::Tool* current_tool = UIContext::instance()
->settings()
->getCurrentTool();
tools::Tool* tool = getCurrentEditorTool();
tools::Ink* ink = getCurrentEditorInk();

// Setup the cursor type debrushding of several factors (current tool,
// foreground color, and layer transparency).
color_t brush_color = get_brush_color(m_sprite, m_layer);
color_t mask_color = m_sprite->transparentColor();

if (current_tool->getInk(0)->isSelection() ||
current_tool->getInk(0)->isSlice()) {
if (ink->isSelection() || ink->isSlice()) {
cursor_type = CURSOR_THICKCROSS;
}
else if (
// Use cursor bounds for inks that are effects (eraser, blur, etc.)
(current_tool->getInk(0)->isEffect()) ||
(ink->isEffect()) ||
// or when the brush color is transparent and we are not in the background layer
(m_layer && !m_layer->isBackground() &&
brush_color == mask_color)) {
Expand All @@ -262,15 +257,15 @@ void Editor::drawBrushPreview(int x, int y, bool refresh)

// For cursor type 'bounds' we have to generate cursor boundaries
if (cursor_type & CURSOR_BRUSHBOUNDS)
generate_cursor_boundaries();
generate_cursor_boundaries(this);

// Draw pixel/brush preview
if (cursor_type & CURSOR_THINCROSS && m_state->requireBrushPreview()) {
IToolSettings* tool_settings = UIContext::instance()
->settings()
->getToolSettings(current_tool);
->getToolSettings(tool);

Brush* brush = editor_get_current_brush();
Brush* brush = editor_get_current_brush(this);
gfx::Rect brushBounds = brush->bounds();

// Create the extra cel to show the brush preview
Expand Down Expand Up @@ -342,7 +337,7 @@ void Editor::moveBrushPreview(int x, int y, bool refresh)
}

if (cursor_type & CURSOR_THINCROSS && m_state->requireBrushPreview()) {
Brush* brush = editor_get_current_brush();
Brush* brush = editor_get_current_brush(this);
gfx::Rect brushBounds = brush->bounds();
gfx::Rect rc1(old_x+brushBounds.x, old_y+brushBounds.y, brushBounds.w, brushBounds.h);
gfx::Rect rc2(new_x+brushBounds.x, new_y+brushBounds.y, brushBounds.w, brushBounds.h);
Expand Down Expand Up @@ -392,7 +387,7 @@ void Editor::clearBrushPreview(bool refresh)

// Clean pixel/brush preview
if (cursor_type & CURSOR_THINCROSS && m_state->requireBrushPreview()) {
Brush* brush = editor_get_current_brush();
Brush* brush = editor_get_current_brush(this);
gfx::Rect brushBounds = brush->bounds();

m_document->prepareExtraCel(x+brushBounds.x, y+brushBounds.y,
Expand Down Expand Up @@ -424,17 +419,15 @@ bool Editor::doesBrushPreviewNeedSubpixel()

//////////////////////////////////////////////////////////////////////

static void generate_cursor_boundaries()
static void generate_cursor_boundaries(Editor* editor)
{
tools::Tool* current_tool = UIContext::instance()
->settings()
->getCurrentTool();
tools::Tool* tool = editor->getCurrentEditorTool();

IBrushSettings* brush_settings = NULL;
if (current_tool)
if (tool)
brush_settings = UIContext::instance()
->settings()
->getToolSettings(current_tool)
->getToolSettings(tool)
->getBrush();

if (cursor_bound.seg == NULL ||
Expand Down

0 comments on commit 9a15126

Please sign in to comment.