Skip to content

Commit

Permalink
new DebugInfo thing: the old debug lines
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Sep 28, 2014
1 parent 6beafc3 commit 507ba35
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/debug/DebugInfo.h
Expand Up @@ -5,5 +5,5 @@
class DebugInfo
{
public:
virtual void Draw(ui::Point position) {}
virtual void Draw() {}
};
110 changes: 110 additions & 0 deletions src/debug/DebugLines.cpp
@@ -0,0 +1,110 @@
#include "DebugLines.h"
#include "gui/interface/Engine.h"
#include "gui/game/GameView.h"
#include "gui/game/GameController.h"

LineDebug::LineDebug(GameView * view, GameController * controller):
view(view),
controller(controller)
{

}

void LineDebug::Draw()
{
Graphics * g = ui::Engine::Ref().g;

if (view->GetDrawingLine())
{
ui::Point drawPoint1 = controller->PointTranslate(view->GetLineStartCoords()), drawPoint2 = controller->PointTranslate(view->GetLineFinishCoords());
if (view->GetDrawSnap())
drawPoint2 = view->lineSnapCoords(drawPoint1, drawPoint2);
//g->draw_line(drawPoint1.X, drawPoint1.Y, drawPoint2.X, drawPoint2.Y, 255, 0, 255, 255);

g->draw_line(0, drawPoint1.Y, XRES, drawPoint1.Y, 255, 255, 255, 120);
g->draw_line(drawPoint1.X, 0, drawPoint1.X, YRES, 255, 255, 255, 120);

g->draw_line(0, drawPoint2.Y, XRES, drawPoint2.Y, 255, 255, 255, 120);
g->draw_line(drawPoint2.X, 0, drawPoint2.X, YRES, 255, 255, 255, 120);

stringstream info;
info << drawPoint2.X << " x " << drawPoint2.Y;
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);

info.str("");
info << drawPoint1.X << " x " << drawPoint1.Y;
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);

info.str("");
info << std::abs(drawPoint2.X-drawPoint1.X);
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);

info.str("");
info << std::abs(drawPoint2.Y-drawPoint1.Y);
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);
}
/*int yBottom = YRES-10;
int xStart = 10;
std::string maxValString;
std::string halfValString;
float maxVal = 255;
float scale = 1.0f;
int bars = 0;
for(int i = 0; i < PT_NUM; i++)
{
if(sim->elements[i].Enabled)
{
if(maxVal < sim->elementCount[i])
maxVal = sim->elementCount[i];
bars++;
}
}
maxAverage = (maxAverage*(1.0f-0.015f)) + (0.015f*maxVal);
scale = 255.0f/maxAverage;
maxValString = format::NumberToString<int>(maxAverage);
halfValString = format::NumberToString<int>(maxAverage/2);
g->fillrect(xStart-5, yBottom - 263, bars+10+Graphics::textwidth(maxValString.c_str())+10, 255 + 13, 0, 0, 0, 180);
bars = 0;
for(int i = 0; i < PT_NUM; i++)
{
if(sim->elements[i].Enabled)
{
float count = sim->elementCount[i];
int barSize = (count * scale - 0.5f);
int barX = bars;//*2;
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);
if(sim->elementCount[i])
{
if(barSize > 256)
{
barSize = 256;
g->blendpixel(xStart+barX, yBottom-barSize-3, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), 255);
g->blendpixel(xStart+barX, yBottom-barSize-5, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), 255);
g->blendpixel(xStart+barX, yBottom-barSize-7, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), 255);
} else {
g->draw_line(xStart+barX, yBottom-barSize-3, xStart+barX, yBottom-barSize-2, 255, 255, 255, 180);
}
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);
}
bars++;
}
}
g->drawtext(xStart + bars + 5, yBottom-5, "0", 255, 255, 255, 255);
g->drawtext(xStart + bars + 5, yBottom-132, halfValString, 255, 255, 255, 255);
g->drawtext(xStart + bars + 5, yBottom-260, maxValString, 255, 255, 255, 255);*/
}

LineDebug::~LineDebug()
{

}
15 changes: 15 additions & 0 deletions src/debug/DebugLines.h
@@ -0,0 +1,15 @@
#pragma once

#include "DebugInfo.h"

class GameView;
class GameController;
class LineDebug : public DebugInfo
{
GameView * view;
GameController * controller;
public:
LineDebug(GameView * view, GameController * controller);
virtual void Draw();
virtual ~LineDebug();
};
3 changes: 1 addition & 2 deletions src/debug/ElementPopulation.cpp
Expand Up @@ -10,10 +10,9 @@ ElementPopulationDebug::ElementPopulationDebug(Simulation * sim):

}

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

int yBottom = YRES-10;
int xStart = 10;
Expand Down
2 changes: 1 addition & 1 deletion src/debug/ElementPopulation.h
Expand Up @@ -9,6 +9,6 @@ class ElementPopulationDebug : public DebugInfo
float maxAverage;
public:
ElementPopulationDebug(Simulation * sim);
virtual void Draw(ui::Point position);
virtual void Draw();
virtual ~ElementPopulationDebug();
};
6 changes: 4 additions & 2 deletions src/gui/game/GameController.cpp
Expand Up @@ -26,12 +26,13 @@
#include "gui/interface/Keys.h"
#include "simulation/Snapshot.h"
#include "debug/DebugInfo.h"
#include "debug/ElementPopulation.h"
#include "debug/DebugLines.h"
#ifdef LUACONSOLE
#include "lua/LuaScriptInterface.h"
#else
#include "lua/TPTScriptInterface.h"
#endif
//#include "debug/ElementPopulation.h"

using namespace std;

Expand Down Expand Up @@ -156,6 +157,7 @@ GameController::GameController():
Client::Ref().AddListener(this);

//debugInfo.push_back(new ElementPopulationDebug(gameModel->GetSimulation()));
//debugInfo.push_back(new LineDebug(gameView, this));
}

GameController::~GameController()
Expand Down Expand Up @@ -741,7 +743,7 @@ void GameController::Tick()
}
for(std::vector<DebugInfo*>::iterator iter = debugInfo.begin(), end = debugInfo.end(); iter != end; iter++)
{
(*iter)->Draw(ui::Point(10, 10));
(*iter)->Draw();
}
commandInterface->OnTick();
}
Expand Down
10 changes: 8 additions & 2 deletions src/gui/game/GameView.h
Expand Up @@ -113,8 +113,6 @@ class GameView: public ui::Window

int lastOffset;
void setToolButtonOffset(int offset);
virtual ui::Point lineSnapCoords(ui::Point point1, ui::Point point2);
virtual ui::Point rectSnapCoords(ui::Point point1, ui::Point point2);

void screenshot();
void record();
Expand Down Expand Up @@ -145,6 +143,14 @@ class GameView: public ui::Window
SelectMode GetSelectMode() { return selectMode; }
void BeginStampSelection();

//all of these are only here for one debug lines
bool GetDrawingLine() { return drawMode == DrawLine && isMouseDown; }
bool GetDrawSnap() { return drawSnap; }
ui::Point GetLineStartCoords() { return drawPoint1; }
ui::Point GetLineFinishCoords() { return currentMouse; }
ui::Point lineSnapCoords(ui::Point point1, ui::Point point2);
ui::Point rectSnapCoords(ui::Point point1, ui::Point point2);

void AttachController(GameController * _c){ c = _c; }
void NotifyRendererChanged(GameModel * sender);
void NotifySimulationChanged(GameModel * sender);
Expand Down

0 comments on commit 507ba35

Please sign in to comment.