Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
castle055 committed Apr 28, 2024
2 parents df191f2 + 6790921 commit f819bfc
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/graphics/compositing.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ namespace cyd::ui::compositing {
//cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, (int) sfrm->width())
);
(*editor)->save();
(*editor)->set_antialias(Cairo::ANTIALIAS_NONE);
// (*editor)->set_antialias(Cairo::ANTIALIAS_NONE);
(*editor)->set_operator(Cairo::Context::Operator::OVER);
(*editor)->set_source(surface, node->op.orig_x + snode->op.x, node->op.orig_y + snode->op.y);
(*editor)->rectangle(node->op.orig_x + snode->op.x, node->op.orig_y + snode->op.y, snode->op.w, snode->op.h);
Expand Down
4 changes: 2 additions & 2 deletions include/graphics/pixelmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ struct pixelmap_t: public md_buffer_t<pixel_t, 2> {
pixelmap_t(unsigned long w, unsigned long h): md_buffer_t<pixel_t, 2>({w, h}) {
}

size_t width() {
[[nodiscard]] size_t width() const {
return size[0];
}

size_t height() {
[[nodiscard]] size_t height() const {
return size[1];
}
};
Expand Down
53 changes: 50 additions & 3 deletions include/graphics/vg.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ namespace cyd::ui::graphics::vg {
}

template<typename... T>
void append(T&&... _elements) {
static_assert((std::derived_from<std::remove_reference_t<T>, vg_element_t> && ...), "Elements must derive from vg_element_t.");
(elements.emplace_back(new std::remove_reference_t<T>{std::forward<T&&>(_elements)}), ...);
void append(T &&... _elements) {
static_assert(
(std::derived_from<std::remove_reference_t<T>, vg_element_t> && ...),
"Elements must derive from vg_element_t."
);
(elements.emplace_back(new std::remove_reference_t<T>{std::forward<T &&>(_elements)}), ...);
}
};

Expand Down Expand Up @@ -506,6 +509,50 @@ namespace cyd::ui::graphics::vg {
}
};

// ? Pixelmap
// * <g> - Pixelmap
struct pixelmap:
vg_element_t,
attrs_core<pixelmap>,
attr_x<pixelmap>,
attr_y<pixelmap>,
attr_rotate<pixelmap>,
attr_pivot_x<pixelmap>,
attr_pivot_y<pixelmap>,
attr_scale_x<pixelmap>,
attr_scale_y<pixelmap>,
attr_w<pixelmap>,
attr_h<pixelmap> {
const pixelmap_t &_pxm;
explicit pixelmap(const pixelmap_t &pxm): _pxm(pxm) {
}

void apply_to(pixelmap_editor_t &editor) const override {
// TODO - cairo_format_stride_for_width() should be called before allocating the image buffer and thus use its
// output to determine the 'width' of the buffer.
Cairo::RefPtr<Cairo::Surface> surf = Cairo::ImageSurface::create(
(unsigned char*) this->_pxm.data,
Cairo::Surface::Format::ARGB32,
(int) this->_pxm.width(),
(int) this->_pxm.height(),
(int) this->_pxm.width() * 4
);
editor->save();
editor->translate(origin_x + _x + _pivot_x, origin_y + _y + _pivot_y);
editor->rotate(_rotate * std::numbers::pi / 180.0);
editor->scale(_scale_x, _scale_y);
editor->set_source(surf, -_pivot_x, -_pivot_y);
editor->paint_with_alpha(_opacity);
editor->restore();

surf->finish();
}

footprint get_footprint() const override {
return {};
}
};

// * <textPath>
// * <tspan>
}
Expand Down
10 changes: 10 additions & 0 deletions include/graphics/vg_attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,20 @@ namespace cyd::ui::graphics::vg {
VG_ATTRIBUTE_DIMENSION(cx, 0);
//! @brief cy - center y-axis coordinate
VG_ATTRIBUTE_DIMENSION(cy, 0);
//! @brief rotate - angle of rotation in degrees
VG_ATTRIBUTE(double, rotate, 0);
//! @brief pivot_x - rotate pivot x-axis coordinate
VG_ATTRIBUTE_DIMENSION(pivot_x, 0);
//! @brief pivot_y - rotate pivot y-axis coordinate
VG_ATTRIBUTE_DIMENSION(pivot_y, 0);
//! @brief a1 - 1st angle in arcs in degrees
VG_ATTRIBUTE(double, a1, 0);
//! @brief a1 - 2st angle in arcs in degrees
VG_ATTRIBUTE(double, a2, 0);
//! @brief rotate - angle of rotation in degrees
VG_ATTRIBUTE(double, scale_x, 1);
//! @brief rotate - angle of rotation in degrees
VG_ATTRIBUTE(double, scale_y, 1);

using point_list_t = std::vector<std::array<int, 2>>;
//! @brief points
Expand Down

0 comments on commit f819bfc

Please sign in to comment.