GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/debugwindow.cpp Lines: 47 76 61.8 %
Date: 2021-03-17 Branches: 37 92 40.2 %

Line Branch Exec Source
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
24
#include "gui/windows/debugwindow.h"
25
26
#include "being/localplayer.h"
27
28
#include "gui/windows/setupwindow.h"
29
30
#include "gui/widgets/createwidget.h"
31
#include "gui/widgets/tabbedarea.h"
32
33
#include "gui/widgets/tabs/mapdebugtab.h"
34
#include "gui/widgets/tabs/netdebugtab.h"
35
#include "gui/widgets/tabs/statdebugtab.h"
36
#include "gui/widgets/tabs/targetdebugtab.h"
37
38
#include "utils/delete2.h"
39
#include "utils/gettext.h"
40
41
#include "debug.h"
42
43
DebugWindow *debugWindow = nullptr;
44
45
2
DebugWindow::DebugWindow(const std::string &name) :
46
    // TRANSLATORS: debug window name
47
2
    Window(_("Debug"), Modal_false, nullptr, "debug.xml"),
48


2
    mTabs(CREATEWIDGETR(TabbedArea, this)),
49

2
    mMapWidget(new MapDebugTab(this)),
50

2
    mTargetWidget(new TargetDebugTab(this)),
51

2
    mNetWidget(new NetDebugTab(this)),
52


22
    mStatWidget(new StatDebugTab(this))
53
{
54
4
    setWindowName(name);
55
2
    if (setupWindow != nullptr)
56
1
        setupWindow->registerWindowForReset(this);
57
58
2
    setResizable(true);
59
2
    setCloseButton(true);
60
4
    setSaveVisible(true);
61
2
    setStickyButtonLock(true);
62
63
2
    setDefaultSize(400, 300, ImagePosition::CENTER, 0, 0);
64
65
4
    mTabs->setSelectable(false);
66
6
    mTabs->getWidgetContainer()->setSelectable(false);
67
6
    mTabs->getTabContainer()->setSelectable(false);
68
    // TRANSLATORS: debug window tab
69

6
    mTabs->addTab(std::string(_("Map")), mMapWidget);
70
    // TRANSLATORS: debug window tab
71

6
    mTabs->addTab(std::string(_("Target")), mTargetWidget);
72
    // TRANSLATORS: debug window tab
73

6
    mTabs->addTab(std::string(_("Net")), mNetWidget);
74
    // TRANSLATORS: debug window tab
75

8
    mTabs->addTab(std::string(_("Stat")), mStatWidget);
76
77
2
    mTabs->setDimension(Rect(0, 0, 600, 300));
78
79
2
    const int w = mDimension.width;
80
2
    const int h = mDimension.height;
81
4
    mMapWidget->resize(w, h);
82
4
    mTargetWidget->resize(w, h);
83
4
    mNetWidget->resize(w, h);
84
4
    mStatWidget->resize(w, h);
85
2
    loadWindowState();
86
4
    enableVisibleSound(true);
87
2
}
88
89
6
DebugWindow::~DebugWindow()
90
{
91
4
    delete2(mMapWidget)
92
4
    delete2(mTargetWidget)
93
4
    delete2(mNetWidget)
94
4
    delete2(mStatWidget)
95
4
}
96
97
2
void DebugWindow::postInit()
98
{
99
2
    Window::postInit();
100
2
    add(mTabs);
101
2
}
102
103
void DebugWindow::slowLogic()
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)
130
        localPlayer->tryPingRequest();
131
    BLOCK_END("DebugWindow::slowLogic")
132
}
133
134
void DebugWindow::draw(Graphics *const g)
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
152
void DebugWindow::safeDraw(Graphics *const g)
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
170
2
void DebugWindow::widgetResized(const Event &event)
171
{
172
2
    Window::widgetResized(event);
173
174
6
    mTabs->setDimension(Rect(0, 0,
175
2
        mDimension.width, mDimension.height));
176
4
}
177
178
#ifdef USE_PROFILER
179
void DebugWindow::logicChildren()
180
{
181
    BLOCK_START("DebugWindow::logicChildren")
182
    BasicContainer::logicChildren();
183
    BLOCK_END("DebugWindow::logicChildren")
184
}
185
#endif  // USE_PROFILER