Browse Source

ui changes

* create UIResizeBorder
* restore miniwindow
* scroll fixes
Eduardo Bart 9 years ago
parent
commit
060c1cf8e7

+ 4
- 0
modules/client_terminal/terminal.lua View File

@@ -114,11 +114,15 @@ function Terminal.init()
114 114
   terminalWindow.onDoubleClick = function(self)
115 115
     if poped then
116 116
       self:fill('parent')
117
+      self:getChildById('bottomResizeBorder'):disable()
118
+      self:getChildById('rightResizeBorder'):disable()
117 119
       poped = false
118 120
     else
119 121
       self:breakAnchors()
120 122
       self:resize(g_window.getWidth()/2, g_window.getHeight()/2)
121 123
       self:move(g_window.getWidth()/2, g_window.getHeight()/2)
124
+      self:getChildById('bottomResizeBorder'):enable()
125
+      self:getChildById('rightResizeBorder'):enable()
122 126
       poped = true
123 127
     end
124 128
   end

+ 13
- 1
modules/client_terminal/terminal.otui View File

@@ -41,4 +41,16 @@ UIWindow
41 41
     margin-left: 5
42 42
     font: terminus-14px-bold
43 43
 
44
-  
44
+  ResizeBorder
45
+    id: bottomResizeBorder
46
+    anchors.bottom: parent.bottom
47
+    anchors.left: parent.left
48
+    anchors.right: parent.right
49
+    enabled: false
50
+
51
+  ResizeBorder
52
+    id: rightResizeBorder
53
+    anchors.right: parent.right
54
+    anchors.top: parent.top
55
+    anchors.bottom: parent.bottom
56
+    enabled: false

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

@@ -42,4 +42,5 @@ Module
42 42
     dofile 'widgets/uisplitter'
43 43
     dofile 'widgets/uiscrollbar'
44 44
     dofile 'widgets/uiscrollarea'
45
+    dofile 'widgets/uiresizeborder'
45 46
 

+ 88
- 0
modules/core_lib/widgets/uiresizeborder.lua View File

@@ -0,0 +1,88 @@
1
+UIResizeBorder = extends(UIWidget)
2
+
3
+function UIResizeBorder.create()
4
+  local resizeborder = UIResizeBorder.internalCreate()
5
+  resizeborder:setFocusable(false)
6
+  resizeborder.minimum = 0
7
+  resizeborder.maximum = 1000
8
+  return resizeborder
9
+end
10
+
11
+function UIResizeBorder:onHoverChange(hovered)
12
+  if hovered then
13
+    if self:getWidth() > self:getHeight() then
14
+      Mouse.setVerticalCursor()
15
+      self.vertical = true
16
+    else
17
+      Mouse.setHorizontalCursor()
18
+      self.vertical = false
19
+    end
20
+    if not self:isPressed() then
21
+      Effects.fadeIn(self)
22
+    end
23
+  else
24
+    if not self:isPressed() then
25
+      Mouse.restoreCursor()
26
+      Effects.fadeOut(self)
27
+    end
28
+  end
29
+end
30
+
31
+function UIResizeBorder:onMouseMove(mousePos, mouseMoved)
32
+  if self:isPressed() then
33
+    if self.vertical then
34
+      local delta = mousePos.y - self:getY() - self:getHeight()/2
35
+      local parent = self:getParent()
36
+      local newsize = math.min(math.max(parent:getHeight() + delta, self.minimum), self.maximum)
37
+      if newsize ~= currentMargin then
38
+        self.newsize = newsize
39
+        if not self.event or self.event:isExecuted() then
40
+          self.event = addEvent(function()
41
+            parent:setHeight(self.newsize)
42
+          end)
43
+        end
44
+      end
45
+    else
46
+      local delta = mousePos.x - self:getX() - self:getWidth()/2
47
+      local parent = self:getParent()
48
+      local newsize = math.min(math.max(parent:getWidth() + delta, self.minimum), self.maximum)
49
+      if newsize ~= currentMargin then
50
+        self.newsize = newsize
51
+        if not self.event or self.event:isExecuted() then
52
+          self.event = addEvent(function()
53
+            parent:setWidth(self.newsize)
54
+          end)
55
+        end
56
+      end
57
+    end
58
+    return true
59
+  end
60
+end
61
+
62
+function UIResizeBorder:onMouseRelease(mousePos, mouseButton)
63
+  if not self:isHovered() then
64
+    Mouse.restoreCursor()
65
+    Effects.fadeOut(self)
66
+  end
67
+end
68
+
69
+function UIResizeBorder:onStyleApply(styleName, styleNode)
70
+  for name,value in pairs(styleNode) do
71
+    if name == 'maximum' then
72
+      self:setMaximum(tonumber(value))
73
+    elseif name == 'minimum' then
74
+      self:setMinimum(tonumber(value))
75
+    end
76
+  end
77
+end
78
+
79
+function UIResizeBorder:setMaximum(maximum)
80
+  self.maximum  = maximum
81
+end
82
+
83
+function UIResizeBorder:setMinimum(minimum)
84
+  self.minimum = minimum
85
+end
86
+
87
+function UIResizeBorder:getMaximum() return self.maximum end
88
+function UIResizeBorder:getMinimum() return self.minimum end

