GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/debugwindow.cpp Lines: 42 72 58.3 %
Date: 2017-11-29 Branches: 31 77 40.3 %

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-2017  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/debugwindowtabs.h"
33
34
#include "utils/delete2.h"
35
#include "utils/gettext.h"
36
37
#include "debug.h"
38
39
DebugWindow *debugWindow = nullptr;
40
41
4
DebugWindow::DebugWindow(const std::string &name) :
42
    // TRANSLATORS: debug window name
43
4
    Window(_("Debug"), Modal_false, nullptr, "debug.xml"),
44

4
    mTabs(CREATEWIDGETR(TabbedArea, this)),
45

4
    mMapWidget(new MapDebugTab(this)),
46

4
    mTargetWidget(new TargetDebugTab(this)),
47


40
    mNetWidget(new NetDebugTab(this))
48
{
49
8
    setWindowName(name);
50
4
    if (setupWindow != nullptr)
51
2
        setupWindow->registerWindowForReset(this);
52
53
4
    setResizable(true);
54
4
    setCloseButton(true);
55
8
    setSaveVisible(true);
56
4
    setStickyButtonLock(true);
57
58
4
    setDefaultSize(400, 300, ImagePosition::CENTER);
59
60
8
    mTabs->setSelectable(false);
61
12
    mTabs->getWidgetContainer()->setSelectable(false);
62
12
    mTabs->getTabContainer()->setSelectable(false);
63
    // TRANSLATORS: debug window tab
64

16
    mTabs->addTab(std::string(_("Map")), mMapWidget);
65
    // TRANSLATORS: debug window tab
66

16
    mTabs->addTab(std::string(_("Target")), mTargetWidget);
67
    // TRANSLATORS: debug window tab
68

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