2022-03-09 20:02:18 +02:00
|
|
|
#include "Painter.hpp"
|
2022-03-18 03:22:30 +02:00
|
|
|
#include "RGB.hpp"
|
2022-03-09 20:02:18 +02:00
|
|
|
|
|
|
|
namespace Raven {
|
|
|
|
|
|
|
|
void Painter::rounded_rectangle(Box &geometry, double border_radius) {
|
|
|
|
double aspect = 1.0;
|
|
|
|
double radius = border_radius / aspect;
|
|
|
|
double degrees = M_PI / 180.0;
|
|
|
|
double x = geometry.get_x();
|
|
|
|
double y = geometry.get_y();
|
|
|
|
double w = geometry.get_width();
|
|
|
|
double h = geometry.get_height();
|
|
|
|
|
|
|
|
m_cairo->begin_new_sub_path();
|
|
|
|
m_cairo->arc(x + w - radius, y + radius, radius, -90 * degrees, 0 * degrees);
|
|
|
|
m_cairo->arc(x + w - radius, y + h - radius, radius, 0 * degrees, 90 * degrees);
|
|
|
|
m_cairo->arc(x + radius, y + h - radius, radius, 90 * degrees, 180 * degrees);
|
|
|
|
m_cairo->arc(x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
|
|
|
|
m_cairo->close_path();
|
|
|
|
}
|
|
|
|
|
2022-03-18 02:49:16 +02:00
|
|
|
bool Painter::text(Point &where, std::string &text) {
|
|
|
|
if (m_pango_font_description == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
PangoLayout *layout = pango_cairo_create_layout(m_cairo->cobj());
|
|
|
|
|
|
|
|
pango_layout_set_font_description(layout, m_pango_font_description);
|
|
|
|
pango_layout_set_text(layout, text.c_str(), -1);
|
|
|
|
|
|
|
|
m_cairo->move_to(where.get_x(), where.get_y());
|
|
|
|
pango_cairo_show_layout(m_cairo->cobj(), layout);
|
|
|
|
|
|
|
|
g_object_unref(layout);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Painter::text(Box &geometry, std::string &text, PaintTextAlign align) {
|
|
|
|
if (m_pango_font_description == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
PangoLayout *layout = pango_cairo_create_layout(m_cairo->cobj());
|
|
|
|
|
|
|
|
int font_width;
|
|
|
|
int font_height;
|
|
|
|
|
|
|
|
pango_layout_set_font_description(layout, m_pango_font_description);
|
|
|
|
pango_layout_set_text(layout, text.c_str(), -1);
|
|
|
|
|
|
|
|
pango_layout_get_pixel_size(layout, &font_width, &font_height);
|
|
|
|
|
|
|
|
double x = -1;
|
|
|
|
double y = geometry.get_y() + ((geometry.get_height() - font_height) / 2);
|
|
|
|
|
|
|
|
if (align == PaintTextAlign::Center) {
|
|
|
|
x = geometry.get_x() + ((geometry.get_width() - font_width) / 2);
|
|
|
|
} else {
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_cairo->move_to(x, y);
|
|
|
|
pango_cairo_show_layout(m_cairo->cobj(), layout);
|
|
|
|
|
|
|
|
g_object_unref(layout);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Painter::source_rgb(RGB &source_rgb) {
|
|
|
|
m_cairo->set_source_rgb(source_rgb.get_r(), source_rgb.get_g(), source_rgb.get_b());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Painter::fill() {
|
|
|
|
m_cairo->fill();
|
|
|
|
}
|
|
|
|
|
2022-03-09 20:02:18 +02:00
|
|
|
}
|