ManaPlus
netdebugtab.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
23 
24 #include "being/localplayer.h"
25 
27 #include "gui/widgets/label.h"
29 
30 #include "net/packetcounters.h"
31 
32 #include "utils/gettext.h"
33 #include "utils/stringutils.h"
34 
35 #include "debug.h"
36 
37 NetDebugTab::NetDebugTab(const Widget2 *const widget) :
38  DebugTab(widget),
39  mPingLabel(new Label(this, " ")),
40  mInPackets1Label(new Label(this, " ")),
41  mOutPackets1Label(new Label(this, " "))
42 {
43  LayoutHelper h(this);
44  ContainerPlacer place = h.getPlacer(0, 0);
45 
46  place(0, 0, mPingLabel, 2, 1);
47  place(0, 1, mInPackets1Label, 2, 1);
48  place(0, 2, mOutPackets1Label, 2, 1);
49 
50  place.getCell().matchColWidth(0, 0);
51  place = h.getPlacer(0, 1);
52  setDimension(Rect(0, 0, 600, 300));
53 }
54 
56 {
57  BLOCK_START("NetDebugTab::logic")
58  if (localPlayer != nullptr)
59  {
60  // TRANSLATORS: debug window label
61  mPingLabel->setCaption(strprintf(_("Ping: %s ms"),
62  localPlayer->getPingTime().c_str()));
63  }
64  else
65  {
66  // TRANSLATORS: debug window label
67  mPingLabel->setCaption(strprintf(_("Ping: %s ms"), "0"));
68  }
69  // TRANSLATORS: debug window label
70  mInPackets1Label->setCaption(strprintf(_("In: %d bytes/s"),
72  // TRANSLATORS: debug window label
73  mOutPackets1Label->setCaption(strprintf(_("Out: %d bytes/s"),
75  BLOCK_END("NetDebugTab::logic")
76 }
LayoutCell & getCell()
Definition: label.h:91
void setCaption(const std::string &caption)
Definition: label.cpp:264
void matchColWidth(const int n1, const int n2)
Definition: layoutcell.cpp:118
ContainerPlacer getPlacer(const int x, const int y)
std::string getPingTime() const
void logic()
Definition: netdebugtab.cpp:55
NetDebugTab(const Widget2 *const widget)
Definition: netdebugtab.cpp:37
Label * mPingLabel
Definition: netdebugtab.h:41
Label * mOutPackets1Label
Definition: netdebugtab.h:43
Label * mInPackets1Label
Definition: netdebugtab.h:42
static int getOutBytes()
static int getInBytes()
Definition: rect.h:74
void setDimension(const Rect &dimension)
Definition: widget.cpp:169
#define new
Definition: debug_new.h:147
#define _(s)
Definition: gettext.h:35
LocalPlayer * localPlayer
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
std::string strprintf(const char *const format,...)