#ifndef WIDGET_IMAGE_H_ #define WIDGET_IMAGE_H_ #include "Widget.h" #include #include "../sdl_helpers.h" class WidgetImage : public Widget { protected: // Image filepath std::string m_filename; // Image surface SDL_Surface* m_image_surface; // Whether to resize the image and how // RESIZE_NONE - Do not resize // RESIZE_FIT - Scale the image to fit the rectangle // RESIZE_STRETCH - Scale and stretch the image to fit the box perfectly ImageResize m_resize_type; // Default - center HorizontalAlign m_halign; // Default - center VerticalAlign m_valign; // Background color to be used // Default - transparent white SDL_Color m_bg_color; public: WidgetImage(int x, int y, int width, int height, std::string filename, ImageResize resize_type = RESIZE_FIT, HorizontalAlign halign = HALIGN_CENTER, VerticalAlign valign = VALIGN_CENTER, SDL_Color bg_color = SDL_Color{.r = 255, .g = 255, .b = 255, .a = SDL_ALPHA_TRANSPARENT}); virtual void draw() override; static std::unique_ptr builder(const nlohmann::json& j); protected: // Create a new surface of the image_surface that is scaled via RESIZE_FIT method // NOTE: The user MUST free the surface when done with it SDL_Surface* image_scale_fit(); }; #endif // WIDGET_IMAGE_H_