Initial image implementation
This commit is contained in:
47
Widgets/WidgetImage.h
Normal file
47
Widgets/WidgetImage.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef WIDGET_IMAGE_H_
|
||||
#define WIDGET_IMAGE_H_
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#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<Widget> builder(const nlohmann::json& j);
|
||||
};
|
||||
|
||||
#endif // WIDGET_IMAGE_H_
|
||||
Reference in New Issue
Block a user