20#include <cairomm/context.h>
39 _name =
"CanvasItemCtrl:Null";
48 , _handle{.type = type}
66 static bool first_run =
true;
67 if (!first_run)
return;
70 constexpr int step = 40;
72 constexpr auto types = std::to_array({
85 constexpr int scale = 1;
87 auto surface = Cairo::ImageSurface::create(Cairo::Surface::Format::ARGB32, (types.size() + 1) * step *
scale, (h + 1) * step *
scale);
88 cairo_surface_set_device_scale(
surface->cobj(), 1, 1);
91 .device_scale =
scale,
92 .cr = Cairo::Context::create(
surface),
97 ctx->set_source_rgb(1, 0.9, 0.9);
99 ctx->set_source_rgba(0, 0, 1, 0.2);
100 ctx->set_line_width(
scale);
101 constexpr double pix =
scale & 1 ? 0.5 : 0;
105 ctx->line_to(
surface->get_width(), y);
108 for (
int i = 1; i <= types.size(); i++) {
109 double x = i * step *
scale + pix;
111 ctx->line_to(x,
surface->get_height());
120 for (
auto type : types) {
130 surface->write_to_png(
"handles.png");
175 if (tolerance == 0) {
176 return _bounds->interiorContains(p);
186 if (
_fill == fill)
return;
208 if (
_shape == shape)
return;
240 if (size_index < MIN_INDEX || size_index >
MAX_INDEX) {
241 std::cerr <<
"CanvasItemCtrl::set_size_via_index: size_index out of range!" << std::endl;
251 auto size =
_width * style.scale() + style.size_extra();
326 if (
_angle == angle)
return;
344 return std::atan2(affine[1], affine[0]);
364 double const w_half =
width / 2;
373 shape = style.shape();
383 double const half =
width / 2.0;
385 dx = -(half + 2) * cos(angle);
386 dy = -(half + 2) * sin(angle);
398 dx = -(half / 2 + 2) * cos(angle);
399 dy = -(half / 2 + 2) * sin(angle);
405 dx = (half / 2 + 2) * (sin(angle) - cos(angle));
406 dy = (half / 2 + 2) * (-sin(angle) - cos(angle));
511 auto stroke_width = style.stroke_width() * (1.0f +
_width * style.stroke_scale());
526 auto pixel_fit = [=](
float v) {
return std::round(v * device_scale) / device_scale; };
532 auto outline_width = pixel_fit(style.outline_width());
534 auto size = std::floor(
width * device_scale) / device_scale;
540 .outline = style.getOutline(),
541 .stroke_width = stroke_width,
542 .outline_width = outline_width,
546 .device_scale = device_scale
constexpr bool DUMP_HANDLES
A class to represent a control node.
Cairo::RefPtr< Cairo::ImageSurface > surface
3x3 matrix representing an affine transformation.
bool flips() const
Check whether this transformation flips objects.
static CRect from_xywh(Coord x, Coord y, Coord w, Coord h)
Create rectangle from origin and dimensions.
Two-dimensional point with integer coordinates.
Two-dimensional point that doubles as a vector.
bool isFinite() const
Check whether both coordinates are finite.
std::shared_ptr< Handles::Css const > const & handlesCss() const
void set_fill(uint32_t rgba) override
void set_click(bool click=true)
bool contains(Geom::Point const &p, double tolerance=0) override
If tolerance is zero, returns true if point p (in canvas units) is inside bounding box,...
void _invalidate_ctrl_handles() override
void build_cache(int device_scale) const
Build object-specific cache.
float get_total_width() const
void set_selected(bool selected=true)
void set_normal(bool selected=false)
Reset the state to normal or normal selected.
std::shared_ptr< Cairo::ImageSurface const > _cache
void set_shape(CanvasItemCtrlShape shape)
void _update(bool propagate) override
Update and redraw control ctrl.
void set_stroke(uint32_t rgba) override
float get_stroke_width() const
int get_pixmap_width(int device_scale) const
Handles::TypeState _handle
void _render(CanvasItemBuffer &buf) const override
Render ctrl to screen via Cairo.
CanvasItemCtrlShape _shape
void set_hover(bool hover=true)
void set_type(CanvasItemCtrlType type)
void set_size(HandleSize rel_size)
void set_anchor(SPAnchorType anchor)
void set_size_via_index(int size_index)
CanvasItemCtrl(CanvasItemGroup *group)
Create a null control node.
void set_position(Geom::Point const &position)
Set the position.
double closest_distance_to(Geom::Point const &p) const
Returns distance between point in canvas units and position of ctrl.
void set_angle(double angle)
Geom::Affine const & affine() const
CanvasItemContext * _context
static Preferences * get()
Access the singleton Preferences object.
int getIntLimited(Glib::ustring const &pref_path, int def=0, int min=INT_MIN, int max=INT_MAX)
Retrieve a limited integer.
struct _cairo_surface cairo_surface_t
GenericRect< IntCoord > IntRect
Angle distance(Angle const &a, Angle const &b)
std::shared_ptr< Cairo::ImageSurface const > draw(RenderParams const ¶ms)
Helper class to stream background task notifications as a series of messages.
static double angle_of(Geom::Affine const &affine)
@ CANVAS_ITEM_CTRL_SHAPE_CARROW
@ CANVAS_ITEM_CTRL_SHAPE_SALIGN
@ CANVAS_ITEM_CTRL_SHAPE_CALIGN
@ CANVAS_ITEM_CTRL_SHAPE_PIVOT
@ CANVAS_ITEM_CTRL_SHAPE_DARROW
@ CANVAS_ITEM_CTRL_SHAPE_SARROW
@ CANVAS_ITEM_CTRL_SHAPE_MALIGN
@ CANVAS_ITEM_CTRL_TYPE_CENTER
@ CANVAS_ITEM_CTRL_TYPE_GUIDE_HANDLE
@ CANVAS_ITEM_CTRL_TYPE_POINTER
@ CANVAS_ITEM_CTRL_TYPE_NODE_AUTO
@ CANVAS_ITEM_CTRL_TYPE_ADJ_ROTATE
@ CANVAS_ITEM_CTRL_TYPE_POINT
@ CANVAS_ITEM_CTRL_TYPE_NODE_CUSP
@ CANVAS_ITEM_CTRL_TYPE_ADJ_HANDLE
@ CANVAS_ITEM_CTRL_TYPE_MARKER
@ CANVAS_ITEM_CTRL_TYPE_NODE_SMOOTH
@ CANVAS_ITEM_CTRL_TYPE_ADJ_SALIGN
@ CANVAS_ITEM_CTRL_TYPE_ADJ_CALIGN
@ CANVAS_ITEM_CTRL_TYPE_ADJ_SKEW
@ CANVAS_ITEM_CTRL_TYPE_ADJ_MALIGN
@ CANVAS_ITEM_CTRL_TYPE_ADJ_CENTER
static int get_size_default()
Singleton class to access the preferences file in a convenient way.
Class used when rendering canvas items.