From 60deb0328aa55ef2c29be3924860da0b78d566fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Thu, 23 Dec 2021 23:36:30 +0100 Subject: [PATCH] Refactored Math::IntPoint in CInput and CImage --- src/app/input.cpp | 2 +- src/app/input.h | 5 +++-- src/common/image.cpp | 16 ++++++++-------- src/common/image.h | 14 +++++++------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/app/input.cpp b/src/app/input.cpp index 54f57169..d24da6a9 100644 --- a/src/app/input.cpp +++ b/src/app/input.cpp @@ -201,7 +201,7 @@ void CInput::EventProcess(Event& event) event.cameraInput = Math::Clamp(m_joyMotionCam + m_cameraKeyMotion, Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector(1.0f, 1.0f, 1.0f)); } -void CInput::MouseMove(Math::IntPoint pos) +void CInput::MouseMove(const glm::ivec2& pos) { m_mousePos = Gfx::CEngine::GetInstancePointer()->WindowToInterfaceCoords(pos); } diff --git a/src/app/input.h b/src/app/input.h index 4236f7d2..1747b01e 100644 --- a/src/app/input.h +++ b/src/app/input.h @@ -27,10 +27,11 @@ #include "common/key.h" #include "common/singleton.h" -#include "math/intpoint.h" #include "math/point.h" #include "math/vector.h" +#include + #include struct Event; @@ -78,7 +79,7 @@ public: void EventProcess(Event &event); //! Called by CApplication on SDL MOUSE_MOTION event - void MouseMove(Math::IntPoint pos); + void MouseMove(const glm::ivec2& pos); //! Returns whether the key is pressed diff --git a/src/common/image.cpp b/src/common/image.cpp index f0ae9977..b3a3594f 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -169,7 +169,7 @@ CImage::CImage() m_data = nullptr; } -CImage::CImage(Math::IntPoint size) +CImage::CImage(const glm::ivec2& size) { m_data = MakeUnique(); m_data->surface = SDL_CreateRGBSurface(0, size.x, size.y, 32, @@ -204,12 +204,12 @@ ImageData* CImage::GetData() return m_data.get(); } -Math::IntPoint CImage::GetSize() const +glm::ivec2 CImage::GetSize() const { if (m_data == nullptr) - return Math::IntPoint(); + return { 0, 0 }; - return Math::IntPoint(m_data->surface->w, m_data->surface->h); + return { m_data->surface->w, m_data->surface->h }; } /** Image must be valid. */ @@ -268,7 +268,7 @@ void CImage::BlitToNewRGBASurface(int width, int height) * \param pixel pixel coords (range x: 0..width-1 y: 0..height-1) * \returns color */ -Gfx::IntColor CImage::GetPixelInt(Math::IntPoint pixel) +Gfx::IntColor CImage::GetPixelInt(const glm::ivec2& pixel) { assert(m_data != nullptr); assert(pixel.x >= 0 && pixel.x < m_data->surface->w); @@ -316,7 +316,7 @@ Gfx::IntColor CImage::GetPixelInt(Math::IntPoint pixel) * \param pixel pixel coords (range x: 0..width-1 y: 0..height-1) * \returns color */ -Gfx::Color CImage::GetPixel(Math::IntPoint pixel) +Gfx::Color CImage::GetPixel(const glm::ivec2& pixel) { return Gfx::IntColorToColor(GetPixelInt(pixel)); } @@ -328,7 +328,7 @@ Gfx::Color CImage::GetPixel(Math::IntPoint pixel) * \param pixel pixel coords (range x: 0..width-1 y: 0..height-1) * \param color color */ -void CImage::SetPixelInt(Math::IntPoint pixel, Gfx::IntColor color) +void CImage::SetPixelInt(const glm::ivec2& pixel, Gfx::IntColor color) { assert(m_data != nullptr); assert(pixel.x >= 0 && pixel.x < m_data->surface->w); @@ -380,7 +380,7 @@ void CImage::SetPixelInt(Math::IntPoint pixel, Gfx::IntColor color) * \param pixel pixel coords (range x: 0..width-1 y: 0..height-1) * \param color color */ -void CImage::SetPixel(Math::IntPoint pixel, Gfx::Color color) +void CImage::SetPixel(const glm::ivec2& pixel, Gfx::Color color) { SetPixelInt(pixel, Gfx::ColorToIntColor(color)); } diff --git a/src/common/image.h b/src/common/image.h index 46161e20..9f44c457 100644 --- a/src/common/image.h +++ b/src/common/image.h @@ -26,7 +26,7 @@ #include "graphics/core/color.h" -#include "math/intpoint.h" +#include #include #include @@ -57,7 +57,7 @@ public: //! Constructs empty image (with nullptr data) CImage(); //! Constructs a RGBA image of given size - CImage(Math::IntPoint size); + CImage(const glm::ivec2& size); //! Destroys image, calling Free() virtual ~CImage(); @@ -74,22 +74,22 @@ public: ImageData* GetData(); //! Returns the image size - Math::IntPoint GetSize() const; + glm::ivec2 GetSize() const; //! Fills the whole image with given color void Fill(Gfx::IntColor color); //! Sets the color at given pixel - void SetPixel(Math::IntPoint pixel, Gfx::Color color); + void SetPixel(const glm::ivec2& pixel, Gfx::Color color); //! Sets the precise color at given pixel - void SetPixelInt(Math::IntPoint pixel, Gfx::IntColor color); + void SetPixelInt(const glm::ivec2& pixel, Gfx::IntColor color); //! Returns the color at given pixel - Gfx::Color GetPixel(Math::IntPoint pixel); + Gfx::Color GetPixel(const glm::ivec2& pixel); //! Returns the precise color at given pixel - Gfx::IntColor GetPixelInt(Math::IntPoint pixel); + Gfx::IntColor GetPixelInt(const glm::ivec2& pixel); //! Pads the image to nearest power of 2 dimensions void PadToNearestPowerOfTwo();