From 0d3c3243a080b7d4f402eef9251a8db37115a82a Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 11 Oct 2013 20:07:57 +1100 Subject: [PATCH] Added a debug display --- common/utility.cpp | 6 +++ common/utility.hpp | 3 ++ editor/editor_scene.cpp | 116 +++++++++++++++++++++++++++++++++++++--- editor/editor_scene.hpp | 6 +++ 4 files changed, 125 insertions(+), 6 deletions(-) diff --git a/common/utility.cpp b/common/utility.cpp index 666927f..784e807 100644 --- a/common/utility.cpp +++ b/common/utility.cpp @@ -45,3 +45,9 @@ std::string truncatePath(std::string pathname) { }).base(), pathname.end()); } + +std::string to_string_custom(int i) { + char buffer[20]; + snprintf(buffer, 20, "%d", i); + return std::string(buffer); +} diff --git a/common/utility.hpp b/common/utility.hpp index e2c3a95..b119271 100644 --- a/common/utility.hpp +++ b/common/utility.hpp @@ -27,4 +27,7 @@ int snapToBase(int base, int x); std::string truncatePath(std::string pathname); +//fixing a known bug in g++ +std::string to_string_custom(int i); + #endif diff --git a/editor/editor_scene.cpp b/editor/editor_scene.cpp index f4c72f6..98ef772 100644 --- a/editor/editor_scene.cpp +++ b/editor/editor_scene.cpp @@ -23,9 +23,9 @@ #include "utility.hpp" -#include -#include #include +#include +#include using namespace std; @@ -34,11 +34,10 @@ using namespace std; //------------------------- EditorScene::EditorScene() { - //32 * 32 sized tiles - pager.SetWidth(32*4); - pager.SetHeight(32*4); + debugInfo.CreateSurface(256, 256); font.LoadSurface("rsc\\graphics\\fonts\\pk_white_8.bmp"); + buttonImage.LoadSurface("rsc\\graphics\\interface\\button_menu.bmp"); buttonImage.SetClipH(buttonImage.GetClipH()/3); @@ -47,7 +46,8 @@ EditorScene::EditorScene() { menuBar.SetEntries({ {"File", "New", "Open", "Save", "Save As...", "Close", "Exit"}, - {"Edit", "Null"} + {"Edit", "Set Tile", "Load Sheet", "Delete Sheet", "Metadata", "Run Script"}, + {"Debugging", "Debug On", "Debug Off", "Toggle Debug"} }); // pager.SetOnNew([](Region* const ptr){ @@ -58,6 +58,10 @@ EditorScene::EditorScene() { // printf("Delete Region: %d, %d\n", ptr->GetX(), ptr->GetY()); // }); + //32 * 32 sized tiles + pager.SetWidth(32*4); + pager.SetHeight(32*4); + sheetList.push_front(TileSheet()); sheetList.front().LoadSurface("rsc\\graphics\\tilesets\\terrain.bmp", 32, 32); } @@ -87,12 +91,31 @@ void EditorScene::Render(SDL_Surface* const screen) { pager.DrawTo(screen, &sheetList, camera.x, camera.y); //draw a big bar across the top + buttonImage.SetClipY(0); for (int i = 0; i < screen->w; i += buttonImage.GetClipW()) { buttonImage.DrawTo(screen, i, 0); } //draw the menu bar menuBar.DrawTo(screen); + + //draw some debugging info + if (debugOpen) { + SDL_FillRect(debugInfo.GetSurface(), 0, 0); + DrawToDebugInfo(string("camera.x: ") + to_string_custom(camera.x), 0); + DrawToDebugInfo(string("camera.y: ") + to_string_custom(camera.y), 1); + debugInfo.DrawTo(screen, screen->w - debugInfo.GetClipW(), buttonImage.GetClipH()); + } +} + +void EditorScene::DrawToDebugInfo(std::string str, int line) { + //draw the debug info on the right + font.DrawStringTo( + str, + debugInfo.GetSurface(), + debugInfo.GetClipW() - str.size() * font.GetCharW(), + font.GetCharH() * line + ); } //------------------------- @@ -132,7 +155,84 @@ void EditorScene::MouseButtonUp(SDL_MouseButtonEvent const& button) { int entry, drop; menuBar.MouseButtonUp(button, &entry, &drop); +#ifdef DEBUG cout << "Menu: (" << entry << "," << drop << ")" << endl; +#endif + + //manage input from the menu bar + switch(entry) { + case 0: //File + switch(drop) { + case 0: + //TODO: NEW + break; + + case 1: + //TODO: OPEN + break; + + case 2: + //TODO: SAVE + break; + + case 3: + //TODO: SAVE AS + break; + + case 4: + //TODO: CLOSE + break; + + case 5: { + //Quit + SDL_Event e; + e.type = SDL_QUIT; + SDL_PushEvent(&e); + } + break; + } + break; + + case 1: //Edit + switch(drop) { + case 0: + //TODO: SET TILE + break; + + case 1: + //TODO: LOAD SHEET + break; + + case 2: + //TODO: DELETE SHEET + break; + + case 3: + //TODO: METADATA + break; + + case 4: + //TODO: RUN SCRIPT + break; + } + break; + + case 2: //Debug + switch(drop) { + case 0: + debugOpen = true; + break; + + case 1: + debugOpen = false; + break; + + case 2: + debugOpen = !debugOpen; + break; + } + break; + } } void EditorScene::KeyDown(SDL_KeyboardEvent const& key) { @@ -145,6 +245,10 @@ void EditorScene::KeyDown(SDL_KeyboardEvent const& key) { camera.x = 0; camera.y = 0; break; + + case SDLK_TAB: + debugOpen = !debugOpen; + break; } } diff --git a/editor/editor_scene.hpp b/editor/editor_scene.hpp index ef2941c..7811fbd 100644 --- a/editor/editor_scene.hpp +++ b/editor/editor_scene.hpp @@ -54,6 +54,12 @@ protected: void KeyUp(SDL_KeyboardEvent const&); //members + + //debugging tools + void DrawToDebugInfo(std::string, int line); + Image debugInfo; + bool debugOpen = true; + RegionPager pager; std::list sheetList;