Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
ctrl-handle-styling.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef INKSCAPE_DISPLAY_CONTROL_CTRL_HANDLE_STYLING_H
3#define INKSCAPE_DISPLAY_CONTROL_CTRL_HANDLE_STYLING_H
7/*
8 * Authors:
9 * Sanidhya Singh
10 *
11 * Copyright (C) 2023 Authors
12 *
13 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
14 */
15
16#include <compare>
17#include <cstdint>
18#include <functional> // std::hash
19#include <string>
20#include <unordered_map>
21
22#include "canvas-item-enums.h"
23
24namespace Inkscape::Handles {
25
30{
32 bool selected = false;
33 bool hover = false;
34 bool click = false;
35
36 auto operator<=>(TypeState const &) const = default;
37};
38
39} // namespace Inkscape::Handles
40
44template <> struct std::hash<Inkscape::Handles::TypeState>
45{
46 size_t operator()(Inkscape::Handles::TypeState const &handle) const
47 {
48 return (size_t{handle.type} << 3) |
49 (size_t{handle.selected} << 2) |
50 (size_t{handle.hover} << 1) |
51 (size_t{handle.click});
52 }
53};
54
55namespace Inkscape::Handles {
56
60template <typename T>
62{
63public:
64 explicit Property(T val) : value(val) {}
65 Property(T val, int spec) : value(val), specificity(spec) {}
66
67 /*
68 * Set value of property based on specificity.
69 */
70 void setProperty(T newValue, int newSpecificity)
71 {
72 if (newSpecificity >= specificity) {
73 value = newValue;
74 specificity = newSpecificity;
75 }
76 }
77
78 /*
79 * Interface to get the value.
80 */
81 T const &operator()() const
82 {
83 return value;
84 }
85
86private:
88 int specificity = 0;
89};
90
114
119struct Css
120{
121 std::unordered_map<TypeState, Style> style_map;
122};
123
124Css parse_css(const std::string& css_file_name);
125
126inline constexpr auto USER_CUSTOM_CSS_FILE_NAME{"handle-theme-custom.css"};
127
128} // namespace Inkscape::Handles
129
130#endif // INKSCAPE_DISPLAY_CONTROL_CTRL_HANDLE_STYLING_H
131
132/*
133 Local Variables:
134 mode:c++
135 c-file-style:"stroustrup"
136 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
137 indent-tabs-mode:nil
138 fill-column:99
139 End:
140*/
141// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Enums for CanvasItems.
Template struct for properties with specificities.
void setProperty(T newValue, int newSpecificity)
Classes related to control handle styling.
Css parse_css(const std::string &css_file_name)
constexpr auto USER_CUSTOM_CSS_FILE_NAME
Helper class to stream background task notifications as a series of messages.
@ CANVAS_ITEM_CTRL_SHAPE_SQUARE
@ CANVAS_ITEM_CTRL_TYPE_DEFAULT
The result of parsing the handle styling CSS files, containing all information needed to style a give...
std::unordered_map< TypeState, Style > style_map
Struct containing all required styling for handles.
Property< uint32_t > stroke
Property< float > outline_opacity
Property< uint32_t > outline
Property< CanvasItemCtrlShape > shape
Property< uint32_t > fill
Struct to manage type and state.
auto operator<=>(TypeState const &) const =default
size_t operator()(Inkscape::Handles::TypeState const &handle) const