Otclient  14/8/2020
uimap.h
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 #ifndef UIMAP_H
24 #define UIMAP_H
25 
26 #include "declarations.h"
27 #include <framework/ui/uiwidget.h>
28 #include "tile.h"
29 
30 #include "mapview.h"
31 
32 class UIMap : public UIWidget
33 {
34 public:
35  UIMap();
36  ~UIMap();
37 
38  void drawSelf(Fw::DrawPane drawPane);
39 
40  void movePixels(int x, int y);
41  bool setZoom(int zoom);
42  bool zoomIn();
43  bool zoomOut();
44  void followCreature(const CreaturePtr& creature) { m_mapView->followCreature(creature); }
45 
46  void setCameraPosition(const Position& pos) { m_mapView->setCameraPosition(pos); }
47  void setMaxZoomIn(int maxZoomIn) { m_maxZoomIn = maxZoomIn; }
48  void setMaxZoomOut(int maxZoomOut) { m_maxZoomOut = maxZoomOut; }
49  void setMultifloor(bool enable) { m_mapView->setMultifloor(enable); }
50  void lockVisibleFloor(int floor) { m_mapView->lockFirstVisibleFloor(floor); }
52  void setVisibleDimension(const Size& visibleDimension);
53  void setViewMode(MapView::ViewMode viewMode) { m_mapView->setViewMode(viewMode); }
54  void setAutoViewMode(bool enable) { m_mapView->setAutoViewMode(enable); }
55  void setDrawFlags(Otc::DrawFlags drawFlags) { m_mapView->setDrawFlags(drawFlags); }
56  void setDrawTexts(bool enable) { m_mapView->setDrawTexts(enable); }
57  void setDrawNames(bool enable) { m_mapView->setDrawNames(enable); }
58  void setDrawHealthBars(bool enable) { m_mapView->setDrawHealthBars(enable); }
59  void setDrawLights(bool enable) { m_mapView->setDrawLights(enable); }
60  void setDrawManaBar(bool enable) { m_mapView->setDrawManaBar(enable); }
61  void setAnimated(bool enable) { m_mapView->setAnimated(enable); }
62  void setKeepAspectRatio(bool enable);
63  void setMapShader(const PainterShaderProgramPtr& shader, float fadeout, float fadein) { m_mapView->setShader(shader, fadein, fadeout); }
64  void setMinimumAmbientLight(float intensity) { m_mapView->setMinimumAmbientLight(intensity); }
65  void setLimitVisibleRange(bool limitVisibleRange) { m_limitVisibleRange = limitVisibleRange; updateVisibleDimension(); }
66  void setAddLightMethod(bool add) { m_mapView->setAddLightMethod(add); }
67 
68  bool isMultifloor() { return m_mapView->isMultifloor(); }
69  bool isAutoViewModeEnabled() { return m_mapView->isAutoViewModeEnabled(); }
70  bool isDrawingTexts() { return m_mapView->isDrawingTexts(); }
71  bool isDrawingNames() { return m_mapView->isDrawingNames(); }
72  bool isDrawingHealthBars() { return m_mapView->isDrawingHealthBars(); }
73  bool isDrawingLights() { return m_mapView->isDrawingLights(); }
74  bool isDrawingManaBar() { return m_mapView->isDrawingManaBar(); }
75  bool isAnimating() { return m_mapView->isAnimating(); }
76  bool isKeepAspectRatioEnabled() { return m_keepAspectRatio; }
77  bool isLimitVisibleRangeEnabled() { return m_limitVisibleRange; }
78 
79  Size getVisibleDimension() { return m_mapView->getVisibleDimension(); }
80  MapView::ViewMode getViewMode() { return m_mapView->getViewMode(); }
82  Otc::DrawFlags getDrawFlags() { return m_mapView->getDrawFlags(); }
83  Position getCameraPosition() { return m_mapView->getCameraPosition(); }
84  Position getPosition(const Point& mousePos);
85  TilePtr getTile(const Point& mousePos);
86  int getMaxZoomIn() { return m_maxZoomIn; }
87  int getMaxZoomOut() { return m_maxZoomOut; }
88  int getZoom() { return m_zoom; }
89  PainterShaderProgramPtr getMapShader() { return m_mapView->getShader(); }
90  float getMinimumAmbientLight() { return m_mapView->getMinimumAmbientLight(); }
91 
92 protected:
93  virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
94  virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
95 
96 private:
97  void updateVisibleDimension();
98  void updateMapSize();
99 
100  int m_zoom;
101  MapViewPtr m_mapView;
102  Rect m_mapRect;
103  float m_aspectRatio;
104  bool m_keepAspectRatio;
105  bool m_limitVisibleRange;
106  int m_maxZoomIn;
107  int m_maxZoomOut;
108 };
109 
110 #endif
MapView::setAnimated
void setAnimated(bool animated)
Definition: mapview.h:116
UIMap::setDrawHealthBars
void setDrawHealthBars(bool enable)
Definition: uimap.h:58
UIMap::unlockVisibleFloor
void unlockVisibleFloor()
Definition: uimap.h:51
MapView::setDrawHealthBars
void setDrawHealthBars(bool enable)
Definition: mapview.h:105
UIWidget
Definition: uiwidget.h:47
UIMap::zoomOut
bool zoomOut()
Definition: uimap.cpp:99
MapView::lockFirstVisibleFloor
void lockFirstVisibleFloor(int firstVisibleFloor)
Definition: mapview.cpp:492
UIMap::setKeepAspectRatio
void setKeepAspectRatio(bool enable)
Definition: uimap.cpp:122
MapView::setDrawManaBar
void setDrawManaBar(bool enable)
Definition: mapview.h:111
UIMap::getMapShader
PainterShaderProgramPtr getMapShader()
Definition: uimap.h:89
MapView::setMinimumAmbientLight
void setMinimumAmbientLight(float intensity)
Definition: mapview.h:92
UIMap::setMaxZoomIn
void setMaxZoomIn(int maxZoomIn)
Definition: uimap.h:47
UIMap
Definition: uimap.h:32
UIMap::zoomIn
bool zoomIn()
Definition: uimap.cpp:85
MapView::getShader
PainterShaderProgramPtr getShader()
Definition: mapview.h:122
TRect< int >
UIMap::setAutoViewMode
void setAutoViewMode(bool enable)
Definition: uimap.h:54
UIMap::setViewMode
void setViewMode(MapView::ViewMode viewMode)
Definition: uimap.h:53
MapView::setMultifloor
void setMultifloor(bool enable)
Definition: mapview.h:65
MapView::isDrawingTexts
bool isDrawingTexts()
Definition: mapview.h:100
MapView::setDrawFlags
void setDrawFlags(Otc::DrawFlags drawFlags)
Definition: mapview.h:96
UIMap::getFollowingCreature
CreaturePtr getFollowingCreature()
Definition: uimap.h:81
UIMap::isAutoViewModeEnabled
bool isAutoViewModeEnabled()
Definition: uimap.h:69
MapView::isAutoViewModeEnabled
bool isAutoViewModeEnabled()
Definition: mapview.h:82
MapView::isMultifloor
bool isMultifloor()
Definition: mapview.h:66
UIMap::isMultifloor
bool isMultifloor()
Definition: uimap.h:68
UIMap::isLimitVisibleRangeEnabled
bool isLimitVisibleRangeEnabled()
Definition: uimap.h:77
UIMap::setMapShader
void setMapShader(const PainterShaderProgramPtr &shader, float fadeout, float fadein)
Definition: uimap.h:63
uiwidget.h
MapView::setDrawLights
void setDrawLights(bool enable)
Definition: mapview.cpp:735
UIMap::isKeepAspectRatioEnabled
bool isKeepAspectRatioEnabled()
Definition: uimap.h:76
UIMap::getCameraPosition
Position getCameraPosition()
Definition: uimap.h:83
UIMap::isDrawingHealthBars
bool isDrawingHealthBars()
Definition: uimap.h:72
UIMap::movePixels
void movePixels(int x, int y)
Definition: uimap.cpp:73
UIMap::setCameraPosition
void setCameraPosition(const Position &pos)
Definition: uimap.h:46
UIWidget::getPosition
Point getPosition()
Definition: uiwidget.h:354
MapView::setShader
void setShader(const PainterShaderProgramPtr &shader, float fadein, float fadeout)
Definition: mapview.cpp:716
UIMap::followCreature
void followCreature(const CreaturePtr &creature)
Definition: uimap.h:44
UIMap::setMinimumAmbientLight
void setMinimumAmbientLight(float intensity)
Definition: uimap.h:64
declarations.h
mapview.h
MapView::setAddLightMethod
void setAddLightMethod(bool add)
Definition: mapview.h:119
UIMap::isAnimating
bool isAnimating()
Definition: uimap.h:75
MapView::getViewMode
ViewMode getViewMode()
Definition: mapview.h:78
MapView::setAutoViewMode
void setAutoViewMode(bool enable)
Definition: mapview.cpp:528
MapView::unlockFirstVisibleFloor
void unlockFirstVisibleFloor()
Definition: mapview.cpp:498
Position
Definition: position.h:33
UIMap::setMultifloor
void setMultifloor(bool enable)
Definition: uimap.h:49
UIMap::isDrawingLights
bool isDrawingLights()
Definition: uimap.h:73
UIMap::isDrawingNames
bool isDrawingNames()
Definition: uimap.h:71
UIMap::getTile
TilePtr getTile(const Point &mousePos)
Definition: uimap.cpp:139
UIMap::getMinimumAmbientLight
float getMinimumAmbientLight()
Definition: uimap.h:90
MapView::setDrawTexts
void setDrawTexts(bool enable)
Definition: mapview.h:99
MapView::getCameraPosition
Position getCameraPosition()
Definition: mapview.cpp:708
MapView::getMinimumAmbientLight
float getMinimumAmbientLight()
Definition: mapview.h:93
UIMap::setDrawFlags
void setDrawFlags(Otc::DrawFlags drawFlags)
Definition: uimap.h:55
UIMap::setZoom
bool setZoom(int zoom)
Definition: uimap.cpp:78
MapView::setDrawNames
void setDrawNames(bool enable)
Definition: mapview.h:102
MapView::setCameraPosition
void setCameraPosition(const Position &pos)
Definition: mapview.cpp:547
UIMap::setDrawLights
void setDrawLights(bool enable)
Definition: uimap.h:59
UIMap::getMaxZoomOut
int getMaxZoomOut()
Definition: uimap.h:87
UIMap::getZoom
int getZoom()
Definition: uimap.h:88
UIMap::isDrawingTexts
bool isDrawingTexts()
Definition: uimap.h:70
UIMap::setDrawNames
void setDrawNames(bool enable)
Definition: uimap.h:57
MapView::getFollowingCreature
CreaturePtr getFollowingCreature()
Definition: mapview.h:86
MapView::isDrawingLights
bool isDrawingLights()
Definition: mapview.h:109
UIMap::setAnimated
void setAnimated(bool enable)
Definition: uimap.h:61
MapView::isDrawingHealthBars
bool isDrawingHealthBars()
Definition: mapview.h:106
MapView::isDrawingManaBar
bool isDrawingManaBar()
Definition: mapview.h:112
MapView::getDrawFlags
Otc::DrawFlags getDrawFlags()
Definition: mapview.h:97
UIMap::setDrawManaBar
void setDrawManaBar(bool enable)
Definition: uimap.h:60
UIMap::onStyleApply
virtual void onStyleApply(const std::string &styleName, const OTMLNodePtr &styleNode)
Definition: uimap.cpp:161
Fw::DrawPane
DrawPane
Definition: const.h:285
stdext::shared_object_ptr< Creature >
Otc::DrawFlags
DrawFlags
Definition: const.h:47
UIMap::onGeometryChange
virtual void onGeometryChange(const Rect &oldRect, const Rect &newRect)
Definition: uimap.cpp:178
UIMap::getVisibleDimension
Size getVisibleDimension()
Definition: uimap.h:79
UIMap::drawSelf
void drawSelf(Fw::DrawPane drawPane)
Definition: uimap.cpp:50
MapView::ViewMode
ViewMode
Definition: mapview.h:37
UIWidget::enable
void enable()
Definition: uiwidget.h:223
UIMap::isDrawingManaBar
bool isDrawingManaBar()
Definition: uimap.h:74
UIMap::setAddLightMethod
void setAddLightMethod(bool add)
Definition: uimap.h:66
UIMap::setLimitVisibleRange
void setLimitVisibleRange(bool limitVisibleRange)
Definition: uimap.h:65
MapView::followCreature
void followCreature(const CreaturePtr &creature)
Definition: mapview.cpp:540
UIMap::UIMap
UIMap()
Definition: uimap.cpp:31
TPoint< int >
UIMap::setVisibleDimension
void setVisibleDimension(const Size &visibleDimension)
Definition: uimap.cpp:113
tile.h
UIMap::~UIMap
~UIMap()
Definition: uimap.cpp:45
UIMap::getViewMode
MapView::ViewMode getViewMode()
Definition: uimap.h:80
UIMap::setMaxZoomOut
void setMaxZoomOut(int maxZoomOut)
Definition: uimap.h:48
MapView::setViewMode
void setViewMode(ViewMode viewMode)
Definition: mapview.cpp:522
TSize< int >
MapView::isDrawingNames
bool isDrawingNames()
Definition: mapview.h:103
MapView::getVisibleDimension
Size getVisibleDimension()
Definition: mapview.h:70
MapView::isAnimating
bool isAnimating()
Definition: mapview.h:117
UIMap::getMaxZoomIn
int getMaxZoomIn()
Definition: uimap.h:86
UIMap::getDrawFlags
Otc::DrawFlags getDrawFlags()
Definition: uimap.h:82
UIMap::lockVisibleFloor
void lockVisibleFloor(int floor)
Definition: uimap.h:50
UIMap::setDrawTexts
void setDrawTexts(bool enable)
Definition: uimap.h:56