Changes in respect to the style guide
WIP
This commit is contained in:
parent
4a004dcb8b
commit
002d97ee27
11 changed files with 319 additions and 189 deletions
|
@ -3,32 +3,37 @@
|
||||||
#include <cigui/utils/Vectors.hpp>
|
#include <cigui/utils/Vectors.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace cig {
|
namespace cig
|
||||||
enum class LayoutSizes : uint8_t {
|
{
|
||||||
|
enum class LayoutSizes : uint8_t
|
||||||
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
Min,
|
Min,
|
||||||
Max,
|
Max,
|
||||||
Fixed,
|
Fixed,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class LayoutAlignment : uint8_t {
|
enum class LayoutAlignment : uint8_t
|
||||||
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
Left,
|
Left,
|
||||||
Right,
|
Right,
|
||||||
Top,
|
Top,
|
||||||
Bottom,
|
Bottom,
|
||||||
Center,
|
Center,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class LayoutDirection : uint8_t {
|
enum class LayoutDirection : uint8_t
|
||||||
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
LeftToRight,
|
LeftToRight,
|
||||||
RightToLeft,
|
RightToLeft,
|
||||||
TopToBottom,
|
TopToBottom,
|
||||||
BottomToTop,
|
BottomToTop,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class LayoutPosition : uint8_t {
|
enum class LayoutPosition : uint8_t
|
||||||
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
Absolute,
|
Absolute,
|
||||||
Left,
|
Left,
|
||||||
|
@ -36,29 +41,34 @@ enum class LayoutPosition : uint8_t {
|
||||||
Top,
|
Top,
|
||||||
Bottom,
|
Bottom,
|
||||||
Center,
|
Center,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Layout {
|
struct Layout
|
||||||
struct {
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
LayoutSizes rule = LayoutSizes::None;
|
LayoutSizes rule = LayoutSizes::None;
|
||||||
vec2f minSize = {0.f, 0.f};
|
vec2f minSize = {0.f, 0.f};
|
||||||
vec2f maxSize = {0.f, 0.f};
|
vec2f maxSize = {0.f, 0.f};
|
||||||
} size;
|
} size;
|
||||||
|
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
LayoutAlignment rule = LayoutAlignment::None;
|
LayoutAlignment rule = LayoutAlignment::None;
|
||||||
vec4f padding = {0.f, 0.f, 0.f, 0.f};
|
vec4f padding = {0.f, 0.f, 0.f, 0.f};
|
||||||
vec4f margin = {0.f, 0.f, 0.f, 0.f};
|
vec4f margin = {0.f, 0.f, 0.f, 0.f};
|
||||||
} alignment;
|
} alignment;
|
||||||
|
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
LayoutDirection rule = LayoutDirection::None;
|
LayoutDirection rule = LayoutDirection::None;
|
||||||
vec2f spacing = {0.f, 0.f};
|
vec2f spacing = {0.f, 0.f};
|
||||||
} direction;
|
} direction;
|
||||||
|
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
LayoutPosition rule = LayoutPosition::None;
|
LayoutPosition rule = LayoutPosition::None;
|
||||||
vec2f position = {0.f, 0.f};
|
vec2f position = {0.f, 0.f};
|
||||||
} position;
|
} position;
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -1,23 +1,23 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sfml/Graphics.hpp>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
namespace cig {
|
namespace sf {
|
||||||
class RenderCall {
|
class Drawable;
|
||||||
|
class RenderTarget;
|
||||||
|
struct RenderStates;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace cig
|
||||||
|
{
|
||||||
|
class RenderCall
|
||||||
|
{
|
||||||
std::shared_ptr<sf::Drawable> drawable;
|
std::shared_ptr<sf::Drawable> drawable;
|
||||||
sf::RenderStates states;
|
sf::RenderStates states;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit RenderCall(const sf::RenderStates &rstates, sf::Drawable *ptr) : drawable(ptr), states(rstates) {
|
explicit RenderCall(const sf::RenderStates& rstates, sf::Drawable* ptr);
|
||||||
if (!drawable) {
|
|
||||||
throw std::runtime_error("RenderCall::RenderCall(): Drawable is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw(sf::RenderTarget &target, const sf::RenderStates &rstates) const {
|
void draw(sf::RenderTarget& target, const sf::RenderStates& rstates) const;
|
||||||
target.draw(*drawable, rstates);
|
};
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
|
@ -1,29 +1,24 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SFML/Graphics.hpp>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <cigui/core/View.hpp>
|
|
||||||
#include <cigui/core/RenderCall.hpp>
|
|
||||||
|
|
||||||
|
namespace sf {
|
||||||
|
class RenderTarget;
|
||||||
|
class RenderStates;
|
||||||
|
}
|
||||||
|
|
||||||
namespace cig {
|
namespace cig {
|
||||||
|
class View;
|
||||||
|
class RenderCall;
|
||||||
|
|
||||||
class Renderer {
|
class Renderer {
|
||||||
public:
|
public:
|
||||||
explicit Renderer(View *_view) : view(_view) { view->draw(); }
|
explicit Renderer(View *_view);
|
||||||
|
|
||||||
std::unique_ptr<View> view;
|
std::unique_ptr<View> view;
|
||||||
|
|
||||||
void update() const {
|
void update() const;
|
||||||
if (view->update())
|
|
||||||
view->draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
void render(sf::RenderTarget &target, const sf::RenderStates &states) const {
|
void render(sf::RenderTarget &target, const sf::RenderStates &states) const;
|
||||||
auto lambda = [&target, &states](const RenderCall& renderCall) { renderCall.draw(target, states); };
|
|
||||||
view->renderCalls().iterate(lambda);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
#include <cigui/utils/List.hpp>
|
|
||||||
#include <cigui/core/Layout.hpp>
|
#include <cigui/core/Layout.hpp>
|
||||||
#include <cigui/core/RenderCall.hpp>
|
#include <cigui/utils/List.hpp>
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace cig
|
namespace cig
|
||||||
{
|
{
|
||||||
|
class RenderCall;
|
||||||
|
|
||||||
class View {
|
class View {
|
||||||
protected:
|
protected:
|
||||||
List<RenderCall> m_RenderCalls;
|
List<RenderCall> m_RenderCalls;
|
||||||
|
@ -17,27 +17,12 @@ namespace cig
|
||||||
public:
|
public:
|
||||||
virtual ~View() = default;
|
virtual ~View() = default;
|
||||||
|
|
||||||
[[nodiscard]] const List<RenderCall> &renderCalls() const { return m_RenderCalls; }
|
[[nodiscard]] const List<RenderCall>& renderCalls() const;
|
||||||
std::unique_ptr<View> content;
|
std::unique_ptr<View> content;
|
||||||
|
|
||||||
virtual bool update() {
|
virtual bool update();
|
||||||
if (content)
|
|
||||||
return content->update();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw() {
|
void draw();
|
||||||
if (!m_RenderCalls.empty()) {
|
|
||||||
m_RenderCalls.clear();
|
|
||||||
}
|
|
||||||
content = std::unique_ptr<View>(body());
|
|
||||||
if (!content) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
content->draw();
|
|
||||||
auto &contentRenderCalls = content->renderCalls();
|
|
||||||
m_RenderCalls.expand(contentRenderCalls);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual View *body() = 0;
|
virtual View *body() = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace cig
|
namespace cig
|
||||||
{
|
{
|
||||||
template <typename T, size_t growth_scalar = 1, size_t growth_summand = 3>
|
template <typename T, size_t growth_scalar = 1, size_t growth_summand = 3>
|
||||||
|
@ -12,68 +13,36 @@ namespace cig
|
||||||
size_t m_Capacity;
|
size_t m_Capacity;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void reserve(const size_t capacity);
|
void reserve(size_t capacity);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit List(const size_t capacity = 3) : m_Capacity(capacity) { reserve(capacity); }
|
explicit List(size_t capacity = 3);
|
||||||
|
|
||||||
void own(T* data, const size_t size)
|
void own(T* data, size_t size);
|
||||||
{
|
|
||||||
m_Data = data;
|
|
||||||
m_Size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void copy(T* data, const size_t size)
|
void copy(T* data, size_t size);
|
||||||
{
|
|
||||||
m_Data = std::make_unique<T[]>(size);
|
|
||||||
std::copy(data, data + size, m_Data.get());
|
|
||||||
m_Size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] size_t size() const { return m_Size; }
|
[[nodiscard]] size_t size() const;
|
||||||
|
|
||||||
T& operator[](size_t index) { return m_Data.get()[index]; }
|
T& operator[](size_t index);
|
||||||
|
|
||||||
const T& operator[](size_t index) const { return m_Data.get()[index]; }
|
const T& operator[](size_t index) const;
|
||||||
|
|
||||||
void need(const size_t additional_size)
|
void need(size_t additional_size);
|
||||||
{
|
|
||||||
if (m_Size + additional_size > m_Capacity)
|
|
||||||
reserve(m_Capacity + additional_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool empty() const { return m_Size == 0; }
|
[[nodiscard]] bool empty() const;
|
||||||
|
|
||||||
void clear() { m_Size = 0; }
|
void clear();
|
||||||
|
|
||||||
void push_back(const T& value)
|
void push_back(const T& value);
|
||||||
{
|
|
||||||
if (m_Size >= m_Capacity)
|
|
||||||
reserve(m_Capacity * growth_scalar + growth_summand);
|
|
||||||
m_Data.get()[m_Size++] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void emplace_back(Args&&... args)
|
void emplace_back(Args&&... args);
|
||||||
{
|
|
||||||
if (m_Size >= m_Capacity)
|
|
||||||
reserve(m_Capacity * growth_scalar + growth_summand);
|
|
||||||
m_Data.get()[m_Size++] = T(std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
void expand(const List<T>& other)
|
void expand(const List<T>& other);
|
||||||
{
|
|
||||||
need(other.size());
|
|
||||||
std::copy(other.m_Data.get(), other.m_Data.get() + other.size(), m_Data.get() + m_Size);
|
|
||||||
m_Size += other.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Lambda>
|
template <typename Lambda>
|
||||||
void iterate(Lambda&& lambda) const
|
void iterate(Lambda&& lambda) const;
|
||||||
{
|
|
||||||
for (size_t i = 0; i < m_Size; i++)
|
|
||||||
lambda(m_Data.get()[i]);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#include <cigui/utils/List.inl>
|
#include <cigui/utils/List.inl>
|
|
@ -1,12 +1,13 @@
|
||||||
|
#include <cigui/utils/List.hpp>
|
||||||
|
|
||||||
#define __LIST_FUNC_DEFINE__(rtt) \
|
#define LIST_FUNC_DEFINE(rtt) \
|
||||||
template <typename T, size_t growth_scalar, size_t growth_summand> \
|
template <typename T, size_t growth_scalar, size_t growth_summand> \
|
||||||
rtt List<T, growth_scalar, growth_summand>
|
rtt List<T, growth_scalar, growth_summand>
|
||||||
|
|
||||||
|
|
||||||
namespace cig
|
namespace cig
|
||||||
{
|
{
|
||||||
__LIST_FUNC_DEFINE__(void)::reserve(const size_t capacity)
|
LIST_FUNC_DEFINE(void)::reserve(const size_t capacity)
|
||||||
{
|
{
|
||||||
if (!m_Data)
|
if (!m_Data)
|
||||||
{
|
{
|
||||||
|
@ -19,4 +20,68 @@ namespace cig
|
||||||
m_Data = std::move(newData);
|
m_Data = std::move(newData);
|
||||||
m_Capacity = capacity;
|
m_Capacity = capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LIST_FUNC_DEFINE()::List(const size_t capacity) : m_Capacity(capacity) { reserve(capacity); }
|
||||||
|
|
||||||
|
LIST_FUNC_DEFINE(void)::own(T* data, const size_t size) {
|
||||||
|
m_Data = data;
|
||||||
|
m_Size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_FUNC_DEFINE(void)::copy(T* data, const size_t size) {
|
||||||
|
m_Data = std::make_unique<T[]>(size);
|
||||||
|
std::copy(data, data + size, m_Data.get());
|
||||||
|
m_Size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_FUNC_DEFINE(size_t)::size() const {
|
||||||
|
return m_Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_FUNC_DEFINE(T &)::operator[](const size_t index) {
|
||||||
|
return m_Data.get()[index];
|
||||||
|
}
|
||||||
|
LIST_FUNC_DEFINE(const T &)::operator[](const size_t index) const {
|
||||||
|
return m_Data.get()[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_FUNC_DEFINE(void)::need(const size_t additional_size) {
|
||||||
|
if (m_Size + additional_size > m_Capacity)
|
||||||
|
reserve(m_Capacity + additional_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_FUNC_DEFINE(bool)::empty() const {
|
||||||
|
return m_Size == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_FUNC_DEFINE(void)::clear() {
|
||||||
|
m_Size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_FUNC_DEFINE(void)::push_back(const T& value) {
|
||||||
|
if (m_Size >= m_Capacity)
|
||||||
|
reserve(m_Capacity * growth_scalar + growth_summand);
|
||||||
|
m_Data.get()[m_Size++] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LIST_FUNC_DEFINE(template <typename... Args> void)::emplace_back(Args&&... args) {
|
||||||
|
if (m_Size >= m_Capacity)
|
||||||
|
reserve(m_Capacity * growth_scalar + growth_summand);
|
||||||
|
m_Data.get()[m_Size++] = T(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_FUNC_DEFINE(void)::expand(const List<T>& other) {
|
||||||
|
need(other.size());
|
||||||
|
std::copy(other.m_Data.get(), other.m_Data.get() + other.size(), m_Data.get() + m_Size);
|
||||||
|
m_Size += other.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_FUNC_DEFINE(template <typename Lambda> void)::iterate(Lambda&& lambda) const
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < m_Size; i++)
|
||||||
|
lambda(m_Data.get()[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef LIST_FUNC_DEFINE
|
|
@ -1,7 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cigui/config.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
#define TYPEDEF_VECTOR(NAME, T, N, s) typedef NAME<T> vec##N##s;
|
#define TYPEDEF_VECTOR(NAME, T, N, s) typedef NAME<T> vec##N##s;
|
||||||
|
|
||||||
#define TYPEDEF_VECTORS(NAME, N) \
|
#define TYPEDEF_VECTORS(NAME, N) \
|
||||||
|
@ -20,47 +23,84 @@
|
||||||
TYPEDEF_VECTOR(NAME, unsigned long long, N, ull)
|
TYPEDEF_VECTOR(NAME, unsigned long long, N, ull)
|
||||||
|
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
#define UNNAMED_STRUCT __extension__ struct
|
#define UNNAMED_STRUCT __extension__ struct
|
||||||
#else
|
#else
|
||||||
#defien UNNAMED_STRUCT struct
|
#defien UNNAMED_STRUCT struct
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if CIGUI_DLL
|
||||||
|
#define VECTOR_TEMPLATE_INST(N, T) CIGUI_TEMPLATE_INST Vector##N<T>; \
|
||||||
|
|
||||||
namespace cig {
|
#define VECTOR_INSTANTIATION(N) \
|
||||||
template <typename T>
|
VECTOR_TEMPLATE_INST(N, float) \
|
||||||
union Vector2 {
|
VECTOR_TEMPLATE_INST(N, double)\
|
||||||
UNNAMED_STRUCT {
|
VECTOR_TEMPLATE_INST(N, long double) \
|
||||||
|
VECTOR_TEMPLATE_INST(N, size_t) \
|
||||||
|
VECTOR_TEMPLATE_INST(N, int) \
|
||||||
|
VECTOR_TEMPLATE_INST(N, short) \
|
||||||
|
VECTOR_TEMPLATE_INST(N, long) \
|
||||||
|
VECTOR_TEMPLATE_INST(N, long long) \
|
||||||
|
VECTOR_TEMPLATE_INST(N, unsigned int) \
|
||||||
|
VECTOR_TEMPLATE_INST(N, unsigned short) \
|
||||||
|
VECTOR_TEMPLATE_INST(N, unsigned long) \
|
||||||
|
VECTOR_TEMPLATE_INST(N, unsigned long long)
|
||||||
|
#else
|
||||||
|
#define VECTOR_INSTANTIATION(N)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
namespace cig
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
union Vector2
|
||||||
|
{
|
||||||
|
UNNAMED_STRUCT
|
||||||
|
{
|
||||||
T x, y;
|
T x, y;
|
||||||
};
|
};
|
||||||
UNNAMED_STRUCT {
|
|
||||||
|
UNNAMED_STRUCT
|
||||||
|
{
|
||||||
T a, b;
|
T a, b;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
TYPEDEF_VECTORS(Vector2, 2)
|
TYPEDEF_VECTORS(Vector2, 2)
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
union Vector3 {
|
union Vector3
|
||||||
UNNAMED_STRUCT {
|
{
|
||||||
|
UNNAMED_STRUCT
|
||||||
|
{
|
||||||
T x, y, z;
|
T x, y, z;
|
||||||
};
|
};
|
||||||
UNNAMED_STRUCT {
|
|
||||||
|
UNNAMED_STRUCT
|
||||||
|
{
|
||||||
T r, g, b;
|
T r, g, b;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
TYPEDEF_VECTORS(Vector3, 3)
|
|
||||||
|
|
||||||
template <typename T>
|
TYPEDEF_VECTORS(Vector3, 3)
|
||||||
union Vector4 {
|
|
||||||
UNNAMED_STRUCT {
|
template <typename T>
|
||||||
|
union Vector4
|
||||||
|
{
|
||||||
|
UNNAMED_STRUCT
|
||||||
|
{
|
||||||
T x, y, z, w;
|
T x, y, z, w;
|
||||||
};
|
};
|
||||||
UNNAMED_STRUCT {
|
|
||||||
|
UNNAMED_STRUCT
|
||||||
|
{
|
||||||
T r, g, b, a;
|
T r, g, b, a;
|
||||||
};
|
};
|
||||||
UNNAMED_STRUCT {
|
|
||||||
|
UNNAMED_STRUCT
|
||||||
|
{
|
||||||
T left, top, right, bottom;
|
T left, top, right, bottom;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
TYPEDEF_VECTORS(Vector4, 4)
|
|
||||||
|
TYPEDEF_VECTORS(Vector4, 4)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cigui/core/View.hpp>
|
#include <cigui/core/View.hpp>
|
||||||
|
#include <SFML/Graphics/Color.hpp>
|
||||||
|
|
||||||
|
namespace sf {
|
||||||
|
class RectangleShape;
|
||||||
|
}
|
||||||
|
|
||||||
namespace cig {
|
namespace cig {
|
||||||
struct Rectangle : View {
|
struct Rectangle : View {
|
||||||
|
|
|
@ -1 +1,14 @@
|
||||||
|
#include <cigui/core/RenderCall.hpp>
|
||||||
|
#include <sfml/Graphics.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace cig {
|
||||||
|
RenderCall::RenderCall(const sf::RenderStates& rstates, sf::Drawable* ptr) : drawable(ptr), states(rstates) {
|
||||||
|
if (!drawable) { throw std::runtime_error("RenderCall::RenderCall(): Drawable is null"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderCall::draw(sf::RenderTarget& target, const sf::RenderStates& rstates) const {
|
||||||
|
target.draw(*drawable, rstates);
|
||||||
|
}
|
||||||
|
}
|
19
src/core/Renderer.cpp
Normal file
19
src/core/Renderer.cpp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#include <cigui/core/Renderer.hpp>
|
||||||
|
|
||||||
|
#include <cigui/core/View.hpp>
|
||||||
|
#include <cigui/core/RenderCall.hpp>
|
||||||
|
#include <sfml/Graphics.hpp>
|
||||||
|
|
||||||
|
namespace cig {
|
||||||
|
Renderer::Renderer(View *_view) : view(_view) { view->draw(); }
|
||||||
|
|
||||||
|
void Renderer::update() const {
|
||||||
|
if (view->update())
|
||||||
|
view->draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::render(sf::RenderTarget &target, const sf::RenderStates &states) const {
|
||||||
|
auto lambda = [&target, &states](const RenderCall &renderCall) { renderCall.draw(target, states); };
|
||||||
|
view->renderCalls().iterate(lambda);
|
||||||
|
}
|
||||||
|
}
|
29
src/core/View.cpp
Normal file
29
src/core/View.cpp
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#include <cigui/core/View.hpp>
|
||||||
|
|
||||||
|
#include <cigui/core/RenderCall.hpp>
|
||||||
|
|
||||||
|
namespace cig {
|
||||||
|
const List<RenderCall>& View::renderCalls() const
|
||||||
|
{
|
||||||
|
return m_RenderCalls;
|
||||||
|
}
|
||||||
|
|
||||||
|
void View::draw() {
|
||||||
|
if (!m_RenderCalls.empty()) {
|
||||||
|
m_RenderCalls.clear();
|
||||||
|
}
|
||||||
|
content = std::unique_ptr<View>(body());
|
||||||
|
if (!content) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
content->draw();
|
||||||
|
auto &contentRenderCalls = content->renderCalls();
|
||||||
|
m_RenderCalls.expand(contentRenderCalls);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool View::update() {
|
||||||
|
if (content)
|
||||||
|
return content->update();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue