Add PaletteIndexChangeEvent for PaletteView::IndexChange event

This was added to avoid deprecated jmouse_b(0) function
in ColorBar::onPaletteIndexChange().
This commit is contained in:
David Capello 2014-11-25 21:51:06 -03:00
parent a35c32dcfe
commit 0a7bbfba6b
6 changed files with 29 additions and 10 deletions

View File

@ -202,14 +202,13 @@ void ColorBar::onPaletteButtonDropDownClick()
} }
} }
void ColorBar::onPaletteIndexChange(int index) void ColorBar::onPaletteIndexChange(PaletteIndexChangeEvent& ev)
{ {
m_lock = true; 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 ((ev.buttons() & kButtonRight) == kButtonRight)
if ((jmouse_b(0) & kButtonRight) == kButtonRight)
setBgColor(color); setBgColor(color);
else else
setFgColor(color); setFgColor(color);

View File

@ -35,6 +35,7 @@
namespace app { namespace app {
class ColorButton; class ColorButton;
class PalettesLoader; class PalettesLoader;
class PaletteIndexChangeEvent;
class ColorBar : public ui::Box { class ColorBar : public ui::Box {
static ColorBar* m_instance; static ColorBar* m_instance;
@ -64,7 +65,7 @@ namespace app {
protected: protected:
void onPaletteButtonClick(); void onPaletteButtonClick();
void onPaletteButtonDropDownClick(); void onPaletteButtonDropDownClick();
void onPaletteIndexChange(int index); void onPaletteIndexChange(PaletteIndexChangeEvent& ev);
void onFgColorButtonChange(const app::Color& color); void onFgColorButtonChange(const app::Color& color);
void onBgColorButtonChange(const app::Color& color); void onBgColorButtonChange(const app::Color& color);
void onColorButtonChange(const app::Color& color); void onColorButtonChange(const app::Color& color);

View File

@ -172,9 +172,9 @@ app::Color ColorSelector::getColor() const
return m_color; 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) void ColorSelector::onColorSlidersChange(ColorSlidersChangeEvent& ev)

View File

@ -34,6 +34,7 @@
#include "ui/view.h" #include "ui/view.h"
namespace app { namespace app {
class PaletteIndexChangeEvent;
class ColorSelector : public PopupWindowPin { class ColorSelector : public PopupWindowPin {
public: public:
@ -52,7 +53,7 @@ namespace app {
Signal1<void, const app::Color&> ColorChange; Signal1<void, const app::Color&> ColorChange;
protected: protected:
void onColorPaletteIndexChange(int index); void onColorPaletteIndexChange(PaletteIndexChangeEvent& ev);;
void onColorSlidersChange(ColorSlidersChangeEvent& ev); void onColorSlidersChange(ColorSlidersChangeEvent& ev);
void onColorHexEntryChange(const app::Color& color); void onColorHexEntryChange(const app::Color& color);
void onColorTypeButtonClick(ui::Event& ev); void onColorTypeButtonClick(ui::Event& ev);

View File

@ -238,7 +238,8 @@ bool PaletteView::onProcessMessage(Message* msg)
selectColor(idx); selectColor(idx);
// Emit signal // Emit signal
IndexChange(idx); PaletteIndexChangeEvent ev(this, idx, mouseMsg->buttons());
IndexChange(ev);
} }
} }

View File

@ -22,12 +22,29 @@
#include "base/connection.h" #include "base/connection.h"
#include "base/signal.h" #include "base/signal.h"
#include "ui/event.h"
#include "ui/mouse_buttons.h"
#include "ui/widget.h" #include "ui/widget.h"
#include <vector> #include <vector>
namespace app { 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 { class PaletteView : public ui::Widget {
public: public:
typedef std::vector<bool> SelectedEntries; typedef std::vector<bool> SelectedEntries;
@ -49,7 +66,7 @@ namespace app {
app::Color getColorByPosition(int x, int y); app::Color getColorByPosition(int x, int y);
// Signals // Signals
Signal1<void, int> IndexChange; Signal1<void, PaletteIndexChangeEvent&> IndexChange;
protected: protected:
bool onProcessMessage(ui::Message* msg) override; bool onProcessMessage(ui::Message* msg) override;