Otclient 1.0  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 <framework/ui/uiwidget.h>
27 #include "declarations.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) override;
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 setDrawTexts(bool enable) { m_mapView->setDrawTexts(enable); }
56  void setDrawNames(bool enable) { m_mapView->setDrawNames(enable); }
57  void setDrawHealthBars(bool enable) { m_mapView->setDrawHealthBars(enable); }
58  void setDrawLights(bool enable) { m_mapView->setDrawLights(enable); }
59  void setDrawManaBar(bool enable) { m_mapView->setDrawManaBar(enable); }
60  void setKeepAspectRatio(bool enable);
61  void setMapShader(const PainterShaderProgramPtr& shader, float fadeout, float fadein) { m_mapView->setShader(shader, fadein, fadeout); }
62  void setMinimumAmbientLight(float intensity) { m_mapView->setMinimumAmbientLight(intensity); }
63  void setLimitVisibleRange(bool limitVisibleRange) { m_limitVisibleRange = limitVisibleRange; updateVisibleDimension(); }
64  void setAddLightMethod(bool add) { m_mapView->setAddLightMethod(add); }
65 
66  bool isMultifloor() { return m_mapView->isMultifloor(); }
67  bool isAutoViewModeEnabled() { return m_mapView->isAutoViewModeEnabled(); }
68  bool isDrawingTexts() { return m_mapView->isDrawingTexts(); }
69  bool isDrawingNames() { return m_mapView->isDrawingNames(); }
70  bool isDrawingHealthBars() { return m_mapView->isDrawingHealthBars(); }
71  bool isDrawingLights() { return m_mapView->isDrawingLights(); }
72  bool isDrawingManaBar() { return m_mapView->isDrawingManaBar(); }
73  bool isKeepAspectRatioEnabled() { return m_keepAspectRatio; }
74  bool isLimitVisibleRangeEnabled() { return m_limitVisibleRange; }
75 
76  std::vector<CreaturePtr> getVisibleCreatures() { return m_mapView->getVisibleCreatures(); }
77 
78  Size getVisibleDimension() { return m_mapView->getVisibleDimension(); }
79  MapView::ViewMode getViewMode() { return m_mapView->getViewMode(); }
81  Position getCameraPosition() { return m_mapView->getCameraPosition(); }
82  Position getPosition(const Point& mousePos);
83  TilePtr getTile(const Point& mousePos);
84  int getMaxZoomIn() { return m_maxZoomIn; }
85  int getMaxZoomOut() { return m_maxZoomOut; }
86  int getZoom() { return m_zoom; }
87  PainterShaderProgramPtr getMapShader() { return m_mapView->getShader(); }
88  float getMinimumAmbientLight() { return m_mapView->getMinimumAmbientLight(); }
89 
90 protected:
91  void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) override;
92  void onGeometryChange(const Rect& oldRect, const Rect& newRect) override;
93 
94 private:
95  void updateVisibleDimension();
96  void updateMapSize();
97 
98  int m_zoom;
99  MapViewPtr m_mapView;
100  Rect m_mapRect;
101  float m_aspectRatio;
102  bool m_keepAspectRatio;
103  bool m_limitVisibleRange;
104  int m_maxZoomIn;
105  int m_maxZoomOut;
106 };
107 
108 #endif
UIMap::setDrawHealthBars
void setDrawHealthBars(bool enable)
Definition: uimap.h:57
UIMap::unlockVisibleFloor
void unlockVisibleFloor()
Definition: uimap.h:51
MapView::setDrawHealthBars
void setDrawHealthBars(bool enable)
Definition: mapview.h:107
UIWidget
Definition: uiwidget.h:47
UIMap::zoomOut
bool zoomOut()
Definition: uimap.cpp:99
MapView::lockFirstVisibleFloor
void lockFirstVisibleFloor(int firstVisibleFloor)
Definition: mapview.cpp:488
UIMap::setKeepAspectRatio
void setKeepAspectRatio(bool enable)
Definition: uimap.cpp:122
MapView::setDrawManaBar
void setDrawManaBar(bool enable)
Definition: mapview.h:113
UIMap::getMapShader
PainterShaderProgramPtr getMapShader()
Definition: uimap.h:87
MapView::setMinimumAmbientLight
void setMinimumAmbientLight(float intensity)
Definition: mapview.h:97
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:121
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:71
MapView::isDrawingTexts
bool isDrawingTexts()
Definition: mapview.h:102
UIMap::getFollowingCreature
CreaturePtr getFollowingCreature()
Definition: uimap.h:80
UIMap::isAutoViewModeEnabled
bool isAutoViewModeEnabled()
Definition: uimap.h:67
MapView::isAutoViewModeEnabled
bool isAutoViewModeEnabled()
Definition: mapview.h:87
MapView::isMultifloor
bool isMultifloor()
Definition: mapview.h:70
UIMap::isMultifloor
bool isMultifloor()
Definition: uimap.h:66
UIMap::isLimitVisibleRangeEnabled
bool isLimitVisibleRangeEnabled()
Definition: uimap.h:74
UIMap::setMapShader
void setMapShader(const PainterShaderProgramPtr &shader, float fadeout, float fadein)
Definition: uimap.h:61
UIMap::onStyleApply
void onStyleApply(const std::string &styleName, const OTMLNodePtr &styleNode) override
Definition: uimap.cpp:161
uiwidget.h
MapView::setDrawLights
void setDrawLights(bool enable)
Definition: mapview.cpp:731
UIMap::onGeometryChange
void onGeometryChange(const Rect &oldRect, const Rect &newRect) override
Definition: uimap.cpp:176
UIMap::isKeepAspectRatioEnabled
bool isKeepAspectRatioEnabled()
Definition: uimap.h:73
UIMap::getCameraPosition
Position getCameraPosition()
Definition: uimap.h:81
UIMap::isDrawingHealthBars
bool isDrawingHealthBars()
Definition: uimap.h:70
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:713
UIMap::followCreature
void followCreature(const CreaturePtr &creature)
Definition: uimap.h:44
UIMap::setMinimumAmbientLight
void setMinimumAmbientLight(float intensity)
Definition: uimap.h:62
declarations.h
mapview.h
MapView::setAddLightMethod
void setAddLightMethod(bool add)
Definition: mapview.h:118
MapView::getViewMode
ViewMode getViewMode()
Definition: mapview.h:82
MapView::setAutoViewMode
void setAutoViewMode(bool enable)
Definition: mapview.cpp:524
MapView::unlockFirstVisibleFloor
void unlockFirstVisibleFloor()
Definition: mapview.cpp:494
Position
Definition: position.h:33
UIMap::setMultifloor
void setMultifloor(bool enable)
Definition: uimap.h:49
UIMap::isDrawingLights
bool isDrawingLights()
Definition: uimap.h:71
UIMap::isDrawingNames
bool isDrawingNames()
Definition: uimap.h:69
UIMap::getTile
TilePtr getTile(const Point &mousePos)
Definition: uimap.cpp:139
UIMap::getMinimumAmbientLight
float getMinimumAmbientLight()
Definition: uimap.h:88
MapView::setDrawTexts
void setDrawTexts(bool enable)
Definition: mapview.h:101
MapView::getCameraPosition
Position getCameraPosition()
Definition: mapview.cpp:705
MapView::getMinimumAmbientLight
float getMinimumAmbientLight()
Definition: mapview.h:98
UIMap::setZoom
bool setZoom(int zoom)
Definition: uimap.cpp:78
MapView::setDrawNames
void setDrawNames(bool enable)
Definition: mapview.h:104
MapView::setCameraPosition
void setCameraPosition(const Position &pos)
Definition: mapview.cpp:543
UIMap::setDrawLights
void setDrawLights(bool enable)
Definition: uimap.h:58
UIMap::getMaxZoomOut
int getMaxZoomOut()
Definition: uimap.h:85
UIMap::getZoom
int getZoom()
Definition: uimap.h:86
UIMap::isDrawingTexts
bool isDrawingTexts()
Definition: uimap.h:68
UIMap::setDrawNames
void setDrawNames(bool enable)
Definition: uimap.h:56
MapView::getFollowingCreature
CreaturePtr getFollowingCreature()
Definition: mapview.h:90
MapView::isDrawingLights
bool isDrawingLights()
Definition: mapview.h:111
UIMap::drawSelf
void drawSelf(Fw::DrawPane drawPane) override
Definition: uimap.cpp:50
MapView::isDrawingHealthBars
bool isDrawingHealthBars()
Definition: mapview.h:108
MapView::isDrawingManaBar
bool isDrawingManaBar()
Definition: mapview.h:114
UIMap::setDrawManaBar
void setDrawManaBar(bool enable)
Definition: uimap.h:59
Fw::DrawPane
DrawPane
Definition: const.h:285
stdext::shared_object_ptr< Creature >
UIMap::getVisibleDimension
Size getVisibleDimension()
Definition: uimap.h:78
MapView::ViewMode
ViewMode
Definition: mapview.h:42
UIWidget::enable
void enable()
Definition: uiwidget.h:223
UIMap::isDrawingManaBar
bool isDrawingManaBar()
Definition: uimap.h:72
UIMap::setAddLightMethod
void setAddLightMethod(bool add)
Definition: uimap.h:64
UIMap::setLimitVisibleRange
void setLimitVisibleRange(bool limitVisibleRange)
Definition: uimap.h:63
MapView::followCreature
void followCreature(const CreaturePtr &creature)
Definition: mapview.cpp:536
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:79
MapView::getVisibleCreatures
std::vector< CreaturePtr > getVisibleCreatures()
Definition: mapview.h:130
UIMap::setMaxZoomOut
void setMaxZoomOut(int maxZoomOut)
Definition: uimap.h:48
MapView::setViewMode
void setViewMode(ViewMode viewMode)
Definition: mapview.cpp:518
TSize< int >
MapView::isDrawingNames
bool isDrawingNames()
Definition: mapview.h:105
MapView::getVisibleDimension
Size getVisibleDimension()
Definition: mapview.h:75
UIMap::getMaxZoomIn
int getMaxZoomIn()
Definition: uimap.h:84
UIMap::lockVisibleFloor
void lockVisibleFloor(int floor)
Definition: uimap.h:50
UIMap::getVisibleCreatures
std::vector< CreaturePtr > getVisibleCreatures()
Definition: uimap.h:76
UIMap::setDrawTexts
void setDrawTexts(bool enable)
Definition: uimap.h:55