Moved common functionality and includes around
This commit is contained in:
parent
df4ead9f85
commit
3a52a3991c
@ -4,6 +4,10 @@ Widget::Widget(int x, int y, int width, int height)
|
||||
: m_surface(nullptr), m_rect{.x = x, .y = y, .w = width, .h = height}
|
||||
{
|
||||
m_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, SDL_PIXELFORMAT_RGBA8888);
|
||||
if (nullptr != m_surface)
|
||||
{
|
||||
SDL_SetSurfaceBlendMode(m_surface, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
}
|
||||
|
||||
Widget::~Widget()
|
||||
@ -39,4 +43,9 @@ void Widget::resize(int width, int height)
|
||||
m_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, SDL_PIXELFORMAT_RGBA8888);
|
||||
m_rect.w = width;
|
||||
m_rect.h = height;
|
||||
|
||||
if (nullptr != m_surface)
|
||||
{
|
||||
SDL_SetSurfaceBlendMode(m_surface, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#define WIDGET_H_
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "../json.hpp"
|
||||
|
||||
class Widget
|
||||
{
|
||||
|
||||
@ -30,10 +30,6 @@ m_halign(halign),
|
||||
m_valign(valign),
|
||||
m_text_color(text_color)
|
||||
{
|
||||
if (nullptr != m_surface)
|
||||
{
|
||||
SDL_SetSurfaceBlendMode(m_surface, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
}
|
||||
|
||||
WidgetText::WidgetText(int x, int y, int width, int height, string text,
|
||||
@ -49,10 +45,6 @@ m_halign(HALIGN_CENTER),
|
||||
m_valign(VALIGN_CENTER),
|
||||
m_text_color{.r = 0, .g = 0, .b = 0, .a = SDL_ALPHA_OPAQUE}
|
||||
{
|
||||
if (nullptr != m_surface)
|
||||
{
|
||||
SDL_SetSurfaceBlendMode(m_surface, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
}
|
||||
|
||||
WidgetText::WidgetText(int x, int y, int width, int height, string text,
|
||||
@ -66,10 +58,6 @@ m_halign(HALIGN_CENTER),
|
||||
m_valign(VALIGN_CENTER),
|
||||
m_text_color{.r = 0, .g = 0, .b = 0, .a = SDL_ALPHA_OPAQUE}
|
||||
{
|
||||
if (nullptr != m_surface)
|
||||
{
|
||||
SDL_SetSurfaceBlendMode(m_surface, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetText::set_text(const string& text)
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
#include <string>
|
||||
|
||||
#include "../sdl_helpers.h"
|
||||
#include "../json.hpp"
|
||||
|
||||
class WidgetText : public Widget
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user