Browse Source

new widget, UICheckBox

Eduardo Bart 9 years ago
parent
commit
532d7f239f

+ 4
- 4
CMakeLists.txt View File

@@ -50,7 +50,7 @@ IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
50 50
     ADD_DEFINITIONS(-D_DEBUG)
51 51
 ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
52 52
 
53
-SET(SOURCES src/framework/ui/uiframecounter.cpp
53
+SET(SOURCES
54 54
     # main
55 55
     src/main.cpp
56 56
 
@@ -94,9 +94,6 @@ SET(SOURCES src/framework/ui/uiframecounter.cpp
94 94
     src/framework/net/rsa.cpp
95 95
     src/framework/net/server.cpp
96 96
 
97
-    # framework util
98
-    src/framework/util/translator.cpp
99
-
100 97
     # framework core
101 98
     src/framework/core/logger.cpp
102 99
     src/framework/core/configs.cpp
@@ -142,6 +139,9 @@ SET(SOURCES src/framework/ui/uiframecounter.cpp
142 139
     src/framework/ui/uiverticallayout.cpp
143 140
     src/framework/ui/uilayout.cpp
144 141
     src/framework/ui/uiprogressbar.cpp
142
+    src/framework/ui/uicheckbox.cpp
143
+    src/framework/ui/uiframecounter.cpp
144
+    src/framework/ui/uitranslator.cpp
145 145
 )
146 146
 
147 147
 IF(HANDLE_EXCEPTIONS)

+ 10
- 10
README.rdoc View File

@@ -1,17 +1,12 @@
1 1
 == What is OTClient?
2 2
 
3 3
 OTClient is an alternative Tibia client for usage with otserv. It aims to be complete and flexible,
4
-for that it uses LUA scripting for all game interface functionality and configuration files created with
5
-a syntax similar to CSS for its interface design. OTClient works with a modular system, this means
4
+for that it uses LUA scripting for all game interface functionality and OTML files that has a syntax
5
+similar to CSS for the client interface design. OTClient works with a modular system, this means
6 6
 that each functionality is a separated module, giving the possibility to users modify and customize
7 7
 anything easily. Users can also create new mods and extend game interface for their own purposes.
8 8
 OTClient is written in C++2011, the upcoming C++ standard.
9 9
 
10
-== Need help?
11
-
12
-If you have any questions or are looking for more information, please feel free to ask on our official
13
-forum at http://otclient.info/
14
-
15 10
 == Getting Started
16 11
 
17 12
 In short, if you need to compile OTClient, follow these tutorials:
@@ -19,9 +14,14 @@ In short, if you need to compile OTClient, follow these tutorials:
19 14
 * {Compiling on Ubuntu}[http://otclient.info/page/articles.html/_/general/compiling-on-ubuntu-r12]
20 15
 Checkout our website at {http://otclient.info}[http://otclient.info/] for tutorials and more information
21 16
 
17
+== Need help?
18
+
19
+If you have any questions or are looking for more information, please feel free to ask on our official
20
+forum at http://otclient.info/
21
+
22 22
 == Bugs
23 23
 
24
-Have found a bug? Please create an issue in our bug tracker!
24
+Have found a bug? Please create an issue in our bug tracker
25 25
 http://otclient.info/tracker
26 26
 
27 27
 == Contributing
@@ -31,8 +31,8 @@ We encourage you to contribute to OTClient! Please check out
31 31
 
32 32
 == Authors
33 33
 
34
-* edubart <edub4rt@gmail.com> (project creator and leader developer)
35
-* baxnie <henrique_santiago93@hotmail.com> (official developer)
34
+* edubart (project creator and leader developer) <edub4rt@gmail.com>
35
+* baxnie (official developer) <henrique_santiago93@hotmail.com>
36 36
 
37 37
 == License
38 38
 

+ 3
- 1
TODO View File

@@ -11,4 +11,6 @@ padding
11 11
 remember password/account
12 12
 scrollbar
13 13
 make otui syntax more like css
14
-a real working border and background property in otui
14
+a real working border and background property in otui
15
+setIcon() for buttons
16
+load state styles in order

+ 2
- 2
modules/about/about.otui View File

@@ -41,7 +41,7 @@ MainWindow
41 41
       anchors.bottom: parent.bottom
42 42
       margin.bottom: 9
43 43
       margin.right: 9
44
-      onClick: About.openWebpage()
44
+      @onClick: About.openWebpage()
45 45
 
46 46
   HorizontalSeparator
47 47
     anchors.left: parent.left
@@ -58,4 +58,4 @@ MainWindow
58 58
     anchors.top: parent.top
59 59
     margin.top: 191
60 60
     margin.left: 188
61
-    onClick: About.destroy()
61
+    @onClick: About.destroy()

+ 1
- 0
modules/core_styles/core_styles.otmod View File

@@ -11,6 +11,7 @@ Module
11 11
     importStyles 'styles/panels.otui'
12 12
     importStyles 'styles/separators.otui'
13 13
     importStyles 'styles/lineedits.otui'
14
+    importStyles 'styles/checkboxes.otui'
14 15
     importStyles 'styles/windows.otui'
15 16
     importStyles 'styles/listboxes.otui'
16 17
     importStyles 'styles/items.otui'

+ 7
- 7
modules/core_styles/styles/buttons.otui View File

@@ -8,18 +8,18 @@ Button < UIButton
8 8
     source: /core_styles/images/button.png
9 9
     border: 5
10 10
 
11
-  state.hover:
11
+  $hover:
12 12
     border-image:
13 13
       source: /core_styles/images/button_hover.png
14 14
       border: 5
15 15
 
16
-  state.pressed:
16
+  $pressed:
17 17
     text-translate: 1 1
18 18
     border-image:
19 19
       source: /core_styles/images/button_down.png
20 20
       border: 5
21 21
 
22
-  state.disabled:
22
+  $disabled:
23 23
     color: #999999
24 24
     background-color: #ffffff88
25 25
 
@@ -32,14 +32,14 @@ TopButton < UIButton
32 32
     size: 26 25
33 33
     border: 3
34 34
 
35
-  state.hover:
35
+  $hover:
36 36
     border-image:
37 37
       source: /core_styles/images/top_button.png
38 38
       size: 26 25
39 39
       offset: 26 0
40 40
       border: 3
41 41
 
42
-  state.pressed:
42
+  $pressed:
43 43
     text-translate: 1 1
44 44
     border-image:
45 45
       source: /core_styles/images/top_button.png
@@ -47,7 +47,7 @@ TopButton < UIButton
47 47
       offset: 52 0
48 48
       border: 3
49 49
 
50
-  state.disabled:
50
+  $disabled:
51 51
     background-color: #ffffff66
52 52
 
53 53
 MenuButton < UIButton
@@ -58,7 +58,7 @@ MenuButton < UIButton
58 58
     source: /core_styles/images/menu.png
59 59
     size: 64 24
60 60
 
61
-  state.hover:
61
+  $hover:
62 62
     border-image:
63 63
       source: /core_styles/images/menu.png
64 64
       offset: 0 24

+ 1
- 1
modules/core_styles/styles/windows.otui View File

@@ -12,7 +12,7 @@ Window < UIWindow
12 12
     border: 4
13 13
     border.top: 20
14 14
 
15
-  state.pressed:
15
+  $pressed:
16 16
     opacity: 192
17 17
 
18 18
 MiniWindow < UIWindow

+ 3
- 3
modules/entergame/characterlist.otui View File

@@ -8,7 +8,7 @@ CharacterListLabel < Label
8 8
   margin.right: 1
9 9
   margin.top: 1
10 10
 
11
-  state.focus:
11
+  $focus:
12 12
     background-color: #ffffff22
13 13
     color: #ffffff
14 14
 
@@ -55,7 +55,7 @@ MainWindow
55 55
     anchors.bottom: parent.bottom
56 56
     margin.bottom: 16
57 57
     margin.right: 16
58
-    onClick: CharacterList.doLogin()
58
+    @onClick: CharacterList.doLogin()
59 59
 
60 60
   Button
61 61
     id: buttonCancel
@@ -65,4 +65,4 @@ MainWindow
65 65
     anchors.bottom: parent.bottom
66 66
     margin.bottom: 16
67 67
     margin.right: 16
68
-    onClick: CharacterList.destroy()
68
+    @onClick: CharacterList.destroy()

+ 24
- 3
modules/entergame/entergame.otui View File

@@ -1,7 +1,7 @@
1 1
 MainWindow
2 2
   id: enterGame
3 3
   title: Enter Game
4
-  size: 236 160
4
+  size: 236 200
5 5
   onEnter: EnterGame.doLogin()
6 6
   onEscape: EnterGame.hide()
7 7
 
@@ -38,6 +38,27 @@ MainWindow
38 38
     margin.left: 18
39 39
     margin.right: 18
40 40
 
41
+  CheckBox
42
+    id: rememberPasswordBox
43
+    text: Remember password
44
+    anchors.left: parent.left
45
+    anchors.right: parent.right
46
+    anchors.top: prev.bottom
47
+    margin.top: 10
48
+    margin.left: 18
49
+    margin.right: 18
50
+
51
+  CheckBox
52
+    id: autoLoginBox
53
+    text: Auto login
54
+    checked: true
55
+    anchors.left: parent.left
56
+    anchors.right: parent.right
57
+    anchors.top: prev.bottom
58
+    margin.top: 8
59
+    margin.left: 18
60
+    margin.right: 18
61
+
41 62
   Button
42 63
     text: Ok
43 64
     width: 64
@@ -45,7 +66,7 @@ MainWindow
45 66
     anchors.bottom: parent.bottom
46 67
     margin.bottom: 16
47 68
     margin.right: 16
48
-    onClick: EnterGame.doLogin()
69
+    @onClick: EnterGame.doLogin()
49 70
 
50 71
   Button
51 72
     text: Cancel
@@ -54,4 +75,4 @@ MainWindow
54 75
     anchors.bottom: parent.bottom
55 76
     margin.bottom: 16
56 77
     margin.right: 16
57
-    onClick: EnterGame.hide()
78
+    @onClick: EnterGame.hide()

+ 2
- 3
modules/inventory/inventory.lua View File

@@ -17,10 +17,9 @@ local InventorySlotAmmo = 10
17 17
 -- public functions
18 18
 function Inventory.create()
19 19
   window = loadUI("/inventory/inventory.otui", Game.gameRightPanel)
20
-  
20
+
21 21
   local itemWidget = window:getChildById('feet')
22 22
   window:setHeight(itemWidget:getPosition().y + itemWidget:getHeight() - window:getPosition().y)
23
-  
24 23
 end
25 24
 
26 25
 function Inventory.destroy()
@@ -52,7 +51,7 @@ function Inventory.onInventoryChange(slot, item)
52 51
   elseif slot == InventorySlotAmmo then
53 52
     slotId = 'ammo'
54 53
   end
55
-  
54
+
56 55
   local itemWidget = window:getChildById(slotId)
57 56
   itemWidget:setItem(item)
58 57
 end

+ 1
- 1
modules/inventory/itempopupmenu.otui View File

@@ -7,4 +7,4 @@ Panel
7 7
 
8 8
   MenuButton
9 9
     text: Quit
10
-    onClick: exit()
10
+    @onClick: exit()

+ 6
- 6
modules/options/options.otui View File

@@ -10,7 +10,7 @@ MainWindow
10 10
     anchors.top: parent.top
11 11
     margin.left: 18
12 12
     margin.top: 32
13
-    onClick: displayErrorBox("Error", "Not implemented yet")
13
+    @onClick: displayErrorBox("Error", "Not implemented yet")
14 14
 
15 15
   Label
16 16
     text: |-
@@ -28,7 +28,7 @@ MainWindow
28 28
     anchors.top: parent.top
29 29
     margin.left: 18
30 30
     margin.top: 65
31
-    onClick: displayErrorBox("Error", "Not implemented yet")
31
+    @onClick: displayErrorBox("Error", "Not implemented yet")
32 32
 
33 33
   Label
34 34
     text: |-
@@ -46,7 +46,7 @@ MainWindow
46 46
     anchors.top: parent.top
47 47
     margin.left: 18
48 48
     margin.top: 98
49
-    onClick: displayErrorBox("Error", "Not implemented yet")
49
+    @onClick: displayErrorBox("Error", "Not implemented yet")
50 50
 
51 51
   Label
52 52
     text: Customise the console
@@ -62,7 +62,7 @@ MainWindow
62 62
     anchors.top: parent.top
63 63
     margin.left: 18
64 64
     margin.top: 131
65
-    onClick: displayErrorBox("Error", "Not implemented yet")
65
+    @onClick: displayErrorBox("Error", "Not implemented yet")
66 66
 
67 67
   Label
68 68
     text: Edit your hotkey texts
@@ -86,7 +86,7 @@ MainWindow
86 86
     anchors.bottom: parent.bottom
87 87
     margin.left: 18
88 88
     margin.bottom: 60
89
-    onClick: displayErrorBox("Error", "Not implemented yet")
89
+    @onClick: displayErrorBox("Error", "Not implemented yet")
90 90
 
91 91
   Label
92 92
     text: |-
@@ -113,4 +113,4 @@ MainWindow
113 113
     anchors.bottom: parent.bottom
114 114
     margin.right: 10
115 115
     margin.bottom: 10
116
-    onClick: Options.destroy()
116
+    @onClick: Options.destroy()

+ 4
- 4
modules/outfit/outfit.otui View File

@@ -12,7 +12,7 @@ Window
12 12
     margin.left: 20
13 13
     
14 14
   Button
15
-    onClick: Outfit.previousType()
15
+    @onClick: Outfit.previousType()
16 16
     text: <<
17 17
     width: 32
18 18
     margin.top: 3
@@ -20,7 +20,7 @@ Window
20 20
     anchors.left: creature.left
21 21
     
22 22
   Button
23
-    onClick: Outfit.nextType()
23
+    @onClick: Outfit.nextType()
24 24
     text: >>
25 25
     width: 32
26 26
     margin.top: 3
@@ -43,7 +43,7 @@ Window
43 43
     anchors.bottom: parent.bottom
44 44
     margin.bottom: 16
45 45
     margin.right: 16
46
-    onClick: Outfit.accept()
46
+    @onClick: Outfit.accept()
47 47
 
48 48
   Button
49 49
     id: buttonCancel
@@ -53,4 +53,4 @@ Window
53 53
     anchors.bottom: parent.bottom
54 54
     margin.bottom: 16
55 55
     margin.right: 16
56
-    onClick: Outfit.destroy()
56
+    @onClick: Outfit.destroy()

+ 4
- 4
modules/topmenu/topmenu.otui View File

@@ -12,7 +12,7 @@ TopPanel
12 12
     margin.top: 4
13 13
     margin.left: 6
14 14
     tooltip: Options
15
-    onClick: Options.create()
15
+    @onClick: Options.create()
16 16
 
17 17
     UIWidget
18 18
       size: 16 16
@@ -25,7 +25,7 @@ TopPanel
25 25
     anchors.left: prev.right
26 26
     margin.left: 6
27 27
     tooltip: Enter game with a character
28
-    onClick: |
28
+    @onClick: |
29 29
       if Game.isOnline() then
30 30
         CharacterList.show()
31 31
       else
@@ -44,7 +44,7 @@ TopPanel
44 44
     margin.top: 4
45 45
     margin.right: 6
46 46
     tooltip: Logout
47
-    onClick: |
47
+    @onClick: |
48 48
       if Game.isOnline() then
49 49
         Game.logout(false)
50 50
       else
@@ -63,7 +63,7 @@ TopPanel
63 63
     margin.top: 4
64 64
     margin.right: 6
65 65
     tooltip: About OTClient
66
-    onClick: About.create()
66
+    @onClick: About.create()
67 67
 
68 68
     UIWidget
69 69
       size: 16 16

+ 5
- 1
src/framework/const.h View File

@@ -246,12 +246,16 @@ namespace Fw
246 246
     };
247 247
 
248 248
     enum WidgetState {
249
+        InvalidState = -1,
249 250
         DefaultState = 0,
250 251
         ActiveState = 1,
251 252
         FocusState = 2,
252 253
         HoverState = 4,
253 254
         PressedState = 8,
254
-        DisabledState = 16
255
+        DisabledState = 16,
256
+        CheckedState = 32,
257
+        OnState = 64,
258
+        LastState = 128
255 259
         //FirstState,
256 260
         //MiddleState,
257 261
         //LastState,

+ 0
- 1
src/framework/core/resourcemanager.cpp View File

@@ -44,7 +44,6 @@ void ResourceManager::init(const char* argv0, const char *appName)
44 44
 
45 45
     bool found = false;
46 46
     for(const std::string& dir : possibleDirs) {
47
-        dump << dir;
48 47
         if(g_resources.addToSearchPath(dir)) {
49 48
             logInfo("Using modules directory '", dir.c_str(), "'");
50 49
             found = true;

+ 0
- 1
src/framework/global.h View File

@@ -64,7 +64,6 @@
64 64
 // additional utilities
65 65
 #include "util/types.h"
66 66
 #include "util/tools.h"
67
-#include "util/translator.h"
68 67
 #include "util/point.h"
69 68
 #include "util/color.h"
70 69
 #include "util/rect.h"

+ 4
- 0
src/framework/luascript/luafunctions.cpp View File

@@ -129,6 +129,10 @@ void LuaInterface::registerFunctions()
129 129
     g_lua.bindClassMemberFunction<UILineEdit>("clearText", &UILineEdit::clearText);
130 130
     g_lua.bindClassMemberFunction<UILineEdit>("getCursorPos", &UILineEdit::getCursorPos);
131 131
 
132
+    // UICheckBox
133
+    g_lua.registerClass<UICheckBox, UIWidget>();
134
+    g_lua.bindClassStaticFunction<UICheckBox>("create", &UIWidget::create<UICheckBox>);
135
+
132 136
     // UIWindow
133 137
     g_lua.registerClass<UIWindow, UIWidget>();
134 138
     g_lua.bindClassStaticFunction<UIWindow>("create", &UIWidget::create<UIWindow>);

+ 6
- 3
src/framework/ui/declarations.h View File

@@ -24,15 +24,16 @@
24 24
 #define FRAMEWORK_UI_DECLARATIONS_H
25 25
 
26 26
 #include <framework/global.h>
27
-#include <framework/platform/platformevent.h>
28 27
 
29 28
 class UIManager;
30 29
 class UIWidget;
31 30
 class UILabel;
32 31
 class UIButton;
33 32
 class UILineEdit;
34
-class UIWindow;
33
+class UICheckBox;
34
+class UIProgressBar;
35 35
 class UIFrameCounter;
36
+class UIWindow;
36 37
 class UILayout;
37 38
 class UIVerticalLayout;
38 39
 class UIAnchorLayout;
@@ -43,8 +44,10 @@ typedef std::weak_ptr<UIWidget> UIWidgetWeakPtr;
43 44
 typedef std::shared_ptr<UILabel> UILabelPtr;
44 45
 typedef std::shared_ptr<UIButton> UIButtonPtr;
45 46
 typedef std::shared_ptr<UILineEdit> UILineEditPtr;
47
+typedef std::shared_ptr<UICheckBox> UICheckBoxPtr;
48
+typedef std::shared_ptr<UIProgressBar> UIProgressBarPtr;
49
+typedef std::shared_ptr<UIFrameCounter> UIFrameCounterPtr;
46 50
 typedef std::shared_ptr<UIWindow> UIWindowPtr;
47
-typedef std::shared_ptr<UIWindow> UIFrameCounterPtr;
48 51
 typedef std::shared_ptr<UILayout> UILayoutPtr;
49 52
 typedef std::shared_ptr<UIVerticalLayout> UIVerticalLayoutPtr;
50 53
 typedef std::shared_ptr<UIAnchorLayout> UIAnchorLayoutPtr;

+ 1
- 0
src/framework/ui/ui.h View File

@@ -31,5 +31,6 @@
31 31
 #include "uiwindow.h"
32 32
 #include "uiframecounter.h"
33 33
 #include "uiprogressbar.h"
34
+#include "uicheckbox.h"
34 35
 
35 36
 #endif

+ 3
- 3
src/framework/ui/uibutton.cpp View File

@@ -40,7 +40,7 @@ void UIButton::render()
40 40
 {
41 41
     UIWidget::render();
42 42
     Rect textRect = m_rect;
43
-    textRect.translate(m_textTranslate);
43
+    textRect.translate(m_textOffset);
44 44
     m_font->renderText(m_text, textRect, Fw::AlignCenter, m_foregroundColor);
45 45
 }
46 46
 
@@ -49,8 +49,8 @@ void UIButton::onStyleApply(const OTMLNodePtr& styleNode)
49 49
     UIWidget::onStyleApply(styleNode);
50 50
 
51 51
     for(OTMLNodePtr node : styleNode->children()) {
52
-        if(node->tag() == "text-translate") {
53
-            m_textTranslate = node->value<Point>();
52
+        if(node->tag() == "text-offset") {
53
+            m_textOffset = node->value<Point>();
54 54
         } else if(node->tag() == "text") {
55 55
             m_text = node->value();
56 56
         }

+ 1
- 1
src/framework/ui/uibutton.h View File

@@ -44,7 +44,7 @@ protected:
44 44
     virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button);
45 45
 
46 46
     SimpleCallback m_onClick;
47
-    Point m_textTranslate;
47
+    Point m_textOffset;
48 48
     std::string m_text;
49 49
 };
50 50
 

+ 66
- 0
src/framework/ui/uicheckbox.cpp View File

@@ -0,0 +1,66 @@
1
+/*
2
+ * Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ * THE SOFTWARE.
21
+ */
22
+
23
+#include "uicheckbox.h"
24
+#include <framework/otml/otmlnode.h>
25
+#include <framework/graphics/image.h>
26
+#include <framework/graphics/font.h>
27
+#include <framework/graphics/graphics.h>
28
+#include <framework/core/eventdispatcher.h>
29
+
30
+void UICheckBox::render()
31
+{
32
+    Rect boxRect;
33
+    boxRect.setSize(m_boxSize);
34
+    boxRect.moveLeft(m_rect.left());
35
+    boxRect.moveVerticalCenter(m_rect.verticalCenter());
36
+    g_graphics.bindColor(m_backgroundColor);
37
+    m_image->draw(boxRect);
38
+
39
+    Rect textRect(m_rect);
40
+    textRect.setTopLeft(textRect.topLeft() + m_textOffset);
41
+    m_font->renderText(m_text, textRect, Fw::AlignLeft, m_foregroundColor);
42
+}
43
+
44
+void UICheckBox::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
45
+{
46
+    if(isPressed() && getRect().contains(mousePos))
47
+        setState(Fw::CheckedState, !isChecked());
48
+}
49
+
50
+void UICheckBox::onStyleApply(const OTMLNodePtr& styleNode)
51
+{
52
+    UIWidget::onStyleApply(styleNode);
53
+
54
+    for(OTMLNodePtr node : styleNode->children()) {
55
+        if(node->tag() == "text-offset")
56
+            m_textOffset = node->value<Point>();
57
+        else if(node->tag() == "text")
58
+            m_text = node->value();
59
+        else if(node->tag() == "box-size")
60
+            m_boxSize = node->value<Size>();
61
+        else if(node->tag() == "checked") {
62
+            // must be scheduled because setChecked can change the style again
63
+            g_dispatcher.addEvent(std::bind(&UICheckBox::setChecked, asUICheckBox(), node->value<bool>()));
64
+        }
65
+    }
66
+}

+ 50
- 0
src/framework/ui/uicheckbox.h View File

@@ -0,0 +1,50 @@
1
+/*
2
+ * Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ * THE SOFTWARE.
21
+ */
22
+
23
+#ifndef UICHECKBOX_H
24
+#define UICHECKBOX_H
25
+
26
+#include "uiwidget.h"
27
+
28
+class UICheckBox : public UIWidget
29
+{
30
+public:
31
+    void render();
32
+
33
+    bool isChecked() { return hasState(Fw::CheckedState); }
34
+    void setChecked(bool checked) { setState(Fw::CheckedState, checked); }
35
+
36
+    void setText(const std::string& text) { m_text = text; }
37
+    std::string getText() { return m_text; }
38
+
39
+    UICheckBoxPtr asUICheckBox() { return std::static_pointer_cast<UICheckBox>(shared_from_this()); }
40
+
41
+protected:
42
+    virtual void onStyleApply(const OTMLNodePtr& styleNode);
43
+    virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button);
44
+
45
+    std::string m_text;
46
+    Size m_boxSize;
47
+    Point m_textOffset;
48
+};
49
+
50
+#endif

+ 1
- 0
src/framework/ui/uiframecounter.cpp View File

@@ -21,6 +21,7 @@
21 21
  */
22 22
 
23 23
 #include "uiframecounter.h"
24
+#include "uitranslator.h"
24 25
 #include <framework/graphics/font.h>
25 26
 #include <framework/otml/otmlnode.h>
26 27
 #include <framework/platform/platform.h>

+ 1
- 0
src/framework/ui/uilabel.cpp View File

@@ -21,6 +21,7 @@
21 21
  */
22 22
 
23 23
 #include "uilabel.h"
24
+#include "uitranslator.h"
24 25
 #include <framework/graphics/font.h>
25 26
 #include <framework/otml/otmlnode.h>
26 27
 

+ 90
- 0
src/framework/ui/uitranslator.cpp View File

@@ -0,0 +1,90 @@
1
+/*
2
+ * Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ * THE SOFTWARE.
21
+ */
22
+
23
+#include "uitranslator.h"
24
+#include <boost/algorithm/string.hpp>
25
+
26
+Fw::AlignmentFlag Fw::translateAlignment(std::string aligment)
27
+{
28
+    boost::to_lower(aligment);
29
+    boost::erase_all(aligment, " ");
30
+    if(aligment == "topleft")
31
+        return Fw::AlignTopLeft;
32
+    else if(aligment == "topright")
33
+        return Fw::AlignTopRight;
34
+    else if(aligment == "bottomleft")
35
+        return Fw::AlignBottomLeft;
36
+    else if(aligment == "bottomright")
37
+        return Fw::AlignBottomRight;
38
+    else if(aligment == "left")
39
+        return Fw::AlignLeftCenter;
40
+    else if(aligment == "right")
41
+        return Fw::AlignRightCenter;
42
+    else if(aligment == "top")
43
+        return Fw::AlignTopCenter;
44
+    else if(aligment == "bottom")
45
+        return Fw::AlignBottomCenter;
46
+    else if(aligment == "center")
47
+        return Fw::AlignCenter;
48
+    return Fw::AlignNone;
49
+}
50
+
51
+Fw::AnchorEdge Fw::translateAnchorEdge(std::string anchorEdge)
52
+{
53
+    boost::to_lower(anchorEdge);
54
+    boost::erase_all(anchorEdge, " ");
55
+    if(anchorEdge == "left")
56
+        return Fw::AnchorLeft;
57
+    else if(anchorEdge == "right")
58
+        return Fw::AnchorRight;
59
+    else if(anchorEdge == "top")
60
+        return Fw::AnchorTop;
61
+    else if(anchorEdge == "bottom")
62
+        return Fw::AnchorBottom;
63
+    else if(anchorEdge == "horizontalcenter")
64
+        return Fw::AnchorHorizontalCenter;
65
+    else if(anchorEdge == "verticalcenter")
66
+        return Fw::AnchorVerticalCenter;
67
+    return Fw::AnchorNone;
68
+}
69
+
70
+Fw::WidgetState Fw::translateState(std::string state)
71
+{
72
+    boost::to_lower(state);
73
+    boost::erase_all(state, " ");
74
+    if(state == "active")
75
+        return Fw::ActiveState;
76
+    else if(state == "focus")
77
+        return Fw::FocusState;
78
+    else if(state == "hover")
79
+        return Fw::HoverState;
80
+    else if(state == "pressed")
81
+        return Fw::PressedState;
82
+    else if(state == "checked")
83
+        return Fw::CheckedState;
84
+    else if(state == "disabled")
85
+        return Fw::DisabledState;
86
+    else if(state == "on")
87
+        return Fw::OnState;
88
+    else
89
+        return Fw::InvalidState;
90
+}

+ 37
- 0
src/framework/ui/uitranslator.h View File

@@ -0,0 +1,37 @@
1
+/*
2
+ * Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ * THE SOFTWARE.
21
+ */
22
+
23
+#ifndef TRANSLATOR_H
24
+#define TRANSLATOR_H
25
+
26
+#include "../const.h"
27
+#include <string>
28
+
29
+namespace Fw {
30
+
31
+AlignmentFlag translateAlignment(std::string aligment);
32
+AnchorEdge translateAnchorEdge(std::string anchorEdge);
33
+WidgetState translateState(std::string state);
34
+
35
+};
36
+
37
+#endif

+ 69
- 34
src/framework/ui/uiwidget.cpp View File

@@ -24,6 +24,7 @@
24 24
 #include "uimanager.h"
25 25
 #include "uianchorlayout.h"
26 26
 #include "uiverticallayout.h"
27
+#include "uitranslator.h"
27 28
 
28 29
 #include <framework/core/eventdispatcher.h>
29 30
 #include <framework/graphics/image.h>
@@ -36,6 +37,7 @@
36 37
 UIWidget::UIWidget()
37 38
 {
38 39
     m_updateEventScheduled = false;
40
+    m_firstOnStyle = true;
39 41
     m_states = Fw::DefaultState;
40 42
 
41 43
     // generate an unique id, this is need because anchored layouts find widgets by id
@@ -611,6 +613,28 @@ void UIWidget::updateLayout()
611 613
         m_layout->update();
612 614
 }
613 615
 
616
+void UIWidget::setState(Fw::WidgetState state, bool on)
617
+{
618
+    if(state == Fw::InvalidState)
619
+        return;
620
+
621
+    int oldStates = m_states;
622
+    if(on)
623
+        m_states |= state;
624
+    else
625
+        m_states &= ~state;
626
+
627
+    if(oldStates != m_states)
628
+        updateStyle();
629
+}
630
+
631
+bool UIWidget::hasState(Fw::WidgetState state)
632
+{
633
+    if(state == Fw::InvalidState)
634
+        return false;
635
+    return (m_states & state);
636
+}
637
+
614 638
 void UIWidget::updateState(Fw::WidgetState state)
615 639
 {
616 640
     bool newStatus = true;
@@ -675,12 +699,7 @@ void UIWidget::updateState(Fw::WidgetState state)
675 699
     }
676 700
 
677 701
     if(newStatus != oldStatus) {
678
-        if(newStatus)
679
-            m_states |= state;
680
-        else
681
-            m_states &= ~state;
682
-
683
-        updateStyle();
702
+        setState(state, newStatus);
684 703
 
685 704
         if(state == Fw::FocusState) {
686 705
             g_dispatcher.addEvent(std::bind(&UIWidget::onFocusChange, asUIWidget(), newStatus, m_lastFocusReason));
@@ -691,10 +710,8 @@ void UIWidget::updateState(Fw::WidgetState state)
691 710
 
692 711
 void UIWidget::updateStates()
693 712
 {
694
-    updateState(Fw::ActiveState);
695
-    updateState(Fw::FocusState);
696
-    updateState(Fw::DisabledState);
697
-    updateState(Fw::HoverState);
713
+    for(int state = 1; state != Fw::LastState; state <<= 1)
714
+        updateState((Fw::WidgetState)state);
698 715
 }
699 716
 
700 717
 void UIWidget::updateStyle()
@@ -712,26 +729,32 @@ void UIWidget::updateStyle()
712 729
         }
713 730
     }
714 731
 
715
-    // merge states styles, NOTE: order does matter
716
-    OTMLNodePtr style = m_style->get("state.active");
717
-    if(style && hasState(Fw::ActiveState))
718
-        newStateStyle->merge(style);
719
-
720
-    style = m_style->get("state.focus");
721
-    if(style && hasState(Fw::FocusState))
722
-        newStateStyle->merge(style);
723
-
724
-    style = m_style->get("state.hover");
725
-    if(style && hasState(Fw::HoverState))
726
-        newStateStyle->merge(style);
727
-
728
-    style = m_style->get("state.pressed");
729
-    if(style && hasState(Fw::PressedState))
730
-        newStateStyle->merge(style);
732
+    // checks for states combination
733
+    for(const OTMLNodePtr& style : m_style->children()) {
734
+        if(boost::starts_with(style->tag(), "$")) {
735
+            std::string statesStr = style->tag().substr(1);
736
+            std::vector<std::string> statesSplit;
737
+            boost::split(statesSplit, statesStr, boost::is_any_of(std::string(" ")));
738
+
739
+            bool match = true;
740
+            for(std::string stateStr : statesSplit) {
741
+                if(stateStr.length() == 0)
742
+                    continue;
743
+
744
+                bool notstate = (stateStr[0] == '!');
745
+                if(notstate)
746
+                    stateStr = stateStr.substr(1);
747
+
748
+                bool stateOn = hasState(Fw::translateState(stateStr));
749
+                if((!notstate && !stateOn) || (notstate && stateOn))
750
+                    match = false;
751
+            }
731 752
 
732
-    style = m_style->get("state.disabled");
733
-    if(style && hasState(Fw::DisabledState))
734
-        newStateStyle->merge(style);
753
+            // merge states styles
754
+            if(match)
755
+                newStateStyle->merge(style);
756
+        }
757
+    }
735 758
 
736 759
     applyStyle(newStateStyle);
737 760
     m_stateStyle = newStateStyle;
@@ -886,13 +909,25 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
886 909
 
887 910
                 anchorLayout->addAnchor(asUIWidget(), anchoredEdge, hookedWidgetId, hookedEdge);
888 911
             }
889
-        } else if(node->tag() == "onClick" ||
890
-                  node->tag() == "onMousePress" ||
891
-                  node->tag() == "onHoverChange") {
892
-            g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
893
-            luaSetField(node->tag());
912
+        // lua functions
913
+        } else if(boost::starts_with(node->tag(), "@")) {
914
+            // on load once
915
+            if(m_firstOnStyle) {
916
+                std::string funcName = node->tag().substr(1);
917
+                std::string funcOrigin = "@" + node->source() + "[" + node->tag() + "]";
918
+                g_lua.loadFunction(node->value(), funcOrigin);
919
+                luaSetField(funcName);
920
+            }
921
+        // lua fields value
922
+        } else if(boost::starts_with(node->tag(), "&")) {
923
+            std::string fieldName = node->tag().substr(1);
924
+            std::string fieldOrigin = "@" + node->source() + "[" + node->tag() + "]";
925
+            g_lua.evaluateExpression(node->value(), fieldOrigin);
926
+            luaSetField(fieldName);
894 927
         }
895 928
     }
929
+
930
+    m_firstOnStyle = false;
896 931
 }
897 932
 
898 933
 void UIWidget::onGeometryUpdate(const Rect& oldRect, const Rect& newRect)

+ 46
- 44
src/framework/ui/uiwidget.h View File

@@ -80,49 +80,48 @@ public:
80 80
     void unlock();
81 81
     void focus();
82 82
 
83
-    bool isActive() const { return hasState(Fw::ActiveState); }
84
-    bool isEnabled() const { return !hasState(Fw::DisabledState); }
85
-    bool isDisabled() const { return hasState(Fw::DisabledState); }
86
-    bool isFocused() const { return hasState(Fw::FocusState); }
87
-    bool isHovered() const { return hasState(Fw::HoverState); }
88
-    bool isPressed() const { return hasState(Fw::PressedState); }
83
+    bool isActive()  { return hasState(Fw::ActiveState); }
84
+    bool isEnabled()  { return !hasState(Fw::DisabledState); }
85
+    bool isDisabled()  { return hasState(Fw::DisabledState); }
86
+    bool isFocused()  { return hasState(Fw::FocusState); }
87
+    bool isHovered()  { return hasState(Fw::HoverState); }
88
+    bool isPressed()  { return hasState(Fw::PressedState); }
89 89
     bool isVisible();
90 90
     bool isHidden() { return !isVisible(); }
91
-    bool isExplicitlyEnabled() const { return m_enabled; }
92
-    bool isExplicitlyVisible() const { return m_visible; }
93
-    bool isFocusable() const { return m_focusable; }
94
-    bool isPhantom() const { return m_phantom; }
95
-    bool isSizeFixed() const { return m_fixedSize; }
96
-    bool hasChildren() const { return m_children.size() > 0; }
91
+    bool isExplicitlyEnabled()  { return m_enabled; }
92
+    bool isExplicitlyVisible()  { return m_visible; }
93
+    bool isFocusable()  { return m_focusable; }
94
+    bool isPhantom()  { return m_phantom; }
95
+    bool isSizeFixed()  { return m_fixedSize; }
96
+    bool hasChildren()  { return m_children.size() > 0; }
97 97
     bool hasChild(const UIWidgetPtr& child);
98
-    bool hasState(Fw::WidgetState state) const { return m_states & state; }
99 98
 
100
-    std::string getId() const { return m_id; }
101
-    int getChildCount() const { return m_children.size(); }
102
-    UILayoutPtr getLayout() const { return m_layout; }
103
-    UIWidgetPtr getParent() const { return m_parent.lock(); }
99
+    std::string getId()  { return m_id; }
100
+    int getChildCount()  { return m_children.size(); }
101
+    UILayoutPtr getLayout()  { return m_layout; }
102
+    UIWidgetPtr getParent()  { return m_parent.lock(); }
104 103
     UIWidgetPtr getRootParent();
105
-    Point getPosition() const { return m_rect.topLeft(); }
106
-    Size getSize() const { return m_rect.size(); }
107
-    Rect getRect() const { return m_rect; }
108
-    int getX() const { return m_rect.x(); }
109
-    int getY() const { return m_rect.y(); }
110
-    int getWidth() const { return m_rect.width(); }
111
-    int getHeight() const { return m_rect.height(); }
112
-    ImagePtr getImage() const { return m_image; }
113
-    FontPtr getFont() const { return m_font; }
114
-    Color getForegroundColor() const { return m_foregroundColor; }
115
-    Color getBackgroundColor() const { return m_backgroundColor; }
116
-    int getOpacity() const { return m_opacity; }
117
-    int getMarginLeft() const { return m_marginLeft; }
118
-    int getMarginRight() const { return m_marginRight; }
119
-    int getMarginTop() const { return m_marginTop; }
120
-    int getMarginBottom() const { return m_marginBottom; }
121
-    Fw::FocusReason getLastFocusReason() const { return m_lastFocusReason; }
122
-    OTMLNodePtr getStyle() const { return m_style; }
123
-
124
-    UIWidgetList getChildren() const { return m_children; }
125
-    UIWidgetPtr getFocusedChild() const { return m_focusedChild; }
104
+    Point getPosition()  { return m_rect.topLeft(); }
105
+    Size getSize()  { return m_rect.size(); }
106
+    Rect getRect()  { return m_rect; }
107
+    int getX()  { return m_rect.x(); }
108
+    int getY()  { return m_rect.y(); }
109
+    int getWidth()  { return m_rect.width(); }
110
+    int getHeight()  { return m_rect.height(); }
111
+    ImagePtr getImage()  { return m_image; }
112
+    FontPtr getFont()  { return m_font; }
113
+    Color getForegroundColor()  { return m_foregroundColor; }
114
+    Color getBackgroundColor()  { return m_backgroundColor; }
115
+    int getOpacity()  { return m_opacity; }
116
+    int getMarginLeft()  { return m_marginLeft; }
117
+    int getMarginRight()  { return m_marginRight; }
118
+    int getMarginTop()  { return m_marginTop; }
119
+    int getMarginBottom()  { return m_marginBottom; }
120
+    Fw::FocusReason getLastFocusReason()  { return m_lastFocusReason; }
121
+    OTMLNodePtr getStyle()  { return m_style; }
122
+
123
+    UIWidgetList getChildren()  { return m_children; }
124
+    UIWidgetPtr getFocusedChild()  { return m_focusedChild; }
126 125
     UIWidgetPtr getChildAfter(const UIWidgetPtr& relativeChild);
127 126
     UIWidgetPtr getChildBefore(const UIWidgetPtr& relativeChild);
128 127
     UIWidgetPtr getChildById(const std::string& childId);
@@ -147,16 +146,17 @@ public:
147 146
 
148 147
     void updateParentLayout();
149 148
     void updateLayout();
150
-    virtual void updateState(Fw::WidgetState state);
149
+
151 150
     void updateStates();
152
-    virtual void updateStyle();
151
+    virtual void updateState(Fw::WidgetState state);
152
+    void setState(Fw::WidgetState state, bool on);
153
+    bool hasState(Fw::WidgetState state);
154
+
155
+    void updateStyle();
153 156
     void applyStyle(const OTMLNodePtr& styleNode);
154 157
 
155 158
     UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
156 159
 
157
-private:
158
-    bool m_updateEventScheduled;
159
-
160 160
 protected:
161 161
     /// Triggered when widget style is changed
162 162
     virtual void onStyleApply(const OTMLNodePtr& styleNode);
@@ -190,6 +190,8 @@ protected:
190 190
     bool m_fixedSize;
191 191
     bool m_pressed;
192 192
     bool m_phantom;
193
+    bool m_updateEventScheduled;
194
+    bool m_firstOnStyle;
193 195
     Rect m_rect;
194 196
     UILayoutPtr m_layout;
195 197
     UIWidgetWeakPtr m_parent;
@@ -198,7 +200,7 @@ protected:
198 200
     UIWidgetPtr m_focusedChild;
199 201
     OTMLNodePtr m_style;
200 202
     OTMLNodePtr m_stateStyle;
201
-    uint m_states;
203
+    int m_states;
202 204
 
203 205
     // basic style components used by all widgets
204 206
     ImagePtr m_image;

+ 1
- 0
src/framework/ui/uiwindow.cpp View File

@@ -21,6 +21,7 @@
21 21
  */
22 22
 
23 23
 #include "uiwindow.h"
24
+#include "uitranslator.h"
24 25
 #include <framework/graphics/borderimage.h>
25 26
 #include <framework/graphics/font.h>
26 27
 #include <framework/graphics/graphics.h>

Loading…
Cancel
Save