Skip to content

Commit 507ba35

Browse files
committed
new DebugInfo thing: the old debug lines
1 parent 6beafc3 commit 507ba35

File tree

7 files changed

+140
-8
lines changed

7 files changed

+140
-8
lines changed

src/debug/DebugInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
class DebugInfo
66
{
77
public:
8-
virtual void Draw(ui::Point position) {}
8+
virtual void Draw() {}
99
};

src/debug/DebugLines.cpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#include "DebugLines.h"
2+
#include "gui/interface/Engine.h"
3+
#include "gui/game/GameView.h"
4+
#include "gui/game/GameController.h"
5+
6+
LineDebug::LineDebug(GameView * view, GameController * controller):
7+
view(view),
8+
controller(controller)
9+
{
10+
11+
}
12+
13+
void LineDebug::Draw()
14+
{
15+
Graphics * g = ui::Engine::Ref().g;
16+
17+
if (view->GetDrawingLine())
18+
{
19+
ui::Point drawPoint1 = controller->PointTranslate(view->GetLineStartCoords()), drawPoint2 = controller->PointTranslate(view->GetLineFinishCoords());
20+
if (view->GetDrawSnap())
21+
drawPoint2 = view->lineSnapCoords(drawPoint1, drawPoint2);
22+
//g->draw_line(drawPoint1.X, drawPoint1.Y, drawPoint2.X, drawPoint2.Y, 255, 0, 255, 255);
23+
24+
g->draw_line(0, drawPoint1.Y, XRES, drawPoint1.Y, 255, 255, 255, 120);
25+
g->draw_line(drawPoint1.X, 0, drawPoint1.X, YRES, 255, 255, 255, 120);
26+
27+
g->draw_line(0, drawPoint2.Y, XRES, drawPoint2.Y, 255, 255, 255, 120);
28+
g->draw_line(drawPoint2.X, 0, drawPoint2.X, YRES, 255, 255, 255, 120);
29+
30+
stringstream info;
31+
info << drawPoint2.X << " x " << drawPoint2.Y;
32+
g->drawtext_outline(drawPoint2.X+(drawPoint2.X>drawPoint1.X?3:-g->textwidth(info.str().c_str())-3), drawPoint2.Y+(drawPoint2.Y<drawPoint1.Y?-10:3), info.str().c_str(), 255, 255, 255, 200);
33+
34+
info.str("");
35+
info << drawPoint1.X << " x " << drawPoint1.Y;
36+
g->drawtext_outline(drawPoint1.X+(drawPoint2.X<drawPoint1.X?3:-g->textwidth(info.str().c_str())-2), drawPoint1.Y+(drawPoint2.Y>drawPoint1.Y?-10:3), info.str().c_str(), 255, 255, 255, 200);
37+
38+
info.str("");
39+
info << std::abs(drawPoint2.X-drawPoint1.X);
40+
g->drawtext_outline((drawPoint1.X+drawPoint2.X)/2-g->textwidth(info.str().c_str())/2, drawPoint1.Y+(drawPoint2.Y>drawPoint1.Y?-10:3), info.str().c_str(), 255, 255, 255, 200);
41+
42+
info.str("");
43+
info << std::abs(drawPoint2.Y-drawPoint1.Y);
44+
g->drawtext_outline(drawPoint1.X+(drawPoint2.X<drawPoint1.X?3:-g->textwidth(info.str().c_str())-2), (drawPoint1.Y+drawPoint2.Y)/2-3, info.str().c_str(), 255, 255, 255, 200);
45+
}
46+
/*int yBottom = YRES-10;
47+
int xStart = 10;
48+
49+
std::string maxValString;
50+
std::string halfValString;
51+
52+
53+
float maxVal = 255;
54+
float scale = 1.0f;
55+
int bars = 0;
56+
for(int i = 0; i < PT_NUM; i++)
57+
{
58+
if(sim->elements[i].Enabled)
59+
{
60+
if(maxVal < sim->elementCount[i])
61+
maxVal = sim->elementCount[i];
62+
bars++;
63+
}
64+
}
65+
maxAverage = (maxAverage*(1.0f-0.015f)) + (0.015f*maxVal);
66+
scale = 255.0f/maxAverage;
67+
68+
maxValString = format::NumberToString<int>(maxAverage);
69+
halfValString = format::NumberToString<int>(maxAverage/2);
70+
71+
72+
g->fillrect(xStart-5, yBottom - 263, bars+10+Graphics::textwidth(maxValString.c_str())+10, 255 + 13, 0, 0, 0, 180);
73+
74+
bars = 0;
75+
for(int i = 0; i < PT_NUM; i++)
76+
{
77+
if(sim->elements[i].Enabled)
78+
{
79+
float count = sim->elementCount[i];
80+
int barSize = (count * scale - 0.5f);
81+
int barX = bars;//*2;
82+
83+
g->draw_line(xStart+barX, yBottom+3, xStart+barX, yBottom+2, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), 255);
84+
if(sim->elementCount[i])
85+
{
86+
if(barSize > 256)
87+
{
88+
barSize = 256;
89+
g->blendpixel(xStart+barX, yBottom-barSize-3, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), 255);
90+
g->blendpixel(xStart+barX, yBottom-barSize-5, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), 255);
91+
g->blendpixel(xStart+barX, yBottom-barSize-7, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), 255);
92+
} else {
93+
94+
g->draw_line(xStart+barX, yBottom-barSize-3, xStart+barX, yBottom-barSize-2, 255, 255, 255, 180);
95+
}
96+
g->draw_line(xStart+barX, yBottom-barSize, xStart+barX, yBottom, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), 255);
97+
}
98+
bars++;
99+
}
100+
}
101+
102+
g->drawtext(xStart + bars + 5, yBottom-5, "0", 255, 255, 255, 255);
103+
g->drawtext(xStart + bars + 5, yBottom-132, halfValString, 255, 255, 255, 255);
104+
g->drawtext(xStart + bars + 5, yBottom-260, maxValString, 255, 255, 255, 255);*/
105+
}
106+
107+
LineDebug::~LineDebug()
108+
{
109+
110+
}

