Compare commits
No commits in common. "26858b795d30f9ab5d66270b7b952aa4e2b143cb" and "ef85745f582fb2405d45e55bdf13b60f02766e43" have entirely different histories.
26858b795d
...
ef85745f58
8 changed files with 35 additions and 52 deletions
|
@ -8,16 +8,9 @@
|
||||||
namespace Raven {
|
namespace Raven {
|
||||||
|
|
||||||
void Button::on_init() {
|
void Button::on_init() {
|
||||||
auto top_level_styles = get_top_level_styles();
|
set_style_do_background_fill(true);
|
||||||
|
set_style_background_fill_color(m_style_normal_background_fill_color);
|
||||||
set_text_fill_color(top_level_styles->get_text_color());
|
set_style_font_description(get_top_level_styles()->get_style_controls_font_description());
|
||||||
set_active_background_fill_color(top_level_styles->get_button_active_color());
|
|
||||||
set_focused_background_fill_color(top_level_styles->get_button_focused_color());
|
|
||||||
set_normal_background_fill_color(top_level_styles->get_button_normal_color());
|
|
||||||
|
|
||||||
set_do_background_fill(true);
|
|
||||||
set_background_fill_color(m_normal_background_fill_color);
|
|
||||||
set_font_description(top_level_styles->get_controls_font_description());
|
|
||||||
|
|
||||||
set_did_init(true);
|
set_did_init(true);
|
||||||
}
|
}
|
||||||
|
@ -25,17 +18,17 @@ void Button::on_init() {
|
||||||
void Button::on_paint() {
|
void Button::on_paint() {
|
||||||
auto painter = get_window()->get_painter();
|
auto painter = get_window()->get_painter();
|
||||||
|
|
||||||
painter.source_rgb(m_text_fill_color);
|
painter.source_rgb(m_style_text_fill_color);
|
||||||
painter.set_pango_font_description(m_font_description);
|
painter.set_pango_font_description(m_style_font_description);
|
||||||
painter.text(get_current_geometry(), m_text, PaintTextAlign::Center);
|
painter.text(get_current_geometry(), m_text, PaintTextAlign::Center);
|
||||||
painter.fill();
|
painter.fill();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::on_focus_update(FocusUpdateEvent &event) {
|
void Button::on_focus_update(FocusUpdateEvent &event) {
|
||||||
if (is_focused()) {
|
if (is_focused()) {
|
||||||
set_background_fill_color(m_focused_background_fill_color);
|
set_style_background_fill_color(m_style_focused_background_fill_color);
|
||||||
} else {
|
} else {
|
||||||
set_background_fill_color(m_normal_background_fill_color);
|
set_style_background_fill_color(m_style_normal_background_fill_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,13 +9,13 @@
|
||||||
namespace Raven {
|
namespace Raven {
|
||||||
|
|
||||||
class Button : public Widget {
|
class Button : public Widget {
|
||||||
DEF_PROP(text_fill_color, RGB, 0.0, 0.0, 0.0)
|
DEF_STYLE(text_fill_color, RGB, 0.0, 0.0, 0.0)
|
||||||
|
|
||||||
DEF_PROP(normal_background_fill_color, RGB, 0.0, 0.0, 0.0)
|
DEF_STYLE(normal_background_fill_color, RGB, 0.6941, 0.3843, 0.5254)
|
||||||
DEF_PROP(focused_background_fill_color, RGB, 0.0, 0.0, 0.0)
|
DEF_STYLE(focused_background_fill_color, RGB, 0.5607, 0.2470, 0.4431)
|
||||||
DEF_PROP(active_background_fill_color, RGB, 0.0, 0.0, 0.0)
|
DEF_STYLE(active_background_fill_color, RGB, 0.896, 0.743, 0.979)
|
||||||
|
|
||||||
DEF_PROP(font_description, PangoFontDescription*, nullptr)
|
DEF_STYLE(font_description, PangoFontDescription*, nullptr)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_text;
|
std::string m_text;
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#define DEF_PROP(name, type, ...) \
|
|
||||||
private: \
|
|
||||||
type m_##name {__VA_ARGS__}; \
|
|
||||||
public: \
|
|
||||||
void set_##name(type new_prop_value) { m_##name = new_prop_value; wants_repaint(); } \
|
|
||||||
type get_##name() { return m_##name; } \
|
|
||||||
private:
|
|
9
src/StyleMacros.hpp
Normal file
9
src/StyleMacros.hpp
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define DEF_STYLE(name, type, ...) \
|
||||||
|
private: \
|
||||||
|
type m_style_##name {__VA_ARGS__}; \
|
||||||
|
public: \
|
||||||
|
void set_style_##name(type new_style_value) { m_style_##name = new_style_value; wants_repaint(); } \
|
||||||
|
type get_style_##name() { return m_style_##name; } \
|
||||||
|
private:
|
|
@ -3,22 +3,12 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Forward.hpp"
|
#include "Forward.hpp"
|
||||||
#include "pango/pango-font.h"
|
#include "pango/pango-font.h"
|
||||||
#include "PropMacros.hpp"
|
#include "StyleMacros.hpp"
|
||||||
#include "RGB.hpp"
|
|
||||||
|
|
||||||
namespace Raven {
|
namespace Raven {
|
||||||
|
|
||||||
class TopLevelStyles {
|
class TopLevelStyles {
|
||||||
DEF_PROP(controls_font_description, PangoFontDescription*, nullptr)
|
DEF_STYLE(controls_font_description, PangoFontDescription*, nullptr)
|
||||||
|
|
||||||
DEF_PROP(text_color, RGB, 0.0, 0.0, 0.0)
|
|
||||||
DEF_PROP(accent_color, RGB, 0.6941, 0.3843, 0.5254)
|
|
||||||
DEF_PROP(accent_color_darker, RGB, 0.5607, 0.2470, 0.4431)
|
|
||||||
DEF_PROP(background_color, RGB, 0.9764, 0.9607, 0.8431)
|
|
||||||
|
|
||||||
DEF_PROP(button_normal_color, RGB, m_accent_color)
|
|
||||||
DEF_PROP(button_focused_color, RGB, m_accent_color_darker)
|
|
||||||
DEF_PROP(button_active_color, RGB, m_accent_color_darker)
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Window *m_window;
|
Window *m_window;
|
||||||
|
@ -32,12 +22,12 @@ public:
|
||||||
pango_font_description_set_weight(font_description, PANGO_WEIGHT_NORMAL);
|
pango_font_description_set_weight(font_description, PANGO_WEIGHT_NORMAL);
|
||||||
pango_font_description_set_absolute_size(font_description, 16 * PANGO_SCALE);
|
pango_font_description_set_absolute_size(font_description, 16 * PANGO_SCALE);
|
||||||
|
|
||||||
m_controls_font_description = font_description;
|
m_style_controls_font_description = font_description;
|
||||||
}
|
}
|
||||||
|
|
||||||
~TopLevelStyles() {
|
~TopLevelStyles() {
|
||||||
if (m_controls_font_description) {
|
if (m_style_controls_font_description) {
|
||||||
pango_font_description_free(m_controls_font_description);
|
pango_font_description_free(m_style_controls_font_description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,14 +37,14 @@ void Widget::remove_child(Widget *child) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::do_generic_paint() {
|
void Widget::do_generic_paint() {
|
||||||
if (m_do_background_fill) {
|
if (m_style_do_background_fill) {
|
||||||
auto painter = m_window->get_painter();
|
auto painter = m_window->get_painter();
|
||||||
auto cr = painter.get_cairo();
|
auto cr = painter.get_cairo();
|
||||||
|
|
||||||
cr->save();
|
cr->save();
|
||||||
|
|
||||||
painter.source_rgb(m_background_fill_color);
|
painter.source_rgb(m_style_background_fill_color);
|
||||||
painter.rounded_rectangle(m_current_geometry, m_background_border_radius);
|
painter.rounded_rectangle(m_current_geometry, m_style_background_border_radius);
|
||||||
painter.fill();
|
painter.fill();
|
||||||
|
|
||||||
cr->restore();
|
cr->restore();
|
||||||
|
|
|
@ -8,15 +8,15 @@
|
||||||
#include "Forward.hpp"
|
#include "Forward.hpp"
|
||||||
#include "RGB.hpp"
|
#include "RGB.hpp"
|
||||||
#include "TopLevelStyles.hpp"
|
#include "TopLevelStyles.hpp"
|
||||||
#include "PropMacros.hpp"
|
#include "StyleMacros.hpp"
|
||||||
|
|
||||||
namespace Raven {
|
namespace Raven {
|
||||||
|
|
||||||
class Widget {
|
class Widget {
|
||||||
|
|
||||||
DEF_PROP(do_background_fill, bool, false)
|
DEF_STYLE(do_background_fill, bool, false)
|
||||||
DEF_PROP(background_fill_color, RGB, 0, 0, 0)
|
DEF_STYLE(background_fill_color, RGB, 0, 0, 0)
|
||||||
DEF_PROP(background_border_radius, double, 0.0)
|
DEF_STYLE(background_border_radius, double, 0.0)
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -13,8 +13,8 @@ int main() {
|
||||||
|
|
||||||
button.set_current_geometry(Raven::Box(10, 10, 100, 30));
|
button.set_current_geometry(Raven::Box(10, 10, 100, 30));
|
||||||
main_widget.set_current_geometry(window.get_current_geometry());
|
main_widget.set_current_geometry(window.get_current_geometry());
|
||||||
main_widget.set_background_fill_color(window.get_top_level_styles()->get_background_color());
|
main_widget.set_style_background_fill_color(Raven::RGB(0.9764, 0.9607, 0.8431));
|
||||||
main_widget.set_do_background_fill(true);
|
main_widget.set_style_do_background_fill(true);
|
||||||
window.set_main_widget(&main_widget);
|
window.set_main_widget(&main_widget);
|
||||||
|
|
||||||
main_widget.add_child(&button);
|
main_widget.add_child(&button);
|
||||||
|
|
Loading…
Reference in a new issue