From 67d806fe63dbd9c34712043f5a482a5b3b9379ad Mon Sep 17 00:00:00 2001 From: Leeor Dicker Date: Mon, 26 Jun 2023 12:03:38 -0400 Subject: [PATCH] Drop remaining NAS2D dependencies in favor of ImGui objects --- OP2-Landlord/Graphics.cpp | 25 ++++++++++++++----------- OP2-Landlord/Graphics.h | 17 +++++++---------- OP2-Landlord/main.cpp | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/OP2-Landlord/Graphics.cpp b/OP2-Landlord/Graphics.cpp index 8e9fd36..e02da2e 100644 --- a/OP2-Landlord/Graphics.cpp +++ b/OP2-Landlord/Graphics.cpp @@ -6,21 +6,21 @@ #include -Graphics::Graphics(NAS2D::Vector windowSize) : +Graphics::Graphics(ImVec2 windowSize) : mWindowSize{windowSize} { init(); } -void Graphics::drawColor(const NAS2D::Color color) +void Graphics::drawColor(const ImColor& color) { SDL_SetRenderDrawColor( mRenderer, - static_cast(color.red), - static_cast(color.green), - static_cast(color.blue), - static_cast(color.alpha) + static_cast(color.Value.x * 255), + static_cast(color.Value.y * 255), + static_cast(color.Value.z * 255), + static_cast(color.Value.w * 255) ); } @@ -33,7 +33,10 @@ void Graphics::clear() void Graphics::present() { - SDL_GetWindowSize(mWindow, &mWindowSize.x, &mWindowSize.y); + int w = 0, h = 0; + SDL_GetWindowSize(mWindow, &w, &h); + mWindowSize = { static_cast(w), static_cast(h) }; + SDL_RenderPresent(mRenderer); } @@ -59,7 +62,7 @@ Graphics::Texture Graphics::loadTexture(const std::string& filename) int width = 0, height = 0; SDL_QueryTexture(out, nullptr, nullptr, &width, &height); - return Texture{ out, SDL_Rect{ 0, 0, width, height }, { width, height } }; + return Texture{ out, SDL_Rect{ 0, 0, width, height }, { static_cast(width), static_cast(height) } }; } @@ -74,8 +77,8 @@ void Graphics::init() "OP2-Landlord", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - mWindowSize.x, - mWindowSize.y, + static_cast(mWindowSize.x), + static_cast(mWindowSize.y), SDL_WINDOW_RESIZABLE); if (!mWindow) @@ -83,7 +86,7 @@ void Graphics::init() throw std::runtime_error("initRenderer(): Unable to create primary window: " + std::string(SDL_GetError())); } - SDL_SetWindowMinimumSize(mWindow, mWindowSize.x, mWindowSize.y); + SDL_SetWindowMinimumSize(mWindow, static_cast(mWindowSize.x), static_cast(mWindowSize.y)); #if defined(__APPLE__) mWindowRenderer = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_SOFTWARE); diff --git a/OP2-Landlord/Graphics.h b/OP2-Landlord/Graphics.h index c732ee0..1550a90 100644 --- a/OP2-Landlord/Graphics.h +++ b/OP2-Landlord/Graphics.h @@ -2,12 +2,9 @@ #include +#include -#include "NAS2D/Math/Rectangle.h" -#include "NAS2D/Math/Point.h" -#include "NAS2D/Math/Vector.h" - -#include "NAS2D/Renderer/Color.h" +#include "imgui.h" class Graphics @@ -19,14 +16,14 @@ class Graphics SDL_Texture* texture{ nullptr }; SDL_Rect area{}; - NAS2D::Vector dimensions{}; + ImVec2 dimensions{}; }; public: Graphics() = delete; - Graphics(NAS2D::Vector windowSize); + Graphics(ImVec2 windowSize); - void drawColor(const NAS2D::Color drawColor); + void drawColor(const ImColor& drawColor); void clear(); void present(); @@ -36,13 +33,13 @@ class Graphics SDL_Window* window() { return mWindow; } SDL_Renderer* renderer() { return mRenderer; } - const NAS2D::Vector& size() { return mWindowSize; } + const ImVec2& size() { return mWindowSize; } private: void init(); - NAS2D::Vector mWindowSize{}; + ImVec2 mWindowSize{}; SDL_Window* mWindow = nullptr; SDL_Renderer* mRenderer = nullptr; diff --git a/OP2-Landlord/main.cpp b/OP2-Landlord/main.cpp index ecafd4a..b682874 100644 --- a/OP2-Landlord/main.cpp +++ b/OP2-Landlord/main.cpp @@ -25,7 +25,7 @@ namespace Graphics graphics({ 800, 600 }); FileIo fileIo(*graphics.window()); - constexpr auto ClearColor = NAS2D::Color{ 30, 30, 30, 255 }; + constexpr auto ClearColor = ImColor{ 0.117f, 0.117f, 0.117f, 1.0f }; constexpr auto EmptyDir{ "Empty Directory" }; constexpr auto EmptyDirMsg{ "No directory for Outpost 2 has been selected" };