diff options
author | Mnikolenko Productengine <mnikolenko@productengine.com> | 2024-03-14 15:29:47 +0200 |
---|---|---|
committer | Mnikolenko Productengine <mnikolenko@productengine.com> | 2024-03-14 15:29:47 +0200 |
commit | 45fcb914c89ff721833497bfb021b7583f24bd1c (patch) | |
tree | f8fb72790b22d6af06ad4b5e478e694c37cf7989 /indra/llui | |
parent | 72d68cbc078cf2c1b9dc3ff81c2c1965f5d6f8c5 (diff) |
Send additional events to the script when specified
Diffstat (limited to 'indra/llui')
-rw-r--r-- | indra/llui/llluafloater.cpp | 78 | ||||
-rw-r--r-- | indra/llui/llluafloater.h | 1 |
2 files changed, 78 insertions, 1 deletions
diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp index 3507c907a0..5b50d85811 100644 --- a/indra/llui/llluafloater.cpp +++ b/indra/llui/llluafloater.cpp @@ -34,6 +34,15 @@ const std::string LISTENER_NAME("LLLuaFloater"); +const std::string COMMIT_EVENT("commit"); +const std::string MOUSE_ENTER_EVENT("mouse_enter"); +const std::string MOUSE_LEAVE_EVENT("mouse_leave"); +const std::string MOUSE_DOWN_EVENT("mouse_down"); +const std::string MOUSE_UP_EVENT("mouse_up"); +const std::string RIGHT_MOUSE_DOWN_EVENT("right_mouse_down"); +const std::string RIGHT_MOUSE_UP_EVENT("right_mouse_up"); +const std::string DOUBLE_CLICK_EVENT("double_click"); + LLLuaFloater::LLLuaFloater(const LLSD &key) : LLFloater(key), mCommandPumpName(key["command_pump"].asString()), @@ -101,7 +110,7 @@ BOOL LLLuaFloater::postBuild() LLSD data; data["ctrl_name"] = view->getName(); - data["event"] = "click"; + data["event"] = COMMIT_EVENT; LLButton* btn = dynamic_cast<LLButton*>(view); if (btn && !isDefaultBtnName(btn->getName())) @@ -133,6 +142,22 @@ BOOL LLLuaFloater::postBuild() } } + //optional field to send additional specified events to the script + if (mKey.has("extra_events")) + { + //the first value is ctrl name, the second contains array of events to send + const LLSD &events_map = mKey["extra_events"]; + for (LLSD::map_const_iterator it = events_map.beginMap(); it != events_map.endMap(); ++it) + { + std::string name = (*it).first; + LLSD data = (*it).second; + for (LLSD::array_const_iterator events_it = data.beginArray(); events_it != data.endArray(); ++events_it) + { + registerCallback(name, events_it->asString()); + } + } + } + post(LLSD().with("command_name", mListenerPumpName).with("event", "post_build")); return true; @@ -143,6 +168,57 @@ void LLLuaFloater::onClose(bool app_quitting) post(LLSD().with("event", "floater_close")); } +void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::string &event) +{ + LLUICtrl *ctrl = getChild<LLUICtrl>(ctrl_name); + if (!ctrl) return; + + LLSD data; + data["ctrl_name"] = ctrl_name; + data["event"] = event; + + auto mouse_event_cb = [this, data](LLUICtrl *ctrl, const LLSD ¶m) { post(data); }; + + auto mouse_event_coords_cb = [this, data](LLUICtrl *ctrl, S32 x, S32 y, MASK mask) + { + LLSD event(data); + post(event.with("x", x).with("y", y)); + }; + + if (event == MOUSE_ENTER_EVENT) + { + ctrl->setMouseEnterCallback(mouse_event_cb); + } + else if (event == MOUSE_LEAVE_EVENT) + { + ctrl->setMouseLeaveCallback(mouse_event_cb); + } + else if (event == MOUSE_DOWN_EVENT) + { + ctrl->setMouseDownCallback(mouse_event_coords_cb); + } + else if (event == MOUSE_UP_EVENT) + { + ctrl->setMouseUpCallback(mouse_event_coords_cb); + } + else if (event == RIGHT_MOUSE_DOWN_EVENT) + { + ctrl->setRightMouseDownCallback(mouse_event_coords_cb); + } + else if (event == RIGHT_MOUSE_UP_EVENT) + { + ctrl->setRightMouseUpCallback(mouse_event_coords_cb); + } + else if (event == DOUBLE_CLICK_EVENT) + { + ctrl->setDoubleClickCallback(mouse_event_coords_cb); + } + else + { + LL_WARNS("LuaFloater") << "Can't register callback for unknown event: " << event << " ,control: " << ctrl_name << LL_ENDL; + } +} + void LLLuaFloater::post(const LLSD &data) { LLSD stamped_data(data); diff --git a/indra/llui/llluafloater.h b/indra/llui/llluafloater.h index 0b7e86746a..eec6180bee 100644 --- a/indra/llui/llluafloater.h +++ b/indra/llui/llluafloater.h @@ -36,6 +36,7 @@ public: LLLuaFloater(const LLSD &key); BOOL postBuild(); + void registerCallback(const std::string &ctrl_name, const std::string &event); void onClose(bool app_quitting); void post(const LLSD &data); |