Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
util.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#include "ui/util.h"
3#include "helper/geom.h"
4#include "util.h"
5
6namespace Inkscape {
7namespace UI {
8namespace Widget {
9
10void region_to_path(Cairo::RefPtr<Cairo::Context> const &cr, Cairo::RefPtr<Cairo::Region> const &reg)
11{
12 for (int i = 0; i < reg->get_num_rectangles(); i++) {
13 auto rect = reg->get_rectangle(i);
14 cr->rectangle(rect.x, rect.y, rect.width, rect.height);
15 }
16}
17
18Cairo::RefPtr<Cairo::Region> shrink_region(Cairo::RefPtr<Cairo::Region> const &reg, int d, int t)
19{
20 // Find the bounding rect, expanded by 1 in all directions.
21 auto rect = geom_to_cairo(expandedBy(cairo_to_geom(reg->get_extents()), 1));
22
23 // Take the complement of the region within the rect.
24 auto reg2 = Cairo::Region::create(rect);
25 reg2->subtract(reg);
26
27 // Increase the width and height of every rectangle by d.
28 auto reg3 = Cairo::Region::create();
29 for (int i = 0; i < reg2->get_num_rectangles(); i++) {
30 auto rect = reg2->get_rectangle(i);
31 rect.x += t;
32 rect.y += t;
33 rect.width += d;
34 rect.height += d;
35 reg3->do_union(rect);
36 }
37
38 // Take the complement of the region within the rect.
39 reg2 = Cairo::Region::create(rect);
40 reg2->subtract(reg3);
41
42 return reg2;
43}
44
46{
47 auto opacity = color.stealOpacity();
48 return Colors::make_contrasted_color(color, 1.0 - opacity);
49}
50
51} // namespace Widget
52} // namespace UI
53} // namespace Inkscape
54
55/*
56 Local Variables:
57 mode:c++
58 c-file-style:"stroustrup"
59 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
60 indent-tabs-mode:nil
61 fill-column:99
62 End:
63*/
64// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
double stealOpacity()
Get the opacity, and remove it from this color.
Definition color.cpp:417
Specific geometry functions for Inkscape, not provided my lib2geom.
auto expandedBy(Geom::IntRect rect, int amount)
Definition geom.h:67
Color make_contrasted_color(Color const &orig, double amount)
Make a darker or lighter version of the color, useful for making checkerboards.
Definition utils.cpp:134
void region_to_path(Cairo::RefPtr< Cairo::Context > const &cr, Cairo::RefPtr< Cairo::Region > const &reg)
Turn a Cairo region into a path on a given Cairo context.
Definition util.cpp:10
Colors::Color checkerboard_darken(Colors::Color color)
Definition util.cpp:45
Cairo::RefPtr< Cairo::Region > shrink_region(Cairo::RefPtr< Cairo::Region > const &reg, int d, int t)
Shrink a region by d/2 in all directions, while also translating it by (d/2 + t, d/2 + t).
Definition util.cpp:18
Helper class to stream background task notifications as a series of messages.
Cairo::RectangleInt geom_to_cairo(const Geom::IntRect &rect)
Definition util.cpp:338
Geom::IntRect cairo_to_geom(const Cairo::RectangleInt &rect)
Definition util.cpp:343