diff --git a/src/app/script/dialog_class.cpp b/src/app/script/dialog_class.cpp index 5a4e65f27..66c40722f 100644 --- a/src/app/script/dialog_class.cpp +++ b/src/app/script/dialog_class.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2019 Igara Studio S.A. +// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018 David Capello // // This program is distributed under the terms of @@ -103,11 +103,11 @@ struct Dialog { }; -template void Dialog_connect_signal(lua_State* L, int dlgIdx, - Signal& signal, + obs::signal& signal, Callback callback) { auto dlg = get_obj(L, dlgIdx); @@ -124,7 +124,7 @@ void Dialog_connect_signal(lua_State* L, lua_pop(L, 1); // Pop the uservalue signal.connect( - base::Bind([=]() { + [=](Args...args) { // In case that the dialog is hidden, we cannot access to the // global LUA_REGISTRYINDEX to get its reference. if (dlg->showRef == LUA_REFNIL) @@ -141,7 +141,7 @@ void Dialog_connect_signal(lua_State* L, // lua_pcall() (that table is like an "event data" parameter // for the function). lua_newtable(L); - callback(L); + callback(L, std::forward(args)...); if (lua_isfunction(L, -2)) { if (lua_pcall(L, 1, 0, 0)) { @@ -164,7 +164,7 @@ void Dialog_connect_signal(lua_State* L, ->scriptEngine() ->consolePrint(ex.what()); } - })); + }); } int Dialog_new(lua_State* L) @@ -193,7 +193,7 @@ int Dialog_new(lua_State* L) if (type == LUA_TFUNCTION) { Dialog_connect_signal( L, -2, dlg->window.Close, - [](lua_State* L){ + [](lua_State*, CloseEvent&){ // Do nothing }); } @@ -395,7 +395,7 @@ int Dialog_button_base(lua_State* L, T** outputWidget = nullptr) auto dlg = get_obj(L, 1); Dialog_connect_signal( L, 1, widget->Click, - [dlg, widget](lua_State* L){ + [dlg, widget](lua_State* L, Event&){ dlg->lastButton = widget; }); closeWindowByDefault = false; @@ -595,7 +595,10 @@ int Dialog_shades(lua_State* L) if (type == LUA_TFUNCTION) { Dialog_connect_signal( L, 1, widget->Click, - [widget](lua_State* L){ + [widget](lua_State* L, ColorShades::ClickEvent& ev){ + lua_pushinteger(L, (int)ev.button()); + lua_setfield(L, -2, "button"); + const int i = widget->getHotEntry(); const Shade shade = widget->getShade(); if (i >= 0 && i < int(shade.size())) { diff --git a/src/app/script/engine.cpp b/src/app/script/engine.cpp index 5759af94e..7e122e68a 100644 --- a/src/app/script/engine.cpp +++ b/src/app/script/engine.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2019 Igara Studio S.A. +// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -26,6 +26,7 @@ #include "doc/blend_mode.h" #include "doc/color_mode.h" #include "filters/target.h" +#include "ui/mouse_button.h" #include #include @@ -341,6 +342,17 @@ Engine::Engine() setfield_integer(L, "GRAYA", TARGET_GRAY_CHANNEL | TARGET_ALPHA_CHANNEL); lua_pop(L, 1); + lua_newtable(L); + lua_pushvalue(L, -1); + lua_setglobal(L, "MouseButton"); + setfield_integer(L, "NONE", (int)ui::kButtonNone); + setfield_integer(L, "LEFT", (int)ui::kButtonLeft); + setfield_integer(L, "RIGHT", (int)ui::kButtonRight); + setfield_integer(L, "MIDDLE", (int)ui::kButtonMiddle); + setfield_integer(L, "X1", (int)ui::kButtonX1); + setfield_integer(L, "X2", (int)ui::kButtonX2); + lua_pop(L, 1); + // Register classes/prototypes register_brush_class(L); register_cel_class(L); diff --git a/src/app/ui/color_popup.cpp b/src/app/ui/color_popup.cpp index 9d07a3d77..1619fd536 100644 --- a/src/app/ui/color_popup.cpp +++ b/src/app/ui/color_popup.cpp @@ -408,7 +408,7 @@ void ColorPopup::onColorHexEntryChange(const app::Color& color) m_disableHexUpdate = false; } -void ColorPopup::onSelectOldColor() +void ColorPopup::onSelectOldColor(ColorShades::ClickEvent&) { Shade shade = m_oldAndNew.getShade(); int hot = m_oldAndNew.getHotEntry(); diff --git a/src/app/ui/color_popup.h b/src/app/ui/color_popup.h index 1aacd16d0..f687da5d2 100644 --- a/src/app/ui/color_popup.h +++ b/src/app/ui/color_popup.h @@ -53,7 +53,7 @@ namespace app { void onMakeFixed() override; void onColorSlidersChange(ColorSlidersChangeEvent& ev); void onColorHexEntryChange(const app::Color& color); - void onSelectOldColor(); + void onSelectOldColor(ColorShades::ClickEvent& ev); void onSimpleColorClick(); void onColorTypeClick(); void onPaletteChange(); diff --git a/src/app/ui/color_shades.cpp b/src/app/ui/color_shades.cpp index a0af5decf..598b64176 100644 --- a/src/app/ui/color_shades.cpp +++ b/src/app/ui/color_shades.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019 Igara Studio S.A. +// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2018 David Capello // // This program is distributed under the terms of @@ -28,8 +28,8 @@ #include "ui/paint_event.h" #include "ui/size_hint_event.h" #include "ui/system.h" +#include -#include namespace app { @@ -147,11 +147,14 @@ bool ColorShades::onProcessMessage(ui::Message* msg) if (m_hotIndex >= 0 && m_hotIndex < int(m_shade.size())) { switch (m_click) { - case ClickEntries: - Click(); + case ClickEntries: { + ClickEvent ev(static_cast(msg)->button()); + Click(ev); + m_hotIndex = -1; invalidate(); break; + } case DragAndDropEntries: m_dragIndex = m_hotIndex; m_dropBefore = false; @@ -164,7 +167,10 @@ bool ColorShades::onProcessMessage(ui::Message* msg) case ui::kMouseUpMessage: { if (m_click == ClickWholeShade) { setSelected(true); - Click(); + + ClickEvent ev(static_cast(msg)->button()); + Click(ev); + closeWindow(); } diff --git a/src/app/ui/color_shades.h b/src/app/ui/color_shades.h index 7d6326625..7917e4439 100644 --- a/src/app/ui/color_shades.h +++ b/src/app/ui/color_shades.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019 Igara Studio S.A. +// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2018 David Capello // // This program is distributed under the terms of @@ -11,6 +11,7 @@ #include "app/shade.h" #include "obs/signal.h" +#include "ui/mouse_button.h" #include "ui/widget.h" namespace doc { @@ -41,7 +42,15 @@ namespace app { int getHotEntry() const { return m_hotIndex; } - obs::signal Click; + class ClickEvent { + public: + ClickEvent(ui::MouseButton button) : m_button(button) { } + ui::MouseButton button() const { return m_button; } + private: + ui::MouseButton m_button; + }; + + obs::signal Click; private: void onInitTheme(ui::InitThemeEvent& ev) override; diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp index cb438fb46..145f5d5c6 100644 --- a/src/app/ui/context_bar.cpp +++ b/src/app/ui/context_bar.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2019 Igara Studio S.A. +// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -595,7 +595,7 @@ private: auto shadeWidget = new ColorShades(shade, ColorShades::ClickWholeShade); shadeWidget->setExpansive(true); shadeWidget->Click.connect( - [&]{ + [&](ColorShades::ClickEvent&){ m_shade.setShade(shade); });