Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
util.h File Reference

Go to the source code of this file.

Classes

class  UIBuilderError
 
class  UIFileUnavailable
 
class  WidgetUnavailable
 

Namespaces

namespace  Cairo
 Control handle rendering/caching.
 
namespace  Glib
 
namespace  Gtk
 
namespace  Inkscape
 Helper class to stream background task notifications as a series of messages.
 
namespace  Inkscape::Colors
 A set of useful color modifying functions which do not fit as generic methods on the color class itself but which are used in various places.
 
namespace  Inkscape::UI
 User interface code.
 

Enumerations

enum class  Inkscape::UI::ForEachResult { Inkscape::UI::_continue , Inkscape::UI::_break , Inkscape::UI::_skip }
 Whether for_each_*() will continue or stop after calling Func per child. More...
 

Functions

Glib::ustring ink_ellipsize_text (Glib::ustring const &src, std::size_t maxlen)
 
void reveal_widget (Gtk::Widget *widget, bool show)
 Show widget, if the widget has a Gtk::Reveal parent, reveal instead.
 
bool is_widget_effectively_visible (Gtk::Widget const *widget)
 
void Inkscape::UI::set_icon_sizes (Gtk::Widget *parent, int pixel_size)
 Recursively set all the icon sizes inside this parent widget.
 
void Inkscape::UI::set_icon_sizes (GtkWidget *parent, int pixel_size)
 
void Inkscape::UI::gui_warning (const std::string &msg, Gtk::Window *parent_window)
 
void Inkscape::UI::system_open (const Glib::ustring &path)
 Opens the given path with platform-specific tools.
 
std::vector< Gtk::Widget * > Inkscape::UI::get_children (Gtk::Widget &widget)
 Get a vector of the widgetʼs children, from get_first_child() through each get_next_sibling().
 
Gtk::Widget & Inkscape::UI::get_nth_child (Gtk::Widget &widget, std::size_t index)
 Get the widgetʼs child at the given position. Throws std::out_of_range if the index is invalid.
 
template<typename Widget >
void Inkscape::UI::remove_all_children (Widget &widget)
 For each child in get_children(widget), call widget.remove(*child). May not cause delete child!
 
template<typename Func >
Gtk::Widget * Inkscape::UI::for_each_child (Gtk::Widget &widget, Func &&func, bool const plus_self=false, bool const recurse=false, int const level=0)
 Call Func with a reference to each child of parent, until it returns _break.
 
template<typename Func >
Gtk::Widget * Inkscape::UI::for_each_descendant (Gtk::Widget &widget, Func &&func)
 Like for_each_child() but also tests the initial widget & recurses through childrenʼs children.
 
template<typename Func >
Gtk::Widget * Inkscape::UI::for_each_parent (Gtk::Widget &widget, Func &&func)
 Call Func with a reference to successive parents, until Func returns _break.
 
template<typename Func >
Gtk::Widget * Inkscape::UI::for_each_page (Gtk::Notebook &notebook, Func &&func)
 Similar to for_each_child, but only iterates over pages in a notebook.
 
Gtk::Widget * Inkscape::UI::find_widget_by_name (Gtk::Widget &parent, Glib::ustring const &name, bool visible_only)
 Returns a named descendent of parent, which has the given name, or nullptr if there's none.
 
Gtk::Widget * Inkscape::UI::find_focusable_widget (Gtk::Widget &parent)
 This function traverses a tree of widgets searching for first focusable widget.
 
bool Inkscape::UI::is_descendant_of (Gtk::Widget const &descendant, Gtk::Widget const &ancestor)
 Returns if widget is a descendant of given ancestor, i.e.: itself, a child, or a childʼs child.
 
bool Inkscape::UI::contains_focus (Gtk::Widget &widget)
 Returns if widget or one of its descendants has focus.
 
int Inkscape::UI::get_font_size (Gtk::Widget &widget)
 Get the relative font size as determined by a widgetʼs style/Pango contexts.
 
void Inkscape::UI::ellipsize (Gtk::Label &label, int const max_width_chars, Pango::EllipsizeMode const mode)
 
Gdk::RGBA mix_colors (const Gdk::RGBA &a, const Gdk::RGBA &b, float ratio)
 
Gdk::RGBA change_alpha (const Gdk::RGBA &color, double new_alpha)
 
