Otclient  14/8/2020
uimapanchorlayout.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 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 "declarations.h"
24 #include "uimapanchorlayout.h"
25 #include "uiminimap.h"
26 #include <framework/ui/uiwidget.h>
27 
28 int UIPositionAnchor::getHookedPoint(const UIWidgetPtr& hookedWidget, const UIWidgetPtr& parentWidget)
29 {
30  UIMinimapPtr minimap = hookedWidget->static_self_cast<UIMinimap>();
31  Rect hookedRect = minimap->getTileRect(m_hookedPosition);
32  int point = 0;
33  if(hookedRect.isValid()) {
34  switch(m_hookedEdge) {
35  case Fw::AnchorLeft:
36  point = hookedRect.left();
37  break;
38  case Fw::AnchorRight:
39  point = hookedRect.right();
40  break;
41  case Fw::AnchorTop:
42  point = hookedRect.top();
43  break;
44  case Fw::AnchorBottom:
45  point = hookedRect.bottom();
46  break;
48  point = hookedRect.horizontalCenter();
49  break;
51  point = hookedRect.verticalCenter();
52  break;
53  default:
54  // must never happens
55  assert(false);
56  break;
57  }
58  }
59  return point;
60 }
61 
62 void UIMapAnchorLayout::addPositionAnchor(const UIWidgetPtr& anchoredWidget, Fw::AnchorEdge anchoredEdge, const Position& hookedPosition, Fw::AnchorEdge hookedEdge)
63 {
64  if(!anchoredWidget)
65  return;
66 
67  assert(anchoredWidget != getParentWidget());
68 
69  UIPositionAnchorPtr anchor(new UIPositionAnchor(anchoredEdge, hookedPosition, hookedEdge));
70  UIAnchorGroupPtr& anchorGroup = m_anchorsGroups[anchoredWidget];
71  if(!anchorGroup)
72  anchorGroup = UIAnchorGroupPtr(new UIAnchorGroup);
73 
74  anchorGroup->addAnchor(anchor);
75 
76  // layout must be updated because a new anchor got in
77  update();
78 }
79 
80 void UIMapAnchorLayout::centerInPosition(const UIWidgetPtr& anchoredWidget, const Position& hookedPosition)
81 {
84 }
85 
86 void UIMapAnchorLayout::fillPosition(const UIWidgetPtr& anchoredWidget, const Position& hookedPosition)
87 {
88  addPositionAnchor(anchoredWidget, Fw::AnchorLeft, hookedPosition, Fw::AnchorLeft);
89  addPositionAnchor(anchoredWidget, Fw::AnchorRight, hookedPosition, Fw::AnchorRight);
90  addPositionAnchor(anchoredWidget, Fw::AnchorTop, hookedPosition, Fw::AnchorTop);
91  addPositionAnchor(anchoredWidget, Fw::AnchorBottom, hookedPosition, Fw::AnchorBottom);
92 }
UIPositionAnchor::getHookedPoint
int getHookedPoint(const UIWidgetPtr &hookedWidget, const UIWidgetPtr &parentWidget)
Definition: uimapanchorlayout.cpp:28
TRect< int >
uimapanchorlayout.h
Fw::AnchorRight
@ AnchorRight
Definition: const.h:216
Fw::AnchorEdge
AnchorEdge
Definition: const.h:211
UIAnchorGroup
Definition: uianchorlayout.h:46
Fw::AnchorLeft
@ AnchorLeft
Definition: const.h:215
uiwidget.h
declarations.h
UIMapAnchorLayout::fillPosition
void fillPosition(const UIWidgetPtr &anchoredWidget, const Position &hookedPosition)
Definition: uimapanchorlayout.cpp:86
stdext::shared_object::static_self_cast
stdext::shared_object_ptr< T > static_self_cast()
Definition: shared_object.h:50
Position
Definition: position.h:33
UIMapAnchorLayout::centerInPosition
void centerInPosition(const UIWidgetPtr &anchoredWidget, const Position &hookedPosition)
Definition: uimapanchorlayout.cpp:80
Fw::AnchorTop
@ AnchorTop
Definition: const.h:213
UILayout::update
void update()
Definition: uilayout.cpp:28
UILayout::getParentWidget
UIWidgetPtr getParentWidget()
Definition: uilayout.h:46
UIAnchorGroupPtr
stdext::shared_object_ptr< UIAnchorGroup > UIAnchorGroupPtr
Definition: declarations.h:50
UIMapAnchorLayout::addPositionAnchor
void addPositionAnchor(const UIWidgetPtr &anchoredWidget, Fw::AnchorEdge anchoredEdge, const Position &hookedPosition, Fw::AnchorEdge hookedEdge)
Definition: uimapanchorlayout.cpp:62
stdext::shared_object_ptr< UIWidget >
uiminimap.h
Fw::AnchorVerticalCenter
@ AnchorVerticalCenter
Definition: const.h:217
Fw::AnchorBottom
@ AnchorBottom
Definition: const.h:214
UIAnchorLayout::m_anchorsGroups
std::unordered_map< UIWidgetPtr, UIAnchorGroupPtr > m_anchorsGroups
Definition: uianchorlayout.h:82
UIPositionAnchor
Definition: uimapanchorlayout.h:29
UIMinimap
Definition: uiminimap.h:29
UIAnchor::m_hookedEdge
Fw::AnchorEdge m_hookedEdge
Definition: uianchorlayout.h:42
Fw::AnchorHorizontalCenter
@ AnchorHorizontalCenter
Definition: const.h:218