+ 2
- 0
modules/core_lib/widgets/uisplitter.lua View File

@@ -33,6 +33,7 @@ function UISplitter:onMouseMove(mousePos, mouseMoved)
33 33
     if self.vertical then
34 34
       local delta = mousePos.y - self:getY() - self:getHeight()/2
35 35
       local newMargin = self:canUpdateMargin(self:getMarginBottom() - delta)
36
+      local currentMargin = self:getMarginBottom()
36 37
       if newMargin ~= currentMargin then
37 38
         self.newMargin = newMargin
38 39
         if not self.event or self.event:isExecuted() then
@@ -44,6 +45,7 @@ function UISplitter:onMouseMove(mousePos, mouseMoved)
44 45
     else
45 46
       local delta = mousePos.x - self:getX() - self:getWidth()/2
46 47
       local newMargin = self:canUpdateMargin(self:getMarginRight() - delta)
48
+      local currentMargin = self:getMarginRight()
47 49
       if newMargin ~= currentMargin then
48 50
         self.newMargin = newMargin
49 51
         if not self.event or self.event:isExecuted() then

+ 9
- 0
modules/core_styles/styles/splitters.otui View File

@@ -0,0 +1,9 @@
1
+Splitter < UISplitter
2
+  size: 4 4
3
+  opacity: 0
4
+  background: #ffffff44
5
+
6
+ResizeBorder < UIResizeBorder
7
+  size: 4 4
8
+  opacity: 0
9
+  background: #ffffff44

+ 2
- 0
modules/game/game.otmod View File

@@ -30,6 +30,8 @@ Module
30 30
 
31 31
     dofile 'widgets/uigamemap'
32 32
     dofile 'widgets/uiitem'
33
+    dofile 'widgets/uiminiwindow'
34
+    dofile 'widgets/uiminiwindowcontainer'
33 35
 
34 36
     dofile 'creature'
35 37
     dofile 'player'

+ 1
- 1
modules/game/gameinterface.otui View File

@@ -1,4 +1,4 @@
1
-GameSidePanel < Panel
1
+GameSidePanel < UIMiniWindowContainer
2 2
   image-source: images/sidepanel.png
3 3
   image-border: 4
4 4
 

+ 28
- 3
modules/game/styles/miniwindow.otui View File

@@ -10,14 +10,39 @@ MiniWindow < UIMiniWindow
10 10
   margin-left: 6
11 11
   margin-right: 6
12 12
   move-policy: free updated
13
-  image-source: /core_styles/styles/images/mini_window.png
13
+  image-source: /game/images/miniwindow.png
14 14
   image-border: 4
15 15
   image-border-top: 23
16
-  padding: 25 8 2 8
16
+  image-border-left: 23
17 17
 
18 18
   $on:
19 19
     height: 24
20 20
     image-border-bottom: 1
21 21
 
22
+  ResizeBorder
23
+    id: bottomResizeBorder
24
+    anchors.bottom: parent.bottom
25
+    anchors.left: parent.left
26
+    anchors.right: parent.right
27
+    height: 2
28
+    margin-bottom: 1
29
+    minimum: 70
30
+
31
+  VerticalScrollBar
32
+    id: miniwindowScrollBar
33
+    anchors.top: parent.top
34
+    anchors.bottom: parent.bottom
35
+    anchors.right: parent.right
36
+    step: 14
37
+    margin-top: 22
38
+    margin-right: 2
39
+    margin-bottom: 2
40
+    fade-effect: false
41
+
42
+MiniWindowContents < ScrollablePanel
43
+  anchors.fill: parent
44
+  padding: 25 21 2 8
45
+  vertical-scrollbar: miniwindowScrollBar
46
+
22 47
 BorderlessGameWindow < UIWindow
