ManaPlus
debugwindow.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
25 
26 #include "being/localplayer.h"
27 
29 
31 #include "gui/widgets/tabbedarea.h"
32 
37 
38 #include "utils/delete2.h"
39 #include "utils/gettext.h"
40 
41 #include "debug.h"
42 
44 
45 DebugWindow::DebugWindow(const std::string &name) :
46  // TRANSLATORS: debug window name
47  Window(_("Debug"), Modal_false, nullptr, "debug.xml"),
48  mTabs(CREATEWIDGETR(TabbedArea, this)),
49  mMapWidget(new MapDebugTab(this)),
50  mTargetWidget(new TargetDebugTab(this)),
51  mNetWidget(new NetDebugTab(this)),
52  mStatWidget(new StatDebugTab(this))
53 {
54  setWindowName(name);
55  if (setupWindow != nullptr)
57 
58  setResizable(true);
59  setCloseButton(true);
60  setSaveVisible(true);
61  setStickyButtonLock(true);
62 
63  setDefaultSize(400, 300, ImagePosition::CENTER, 0, 0);
64 
65  mTabs->setSelectable(false);
68  // TRANSLATORS: debug window tab
69  mTabs->addTab(std::string(_("Map")), mMapWidget);
70  // TRANSLATORS: debug window tab
71  mTabs->addTab(std::string(_("Target")), mTargetWidget);
72  // TRANSLATORS: debug window tab
73  mTabs->addTab(std::string(_("Net")), mNetWidget);
74  // TRANSLATORS: debug window tab
75  mTabs->addTab(std::string(_("Stat")), mStatWidget);
76 
77  mTabs->setDimension(Rect(0, 0, 600, 300));
78 
79  const int w = mDimension.width;
80  const int h = mDimension.height;
81  mMapWidget->resize(w, h);
82  mTargetWidget->resize(w, h);
83  mNetWidget->resize(w, h);
84  mStatWidget->resize(w, h);
86  enableVisibleSound(true);
87 }
88 
90 {
95 }
96 
98 {
100  add(mTabs);
101 }
102 
104 {
105  BLOCK_START("DebugWindow::slowLogic")
106  if (!isWindowVisible() || (mTabs == nullptr))
107  {
108  BLOCK_END("DebugWindow::slowLogic")
109  return;
110  }
111 
112  switch (mTabs->getSelectedTabIndex())
113  {
114  default:
115  case 0:
116  mMapWidget->logic();
117  break;
118  case 1:
119  mTargetWidget->logic();
120  break;
121  case 2:
122  mNetWidget->logic();
123  break;
124  case 3:
125  mStatWidget->logic();
126  break;
127  }
128 
129  if (localPlayer != nullptr)
131  BLOCK_END("DebugWindow::slowLogic")
132 }
133 
135 {
136  BLOCK_START("DebugWindow::draw")
137  Window::draw(g);
138 
139  if (localPlayer != nullptr)
140  {
141  const Being *const target = localPlayer->getTarget();
142  if (target != nullptr)
143  {
144  target->draw(g, -target->getPixelX() + mapTileSize / 2
145  + mDimension.width / 2, -target->getPixelY() + mapTileSize
146  + mDimension.height / 2);
147  }
148  }
149  BLOCK_END("DebugWindow::draw")
150 }
151 
153 {
154  BLOCK_START("DebugWindow::draw")
155  Window::safeDraw(g);
156 
157  if (localPlayer != nullptr)
158  {
159  const Being *const target = localPlayer->getTarget();
160  if (target != nullptr)
161  {
162  target->draw(g, -target->getPixelX() + mapTileSize / 2
163  + mDimension.width / 2, -target->getPixelY() + mapTileSize
164  + mDimension.height / 2);
165  }
166  }
167  BLOCK_END("DebugWindow::draw")
168 }
169 
171 {
172  Window::widgetResized(event);
173 
174  mTabs->setDimension(Rect(0, 0,
176 }
177 
178 #ifdef USE_PROFILER
180 {
181  BLOCK_START("DebugWindow::logicChildren")
184 }
185 #endif // USE_PROFILER
virtual int getPixelY() const
Definition: actor.h:93
int getPixelX() const
Definition: actor.h:87
virtual void add(Widget *const widget)
virtual void logicChildren()
Definition: being.h:96
void draw(Graphics *const graphics, const int offsetX, const int offsetY) const
Definition: being.cpp:3839
void resize(const int x, const int y)
Definition: debugtab.h:40
void safeDraw(Graphics *const g)
TabbedArea * mTabs
Definition: debugwindow.h:72
void draw(Graphics *const g)
MapDebugTab * mMapWidget
Definition: debugwindow.h:73
TargetDebugTab * mTargetWidget
Definition: debugwindow.h:74
DebugWindow(const std::string &name)
Definition: debugwindow.cpp:45
void slowLogic()
void postInit()
Definition: debugwindow.cpp:97
void widgetResized(const Event &event)
StatDebugTab * mStatWidget
Definition: debugwindow.h:76
NetDebugTab * mNetWidget
Definition: debugwindow.h:75
Definition: event.h:79
Being * getTarget() const
void tryPingRequest()
void logic()
Definition: netdebugtab.cpp:55
Definition: rect.h:74
int width
Definition: rect.h:219
int height
Definition: rect.h:224
void registerWindowForReset(Window *const window)
Widget * getTabContainer() const
Definition: tabbedarea.h:241
int getSelectedTabIndex() const
Definition: tabbedarea.cpp:449
Widget * getWidgetContainer() const
Definition: tabbedarea.h:244
void setDimension(const Rect &dimension)
Definition: tabbedarea.cpp:771
void addTab(Tab *const tab, Widget *const widget)
Definition: tabbedarea.cpp:238
Rect mDimension
Definition: widget.h:1101
void setSelectable(const bool selectable)
Definition: widget.h:948
Definition: window.h:102
void safeDraw(Graphics *const graphics)
Definition: window.cpp:423
void setSaveVisible(const bool save)
Definition: window.h:300
void setResizable(const bool resize)
Definition: window.cpp:627
bool isWindowVisible() const
Definition: window.h:484
void setWindowName(const std::string &name)
Definition: window.h:355
void postInit()
Definition: window.cpp:249
void enableVisibleSound(bool b)
Definition: window.h:481
void widgetResized(const Event &event)
Definition: window.cpp:655
void draw(Graphics *const graphics)
Definition: window.cpp:311
void setCloseButton(const bool flag)
Definition: window.cpp:749
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:772
void setDefaultSize()
Definition: window.cpp:1198
void loadWindowState()
Definition: window.cpp:1087
static const int mapTileSize
Definition: map.h:27
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
#define new
Definition: debug_new.h:147
DebugWindow * debugWindow
Definition: debugwindow.cpp:43
#define delete2(var)
Definition: delete2.h:25
#define _(s)
Definition: gettext.h:35
#define nullptr
Definition: localconsts.h:45
LocalPlayer * localPlayer
const bool Modal_false
Definition: modal.h:30
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
SetupWindow * setupWindow
Definition: setupwindow.cpp:64