diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/README.txt | 2 | ||||
-rw-r--r-- | src/common/config.h.cmake | 3 | ||||
-rw-r--r-- | src/common/event.h | 2 | ||||
-rw-r--r-- | src/common/image.cpp | 35 | ||||
-rw-r--r-- | src/common/image.h | 6 | ||||
-rw-r--r-- | src/common/iman.h | 2 |
6 files changed, 37 insertions, 13 deletions
diff --git a/src/common/README.txt b/src/common/README.txt index 73d65b7..25c9fbf 100644 --- a/src/common/README.txt +++ b/src/common/README.txt @@ -1,4 +1,4 @@ /** - * \dir common + * \dir src/common * \brief Structs and utils shared throughout the application */ diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index f496db0..8c85df1 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -1,10 +1,9 @@ #pragma once // Macros set by CMake -#cmakedefine DEBUG - #cmakedefine PLATFORM_WINDOWS @PLATFORM_WINDOWS@ #cmakedefine PLATFORM_LINUX @PLATFORM_LINUX@ #cmakedefine PLATFORM_OTHER @PLATFORM_OTHER@ #cmakedefine USE_GLEW @USE_GLEW@ +#cmakedefine GLEW_STATIC
\ No newline at end of file diff --git a/src/common/event.h b/src/common/event.h index dc50ee6..ce2872a 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -81,7 +81,7 @@ enum WheelDirection }; /** - * \enum MouseWheelEventData + * \struct MouseWheelEventData * \brief Additional data for mouse wheel event. */ struct MouseWheelEventData diff --git a/src/common/image.cpp b/src/common/image.cpp index 50f6eee..6a2ab0e 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -190,7 +190,7 @@ Math::IntPoint CImage::GetSize() const * \param pixel pixel coords (range x: 0..width-1 y: 0..height-1) * \returns color */ -Gfx::Color CImage::GetPixel(Math::IntPoint pixel) +Gfx::IntColor CImage::GetPixelInt(Math::IntPoint pixel) { assert(m_data != nullptr); assert(pixel.x >= 0 || pixel.x <= m_data->surface->w); @@ -229,16 +229,28 @@ Gfx::Color CImage::GetPixel(Math::IntPoint pixel) Uint8 r = 0, g = 0, b = 0, a = 0; SDL_GetRGBA(u, m_data->surface->format, &r, &g, &b, &a); - return Gfx::Color(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f); + return Gfx::IntColor(r, g, b, a); +} + +/** + * Image must be valid and pixel coords in valid range. + * + * \param pixel pixel coords (range x: 0..width-1 y: 0..height-1) + * \returns color + */ +Gfx::Color CImage::GetPixel(Math::IntPoint pixel) +{ + return Gfx::IntColorToColor(GetPixelInt(pixel)); } + /** * Image must be valid and pixel coords in valid range. * * \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::SetPixelInt(Math::IntPoint pixel, Gfx::IntColor color) { assert(m_data != nullptr); assert(pixel.x >= 0 || pixel.x <= m_data->surface->w); @@ -248,11 +260,7 @@ void CImage::SetPixel(Math::IntPoint pixel, Gfx::Color color) int index = pixel.y * m_data->surface->pitch + pixel.x * bpp; Uint8* p = &static_cast<Uint8*>(m_data->surface->pixels)[index]; - Uint8 r = static_cast<Uint8>(color.r * 255.0f); - Uint8 g = static_cast<Uint8>(color.g * 255.0f); - Uint8 b = static_cast<Uint8>(color.b * 255.0f); - Uint8 a = static_cast<Uint8>(color.a * 255.0f); - Uint32 u = SDL_MapRGBA(m_data->surface->format, r, g, b, a); + Uint32 u = SDL_MapRGBA(m_data->surface->format, color.r, color.g, color.b, color.a); switch(bpp) { @@ -288,6 +296,17 @@ void CImage::SetPixel(Math::IntPoint pixel, Gfx::Color color) } } +/** + * Image must be valid and pixel coords in valid range. + * + * \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) +{ + SetPixelInt(pixel, Gfx::ColorToIntColor(color)); +} + std::string CImage::GetError() { return m_error; diff --git a/src/common/image.h b/src/common/image.h index 93c7cab..3391bdb 100644 --- a/src/common/image.h +++ b/src/common/image.h @@ -78,9 +78,15 @@ public: //! Sets the color at given pixel void SetPixel(Math::IntPoint pixel, Gfx::Color color); + //! Sets the precise color at given pixel + void SetPixelInt(Math::IntPoint pixel, Gfx::IntColor color); + //! Returns the color at given pixel Gfx::Color GetPixel(Math::IntPoint pixel); + //! Returns the precise color at given pixel + Gfx::IntColor GetPixelInt(Math::IntPoint pixel); + //! Loads an image from the specified file bool Load(const std::string &fileName); diff --git a/src/common/iman.h b/src/common/iman.h index 44f143a..75655aa 100644 --- a/src/common/iman.h +++ b/src/common/iman.h @@ -95,7 +95,7 @@ enum ManagedClassType /** - * \enum ManagedClassInstances + * \struct ManagedClassInstances * \brief Instances of class managed by CInstanceManager */ struct ManagedClassInstances |