farmlands/src/gui/primitives/UIElement.cpp

80 lines
1.2 KiB
C++

/*
* UIElement.cpp
*
* Created on: Nov 27, 2016
* Author: tibi
*/
#include <graphics/backend/SdlRenderer.h>
#include <gui/primitives/UIElement.h>
using namespace farmlands::graphics::backend;
namespace farmlands
{
namespace gui
{
namespace primitives
{
UIElement::UIElement()
: m_x(0), m_y(0),
m_w(0), m_h(0)
{
}
UIElement::~UIElement()
{
}
void UIElement::render(graphics::RenderContext* context)
{
if (m_backColor.a > 0)
{
SDL_Rect rect =
{
(int) m_x,
(int) m_y,
(int) m_w,
(int) m_h
};
SDL_SetRenderDrawColor(SdlRenderer::instance().internalRenderer(), m_backColor.r, m_backColor.g, m_backColor.b, m_backColor.a);
SDL_RenderFillRect(SdlRenderer::instance().internalRenderer(), &rect);
}
}
bool UIElement::handleEvent(SDL_Event& event)
{
return false;
}
void UIElement::setPosition(float x, float y)
{
m_x = x;
m_y = y;
}
void UIElement::setSize(float w, float h)
{
m_w = w;
m_h = h;
}
void UIElement::setBackColor(SDL_Color backColor)
{
m_backColor = backColor;
}
void UIElement::setBackColor(float r, float g, float b, float a)
{
m_backColor.r = r * 255;
m_backColor.g = g * 255;
m_backColor.b = b * 255;
m_backColor.a = a * 255;
}
} /* namespace primitives */
} /* namespace gui */
} /* namespace farmlands */