From 507ba35ce089da17d75549c3907e0512f6b8fc29 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 27 Sep 2014 21:40:16 -0400 Subject: [PATCH] new DebugInfo thing: the old debug lines --- src/debug/DebugInfo.h | 2 +- src/debug/DebugLines.cpp | 110 ++++++++++++++++++++++++++++++++ src/debug/DebugLines.h | 15 +++++ src/debug/ElementPopulation.cpp | 3 +- src/debug/ElementPopulation.h | 2 +- src/gui/game/GameController.cpp | 6 +- src/gui/game/GameView.h | 10 ++- 7 files changed, 140 insertions(+), 8 deletions(-) create mode 100644 src/debug/DebugLines.cpp create mode 100644 src/debug/DebugLines.h diff --git a/src/debug/DebugInfo.h b/src/debug/DebugInfo.h index 4cdfedc38f..5a7f00500b 100644 --- a/src/debug/DebugInfo.h +++ b/src/debug/DebugInfo.h @@ -5,5 +5,5 @@ class DebugInfo { public: - virtual void Draw(ui::Point position) {} + virtual void Draw() {} }; diff --git a/src/debug/DebugLines.cpp b/src/debug/DebugLines.cpp new file mode 100644 index 0000000000..3f2da84913 --- /dev/null +++ b/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.Ydrawtext_outline(drawPoint1.X+(drawPoint2.Xtextwidth(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.Xtextwidth(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(maxAverage); + halfValString = format::NumberToString(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() +{ + +} diff --git a/src/debug/DebugLines.h b/src/debug/DebugLines.h new file mode 100644 index 0000000000..302408921f --- /dev/null +++ b/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(); +}; diff --git a/src/debug/ElementPopulation.cpp b/src/debug/ElementPopulation.cpp index 33994a7452..e01de6e203 100644 --- a/src/debug/ElementPopulation.cpp +++ b/src/debug/ElementPopulation.cpp @@ -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; diff --git a/src/debug/ElementPopulation.h b/src/debug/ElementPopulation.h index a1a2093171..dfd679e62e 100644 --- a/src/debug/ElementPopulation.h +++ b/src/debug/ElementPopulation.h @@ -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(); }; diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 43f0396644..8f7cbe9889 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -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; @@ -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() @@ -741,7 +743,7 @@ void GameController::Tick() } for(std::vector::iterator iter = debugInfo.begin(), end = debugInfo.end(); iter != end; iter++) { - (*iter)->Draw(ui::Point(10, 10)); + (*iter)->Draw(); } commandInterface->OnTick(); } diff --git a/src/gui/game/GameView.h b/src/gui/game/GameView.h index 90fae7db25..acbe0e03e0 100644 --- a/src/gui/game/GameView.h +++ b/src/gui/game/GameView.h @@ -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(); @@ -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);