diff --git a/src/app/ui/color_bar.cpp b/src/app/ui/color_bar.cpp index 505675166..4224fb310 100644 --- a/src/app/ui/color_bar.cpp +++ b/src/app/ui/color_bar.cpp @@ -202,14 +202,13 @@ void ColorBar::onPaletteButtonDropDownClick() } } -void ColorBar::onPaletteIndexChange(int index) +void ColorBar::onPaletteIndexChange(PaletteIndexChangeEvent& ev) { m_lock = true; - app::Color color = app::Color::fromIndex(index); + app::Color color = app::Color::fromIndex(ev.index()); - // TODO create a PaletteChangeEvent and take left/right mouse button from there - if ((jmouse_b(0) & kButtonRight) == kButtonRight) + if ((ev.buttons() & kButtonRight) == kButtonRight) setBgColor(color); else setFgColor(color); diff --git a/src/app/ui/color_bar.h b/src/app/ui/color_bar.h index 6ace9f835..7238d903a 100644 --- a/src/app/ui/color_bar.h +++ b/src/app/ui/color_bar.h @@ -35,6 +35,7 @@ namespace app { class ColorButton; class PalettesLoader; + class PaletteIndexChangeEvent; class ColorBar : public ui::Box { static ColorBar* m_instance; @@ -64,7 +65,7 @@ namespace app { protected: void onPaletteButtonClick(); void onPaletteButtonDropDownClick(); - void onPaletteIndexChange(int index); + void onPaletteIndexChange(PaletteIndexChangeEvent& ev); void onFgColorButtonChange(const app::Color& color); void onBgColorButtonChange(const app::Color& color); void onColorButtonChange(const app::Color& color); diff --git a/src/app/ui/color_selector.cpp b/src/app/ui/color_selector.cpp index 973202edb..9f509bab2 100644 --- a/src/app/ui/color_selector.cpp +++ b/src/app/ui/color_selector.cpp @@ -172,9 +172,9 @@ app::Color ColorSelector::getColor() const return m_color; } -void ColorSelector::onColorPaletteIndexChange(int index) +void ColorSelector::onColorPaletteIndexChange(PaletteIndexChangeEvent& ev) { - setColorWithSignal(app::Color::fromIndex(index)); + setColorWithSignal(app::Color::fromIndex(ev.index())); } void ColorSelector::onColorSlidersChange(ColorSlidersChangeEvent& ev) diff --git a/src/app/ui/color_selector.h b/src/app/ui/color_selector.h index e3fee262f..e35947e48 100644 --- a/src/app/ui/color_selector.h +++ b/src/app/ui/color_selector.h @@ -34,6 +34,7 @@ #include "ui/view.h" namespace app { + class PaletteIndexChangeEvent; class ColorSelector : public PopupWindowPin { public: @@ -52,7 +53,7 @@ namespace app { Signal1 ColorChange; protected: - void onColorPaletteIndexChange(int index); + void onColorPaletteIndexChange(PaletteIndexChangeEvent& ev);; void onColorSlidersChange(ColorSlidersChangeEvent& ev); void onColorHexEntryChange(const app::Color& color); void onColorTypeButtonClick(ui::Event& ev); diff --git a/src/app/ui/palette_view.cpp b/src/app/ui/palette_view.cpp index e2a929373..d769b19e4 100644 --- a/src/app/ui/palette_view.cpp +++ b/src/app/ui/palette_view.cpp @@ -238,7 +238,8 @@ bool PaletteView::onProcessMessage(Message* msg) selectColor(idx); // Emit signal - IndexChange(idx); + PaletteIndexChangeEvent ev(this, idx, mouseMsg->buttons()); + IndexChange(ev); } } diff --git a/src/app/ui/palette_view.h b/src/app/ui/palette_view.h index 950e570f4..1c4ec6f2b 100644 --- a/src/app/ui/palette_view.h +++ b/src/app/ui/palette_view.h @@ -22,12 +22,29 @@ #include "base/connection.h" #include "base/signal.h" +#include "ui/event.h" +#include "ui/mouse_buttons.h" #include "ui/widget.h" #include namespace app { + class PaletteIndexChangeEvent : public ui::Event { + public: + PaletteIndexChangeEvent(ui::Widget* source, int index, ui::MouseButtons buttons) + : Event(source) + , m_index(index) + , m_buttons(buttons) { } + + int index() const { return m_index; } + ui::MouseButtons buttons() const { return m_buttons; } + + private: + int m_index; + ui::MouseButtons m_buttons; + }; + class PaletteView : public ui::Widget { public: typedef std::vector SelectedEntries; @@ -49,7 +66,7 @@ namespace app { app::Color getColorByPosition(int x, int y); // Signals - Signal1 IndexChange; + Signal1 IndexChange; protected: bool onProcessMessage(ui::Message* msg) override;