double get_luminance (const Gdk::RGBA &color)
 Calculate luminance of an RGBA color from its RGB in range 0 to 1 inclusive.
 
Gdk::RGBA get_color_with_class (Gtk::Widget &widget, Glib::ustring const &css_class)
 
Glib::ustring gdk_to_css_color (const Gdk::RGBA &color)
 These GUI related color conversions allow us to convert from SVG xml attributes to Gdk colors, without needing the entire CMS framework, which would be excessive for widget painting.
 
Gdk::RGBA css_color_to_gdk (const char *value)
 
guint32 to_guint32 (Gdk::RGBA const &rgba)
 
Gdk::RGBA color_to_rgba (Inkscape::Colors::Color const &color)
 
Gdk::RGBA to_rgba (guint32 const u32)
 
uint32_t conv_gdk_color_to_rgba (const Gdk::RGBA &color, double replace_alpha=-1)
 
Geom::IntRect cairo_to_geom (const Cairo::RectangleInt &rect)
 
Cairo::RectangleInt geom_to_cairo (const Geom::IntRect &rect)
 
Cairo::Matrix geom_to_cairo (const Geom::Affine &affine)
 
Geom::IntPoint dimensions (const Cairo::RefPtr< Cairo::ImageSurface > &surface)
 
Geom::IntPoint dimensions (const Gdk::Rectangle &allocation)
 
template<typename T >
Gdk::Graphene::Rect geom_to_gtk (Geom::GenericRect< T > const &rect)
 
Gdk::Graphene::Point geom_to_gtk (Geom::IntPoint const &point)
 
Gdk::Graphene::Point geom_to_gtk (Geom::Point const &point)
 
std::vector< GskColorStop > create_cubic_gradient (const Gdk::RGBA &from, const Gdk::RGBA &to, Geom::Point ctrl1, Geom::Point ctrl2, Geom::Point p0=Geom::Point(0, 0), Geom::Point p1=Geom::Point(1, 1), int steps=8)
 
void set_dark_titlebar (Glib::RefPtr< Gdk::Surface > const &surface, bool is_dark)
 
unsigned int get_color_value (const Glib::ustring color)
 Color is store as a string in the form #RRGGBBAA, '0' means "unset".
 
Glib::ustring round_numbers (const Glib::ustring &text, int precision)
 
void truncate_digits (const Glib::RefPtr< Gtk::TextBuffer > &buffer, int precision)
 
Glib::RefPtr< Gdk::Texture > to_texture (Cairo::RefPtr< Cairo::Surface > const &surface)
 Convert an image surface in ARGB32 format to a texture.
 
void restrict_minsize_to_square (Gtk::Widget &widget, int min_size_px)
 
char const * get_text (Gtk::Editable const &editable)
 Get the text from a GtkEditable without the temporary copy imposed by gtkmm.
 

Function Documentation

◆ cairo_to_geom()

◆ change_alpha()

◆ color_to_rgba()

Gdk::RGBA color_to_rgba ( Inkscape::Colors::Color const &  color)

Definition at line 320 of file util.cpp.

References to_rgba(), and Inkscape::Colors::Color::toRGBA().

Referenced by Inkscape::Extension::ParamColor::get_widget().

◆ conv_gdk_color_to_rgba()

uint32_t conv_gdk_color_to_rgba ( const Gdk::RGBA &  color,
double  replace_alpha = -1 
)

◆ create_cubic_gradient()

std::vector< GskColorStop > create_cubic_gradient ( const Gdk::RGBA &  from,
const Gdk::RGBA &  to,
Geom::Point  ctrl1,
Geom::Point  ctrl2,
Geom::Point  p0 = Geom::Point(0, 0),
Geom::Point  p1 = Geom::Point(1, 1),
int  steps = 8 
)

Definition at line 378 of file util.cpp.

References Geom::bernstein_value_at(), mix_colors(), offset, and result.

Referenced by Inkscape::UI::Widget::Ruler::draw_ruler().

◆ css_color_to_gdk()

Gdk::RGBA css_color_to_gdk ( const char *  value)

Definition at line 343 of file util.cpp.

References Inkscape::Colors::hex_to_rgba(), and to_rgba().

◆ dimensions() [1/2]

◆ dimensions() [2/2]

Geom::IntPoint dimensions ( const Gdk::Rectangle &  allocation)

Definition at line 373 of file util.cpp.

◆ gdk_to_css_color()