23
-  focusable: false
48
+  focusable: false

+ 36
- 0
modules/game/widgets/uiminiwindow.lua View File

@@ -0,0 +1,36 @@
1
+UIMiniWindow = extends(UIWindow)
2
+
3
+function UIMiniWindow.create()
4
+  local miniwindow = UIMiniWindow.internalCreate()
5
+  return miniwindow
6
+end
7
+
8
+function UIMiniWindow:onDragEnter(mousePos)
9
+  local parent = self:getParent()
10
+  if not parent then return false end
11
+
12
+  if parent:getClassName() == 'UIMiniWindowContainer' then
13
+    local containerParent = parent:getParent()
14
+    parent:removeChild(self)
15
+    containerParent:addChild(self)
16
+  end
17
+
18
+  local oldPos = self:getPosition()
19
+  self.movingReference = { x = mousePos.x - oldPos.x, y = mousePos.y - oldPos.y }
20
+  self:setPosition(oldPos)
21
+  return true
22
+end
23
+
24
+function UIMiniWindow:onDragLeave(droppedWidget, mousePos)
25
+  -- TODO: drop on other interfaces
26
+end
27
+
28
+function UIMiniWindow:onFocusChange(focused)
29
+  -- miniwindows only raises when its outside MiniWindowContainers
30
+  if not focused then return end
31
+  local parent = self:getParent()
32
+  if parent and parent:getClassName() ~= 'UIMiniWindowContainer' then
33
+    self:raise()
34
+  end
35
+end
36
+

+ 4
- 0
modules/game/widgets/uiminiwindowcontainer.lua View File

@@ -7,6 +7,10 @@ function UIMiniWindowContainer.create()
7 7
   return container
8 8
 end
9 9
 
10
+function UIMiniWindowContainer:onDrop(widget, mousePos)
11
+  print 'drop'
12
+end
13
+
10 14
 function UIMiniWindowContainer:getClassName()
11 15
   return 'UIMiniWindowContainer'
12 16
 end

+ 1
- 1
modules/game_inventory/inventory.lua View File

@@ -13,7 +13,7 @@ function Inventory.init()
13 13
 
14 14
   Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
15 15
 
16
-  inventoryWindow = displayUI('inventory.otui', GameInterface.getRightPanel())
16
+  inventoryWindow = displayUI('inventory.otui', GameInterface.getRightPanel()):getChildById('inventoryWindow')
17 17
   inventoryButton = TopMenu.addGameToggleButton('inventoryButton', 'Inventory (Ctrl+I)', 'inventory.png', Inventory.toggle)
18 18
   inventoryButton:setOn(true)
19 19
 

+ 98
- 96
modules/game_inventory/inventory.otui View File

@@ -1,111 +1,113 @@
1
-BorderlessGameWindow
2
-  id: inventoryWindow
1
+MiniWindow
2
+  text: Inventory
3
+  icon: inventory.png
3 4
   width: 192
4 5
   height: 154
5
-  margin-top: 10
6
-  margin-left: 6
7
-  margin-right: 6
8 6
 
9
-  Item
10
-    // head
11
-    id: slot1
12
-    anchors.top: parent.top
13
-    anchors.horizontalCenter: parent.horizontalCenter
14
-    &position: {x=65535, y=1, z=0}
7
+  MiniWindowContents
8
+    id: inventoryWindow
15 9
 
16
-  Item
17
-    // armor
18
-    id: slot4
19
-    anchors.top: prev.bottom
20
-    anchors.horizontalCenter: prev.horizontalCenter
21
-    margin-top: 5
22
-    &position: {x=65535, y=4, z=0}
10
+    Item
11
+      // head
12
+      id: slot1
13
+      anchors.top: parent.top
14
+      anchors.horizontalCenter: parent.horizontalCenter
15
+      &position: {x=65535, y=1, z=0}
23 16
 
24
-  Item
25
-    // legs
26
-    id: slot7
27
-    anchors.top: prev.bottom
28
-    anchors.horizontalCenter: prev.horizontalCenter
29
-    margin-top: 5
30
-    &position: {x=65535, y=7, z=0}
17
+    Item
18
+      // armor
19
+      id: slot4
20
+      anchors.top: prev.bottom
21
+      anchors.horizontalCenter: prev.horizontalCenter
22
+      margin-top: 5
23
+      &position: {x=65535, y=4, z=0}
31 24
 
