From 8753f82fd01635a8ea8fc5b724c45d88bddfac9b Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Fri, 10 Aug 2012 16:26:39 -0300 Subject: [PATCH] Change cursor on textedit, remove possibility to close EnterGame window --- modules/client/client.lua | 5 ++ modules/client_entergame/entergame.otui | 11 +-- .../skins/default/cursors/text.png | Bin 0 -> 964 bytes modules/corelib/mouse.lua | 33 --------- src/framework/CMakeLists.txt | 3 + src/framework/input/mouse.cpp | 67 ++++++++++++++++++ src/framework/input/mouse.h | 40 +++++++++++ src/framework/luafunctions.cpp | 11 +++ src/framework/ui/uitextedit.cpp | 9 +++ src/framework/ui/uitextedit.h | 1 + 10 files changed, 137 insertions(+), 43 deletions(-) create mode 100644 modules/client_skins/skins/default/cursors/text.png create mode 100644 src/framework/input/mouse.cpp create mode 100644 src/framework/input/mouse.h diff --git a/modules/client/client.lua b/modules/client/client.lua index 7a8485bc..bbfb1e2a 100644 --- a/modules/client/client.lua +++ b/modules/client/client.lua @@ -37,6 +37,11 @@ function Client.init() g_window.setIcon(resolvepath('clienticon.png')) g_keyboard.bindKeyDown('Ctrl+Shift+R', Client.reloadScripts) + local clientVersion = g_settings.getInteger('client-version') + if clientVersion ~= 0 then + g_game.setClientVersion(clientVersion) + end + connect(g_app, { onRun = function() -- Play startup music (The Silver Tree, by Mattias Westlund) diff --git a/modules/client_entergame/entergame.otui b/modules/client_entergame/entergame.otui index 2d2e0844..ddb76c9b 100644 --- a/modules/client_entergame/entergame.otui +++ b/modules/client_entergame/entergame.otui @@ -5,7 +5,6 @@ EnterGameWindow !text: tr('Enter Game') size: 236 274 @onEnter: EnterGame.doLogin() - @onEscape: EnterGame.hide() MenuLabel !text: tr('Account name') @@ -107,14 +106,6 @@ EnterGameWindow Button !text: tr('Ok') width: 64 - anchors.right: next.left - anchors.bottom: parent.bottom - margin-right: 10 - @onClick: EnterGame.doLogin() - - Button - !text: tr('Cancel') - width: 64 anchors.right: parent.right anchors.bottom: parent.bottom - @onClick: EnterGame.hide() + @onClick: EnterGame.doLogin() diff --git a/modules/client_skins/skins/default/cursors/text.png b/modules/client_skins/skins/default/cursors/text.png new file mode 100644 index 0000000000000000000000000000000000000000..2a69d564cd510fc9c63b1e27bf4c7320d3bf4d1a GIT binary patch literal 964 zcmV;#13UbQP)Px&08mU+MSy^S00030|NjF60|W#F1qB5L1_lQQ2M7oV2?+@b3JMDg3k(bl4Gj$r z4h|0w4-gO#5fKp*5)u;=6BHB_6%`d078Vy57Z?~A85tQG8X6lL8yp-Q9UUDW9v&Yb zA0QwgAt50mA|fLrBP1jwB_$;$CMG8*CnzW=DJdx`Dk>{0D=aK5EiElBE-o)GFEB7L zF)=YRGBPtWGc+_bH8nLhHa0gmH#j&rIXO8xIyyT$J3Kr*Jv}`>K0ZG`KR`f0K|w)6 zLPA4BLqtSGMMXtMMn*?RM@UFWNl8gcN=i#hOH52mO-)TsPEJoxPf$=$QBhG+Qc_b> zQ&dz`RaI41R#sP6S6EnBSy@?HT3TCMTU=aRU0q#XUS3~cUtnNhVPRonVq#-sV`OAx zWo2b%W@cw+XJ}|>X=!O{YHDk1Yiw+6ZEbCCZf7mzbEC znVFfInwp!No1C1Sot>SYo}QndpP-Ll?si~=| zs;aB2tE{Z7t*x!DuCA}IuduMNv9YnTva++Yv$V9dwY9ajwzjvox45{txw*Nzy1Ki& zyS%)-y}iA@zP`V|zreu2!NI}8!otJD!^FhI#l^+O#>U6T$H>UY$;rve%F4^j%goHo z&CSiu&d$%z&(P4&(b3V;($dq@)6~?|)z#J3*4Ee8*Vx$D+1c6J+S=RO+uYpT-QC^Z z-rnEe-{9cj;o;%p;^O1ulq(=H}<;=jiC@>FMd}>gwz3>+J08?d|RE?(XmJ z@9^;O@$vEU^78ZZ^Yrxe_4W1k_V)Mp_xSku`T60}(QBtr3_2001yaL_t(I%VS`I0R|j^iII^JjBzRe0!Dl$fDOSXJF0+g m3J69PQPIsrAi77vZ~*|*umGDLhK=h00000 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "mouse.h" +#include +#include + +Mouse g_mouse; + +void Mouse::setTargetCursor() +{ + g_window.setMouseCursor("/cursors/targetcursor.png", Point(9, 9)); + m_cursorChanged = true; +} + +void Mouse::setHorizontalCursor() +{ + g_window.setMouseCursor("/cursors/horizontal.png", Point(9, 4)); + m_cursorChanged = true; +} + +void Mouse::setVerticalCursor() +{ + g_window.setMouseCursor("/cursors/vertical.png", Point(4, 9)); + m_cursorChanged = true; +} + +void Mouse::setTextCursor() +{ + g_window.setMouseCursor("/cursors/text.png", Point(4, 9)); + m_cursorChanged = true; +} + +void Mouse::restoreCursor() +{ + g_window.restoreMouseCursor(); + m_cursorChanged = false; +} + +bool Mouse::isCursorChanged() +{ + return m_cursorChanged; +} + +bool Mouse::isPressed(Fw::MouseButton mouseButton) +{ + return g_window.isMouseButtonPressed(mouseButton); +} diff --git a/src/framework/input/mouse.h b/src/framework/input/mouse.h new file mode 100644 index 00000000..4b55bc3a --- /dev/null +++ b/src/framework/input/mouse.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2010-2012 OTClient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +class Mouse +{ +public: + void setTargetCursor(); + void setHorizontalCursor(); + void setVerticalCursor(); + void setTextCursor(); + void restoreCursor(); + bool isCursorChanged(); + bool isPressed(Fw::MouseButton mouseButton); + +private: + bool m_cursorChanged; +}; + +extern Mouse g_mouse; diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 0a6c79f8..a17c3043 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #endif #ifdef FW_NET @@ -240,6 +241,16 @@ void Application::registerLuaFunctions() g_lua.bindSingletonFunction("g_window", "isMaximized", &PlatformWindow::isMaximized, &g_window); g_lua.bindSingletonFunction("g_window", "hasFocus", &PlatformWindow::hasFocus, &g_window); + // Input + g_lua.registerSingletonClass("g_mouse"); + g_lua.bindSingletonFunction("g_mouse", "setTargetCursor", &Mouse::setTargetCursor, &g_mouse); + g_lua.bindSingletonFunction("g_mouse", "setHorizontalCursor", &Mouse::setHorizontalCursor, &g_mouse); + g_lua.bindSingletonFunction("g_mouse", "setVerticalCursor", &Mouse::setVerticalCursor, &g_mouse); + g_lua.bindSingletonFunction("g_mouse", "setTextCursor", &Mouse::setTextCursor, &g_mouse); + g_lua.bindSingletonFunction("g_mouse", "restoreCursor", &Mouse::restoreCursor, &g_mouse); + g_lua.bindSingletonFunction("g_mouse", "isCursorChanged", &Mouse::isCursorChanged, &g_mouse); + g_lua.bindSingletonFunction("g_mouse", "isPressed", &Mouse::isPressed, &g_mouse); + // Graphics g_lua.registerSingletonClass("g_graphics"); g_lua.bindSingletonFunction("g_graphics", "isPainterEngineAvailable", &Graphics::isPainterEngineAvailable, &g_graphics); diff --git a/src/framework/ui/uitextedit.cpp b/src/framework/ui/uitextedit.cpp index f20d8004..3a8d0f11 100644 --- a/src/framework/ui/uitextedit.cpp +++ b/src/framework/ui/uitextedit.cpp @@ -27,6 +27,7 @@ #include #include #include +#include UITextEdit::UITextEdit() { @@ -391,6 +392,14 @@ std::string UITextEdit::getDisplayedText() return m_text; } +void UITextEdit::onHoverChange(bool hovered) +{ + if(hovered) + g_mouse.setTextCursor(); + else + g_mouse.restoreCursor(); +} + void UITextEdit::onTextChange(const std::string& text, const std::string& oldText) { m_cursorPos = text.length(); diff --git a/src/framework/ui/uitextedit.h b/src/framework/ui/uitextedit.h index 1a7ef69b..5e2fe721 100644 --- a/src/framework/ui/uitextedit.h +++ b/src/framework/ui/uitextedit.h @@ -62,6 +62,7 @@ public: bool isMultiline() { return m_multiline; } protected: + virtual void onHoverChange(bool hovered); virtual void onTextChange(const std::string& text, const std::string& oldText); virtual void onFontChange(const std::string& font); virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);