src/debug/DebugLines.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include "DebugInfo.h"
4+
5+
class GameView;
6+
class GameController;
7+
class LineDebug : public DebugInfo
8+
{
9+
GameView * view;
10+
GameController * controller;
11+
public:
12+
LineDebug(GameView * view, GameController * controller);
13+
virtual void Draw();
14+
virtual ~LineDebug();
15+
};

src/debug/ElementPopulation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ ElementPopulationDebug::ElementPopulationDebug(Simulation * sim):
1010

1111
}
1212

13-
void ElementPopulationDebug::Draw(ui::Point position)
13+
void ElementPopulationDebug::Draw()
1414
{
1515
Graphics * g = ui::Engine::Ref().g;
16-
//g->drawtext(10, 10, "Arse", 255, 255, 255, 255);
1716

1817
int yBottom = YRES-10;
1918
int xStart = 10;

src/debug/ElementPopulation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ class ElementPopulationDebug : public DebugInfo
99
float maxAverage;
1010
public:
1111
ElementPopulationDebug(Simulation * sim);
12-
virtual void Draw(ui::Point position);
12+
virtual void Draw();
1313
virtual ~ElementPopulationDebug();
1414
};

src/gui/game/GameController.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
#include "gui/interface/Keys.h"
2727
#include "simulation/Snapshot.h"
2828
#include "debug/DebugInfo.h"
29+
#include "debug/ElementPopulation.h"
30+
#include "debug/DebugLines.h"
2931
#ifdef LUACONSOLE
3032
#include "lua/LuaScriptInterface.h"
3133
#else
3234
#include "lua/TPTScriptInterface.h"
3335
#endif
34-
//#include "debug/ElementPopulation.h"
3536

3637
using namespace std;
3738

@@ -156,6 +157,7 @@ GameController::GameController():
156157
Client::Ref().AddListener(this);
157158

158159
//debugInfo.push_back(new ElementPopulationDebug(gameModel->GetSimulation()));
160+
//debugInfo.push_back(new LineDebug(gameView, this));
159161
}
160162

161163
GameController::~GameController()
@@ -741,7 +743,7 @@ void GameController::Tick()
741743
}
742744
for(std::vector<DebugInfo*>::iterator iter = debugInfo.begin(), end = debugInfo.end(); iter != end; iter++)
743745
{
744-
(*iter)->Draw(ui::Point(10, 10));
746+
(*iter)->Draw();
745747
}
746748
commandInterface->OnTick();
747749
}

src/gui/game/GameView.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ class GameView: public ui::Window
113113

114114
int lastOffset;
115115
void setToolButtonOffset(int offset);
116-
virtual ui::Point lineSnapCoords(ui::Point point1, ui::Point point2);
117-
virtual ui::Point rectSnapCoords(ui::Point point1, ui::Point point2);
118116

119117
void screenshot();
120118
void record();
@@ -145,6 +143,14 @@ class GameView: public ui::Window
145143
SelectMode GetSelectMode() { return selectMode; }
146144
void BeginStampSelection();
147145

146+
//all of these are only here for one debug lines
147+
bool GetDrawingLine() { return drawMode == DrawLine && isMouseDown; }
148+
bool GetDrawSnap() { return drawSnap; }
149+
ui::Point GetLineStartCoords() { return drawPoint1; }
150+
ui::Point GetLineFinishCoords() { return currentMouse; }
151+
ui::Point lineSnapCoords(ui::Point point1, ui::Point point2);
152+
ui::Point rectSnapCoords(ui::Point point1, ui::Point point2);
153+
148154
void AttachController(GameController * _c){ c = _c; }
149155
void NotifyRendererChanged(GameModel * sender);
150156
void NotifySimulationChanged(GameModel * sender);

0 commit comments

Comments
 (0)