32
-  Item
33
-    // feet
34
-    id: slot8
35
-    anchors.top: prev.bottom
36
-    anchors.horizontalCenter: prev.horizontalCenter
37
-    margin-top: 5
38
-    &position: {x=65535, y=8, z=0}
25
+    Item
26
+      // legs
27
+      id: slot7
28
+      anchors.top: prev.bottom
29
+      anchors.horizontalCenter: prev.horizontalCenter
30
+      margin-top: 5
31
+      &position: {x=65535, y=7, z=0}
39 32
 
40
-  Item
41
-    // necklace
42
-    id: slot2
43
-    anchors.top: parent.top
44
-    anchors.right: slot1.left
45
-    margin-top: 10
46
-    margin-right: 5
47
-    &position: {x=65535, y=2, z=0}
33
+    Item
34
+      // feet
35
+      id: slot8
36
+      anchors.top: prev.bottom
37
+      anchors.horizontalCenter: prev.horizontalCenter
38
+      margin-top: 5
39
+      margin-bottom: 10
40
+      &position: {x=65535, y=8, z=0}
48 41
 
49
-  Item
50
-    // left
51
-    id: slot6
52
-    anchors.top: prev.bottom
53
-    anchors.horizontalCenter: prev.horizontalCenter
54
-    margin-top: 5
55
-    &position: {x=65535, y=6, z=0}
42
+    Item
43
+      // necklace
44
+      id: slot2
45
+      anchors.top: parent.top
46
+      anchors.right: slot1.left
47
+      margin-top: 10
48
+      margin-right: 5
49
+      &position: {x=65535, y=2, z=0}
56 50
 
57
-  Item
58
-    // ring
59
-    id: slot9
60
-    anchors.top: prev.bottom
61
-    anchors.horizontalCenter: prev.horizontalCenter
62
-    margin-top: 5
63
-    &position: {x=65535, y=9, z=0}
51
+    Item
52
+      // left
53
+      id: slot6
54
+      anchors.top: prev.bottom
55
+      anchors.horizontalCenter: prev.horizontalCenter
56
+      margin-top: 5
57
+      &position: {x=65535, y=6, z=0}
64 58
 
65
-  Item
66
-    // backpack
67
-    id: slot3
68
-    anchors.top: parent.top
69
-    anchors.left: slot1.right
70
-    margin-top: 10
71
-    margin-left: 5
72
-    &position: {x=65535, y=3, z=0}
59
+    Item
60
+      // ring
61
+      id: slot9
62
+      anchors.top: prev.bottom
63
+      anchors.horizontalCenter: prev.horizontalCenter
64
+      margin-top: 5
65
+      &position: {x=65535, y=9, z=0}
73 66
 
74
-  Item
75
-    // right
76
-    id: slot5
77
-    anchors.top: prev.bottom
78
-    anchors.horizontalCenter: prev.horizontalCenter
79
-    margin-top: 5
80
-    &position: {x=65535, y=5, z=0}
67
+    Item
68
+      // backpack
69
+      id: slot3
70
+      anchors.top: parent.top
71
+      anchors.left: slot1.right
72
+      margin-top: 10
73
+      margin-left: 5
74
+      &position: {x=65535, y=3, z=0}
81 75
 
82
-  Item
83
-    // ammo
84
-    id: slot10
85
-    anchors.top: prev.bottom
86
-    anchors.horizontalCenter: prev.horizontalCenter
87
-    margin-top: 5
88
-    &position: {x=65535, y=10, z=0}
76
+    Item
77
+      // right
78
+      id: slot5
79
+      anchors.top: prev.bottom
80
+      anchors.horizontalCenter: prev.horizontalCenter
81
+      margin-top: 5
82
+      &position: {x=65535, y=5, z=0}
89 83
 
90
-  GameLabel
91
-    id: soul
92
-    anchors.top: slot9.bottom
93
-    anchors.bottom: slot8.bottom
94
-    anchors.left: slot9.left
95
-    anchors.right: slot9.right
96
-    margin-top: 5
97
-    text-align: center
98
-    image-source: /core_styles/styles/images/panel_flat.png
99
-    image-border: 1
84
+    Item
85
+      // ammo
86
+      id: slot10
87
+      anchors.top: prev.bottom
88
+      anchors.horizontalCenter: prev.horizontalCenter
89
+      margin-top: 5
90
+      &position: {x=65535, y=10, z=0}
100 91
 