Glib::ustring gdk_to_css_color ( const Gdk::RGBA &  color)

These GUI related color conversions allow us to convert from SVG xml attributes to Gdk colors, without needing the entire CMS framework, which would be excessive for widget painting.

Definition at line 340 of file util.cpp.

References Inkscape::Colors::rgba_to_hex(), and to_guint32().

Referenced by Inkscape::UI::Dialog::StartScreen::canvas_changed(), and Inkscape::UI::Widget::GradientWithStops::draw_func().

◆ geom_to_cairo() [1/2]

Cairo::Matrix geom_to_cairo ( const Geom::Affine affine)

Definition at line 363 of file util.cpp.

◆ geom_to_cairo() [2/2]

◆ geom_to_gtk() [1/3]

template<typename T >
Gdk::Graphene::Rect geom_to_gtk ( Geom::GenericRect< T > const &  rect)
inline

◆ geom_to_gtk() [2/3]

Gdk::Graphene::Point geom_to_gtk ( Geom::IntPoint const &  point)
inline

Definition at line 218 of file util.h.

References Geom::IntPoint::x(), and Geom::IntPoint::y().

◆ geom_to_gtk() [3/3]

Gdk::Graphene::Point geom_to_gtk ( Geom::Point const &  point)
inline

Definition at line 221 of file util.h.

References Geom::Point::x(), and Geom::Point::y().

◆ get_color_value()

unsigned int get_color_value ( const Glib::ustring  color)

Color is store as a string in the form #RRGGBBAA, '0' means "unset".

Parameters
color- The string color from glade.

Definition at line 275 of file util.cpp.

References SP_RGBA32_F_COMPOSE().

Referenced by Inkscape::UI::Dialog::StartScreen::theme_changed().

◆ get_color_with_class()

◆ get_luminance()

double get_luminance ( const Gdk::RGBA &  color)

Calculate luminance of an RGBA color from its RGB in range 0 to 1 inclusive.

This uses the perceived brightness formula given at: https://www.w3.org/TR/AERT/#color-contrast

Definition at line 295 of file util.cpp.

◆ get_text()

char const * get_text ( Gtk::Editable const &  editable)

Get the text from a GtkEditable without the temporary copy imposed by gtkmm.

Definition at line 549 of file util.cpp.

Referenced by Inkscape::UI::Widget::InkSpinButton::commit_entry().

◆ ink_ellipsize_text()

Glib::ustring ink_ellipsize_text ( Glib::ustring const &  src,
std::size_t  maxlen 
)

Definition at line 67 of file util.cpp.

◆ is_widget_effectively_visible()

bool is_widget_effectively_visible ( Gtk::Widget const *  widget)

Definition at line 97 of file util.cpp.

◆ mix_colors()

Gdk::RGBA mix_colors ( const Gdk::RGBA &  a,
const Gdk::RGBA &  b,
float  ratio 
)

◆ restrict_minsize_to_square()

void restrict_minsize_to_square ( Gtk::Widget &  widget,
int  min_size_px 
)

Definition at line 537 of file util.cpp.

References css, and name.

Referenced by Inkscape::UI::Widget::ColorPicker::_construct().

◆ reveal_widget()

void reveal_widget ( Gtk::Widget *  widget,
bool  show 
)

Show widget, if the widget has a Gtk::Reveal parent, reveal instead.

Parameters
widget- The child widget to show.

Definition at line 83 of file util.cpp.

◆ round_numbers()

Glib::ustring round_numbers ( const Glib::ustring &  text,
int  precision 
)

Definition at line 473 of file util.cpp.

References fmt_number().

Referenced by truncate_digits().

◆ set_dark_titlebar()

void set_dark_titlebar ( Glib::RefPtr< Gdk::Surface > const &  surface,
bool  is_dark 
)

Definition at line 433 of file util.cpp.

References surface.

Referenced by Inkscape::UI::ThemeContext::themechangecallback().

◆ to_guint32()

◆ to_rgba()

Gdk::RGBA to_rgba ( guint32 const  u32)

◆ to_texture()

◆ truncate_digits()

void truncate_digits ( const Glib::RefPtr< Gtk::TextBuffer > &  buffer,
int  precision 
)

Definition at line 481 of file util.cpp.

References end, round_numbers(), and start.

Referenced by Inkscape::UI::Dialog::AttrDialog::truncateDigits().