GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/debugwindow.cpp Lines: 47 76 61.8 %
Date: 2018-09-20 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-2018  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#include "gui/windows/debugwindow.h"
24
25
#include "being/localplayer.h"
26
27
#include "gui/windows/setupwindow.h"
28
29
#include "gui/widgets/createwidget.h"
30
#include "gui/widgets/tabbedarea.h"
31
32
#include "gui/widgets/tabs/mapdebugtab.h"
33
#include "gui/widgets/tabs/netdebugtab.h"
34
#include "gui/widgets/tabs/statdebugtab.h"
35
#include "gui/widgets/tabs/targetdebugtab.h"
36
37
#include "utils/delete2.h"
38
#include "utils/gettext.h"
39
40
#include "debug.h"
41
42
DebugWindow *debugWindow = nullptr;
43
44
2
DebugWindow::DebugWindow(const std::string &name) :
45
    // TRANSLATORS: debug window name
46
2
    Window(_("Debug"), Modal_false, nullptr, "debug.xml"),
47


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

2
    mMapWidget(new MapDebugTab(this)),
49

2
    mTargetWidget(new TargetDebugTab(this)),
50

2
    mNetWidget(new NetDebugTab(this)),
51


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

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

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

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

8
    mTabs->addTab(std::string(_("Stat")), mStatWidget);
75
76
2
    mTabs->setDimension(Rect(0, 0, 600, 300));
77
78
2
    const int w = mDimension.width;
79
2
    const int h = mDimension.height;
80
4
    mMapWidget->resize(w, h);
81
4
    mTargetWidget->resize(w, h);
82
4
    mNetWidget->resize(w, h);
83
4
    mStatWidget->resize(w, h);
84
2
    loadWindowState();
85
4
    enableVisibleSound(true);
86
2
}
87
88
6
DebugWindow::~DebugWindow()
89
{
90
4
    delete2(mMapWidget);
91
4
    delete2(mTargetWidget);
92
4
    delete2(mNetWidget);
93
4
    delete2(mStatWidget);
94
4
}
95
96
2
void DebugWindow::postInit()
97
{
98
2
    Window::postInit();
99
2
    add(mTabs);
100
2
}
101
102
void DebugWindow::slowLogic()
103
{
104
    BLOCK_START("DebugWindow::slowLogic")
105
    if (!isWindowVisible() || (mTabs == nullptr))
106
    {
107
        BLOCK_END("DebugWindow::slowLogic")
108
        return;
109
    }
110
111
    switch (mTabs->getSelectedTabIndex())
112
    {
113
        default:
114
        case 0:
115
            mMapWidget->logic();
116
            break;
117
        case 1:
118
            mTargetWidget->logic();
119
            break;
120
        case 2:
121
            mNetWidget->logic();
122
            break;
123
        case 3:
124
            mStatWidget->logic();
125
            break;
126
    }
127
128
    if (localPlayer != nullptr)
129
        localPlayer->tryPingRequest();
130
    BLOCK_END("DebugWindow::slowLogic")
131
}
132
133
void DebugWindow::draw(Graphics *const g)
134
{
135
    BLOCK_START("DebugWindow::draw")
136
    Window::draw(g);
137
138
    if (localPlayer != nullptr)
139
    {
140
        const Being *const target = localPlayer->getTarget();
141
        if (target != nullptr)
142
        {
143
            target->draw(g, -target->getPixelX() + mapTileSize / 2
144
                + mDimension.width / 2, -target->getPixelY() + mapTileSize
145
                + mDimension.height / 2);
146
        }
147
    }
148
    BLOCK_END("DebugWindow::draw")
149
}
150
151
void DebugWindow::safeDraw(Graphics *const g)
152
{
153
    BLOCK_START("DebugWindow::draw")
154
    Window::safeDraw(g);
155
156
    if (localPlayer != nullptr)
157
    {
158
        const Being *const target = localPlayer->getTarget();
159
        if (target != nullptr)
160
        {
161
            target->draw(g, -target->getPixelX() + mapTileSize / 2
162
                + mDimension.width / 2, -target->getPixelY() + mapTileSize
163
                + mDimension.height / 2);
164
        }
165
    }
166
    BLOCK_END("DebugWindow::draw")
167
}
168
169
2
void DebugWindow::widgetResized(const Event &event)
170
{
171
2
    Window::widgetResized(event);
172
173
6
    mTabs->setDimension(Rect(0, 0,
174
2
        mDimension.width, mDimension.height));
175
4
}
176
177
#ifdef USE_PROFILER
178
void DebugWindow::logicChildren()
179
{
180
    BLOCK_START("DebugWindow::logicChildren")
181
    BasicContainer::logicChildren();
182
    BLOCK_END("DebugWindow::logicChildren")
183
}
184
#endif  // USE_PROFILER