101
-  GameLabel
102
-    id: capacity
103
-    anchors.top: slot10.bottom
104
-    anchors.bottom: slot8.bottom
105
-    anchors.left: slot10.left
106
-    anchors.right: slot10.right
107
-    margin-top: 5
108
-    text-align: center
109
-    image-source: /core_styles/styles/images/panel_flat.png
110
-    image-border: 1
92
+    GameLabel
93
+      id: soul
94
+      anchors.top: slot9.bottom
95
+      anchors.bottom: slot8.bottom
96
+      anchors.left: slot9.left
97
+      anchors.right: slot9.right
98
+      margin-top: 5
99
+      text-align: center
100
+      image-source: /core_styles/styles/images/panel_flat.png
101
+      image-border: 1
102
+
103
+    GameLabel
104
+      id: capacity
105
+      anchors.top: slot10.bottom
106
+      anchors.bottom: slot8.bottom
107
+      anchors.left: slot10.left
108
+      anchors.right: slot10.right
109
+      margin-top: 5
110
+      text-align: center
111
+      image-source: /core_styles/styles/images/panel_flat.png
112
+      image-border: 1
111 113
 

+ 17
- 1
src/framework/ui/uianchorlayout.cpp View File

@@ -155,6 +155,23 @@ void UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anch
155 155
                 break;
156 156
         }
157 157
 
158
+        if(hookedWidget == parentWidget) {
159
+            switch(anchor.getHookedEdge()) {
160
+                case Fw::AnchorLeft:
161
+                case Fw::AnchorRight:
162
+                case Fw::AnchorHorizontalCenter:
163
+                    point -= parentWidget->getVirtualOffset().x;
164
+                    break;
165
+                case Fw::AnchorBottom:
166
+                case Fw::AnchorTop:
167
+                case Fw::AnchorVerticalCenter:
168
+                    point -= parentWidget->getVirtualOffset().y;
169
+                    break;
170
+                default:
171
+                    break;
172
+            }
173
+        }
174
+
158 175
         switch(anchor.getAnchoredEdge()) {
159 176
             case Fw::AnchorHorizontalCenter:
160 177
                 newRect.moveHorizontalCenter(point + widget->getMarginLeft() - widget->getMarginRight());
@@ -197,7 +214,6 @@ void UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anch
197 214
         }
198 215
     }
199 216
 
200
-    newRect.translate(-parentWidget->getVirtualOffset());
201 217
     widget->setRect(newRect);
202 218
     anchorGroup.setUpdated(true);
203 219
 }

+ 20
- 4
src/framework/ui/uiwidget.cpp View File

@@ -902,19 +902,35 @@ Rect UIWidget::getClippingRect()
902 902
     return rect;
903 903
 }
904 904
 
905
+Rect UIWidget::getMarginRect()
906
+{
907
+    Rect rect = m_rect;
908
+    rect.expand(m_margin.top, m_margin.right, m_margin.bottom, m_margin.left);
909
+    return rect;
910
+}
911
+
905 912
 Rect UIWidget::getChildrenRect()
906 913
 {
907 914
     Rect childrenRect;
908 915
     for(const UIWidgetPtr& child : m_children) {
909
-        if(!child->isExplicitlyVisible() || !child->getRect().isValid() || child->getOpacity() == 0.0f)
916
+        if(!child->isExplicitlyVisible() || !child->getRect().isValid())
910 917
             continue;
918
+        Rect marginRect = child->getMarginRect();
911 919
         if(!childrenRect.isValid())
912
-            childrenRect = child->getRect();
920
+            childrenRect = marginRect;
913 921
         else
914
-            childrenRect = childrenRect.united(child->getRect());
922
+            childrenRect = childrenRect.united(marginRect);
915 923
     }
924
+
925
+    Rect myClippingRect = getClippingRect();
916 926
     if(!childrenRect.isValid())
917
-        childrenRect = getClippingRect();
927
+        childrenRect = myClippingRect;
928
+    else {
929
+        if(childrenRect.width() < myClippingRect.width())
930
+            childrenRect.setWidth(myClippingRect.width());
931
+        if(childrenRect.height() < myClippingRect.height())
932
+            childrenRect.setHeight(myClippingRect.height());
933
+    }
918 934
     return childrenRect;
919 935
 }
920 936
 

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

@@ -134,6 +134,7 @@ public:
134 134
     bool hasChild(const UIWidgetPtr& child);
135 135
     int getChildIndex(const UIWidgetPtr& child);
136 136
     Rect getClippingRect();
137
+    Rect getMarginRect();
137 138
     Rect getChildrenRect();
138 139
     UIAnchorLayoutPtr getAnchoredLayout();
139 140
     UIWidgetPtr getRootParent();

Loading…
Cancel
Save