mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-18 11:42:47 +00:00
[lua] Add ev.button property onclick of shades widget
This commit is contained in:
parent
09ea577a08
commit
32fd67e187
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2018-2019 Igara Studio S.A.
|
// Copyright (C) 2018-2020 Igara Studio S.A.
|
||||||
// Copyright (C) 2018 David Capello
|
// Copyright (C) 2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -103,11 +103,11 @@ struct Dialog {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Signal,
|
template<typename...Args,
|
||||||
typename Callback>
|
typename Callback>
|
||||||
void Dialog_connect_signal(lua_State* L,
|
void Dialog_connect_signal(lua_State* L,
|
||||||
int dlgIdx,
|
int dlgIdx,
|
||||||
Signal& signal,
|
obs::signal<void(Args...)>& signal,
|
||||||
Callback callback)
|
Callback callback)
|
||||||
{
|
{
|
||||||
auto dlg = get_obj<Dialog>(L, dlgIdx);
|
auto dlg = get_obj<Dialog>(L, dlgIdx);
|
||||||
@ -124,7 +124,7 @@ void Dialog_connect_signal(lua_State* L,
|
|||||||
lua_pop(L, 1); // Pop the uservalue
|
lua_pop(L, 1); // Pop the uservalue
|
||||||
|
|
||||||
signal.connect(
|
signal.connect(
|
||||||
base::Bind<void>([=]() {
|
[=](Args...args) {
|
||||||
// In case that the dialog is hidden, we cannot access to the
|
// In case that the dialog is hidden, we cannot access to the
|
||||||
// global LUA_REGISTRYINDEX to get its reference.
|
// global LUA_REGISTRYINDEX to get its reference.
|
||||||
if (dlg->showRef == LUA_REFNIL)
|
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
|
// lua_pcall() (that table is like an "event data" parameter
|
||||||
// for the function).
|
// for the function).
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
callback(L);
|
callback(L, std::forward<Args>(args)...);
|
||||||
|
|
||||||
if (lua_isfunction(L, -2)) {
|
if (lua_isfunction(L, -2)) {
|
||||||
if (lua_pcall(L, 1, 0, 0)) {
|
if (lua_pcall(L, 1, 0, 0)) {
|
||||||
@ -164,7 +164,7 @@ void Dialog_connect_signal(lua_State* L,
|
|||||||
->scriptEngine()
|
->scriptEngine()
|
||||||
->consolePrint(ex.what());
|
->consolePrint(ex.what());
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
int Dialog_new(lua_State* L)
|
int Dialog_new(lua_State* L)
|
||||||
@ -193,7 +193,7 @@ int Dialog_new(lua_State* L)
|
|||||||
if (type == LUA_TFUNCTION) {
|
if (type == LUA_TFUNCTION) {
|
||||||
Dialog_connect_signal(
|
Dialog_connect_signal(
|
||||||
L, -2, dlg->window.Close,
|
L, -2, dlg->window.Close,
|
||||||
[](lua_State* L){
|
[](lua_State*, CloseEvent&){
|
||||||
// Do nothing
|
// Do nothing
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -395,7 +395,7 @@ int Dialog_button_base(lua_State* L, T** outputWidget = nullptr)
|
|||||||
auto dlg = get_obj<Dialog>(L, 1);
|
auto dlg = get_obj<Dialog>(L, 1);
|
||||||
Dialog_connect_signal(
|
Dialog_connect_signal(
|
||||||
L, 1, widget->Click,
|
L, 1, widget->Click,
|
||||||
[dlg, widget](lua_State* L){
|
[dlg, widget](lua_State* L, Event&){
|
||||||
dlg->lastButton = widget;
|
dlg->lastButton = widget;
|
||||||
});
|
});
|
||||||
closeWindowByDefault = false;
|
closeWindowByDefault = false;
|
||||||
@ -595,7 +595,10 @@ int Dialog_shades(lua_State* L)
|
|||||||
if (type == LUA_TFUNCTION) {
|
if (type == LUA_TFUNCTION) {
|
||||||
Dialog_connect_signal(
|
Dialog_connect_signal(
|
||||||
L, 1, widget->Click,
|
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 int i = widget->getHotEntry();
|
||||||
const Shade shade = widget->getShade();
|
const Shade shade = widget->getShade();
|
||||||
if (i >= 0 && i < int(shade.size())) {
|
if (i >= 0 && i < int(shade.size())) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2018-2019 Igara Studio S.A.
|
// Copyright (C) 2018-2020 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2018 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -26,6 +26,7 @@
|
|||||||
#include "doc/blend_mode.h"
|
#include "doc/blend_mode.h"
|
||||||
#include "doc/color_mode.h"
|
#include "doc/color_mode.h"
|
||||||
#include "filters/target.h"
|
#include "filters/target.h"
|
||||||
|
#include "ui/mouse_button.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -341,6 +342,17 @@ Engine::Engine()
|
|||||||
setfield_integer(L, "GRAYA", TARGET_GRAY_CHANNEL | TARGET_ALPHA_CHANNEL);
|
setfield_integer(L, "GRAYA", TARGET_GRAY_CHANNEL | TARGET_ALPHA_CHANNEL);
|
||||||
lua_pop(L, 1);
|
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 classes/prototypes
|
||||||
register_brush_class(L);
|
register_brush_class(L);
|
||||||
register_cel_class(L);
|
register_cel_class(L);
|
||||||
|
@ -408,7 +408,7 @@ void ColorPopup::onColorHexEntryChange(const app::Color& color)
|
|||||||
m_disableHexUpdate = false;
|
m_disableHexUpdate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorPopup::onSelectOldColor()
|
void ColorPopup::onSelectOldColor(ColorShades::ClickEvent&)
|
||||||
{
|
{
|
||||||
Shade shade = m_oldAndNew.getShade();
|
Shade shade = m_oldAndNew.getShade();
|
||||||
int hot = m_oldAndNew.getHotEntry();
|
int hot = m_oldAndNew.getHotEntry();
|
||||||
|
@ -53,7 +53,7 @@ namespace app {
|
|||||||
void onMakeFixed() override;
|
void onMakeFixed() override;
|
||||||
void onColorSlidersChange(ColorSlidersChangeEvent& ev);
|
void onColorSlidersChange(ColorSlidersChangeEvent& ev);
|
||||||
void onColorHexEntryChange(const app::Color& color);
|
void onColorHexEntryChange(const app::Color& color);
|
||||||
void onSelectOldColor();
|
void onSelectOldColor(ColorShades::ClickEvent& ev);
|
||||||
void onSimpleColorClick();
|
void onSimpleColorClick();
|
||||||
void onColorTypeClick();
|
void onColorTypeClick();
|
||||||
void onPaletteChange();
|
void onPaletteChange();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2019 Igara Studio S.A.
|
// Copyright (C) 2019-2020 Igara Studio S.A.
|
||||||
// Copyright (C) 2018 David Capello
|
// Copyright (C) 2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -28,8 +28,8 @@
|
|||||||
#include "ui/paint_event.h"
|
#include "ui/paint_event.h"
|
||||||
#include "ui/size_hint_event.h"
|
#include "ui/size_hint_event.h"
|
||||||
#include "ui/system.h"
|
#include "ui/system.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <limits>
|
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
|
|
||||||
@ -147,11 +147,14 @@ bool ColorShades::onProcessMessage(ui::Message* msg)
|
|||||||
if (m_hotIndex >= 0 &&
|
if (m_hotIndex >= 0 &&
|
||||||
m_hotIndex < int(m_shade.size())) {
|
m_hotIndex < int(m_shade.size())) {
|
||||||
switch (m_click) {
|
switch (m_click) {
|
||||||
case ClickEntries:
|
case ClickEntries: {
|
||||||
Click();
|
ClickEvent ev(static_cast<ui::MouseMessage*>(msg)->button());
|
||||||
|
Click(ev);
|
||||||
|
|
||||||
m_hotIndex = -1;
|
m_hotIndex = -1;
|
||||||
invalidate();
|
invalidate();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case DragAndDropEntries:
|
case DragAndDropEntries:
|
||||||
m_dragIndex = m_hotIndex;
|
m_dragIndex = m_hotIndex;
|
||||||
m_dropBefore = false;
|
m_dropBefore = false;
|
||||||
@ -164,7 +167,10 @@ bool ColorShades::onProcessMessage(ui::Message* msg)
|
|||||||
case ui::kMouseUpMessage: {
|
case ui::kMouseUpMessage: {
|
||||||
if (m_click == ClickWholeShade) {
|
if (m_click == ClickWholeShade) {
|
||||||
setSelected(true);
|
setSelected(true);
|
||||||
Click();
|
|
||||||
|
ClickEvent ev(static_cast<ui::MouseMessage*>(msg)->button());
|
||||||
|
Click(ev);
|
||||||
|
|
||||||
closeWindow();
|
closeWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2019 Igara Studio S.A.
|
// Copyright (C) 2019-2020 Igara Studio S.A.
|
||||||
// Copyright (C) 2018 David Capello
|
// Copyright (C) 2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "app/shade.h"
|
#include "app/shade.h"
|
||||||
#include "obs/signal.h"
|
#include "obs/signal.h"
|
||||||
|
#include "ui/mouse_button.h"
|
||||||
#include "ui/widget.h"
|
#include "ui/widget.h"
|
||||||
|
|
||||||
namespace doc {
|
namespace doc {
|
||||||
@ -41,7 +42,15 @@ namespace app {
|
|||||||
|
|
||||||
int getHotEntry() const { return m_hotIndex; }
|
int getHotEntry() const { return m_hotIndex; }
|
||||||
|
|
||||||
obs::signal<void()> 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<void(ClickEvent&)> Click;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onInitTheme(ui::InitThemeEvent& ev) override;
|
void onInitTheme(ui::InitThemeEvent& ev) override;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2018-2019 Igara Studio S.A.
|
// Copyright (C) 2018-2020 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2018 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -595,7 +595,7 @@ private:
|
|||||||
auto shadeWidget = new ColorShades(shade, ColorShades::ClickWholeShade);
|
auto shadeWidget = new ColorShades(shade, ColorShades::ClickWholeShade);
|
||||||
shadeWidget->setExpansive(true);
|
shadeWidget->setExpansive(true);
|
||||||
shadeWidget->Click.connect(
|
shadeWidget->Click.connect(
|
||||||
[&]{
|
[&](ColorShades::ClickEvent&){
|
||||||
m_shade.setShade(shade);
|
m_shade.setShade(shade);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user