Simple GUI Library
rectangle.cpp
Go to the documentation of this file.
1/**
2 * @author Nikita Mochalov (github.com/tralf-strues)
3 * @file rectangle.cpp
4 * @date 2021-12-07
5 *
6 * @copyright Copyright (c) 2021
7 */
8
10
11using namespace Sgl;
12
13Rectangle::Rectangle(Sml::Color fillColor) : Shape(fillColor) {}
14Rectangle::Rectangle(const Background* background) : Shape(background) {}
15
16int32_t Rectangle::getWidth() const { return m_Width; }
17void Rectangle::setWidth(int32_t width) { m_Width = width; }
18
19int32_t Rectangle::getHeight() const { return m_Height; }
20void Rectangle::setHeight(int32_t height) { m_Height = height; }
21
22void Rectangle::render(const Sml::Rectangle<int32_t>& targetRegion)
23{
24 renderShadow(targetRegion);
25
26 Sml::Rectangle<int32_t> region = getLayoutBounds();
27 region.pos += targetRegion.pos;
28
29 Sml::Renderer::getInstance().setColor(m_FillColor);
30 Sml::renderFilledRect(region);
31
32 if (getBackground() != nullptr)
33 {
34 Sgl::Background::fillArea(getBackground(), region);
35 }
36
37 if (getBorder() != nullptr)
38 {
39 Border::encloseArea(getBorder(), targetRegion);
40 }
41}
42
43int32_t Rectangle::computePrefWidth(int32_t height) const
44{
45 return m_Width;
46}
47
48int32_t Rectangle::computePrefHeight(int32_t width) const
49{
50 return m_Height;
51}