Skip to content

Commit

Permalink
Drop remaining NAS2D dependencies in favor of ImGui objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ldicker83 committed Jun 26, 2023
1 parent 49a0099 commit 67d806f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
25 changes: 14 additions & 11 deletions OP2-Landlord/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
#include <iostream>


Graphics::Graphics(NAS2D::Vector<int> 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<Uint8>(color.red),
static_cast<Uint8>(color.green),
static_cast<Uint8>(color.blue),
static_cast<Uint8>(color.alpha)
static_cast<Uint8>(color.Value.x * 255),
static_cast<Uint8>(color.Value.y * 255),
static_cast<Uint8>(color.Value.z * 255),
static_cast<Uint8>(color.Value.w * 255)
);
}

Expand All @@ -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<float>(w), static_cast<float>(h) };

SDL_RenderPresent(mRenderer);
}

Expand All @@ -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<float>(width), static_cast<float>(height) } };
}


Expand All @@ -74,16 +77,16 @@ void Graphics::init()
"OP2-Landlord",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
mWindowSize.x,
mWindowSize.y,
static_cast<int>(mWindowSize.x),
static_cast<int>(mWindowSize.y),
SDL_WINDOW_RESIZABLE);

if (!mWindow)
{
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<int>(mWindowSize.x), static_cast<int>(mWindowSize.y));

#if defined(__APPLE__)
mWindowRenderer = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_SOFTWARE);
Expand Down
17 changes: 7 additions & 10 deletions OP2-Landlord/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@


#include <SDL2/SDL.h>
#include <string>

#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
Expand All @@ -19,14 +16,14 @@ class Graphics
SDL_Texture* texture{ nullptr };
SDL_Rect area{};

NAS2D::Vector<int> dimensions{};
ImVec2 dimensions{};
};

public:
Graphics() = delete;
Graphics(NAS2D::Vector<int> windowSize);
Graphics(ImVec2 windowSize);

void drawColor(const NAS2D::Color drawColor);
void drawColor(const ImColor& drawColor);

void clear();
void present();
Expand All @@ -36,13 +33,13 @@ class Graphics
SDL_Window* window() { return mWindow; }
SDL_Renderer* renderer() { return mRenderer; }

const NAS2D::Vector<int>& size() { return mWindowSize; }
const ImVec2& size() { return mWindowSize; }

private:
void init();


NAS2D::Vector<int> mWindowSize{};
ImVec2 mWindowSize{};

SDL_Window* mWindow = nullptr;
SDL_Renderer* mRenderer = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion OP2-Landlord/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down

0 comments on commit 67d806f

Please sign in to comment.