Initial commit. Added base of framework
This commit is contained in:
42
Widgets/Widget.cpp
Normal file
42
Widgets/Widget.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "Widget.h"
|
||||
|
||||
Widget::Widget(int width, int height)
|
||||
: m_surface(nullptr), m_rect{.x = 0, .y = 0, .w = width, .h = height}
|
||||
{
|
||||
m_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, SDL_PIXELFORMAT_RGBA8888);
|
||||
}
|
||||
|
||||
Widget::~Widget()
|
||||
{
|
||||
if (nullptr != m_surface)
|
||||
{
|
||||
SDL_FreeSurface(m_surface);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Surface* Widget::get_internal_surface()
|
||||
{
|
||||
return m_surface;
|
||||
}
|
||||
|
||||
SDL_Rect Widget::get_rect()
|
||||
{
|
||||
return m_rect;
|
||||
}
|
||||
|
||||
void Widget::set_position(int x, int y)
|
||||
{
|
||||
m_rect.x = x;
|
||||
m_rect.y = y;
|
||||
}
|
||||
|
||||
void Widget::resize(int width, int height)
|
||||
{
|
||||
if (nullptr != m_surface)
|
||||
{
|
||||
SDL_FreeSurface(m_surface);
|
||||
}
|
||||
m_surface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, SDL_PIXELFORMAT_RGBA8888);
|
||||
m_rect.w = width;
|
||||
m_rect.h = height;
|
||||
}
|
||||
36
Widgets/Widget.h
Normal file
36
Widgets/Widget.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef WIDGET_H_
|
||||
#define WIDGET_H_
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
class Widget
|
||||
{
|
||||
private:
|
||||
// Internal surface for drawing
|
||||
SDL_Surface* m_surface;
|
||||
|
||||
// Holds the size and position of the widget
|
||||
SDL_Rect m_rect;
|
||||
|
||||
public:
|
||||
Widget(int width, int height);
|
||||
~Widget();
|
||||
|
||||
// Method which updates the internal surface with the latest image
|
||||
virtual void draw() = 0;
|
||||
|
||||
// Returns the internal surface
|
||||
// Used for bliting to the main surface;
|
||||
SDL_Surface* get_internal_surface();
|
||||
|
||||
// Returns the internal position and size
|
||||
SDL_Rect get_rect();
|
||||
|
||||
// Sets the position of the widget on the screen
|
||||
void set_position(int x, int y);
|
||||
|
||||
// Sets the size of the widget on the screen
|
||||
void resize(int width, int height);
|
||||
};
|
||||
|
||||
#endif // WIDGET_H_
|
||||
Reference in New Issue
Block a user