[lua] Add possibility to modify the mouseCursor of a canvas

This commit is contained in:
David Capello 2022-12-26 15:33:14 -03:00
parent ae6f9c22ba
commit a6a7519178
4 changed files with 45 additions and 0 deletions

View File

@ -13,6 +13,7 @@
#include "ui/paint_event.h"
#include "ui/resize_event.h"
#include "ui/size_hint_event.h"
#include "ui/system.h"
#ifdef ENABLE_UI
@ -63,6 +64,10 @@ bool Canvas::onProcessMessage(ui::Message* msg)
{
switch (msg->type()) {
case ui::kSetCursorMessage:
ui::set_mouse_cursor(m_cursorType);
return true;
case ui::kMouseMoveMessage: {
auto mouseMsg = static_cast<ui::MouseMessage*>(msg);
MouseMove(mouseMsg);

View File

@ -9,6 +9,7 @@
#pragma once
#include "os/surface.h"
#include "ui/cursor_type.h"
#include "ui/widget.h"
namespace app {
@ -26,6 +27,10 @@ public:
void callPaint();
void setMouseCursor(const ui::CursorType cursor) {
m_cursorType = cursor;
}
obs::signal<void(GraphicsContext&)> Paint;
obs::signal<void(ui::MouseMessage*)> MouseMove;
obs::signal<void(ui::MouseMessage*)> MouseDown;
@ -38,6 +43,7 @@ private:
void onPaint(ui::PaintEvent& ev) override;
os::SurfaceRef m_surface;
ui::CursorType m_cursorType = ui::kArrowCursor;
};
} // namespace script

View File

@ -35,6 +35,7 @@
#include "ui/message.h"
#include "ui/separator.h"
#include "ui/slider.h"
#include "ui/system.h"
#include "ui/window.h"
#include <map>
@ -1137,6 +1138,15 @@ int Dialog_modify(lua_State* L)
}
lua_pop(L, 1);
type = lua_getfield(L, 2, "mouseCursor");
if (type != LUA_TNIL) {
if (auto canvas = dynamic_cast<Canvas*>(widget)) {
auto cursor = (ui::CursorType)lua_tointeger(L, -1);
canvas->setMouseCursor(cursor);
}
}
lua_pop(L, 1);
// TODO shades mode? file title / open / save / filetypes? on* events?
if (relayout) {

View File

@ -30,6 +30,7 @@
#include "doc/blend_mode.h"
#include "doc/color_mode.h"
#include "filters/target.h"
#include "ui/cursor_type.h"
#include "ui/mouse_button.h"
#include <fstream>
@ -371,6 +372,29 @@ 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, "MouseCursor");
setfield_integer(L, "HIDDEN", (int)ui::kNoCursor);
setfield_integer(L, "ARROW", (int)ui::kArrowCursor);
setfield_integer(L, "CROSSHAIR", (int)ui::kCrosshairCursor);
setfield_integer(L, "POINTER", (int)ui::kHandCursor);
setfield_integer(L, "NOT_ALLOWED", (int)ui::kForbiddenCursor);
setfield_integer(L, "GRAB", (int)ui::kScrollCursor);
setfield_integer(L, "GRABBING", (int)ui::kScrollCursor);
setfield_integer(L, "MOVE", (int)ui::kMoveCursor);
setfield_integer(L, "NS_RESIZE", (int)ui::kSizeNSCursor);
setfield_integer(L, "WE_RESIZE", (int)ui::kSizeWECursor);
setfield_integer(L, "N_RESIZE", (int)ui::kSizeNCursor);
setfield_integer(L, "NE_RESIZE", (int)ui::kSizeNECursor);
setfield_integer(L, "E_RESIZE", (int)ui::kSizeECursor);
setfield_integer(L, "SE_RESIZE", (int)ui::kSizeSECursor);
setfield_integer(L, "S_RESIZE", (int)ui::kSizeSCursor);
setfield_integer(L, "SW_RESIZE", (int)ui::kSizeSWCursor);
setfield_integer(L, "W_RESIZE", (int)ui::kSizeWCursor);
setfield_integer(L, "NW_RESIZE", (int)ui::kSizeNWCursor);
lua_pop(L, 1);
lua_newtable(L);
lua_pushvalue(L, -1);
lua_setglobal(L, "MouseButton");