Merge lp:~penginsbacon/inkscape/fill-n-stroke-cppify into lp:~inkscape.dev/inkscape/trunk
- fill-n-stroke-cppify
- Merge into trunk
Status: | Superseded |
---|---|
Proposed branch: | lp:~penginsbacon/inkscape/fill-n-stroke-cppify |
Merge into: | lp:~inkscape.dev/inkscape/trunk |
Diff against target: |
9988 lines (+3793/-4028) 45 files modified
src/desktop-style.cpp (+2/-2) src/extension/internal/cairo-render-context.cpp (+8/-9) src/extension/internal/emf-print.cpp (+4/-4) src/extension/internal/wmf-print.cpp (+2/-2) src/extension/param/color.cpp (+32/-41) src/extension/param/color.h (+7/-2) src/extension/param/parameter.cpp (+5/-2) src/knot-holder-entity.cpp (+9/-9) src/selection-chemistry.cpp (+5/-5) src/sp-item.cpp (+4/-4) src/sp-pattern.cpp (+387/-402) src/sp-pattern.h (+98/-65) src/ui/CMakeLists.txt (+14/-0) src/ui/Makefile_insert (+2/-0) src/ui/dialog/objects.cpp (+17/-20) src/ui/dialog/objects.h (+6/-3) src/ui/dialog/tags.cpp (+1/-1) src/ui/selected-color.cpp (+161/-0) src/ui/selected-color.h (+96/-0) src/ui/widget/Makefile_insert (+12/-0) src/ui/widget/color-entry.cpp (+104/-0) src/ui/widget/color-entry.h (+53/-0) src/ui/widget/color-icc-selector.cpp (+570/-620) src/ui/widget/color-icc-selector.h (+39/-35) src/ui/widget/color-notebook.cpp (+226/-673) src/ui/widget/color-notebook.h (+61/-82) src/ui/widget/color-picker.cpp (+31/-41) src/ui/widget/color-picker.h (+5/-3) src/ui/widget/color-scales.cpp (+559/-657) src/ui/widget/color-scales.h (+64/-56) src/ui/widget/color-slider.cpp (+611/-727) src/ui/widget/color-slider.h (+99/-49) src/ui/widget/color-wheel-selector.cpp (+218/-279) src/ui/widget/color-wheel-selector.h (+73/-56) src/widgets/CMakeLists.txt (+0/-10) src/widgets/Makefile_insert (+0/-10) src/widgets/fill-style.cpp (+2/-2) src/widgets/gradient-selector.cpp (+4/-0) src/widgets/gradient-vector.cpp (+58/-24) src/widgets/paint-selector.cpp (+52/-54) src/widgets/paint-selector.h (+13/-3) src/widgets/sp-color-selector.cpp (+6/-1) src/widgets/sp-color-selector.h (+8/-0) src/widgets/swatch-selector.cpp (+58/-70) src/widgets/swatch-selector.h (+7/-5) |
To merge this branch: | bzr merge lp:~penginsbacon/inkscape/fill-n-stroke-cppify |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tavmjong Bah | code | Needs Fixing | |
Review via email: mp+257482@code.launchpad.net |
This proposal has been superseded by a proposal from 2015-05-03.
Commit message
Description of the change
This branch merges the c++-sification effort from GSOC 2014 project.
Refactored classes are related to fill'n'stroke dialog. The list includes:
SPColorSelector
SPColorWheelSel
SPColorICCSelector
SPColorScales
SPNotebook
SPColorSlider
SPPattern
Tavmjong Bah (tavmjong-free) wrote : | # |
- 14071. By Tomasz Boczkowski
-
merge with trunk
- 14072. By Tomasz Boczkowski
-
gtk3 compile fix
- 14073. By Tomasz Boczkowski
-
Removed unnecessary inclusion of glibmm/threads.h
- 14074. By Tomasz Boczkowski
-
merged trunk
- 14075. By Tomasz Boczkowski
-
Introduced fixes after merge proposal review
- 14076. By Tomasz Boczkowski
-
Removed commented out code from ColorNotebook
- 14077. By Tomasz Boczkowski
-
Reformatted refactored files
- 14078. By Tomasz Boczkowski
-
Reformatted SPPattern
- 14079. By Tomasz Boczkowski
-
renamed SPPattern methods to match coding style
- 14080. By Tomasz Boczkowski
-
merged trunk
- 14081. By Tomasz Boczkowski
-
Using MODE_SOLID_COLOR in paint selector instead of duplicated MODE_COLOR_RGB and MODE_COLOR_CMYK
- 14082. By Tomasz Boczkowski
-
fixed crash in paint selector when changing from gradient to solid color
- 14083. By Tomasz Boczkowski
-
merged trunk
- 14084. By Tomasz Boczkowski
-
fixed color selector not remembering it's last open tab
- 14085. By Tomasz Boczkowski
-
merged trunk
- 14086. By Tomasz Boczkowski
-
merged trunk
- 14087. By Tomasz Boczkowski
-
fixed: color scales - extra row in RGB mode
- 14088. By Tomasz Boczkowski
-
fixed: color scales - updating color when switched from undefined
- 14089. By Tomasz Boczkowski
-
fixed: color icc selector - extra rows on startup
Unmerged revisions
Preview Diff
1 | === modified file 'src/desktop-style.cpp' |
2 | --- src/desktop-style.cpp 2015-02-27 03:21:48 +0000 |
3 | +++ src/desktop-style.cpp 2015-05-03 11:19:29 +0000 |
4 | @@ -576,8 +576,8 @@ |
5 | return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server |
6 | } |
7 | |
8 | - SPPattern *pat = pattern_getroot (pattern); |
9 | - SPPattern *pat_res = pattern_getroot (pattern_res); |
10 | + SPPattern *pat = SP_PATTERN (server)->rootPattern(); |
11 | + SPPattern *pat_res = SP_PATTERN (server_res)->rootPattern(); |
12 | if (pat_res != pat) { |
13 | return QUERY_STYLE_MULTIPLE_DIFFERENT; // different pattern roots |
14 | } |
15 | |
16 | === modified file 'src/extension/internal/cairo-render-context.cpp' |
17 | --- src/extension/internal/cairo-render-context.cpp 2015-03-07 07:05:30 +0000 |
18 | +++ src/extension/internal/cairo-render-context.cpp 2015-05-03 11:19:29 +0000 |
19 | @@ -1008,17 +1008,16 @@ |
20 | ps2user = Geom::identity(); |
21 | pcs2dev = Geom::identity(); |
22 | |
23 | - double x = pattern_x(pat); |
24 | - double y = pattern_y(pat); |
25 | - double width = pattern_width(pat); |
26 | - double height = pattern_height(pat); |
27 | + double x = pat->x(); |
28 | + double y = pat->y(); |
29 | + double width = pat->width(); |
30 | + double height = pat->height(); |
31 | double bbox_width_scaler; |
32 | double bbox_height_scaler; |
33 | |
34 | TRACE(("%f x %f pattern\n", width, height)); |
35 | |
36 | - if (pbox && pattern_patternUnits(pat) == SP_PATTERN_UNITS_OBJECTBOUNDINGBOX) { |
37 | - //Geom::Affine bbox2user (pbox->x1 - pbox->x0, 0.0, 0.0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0); |
38 | + if (pbox && pat->patternUnits() == SPPattern::UNITS_OBJECTBOUNDINGBOX) { |
39 | bbox_width_scaler = pbox->width(); |
40 | bbox_height_scaler = pbox->height(); |
41 | ps2user[4] = x * bbox_width_scaler + pbox->left(); |
42 | @@ -1031,13 +1030,13 @@ |
43 | } |
44 | |
45 | // apply pattern transformation |
46 | - Geom::Affine pattern_transform(pattern_patternTransform(pat)); |
47 | + Geom::Affine pattern_transform(pat->getTransform()); |
48 | ps2user *= pattern_transform; |
49 | Geom::Point ori (ps2user[4], ps2user[5]); |
50 | |
51 | // create pattern contents coordinate system |
52 | if (pat->viewBox_set) { |
53 | - Geom::Rect view_box = *pattern_viewBox(pat); |
54 | + Geom::Rect view_box = *pat->viewbox(); |
55 | |
56 | double x, y, w, h; |
57 | x = 0; |
58 | @@ -1050,7 +1049,7 @@ |
59 | pcs2dev[3] = h / view_box.height(); |
60 | pcs2dev[4] = x - view_box.left() * pcs2dev[0]; |
61 | pcs2dev[5] = y - view_box.top() * pcs2dev[3]; |
62 | - } else if (pbox && pattern_patternContentUnits(pat) == SP_PATTERN_UNITS_OBJECTBOUNDINGBOX) { |
63 | + } else if (pbox && pat->patternContentUnits() == SPPattern::UNITS_OBJECTBOUNDINGBOX) { |
64 | pcs2dev[0] = pbox->width(); |
65 | pcs2dev[3] = pbox->height(); |
66 | } |
67 | |
68 | === modified file 'src/extension/internal/emf-print.cpp' |
69 | --- src/extension/internal/emf-print.cpp 2015-04-27 18:49:22 +0000 |
70 | +++ src/extension/internal/emf-print.cpp 2015-05-03 11:19:29 +0000 |
71 | @@ -388,8 +388,8 @@ |
72 | } else if (SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style))) { // must be paint-server |
73 | SPPaintServer *paintserver = style->fill.value.href->getObject(); |
74 | SPPattern *pat = SP_PATTERN(paintserver); |
75 | - double dwidth = pattern_width(pat); |
76 | - double dheight = pattern_height(pat); |
77 | + double dwidth = pat->width(); |
78 | + double dheight = pat->height(); |
79 | width = dwidth; |
80 | height = dheight; |
81 | brush_classify(pat, 0, &pixbuf, &hatchType, &hatchColor, &bkColor); |
82 | @@ -573,8 +573,8 @@ |
83 | if (SP_IS_PATTERN(SP_STYLE_STROKE_SERVER(style))) { // must be paint-server |
84 | SPPaintServer *paintserver = style->stroke.value.href->getObject(); |
85 | SPPattern *pat = SP_PATTERN(paintserver); |
86 | - double dwidth = pattern_width(pat); |
87 | - double dheight = pattern_height(pat); |
88 | + double dwidth = pat->width(); |
89 | + double dheight = pat->height(); |
90 | width = dwidth; |
91 | height = dheight; |
92 | brush_classify(pat, 0, &pixbuf, &hatchType, &hatchColor, &bkColor); |
93 | |
94 | === modified file 'src/extension/internal/wmf-print.cpp' |
95 | --- src/extension/internal/wmf-print.cpp 2015-04-27 18:49:22 +0000 |
96 | +++ src/extension/internal/wmf-print.cpp 2015-05-03 11:19:29 +0000 |
97 | @@ -380,8 +380,8 @@ |
98 | } else if (SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style))) { // must be paint-server |
99 | SPPaintServer *paintserver = style->fill.value.href->getObject(); |
100 | SPPattern *pat = SP_PATTERN(paintserver); |
101 | - double dwidth = pattern_width(pat); |
102 | - double dheight = pattern_height(pat); |
103 | + double dwidth = pat->width(); |
104 | + double dheight = pat->height(); |
105 | width = dwidth; |
106 | height = dheight; |
107 | brush_classify(pat, 0, &pixbuf, &hatchType, &hatchColor, &bkColor); |
108 | |
109 | === modified file 'src/extension/param/color.cpp' |
110 | --- src/extension/param/color.cpp 2015-04-27 23:38:31 +0000 |
111 | +++ src/extension/param/color.cpp 2015-05-03 11:19:29 +0000 |
112 | @@ -24,41 +24,37 @@ |
113 | #include "color.h" |
114 | |
115 | #include <color.h> |
116 | -#include "widgets/sp-color-selector.h" |
117 | -#include "widgets/sp-color-notebook.h" |
118 | +#include "ui/widget/color-notebook.h" |
119 | #include "preferences.h" |
120 | |
121 | - |
122 | namespace Inkscape { |
123 | namespace Extension { |
124 | |
125 | -void sp_color_param_changed(SPColorSelector *csel, GObject *cp); |
126 | - |
127 | - |
128 | ParamColor::~ParamColor(void) |
129 | { |
130 | - |
131 | + _color_changed.disconnect(); |
132 | } |
133 | |
134 | guint32 ParamColor::set( guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ ) |
135 | { |
136 | - _value = in; |
137 | + _color_changed.block(true); |
138 | + _color.setValue(in); |
139 | + _color_changed.block(false); |
140 | |
141 | gchar * prefname = this->pref_name(); |
142 | std::string value; |
143 | string(value); |
144 | - |
145 | + |
146 | Inkscape::Preferences *prefs = Inkscape::Preferences::get(); |
147 | prefs->setString(extension_pref_root + prefname, value); |
148 | g_free(prefname); |
149 | |
150 | - return _value; |
151 | + return in; |
152 | } |
153 | |
154 | -ParamColor::ParamColor(const gchar *name, const gchar *guitext, const gchar *desc, const Parameter::_scope_t scope, |
155 | - bool gui_hidden, const gchar *gui_tip, Inkscape::Extension::Extension *ext, |
156 | - Inkscape::XML::Node *xml) |
157 | - : Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), _value(0), _changeSignal(0) |
158 | +ParamColor::ParamColor (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : |
159 | + Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), |
160 | + _changeSignal(0) |
161 | { |
162 | const char * defaulthex = NULL; |
163 | if (xml->firstChild() != NULL) |
164 | @@ -72,51 +68,46 @@ |
165 | if (!paramval.empty()) |
166 | defaulthex = paramval.data(); |
167 | |
168 | - if (defaulthex) |
169 | - _value = atoi(defaulthex); |
170 | + if (defaulthex) { |
171 | + _color.setValue(atoi(defaulthex)); |
172 | + } |
173 | + _color_changed = _color.signal_changed.connect(sigc::mem_fun(this, &ParamColor::_onColorChanged)); |
174 | + |
175 | } |
176 | |
177 | void ParamColor::string(std::string &string) const |
178 | { |
179 | char str[16]; |
180 | - sprintf(str, "%i", _value); |
181 | + snprintf(str, 16, "%i", _color.value()); |
182 | string += str; |
183 | } |
184 | |
185 | Gtk::Widget *ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal<void> * changeSignal ) |
186 | { |
187 | - if (_gui_hidden) return NULL; |
188 | + using Inkscape::UI::Widget::ColorNotebook; |
189 | + |
190 | + if (_gui_hidden) return NULL; |
191 | |
192 | _changeSignal = new sigc::signal<void>(*changeSignal); |
193 | - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); |
194 | - SPColorSelector* spColorSelector = (SPColorSelector*)sp_color_selector_new(SP_TYPE_COLOR_NOTEBOOK); |
195 | |
196 | - ColorSelector* colorSelector = spColorSelector->base; |
197 | - if (_value < 1) { |
198 | - _value = 0xFF000000; |
199 | + if (_color.value() < 1) { |
200 | + _color_changed.block(true); |
201 | + _color.setValue(0xFF000000); |
202 | + _color_changed.block(false); |
203 | } |
204 | - SPColor *color = new SPColor( _value ); |
205 | - float alpha = (_value & 0xff) / 255.0F; |
206 | - colorSelector->setColorAlpha(*color, alpha); |
207 | - |
208 | - hbox->pack_start (*Glib::wrap(&spColorSelector->vbox), true, true, 0); |
209 | - g_signal_connect(G_OBJECT(spColorSelector), "changed", G_CALLBACK(sp_color_param_changed), (void*)this); |
210 | - |
211 | - gtk_widget_show(GTK_WIDGET(spColorSelector)); |
212 | + |
213 | + Gtk::HBox *hbox = Gtk::manage(new Gtk::HBox(false, 4)); |
214 | + Gtk::Widget *selector = Gtk::manage(new ColorNotebook(_color)); |
215 | + hbox->pack_start (*selector, true, true, 0); |
216 | + selector->show(); |
217 | hbox->show(); |
218 | - |
219 | - return dynamic_cast<Gtk::Widget *>(hbox); |
220 | + return hbox; |
221 | } |
222 | |
223 | -void sp_color_param_changed(SPColorSelector *csel, GObject *obj) |
224 | +void ParamColor::_onColorChanged() |
225 | { |
226 | - const SPColor color = csel->base->getColor(); |
227 | - float alpha = csel->base->getAlpha(); |
228 | - |
229 | - ParamColor* ptr = reinterpret_cast<ParamColor*>(obj); |
230 | - ptr->set(color.toRGBA32( alpha ), NULL, NULL); |
231 | - |
232 | - ptr->_changeSignal->emit(); |
233 | + if (_changeSignal) |
234 | + _changeSignal->emit(); |
235 | } |
236 | |
237 | }; /* namespace Extension */ |
238 | |
239 | === modified file 'src/extension/param/color.h' |
240 | --- src/extension/param/color.h 2012-02-29 01:16:51 +0000 |
241 | +++ src/extension/param/color.h 2015-05-03 11:19:29 +0000 |
242 | @@ -9,6 +9,7 @@ |
243 | */ |
244 | |
245 | #include "parameter.h" |
246 | +#include "ui/selected-color.h" |
247 | |
248 | class SPDocument; |
249 | |
250 | @@ -25,14 +26,17 @@ |
251 | |
252 | class ParamColor : public Parameter { |
253 | private: |
254 | - guint32 _value; |
255 | + void _onColorChanged(); |
256 | + |
257 | + Inkscape::UI::SelectedColor _color; |
258 | + sigc::connection _color_changed; |
259 | public: |
260 | ParamColor(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); |
261 | |
262 | virtual ~ParamColor(void); |
263 | |
264 | /** Returns \c _value, with a \i const to protect it. */ |
265 | - guint32 get( SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/ ) const { return _value; } |
266 | + guint32 get( SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/ ) const { return _color.value(); } |
267 | |
268 | guint32 set (guint32 in, SPDocument * doc, Inkscape::XML::Node * node); |
269 | |
270 | @@ -44,6 +48,7 @@ |
271 | virtual void string (std::string &string) const; |
272 | |
273 | sigc::signal<void> * _changeSignal; |
274 | + |
275 | }; // class ParamColor |
276 | |
277 | } // namespace Extension |
278 | |
279 | === modified file 'src/extension/param/parameter.cpp' |
280 | --- src/extension/param/parameter.cpp 2014-03-27 01:33:44 +0000 |
281 | +++ src/extension/param/parameter.cpp 2015-05-03 11:19:29 +0000 |
282 | @@ -15,6 +15,10 @@ |
283 | # include "config.h" |
284 | #endif |
285 | |
286 | +#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H |
287 | +#include <glibmm/threads.h> |
288 | +#endif |
289 | + |
290 | #ifdef linux // does the dollar sign need escaping when passed as string parameter? |
291 | # define ESCAPE_DOLLAR_COMMANDLINE |
292 | #endif |
293 | @@ -26,8 +30,7 @@ |
294 | #include "document-private.h" |
295 | #include "sp-object.h" |
296 | #include <color.h> |
297 | -#include "widgets/sp-color-selector.h" |
298 | -#include "widgets/sp-color-notebook.h" |
299 | +#include "ui/widget/color-notebook.h" |
300 | |
301 | #include "parameter.h" |
302 | #include "bool.h" |
303 | |
304 | === modified file 'src/knot-holder-entity.cpp' |
305 | --- src/knot-holder-entity.cpp 2014-08-04 16:10:37 +0000 |
306 | +++ src/knot-holder-entity.cpp 2015-05-03 11:19:29 +0000 |
307 | @@ -140,19 +140,19 @@ |
308 | |
309 | static gdouble sp_pattern_extract_theta(SPPattern const *pat) |
310 | { |
311 | - Geom::Affine transf = pat->patternTransform; |
312 | + Geom::Affine transf = pat->getTransform(); |
313 | return Geom::atan2(transf.xAxis()); |
314 | } |
315 | |
316 | static Geom::Point sp_pattern_extract_scale(SPPattern const *pat) |
317 | { |
318 | - Geom::Affine transf = pat->patternTransform; |
319 | + Geom::Affine transf = pat->getTransform(); |
320 | return Geom::Point( transf.expansionX(), transf.expansionY() ); |
321 | } |
322 | |
323 | static Geom::Point sp_pattern_extract_trans(SPPattern const *pat) |
324 | { |
325 | - return Geom::Point(pat->patternTransform[4], pat->patternTransform[5]); |
326 | + return Geom::Point(pat->getTransform()[4], pat->getTransform()[5]); |
327 | } |
328 | |
329 | void |
330 | @@ -191,7 +191,7 @@ |
331 | { |
332 | SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer()); |
333 | |
334 | - gdouble x = pattern_width(pat); |
335 | + gdouble x = pat->width(); |
336 | gdouble y = 0; |
337 | Geom::Point delta = Geom::Point(x,y); |
338 | Geom::Point scale = sp_pattern_extract_scale(pat); |
339 | @@ -240,8 +240,8 @@ |
340 | |
341 | // Get the new scale from the position of the knotholder |
342 | Geom::Point d = p_snapped - sp_pattern_extract_trans(pat); |
343 | - gdouble pat_x = pattern_width(pat); |
344 | - gdouble pat_y = pattern_height(pat); |
345 | + gdouble pat_x = pat->width(); |
346 | + gdouble pat_y = pat->height(); |
347 | Geom::Scale scl(1); |
348 | if ( state & GDK_CONTROL_MASK ) { |
349 | // if ctrl is pressed: use 1:1 scaling |
350 | @@ -267,10 +267,10 @@ |
351 | { |
352 | SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer()); |
353 | |
354 | - gdouble x = pattern_width(pat); |
355 | - gdouble y = pattern_height(pat); |
356 | + gdouble x = pat->width(); |
357 | + gdouble y = pat->height(); |
358 | Geom::Point delta = Geom::Point(x,y); |
359 | - Geom::Affine a = pat->patternTransform; |
360 | + Geom::Affine a = pat->getTransform(); |
361 | a[4] = 0; |
362 | a[5] = 0; |
363 | delta = delta * a; |
364 | |
365 | === modified file 'src/selection-chemistry.cpp' |
366 | --- src/selection-chemistry.cpp 2015-05-02 19:48:52 +0000 |
367 | +++ src/selection-chemistry.cpp 2015-05-03 11:19:29 +0000 |
368 | @@ -1939,8 +1939,8 @@ |
369 | } |
370 | |
371 | } else if (dynamic_cast<SPPattern *>(sel_server) && dynamic_cast<SPPattern *>(iter_server)) { |
372 | - SPPattern *sel_pat = pattern_getroot(dynamic_cast<SPPattern *>(sel_server)); |
373 | - SPPattern *iter_pat = pattern_getroot(dynamic_cast<SPPattern *>(iter_server)); |
374 | + SPPattern *sel_pat = dynamic_cast<SPPattern *>(sel_server)->rootPattern(); |
375 | + SPPattern *iter_pat = dynamic_cast<SPPattern *>(iter_server)->rootPattern(); |
376 | if (sel_pat == iter_pat) { |
377 | match = true; |
378 | } |
379 | @@ -3288,7 +3288,7 @@ |
380 | int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); |
381 | prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); |
382 | |
383 | - gchar const *pat_id = pattern_tile(repr_copies, bbox, doc, |
384 | + gchar const *pat_id = SPPattern::produce(repr_copies, bbox, doc, |
385 | ( Geom::Affine(Geom::Translate(desktop->dt2doc(Geom::Point(r->min()[Geom::X], |
386 | r->max()[Geom::Y])))) |
387 | * parent_transform.inverse() ), |
388 | @@ -3366,9 +3366,9 @@ |
389 | |
390 | did = true; |
391 | |
392 | - SPPattern *pattern = pattern_getroot(basePat); |
393 | + SPPattern *pattern = basePat->rootPattern(); |
394 | |
395 | - Geom::Affine pat_transform = pattern_patternTransform(basePat); |
396 | + Geom::Affine pat_transform = basePat->getTransform(); |
397 | pat_transform *= item->transform; |
398 | |
399 | for (SPObject *child = pattern->firstChild() ; child != NULL; child = child->next ) { |
400 | |
401 | === modified file 'src/sp-item.cpp' |
402 | --- src/sp-item.cpp 2015-03-16 20:22:36 +0000 |
403 | +++ src/sp-item.cpp 2015-05-03 11:19:29 +0000 |
404 | @@ -1234,8 +1234,8 @@ |
405 | SPObject *server = style->getFillPaintServer(); |
406 | SPPattern *serverPatt = dynamic_cast<SPPattern *>(server); |
407 | if ( serverPatt ) { |
408 | - SPPattern *pattern = sp_pattern_clone_if_necessary(this, serverPatt, "fill"); |
409 | - sp_pattern_transform_multiply(pattern, postmul, set); |
410 | + SPPattern *pattern = serverPatt->clone_if_necessary(this, "fill"); |
411 | + pattern->transform_multiply(postmul, set); |
412 | } |
413 | } |
414 | |
415 | @@ -1244,8 +1244,8 @@ |
416 | SPObject *server = style->getStrokePaintServer(); |
417 | SPPattern *serverPatt = dynamic_cast<SPPattern *>(server); |
418 | if ( serverPatt ) { |
419 | - SPPattern *pattern = sp_pattern_clone_if_necessary(this, serverPatt, "stroke"); |
420 | - sp_pattern_transform_multiply(pattern, postmul, set); |
421 | + SPPattern *pattern = serverPatt->clone_if_necessary(this, "stroke"); |
422 | + pattern->transform_multiply(postmul, set); |
423 | } |
424 | } |
425 | } |
426 | |
427 | === modified file 'src/sp-pattern.cpp' |
428 | --- src/sp-pattern.cpp 2015-04-26 09:44:42 +0000 |
429 | +++ src/sp-pattern.cpp 2015-05-03 11:19:29 +0000 |
430 | @@ -5,7 +5,7 @@ |
431 | * Lauris Kaplinski <lauris@kaplinski.com> |
432 | * bulia byak <buliabyak@users.sf.net> |
433 | * Jon A. Cruz <jon@joncruz.org> |
434 | - * Abhishek Sharma |
435 | + * Abhishek Sharma |
436 | * |
437 | * Copyright (C) 2002 Lauris Kaplinski |
438 | * |
439 | @@ -13,15 +13,15 @@ |
440 | */ |
441 | |
442 | #ifdef HAVE_CONFIG_H |
443 | -# include "config.h" |
444 | +#include "config.h" |
445 | #endif |
446 | |
447 | #include <cstring> |
448 | #include <string> |
449 | #include <glibmm.h> |
450 | #include <2geom/transforms.h> |
451 | +#include <sigc++/functors/mem_fun.h> |
452 | |
453 | -#include "macros.h" |
454 | #include "svg/svg.h" |
455 | #include "display/cairo-utils.h" |
456 | #include "display/drawing-context.h" |
457 | @@ -34,67 +34,61 @@ |
458 | #include "style.h" |
459 | #include "sp-pattern.h" |
460 | #include "xml/repr.h" |
461 | -#include "display/grayscale.h" |
462 | - |
463 | -#include <sigc++/functors/ptr_fun.h> |
464 | -#include <sigc++/adaptors/bind.h> |
465 | - |
466 | -/* |
467 | - * Pattern |
468 | - */ |
469 | -static void pattern_ref_changed(SPObject *old_ref, SPObject *ref, SPPattern *pat); |
470 | -static void pattern_ref_modified (SPObject *ref, guint flags, SPPattern *pattern); |
471 | - |
472 | -SPPattern::SPPattern() : SPPaintServer(), SPViewBox() { |
473 | - this->href = NULL; |
474 | - |
475 | - this->ref = new SPPatternReference(this); |
476 | - this->ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(pattern_ref_changed), this)); |
477 | - |
478 | - this->patternUnits = SP_PATTERN_UNITS_OBJECTBOUNDINGBOX; |
479 | - this->patternUnits_set = FALSE; |
480 | - |
481 | - this->patternContentUnits = SP_PATTERN_UNITS_USERSPACEONUSE; |
482 | - this->patternContentUnits_set = FALSE; |
483 | - |
484 | - this->patternTransform = Geom::identity(); |
485 | - this->patternTransform_set = FALSE; |
486 | - |
487 | - this->x.unset(); |
488 | - this->y.unset(); |
489 | - this->width.unset(); |
490 | - this->height.unset(); |
491 | -} |
492 | - |
493 | -SPPattern::~SPPattern() { |
494 | -} |
495 | - |
496 | -void SPPattern::build(SPDocument* doc, Inkscape::XML::Node* repr) { |
497 | - SPPaintServer::build(doc, repr); |
498 | - |
499 | - this->readAttr( "patternUnits" ); |
500 | - this->readAttr( "patternContentUnits" ); |
501 | - this->readAttr( "patternTransform" ); |
502 | - this->readAttr( "x" ); |
503 | - this->readAttr( "y" ); |
504 | - this->readAttr( "width" ); |
505 | - this->readAttr( "height" ); |
506 | - this->readAttr( "viewBox" ); |
507 | - this->readAttr( "preserveAspectRatio" ); |
508 | - this->readAttr( "xlink:href" ); |
509 | - |
510 | - /* Register ourselves */ |
511 | - doc->addResource("pattern", this); |
512 | -} |
513 | - |
514 | -void SPPattern::release() { |
515 | + |
516 | +#include "sp-factory.h" |
517 | + |
518 | +SPPattern::SPPattern() |
519 | + : SPPaintServer() |
520 | + , SPViewBox() |
521 | +{ |
522 | + this->ref = new SPPatternReference(this); |
523 | + this->ref->changedSignal().connect(sigc::mem_fun(this, &SPPattern::_onRefChanged)); |
524 | + |
525 | + this->_pattern_units = UNITS_OBJECTBOUNDINGBOX; |
526 | + this->_pattern_units_set = false; |
527 | + |
528 | + this->_pattern_content_units = UNITS_USERSPACEONUSE; |
529 | + this->_pattern_content_units_set = false; |
530 | + |
531 | + this->_pattern_transform = Geom::identity(); |
532 | + this->_pattern_transform_set = false; |
533 | + |
534 | + this->_x.unset(); |
535 | + this->_y.unset(); |
536 | + this->_width.unset(); |
537 | + this->_height.unset(); |
538 | +} |
539 | + |
540 | +SPPattern::~SPPattern() {} |
541 | + |
542 | +void SPPattern::build(SPDocument *doc, Inkscape::XML::Node *repr) |
543 | +{ |
544 | + SPPaintServer::build(doc, repr); |
545 | + |
546 | + this->readAttr("patternUnits"); |
547 | + this->readAttr("patternContentUnits"); |
548 | + this->readAttr("patternTransform"); |
549 | + this->readAttr("x"); |
550 | + this->readAttr("y"); |
551 | + this->readAttr("width"); |
552 | + this->readAttr("height"); |
553 | + this->readAttr("viewBox"); |
554 | + this->readAttr("preserveAspectRatio"); |
555 | + this->readAttr("xlink:href"); |
556 | + |
557 | + /* Register ourselves */ |
558 | + doc->addResource("pattern", this); |
559 | +} |
560 | + |
561 | +void SPPattern::release() |
562 | +{ |
563 | if (this->document) { |
564 | // Unregister ourselves |
565 | this->document->removeResource("pattern", this); |
566 | } |
567 | |
568 | if (this->ref) { |
569 | - this->modified_connection.disconnect(); |
570 | + this->_modified_connection.disconnect(); |
571 | this->ref->detach(); |
572 | delete this->ref; |
573 | this->ref = NULL; |
574 | @@ -103,113 +97,121 @@ |
575 | SPPaintServer::release(); |
576 | } |
577 | |
578 | -void SPPattern::set(unsigned int key, const gchar* value) { |
579 | - switch (key) { |
580 | - case SP_ATTR_PATTERNUNITS: |
581 | - if (value) { |
582 | - if (!strcmp (value, "userSpaceOnUse")) { |
583 | - this->patternUnits = SP_PATTERN_UNITS_USERSPACEONUSE; |
584 | - } else { |
585 | - this->patternUnits = SP_PATTERN_UNITS_OBJECTBOUNDINGBOX; |
586 | - } |
587 | - |
588 | - this->patternUnits_set = TRUE; |
589 | - } else { |
590 | - this->patternUnits_set = FALSE; |
591 | - } |
592 | - |
593 | - this->requestModified(SP_OBJECT_MODIFIED_FLAG); |
594 | - break; |
595 | - |
596 | - case SP_ATTR_PATTERNCONTENTUNITS: |
597 | - if (value) { |
598 | - if (!strcmp (value, "userSpaceOnUse")) { |
599 | - this->patternContentUnits = SP_PATTERN_UNITS_USERSPACEONUSE; |
600 | - } else { |
601 | - this->patternContentUnits = SP_PATTERN_UNITS_OBJECTBOUNDINGBOX; |
602 | - } |
603 | - |
604 | - this->patternContentUnits_set = TRUE; |
605 | - } else { |
606 | - this->patternContentUnits_set = FALSE; |
607 | - } |
608 | - |
609 | - this->requestModified(SP_OBJECT_MODIFIED_FLAG); |
610 | - break; |
611 | - |
612 | - case SP_ATTR_PATTERNTRANSFORM: { |
613 | - Geom::Affine t; |
614 | - |
615 | - if (value && sp_svg_transform_read (value, &t)) { |
616 | - this->patternTransform = t; |
617 | - this->patternTransform_set = TRUE; |
618 | - } else { |
619 | - this->patternTransform = Geom::identity(); |
620 | - this->patternTransform_set = FALSE; |
621 | - } |
622 | - |
623 | - this->requestModified(SP_OBJECT_MODIFIED_FLAG); |
624 | - break; |
625 | - } |
626 | - case SP_ATTR_X: |
627 | - this->x.readOrUnset(value); |
628 | - this->requestModified(SP_OBJECT_MODIFIED_FLAG); |
629 | - break; |
630 | - |
631 | - case SP_ATTR_Y: |
632 | - this->y.readOrUnset(value); |
633 | - this->requestModified(SP_OBJECT_MODIFIED_FLAG); |
634 | - break; |
635 | - |
636 | - case SP_ATTR_WIDTH: |
637 | - this->width.readOrUnset(value); |
638 | - this->requestModified(SP_OBJECT_MODIFIED_FLAG); |
639 | - break; |
640 | - |
641 | - case SP_ATTR_HEIGHT: |
642 | - this->height.readOrUnset(value); |
643 | - this->requestModified(SP_OBJECT_MODIFIED_FLAG); |
644 | - break; |
645 | - |
646 | - case SP_ATTR_VIEWBOX: |
647 | - set_viewBox( value ); |
648 | +void SPPattern::set(unsigned int key, const gchar *value) |
649 | +{ |
650 | + switch (key) { |
651 | + case SP_ATTR_PATTERNUNITS: |
652 | + if (value) { |
653 | + if (!strcmp(value, "userSpaceOnUse")) { |
654 | + this->_pattern_units = UNITS_USERSPACEONUSE; |
655 | + } |
656 | + else { |
657 | + this->_pattern_units = UNITS_OBJECTBOUNDINGBOX; |
658 | + } |
659 | + |
660 | + this->_pattern_units_set = true; |
661 | + } |
662 | + else { |
663 | + this->_pattern_units_set = false; |
664 | + } |
665 | + |
666 | + this->requestModified(SP_OBJECT_MODIFIED_FLAG); |
667 | + break; |
668 | + |
669 | + case SP_ATTR_PATTERNCONTENTUNITS: |
670 | + if (value) { |
671 | + if (!strcmp(value, "userSpaceOnUse")) { |
672 | + this->_pattern_content_units = UNITS_USERSPACEONUSE; |
673 | + } |
674 | + else { |
675 | + this->_pattern_content_units = UNITS_OBJECTBOUNDINGBOX; |
676 | + } |
677 | + |
678 | + this->_pattern_content_units_set = true; |
679 | + } |
680 | + else { |
681 | + this->_pattern_content_units_set = false; |
682 | + } |
683 | + |
684 | + this->requestModified(SP_OBJECT_MODIFIED_FLAG); |
685 | + break; |
686 | + |
687 | + case SP_ATTR_PATTERNTRANSFORM: { |
688 | + Geom::Affine t; |
689 | + |
690 | + if (value && sp_svg_transform_read(value, &t)) { |
691 | + this->_pattern_transform = t; |
692 | + this->_pattern_transform_set = true; |
693 | + } |
694 | + else { |
695 | + this->_pattern_transform = Geom::identity(); |
696 | + this->_pattern_transform_set = false; |
697 | + } |
698 | + |
699 | + this->requestModified(SP_OBJECT_MODIFIED_FLAG); |
700 | + break; |
701 | + } |
702 | + case SP_ATTR_X: |
703 | + this->_x.readOrUnset(value); |
704 | + this->requestModified(SP_OBJECT_MODIFIED_FLAG); |
705 | + break; |
706 | + |
707 | + case SP_ATTR_Y: |
708 | + this->_y.readOrUnset(value); |
709 | + this->requestModified(SP_OBJECT_MODIFIED_FLAG); |
710 | + break; |
711 | + |
712 | + case SP_ATTR_WIDTH: |
713 | + this->_width.readOrUnset(value); |
714 | + this->requestModified(SP_OBJECT_MODIFIED_FLAG); |
715 | + break; |
716 | + |
717 | + case SP_ATTR_HEIGHT: |
718 | + this->_height.readOrUnset(value); |
719 | + this->requestModified(SP_OBJECT_MODIFIED_FLAG); |
720 | + break; |
721 | + |
722 | + case SP_ATTR_VIEWBOX: |
723 | + set_viewBox(value); |
724 | this->requestModified(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); |
725 | break; |
726 | |
727 | case SP_ATTR_PRESERVEASPECTRATIO: |
728 | - set_preserveAspectRatio( value ); |
729 | + set_preserveAspectRatio(value); |
730 | this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); |
731 | break; |
732 | |
733 | - case SP_ATTR_XLINK_HREF: |
734 | - if ( value && this->href && ( strcmp(value, this->href) == 0 ) ) { |
735 | - /* Href unchanged, do nothing. */ |
736 | - } else { |
737 | - g_free(this->href); |
738 | - this->href = NULL; |
739 | - |
740 | - if (value) { |
741 | - // First, set the href field; it's only used in the "unchanged" check above. |
742 | - this->href = g_strdup(value); |
743 | - // Now do the attaching, which emits the changed signal. |
744 | - if (value) { |
745 | - try { |
746 | - this->ref->attach(Inkscape::URI(value)); |
747 | - } catch (Inkscape::BadURIException &e) { |
748 | - g_warning("%s", e.what()); |
749 | - this->ref->detach(); |
750 | - } |
751 | - } else { |
752 | - this->ref->detach(); |
753 | - } |
754 | - } |
755 | - } |
756 | - break; |
757 | - |
758 | - default: |
759 | - SPPaintServer::set(key, value); |
760 | - break; |
761 | - } |
762 | + case SP_ATTR_XLINK_HREF: |
763 | + if (value && this->href == value) { |
764 | + /* Href unchanged, do nothing. */ |
765 | + } |
766 | + else { |
767 | + this->href.clear(); |
768 | + |
769 | + if (value) { |
770 | + // First, set the href field; it's only used in the "unchanged" check above. |
771 | + this->href = value; |
772 | + // Now do the attaching, which emits the changed signal. |
773 | + if (value) { |
774 | + try { |
775 | + this->ref->attach(Inkscape::URI(value)); |
776 | + } |
777 | + catch (Inkscape::BadURIException &e) { |
778 | + g_warning("%s", e.what()); |
779 | + this->ref->detach(); |
780 | + } |
781 | + } |
782 | + else { |
783 | + this->ref->detach(); |
784 | + } |
785 | + } |
786 | + } |
787 | + break; |
788 | + |
789 | + default: |
790 | + SPPaintServer::set(key, value); |
791 | + break; |
792 | + } |
793 | } |
794 | |
795 | |
796 | @@ -217,104 +219,90 @@ |
797 | |
798 | /* fixme: We need ::order_changed handler too (Lauris) */ |
799 | |
800 | -static GSList *pattern_getchildren(SPPattern *pat) |
801 | +void SPPattern::_getChildren(std::list<SPObject *> &l) |
802 | { |
803 | - GSList *l = NULL; |
804 | - |
805 | - for (SPPattern *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
806 | + for (SPPattern *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
807 | if (pat_i->firstChild()) { // find the first one with children |
808 | - for (SPObject *child = pat->firstChild() ; child ; child = child->getNext() ) { |
809 | - l = g_slist_prepend (l, child); |
810 | - } |
811 | - break; // do not go further up the chain if children are found |
812 | - } |
813 | - } |
814 | - |
815 | - return l; |
816 | -} |
817 | - |
818 | -void SPPattern::update(SPCtx* ctx, unsigned int flags) { |
819 | - if (flags & SP_OBJECT_MODIFIED_FLAG) { |
820 | - flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; |
821 | - } |
822 | - |
823 | - flags &= SP_OBJECT_MODIFIED_CASCADE; |
824 | - |
825 | - GSList *l = pattern_getchildren (this); |
826 | - l = g_slist_reverse (l); |
827 | - |
828 | - while (l) { |
829 | - SPObject *child = SP_OBJECT (l->data); |
830 | - |
831 | - sp_object_ref (child, NULL); |
832 | - l = g_slist_remove (l, child); |
833 | - |
834 | - if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { |
835 | - child->updateDisplay(ctx, flags); |
836 | - } |
837 | - |
838 | - sp_object_unref (child, NULL); |
839 | - } |
840 | -} |
841 | - |
842 | -void SPPattern::modified(unsigned int flags) { |
843 | - if (flags & SP_OBJECT_MODIFIED_FLAG) { |
844 | - flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; |
845 | - } |
846 | - |
847 | - flags &= SP_OBJECT_MODIFIED_CASCADE; |
848 | - |
849 | - GSList *l = pattern_getchildren (this); |
850 | - l = g_slist_reverse (l); |
851 | - |
852 | - while (l) { |
853 | - SPObject *child = SP_OBJECT (l->data); |
854 | - |
855 | - sp_object_ref (child, NULL); |
856 | - l = g_slist_remove (l, child); |
857 | - |
858 | - if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { |
859 | - child->emitModified(flags); |
860 | - } |
861 | - |
862 | - sp_object_unref (child, NULL); |
863 | - } |
864 | -} |
865 | - |
866 | -/** |
867 | -Gets called when the pattern is reattached to another <pattern> |
868 | -*/ |
869 | -static void |
870 | -pattern_ref_changed(SPObject *old_ref, SPObject *ref, SPPattern *pat) |
871 | -{ |
872 | - if (old_ref) { |
873 | - pat->modified_connection.disconnect(); |
874 | - } |
875 | - |
876 | - if (SP_IS_PATTERN (ref)) { |
877 | - pat->modified_connection = ref->connectModified(sigc::bind<2>(sigc::ptr_fun(&pattern_ref_modified), pat)); |
878 | - } |
879 | - |
880 | - pattern_ref_modified (ref, 0, pat); |
881 | -} |
882 | - |
883 | -/** |
884 | -Gets called when the referenced <pattern> is changed |
885 | -*/ |
886 | -static void pattern_ref_modified (SPObject */*ref*/, guint /*flags*/, SPPattern *pattern) |
887 | -{ |
888 | - if ( SP_IS_OBJECT(pattern) ) { |
889 | - pattern->requestModified(SP_OBJECT_MODIFIED_FLAG); |
890 | - } |
891 | + for (SPObject *child = pat_i->firstChild(); child; child = child->getNext()) { |
892 | + l.push_back(child); |
893 | + } |
894 | + break; // do not go further up the chain if children are found |
895 | + } |
896 | + } |
897 | +} |
898 | + |
899 | +void SPPattern::update(SPCtx *ctx, unsigned int flags) |
900 | +{ |
901 | + typedef std::list<SPObject *>::iterator SPObjectIterator; |
902 | + |
903 | + if (flags & SP_OBJECT_MODIFIED_FLAG) { |
904 | + flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; |
905 | + } |
906 | + |
907 | + flags &= SP_OBJECT_MODIFIED_CASCADE; |
908 | + |
909 | + std::list<SPObject *> l; |
910 | + _getChildren(l); |
911 | + |
912 | + for (SPObjectIterator it = l.begin(); it != l.end(); it++) { |
913 | + SPObject *child = *it; |
914 | + |
915 | + sp_object_ref(child, NULL); |
916 | + |
917 | + if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { |
918 | + child->updateDisplay(ctx, flags); |
919 | + } |
920 | + |
921 | + sp_object_unref(child, NULL); |
922 | + } |
923 | +} |
924 | + |
925 | +void SPPattern::modified(unsigned int flags) |
926 | +{ |
927 | + typedef std::list<SPObject *>::iterator SPObjectIterator; |
928 | + |
929 | + if (flags & SP_OBJECT_MODIFIED_FLAG) { |
930 | + flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; |
931 | + } |
932 | + |
933 | + flags &= SP_OBJECT_MODIFIED_CASCADE; |
934 | + |
935 | + std::list<SPObject *> l; |
936 | + _getChildren(l); |
937 | + |
938 | + for (SPObjectIterator it = l.begin(); it != l.end(); it++) { |
939 | + SPObject *child = *it; |
940 | + |
941 | + sp_object_ref(child, NULL); |
942 | + |
943 | + if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { |
944 | + child->emitModified(flags); |
945 | + } |
946 | + |
947 | + sp_object_unref(child, NULL); |
948 | + } |
949 | +} |
950 | + |
951 | +void SPPattern::_onRefChanged(SPObject *old_ref, SPObject *ref) |
952 | +{ |
953 | + if (old_ref) { |
954 | + _modified_connection.disconnect(); |
955 | + } |
956 | + |
957 | + if (SP_IS_PATTERN(ref)) { |
958 | + _modified_connection = ref->connectModified(sigc::mem_fun(this, &SPPattern::_onRefModified)); |
959 | + } |
960 | + |
961 | + _onRefModified(ref, 0); |
962 | +} |
963 | + |
964 | +void SPPattern::_onRefModified(SPObject * /*ref*/, guint /*flags*/) |
965 | +{ |
966 | + requestModified(SP_OBJECT_MODIFIED_FLAG); |
967 | // Conditional to avoid causing infinite loop if there's a cycle in the href chain. |
968 | } |
969 | |
970 | - |
971 | -/** |
972 | -Count how many times pat is used by the styles of o and its descendants |
973 | -*/ |
974 | -static guint |
975 | -count_pattern_hrefs(SPObject *o, SPPattern *pat) |
976 | +guint SPPattern::_countHrefs(SPObject *o) const |
977 | { |
978 | if (!o) |
979 | return 1; |
980 | @@ -322,84 +310,79 @@ |
981 | guint i = 0; |
982 | |
983 | SPStyle *style = o->style; |
984 | - if (style |
985 | - && style->fill.isPaintserver() |
986 | - && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style)) |
987 | - && SP_PATTERN(SP_STYLE_FILL_SERVER(style)) == pat) |
988 | - { |
989 | - i ++; |
990 | + if (style && style->fill.isPaintserver() && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style)) && |
991 | + SP_PATTERN(SP_STYLE_FILL_SERVER(style)) == this) { |
992 | + i++; |
993 | } |
994 | - if (style |
995 | - && style->stroke.isPaintserver() |
996 | - && SP_IS_PATTERN(SP_STYLE_STROKE_SERVER(style)) |
997 | - && SP_PATTERN(SP_STYLE_STROKE_SERVER(style)) == pat) |
998 | - { |
999 | - i ++; |
1000 | + if (style && style->stroke.isPaintserver() && SP_IS_PATTERN(SP_STYLE_STROKE_SERVER(style)) && |
1001 | + SP_PATTERN(SP_STYLE_STROKE_SERVER(style)) == this) { |
1002 | + i++; |
1003 | } |
1004 | |
1005 | - for ( SPObject *child = o->firstChild(); child != NULL; child = child->next ) { |
1006 | - i += count_pattern_hrefs(child, pat); |
1007 | + for (SPObject *child = o->firstChild(); child != NULL; child = child->next) { |
1008 | + i += _countHrefs(child); |
1009 | } |
1010 | |
1011 | return i; |
1012 | } |
1013 | |
1014 | -SPPattern *pattern_chain(SPPattern *pattern) |
1015 | +SPPattern *SPPattern::_chain() const |
1016 | { |
1017 | - SPDocument *document = pattern->document; |
1018 | - Inkscape::XML::Document *xml_doc = document->getReprDoc(); |
1019 | + Inkscape::XML::Document *xml_doc = document->getReprDoc(); |
1020 | Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); |
1021 | |
1022 | Inkscape::XML::Node *repr = xml_doc->createElement("svg:pattern"); |
1023 | repr->setAttribute("inkscape:collect", "always"); |
1024 | - gchar *parent_ref = g_strconcat("#", pattern->getRepr()->attribute("id"), NULL); |
1025 | - repr->setAttribute("xlink:href", parent_ref); |
1026 | - g_free (parent_ref); |
1027 | + Glib::ustring parent_ref = Glib::ustring::compose("#%1", getRepr()->attribute("id")); |
1028 | + repr->setAttribute("xlink:href", parent_ref); |
1029 | |
1030 | defsrepr->addChild(repr, NULL); |
1031 | const gchar *child_id = repr->attribute("id"); |
1032 | SPObject *child = document->getObjectById(child_id); |
1033 | - g_assert (SP_IS_PATTERN (child)); |
1034 | + g_assert(SP_IS_PATTERN(child)); |
1035 | |
1036 | - return SP_PATTERN (child); |
1037 | + return SP_PATTERN(child); |
1038 | } |
1039 | |
1040 | -SPPattern * |
1041 | -sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const gchar *property) |
1042 | +SPPattern *SPPattern::clone_if_necessary(SPItem *item, const gchar *property) |
1043 | { |
1044 | - if (!pattern->href || pattern->hrefcount > count_pattern_hrefs(item, pattern)) { |
1045 | - pattern = pattern_chain (pattern); |
1046 | - gchar *href = g_strconcat("url(#", pattern->getRepr()->attribute("id"), ")", NULL); |
1047 | + SPPattern *pattern = this; |
1048 | + if (pattern->href.empty() || pattern->hrefcount > _countHrefs(item)) { |
1049 | + pattern = _chain(); |
1050 | + Glib::ustring href = Glib::ustring::compose("url(#%1)", pattern->getRepr()->attribute("id")); |
1051 | |
1052 | - SPCSSAttr *css = sp_repr_css_attr_new (); |
1053 | - sp_repr_css_set_property (css, property, href); |
1054 | + SPCSSAttr *css = sp_repr_css_attr_new(); |
1055 | + sp_repr_css_set_property(css, property, href.c_str()); |
1056 | sp_repr_css_change_recursive(item->getRepr(), css, "style"); |
1057 | } |
1058 | return pattern; |
1059 | } |
1060 | |
1061 | -void |
1062 | -sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool set) |
1063 | +void SPPattern::transform_multiply(Geom::Affine postmul, bool set) |
1064 | { |
1065 | // this formula is for a different interpretation of pattern transforms as described in (*) in sp-pattern.cpp |
1066 | // for it to work, we also need sp_object_read_attr( item, "transform"); |
1067 | - //pattern->patternTransform = premul * item->transform * pattern->patternTransform * item->transform.inverse() * postmul; |
1068 | + // pattern->patternTransform = premul * item->transform * pattern->patternTransform * item->transform.inverse() * |
1069 | + // postmul; |
1070 | |
1071 | // otherwise the formula is much simpler |
1072 | if (set) { |
1073 | - pattern->patternTransform = postmul; |
1074 | - } else { |
1075 | - pattern->patternTransform = pattern_patternTransform(pattern) * postmul; |
1076 | - } |
1077 | - pattern->patternTransform_set = TRUE; |
1078 | + _pattern_transform = postmul; |
1079 | + } |
1080 | + else { |
1081 | + _pattern_transform = getTransform() * postmul; |
1082 | + } |
1083 | + _pattern_transform_set = true; |
1084 | |
1085 | - gchar *c=sp_svg_transform_write(pattern->patternTransform); |
1086 | - pattern->getRepr()->setAttribute("patternTransform", c); |
1087 | - g_free(c); |
1088 | + Glib::ustring c = sp_svg_transform_write(_pattern_transform); |
1089 | + getRepr()->setAttribute("patternTransform", c); |
1090 | } |
1091 | |
1092 | -const gchar *pattern_tile(const std::vector<Inkscape::XML::Node*> &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move) |
1093 | +const gchar *SPPattern::produce(const std::vector<Inkscape::XML::Node *> &reprs, Geom::Rect bounds, |
1094 | + SPDocument *document, Geom::Affine transform, Geom::Affine move) |
1095 | { |
1096 | + typedef std::vector<Inkscape::XML::Node *>::const_iterator NodePtrIterator; |
1097 | + |
1098 | Inkscape::XML::Document *xml_doc = document->getReprDoc(); |
1099 | Inkscape::XML::Node *defsrepr = document->getDefs()->getRepr(); |
1100 | |
1101 | @@ -408,20 +391,19 @@ |
1102 | sp_repr_set_svg_double(repr, "width", bounds.dimensions()[Geom::X]); |
1103 | sp_repr_set_svg_double(repr, "height", bounds.dimensions()[Geom::Y]); |
1104 | |
1105 | - gchar *t=sp_svg_transform_write(transform); |
1106 | + Glib::ustring t = sp_svg_transform_write(transform); |
1107 | repr->setAttribute("patternTransform", t); |
1108 | - g_free(t); |
1109 | |
1110 | defsrepr->appendChild(repr); |
1111 | const gchar *pat_id = repr->attribute("id"); |
1112 | SPObject *pat_object = document->getObjectById(pat_id); |
1113 | |
1114 | - for (std::vector<Inkscape::XML::Node*>::const_iterator i=reprs.begin();i!=reprs.end();i++){ |
1115 | + for (NodePtrIterator i = reprs.begin(); i != reprs.end(); i++) { |
1116 | Inkscape::XML::Node *node = *i; |
1117 | SPItem *copy = SP_ITEM(pat_object->appendChildRepr(node)); |
1118 | |
1119 | Geom::Affine dup_transform; |
1120 | - if (!sp_svg_transform_read (node->attribute("transform"), &dup_transform)) |
1121 | + if (!sp_svg_transform_read(node->attribute("transform"), &dup_transform)) |
1122 | dup_transform = Geom::identity(); |
1123 | dup_transform *= move; |
1124 | |
1125 | @@ -432,14 +414,15 @@ |
1126 | return pat_id; |
1127 | } |
1128 | |
1129 | -SPPattern *pattern_getroot(SPPattern *pat) |
1130 | +SPPattern *SPPattern::rootPattern() |
1131 | { |
1132 | - for (SPPattern *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1133 | - if ( pat_i->firstChild() ) { // find the first one with children |
1134 | + for (SPPattern *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1135 | + if (pat_i->firstChild()) { // find the first one with children |
1136 | return pat_i; |
1137 | } |
1138 | } |
1139 | - return pat; // document is broken, we can't get to root; but at least we can return pat which is supposedly a valid pattern |
1140 | + return this; // document is broken, we can't get to root; but at least we can return pat which is supposedly a valid |
1141 | + // pattern |
1142 | } |
1143 | |
1144 | |
1145 | @@ -447,73 +430,73 @@ |
1146 | // Access functions that look up fields up the chain of referenced patterns and return the first one which is set |
1147 | // FIXME: all of them must use chase_hrefs the same as in SPGradient, to avoid lockup on circular refs |
1148 | |
1149 | -guint pattern_patternUnits (SPPattern const *pat) |
1150 | -{ |
1151 | - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1152 | - if (pat_i->patternUnits_set) |
1153 | - return pat_i->patternUnits; |
1154 | - } |
1155 | - return pat->patternUnits; |
1156 | -} |
1157 | - |
1158 | -guint pattern_patternContentUnits (SPPattern const *pat) |
1159 | -{ |
1160 | - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1161 | - if (pat_i->patternContentUnits_set) |
1162 | - return pat_i->patternContentUnits; |
1163 | - } |
1164 | - return pat->patternContentUnits; |
1165 | -} |
1166 | - |
1167 | -Geom::Affine const &pattern_patternTransform(SPPattern const *pat) |
1168 | -{ |
1169 | - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1170 | - if (pat_i->patternTransform_set) |
1171 | - return pat_i->patternTransform; |
1172 | - } |
1173 | - return pat->patternTransform; |
1174 | -} |
1175 | - |
1176 | -gdouble pattern_x (SPPattern const *pat) |
1177 | -{ |
1178 | - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1179 | - if (pat_i->x._set) |
1180 | - return pat_i->x.computed; |
1181 | - } |
1182 | - return 0; |
1183 | -} |
1184 | - |
1185 | -gdouble pattern_y (SPPattern const *pat) |
1186 | -{ |
1187 | - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1188 | - if (pat_i->y._set) |
1189 | - return pat_i->y.computed; |
1190 | - } |
1191 | - return 0; |
1192 | -} |
1193 | - |
1194 | -gdouble pattern_width (SPPattern const* pat) |
1195 | -{ |
1196 | - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1197 | - if (pat_i->width._set) |
1198 | - return pat_i->width.computed; |
1199 | - } |
1200 | - return 0; |
1201 | -} |
1202 | - |
1203 | -gdouble pattern_height (SPPattern const *pat) |
1204 | -{ |
1205 | - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1206 | - if (pat_i->height._set) |
1207 | - return pat_i->height.computed; |
1208 | - } |
1209 | - return 0; |
1210 | -} |
1211 | - |
1212 | -Geom::OptRect pattern_viewBox (SPPattern const *pat) |
1213 | +SPPattern::PatternUnits SPPattern::patternUnits() const |
1214 | +{ |
1215 | + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1216 | + if (pat_i->_pattern_units_set) |
1217 | + return pat_i->_pattern_units; |
1218 | + } |
1219 | + return _pattern_units; |
1220 | +} |
1221 | + |
1222 | +SPPattern::PatternUnits SPPattern::patternContentUnits() const |
1223 | +{ |
1224 | + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1225 | + if (pat_i->_pattern_content_units_set) |
1226 | + return pat_i->_pattern_content_units; |
1227 | + } |
1228 | + return _pattern_content_units; |
1229 | +} |
1230 | + |
1231 | +Geom::Affine const &SPPattern::getTransform() const |
1232 | +{ |
1233 | + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1234 | + if (pat_i->_pattern_transform_set) |
1235 | + return pat_i->_pattern_transform; |
1236 | + } |
1237 | + return _pattern_transform; |
1238 | +} |
1239 | + |
1240 | +gdouble SPPattern::x() const |
1241 | +{ |
1242 | + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1243 | + if (pat_i->_x._set) |
1244 | + return pat_i->_x.computed; |
1245 | + } |
1246 | + return 0; |
1247 | +} |
1248 | + |
1249 | +gdouble SPPattern::y() const |
1250 | +{ |
1251 | + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1252 | + if (pat_i->_y._set) |
1253 | + return pat_i->_y.computed; |
1254 | + } |
1255 | + return 0; |
1256 | +} |
1257 | + |
1258 | +gdouble SPPattern::width() const |
1259 | +{ |
1260 | + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1261 | + if (pat_i->_width._set) |
1262 | + return pat_i->_width.computed; |
1263 | + } |
1264 | + return 0; |
1265 | +} |
1266 | + |
1267 | +gdouble SPPattern::height() const |
1268 | +{ |
1269 | + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1270 | + if (pat_i->_height._set) |
1271 | + return pat_i->_height.computed; |
1272 | + } |
1273 | + return 0; |
1274 | +} |
1275 | + |
1276 | +Geom::OptRect SPPattern::viewbox() const |
1277 | { |
1278 | Geom::OptRect viewbox; |
1279 | - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1280 | + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1281 | if (pat_i->viewBox_set) { |
1282 | viewbox = pat_i->viewBox; |
1283 | break; |
1284 | @@ -522,10 +505,10 @@ |
1285 | return viewbox; |
1286 | } |
1287 | |
1288 | -static bool pattern_hasItemChildren (SPPattern const *pat) |
1289 | +bool SPPattern::_hasItemChildren() const |
1290 | { |
1291 | bool hasChildren = false; |
1292 | - for (SPObject const *child = pat->firstChild() ; child && !hasChildren ; child = child->getNext() ) { |
1293 | + for (SPObject const *child = firstChild(); child && !hasChildren; child = child->getNext()) { |
1294 | if (SP_IS_ITEM(child)) { |
1295 | hasChildren = true; |
1296 | } |
1297 | @@ -535,15 +518,16 @@ |
1298 | |
1299 | bool SPPattern::isValid() const |
1300 | { |
1301 | - double tile_width = pattern_width(this); |
1302 | - double tile_height = pattern_height(this); |
1303 | + double tile_width = width(); |
1304 | + double tile_height = height(); |
1305 | |
1306 | - if (tile_width <= 0 || tile_height <= 0) |
1307 | - return false; |
1308 | - return true; |
1309 | + if (tile_width <= 0 || tile_height <= 0) |
1310 | + return false; |
1311 | + return true; |
1312 | } |
1313 | |
1314 | -cairo_pattern_t* SPPattern::pattern_new(cairo_t *base_ct, Geom::OptRect const &bbox, double opacity) { |
1315 | +cairo_pattern_t *SPPattern::pattern_new(cairo_t *base_ct, Geom::OptRect const &bbox, double opacity) |
1316 | +{ |
1317 | |
1318 | bool needs_opacity = (1.0 - opacity) >= 1e-3; |
1319 | bool visible = opacity >= 1e-3; |
1320 | @@ -557,28 +541,28 @@ |
1321 | |
1322 | for (SPPattern *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { |
1323 | // find the first one with item children |
1324 | - if (pat_i && SP_IS_OBJECT(pat_i) && pattern_hasItemChildren(pat_i)) { |
1325 | + if (pat_i && SP_IS_OBJECT(pat_i) && pat_i->_hasItemChildren()) { |
1326 | shown = pat_i; |
1327 | break; // do not go further up the chain if children are found |
1328 | } |
1329 | } |
1330 | |
1331 | if (!shown) { |
1332 | - return cairo_pattern_create_rgba(0,0,0,0); |
1333 | + return cairo_pattern_create_rgba(0, 0, 0, 0); |
1334 | } |
1335 | |
1336 | /* Create drawing for rendering */ |
1337 | Inkscape::Drawing drawing; |
1338 | - unsigned int dkey = SPItem::display_key_new (1); |
1339 | + unsigned int dkey = SPItem::display_key_new(1); |
1340 | Inkscape::DrawingGroup *root = new Inkscape::DrawingGroup(drawing); |
1341 | drawing.setRoot(root); |
1342 | |
1343 | - for (SPObject *child = shown->firstChild(); child != NULL; child = child->getNext() ) { |
1344 | - if (SP_IS_ITEM (child)) { |
1345 | + for (SPObject *child = shown->firstChild(); child != NULL; child = child->getNext()) { |
1346 | + if (SP_IS_ITEM(child)) { |
1347 | // for each item in pattern, show it on our drawing, add to the group, |
1348 | // and connect to the release signal in case the item gets deleted |
1349 | Inkscape::DrawingItem *cai; |
1350 | - cai = SP_ITEM(child)->invoke_show (drawing, dkey, SP_ITEM_SHOW_DISPLAY); |
1351 | + cai = SP_ITEM(child)->invoke_show(drawing, dkey, SP_ITEM_SHOW_DISPLAY); |
1352 | root->appendChild(cai); |
1353 | } |
1354 | } |
1355 | @@ -591,40 +575,41 @@ |
1356 | // * "x", "y", and "patternTransform" transform tile to user space after tile is generated. |
1357 | |
1358 | // These functions recursively search up the tree to find the values. |
1359 | - double tile_x = pattern_x(this); |
1360 | - double tile_y = pattern_y(this); |
1361 | - double tile_width = pattern_width(this); |
1362 | - double tile_height = pattern_height(this); |
1363 | - if ( bbox && (pattern_patternUnits(this) == SP_PATTERN_UNITS_OBJECTBOUNDINGBOX) ) { |
1364 | - tile_x *= bbox->width(); |
1365 | - tile_y *= bbox->height(); |
1366 | - tile_width *= bbox->width(); |
1367 | + double tile_x = x(); |
1368 | + double tile_y = y(); |
1369 | + double tile_width = width(); |
1370 | + double tile_height = height(); |
1371 | + if (bbox && (patternUnits() == UNITS_OBJECTBOUNDINGBOX)) { |
1372 | + tile_x *= bbox->width(); |
1373 | + tile_y *= bbox->height(); |
1374 | + tile_width *= bbox->width(); |
1375 | tile_height *= bbox->height(); |
1376 | } |
1377 | |
1378 | // Pattern size in pattern space |
1379 | Geom::Rect pattern_tile = Geom::Rect::from_xywh(0, 0, tile_width, tile_height); |
1380 | - |
1381 | + |
1382 | // Content to tile (pattern space) |
1383 | Geom::Affine content2ps; |
1384 | - Geom::OptRect effective_view_box = pattern_viewBox(this); |
1385 | + Geom::OptRect effective_view_box = viewbox(); |
1386 | if (effective_view_box) { |
1387 | - // viewBox to pattern server (using SPViewBox) |
1388 | + // viewBox to pattern server (using SPViewBox) |
1389 | viewBox = *effective_view_box; |
1390 | c2p.setIdentity(); |
1391 | - apply_viewbox( pattern_tile ); |
1392 | + apply_viewbox(pattern_tile); |
1393 | content2ps = c2p; |
1394 | - } else { |
1395 | + } |
1396 | + else { |
1397 | |
1398 | // Content to bbox |
1399 | - if (bbox && (pattern_patternContentUnits(this) == SP_PATTERN_UNITS_OBJECTBOUNDINGBOX) ) { |
1400 | - content2ps = Geom::Affine(bbox->width(), 0.0, 0.0, bbox->height(), 0,0); |
1401 | + if (bbox && (patternContentUnits() == UNITS_OBJECTBOUNDINGBOX)) { |
1402 | + content2ps = Geom::Affine(bbox->width(), 0.0, 0.0, bbox->height(), 0, 0); |
1403 | } |
1404 | } |
1405 | |
1406 | |
1407 | // Tile (pattern space) to user. |
1408 | - Geom::Affine ps2user = Geom::Translate(tile_x,tile_y) * pattern_patternTransform(this); |
1409 | + Geom::Affine ps2user = Geom::Translate(tile_x, tile_y) * getTransform(); |
1410 | |
1411 | |
1412 | // Transform of object with pattern (includes screen scaling) |
1413 | @@ -644,7 +629,7 @@ |
1414 | // to find the optimum tile size for rendering |
1415 | // c is number of pixels in buffer x and y. |
1416 | // Scale factor of 1.1 is too small... see bug #1251039 |
1417 | - Geom::Point c(pattern_tile.dimensions()*ps2user.descrim()*full.descrim()*2.0); |
1418 | + Geom::Point c(pattern_tile.dimensions() * ps2user.descrim() * full.descrim() * 2.0); |
1419 | |
1420 | // Create drawing surface with size of pattern tile (in pattern space) but with number of pixels |
1421 | // based on required resolution (c). |
1422 | @@ -660,16 +645,16 @@ |
1423 | } |
1424 | |
1425 | // TODO: make sure there are no leaks. |
1426 | - Inkscape::UpdateContext ctx; // UpdateContext is structure with only ctm! |
1427 | + Inkscape::UpdateContext ctx; // UpdateContext is structure with only ctm! |
1428 | ctx.ctm = content2ps * pattern_surface.drawingTransform(); |
1429 | - dc.transform( pattern_surface.drawingTransform().inverse() ); |
1430 | + dc.transform(pattern_surface.drawingTransform().inverse()); |
1431 | drawing.update(Geom::IntRect::infinite(), ctx); |
1432 | |
1433 | // Render drawing to pattern_surface via drawing context, this calls root->render |
1434 | // which is really DrawingItem->render(). |
1435 | drawing.render(dc, one_tile); |
1436 | - for (SPObject *child = shown->firstChild() ; child != NULL; child = child->getNext() ) { |
1437 | - if (SP_IS_ITEM (child)) { |
1438 | + for (SPObject *child = shown->firstChild(); child != NULL; child = child->getNext()) { |
1439 | + if (SP_IS_ITEM(child)) { |
1440 | SP_ITEM(child)->invoke_hide(dkey); |
1441 | } |
1442 | } |
1443 | @@ -685,12 +670,12 @@ |
1444 | |
1445 | if (needs_opacity) { |
1446 | dc.popGroupToSource(); // pop raw pattern |
1447 | - dc.paint(opacity); // apply opacity |
1448 | + dc.paint(opacity); // apply opacity |
1449 | } |
1450 | |
1451 | cairo_pattern_t *cp = cairo_pattern_create_for_surface(pattern_surface.raw()); |
1452 | // Apply transformation to user space. Also compensate for oversampling. |
1453 | - ink_cairo_pattern_set_matrix(cp, ps2user.inverse() * pattern_surface.drawingTransform() ); |
1454 | + ink_cairo_pattern_set_matrix(cp, ps2user.inverse() * pattern_surface.drawingTransform()); |
1455 | |
1456 | cairo_pattern_set_extend(cp, CAIRO_EXTEND_REPEAT); |
1457 | |
1458 | |
1459 | === modified file 'src/sp-pattern.h' |
1460 | --- src/sp-pattern.h 2015-02-19 03:25:21 +0000 |
1461 | +++ src/sp-pattern.h 2015-05-03 11:19:29 +0000 |
1462 | @@ -1,9 +1,6 @@ |
1463 | -#ifndef SEEN_SP_PATTERN_H |
1464 | -#define SEEN_SP_PATTERN_H |
1465 | - |
1466 | -/* |
1467 | +/** @file |
1468 | * SVG <pattern> implementation |
1469 | - * |
1470 | + *//* |
1471 | * Author: |
1472 | * Lauris Kaplinski <lauris@kaplinski.com> |
1473 | * Abhishek Sharma |
1474 | @@ -13,95 +10,131 @@ |
1475 | * Released under GNU GPL, read the file 'COPYING' for more information |
1476 | */ |
1477 | |
1478 | -#define SP_PATTERN(obj) (dynamic_cast<SPPattern*>((SPObject*)obj)) |
1479 | -#define SP_IS_PATTERN(obj) (dynamic_cast<const SPPattern*>((SPObject*)obj) != NULL) |
1480 | +#ifndef SEEN_SP_PATTERN_H |
1481 | +#define SEEN_SP_PATTERN_H |
1482 | |
1483 | -class SPPatternReference; |
1484 | -class SPItem; |
1485 | -typedef struct _GSList GSList; |
1486 | +#include <list> |
1487 | +#include <stddef.h> |
1488 | +#include <glibmm/ustring.h> |
1489 | +#include <sigc++/connection.h> |
1490 | |
1491 | #include "svg/svg-length.h" |
1492 | #include "sp-paint-server.h" |
1493 | #include "uri-references.h" |
1494 | #include "viewbox.h" |
1495 | |
1496 | -#include <sigc++/connection.h> |
1497 | - |
1498 | +class SPPatternReference; |
1499 | +class SPItem; |
1500 | + |
1501 | +namespace Inkscape { |
1502 | +namespace XML { |
1503 | + |
1504 | +class Node; |
1505 | +} |
1506 | +} |
1507 | + |
1508 | +#define SP_PATTERN(obj) (dynamic_cast<SPPattern *>((SPObject *)obj)) |
1509 | +#define SP_IS_PATTERN(obj) (dynamic_cast<const SPPattern *>((SPObject *)obj) != NULL) |
1510 | |
1511 | class SPPattern : public SPPaintServer, public SPViewBox { |
1512 | public: |
1513 | - SPPattern(); |
1514 | - virtual ~SPPattern(); |
1515 | + enum PatternUnits { UNITS_USERSPACEONUSE, UNITS_OBJECTBOUNDINGBOX }; |
1516 | + |
1517 | + SPPattern(); |
1518 | + virtual ~SPPattern(); |
1519 | |
1520 | /* Reference (href) */ |
1521 | - char *href; |
1522 | + Glib::ustring href; |
1523 | SPPatternReference *ref; |
1524 | |
1525 | + gdouble x() const; |
1526 | + gdouble y() const; |
1527 | + gdouble width() const; |
1528 | + gdouble height() const; |
1529 | + Geom::OptRect viewbox() const; |
1530 | + SPPattern::PatternUnits patternUnits() const; |
1531 | + SPPattern::PatternUnits patternContentUnits() const; |
1532 | + Geom::Affine const &getTransform() const; |
1533 | + SPPattern *rootPattern(); // TODO: const |
1534 | + |
1535 | + SPPattern *clone_if_necessary(SPItem *item, const gchar *property); |
1536 | + void transform_multiply(Geom::Affine postmul, bool set); |
1537 | + |
1538 | + /** |
1539 | + * @brief create a new pattern in XML tree |
1540 | + * @return created pattern id |
1541 | + */ |
1542 | + static const gchar *produce(const std::vector<Inkscape::XML::Node *> &reprs, Geom::Rect bounds, |
1543 | + SPDocument *document, Geom::Affine transform, Geom::Affine move); |
1544 | + |
1545 | + bool isValid() const; |
1546 | + |
1547 | + virtual cairo_pattern_t *pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity); |
1548 | + |
1549 | +protected: |
1550 | + virtual void build(SPDocument *doc, Inkscape::XML::Node *repr); |
1551 | + virtual void release(); |
1552 | + virtual void set(unsigned int key, const gchar *value); |
1553 | + virtual void update(SPCtx *ctx, unsigned int flags); |
1554 | + virtual void modified(unsigned int flags); |
1555 | + |
1556 | +private: |
1557 | + bool _hasItemChildren() const; |
1558 | + void _getChildren(std::list<SPObject *> &l); |
1559 | + SPPattern *_chain() const; |
1560 | + |
1561 | + /** |
1562 | + Count how many times pattern is used by the styles of o and its descendants |
1563 | + */ |
1564 | + guint _countHrefs(SPObject *o) const; |
1565 | + |
1566 | + /** |
1567 | + Gets called when the pattern is reattached to another <pattern> |
1568 | + */ |
1569 | + void _onRefChanged(SPObject *old_ref, SPObject *ref); |
1570 | + |
1571 | + /** |
1572 | + Gets called when the referenced <pattern> is changed |
1573 | + */ |
1574 | + void _onRefModified(SPObject *ref, guint flags); |
1575 | + |
1576 | /* patternUnits and patternContentUnits attribute */ |
1577 | - unsigned int patternUnits : 1; |
1578 | - unsigned int patternUnits_set : 1; |
1579 | - unsigned int patternContentUnits : 1; |
1580 | - unsigned int patternContentUnits_set : 1; |
1581 | + PatternUnits _pattern_units : 1; |
1582 | + bool _pattern_units_set : 1; |
1583 | + PatternUnits _pattern_content_units : 1; |
1584 | + bool _pattern_content_units_set : 1; |
1585 | /* patternTransform attribute */ |
1586 | - Geom::Affine patternTransform; |
1587 | - unsigned int patternTransform_set : 1; |
1588 | + Geom::Affine _pattern_transform; |
1589 | + bool _pattern_transform_set : 1; |
1590 | /* Tile rectangle */ |
1591 | - SVGLength x; |
1592 | - SVGLength y; |
1593 | - SVGLength width; |
1594 | - SVGLength height; |
1595 | - |
1596 | - sigc::connection modified_connection; |
1597 | - |
1598 | - bool isValid() const; |
1599 | - |
1600 | - virtual cairo_pattern_t* pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity); |
1601 | - |
1602 | -protected: |
1603 | - virtual void build(SPDocument* doc, Inkscape::XML::Node* repr); |
1604 | - virtual void release(); |
1605 | - virtual void set(unsigned int key, const gchar* value); |
1606 | - virtual void update(SPCtx* ctx, unsigned int flags); |
1607 | - virtual void modified(unsigned int flags); |
1608 | + SVGLength _x; |
1609 | + SVGLength _y; |
1610 | + SVGLength _width; |
1611 | + SVGLength _height; |
1612 | + |
1613 | + sigc::connection _modified_connection; |
1614 | }; |
1615 | |
1616 | |
1617 | class SPPatternReference : public Inkscape::URIReference { |
1618 | public: |
1619 | - SPPatternReference (SPObject *obj) : URIReference(obj) {} |
1620 | - SPPattern *getObject() const { |
1621 | + SPPatternReference(SPObject *obj) |
1622 | + : URIReference(obj) |
1623 | + { |
1624 | + } |
1625 | + |
1626 | + SPPattern *getObject() const |
1627 | + { |
1628 | return reinterpret_cast<SPPattern *>(URIReference::getObject()); |
1629 | } |
1630 | |
1631 | protected: |
1632 | - virtual bool _acceptObject(SPObject *obj) const { |
1633 | - return SP_IS_PATTERN (obj); |
1634 | + virtual bool _acceptObject(SPObject *obj) const |
1635 | + { |
1636 | + return SP_IS_PATTERN(obj); |
1637 | } |
1638 | }; |
1639 | |
1640 | -enum { |
1641 | - SP_PATTERN_UNITS_USERSPACEONUSE, |
1642 | - SP_PATTERN_UNITS_OBJECTBOUNDINGBOX |
1643 | -}; |
1644 | - |
1645 | -unsigned int pattern_users (SPPattern *pattern); |
1646 | -SPPattern *pattern_chain (SPPattern *pattern); |
1647 | -SPPattern *sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const char *property); |
1648 | -void sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool set); |
1649 | - |
1650 | -const char *pattern_tile (const std::vector<Inkscape::XML::Node*> &reprs, Geom::Rect bounds, SPDocument *document, Geom::Affine transform, Geom::Affine move); |
1651 | - |
1652 | -SPPattern *pattern_getroot (SPPattern *pat); |
1653 | - |
1654 | -unsigned int pattern_patternUnits (SPPattern const *pat); |
1655 | -unsigned int pattern_patternContentUnits (SPPattern const *pat); |
1656 | -Geom::Affine const &pattern_patternTransform(SPPattern const *pat); |
1657 | -double pattern_x (SPPattern const *pat); |
1658 | -double pattern_y (SPPattern const *pat); |
1659 | -double pattern_width (SPPattern const *pat); |
1660 | -double pattern_height (SPPattern const *pat); |
1661 | -Geom::OptRect pattern_viewBox (SPPattern const *pat); |
1662 | - |
1663 | #endif // SEEN_SP_PATTERN_H |
1664 | |
1665 | /* |
1666 | |
1667 | === modified file 'src/ui/CMakeLists.txt' |
1668 | --- src/ui/CMakeLists.txt 2015-04-08 01:54:48 +0000 |
1669 | +++ src/ui/CMakeLists.txt 2015-05-03 11:19:29 +0000 |
1670 | @@ -6,6 +6,7 @@ |
1671 | interface.cpp |
1672 | object-edit.cpp |
1673 | previewholder.cpp |
1674 | + selected-color.cpp |
1675 | shape-editor.cpp |
1676 | tool-factory.cpp |
1677 | tools-switch.cpp |
1678 | @@ -115,8 +116,14 @@ |
1679 | widget/anchor-selector.cpp |
1680 | widget/button.cpp |
1681 | widget/clipmaskicon.cpp |
1682 | + widget/color-entry.cpp |
1683 | + widget/color-icc-selector.cpp |
1684 | + widget/color-notebook.cpp |
1685 | widget/color-picker.cpp |
1686 | widget/color-preview.cpp |
1687 | + widget/color-scales.cpp |
1688 | + widget/color-slider.cpp |
1689 | + widget/color-wheel-selector.cpp |
1690 | widget/dock-item.cpp |
1691 | widget/dock.cpp |
1692 | widget/entity-entry.cpp |
1693 | @@ -174,6 +181,7 @@ |
1694 | previewable.h |
1695 | previewfillable.h |
1696 | previewholder.h |
1697 | + selected-color.h |
1698 | shape-editor.h |
1699 | tool-factory.h |
1700 | tools-switch.h |
1701 | @@ -287,8 +295,14 @@ |
1702 | widget/anchor-selector.h |
1703 | widget/attr-widget.h |
1704 | widget/button.h |
1705 | + widget/color-entry.h |
1706 | + widget/color-icc-selector.h |
1707 | + widget/color-notebook.h |
1708 | widget/color-picker.h |
1709 | widget/color-preview.h |
1710 | + widget/color-scales.h |
1711 | + widget/color-slider.h |
1712 | + widget/color-wheel-selector.h |
1713 | widget/combo-enums.h |
1714 | widget/dock-item.h |
1715 | widget/dock.h |
1716 | |
1717 | === modified file 'src/ui/Makefile_insert' |
1718 | --- src/ui/Makefile_insert 2015-02-25 01:04:28 +0000 |
1719 | +++ src/ui/Makefile_insert 2015-05-03 11:19:29 +0000 |
1720 | @@ -19,6 +19,8 @@ |
1721 | ui/previewfillable.h \ |
1722 | ui/previewholder.cpp \ |
1723 | ui/previewholder.h \ |
1724 | + ui/selected-color.h \ |
1725 | + ui/selected-color.cpp \ |
1726 | ui/shape-editor.cpp \ |
1727 | ui/shape-editor.h \ |
1728 | ui/tool-factory.cpp \ |
1729 | |
1730 | === modified file 'src/ui/dialog/objects.cpp' |
1731 | --- src/ui/dialog/objects.cpp 2015-02-27 02:10:36 +0000 |
1732 | +++ src/ui/dialog/objects.cpp 2015-05-03 11:19:29 +0000 |
1733 | @@ -45,6 +45,7 @@ |
1734 | #include "style.h" |
1735 | #include "ui/tools-switch.h" |
1736 | #include "ui/icon-names.h" |
1737 | +#include "ui/selected-color.h" |
1738 | #include "ui/widget/imagetoggler.h" |
1739 | #include "ui/widget/layertypeicon.h" |
1740 | #include "ui/widget/insertordericon.h" |
1741 | @@ -53,7 +54,7 @@ |
1742 | #include "ui/tools/node-tool.h" |
1743 | #include "ui/tools/tool-base.h" |
1744 | #include "verbs.h" |
1745 | -#include "widgets/sp-color-notebook.h" |
1746 | +#include "ui/widget/color-notebook.h" |
1747 | #include "widgets/icon.h" |
1748 | #include "xml/node.h" |
1749 | #include "xml/node-observer.h" |
1750 | @@ -928,12 +929,12 @@ |
1751 | //If the current item is not selected, store only it in the highlight source |
1752 | _storeHighlightTarget(iter); |
1753 | } |
1754 | - if (_colorSelector) |
1755 | + if (_selectedColor) |
1756 | { |
1757 | //Set up the color selector |
1758 | SPColor color; |
1759 | color.set( row[_model->_colHighlight] ); |
1760 | - _colorSelector->base->setColorAlpha(color, SP_RGBA32_A_F(row[_model->_colHighlight])); |
1761 | + _selectedColor->setColorAlpha(color, SP_RGBA32_A_F(row[_model->_colHighlight])); |
1762 | } |
1763 | //Show the color selector dialog |
1764 | _colorSelectorDialog.show(); |
1765 | @@ -1440,17 +1441,16 @@ |
1766 | * @param csel Color selector |
1767 | * @param cp Objects panel |
1768 | */ |
1769 | -void sp_highlight_picker_color_mod(SPColorSelector *csel, GObject * cp) |
1770 | +void ObjectsPanel::_highlightPickerColorMod() |
1771 | { |
1772 | SPColor color; |
1773 | float alpha = 0; |
1774 | - csel->base->getColorAlpha(color, alpha); |
1775 | + _selectedColor->colorAlpha(color, alpha); |
1776 | + |
1777 | guint32 rgba = color.toRGBA32( alpha ); |
1778 | - |
1779 | - ObjectsPanel *ptr = reinterpret_cast<ObjectsPanel *>(cp); |
1780 | |
1781 | //Set the highlight color for all items in the _highlight_target (all selected items) |
1782 | - for (std::vector<SPItem *>::iterator iter = ptr->_highlight_target.begin(); iter != ptr->_highlight_target.end(); ++iter) |
1783 | + for (std::vector<SPItem *>::iterator iter = _highlight_target.begin(); iter != _highlight_target.end(); ++iter) |
1784 | { |
1785 | SPItem * target = *iter; |
1786 | target->setHighlightColor(rgba); |
1787 | @@ -1922,18 +1922,16 @@ |
1788 | _colorSelectorDialog.set_title (_("Select Highlight Color")); |
1789 | _colorSelectorDialog.set_border_width (4); |
1790 | _colorSelectorDialog.property_modal() = true; |
1791 | - _colorSelector = SP_COLOR_SELECTOR(sp_color_selector_new(SP_TYPE_COLOR_NOTEBOOK)); |
1792 | + _selectedColor.reset(new Inkscape::UI::SelectedColor); |
1793 | + Gtk::Widget *color_selector = Gtk::manage(new Inkscape::UI::Widget::ColorNotebook(*_selectedColor)); |
1794 | _colorSelectorDialog.get_vbox()->pack_start ( |
1795 | - *Glib::wrap(&_colorSelector->vbox), true, true, 0); |
1796 | - |
1797 | - g_signal_connect(G_OBJECT(_colorSelector), "dragged", |
1798 | - G_CALLBACK(sp_highlight_picker_color_mod), (void *)this); |
1799 | - g_signal_connect(G_OBJECT(_colorSelector), "released", |
1800 | - G_CALLBACK(sp_highlight_picker_color_mod), (void *)this); |
1801 | - g_signal_connect(G_OBJECT(_colorSelector), "changed", |
1802 | - G_CALLBACK(sp_highlight_picker_color_mod), (void *)this); |
1803 | - |
1804 | - gtk_widget_show(GTK_WIDGET(_colorSelector)); |
1805 | + *color_selector, true, true, 0); |
1806 | + |
1807 | + _selectedColor->signal_dragged.connect(sigc::mem_fun(*this, &ObjectsPanel::_highlightPickerColorMod)); |
1808 | + _selectedColor->signal_released.connect(sigc::mem_fun(*this, &ObjectsPanel::_highlightPickerColorMod)); |
1809 | + _selectedColor->signal_changed.connect(sigc::mem_fun(*this, &ObjectsPanel::_highlightPickerColorMod)); |
1810 | + |
1811 | + color_selector->show(); |
1812 | |
1813 | setDesktop( targetDesktop ); |
1814 | |
1815 | @@ -1951,7 +1949,6 @@ |
1816 | { |
1817 | //Close the highlight selection dialog |
1818 | _colorSelectorDialog.hide(); |
1819 | - _colorSelector = NULL; |
1820 | |
1821 | //Set the desktop to null, which will disconnect all object watchers |
1822 | setDesktop(NULL); |
1823 | |
1824 | === modified file 'src/ui/dialog/objects.h' |
1825 | --- src/ui/dialog/objects.h 2015-04-27 23:38:31 +0000 |
1826 | +++ src/ui/dialog/objects.h 2015-05-03 11:19:29 +0000 |
1827 | @@ -16,6 +16,7 @@ |
1828 | # include <config.h> |
1829 | #endif |
1830 | |
1831 | +#include <boost/scoped_ptr.hpp> |
1832 | #include <gtkmm/box.h> |
1833 | #include <gtkmm/treeview.h> |
1834 | #include <gtkmm/treestore.h> |
1835 | @@ -36,6 +37,9 @@ |
1836 | namespace Inkscape { |
1837 | |
1838 | namespace UI { |
1839 | + |
1840 | +class SelectedColor; |
1841 | + |
1842 | namespace Dialog { |
1843 | |
1844 | |
1845 | @@ -166,8 +170,7 @@ |
1846 | Gtk::Alignment _blur_alignment; |
1847 | |
1848 | Gtk::Dialog _colorSelectorDialog; |
1849 | - SPColorSelector *_colorSelector; |
1850 | - |
1851 | + boost::scoped_ptr<Inkscape::UI::SelectedColor> _selectedColor; |
1852 | |
1853 | //Methods: |
1854 | |
1855 | @@ -233,7 +236,7 @@ |
1856 | |
1857 | void setupDialog(const Glib::ustring &title); |
1858 | |
1859 | - friend void sp_highlight_picker_color_mod(SPColorSelector *csel, GObject *cp); |
1860 | + void _highlightPickerColorMod(); |
1861 | |
1862 | }; |
1863 | |
1864 | |
1865 | === modified file 'src/ui/dialog/tags.cpp' |
1866 | --- src/ui/dialog/tags.cpp 2015-02-27 03:21:48 +0000 |
1867 | +++ src/ui/dialog/tags.cpp 2015-05-03 11:19:29 +0000 |
1868 | @@ -51,7 +51,7 @@ |
1869 | #include "ui/tools/tool-base.h" //"event-context.h" |
1870 | #include "selection.h" |
1871 | //#include "dialogs/dialog-events.h" |
1872 | -#include "widgets/sp-color-notebook.h" |
1873 | +#include "ui/widget/color-notebook.h" |
1874 | #include "style.h" |
1875 | #include "filter-chemistry.h" |
1876 | #include "filters/blend.h" |
1877 | |
1878 | === added file 'src/ui/selected-color.cpp' |
1879 | --- src/ui/selected-color.cpp 1970-01-01 00:00:00 +0000 |
1880 | +++ src/ui/selected-color.cpp 2015-05-03 11:19:29 +0000 |
1881 | @@ -0,0 +1,161 @@ |
1882 | +/** @file |
1883 | + * Color selected in color selector widget. |
1884 | + * This file was created during the refactoring of SPColorSelector |
1885 | + *//* |
1886 | + * Authors: |
1887 | + * bulia byak <buliabyak@users.sf.net> |
1888 | + * Jon A. Cruz <jon@joncruz.org> |
1889 | + * Tomasz Boczkowski <penginsbacon@gmail.com> |
1890 | + * |
1891 | + * Copyright (C) 2014 Authors |
1892 | + * Released under GNU GPL, read the file 'COPYING' for more information |
1893 | + */ |
1894 | +#ifdef HAVE_CONFIG_H |
1895 | +# include "config.h" |
1896 | +#endif |
1897 | + |
1898 | +#include <glibmm/ustring.h> |
1899 | +#include <cmath> |
1900 | + |
1901 | +#include "svg/svg-icc-color.h" |
1902 | +#include "ui/selected-color.h" |
1903 | + |
1904 | +namespace Inkscape { |
1905 | +namespace UI { |
1906 | + |
1907 | +double const SelectedColor::_EPSILON = 1e-4; |
1908 | + |
1909 | +SelectedColor::SelectedColor() |
1910 | + : _color(0) |
1911 | + , _alpha(1.0) |
1912 | + , _held(false) |
1913 | + , _virgin(true) |
1914 | + , _updating(false) |
1915 | +{ |
1916 | + |
1917 | +} |
1918 | + |
1919 | +SelectedColor::~SelectedColor() { |
1920 | + |
1921 | +} |
1922 | + |
1923 | +void SelectedColor::setColor(SPColor const &color) |
1924 | +{ |
1925 | + setColorAlpha( color, _alpha); |
1926 | +} |
1927 | + |
1928 | +SPColor SelectedColor::color() const |
1929 | +{ |
1930 | + return _color; |
1931 | +} |
1932 | + |
1933 | +void SelectedColor::setAlpha(gfloat alpha) |
1934 | +{ |
1935 | + g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) ); |
1936 | + setColorAlpha( _color, alpha); |
1937 | +} |
1938 | + |
1939 | +gfloat SelectedColor::alpha() const |
1940 | +{ |
1941 | + return _alpha; |
1942 | +} |
1943 | + |
1944 | +void SelectedColor::setValue(guint32 value) |
1945 | +{ |
1946 | + SPColor color(value); |
1947 | + gfloat alpha = SP_RGBA32_A_F(value); |
1948 | + setColorAlpha(color, alpha); |
1949 | +} |
1950 | + |
1951 | +guint32 SelectedColor::value() const |
1952 | +{ |
1953 | + return color().toRGBA32(_alpha); |
1954 | +} |
1955 | + |
1956 | +void SelectedColor::setColorAlpha(SPColor const &color, gfloat alpha) |
1957 | +{ |
1958 | +#ifdef DUMP_CHANGE_INFO |
1959 | + g_message("SelectedColor::setColorAlpha( this=%p, %f, %f, %f, %s, %f, %s) in %s", this, color.v.c[0], color.v.c[1], color.v.c[2], (color.icc?color.icc->colorProfile.c_str():"<null>"), alpha, (emit?"YES":"no"), FOO_NAME(_csel)); |
1960 | +#endif |
1961 | + g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) ); |
1962 | + |
1963 | + if (_updating) { |
1964 | + return; |
1965 | + } |
1966 | + |
1967 | +#ifdef DUMP_CHANGE_INFO |
1968 | + g_message("---- SelectedColor::setColorAlpha virgin:%s !close:%s alpha is:%s in %s", |
1969 | + (_virgin?"YES":"no"), |
1970 | + (!color.isClose( _color, _epsilon )?"YES":"no"), |
1971 | + ((fabs((_alpha) - (alpha)) >= _epsilon )?"YES":"no"), |
1972 | + FOO_NAME(_csel) |
1973 | + ); |
1974 | +#endif |
1975 | + |
1976 | + if ( _virgin || !color.isClose( _color, _EPSILON ) || |
1977 | + (fabs((_alpha) - (alpha)) >= _EPSILON )) { |
1978 | + |
1979 | + _virgin = false; |
1980 | + |
1981 | + _color = color; |
1982 | + _alpha = alpha; |
1983 | + |
1984 | + _updating = true; |
1985 | + if (_held) { |
1986 | + signal_dragged.emit(); |
1987 | + } else { |
1988 | + signal_changed.emit(); |
1989 | + } |
1990 | + _updating = false; |
1991 | + |
1992 | +#ifdef DUMP_CHANGE_INFO |
1993 | + } else { |
1994 | + g_message("++++ SelectedColor::setColorAlpha color:%08x ==> _color:%08X isClose:%s in %s", color.toRGBA32(alpha), _color.toRGBA32(_alpha), |
1995 | + (color.isClose( _color, _epsilon )?"YES":"no"), FOO_NAME(_csel)); |
1996 | +#endif |
1997 | + } |
1998 | +} |
1999 | + |
2000 | +void SelectedColor::colorAlpha(SPColor &color, gfloat &alpha) const { |
2001 | + color = _color; |
2002 | + alpha = _alpha; |
2003 | +} |
2004 | + |
2005 | +void SelectedColor::setHeld(bool held) { |
2006 | + if (_updating) { |
2007 | + return; |
2008 | + } |
2009 | + bool grabbed = held && !_held; |
2010 | + bool released = !held && _held; |
2011 | + |
2012 | + _held = held; |
2013 | + |
2014 | + _updating = true; |
2015 | + if (grabbed) { |
2016 | + signal_grabbed.emit(); |
2017 | + } |
2018 | + |
2019 | + if (released) { |
2020 | + signal_released.emit(); |
2021 | + signal_changed.emit(); |
2022 | + } |
2023 | + _updating = false; |
2024 | +} |
2025 | + |
2026 | +void SelectedColor::preserveICC() { |
2027 | + _color.icc = _color.icc ? new SVGICCColor(*_color.icc) : 0; |
2028 | +} |
2029 | + |
2030 | +} |
2031 | +} |
2032 | + |
2033 | +/* |
2034 | + Local Variables: |
2035 | + mode:c++ |
2036 | + c-file-style:"stroustrup" |
2037 | + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
2038 | + indent-tabs-mode:nil |
2039 | + fill-column:99 |
2040 | + End: |
2041 | +*/ |
2042 | +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |
2043 | |
2044 | === added file 'src/ui/selected-color.h' |
2045 | --- src/ui/selected-color.h 1970-01-01 00:00:00 +0000 |
2046 | +++ src/ui/selected-color.h 2015-05-03 11:19:29 +0000 |
2047 | @@ -0,0 +1,96 @@ |
2048 | +/** @file |
2049 | + * Color selected in color selector widget. |
2050 | + * This file was created during the refactoring of SPColorSelector |
2051 | + *//* |
2052 | + * Authors: |
2053 | + * bulia byak <buliabyak@users.sf.net> |
2054 | + * Jon A. Cruz <jon@joncruz.org> |
2055 | + * Tomasz Boczkowski <penginsbacon@gmail.com> |
2056 | + * |
2057 | + * Copyright (C) 2014 Authors |
2058 | + * Released under GNU GPL, read the file 'COPYING' for more information |
2059 | + */ |
2060 | +#ifndef SEEN_SELECTED_COLOR |
2061 | +#define SEEN_SELECTED_COLOR |
2062 | + |
2063 | +#include <sigc++/signal.h> |
2064 | +#include "color.h" |
2065 | + |
2066 | +namespace Gtk |
2067 | +{ |
2068 | + class Widget; |
2069 | +} |
2070 | + |
2071 | +namespace Inkscape { |
2072 | +namespace UI { |
2073 | + |
2074 | +class SelectedColor { |
2075 | +public: |
2076 | + SelectedColor(); |
2077 | + virtual ~SelectedColor(); |
2078 | + |
2079 | + void setColor(SPColor const &color); |
2080 | + SPColor color() const; |
2081 | + |
2082 | + void setAlpha(gfloat alpha); |
2083 | + gfloat alpha() const; |
2084 | + |
2085 | + void setValue(guint32 value); |
2086 | + guint32 value() const; |
2087 | + |
2088 | + void setColorAlpha(SPColor const &color, gfloat alpha); |
2089 | + void colorAlpha(SPColor &color, gfloat &alpha) const; |
2090 | + |
2091 | + void setHeld(bool held); |
2092 | + |
2093 | + void preserveICC(); |
2094 | + |
2095 | + sigc::signal<void> signal_grabbed; |
2096 | + sigc::signal<void> signal_dragged; |
2097 | + sigc::signal<void> signal_released; |
2098 | + sigc::signal<void> signal_changed; |
2099 | +private: |
2100 | + // By default, disallow copy constructor and assignment operator |
2101 | + SelectedColor(SelectedColor const &obj); |
2102 | + SelectedColor& operator=(SelectedColor const &obj); |
2103 | + |
2104 | + SPColor _color; |
2105 | + /** |
2106 | + * Color alpha value guaranteed to be in [0, 1]. |
2107 | + */ |
2108 | + gfloat _alpha; |
2109 | + |
2110 | + bool _held; |
2111 | + /** |
2112 | + * This flag is true if no color is set yet |
2113 | + */ |
2114 | + bool _virgin; |
2115 | + |
2116 | + bool _updating; |
2117 | + |
2118 | + static double const _EPSILON; |
2119 | +}; |
2120 | + |
2121 | +class ColorSelectorFactory { |
2122 | +public: |
2123 | + virtual ~ColorSelectorFactory() { |
2124 | + } |
2125 | + |
2126 | + virtual Gtk::Widget* createWidget(SelectedColor &color) const = 0; |
2127 | + virtual Glib::ustring modeName() const = 0; |
2128 | +}; |
2129 | + |
2130 | +} |
2131 | +} |
2132 | + |
2133 | +#endif |
2134 | +/* |
2135 | + Local Variables: |
2136 | + mode:c++ |
2137 | + c-file-style:"stroustrup" |
2138 | + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
2139 | + indent-tabs-mode:nil |
2140 | + fill-column:99 |
2141 | + End: |
2142 | +*/ |
2143 | +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |
2144 | |
2145 | === modified file 'src/ui/widget/Makefile_insert' |
2146 | --- src/ui/widget/Makefile_insert 2014-10-08 02:22:03 +0000 |
2147 | +++ src/ui/widget/Makefile_insert 2015-05-03 11:19:29 +0000 |
2148 | @@ -6,10 +6,22 @@ |
2149 | ui/widget/attr-widget.h \ |
2150 | ui/widget/button.h \ |
2151 | ui/widget/button.cpp \ |
2152 | + ui/widget/color-entry.cpp \ |
2153 | + ui/widget/color-entry.h \ |
2154 | + ui/widget/color-icc-selector.cpp \ |
2155 | + ui/widget/color-icc-selector.h \ |
2156 | + ui/widget/color-notebook.cpp \ |
2157 | + ui/widget/color-notebook.h \ |
2158 | + ui/widget/color-wheel-selector.cpp \ |
2159 | + ui/widget/color-wheel-selector.h \ |
2160 | ui/widget/color-picker.cpp \ |
2161 | ui/widget/color-picker.h \ |
2162 | ui/widget/color-preview.cpp \ |
2163 | ui/widget/color-preview.h \ |
2164 | + ui/widget/color-slider.cpp \ |
2165 | + ui/widget/color-slider.h \ |
2166 | + ui/widget/color-scales.cpp \ |
2167 | + ui/widget/color-scales.h \ |
2168 | ui/widget/combo-enums.h \ |
2169 | ui/widget/dock.h \ |
2170 | ui/widget/dock.cpp \ |
2171 | |
2172 | === added file 'src/ui/widget/color-entry.cpp' |
2173 | --- src/ui/widget/color-entry.cpp 1970-01-01 00:00:00 +0000 |
2174 | +++ src/ui/widget/color-entry.cpp 2015-05-03 11:19:29 +0000 |
2175 | @@ -0,0 +1,104 @@ |
2176 | +/** @file |
2177 | + * Entry widget for typing color value in css form |
2178 | + *//* |
2179 | + * Authors: |
2180 | + * Tomasz Boczkowski <penginsbacon@gmail.com> |
2181 | + * |
2182 | + * Copyright (C) 2014 Authors |
2183 | + * Released under GNU GPL, read the file 'COPYING' for more information |
2184 | + */ |
2185 | +#include <glibmm.h> |
2186 | +#include <glibmm/i18n.h> |
2187 | +#include <iomanip> |
2188 | + |
2189 | +#include "color-entry.h" |
2190 | + |
2191 | +namespace Inkscape { |
2192 | +namespace UI { |
2193 | +namespace Widget { |
2194 | + |
2195 | +ColorEntry::ColorEntry(SelectedColor &color) |
2196 | + : _color(color) |
2197 | + , _updating(false) |
2198 | +{ |
2199 | + _color_changed_connection = color.signal_changed.connect(sigc::mem_fun(this, &ColorEntry::_onColorChanged)); |
2200 | + _color_dragged_connection = color.signal_dragged.connect(sigc::mem_fun(this, &ColorEntry::_onColorChanged)); |
2201 | + _onColorChanged(); |
2202 | + |
2203 | + set_max_length(8); |
2204 | + set_width_chars(8); |
2205 | + set_tooltip_text(_("Hexadecimal RGBA value of the color")); |
2206 | +} |
2207 | + |
2208 | +ColorEntry::~ColorEntry() |
2209 | +{ |
2210 | + _color_changed_connection.disconnect(); |
2211 | + _color_dragged_connection.disconnect(); |
2212 | +} |
2213 | + |
2214 | +void ColorEntry::on_changed() |
2215 | +{ |
2216 | + if (_updating) { |
2217 | + return; |
2218 | + } |
2219 | + |
2220 | + Glib::ustring text = get_text(); |
2221 | + bool changed = false; |
2222 | + |
2223 | + // Coerce the value format to eight hex digits |
2224 | + if (!text.empty() && text[0] == '#') { |
2225 | + changed = true; |
2226 | + text.erase(0, 1); |
2227 | + if (text.size() == 6) { |
2228 | + // it was a standard RGB hex |
2229 | + unsigned int alpha = SP_COLOR_F_TO_U(_color.alpha()); |
2230 | + text += Glib::ustring::format(std::hex, std::setw(2), std::setfill(L'0'), alpha); |
2231 | + } |
2232 | + } |
2233 | + |
2234 | + gchar *str = g_strdup(text.c_str()); |
2235 | + gchar *end = 0; |
2236 | + guint64 rgba = g_ascii_strtoull(str, &end, 16); |
2237 | + if (end != str) { |
2238 | + ptrdiff_t len = end - str; |
2239 | + if (len < 8) { |
2240 | + rgba = rgba << (4 * (8 - len)); |
2241 | + } |
2242 | + if (changed) { |
2243 | + set_text(str); |
2244 | + } |
2245 | + SPColor color(rgba); |
2246 | + _color.setColorAlpha(color, SP_RGBA32_A_F(rgba)); |
2247 | + } |
2248 | + g_free(str); |
2249 | +} |
2250 | + |
2251 | + |
2252 | +void ColorEntry::_onColorChanged() |
2253 | +{ |
2254 | + SPColor color = _color.color(); |
2255 | + gdouble alpha = _color.alpha(); |
2256 | + |
2257 | + guint32 rgba = color.toRGBA32(alpha); |
2258 | + Glib::ustring text = Glib::ustring::format(std::hex, std::setw(8), std::setfill(L'0'), rgba); |
2259 | + |
2260 | + Glib::ustring old_text = get_text(); |
2261 | + if (old_text != text) { |
2262 | + _updating = true; |
2263 | + set_text(text); |
2264 | + _updating = false; |
2265 | + } |
2266 | +} |
2267 | +} |
2268 | +} |
2269 | +} |
2270 | +/* |
2271 | + Local Variables: |
2272 | + mode:c++ |
2273 | + c-file-style:"stroustrup" |
2274 | + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
2275 | + indent-tabs-mode:nil |
2276 | + fill-column:99 |
2277 | + End: |
2278 | +*/ |
2279 | +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |
2280 | |
2281 | === added file 'src/ui/widget/color-entry.h' |
2282 | --- src/ui/widget/color-entry.h 1970-01-01 00:00:00 +0000 |
2283 | +++ src/ui/widget/color-entry.h 2015-05-03 11:19:29 +0000 |
2284 | @@ -0,0 +1,53 @@ |
2285 | +/** @file |
2286 | + * Entry widget for typing color value in css form |
2287 | + *//* |
2288 | + * Authors: |
2289 | + * Tomasz Boczkowski <penginsbacon@gmail.com> |
2290 | + * |
2291 | + * Copyright (C) 2014 Authors |
2292 | + * Released under GNU GPL, read the file 'COPYING' for more information |
2293 | + */ |
2294 | + |
2295 | +#ifndef SEEN_COLOR_ENTRY_H |
2296 | +#define SEEN_COLOR_ENTRY_H_ |
2297 | + |
2298 | +#include <gtkmm/entry.h> |
2299 | +#include "ui/selected-color.h" |
2300 | + |
2301 | +namespace Inkscape { |
2302 | +namespace UI { |
2303 | +namespace Widget { |
2304 | + |
2305 | +class ColorEntry : public Gtk::Entry |
2306 | +{ |
2307 | +public: |
2308 | + ColorEntry(SelectedColor &color); |
2309 | + virtual ~ColorEntry(); |
2310 | + |
2311 | +protected: |
2312 | + void on_changed(); |
2313 | + |
2314 | +private: |
2315 | + void _onColorChanged(); |
2316 | + |
2317 | + SelectedColor &_color; |
2318 | + sigc::connection _color_changed_connection; |
2319 | + sigc::connection _color_dragged_connection; |
2320 | + bool _updating; |
2321 | +}; |
2322 | + |
2323 | +} |
2324 | +} |
2325 | +} |
2326 | + |
2327 | +#endif |
2328 | +/* |
2329 | + Local Variables: |
2330 | + mode:c++ |
2331 | + c-file-style:"stroustrup" |
2332 | + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
2333 | + indent-tabs-mode:nil |
2334 | + fill-column:99 |
2335 | + End: |
2336 | +*/ |
2337 | +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |
2338 | |
2339 | === renamed file 'src/widgets/sp-color-icc-selector.cpp' => 'src/ui/widget/color-icc-selector.cpp' |
2340 | --- src/widgets/sp-color-icc-selector.cpp 2014-10-08 02:22:03 +0000 |
2341 | +++ src/ui/widget/color-icc-selector.cpp 2015-05-03 11:19:29 +0000 |
2342 | @@ -1,24 +1,26 @@ |
2343 | #ifdef HAVE_CONFIG_H |
2344 | -# include "config.h" |
2345 | +#include "config.h" |
2346 | #endif |
2347 | |
2348 | -#include "gradient-vector.h" |
2349 | #include <math.h> |
2350 | +#include <gtkmm/adjustment.h> |
2351 | +#include <glibmm/i18n.h> |
2352 | + |
2353 | #include <gtk/gtk.h> |
2354 | -#include <glibmm/i18n.h> |
2355 | #include <map> |
2356 | #include <set> |
2357 | #include <vector> |
2358 | |
2359 | #include "ui/dialog-events.h" |
2360 | -#include "sp-color-icc-selector.h" |
2361 | -#include "sp-color-scales.h" |
2362 | -#include "sp-color-slider.h" |
2363 | +#include "ui/widget/color-icc-selector.h" |
2364 | +#include "ui/widget/color-scales.h" |
2365 | +#include "ui/widget/color-slider.h" |
2366 | #include "svg/svg-icc-color.h" |
2367 | #include "colorspace.h" |
2368 | #include "document.h" |
2369 | #include "inkscape.h" |
2370 | #include "profile-manager.h" |
2371 | +#include "widgets/gradient-vector.h" |
2372 | |
2373 | #define noDEBUG_LCMS |
2374 | |
2375 | @@ -32,137 +34,32 @@ |
2376 | #endif // DEBUG_LCMS |
2377 | #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2378 | |
2379 | - |
2380 | #ifdef DEBUG_LCMS |
2381 | extern guint update_in_progress; |
2382 | -#define DEBUG_MESSAGE(key, ...) \ |
2383 | -{\ |
2384 | - Inkscape::Preferences *prefs = Inkscape::Preferences::get();\ |
2385 | - bool dump = prefs->getBool("/options/scislac/" #key);\ |
2386 | - bool dumpD = prefs->getBool("/options/scislac/" #key "D");\ |
2387 | - bool dumpD2 = prefs->getBool("/options/scislac/" #key "D2");\ |
2388 | - dumpD &&= ( (update_in_progress == 0) || dumpD2 );\ |
2389 | - if ( dump )\ |
2390 | - {\ |
2391 | - g_message( __VA_ARGS__ );\ |
2392 | -\ |
2393 | - }\ |
2394 | - if ( dumpD )\ |
2395 | - {\ |
2396 | - GtkWidget *dialog = gtk_message_dialog_new(NULL,\ |
2397 | - GTK_DIALOG_DESTROY_WITH_PARENT, \ |
2398 | - GTK_MESSAGE_INFO, \ |
2399 | - GTK_BUTTONS_OK, \ |
2400 | - __VA_ARGS__ \ |
2401 | - );\ |
2402 | - g_signal_connect_swapped(dialog, "response",\ |
2403 | - G_CALLBACK(gtk_widget_destroy), \ |
2404 | - dialog); \ |
2405 | - gtk_widget_show_all( dialog );\ |
2406 | - }\ |
2407 | -} |
2408 | +#define DEBUG_MESSAGE(key, ...) \ |
2409 | + { \ |
2410 | + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); \ |
2411 | + bool dump = prefs->getBool("/options/scislac/" #key); \ |
2412 | + bool dumpD = prefs->getBool("/options/scislac/" #key "D"); \ |
2413 | + bool dumpD2 = prefs->getBool("/options/scislac/" #key "D2"); \ |
2414 | + dumpD && = ((update_in_progress == 0) || dumpD2); \ |
2415 | + if (dump) { \ |
2416 | + g_message(__VA_ARGS__); \ |
2417 | + } \ |
2418 | + if (dumpD) { \ |
2419 | + GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, \ |
2420 | + GTK_BUTTONS_OK, __VA_ARGS__); \ |
2421 | + g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); \ |
2422 | + gtk_widget_show_all(dialog); \ |
2423 | + } \ |
2424 | + } |
2425 | #endif // DEBUG_LCMS |
2426 | |
2427 | |
2428 | - |
2429 | -G_BEGIN_DECLS |
2430 | - |
2431 | -static void sp_color_icc_selector_dispose(GObject *object); |
2432 | -static void sp_color_icc_selector_show_all (GtkWidget *widget); |
2433 | -static void sp_color_icc_selector_hide(GtkWidget *widget); |
2434 | - |
2435 | -G_END_DECLS |
2436 | - |
2437 | -/** |
2438 | - * Class containing the parts for a single color component's UI presence. |
2439 | - */ |
2440 | -class ComponentUI |
2441 | -{ |
2442 | -public: |
2443 | - ComponentUI() : |
2444 | - _component(), |
2445 | - _adj(0), |
2446 | - _slider(0), |
2447 | - _btn(0), |
2448 | - _label(0), |
2449 | - _map(0) |
2450 | - { |
2451 | - } |
2452 | - |
2453 | - ComponentUI(colorspace::Component const &component) : |
2454 | - _component(component), |
2455 | - _adj(0), |
2456 | - _slider(0), |
2457 | - _btn(0), |
2458 | - _label(0), |
2459 | - _map(0) |
2460 | - { |
2461 | - } |
2462 | - |
2463 | - colorspace::Component _component; |
2464 | - GtkAdjustment *_adj; // Component adjustment |
2465 | - GtkWidget *_slider; |
2466 | - GtkWidget *_btn; // spinbutton |
2467 | - GtkWidget *_label; // Label |
2468 | - guchar *_map; |
2469 | -}; |
2470 | - |
2471 | -/** |
2472 | - * Class that implements the internals of the selector. |
2473 | - */ |
2474 | -class ColorICCSelectorImpl |
2475 | -{ |
2476 | -public: |
2477 | - |
2478 | - ColorICCSelectorImpl( ColorICCSelector *owner); |
2479 | - |
2480 | - ~ColorICCSelectorImpl(); |
2481 | - |
2482 | - static void _adjustmentChanged ( GtkAdjustment *adjustment, SPColorICCSelector *cs ); |
2483 | - |
2484 | - static void _sliderGrabbed( SPColorSlider *slider, SPColorICCSelector *cs ); |
2485 | - static void _sliderReleased( SPColorSlider *slider, SPColorICCSelector *cs ); |
2486 | - static void _sliderChanged( SPColorSlider *slider, SPColorICCSelector *cs ); |
2487 | - |
2488 | - static void _profileSelected( GtkWidget* src, gpointer data ); |
2489 | - static void _fixupHit( GtkWidget* src, gpointer data ); |
2490 | - |
2491 | -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2492 | - void _setProfile( SVGICCColor* profile ); |
2493 | - void _switchToProfile( gchar const* name ); |
2494 | -#endif |
2495 | - void _updateSliders( gint ignore ); |
2496 | - void _profilesChanged( std::string const & name ); |
2497 | - |
2498 | - ColorICCSelector *_owner; |
2499 | - |
2500 | - gboolean _updating : 1; |
2501 | - gboolean _dragging : 1; |
2502 | - |
2503 | - guint32 _fixupNeeded; |
2504 | - GtkWidget* _fixupBtn; |
2505 | - GtkWidget* _profileSel; |
2506 | - |
2507 | - std::vector<ComponentUI> _compUI; |
2508 | - |
2509 | - GtkAdjustment* _adj; // Channel adjustment |
2510 | - GtkWidget* _slider; |
2511 | - GtkWidget* _sbtn; // Spinbutton |
2512 | - GtkWidget* _label; // Label |
2513 | - |
2514 | -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2515 | - std::string _profileName; |
2516 | - Inkscape::ColorProfile* _prof; |
2517 | - guint _profChannelCount; |
2518 | - gulong _profChangedID; |
2519 | -#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2520 | -}; |
2521 | - |
2522 | #define XPAD 4 |
2523 | #define YPAD 1 |
2524 | |
2525 | -namespace |
2526 | -{ |
2527 | +namespace { |
2528 | |
2529 | size_t maxColorspaceComponentCount = 0; |
2530 | |
2531 | @@ -187,91 +84,40 @@ |
2532 | /** |
2533 | * Helper function to handle GTK2/GTK3 attachment #ifdef code. |
2534 | */ |
2535 | -void attachToGridOrTable(GtkWidget *parent, |
2536 | - GtkWidget *child, |
2537 | - guint left, |
2538 | - guint top, |
2539 | - guint width, |
2540 | - guint height, |
2541 | - bool hexpand = false, |
2542 | - bool centered = false, |
2543 | - guint xpadding = XPAD, |
2544 | - guint ypadding = YPAD) |
2545 | +void attachToGridOrTable(GtkWidget *parent, GtkWidget *child, guint left, guint top, guint width, guint height, |
2546 | + bool hexpand = false, bool centered = false, guint xpadding = XPAD, guint ypadding = YPAD) |
2547 | { |
2548 | -#if GTK_CHECK_VERSION(3,0,0) |
2549 | - #if GTK_CHECK_VERSION(3,12,0) |
2550 | - gtk_widget_set_margin_start( child, xpadding ); |
2551 | - gtk_widget_set_margin_end( child, xpadding ); |
2552 | - #else |
2553 | - gtk_widget_set_margin_left( child, xpadding ); |
2554 | - gtk_widget_set_margin_right( child, xpadding ); |
2555 | - #endif |
2556 | +#if GTK_CHECK_VERSION(3, 0, 0) |
2557 | + #if GTK_CHECK_VERSION(3, 12, 0) |
2558 | + gtk_widget_set_margin_start(child, xpadding); |
2559 | + gtk_widget_set_margin_end(child, xpadding); |
2560 | + #else |
2561 | + gtk_widget_set_margin_left(child, xpadding); |
2562 | + gtk_widget_set_margin_right(child, xpadding); |
2563 | + #endif |
2564 | |
2565 | - gtk_widget_set_margin_top( child, ypadding ); |
2566 | - gtk_widget_set_margin_bottom( child, ypadding ); |
2567 | + gtk_widget_set_margin_top(child, ypadding); |
2568 | + gtk_widget_set_margin_bottom(child, ypadding); |
2569 | if (hexpand) { |
2570 | gtk_widget_set_hexpand(child, TRUE); |
2571 | } |
2572 | if (centered) { |
2573 | - gtk_widget_set_halign( child, GTK_ALIGN_CENTER ); |
2574 | - gtk_widget_set_valign( child, GTK_ALIGN_CENTER ); |
2575 | + gtk_widget_set_halign(child, GTK_ALIGN_CENTER); |
2576 | + gtk_widget_set_valign(child, GTK_ALIGN_CENTER); |
2577 | } |
2578 | - gtk_grid_attach( GTK_GRID(parent), child, left, top, width, height ); |
2579 | + gtk_grid_attach(GTK_GRID(parent), child, left, top, width, height); |
2580 | #else |
2581 | - GtkAttachOptions xoptions = centered ? static_cast<GtkAttachOptions>(0) : hexpand ? (GTK_EXPAND | GTK_FILL) : GTK_FILL; |
2582 | + GtkAttachOptions xoptions = |
2583 | + centered ? static_cast<GtkAttachOptions>(0) : hexpand ? (GTK_EXPAND | GTK_FILL) : GTK_FILL; |
2584 | GtkAttachOptions yoptions = centered ? static_cast<GtkAttachOptions>(0) : GTK_FILL; |
2585 | |
2586 | - gtk_table_attach( GTK_TABLE(parent), child, left, left + width, top, top + height, xoptions, yoptions, xpadding, ypadding ); |
2587 | + gtk_table_attach(GTK_TABLE(parent), child, left, left + width, top, top + height, xoptions, yoptions, xpadding, |
2588 | + ypadding); |
2589 | #endif |
2590 | } |
2591 | |
2592 | } // namespace |
2593 | |
2594 | -G_DEFINE_TYPE(SPColorICCSelector, sp_color_icc_selector, SP_TYPE_COLOR_SELECTOR); |
2595 | - |
2596 | -static void sp_color_icc_selector_class_init(SPColorICCSelectorClass *klass) |
2597 | -{ |
2598 | - static const gchar* nameset[] = {N_("CMS"), 0}; |
2599 | - GObjectClass *object_class = G_OBJECT_CLASS(klass); |
2600 | - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); |
2601 | - SPColorSelectorClass *selector_class = SP_COLOR_SELECTOR_CLASS (klass); |
2602 | - |
2603 | - selector_class->name = nameset; |
2604 | - selector_class->submode_count = 1; |
2605 | - |
2606 | - object_class->dispose = sp_color_icc_selector_dispose; |
2607 | - |
2608 | - widget_class->show_all = sp_color_icc_selector_show_all; |
2609 | - widget_class->hide = sp_color_icc_selector_hide; |
2610 | -} |
2611 | - |
2612 | - |
2613 | -ColorICCSelector::ColorICCSelector( SPColorSelector* csel ) |
2614 | - : ColorSelector( csel ), |
2615 | - _impl(NULL) |
2616 | -{ |
2617 | -} |
2618 | - |
2619 | -ColorICCSelector::~ColorICCSelector() |
2620 | -{ |
2621 | - if (_impl) |
2622 | - { |
2623 | - delete _impl; |
2624 | - _impl = 0; |
2625 | - } |
2626 | -} |
2627 | - |
2628 | -void sp_color_icc_selector_init(SPColorICCSelector *cs) |
2629 | -{ |
2630 | - SP_COLOR_SELECTOR(cs)->base = new ColorICCSelector( SP_COLOR_SELECTOR(cs) ); |
2631 | - |
2632 | - if ( SP_COLOR_SELECTOR(cs)->base ) |
2633 | - { |
2634 | - SP_COLOR_SELECTOR(cs)->base->init(); |
2635 | - } |
2636 | -} |
2637 | - |
2638 | - |
2639 | /* |
2640 | icSigRgbData |
2641 | icSigCmykData |
2642 | @@ -283,32 +129,32 @@ |
2643 | |
2644 | |
2645 | #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2646 | -static cmsUInt16Number* getScratch() { |
2647 | +static cmsUInt16Number *getScratch() |
2648 | +{ |
2649 | // bytes per pixel * input channels * width |
2650 | - static cmsUInt16Number* scritch = static_cast<cmsUInt16Number*>(g_new(cmsUInt16Number, 4 * 1024)); |
2651 | + static cmsUInt16Number *scritch = static_cast<cmsUInt16Number *>(g_new(cmsUInt16Number, 4 * 1024)); |
2652 | |
2653 | return scritch; |
2654 | } |
2655 | |
2656 | -colorspace::Component::Component() : |
2657 | - name(), |
2658 | - tip(), |
2659 | - scale(1) |
2660 | -{ |
2661 | -} |
2662 | - |
2663 | -colorspace::Component::Component(std::string const &name, std::string const &tip, guint scale) : |
2664 | - name(name), |
2665 | - tip(tip), |
2666 | - scale(scale) |
2667 | -{ |
2668 | -} |
2669 | - |
2670 | -std::vector<colorspace::Component> colorspace::getColorSpaceInfo( uint32_t space ) |
2671 | +colorspace::Component::Component() |
2672 | + : name() |
2673 | + , tip() |
2674 | + , scale(1) |
2675 | +{ |
2676 | +} |
2677 | + |
2678 | +colorspace::Component::Component(std::string const &name, std::string const &tip, guint scale) |
2679 | + : name(name) |
2680 | + , tip(tip) |
2681 | + , scale(scale) |
2682 | +{ |
2683 | +} |
2684 | + |
2685 | +std::vector<colorspace::Component> colorspace::getColorSpaceInfo(uint32_t space) |
2686 | { |
2687 | static std::map<cmsUInt32Number, std::vector<Component> > sets; |
2688 | - if (sets.empty()) |
2689 | - { |
2690 | + if (sets.empty()) { |
2691 | sets[cmsSigXYZData].push_back(Component("_X", "X", 2)); // TYPE_XYZ_16 |
2692 | sets[cmsSigXYZData].push_back(Component("_Y", "Y", 1)); |
2693 | sets[cmsSigXYZData].push_back(Component("_Z", "Z", 2)); |
2694 | @@ -317,7 +163,7 @@ |
2695 | sets[cmsSigLabData].push_back(Component("_a", "a", 256)); |
2696 | sets[cmsSigLabData].push_back(Component("_b", "b", 256)); |
2697 | |
2698 | - //cmsSigLuvData |
2699 | + // cmsSigLuvData |
2700 | |
2701 | sets[cmsSigYCbCrData].push_back(Component("_Y", "Y", 1)); // TYPE_YCbCr_16 |
2702 | sets[cmsSigYCbCrData].push_back(Component("C_b", "Cb", 1)); |
2703 | @@ -350,8 +196,7 @@ |
2704 | sets[cmsSigCmyData].push_back(Component(_("_M:"), _("Magenta"), 1)); |
2705 | sets[cmsSigCmyData].push_back(Component(_("_Y:"), _("Yellow"), 1)); |
2706 | |
2707 | - for (std::map<cmsUInt32Number, std::vector<Component> >::iterator it = sets.begin(); it != sets.end(); ++it) |
2708 | - { |
2709 | + for (std::map<cmsUInt32Number, std::vector<Component> >::iterator it = sets.begin(); it != sets.end(); ++it) { |
2710 | knownColorspaces.insert(it->first); |
2711 | maxColorspaceComponentCount = std::max(maxColorspaceComponentCount, it->second.size()); |
2712 | } |
2713 | @@ -359,39 +204,148 @@ |
2714 | |
2715 | std::vector<Component> target; |
2716 | |
2717 | - if (sets.find(space) != sets.end()) |
2718 | - { |
2719 | + if (sets.find(space) != sets.end()) { |
2720 | target = sets[space]; |
2721 | } |
2722 | return target; |
2723 | } |
2724 | |
2725 | |
2726 | -std::vector<colorspace::Component> colorspace::getColorSpaceInfo( Inkscape::ColorProfile *prof ) |
2727 | -{ |
2728 | - return getColorSpaceInfo( asICColorSpaceSig(prof->getColorSpace()) ); |
2729 | -} |
2730 | - |
2731 | -#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2732 | - |
2733 | -ColorICCSelectorImpl::ColorICCSelectorImpl(ColorICCSelector *owner) : |
2734 | - _owner(owner), |
2735 | - _updating( FALSE ), |
2736 | - _dragging( FALSE ), |
2737 | - _fixupNeeded(0), |
2738 | - _fixupBtn(0), |
2739 | - _profileSel(0), |
2740 | - _compUI(), |
2741 | - _adj(0), |
2742 | - _slider(0), |
2743 | - _sbtn(0), |
2744 | - _label(0) |
2745 | -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2746 | - , |
2747 | - _profileName(), |
2748 | - _prof(0), |
2749 | - _profChannelCount(0), |
2750 | - _profChangedID(0) |
2751 | +std::vector<colorspace::Component> colorspace::getColorSpaceInfo(Inkscape::ColorProfile *prof) |
2752 | +{ |
2753 | + return getColorSpaceInfo(asICColorSpaceSig(prof->getColorSpace())); |
2754 | +} |
2755 | + |
2756 | +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2757 | + |
2758 | +namespace Inkscape { |
2759 | +namespace UI { |
2760 | +namespace Widget { |
2761 | + |
2762 | +/** |
2763 | + * Class containing the parts for a single color component's UI presence. |
2764 | + */ |
2765 | +class ComponentUI { |
2766 | + public: |
2767 | + ComponentUI() |
2768 | + : _component() |
2769 | + , _adj(0) |
2770 | + , _slider(0) |
2771 | + , _btn(0) |
2772 | + , _label(0) |
2773 | + , _map(0) |
2774 | + { |
2775 | + } |
2776 | + |
2777 | + ComponentUI(colorspace::Component const &component) |
2778 | + : _component(component) |
2779 | + , _adj(0) |
2780 | + , _slider(0) |
2781 | + , _btn(0) |
2782 | + , _label(0) |
2783 | + , _map(0) |
2784 | + { |
2785 | + } |
2786 | + |
2787 | + colorspace::Component _component; |
2788 | + GtkAdjustment *_adj; // Component adjustment |
2789 | + Inkscape::UI::Widget::ColorSlider *_slider; |
2790 | + GtkWidget *_btn; // spinbutton |
2791 | + GtkWidget *_label; // Label |
2792 | + guchar *_map; |
2793 | +}; |
2794 | + |
2795 | +/** |
2796 | + * Class that implements the internals of the selector. |
2797 | + */ |
2798 | +class ColorICCSelectorImpl { |
2799 | + public: |
2800 | + ColorICCSelectorImpl(ColorICCSelector *owner, SelectedColor &color); |
2801 | + |
2802 | + ~ColorICCSelectorImpl(); |
2803 | + |
2804 | + static void _adjustmentChanged(GtkAdjustment *adjustment, ColorICCSelectorImpl *cs); |
2805 | + |
2806 | + void _sliderGrabbed(); |
2807 | + void _sliderReleased(); |
2808 | + void _sliderChanged(); |
2809 | + |
2810 | + static void _profileSelected(GtkWidget *src, gpointer data); |
2811 | + static void _fixupHit(GtkWidget *src, gpointer data); |
2812 | + |
2813 | +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2814 | + void _setProfile(SVGICCColor *profile); |
2815 | + void _switchToProfile(gchar const *name); |
2816 | +#endif |
2817 | + void _updateSliders(gint ignore); |
2818 | + void _profilesChanged(std::string const &name); |
2819 | + |
2820 | + ColorICCSelector *_owner; |
2821 | + SelectedColor &_color; |
2822 | + |
2823 | + gboolean _updating : 1; |
2824 | + gboolean _dragging : 1; |
2825 | + |
2826 | + guint32 _fixupNeeded; |
2827 | + GtkWidget *_fixupBtn; |
2828 | + GtkWidget *_profileSel; |
2829 | + |
2830 | + std::vector<ComponentUI> _compUI; |
2831 | + |
2832 | + GtkAdjustment *_adj; // Channel adjustment |
2833 | + Inkscape::UI::Widget::ColorSlider *_slider; |
2834 | + GtkWidget *_sbtn; // Spinbutton |
2835 | + GtkWidget *_label; // Label |
2836 | + |
2837 | +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2838 | + std::string _profileName; |
2839 | + Inkscape::ColorProfile *_prof; |
2840 | + guint _profChannelCount; |
2841 | + gulong _profChangedID; |
2842 | +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2843 | +}; |
2844 | + |
2845 | + |
2846 | + |
2847 | +const gchar *ColorICCSelector::MODE_NAME = N_("CMS"); |
2848 | + |
2849 | +ColorICCSelector::ColorICCSelector(SelectedColor &color) |
2850 | + : _impl(NULL) |
2851 | +{ |
2852 | + _impl = new ColorICCSelectorImpl(this, color); |
2853 | + init(); |
2854 | + color.signal_changed.connect(sigc::mem_fun(this, &ColorICCSelector::_colorChanged)); |
2855 | + // color.signal_dragged.connect(sigc::mem_fun(this, &ColorICCSelector::_colorChanged)); |
2856 | +} |
2857 | + |
2858 | +ColorICCSelector::~ColorICCSelector() |
2859 | +{ |
2860 | + if (_impl) { |
2861 | + delete _impl; |
2862 | + _impl = 0; |
2863 | + } |
2864 | +} |
2865 | + |
2866 | + |
2867 | + |
2868 | +ColorICCSelectorImpl::ColorICCSelectorImpl(ColorICCSelector *owner, SelectedColor &color) |
2869 | + : _owner(owner) |
2870 | + , _color(color) |
2871 | + , _updating(FALSE) |
2872 | + , _dragging(FALSE) |
2873 | + , _fixupNeeded(0) |
2874 | + , _fixupBtn(0) |
2875 | + , _profileSel(0) |
2876 | + , _compUI() |
2877 | + , _adj(0) |
2878 | + , _slider(0) |
2879 | + , _sbtn(0) |
2880 | + , _label(0) |
2881 | +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2882 | + , _profileName() |
2883 | + , _prof(0) |
2884 | + , _profChannelCount(0) |
2885 | + , _profChangedID(0) |
2886 | #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2887 | { |
2888 | } |
2889 | @@ -405,21 +359,14 @@ |
2890 | |
2891 | void ColorICCSelector::init() |
2892 | { |
2893 | - if (_impl) delete(_impl); |
2894 | - _impl = new ColorICCSelectorImpl(this); |
2895 | gint row = 0; |
2896 | |
2897 | _impl->_updating = FALSE; |
2898 | _impl->_dragging = FALSE; |
2899 | |
2900 | -#if GTK_CHECK_VERSION(3,0,0) |
2901 | - GtkWidget *t = gtk_grid_new(); |
2902 | -#else |
2903 | - GtkWidget *t = gtk_table_new(5, 3, FALSE); |
2904 | -#endif |
2905 | + GtkWidget *t = GTK_WIDGET(gobj()); |
2906 | |
2907 | - gtk_widget_show (t); |
2908 | - gtk_box_pack_start (GTK_BOX (_csel), t, TRUE, TRUE, 4); |
2909 | + gtk_widget_show(t); |
2910 | |
2911 | _impl->_compUI.clear(); |
2912 | |
2913 | @@ -428,50 +375,53 @@ |
2914 | |
2915 | |
2916 | _impl->_fixupBtn = gtk_button_new_with_label(_("Fix")); |
2917 | - g_signal_connect( G_OBJECT(_impl->_fixupBtn), "clicked", G_CALLBACK(ColorICCSelectorImpl::_fixupHit), (gpointer)_impl ); |
2918 | - gtk_widget_set_sensitive( _impl->_fixupBtn, FALSE ); |
2919 | - gtk_widget_set_tooltip_text( _impl->_fixupBtn, _("Fix RGB fallback to match icc-color() value.") ); |
2920 | - //gtk_misc_set_alignment( GTK_MISC (_impl->_fixupBtn), 1.0, 0.5 ); |
2921 | - gtk_widget_show( _impl->_fixupBtn ); |
2922 | + g_signal_connect(G_OBJECT(_impl->_fixupBtn), "clicked", G_CALLBACK(ColorICCSelectorImpl::_fixupHit), |
2923 | + (gpointer)_impl); |
2924 | + gtk_widget_set_sensitive(_impl->_fixupBtn, FALSE); |
2925 | + gtk_widget_set_tooltip_text(_impl->_fixupBtn, _("Fix RGB fallback to match icc-color() value.")); |
2926 | + // gtk_misc_set_alignment( GTK_MISC (_impl->_fixupBtn), 1.0, 0.5 ); |
2927 | + gtk_widget_show(_impl->_fixupBtn); |
2928 | |
2929 | attachToGridOrTable(t, _impl->_fixupBtn, 0, row, 1, 1); |
2930 | |
2931 | // Combobox and store with 2 columns : label (0) and full name (1) |
2932 | - GtkListStore *store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); |
2933 | - _impl->_profileSel = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store)); |
2934 | + GtkListStore *store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); |
2935 | + _impl->_profileSel = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); |
2936 | |
2937 | - GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); |
2938 | + GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
2939 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(_impl->_profileSel), renderer, TRUE); |
2940 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(_impl->_profileSel), renderer, "text", 0, NULL); |
2941 | |
2942 | GtkTreeIter iter; |
2943 | - gtk_list_store_append (store, &iter); |
2944 | - gtk_list_store_set (store, &iter, 0, _("<none>"), 1, _("<none>"), -1); |
2945 | + gtk_list_store_append(store, &iter); |
2946 | + gtk_list_store_set(store, &iter, 0, _("<none>"), 1, _("<none>"), -1); |
2947 | |
2948 | - gtk_widget_show( _impl->_profileSel ); |
2949 | - gtk_combo_box_set_active( GTK_COMBO_BOX(_impl->_profileSel), 0 ); |
2950 | + gtk_widget_show(_impl->_profileSel); |
2951 | + gtk_combo_box_set_active(GTK_COMBO_BOX(_impl->_profileSel), 0); |
2952 | |
2953 | attachToGridOrTable(t, _impl->_profileSel, 1, row, 1, 1); |
2954 | |
2955 | #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2956 | - _impl->_profChangedID = g_signal_connect( G_OBJECT(_impl->_profileSel), "changed", G_CALLBACK(ColorICCSelectorImpl::_profileSelected), (gpointer)_impl ); |
2957 | + _impl->_profChangedID = g_signal_connect(G_OBJECT(_impl->_profileSel), "changed", |
2958 | + G_CALLBACK(ColorICCSelectorImpl::_profileSelected), (gpointer)_impl); |
2959 | #else |
2960 | - gtk_widget_set_sensitive( _impl->_profileSel, false ); |
2961 | + gtk_widget_set_sensitive(_impl->_profileSel, false); |
2962 | #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2963 | |
2964 | |
2965 | row++; |
2966 | |
2967 | - // populate the data for colorspaces and channels: |
2968 | +// populate the data for colorspaces and channels: |
2969 | #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2970 | - std::vector<colorspace::Component> things = colorspace::getColorSpaceInfo( cmsSigRgbData ); |
2971 | + std::vector<colorspace::Component> things = colorspace::getColorSpaceInfo(cmsSigRgbData); |
2972 | #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2973 | |
2974 | - for ( size_t i = 0; i < maxColorspaceComponentCount; i++ ) { |
2975 | + for (size_t i = 0; i < maxColorspaceComponentCount; i++) { |
2976 | #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
2977 | if (i < things.size()) { |
2978 | _impl->_compUI.push_back(ComponentUI(things[i])); |
2979 | - } else { |
2980 | + } |
2981 | + else { |
2982 | _impl->_compUI.push_back(ComponentUI()); |
2983 | } |
2984 | |
2985 | @@ -482,9 +432,9 @@ |
2986 | std::string labelStr = "."; |
2987 | #endif |
2988 | |
2989 | - _impl->_compUI[i]._label = gtk_label_new_with_mnemonic( labelStr.c_str() ); |
2990 | - gtk_misc_set_alignment( GTK_MISC (_impl->_compUI[i]._label), 1.0, 0.5 ); |
2991 | - gtk_widget_show( _impl->_compUI[i]._label ); |
2992 | + _impl->_compUI[i]._label = gtk_label_new_with_mnemonic(labelStr.c_str()); |
2993 | + gtk_misc_set_alignment(GTK_MISC(_impl->_compUI[i]._label), 1.0, 0.5); |
2994 | + gtk_widget_show(_impl->_compUI[i]._label); |
2995 | |
2996 | attachToGridOrTable(t, _impl->_compUI[i]._label, 0, row, 1, 1); |
2997 | |
2998 | @@ -493,41 +443,45 @@ |
2999 | gdouble step = static_cast<gdouble>(scaleValue) / 100.0; |
3000 | gdouble page = static_cast<gdouble>(scaleValue) / 10.0; |
3001 | gint digits = (step > 0.9) ? 0 : 2; |
3002 | - _impl->_compUI[i]._adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0.0, 0.0, scaleValue, step, page, page ) ); |
3003 | + _impl->_compUI[i]._adj = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, scaleValue, step, page, page)); |
3004 | |
3005 | // Slider |
3006 | - _impl->_compUI[i]._slider = sp_color_slider_new( _impl->_compUI[i]._adj ); |
3007 | -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3008 | - gtk_widget_set_tooltip_text( _impl->_compUI[i]._slider, (i < things.size()) ? things[i].tip.c_str() : "" ); |
3009 | -#else |
3010 | - gtk_widget_set_tooltip_text( _impl->_compUI[i]._slider, "." ); |
3011 | -#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3012 | - gtk_widget_show( _impl->_compUI[i]._slider ); |
3013 | - |
3014 | - attachToGridOrTable(t, _impl->_compUI[i]._slider, 1, row, 1, 1, true); |
3015 | - |
3016 | - _impl->_compUI[i]._btn = gtk_spin_button_new( _impl->_compUI[i]._adj, step, digits ); |
3017 | -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3018 | - gtk_widget_set_tooltip_text( _impl->_compUI[i]._btn, (i < things.size()) ? things[i].tip.c_str() : "" ); |
3019 | -#else |
3020 | - gtk_widget_set_tooltip_text( _impl->_compUI[i]._btn, "." ); |
3021 | -#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3022 | - sp_dialog_defocus_on_enter( _impl->_compUI[i]._btn ); |
3023 | - gtk_label_set_mnemonic_widget( GTK_LABEL(_impl->_compUI[i]._label), _impl->_compUI[i]._btn ); |
3024 | - gtk_widget_show( _impl->_compUI[i]._btn ); |
3025 | + _impl->_compUI[i]._slider = |
3026 | + Gtk::manage(new Inkscape::UI::Widget::ColorSlider(Glib::wrap(_impl->_compUI[i]._adj, true))); |
3027 | +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3028 | + _impl->_compUI[i]._slider->set_tooltip_text((i < things.size()) ? things[i].tip.c_str() : ""); |
3029 | +#else |
3030 | + _impl->_compUI[i]._slider->set_tooltip_text("."); |
3031 | +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3032 | + _impl->_compUI[i]._slider->show(); |
3033 | + |
3034 | + attachToGridOrTable(t, _impl->_compUI[i]._slider->gobj(), 1, row, 1, 1, true); |
3035 | + |
3036 | + _impl->_compUI[i]._btn = gtk_spin_button_new(_impl->_compUI[i]._adj, step, digits); |
3037 | +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3038 | + gtk_widget_set_tooltip_text(_impl->_compUI[i]._btn, (i < things.size()) ? things[i].tip.c_str() : ""); |
3039 | +#else |
3040 | + gtk_widget_set_tooltip_text(_impl->_compUI[i]._btn, "."); |
3041 | +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3042 | + sp_dialog_defocus_on_enter(_impl->_compUI[i]._btn); |
3043 | + gtk_label_set_mnemonic_widget(GTK_LABEL(_impl->_compUI[i]._label), _impl->_compUI[i]._btn); |
3044 | + gtk_widget_show(_impl->_compUI[i]._btn); |
3045 | |
3046 | attachToGridOrTable(t, _impl->_compUI[i]._btn, 2, row, 1, 1, false, true); |
3047 | |
3048 | - _impl->_compUI[i]._map = g_new( guchar, 4 * 1024 ); |
3049 | - memset( _impl->_compUI[i]._map, 0x0ff, 1024 * 4 ); |
3050 | + _impl->_compUI[i]._map = g_new(guchar, 4 * 1024); |
3051 | + memset(_impl->_compUI[i]._map, 0x0ff, 1024 * 4); |
3052 | |
3053 | |
3054 | // Signals |
3055 | - g_signal_connect( G_OBJECT( _impl->_compUI[i]._adj ), "value_changed", G_CALLBACK( ColorICCSelectorImpl::_adjustmentChanged ), _csel ); |
3056 | + g_signal_connect(G_OBJECT(_impl->_compUI[i]._adj), "value_changed", |
3057 | + G_CALLBACK(ColorICCSelectorImpl::_adjustmentChanged), _impl); |
3058 | |
3059 | - g_signal_connect( G_OBJECT( _impl->_compUI[i]._slider ), "grabbed", G_CALLBACK( ColorICCSelectorImpl::_sliderGrabbed ), _csel ); |
3060 | - g_signal_connect( G_OBJECT( _impl->_compUI[i]._slider ), "released", G_CALLBACK( ColorICCSelectorImpl::_sliderReleased ), _csel ); |
3061 | - g_signal_connect( G_OBJECT( _impl->_compUI[i]._slider ), "changed", G_CALLBACK( ColorICCSelectorImpl::_sliderChanged ), _csel ); |
3062 | + _impl->_compUI[i]._slider->signal_grabbed.connect(sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderGrabbed)); |
3063 | + _impl->_compUI[i]._slider->signal_released.connect( |
3064 | + sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderReleased)); |
3065 | + _impl->_compUI[i]._slider->signal_value_changed.connect( |
3066 | + sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderChanged)); |
3067 | |
3068 | row++; |
3069 | } |
3070 | @@ -543,16 +497,14 @@ |
3071 | _impl->_adj = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 255.0, 1.0, 10.0, 10.0)); |
3072 | |
3073 | // Slider |
3074 | - _impl->_slider = sp_color_slider_new(_impl->_adj); |
3075 | - gtk_widget_set_tooltip_text(_impl->_slider, _("Alpha (opacity)")); |
3076 | - gtk_widget_show(_impl->_slider); |
3077 | - |
3078 | - attachToGridOrTable(t, _impl->_slider, 1, row, 1, 1, true); |
3079 | - |
3080 | - sp_color_slider_set_colors( SP_COLOR_SLIDER( _impl->_slider ), |
3081 | - SP_RGBA32_F_COMPOSE( 1.0, 1.0, 1.0, 0.0 ), |
3082 | - SP_RGBA32_F_COMPOSE( 1.0, 1.0, 1.0, 0.5 ), |
3083 | - SP_RGBA32_F_COMPOSE( 1.0, 1.0, 1.0, 1.0 ) ); |
3084 | + _impl->_slider = Gtk::manage(new Inkscape::UI::Widget::ColorSlider(Glib::wrap(_impl->_adj, true))); |
3085 | + _impl->_slider->set_tooltip_text(_("Alpha (opacity)")); |
3086 | + _impl->_slider->show(); |
3087 | + |
3088 | + attachToGridOrTable(t, _impl->_slider->gobj(), 1, row, 1, 1, true); |
3089 | + |
3090 | + _impl->_slider->setColors(SP_RGBA32_F_COMPOSE(1.0, 1.0, 1.0, 0.0), SP_RGBA32_F_COMPOSE(1.0, 1.0, 1.0, 0.5), |
3091 | + SP_RGBA32_F_COMPOSE(1.0, 1.0, 1.0, 1.0)); |
3092 | |
3093 | |
3094 | // Spinbutton |
3095 | @@ -565,96 +517,70 @@ |
3096 | attachToGridOrTable(t, _impl->_sbtn, 2, row, 1, 1, false, true); |
3097 | |
3098 | // Signals |
3099 | - g_signal_connect(G_OBJECT(_impl->_adj), "value_changed", G_CALLBACK(ColorICCSelectorImpl::_adjustmentChanged), _csel); |
3100 | - |
3101 | - g_signal_connect(G_OBJECT(_impl->_slider), "grabbed", G_CALLBACK(ColorICCSelectorImpl::_sliderGrabbed), _csel); |
3102 | - g_signal_connect(G_OBJECT(_impl->_slider), "released", G_CALLBACK(ColorICCSelectorImpl::_sliderReleased), _csel); |
3103 | - g_signal_connect(G_OBJECT(_impl->_slider), "changed", G_CALLBACK(ColorICCSelectorImpl::_sliderChanged), _csel); |
3104 | -} |
3105 | - |
3106 | -static void sp_color_icc_selector_dispose(GObject *object) |
3107 | -{ |
3108 | - if (G_OBJECT_CLASS(sp_color_icc_selector_parent_class)->dispose) { |
3109 | - G_OBJECT_CLASS(sp_color_icc_selector_parent_class)->dispose(object); |
3110 | - } |
3111 | -} |
3112 | - |
3113 | -static void |
3114 | -sp_color_icc_selector_show_all (GtkWidget *widget) |
3115 | -{ |
3116 | - gtk_widget_show (widget); |
3117 | -} |
3118 | - |
3119 | -static void sp_color_icc_selector_hide(GtkWidget *widget) |
3120 | -{ |
3121 | - gtk_widget_hide(widget); |
3122 | -} |
3123 | - |
3124 | -GtkWidget * |
3125 | -sp_color_icc_selector_new (void) |
3126 | -{ |
3127 | - SPColorICCSelector *csel; |
3128 | - |
3129 | - csel = static_cast<SPColorICCSelector*>(g_object_new (SP_TYPE_COLOR_ICC_SELECTOR, NULL)); |
3130 | - |
3131 | - return GTK_WIDGET (csel); |
3132 | -} |
3133 | - |
3134 | - |
3135 | -void ColorICCSelectorImpl::_fixupHit( GtkWidget* /*src*/, gpointer data ) |
3136 | -{ |
3137 | - ColorICCSelectorImpl* self = reinterpret_cast<ColorICCSelectorImpl*>(data); |
3138 | - gtk_widget_set_sensitive( self->_fixupBtn, FALSE ); |
3139 | - self->_adjustmentChanged( self->_compUI[0]._adj, SP_COLOR_ICC_SELECTOR(self->_owner->_csel) ); |
3140 | + g_signal_connect(G_OBJECT(_impl->_adj), "value_changed", G_CALLBACK(ColorICCSelectorImpl::_adjustmentChanged), |
3141 | + _impl); |
3142 | + |
3143 | + _impl->_slider->signal_grabbed.connect(sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderGrabbed)); |
3144 | + _impl->_slider->signal_released.connect(sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderReleased)); |
3145 | + _impl->_slider->signal_value_changed.connect(sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderChanged)); |
3146 | +} |
3147 | + |
3148 | +void ColorICCSelectorImpl::_fixupHit(GtkWidget * /*src*/, gpointer data) |
3149 | +{ |
3150 | + ColorICCSelectorImpl *self = reinterpret_cast<ColorICCSelectorImpl *>(data); |
3151 | + gtk_widget_set_sensitive(self->_fixupBtn, FALSE); |
3152 | + self->_adjustmentChanged(self->_compUI[0]._adj, self); |
3153 | } |
3154 | |
3155 | #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3156 | -void ColorICCSelectorImpl::_profileSelected( GtkWidget* /*src*/, gpointer data ) |
3157 | +void ColorICCSelectorImpl::_profileSelected(GtkWidget * /*src*/, gpointer data) |
3158 | { |
3159 | - ColorICCSelectorImpl* self = reinterpret_cast<ColorICCSelectorImpl*>(data); |
3160 | + ColorICCSelectorImpl *self = reinterpret_cast<ColorICCSelectorImpl *>(data); |
3161 | |
3162 | - GtkTreeIter iter; |
3163 | + GtkTreeIter iter; |
3164 | if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(self->_profileSel), &iter)) { |
3165 | GtkTreeModel *store = gtk_combo_box_get_model(GTK_COMBO_BOX(self->_profileSel)); |
3166 | - gchar* name = 0; |
3167 | + gchar *name = 0; |
3168 | |
3169 | gtk_tree_model_get(store, &iter, 1, &name, -1); |
3170 | - self->_switchToProfile( name ); |
3171 | - gtk_widget_set_tooltip_text(self->_profileSel, name ); |
3172 | + self->_switchToProfile(name); |
3173 | + gtk_widget_set_tooltip_text(self->_profileSel, name); |
3174 | |
3175 | - if ( name ) { |
3176 | - g_free( name ); |
3177 | + if (name) { |
3178 | + g_free(name); |
3179 | } |
3180 | } |
3181 | } |
3182 | #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3183 | |
3184 | #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3185 | -void ColorICCSelectorImpl::_switchToProfile( gchar const* name ) |
3186 | +void ColorICCSelectorImpl::_switchToProfile(gchar const *name) |
3187 | { |
3188 | bool dirty = false; |
3189 | - SPColor tmp( _owner->_color ); |
3190 | + SPColor tmp(_color.color()); |
3191 | |
3192 | - if ( name ) { |
3193 | - if ( tmp.icc && tmp.icc->colorProfile == name ) { |
3194 | -#ifdef DEBUG_LCMS |
3195 | - g_message("Already at name [%s]", name ); |
3196 | -#endif // DEBUG_LCMS |
3197 | - } else { |
3198 | -#ifdef DEBUG_LCMS |
3199 | - g_message("Need to switch to profile [%s]", name ); |
3200 | -#endif // DEBUG_LCMS |
3201 | - if ( tmp.icc ) { |
3202 | + if (name) { |
3203 | + if (tmp.icc && tmp.icc->colorProfile == name) { |
3204 | +#ifdef DEBUG_LCMS |
3205 | + g_message("Already at name [%s]", name); |
3206 | +#endif // DEBUG_LCMS |
3207 | + } |
3208 | + else { |
3209 | +#ifdef DEBUG_LCMS |
3210 | + g_message("Need to switch to profile [%s]", name); |
3211 | +#endif // DEBUG_LCMS |
3212 | + if (tmp.icc) { |
3213 | tmp.icc->colors.clear(); |
3214 | - } else { |
3215 | + } |
3216 | + else { |
3217 | tmp.icc = new SVGICCColor(); |
3218 | } |
3219 | tmp.icc->colorProfile = name; |
3220 | - Inkscape::ColorProfile* newProf = SP_ACTIVE_DOCUMENT->profileManager->find(name); |
3221 | - if ( newProf ) { |
3222 | + Inkscape::ColorProfile *newProf = SP_ACTIVE_DOCUMENT->profileManager->find(name); |
3223 | + if (newProf) { |
3224 | cmsHTRANSFORM trans = newProf->getTransfFromSRGB8(); |
3225 | - if ( trans ) { |
3226 | - guint32 val = _owner->_color.toRGBA32(0); |
3227 | + if (trans) { |
3228 | + guint32 val = _color.color().toRGBA32(0); |
3229 | guchar pre[4] = { |
3230 | static_cast<guchar>(SP_RGBA32_R_U(val)), |
3231 | static_cast<guchar>(SP_RGBA32_G_U(val)), |
3232 | @@ -663,29 +589,31 @@ |
3233 | #ifdef DEBUG_LCMS |
3234 | g_message("Shoving in [%02x] [%02x] [%02x]", pre[0], pre[1], pre[2]); |
3235 | #endif // DEBUG_LCMS |
3236 | - cmsUInt16Number post[4] = {0,0,0,0}; |
3237 | - cmsDoTransform( trans, pre, post, 1 ); |
3238 | + cmsUInt16Number post[4] = { 0, 0, 0, 0 }; |
3239 | + cmsDoTransform(trans, pre, post, 1); |
3240 | #ifdef DEBUG_LCMS |
3241 | g_message("got on out [%04x] [%04x] [%04x] [%04x]", post[0], post[1], post[2], post[3]); |
3242 | #endif // DEBUG_LCMS |
3243 | #if HAVE_LIBLCMS1 |
3244 | - guint count = _cmsChannelsOf( asICColorSpaceSig(newProf->getColorSpace()) ); |
3245 | + guint count = _cmsChannelsOf(asICColorSpaceSig(newProf->getColorSpace())); |
3246 | #elif HAVE_LIBLCMS2 |
3247 | - guint count = cmsChannelsOf( asICColorSpaceSig(newProf->getColorSpace()) ); |
3248 | + guint count = cmsChannelsOf(asICColorSpaceSig(newProf->getColorSpace())); |
3249 | #endif |
3250 | |
3251 | - std::vector<colorspace::Component> things = colorspace::getColorSpaceInfo(asICColorSpaceSig(newProf->getColorSpace())); |
3252 | + std::vector<colorspace::Component> things = |
3253 | + colorspace::getColorSpaceInfo(asICColorSpaceSig(newProf->getColorSpace())); |
3254 | |
3255 | - for ( guint i = 0; i < count; i++ ) { |
3256 | - gdouble val = (((gdouble)post[i])/65535.0) * (gdouble)((i < things.size()) ? things[i].scale : 1); |
3257 | + for (guint i = 0; i < count; i++) { |
3258 | + gdouble val = |
3259 | + (((gdouble)post[i]) / 65535.0) * (gdouble)((i < things.size()) ? things[i].scale : 1); |
3260 | #ifdef DEBUG_LCMS |
3261 | g_message(" scaled %d by %d to be %f", i, ((i < things.size()) ? things[i].scale : 1), val); |
3262 | #endif // DEBUG_LCMS |
3263 | tmp.icc->colors.push_back(val); |
3264 | } |
3265 | cmsHTRANSFORM retrans = newProf->getTransfToSRGB8(); |
3266 | - if ( retrans ) { |
3267 | - cmsDoTransform( retrans, post, pre, 1 ); |
3268 | + if (retrans) { |
3269 | + cmsDoTransform(retrans, post, pre, 1); |
3270 | #ifdef DEBUG_LCMS |
3271 | g_message(" back out [%02x] [%02x] [%02x]", pre[0], pre[1], pre[2]); |
3272 | #endif // DEBUG_LCMS |
3273 | @@ -695,30 +623,32 @@ |
3274 | } |
3275 | dirty = true; |
3276 | } |
3277 | - } else { |
3278 | + } |
3279 | + else { |
3280 | #ifdef DEBUG_LCMS |
3281 | - g_message("NUKE THE ICC"); |
3282 | + g_message("NUKE THE ICC"); |
3283 | #endif // DEBUG_LCMS |
3284 | - if ( tmp.icc ) { |
3285 | + if (tmp.icc) { |
3286 | delete tmp.icc; |
3287 | tmp.icc = 0; |
3288 | dirty = true; |
3289 | - _fixupHit( 0, this ); |
3290 | - } else { |
3291 | + _fixupHit(0, this); |
3292 | + } |
3293 | + else { |
3294 | #ifdef DEBUG_LCMS |
3295 | - g_message("No icc to nuke"); |
3296 | + g_message("No icc to nuke"); |
3297 | #endif // DEBUG_LCMS |
3298 | } |
3299 | } |
3300 | |
3301 | - if ( dirty ) { |
3302 | + if (dirty) { |
3303 | #ifdef DEBUG_LCMS |
3304 | g_message("+----------------"); |
3305 | g_message("+ new color is [%s]", tmp.toString().c_str()); |
3306 | #endif // DEBUG_LCMS |
3307 | - _setProfile( tmp.icc ); |
3308 | + _setProfile(tmp.icc); |
3309 | //_adjustmentChanged( _compUI[0]._adj, SP_COLOR_ICC_SELECTOR(_csel) ); |
3310 | - _owner->setColorAlpha( tmp, _owner->_alpha, true ); |
3311 | + _color.setColor(tmp); |
3312 | #ifdef DEBUG_LCMS |
3313 | g_message("+_________________"); |
3314 | #endif // DEBUG_LCMS |
3315 | @@ -727,45 +657,43 @@ |
3316 | #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3317 | |
3318 | #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3319 | -void ColorICCSelectorImpl::_profilesChanged( std::string const & name ) |
3320 | +void ColorICCSelectorImpl::_profilesChanged(std::string const &name) |
3321 | { |
3322 | - GtkComboBox* combo = GTK_COMBO_BOX(_profileSel); |
3323 | + GtkComboBox *combo = GTK_COMBO_BOX(_profileSel); |
3324 | |
3325 | - g_signal_handler_block( G_OBJECT(_profileSel), _profChangedID ); |
3326 | + g_signal_handler_block(G_OBJECT(_profileSel), _profChangedID); |
3327 | |
3328 | GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(combo)); |
3329 | gtk_list_store_clear(store); |
3330 | |
3331 | GtkTreeIter iter; |
3332 | - gtk_list_store_append (store, &iter); |
3333 | + gtk_list_store_append(store, &iter); |
3334 | gtk_list_store_set(store, &iter, 0, _("<none>"), 1, _("<none>"), -1); |
3335 | |
3336 | - gtk_combo_box_set_active( combo, 0 ); |
3337 | + gtk_combo_box_set_active(combo, 0); |
3338 | |
3339 | int index = 1; |
3340 | - const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "iccprofile" ); |
3341 | - while ( current ) { |
3342 | - SPObject* obj = SP_OBJECT(current->data); |
3343 | - Inkscape::ColorProfile* prof = reinterpret_cast<Inkscape::ColorProfile*>(obj); |
3344 | + const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList("iccprofile"); |
3345 | + while (current) { |
3346 | + SPObject *obj = SP_OBJECT(current->data); |
3347 | + Inkscape::ColorProfile *prof = reinterpret_cast<Inkscape::ColorProfile *>(obj); |
3348 | |
3349 | - gtk_list_store_append (store, &iter); |
3350 | + gtk_list_store_append(store, &iter); |
3351 | gtk_list_store_set(store, &iter, 0, gr_ellipsize_text(prof->name, 25).c_str(), 1, prof->name, -1); |
3352 | |
3353 | - if ( name == prof->name ) { |
3354 | - gtk_combo_box_set_active( combo, index ); |
3355 | - gtk_widget_set_tooltip_text(_profileSel, prof->name ); |
3356 | + if (name == prof->name) { |
3357 | + gtk_combo_box_set_active(combo, index); |
3358 | + gtk_widget_set_tooltip_text(_profileSel, prof->name); |
3359 | } |
3360 | |
3361 | index++; |
3362 | current = g_slist_next(current); |
3363 | } |
3364 | |
3365 | - g_signal_handler_unblock( G_OBJECT(_profileSel), _profChangedID ); |
3366 | + g_signal_handler_unblock(G_OBJECT(_profileSel), _profChangedID); |
3367 | } |
3368 | #else |
3369 | -void ColorICCSelectorImpl::_profilesChanged( std::string const & /*name*/ ) |
3370 | -{ |
3371 | -} |
3372 | +void ColorICCSelectorImpl::_profilesChanged(std::string const & /*name*/) {} |
3373 | #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3374 | |
3375 | // Helpers for setting color value |
3376 | @@ -773,192 +701,200 @@ |
3377 | void ColorICCSelector::_colorChanged() |
3378 | { |
3379 | _impl->_updating = TRUE; |
3380 | - //sp_color_icc_set_color( SP_COLOR_ICC( _icc ), &color ); |
3381 | - |
3382 | -#ifdef DEBUG_LCMS |
3383 | - g_message( "/^^^^^^^^^ %p::_colorChanged(%08x:%s)", this, |
3384 | - _color.toRGBA32(_alpha), ( (_color.icc) ? _color.icc->colorProfile.c_str(): "<null>" ) |
3385 | - ); |
3386 | -#endif // DEBUG_LCMS |
3387 | - |
3388 | -#ifdef DEBUG_LCMS |
3389 | - g_message("FLIPPIES!!!! %p '%s'", _color.icc, (_color.icc ? _color.icc->colorProfile.c_str():"<null>")); |
3390 | -#endif // DEBUG_LCMS |
3391 | - |
3392 | - _impl->_profilesChanged( (_color.icc) ? _color.icc->colorProfile : std::string("") ); |
3393 | - ColorScales::setScaled( _impl->_adj, _alpha ); |
3394 | +// sp_color_icc_set_color( SP_COLOR_ICC( _icc ), &color ); |
3395 | + |
3396 | +#ifdef DEBUG_LCMS |
3397 | + g_message("/^^^^^^^^^ %p::_colorChanged(%08x:%s)", this, _impl->_color.color().toRGBA32(_impl->_color.alpha()), |
3398 | + ((_impl->_color.color().icc) ? _impl->_color.color().icc->colorProfile.c_str() : "<null>")); |
3399 | +#endif // DEBUG_LCMS |
3400 | + |
3401 | +#ifdef DEBUG_LCMS |
3402 | + g_message("FLIPPIES!!!! %p '%s'", _impl->_color.color().icc, |
3403 | + (_impl->_color.color().icc ? _impl->_color.color().icc->colorProfile.c_str() : "<null>")); |
3404 | +#endif // DEBUG_LCMS |
3405 | + |
3406 | + _impl->_profilesChanged((_impl->_color.color().icc) ? _impl->_color.color().icc->colorProfile : std::string("")); |
3407 | + ColorScales::setScaled(_impl->_adj, _impl->_color.alpha()); |
3408 | |
3409 | #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3410 | - _impl->_setProfile( _color.icc ); |
3411 | + _impl->_setProfile(_impl->_color.color().icc); |
3412 | _impl->_fixupNeeded = 0; |
3413 | - gtk_widget_set_sensitive( _impl->_fixupBtn, FALSE ); |
3414 | + gtk_widget_set_sensitive(_impl->_fixupBtn, FALSE); |
3415 | |
3416 | if (_impl->_prof) { |
3417 | - if (_impl->_prof->getTransfToSRGB8() ) { |
3418 | + if (_impl->_prof->getTransfToSRGB8()) { |
3419 | cmsUInt16Number tmp[4]; |
3420 | - for ( guint i = 0; i < _impl->_profChannelCount; i++ ) { |
3421 | + for (guint i = 0; i < _impl->_profChannelCount; i++) { |
3422 | gdouble val = 0.0; |
3423 | - if ( _color.icc->colors.size() > i ) { |
3424 | - if ( _impl->_compUI[i]._component.scale == 256 ) { |
3425 | - val = (_color.icc->colors[i] + 128.0) / static_cast<gdouble>(_impl->_compUI[i]._component.scale); |
3426 | - } else { |
3427 | - val = _color.icc->colors[i] / static_cast<gdouble>(_impl->_compUI[i]._component.scale); |
3428 | + if (_impl->_color.color().icc->colors.size() > i) { |
3429 | + if (_impl->_compUI[i]._component.scale == 256) { |
3430 | + val = (_impl->_color.color().icc->colors[i] + 128.0) / |
3431 | + static_cast<gdouble>(_impl->_compUI[i]._component.scale); |
3432 | + } |
3433 | + else { |
3434 | + val = _impl->_color.color().icc->colors[i] / |
3435 | + static_cast<gdouble>(_impl->_compUI[i]._component.scale); |
3436 | } |
3437 | } |
3438 | tmp[i] = val * 0x0ffff; |
3439 | } |
3440 | - guchar post[4] = {0,0,0,0}; |
3441 | + guchar post[4] = { 0, 0, 0, 0 }; |
3442 | cmsHTRANSFORM trans = _impl->_prof->getTransfToSRGB8(); |
3443 | - if ( trans ) { |
3444 | - cmsDoTransform( trans, tmp, post, 1 ); |
3445 | - guint32 other = SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255 ); |
3446 | - if ( other != _color.toRGBA32(255) ) { |
3447 | + if (trans) { |
3448 | + cmsDoTransform(trans, tmp, post, 1); |
3449 | + guint32 other = SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255); |
3450 | + if (other != _impl->_color.color().toRGBA32(255)) { |
3451 | _impl->_fixupNeeded = other; |
3452 | - gtk_widget_set_sensitive( _impl->_fixupBtn, TRUE ); |
3453 | + gtk_widget_set_sensitive(_impl->_fixupBtn, TRUE); |
3454 | #ifdef DEBUG_LCMS |
3455 | - g_message("Color needs to change 0x%06x to 0x%06x", _color.toRGBA32(255) >> 8, other >> 8 ); |
3456 | + g_message("Color needs to change 0x%06x to 0x%06x", _color.toRGBA32(255) >> 8, other >> 8); |
3457 | #endif // DEBUG_LCMS |
3458 | } |
3459 | } |
3460 | } |
3461 | } |
3462 | #else |
3463 | - //(void)color; |
3464 | +//(void)color; |
3465 | #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3466 | - _impl->_updateSliders( -1 ); |
3467 | + _impl->_updateSliders(-1); |
3468 | |
3469 | |
3470 | _impl->_updating = FALSE; |
3471 | #ifdef DEBUG_LCMS |
3472 | - g_message( "\\_________ %p::_colorChanged()", this ); |
3473 | + g_message("\\_________ %p::_colorChanged()", this); |
3474 | #endif // DEBUG_LCMS |
3475 | } |
3476 | |
3477 | #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3478 | -void ColorICCSelectorImpl::_setProfile( SVGICCColor* profile ) |
3479 | +void ColorICCSelectorImpl::_setProfile(SVGICCColor *profile) |
3480 | { |
3481 | #ifdef DEBUG_LCMS |
3482 | - g_message( "/^^^^^^^^^ %p::_setProfile(%s)", this, |
3483 | - ( (profile) ? profile->colorProfile.c_str() : "<null>") |
3484 | - ); |
3485 | + g_message("/^^^^^^^^^ %p::_setProfile(%s)", this, ((profile) ? profile->colorProfile.c_str() : "<null>")); |
3486 | #endif // DEBUG_LCMS |
3487 | bool profChanged = false; |
3488 | - if ( _prof && (!profile || (_profileName != profile->colorProfile) ) ) { |
3489 | + if (_prof && (!profile || (_profileName != profile->colorProfile))) { |
3490 | // Need to clear out the prior one |
3491 | profChanged = true; |
3492 | _profileName.clear(); |
3493 | _prof = 0; |
3494 | _profChannelCount = 0; |
3495 | - } else if ( profile && !_prof ) { |
3496 | + } |
3497 | + else if (profile && !_prof) { |
3498 | profChanged = true; |
3499 | } |
3500 | |
3501 | - for ( size_t i = 0; i < _compUI.size(); i++ ) { |
3502 | - gtk_widget_hide( _compUI[i]._label ); |
3503 | - gtk_widget_hide( _compUI[i]._slider ); |
3504 | - gtk_widget_hide( _compUI[i]._btn ); |
3505 | + for (size_t i = 0; i < _compUI.size(); i++) { |
3506 | + gtk_widget_hide(_compUI[i]._label); |
3507 | + _compUI[i]._slider->hide(); |
3508 | + gtk_widget_hide(_compUI[i]._btn); |
3509 | } |
3510 | |
3511 | - if ( profile ) { |
3512 | + if (profile) { |
3513 | _prof = SP_ACTIVE_DOCUMENT->profileManager->find(profile->colorProfile.c_str()); |
3514 | - if ( _prof && (asICColorProfileClassSig(_prof->getProfileClass()) != cmsSigNamedColorClass) ) { |
3515 | + if (_prof && (asICColorProfileClassSig(_prof->getProfileClass()) != cmsSigNamedColorClass)) { |
3516 | #if HAVE_LIBLCMS1 |
3517 | - _profChannelCount = _cmsChannelsOf( asICColorSpaceSig(_prof->getColorSpace()) ); |
3518 | + _profChannelCount = _cmsChannelsOf(asICColorSpaceSig(_prof->getColorSpace())); |
3519 | #elif HAVE_LIBLCMS2 |
3520 | - _profChannelCount = cmsChannelsOf( asICColorSpaceSig(_prof->getColorSpace()) ); |
3521 | + _profChannelCount = cmsChannelsOf(asICColorSpaceSig(_prof->getColorSpace())); |
3522 | #endif |
3523 | |
3524 | - if ( profChanged ) { |
3525 | - std::vector<colorspace::Component> things = colorspace::getColorSpaceInfo(asICColorSpaceSig(_prof->getColorSpace())); |
3526 | - for (size_t i = 0; (i < things.size()) && (i < _profChannelCount); ++i) |
3527 | - { |
3528 | + if (profChanged) { |
3529 | + std::vector<colorspace::Component> things = |
3530 | + colorspace::getColorSpaceInfo(asICColorSpaceSig(_prof->getColorSpace())); |
3531 | + for (size_t i = 0; (i < things.size()) && (i < _profChannelCount); ++i) { |
3532 | _compUI[i]._component = things[i]; |
3533 | } |
3534 | |
3535 | - for ( guint i = 0; i < _profChannelCount; i++ ) { |
3536 | - gtk_label_set_text_with_mnemonic( GTK_LABEL(_compUI[i]._label), (i < things.size()) ? things[i].name.c_str() : ""); |
3537 | - |
3538 | - gtk_widget_set_tooltip_text( _compUI[i]._slider, (i < things.size()) ? things[i].tip.c_str() : "" ); |
3539 | - gtk_widget_set_tooltip_text( _compUI[i]._btn, (i < things.size()) ? things[i].tip.c_str() : "" ); |
3540 | - |
3541 | - sp_color_slider_set_colors( SP_COLOR_SLIDER(_compUI[i]._slider), |
3542 | - SPColor(0.0, 0.0, 0.0).toRGBA32(0xff), |
3543 | - SPColor(0.5, 0.5, 0.5).toRGBA32(0xff), |
3544 | - SPColor(1.0, 1.0, 1.0).toRGBA32(0xff) ); |
3545 | -/* |
3546 | - _compUI[i]._adj = GTK_ADJUSTMENT( gtk_adjustment_new( val, 0.0, _fooScales[i], step, page, page ) ); |
3547 | - g_signal_connect( G_OBJECT( _compUI[i]._adj ), "value_changed", G_CALLBACK( _adjustmentChanged ), _csel ); |
3548 | - |
3549 | - sp_color_slider_set_adjustment( SP_COLOR_SLIDER(_compUI[i]._slider), _compUI[i]._adj ); |
3550 | - gtk_spin_button_set_adjustment( GTK_SPIN_BUTTON(_compUI[i]._btn), _compUI[i]._adj ); |
3551 | - gtk_spin_button_set_digits( GTK_SPIN_BUTTON(_compUI[i]._btn), digits ); |
3552 | -*/ |
3553 | - gtk_widget_show( _compUI[i]._label ); |
3554 | - gtk_widget_show( _compUI[i]._slider ); |
3555 | - gtk_widget_show( _compUI[i]._btn ); |
3556 | - //gtk_adjustment_set_value( _compUI[i]._adj, 0.0 ); |
3557 | - //gtk_adjustment_set_value( _compUI[i]._adj, val ); |
3558 | + for (guint i = 0; i < _profChannelCount; i++) { |
3559 | + gtk_label_set_text_with_mnemonic(GTK_LABEL(_compUI[i]._label), |
3560 | + (i < things.size()) ? things[i].name.c_str() : ""); |
3561 | + |
3562 | + _compUI[i]._slider->set_tooltip_text((i < things.size()) ? things[i].tip.c_str() : ""); |
3563 | + gtk_widget_set_tooltip_text(_compUI[i]._btn, (i < things.size()) ? things[i].tip.c_str() : ""); |
3564 | + |
3565 | + _compUI[i]._slider->setColors(SPColor(0.0, 0.0, 0.0).toRGBA32(0xff), |
3566 | + SPColor(0.5, 0.5, 0.5).toRGBA32(0xff), |
3567 | + SPColor(1.0, 1.0, 1.0).toRGBA32(0xff)); |
3568 | + /* |
3569 | + _compUI[i]._adj = GTK_ADJUSTMENT( gtk_adjustment_new( val, 0.0, _fooScales[i], |
3570 | + step, page, page ) ); |
3571 | + g_signal_connect( G_OBJECT( _compUI[i]._adj ), "value_changed", G_CALLBACK( |
3572 | + _adjustmentChanged ), _csel ); |
3573 | + |
3574 | + sp_color_slider_set_adjustment( SP_COLOR_SLIDER(_compUI[i]._slider), |
3575 | + _compUI[i]._adj ); |
3576 | + gtk_spin_button_set_adjustment( GTK_SPIN_BUTTON(_compUI[i]._btn), |
3577 | + _compUI[i]._adj ); |
3578 | + gtk_spin_button_set_digits( GTK_SPIN_BUTTON(_compUI[i]._btn), digits ); |
3579 | + */ |
3580 | + gtk_widget_show(_compUI[i]._label); |
3581 | + _compUI[i]._slider->show(); |
3582 | + gtk_widget_show(_compUI[i]._btn); |
3583 | + // gtk_adjustment_set_value( _compUI[i]._adj, 0.0 ); |
3584 | + // gtk_adjustment_set_value( _compUI[i]._adj, val ); |
3585 | } |
3586 | - for ( size_t i = _profChannelCount; i < _compUI.size(); i++ ) { |
3587 | - gtk_widget_hide( _compUI[i]._label ); |
3588 | - gtk_widget_hide( _compUI[i]._slider ); |
3589 | - gtk_widget_hide( _compUI[i]._btn ); |
3590 | + for (size_t i = _profChannelCount; i < _compUI.size(); i++) { |
3591 | + gtk_widget_hide(_compUI[i]._label); |
3592 | + _compUI[i]._slider->hide(); |
3593 | + gtk_widget_hide(_compUI[i]._btn); |
3594 | } |
3595 | } |
3596 | - } else { |
3597 | + } |
3598 | + else { |
3599 | // Give up for now on named colors |
3600 | _prof = 0; |
3601 | } |
3602 | } |
3603 | |
3604 | #ifdef DEBUG_LCMS |
3605 | - g_message( "\\_________ %p::_setProfile()", this ); |
3606 | + g_message("\\_________ %p::_setProfile()", this); |
3607 | #endif // DEBUG_LCMS |
3608 | } |
3609 | #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3610 | |
3611 | -void ColorICCSelectorImpl::_updateSliders( gint ignore ) |
3612 | +void ColorICCSelectorImpl::_updateSliders(gint ignore) |
3613 | { |
3614 | #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3615 | - if ( _owner->_color.icc ) |
3616 | - { |
3617 | - for ( guint i = 0; i < _profChannelCount; i++ ) { |
3618 | + if (_color.color().icc) { |
3619 | + for (guint i = 0; i < _profChannelCount; i++) { |
3620 | gdouble val = 0.0; |
3621 | - if ( _owner->_color.icc->colors.size() > i ) { |
3622 | - if ( _compUI[i]._component.scale == 256 ) { |
3623 | - val = (_owner->_color.icc->colors[i] + 128.0) / static_cast<gdouble>(_compUI[i]._component.scale); |
3624 | - } else { |
3625 | - val = _owner->_color.icc->colors[i] / static_cast<gdouble>(_compUI[i]._component.scale); |
3626 | + if (_color.color().icc->colors.size() > i) { |
3627 | + if (_compUI[i]._component.scale == 256) { |
3628 | + val = (_color.color().icc->colors[i] + 128.0) / static_cast<gdouble>(_compUI[i]._component.scale); |
3629 | + } |
3630 | + else { |
3631 | + val = _color.color().icc->colors[i] / static_cast<gdouble>(_compUI[i]._component.scale); |
3632 | } |
3633 | } |
3634 | - gtk_adjustment_set_value( _compUI[i]._adj, val ); |
3635 | + gtk_adjustment_set_value(_compUI[i]._adj, val); |
3636 | } |
3637 | |
3638 | - if ( _prof ) { |
3639 | - if ( _prof->getTransfToSRGB8() ) { |
3640 | - for ( guint i = 0; i < _profChannelCount; i++ ) { |
3641 | - if ( static_cast<gint>(i) != ignore ) { |
3642 | - cmsUInt16Number* scratch = getScratch(); |
3643 | - cmsUInt16Number filler[4] = {0, 0, 0, 0}; |
3644 | - for ( guint j = 0; j < _profChannelCount; j++ ) { |
3645 | - filler[j] = 0x0ffff * ColorScales::getScaled( _compUI[j]._adj ); |
3646 | + if (_prof) { |
3647 | + if (_prof->getTransfToSRGB8()) { |
3648 | + for (guint i = 0; i < _profChannelCount; i++) { |
3649 | + if (static_cast<gint>(i) != ignore) { |
3650 | + cmsUInt16Number *scratch = getScratch(); |
3651 | + cmsUInt16Number filler[4] = { 0, 0, 0, 0 }; |
3652 | + for (guint j = 0; j < _profChannelCount; j++) { |
3653 | + filler[j] = 0x0ffff * ColorScales::getScaled(_compUI[j]._adj); |
3654 | } |
3655 | - |
3656 | - cmsUInt16Number* p = scratch; |
3657 | - for ( guint x = 0; x < 1024; x++ ) { |
3658 | - for ( guint j = 0; j < _profChannelCount; j++ ) { |
3659 | - if ( j == i ) { |
3660 | + |
3661 | + cmsUInt16Number *p = scratch; |
3662 | + for (guint x = 0; x < 1024; x++) { |
3663 | + for (guint j = 0; j < _profChannelCount; j++) { |
3664 | + if (j == i) { |
3665 | *p++ = x * 0x0ffff / 1024; |
3666 | - } else { |
3667 | + } |
3668 | + else { |
3669 | *p++ = filler[j]; |
3670 | } |
3671 | } |
3672 | } |
3673 | - |
3674 | + |
3675 | cmsHTRANSFORM trans = _prof->getTransfToSRGB8(); |
3676 | - if ( trans ) { |
3677 | - cmsDoTransform( trans, scratch, _compUI[i]._map, 1024 ); |
3678 | - sp_color_slider_set_map( SP_COLOR_SLIDER(_compUI[i]._slider), _compUI[i]._map ); |
3679 | + if (trans) { |
3680 | + cmsDoTransform(trans, scratch, _compUI[i]._map, 1024); |
3681 | + _compUI[i]._slider->setMap(_compUI[i]._map); |
3682 | } |
3683 | } |
3684 | } |
3685 | @@ -969,15 +905,15 @@ |
3686 | (void)ignore; |
3687 | #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3688 | |
3689 | - guint32 start = _owner->_color.toRGBA32( 0x00 ); |
3690 | - guint32 mid = _owner->_color.toRGBA32( 0x7f ); |
3691 | - guint32 end = _owner->_color.toRGBA32( 0xff ); |
3692 | + guint32 start = _color.color().toRGBA32(0x00); |
3693 | + guint32 mid = _color.color().toRGBA32(0x7f); |
3694 | + guint32 end = _color.color().toRGBA32(0xff); |
3695 | |
3696 | - sp_color_slider_set_colors( SP_COLOR_SLIDER(_slider), start, mid, end ); |
3697 | + _slider->setColors(start, mid, end); |
3698 | } |
3699 | |
3700 | |
3701 | -void ColorICCSelectorImpl::_adjustmentChanged( GtkAdjustment *adjustment, SPColorICCSelector *cs ) |
3702 | +void ColorICCSelectorImpl::_adjustmentChanged(GtkAdjustment *adjustment, ColorICCSelectorImpl *cs) |
3703 | { |
3704 | // // TODO check this. It looks questionable: |
3705 | // // if a value is entered between 0 and 1 exclusive, normalize it to (int) 0..255 or 0..100 |
3706 | @@ -986,121 +922,135 @@ |
3707 | // } |
3708 | |
3709 | #ifdef DEBUG_LCMS |
3710 | - g_message( "/^^^^^^^^^ %p::_adjustmentChanged()", cs ); |
3711 | + g_message("/^^^^^^^^^ %p::_adjustmentChanged()", cs); |
3712 | #endif // DEBUG_LCMS |
3713 | |
3714 | - ColorICCSelector* iccSelector = static_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base); |
3715 | - if (iccSelector->_impl->_updating) { |
3716 | - return; |
3717 | - } |
3718 | - |
3719 | - iccSelector->_impl->_updating = TRUE; |
3720 | - |
3721 | - gint match = -1; |
3722 | - |
3723 | - SPColor newColor( iccSelector->_color ); |
3724 | - gfloat scaled = ColorScales::getScaled( iccSelector->_impl->_adj ); |
3725 | - if ( iccSelector->_impl->_adj == adjustment ) { |
3726 | + ColorICCSelector *iccSelector = cs->_owner; |
3727 | + if (iccSelector->_impl->_updating) { |
3728 | + return; |
3729 | + } |
3730 | + |
3731 | + iccSelector->_impl->_updating = TRUE; |
3732 | + |
3733 | + gint match = -1; |
3734 | + |
3735 | + SPColor newColor(iccSelector->_impl->_color.color()); |
3736 | + gfloat scaled = ColorScales::getScaled(iccSelector->_impl->_adj); |
3737 | + if (iccSelector->_impl->_adj == adjustment) { |
3738 | #ifdef DEBUG_LCMS |
3739 | - g_message("ALPHA"); |
3740 | + g_message("ALPHA"); |
3741 | #endif // DEBUG_LCMS |
3742 | - } else { |
3743 | + } |
3744 | + else { |
3745 | #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3746 | - for ( size_t i = 0; i < iccSelector->_impl->_compUI.size(); i++ ) { |
3747 | - if ( iccSelector->_impl->_compUI[i]._adj == adjustment ) { |
3748 | - match = i; |
3749 | - break; |
3750 | - } |
3751 | - } |
3752 | - if ( match >= 0 ) { |
3753 | -#ifdef DEBUG_LCMS |
3754 | - g_message(" channel %d", match ); |
3755 | -#endif // DEBUG_LCMS |
3756 | - } |
3757 | - |
3758 | - |
3759 | - cmsUInt16Number tmp[4]; |
3760 | - for ( guint i = 0; i < 4; i++ ) { |
3761 | - tmp[i] = ColorScales::getScaled( iccSelector->_impl->_compUI[i]._adj ) * 0x0ffff; |
3762 | - } |
3763 | - guchar post[4] = {0,0,0,0}; |
3764 | - |
3765 | - cmsHTRANSFORM trans = iccSelector->_impl->_prof->getTransfToSRGB8(); |
3766 | - if ( trans ) { |
3767 | - cmsDoTransform( trans, tmp, post, 1 ); |
3768 | - } |
3769 | - |
3770 | - SPColor other( SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255) ); |
3771 | - other.icc = new SVGICCColor(); |
3772 | - if ( iccSelector->_color.icc ) { |
3773 | - other.icc->colorProfile = iccSelector->_color.icc->colorProfile; |
3774 | - } |
3775 | - |
3776 | - guint32 prior = iccSelector->_color.toRGBA32(255); |
3777 | - guint32 newer = other.toRGBA32(255); |
3778 | - |
3779 | - if ( prior != newer ) { |
3780 | -#ifdef DEBUG_LCMS |
3781 | - g_message("Transformed color from 0x%08x to 0x%08x", prior, newer ); |
3782 | - g_message(" ~~~~ FLIP"); |
3783 | -#endif // DEBUG_LCMS |
3784 | - newColor = other; |
3785 | - newColor.icc->colors.clear(); |
3786 | - for ( guint i = 0; i < iccSelector->_impl->_profChannelCount; i++ ) { |
3787 | - gdouble val = ColorScales::getScaled( iccSelector->_impl->_compUI[i]._adj ); |
3788 | - val *= iccSelector->_impl->_compUI[i]._component.scale; |
3789 | - if ( iccSelector->_impl->_compUI[i]._component.scale == 256 ) { |
3790 | - val -= 128; |
3791 | - } |
3792 | - newColor.icc->colors.push_back( val ); |
3793 | - } |
3794 | - } |
3795 | + for (size_t i = 0; i < iccSelector->_impl->_compUI.size(); i++) { |
3796 | + if (iccSelector->_impl->_compUI[i]._adj == adjustment) { |
3797 | + match = i; |
3798 | + break; |
3799 | + } |
3800 | + } |
3801 | + if (match >= 0) { |
3802 | +#ifdef DEBUG_LCMS |
3803 | + g_message(" channel %d", match); |
3804 | +#endif // DEBUG_LCMS |
3805 | + } |
3806 | + |
3807 | + |
3808 | + cmsUInt16Number tmp[4]; |
3809 | + for (guint i = 0; i < 4; i++) { |
3810 | + tmp[i] = ColorScales::getScaled(iccSelector->_impl->_compUI[i]._adj) * 0x0ffff; |
3811 | + } |
3812 | + guchar post[4] = { 0, 0, 0, 0 }; |
3813 | + |
3814 | + cmsHTRANSFORM trans = iccSelector->_impl->_prof->getTransfToSRGB8(); |
3815 | + if (trans) { |
3816 | + cmsDoTransform(trans, tmp, post, 1); |
3817 | + } |
3818 | + |
3819 | + SPColor other(SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255)); |
3820 | + other.icc = new SVGICCColor(); |
3821 | + if (iccSelector->_impl->_color.color().icc) { |
3822 | + other.icc->colorProfile = iccSelector->_impl->_color.color().icc->colorProfile; |
3823 | + } |
3824 | + |
3825 | + guint32 prior = iccSelector->_impl->_color.color().toRGBA32(255); |
3826 | + guint32 newer = other.toRGBA32(255); |
3827 | + |
3828 | + if (prior != newer) { |
3829 | +#ifdef DEBUG_LCMS |
3830 | + g_message("Transformed color from 0x%08x to 0x%08x", prior, newer); |
3831 | + g_message(" ~~~~ FLIP"); |
3832 | +#endif // DEBUG_LCMS |
3833 | + newColor = other; |
3834 | + newColor.icc->colors.clear(); |
3835 | + for (guint i = 0; i < iccSelector->_impl->_profChannelCount; i++) { |
3836 | + gdouble val = ColorScales::getScaled(iccSelector->_impl->_compUI[i]._adj); |
3837 | + val *= iccSelector->_impl->_compUI[i]._component.scale; |
3838 | + if (iccSelector->_impl->_compUI[i]._component.scale == 256) { |
3839 | + val -= 128; |
3840 | + } |
3841 | + newColor.icc->colors.push_back(val); |
3842 | + } |
3843 | + } |
3844 | #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
3845 | - } |
3846 | - iccSelector->_updateInternals( newColor, scaled, iccSelector->_impl->_dragging ); |
3847 | - iccSelector->_impl->_updateSliders( match ); |
3848 | + } |
3849 | + iccSelector->_impl->_color.setColorAlpha(newColor, scaled); |
3850 | + // iccSelector->_updateInternals( newColor, scaled, iccSelector->_impl->_dragging ); |
3851 | + iccSelector->_impl->_updateSliders(match); |
3852 | |
3853 | - iccSelector->_impl->_updating = FALSE; |
3854 | + iccSelector->_impl->_updating = FALSE; |
3855 | #ifdef DEBUG_LCMS |
3856 | - g_message( "\\_________ %p::_adjustmentChanged()", cs ); |
3857 | + g_message("\\_________ %p::_adjustmentChanged()", cs); |
3858 | #endif // DEBUG_LCMS |
3859 | } |
3860 | |
3861 | -void ColorICCSelectorImpl::_sliderGrabbed( SPColorSlider * /*slider*/, SPColorICCSelector * /*cs*/ ) |
3862 | +void ColorICCSelectorImpl::_sliderGrabbed() |
3863 | { |
3864 | -// ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base); |
3865 | -// if (!iccSelector->_dragging) { |
3866 | -// iccSelector->_dragging = TRUE; |
3867 | -// iccSelector->_grabbed(); |
3868 | -// iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_impl->_adj ), iccSelector->_dragging ); |
3869 | -// } |
3870 | + // ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base); |
3871 | + // if (!iccSelector->_dragging) { |
3872 | + // iccSelector->_dragging = TRUE; |
3873 | + // iccSelector->_grabbed(); |
3874 | + // iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_impl->_adj ), |
3875 | + // iccSelector->_dragging ); |
3876 | + // } |
3877 | } |
3878 | |
3879 | -void ColorICCSelectorImpl::_sliderReleased( SPColorSlider * /*slider*/, SPColorICCSelector * /*cs*/ ) |
3880 | +void ColorICCSelectorImpl::_sliderReleased() |
3881 | { |
3882 | -// ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base); |
3883 | -// if (iccSelector->_dragging) { |
3884 | -// iccSelector->_dragging = FALSE; |
3885 | -// iccSelector->_released(); |
3886 | -// iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_adj ), iccSelector->_dragging ); |
3887 | -// } |
3888 | + // ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base); |
3889 | + // if (iccSelector->_dragging) { |
3890 | + // iccSelector->_dragging = FALSE; |
3891 | + // iccSelector->_released(); |
3892 | + // iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_adj ), |
3893 | + // iccSelector->_dragging ); |
3894 | + // } |
3895 | } |
3896 | |
3897 | #ifdef DEBUG_LCMS |
3898 | -void ColorICCSelectorImpl::_sliderChanged( SPColorSlider *slider, SPColorICCSelector *cs ) |
3899 | +void ColorICCSelectorImpl::_sliderChanged(SPColorSlider *slider, SPColorICCSelector *cs) |
3900 | #else |
3901 | -void ColorICCSelectorImpl::_sliderChanged( SPColorSlider * /*slider*/, SPColorICCSelector * /*cs*/ ) |
3902 | +void ColorICCSelectorImpl::_sliderChanged() |
3903 | #endif // DEBUG_LCMS |
3904 | { |
3905 | #ifdef DEBUG_LCMS |
3906 | - g_message("Changed %p and %p", slider, cs ); |
3907 | + g_message("Changed %p and %p", slider, cs); |
3908 | #endif // DEBUG_LCMS |
3909 | -// ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base); |
3910 | - |
3911 | -// iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_adj ), iccSelector->_dragging ); |
3912 | -} |
3913 | - |
3914 | - |
3915 | + // ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base); |
3916 | + |
3917 | + // iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_adj ), |
3918 | + // iccSelector->_dragging ); |
3919 | +} |
3920 | + |
3921 | +Gtk::Widget *ColorICCSelectorFactory::createWidget(Inkscape::UI::SelectedColor &color) const |
3922 | +{ |
3923 | + Gtk::Widget *w = Gtk::manage(new ColorICCSelector(color)); |
3924 | + return w; |
3925 | +} |
3926 | + |
3927 | +Glib::ustring ColorICCSelectorFactory::modeName() const { return gettext(ColorICCSelector::MODE_NAME); } |
3928 | +} |
3929 | +} |
3930 | +} |
3931 | /* |
3932 | Local Variables: |
3933 | mode:c++ |
3934 | |
3935 | === renamed file 'src/widgets/sp-color-icc-selector.h' => 'src/ui/widget/color-icc-selector.h' |
3936 | --- src/widgets/sp-color-icc-selector.h 2014-10-08 02:22:03 +0000 |
3937 | +++ src/ui/widget/color-icc-selector.h 2015-05-03 11:19:29 +0000 |
3938 | @@ -1,63 +1,67 @@ |
3939 | #ifndef SEEN_SP_COLOR_ICC_SELECTOR_H |
3940 | #define SEEN_SP_COLOR_ICC_SELECTOR_H |
3941 | |
3942 | -#include <glib.h> |
3943 | -#include "sp-color-selector.h" |
3944 | +#ifdef HAVE_CONFIG_H |
3945 | +#include <config.h> |
3946 | +#endif |
3947 | + |
3948 | +#include <gtkmm/widget.h> |
3949 | +#if WITH_GTKMM_3_0 |
3950 | +#include <gtkmm/grid.h> |
3951 | +#else |
3952 | +#include <gtkmm/table.h> |
3953 | +#endif |
3954 | + |
3955 | +#include "ui/selected-color.h" |
3956 | |
3957 | namespace Inkscape { |
3958 | + |
3959 | class ColorProfile; |
3960 | -} |
3961 | |
3962 | -struct SPColorICCSelector; |
3963 | -struct SPColorICCSelectorClass; |
3964 | +namespace UI { |
3965 | +namespace Widget { |
3966 | |
3967 | class ColorICCSelectorImpl; |
3968 | |
3969 | -class ColorICCSelector: public ColorSelector |
3970 | -{ |
3971 | -public: |
3972 | - ColorICCSelector( SPColorSelector* csel ); |
3973 | +class ColorICCSelector |
3974 | +#if GTK_CHECK_VERSION(3, 0, 0) |
3975 | + : public Gtk::Grid |
3976 | +#else |
3977 | + : public Gtk::Table |
3978 | +#endif |
3979 | + { |
3980 | + public: |
3981 | + static const gchar *MODE_NAME; |
3982 | + |
3983 | + ColorICCSelector(SelectedColor &color); |
3984 | virtual ~ColorICCSelector(); |
3985 | |
3986 | virtual void init(); |
3987 | |
3988 | -protected: |
3989 | + protected: |
3990 | virtual void _colorChanged(); |
3991 | |
3992 | - void _recalcColor( gboolean changing ); |
3993 | + void _recalcColor(gboolean changing); |
3994 | |
3995 | -private: |
3996 | + private: |
3997 | friend class ColorICCSelectorImpl; |
3998 | |
3999 | // By default, disallow copy constructor and assignment operator |
4000 | - ColorICCSelector( const ColorICCSelector& obj ); |
4001 | - ColorICCSelector& operator=( const ColorICCSelector& obj ); |
4002 | + ColorICCSelector(const ColorICCSelector &obj); |
4003 | + ColorICCSelector &operator=(const ColorICCSelector &obj); |
4004 | |
4005 | ColorICCSelectorImpl *_impl; |
4006 | }; |
4007 | |
4008 | |
4009 | - |
4010 | -#define SP_TYPE_COLOR_ICC_SELECTOR (sp_color_icc_selector_get_type()) |
4011 | -#define SP_COLOR_ICC_SELECTOR(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_COLOR_ICC_SELECTOR, SPColorICCSelector)) |
4012 | -#define SP_COLOR_ICC_SELECTOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), SP_TYPE_COLOR_ICC_SELECTOR, SPColorICCSelectorClass)) |
4013 | -#define SP_IS_COLOR_ICC_SELECTOR(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SP_TYPE_COLOR_ICC_SELECTOR)) |
4014 | -#define SP_IS_COLOR_ICC_SELECTOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), SP_TYPE_COLOR_ICC_SELECTOR)) |
4015 | - |
4016 | -struct SPColorICCSelector { |
4017 | - SPColorSelector parent; |
4018 | -}; |
4019 | - |
4020 | -struct SPColorICCSelectorClass { |
4021 | - SPColorSelectorClass parent_class; |
4022 | -}; |
4023 | - |
4024 | -GType sp_color_icc_selector_get_type(void); |
4025 | - |
4026 | -GtkWidget *sp_color_icc_selector_new(void); |
4027 | - |
4028 | - |
4029 | - |
4030 | +class ColorICCSelectorFactory : public ColorSelectorFactory { |
4031 | + public: |
4032 | + Gtk::Widget *createWidget(SelectedColor &color) const; |
4033 | + Glib::ustring modeName() const; |
4034 | +}; |
4035 | +} |
4036 | +} |
4037 | +} |
4038 | #endif // SEEN_SP_COLOR_ICC_SELECTOR_H |
4039 | |
4040 | /* |
4041 | |
4042 | === renamed file 'src/widgets/sp-color-notebook.cpp' => 'src/ui/widget/color-notebook.cpp' |
4043 | --- src/widgets/sp-color-notebook.cpp 2014-10-08 02:22:03 +0000 |
4044 | +++ src/ui/widget/color-notebook.cpp 2015-05-03 11:19:29 +0000 |
4045 | @@ -1,11 +1,13 @@ |
4046 | -/* |
4047 | - * A notebook with RGB, CMYK, CMS, HSL, and Wheel pages |
4048 | - * |
4049 | - * Author: |
4050 | +/** |
4051 | + * @file |
4052 | + * A notebook with RGB, CMYK, CMS, HSL, and Wheel pages - implementation |
4053 | + */ |
4054 | +/* Authors: |
4055 | * Lauris Kaplinski <lauris@kaplinski.com> |
4056 | * bulia byak <buliabyak@users.sf.net> |
4057 | + * Tomasz Boczkowski <penginsbacon@gmail.com> (c++-sification) |
4058 | * |
4059 | - * Copyright (C) 2001-2002 Lauris Kaplinski |
4060 | + * Copyright (C) 2001-2014 Authors |
4061 | * |
4062 | * This code is in public domain |
4063 | */ |
4064 | @@ -14,7 +16,7 @@ |
4065 | #define noDUMP_CHANGE_INFO |
4066 | |
4067 | #ifdef HAVE_CONFIG_H |
4068 | -# include "config.h" |
4069 | +#include "config.h" |
4070 | #endif |
4071 | |
4072 | #include "widgets/icon.h" |
4073 | @@ -22,512 +24,233 @@ |
4074 | #include <string> |
4075 | #include <cstdlib> |
4076 | #include <cstddef> |
4077 | -#include <gtk/gtk.h> |
4078 | #include <glibmm/i18n.h> |
4079 | +#include <gtkmm/label.h> |
4080 | +#include <gtkmm/notebook.h> |
4081 | |
4082 | -#include "ui/dialog-events.h" |
4083 | -#include "../preferences.h" |
4084 | -#include "sp-color-notebook.h" |
4085 | -#include "spw-utilities.h" |
4086 | -#include "sp-color-scales.h" |
4087 | -#include "sp-color-icc-selector.h" |
4088 | -#include "sp-color-wheel-selector.h" |
4089 | +#include "preferences.h" |
4090 | +#include "widgets/spw-utilities.h" |
4091 | #include "svg/svg-icc-color.h" |
4092 | -#include "../inkscape.h" |
4093 | -#include "../document.h" |
4094 | -#include "../profile-manager.h" |
4095 | +#include "inkscape.h" |
4096 | +#include "document.h" |
4097 | +#include "profile-manager.h" |
4098 | #include "color-profile.h" |
4099 | #include "cms-system.h" |
4100 | +#include "ui/dialog-events.h" |
4101 | #include "ui/tools-switch.h" |
4102 | #include "ui/tools/tool-base.h" |
4103 | +#include "ui/widget/color-entry.h" |
4104 | +#include "ui/widget/color-icc-selector.h" |
4105 | +#include "ui/widget/color-notebook.h" |
4106 | +#include "ui/widget/color-scales.h" |
4107 | +#include "ui/widget/color-wheel-selector.h" |
4108 | |
4109 | using Inkscape::CMSSystem; |
4110 | |
4111 | -struct SPColorNotebookTracker { |
4112 | - const gchar* name; |
4113 | - const gchar* className; |
4114 | - GType type; |
4115 | - guint submode; |
4116 | - gboolean enabledFull; |
4117 | - gboolean enabledBrief; |
4118 | - SPColorNotebook *backPointer; |
4119 | -}; |
4120 | - |
4121 | -static void sp_color_notebook_dispose(GObject *object); |
4122 | - |
4123 | -static void sp_color_notebook_show_all (GtkWidget *widget); |
4124 | -static void sp_color_notebook_hide(GtkWidget *widget); |
4125 | - |
4126 | #define XPAD 4 |
4127 | #define YPAD 1 |
4128 | |
4129 | -G_DEFINE_TYPE(SPColorNotebook, sp_color_notebook, SP_TYPE_COLOR_SELECTOR); |
4130 | - |
4131 | -static void sp_color_notebook_class_init(SPColorNotebookClass *klass) |
4132 | -{ |
4133 | - GObjectClass *object_class = reinterpret_cast<GObjectClass *>(klass); |
4134 | - GtkWidgetClass *widget_class = reinterpret_cast<GtkWidgetClass *>(klass); |
4135 | - |
4136 | - object_class->dispose = sp_color_notebook_dispose; |
4137 | - |
4138 | - widget_class->show_all = sp_color_notebook_show_all; |
4139 | - widget_class->hide = sp_color_notebook_hide; |
4140 | -} |
4141 | - |
4142 | -static void |
4143 | -sp_color_notebook_switch_page(GtkNotebook *notebook, |
4144 | - GtkWidget *page, |
4145 | - guint page_num, |
4146 | - SPColorNotebook *colorbook) |
4147 | -{ |
4148 | - if ( colorbook ) |
4149 | - { |
4150 | - ColorNotebook* nb = dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base); |
4151 | - nb->switchPage( notebook, page, page_num ); |
4152 | - |
4153 | - // remember the page we switched to |
4154 | - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); |
4155 | - prefs->setInt("/colorselector/page", page_num); |
4156 | - } |
4157 | -} |
4158 | - |
4159 | -void ColorNotebook::switchPage(GtkNotebook*, |
4160 | - GtkWidget*, |
4161 | - guint page_num) |
4162 | -{ |
4163 | - SPColorSelector* csel; |
4164 | - GtkWidget* widget; |
4165 | - |
4166 | - if ( gtk_notebook_get_current_page (GTK_NOTEBOOK (_book)) >= 0 ) |
4167 | - { |
4168 | - csel = getCurrentSelector(); |
4169 | - csel->base->getColorAlpha(_color, _alpha); |
4170 | - } |
4171 | - widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (_book), page_num); |
4172 | - if ( widget && SP_IS_COLOR_SELECTOR(widget) ) |
4173 | - { |
4174 | - csel = SP_COLOR_SELECTOR (widget); |
4175 | - csel->base->setColorAlpha( _color, _alpha ); |
4176 | - |
4177 | - // Temporary workaround to undo a spurious GRABBED |
4178 | - _released(); |
4179 | - } |
4180 | -} |
4181 | - |
4182 | -static gint sp_color_notebook_menu_handler( GtkWidget *widget, GdkEvent *event ) |
4183 | -{ |
4184 | - if (event->type == GDK_BUTTON_PRESS) |
4185 | - { |
4186 | - SPColorSelector* csel = SP_COLOR_SELECTOR(widget); |
4187 | - (dynamic_cast<ColorNotebook*>(csel->base))->menuHandler( event ); |
4188 | - |
4189 | - /* Tell calling code that we have handled this event; the buck |
4190 | - * stops here. */ |
4191 | - return TRUE; |
4192 | - } |
4193 | - |
4194 | - /* Tell calling code that we have not handled this event; pass it on. */ |
4195 | - return FALSE; |
4196 | -} |
4197 | - |
4198 | -gint ColorNotebook::menuHandler( GdkEvent* event ) |
4199 | -{ |
4200 | - GdkEventButton *bevent = (GdkEventButton *) event; |
4201 | - gtk_menu_popup (GTK_MENU( _popup ), NULL, NULL, NULL, NULL, |
4202 | - bevent->button, bevent->time); |
4203 | - return TRUE; |
4204 | -} |
4205 | - |
4206 | -static void sp_color_notebook_menuitem_response (GtkMenuItem *menuitem, gpointer user_data) |
4207 | -{ |
4208 | - gboolean active = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (menuitem)); |
4209 | - SPColorNotebookTracker *entry = reinterpret_cast< SPColorNotebookTracker* > (user_data); |
4210 | - if ( entry ) |
4211 | - { |
4212 | - if ( active ) |
4213 | - { |
4214 | - (dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(entry->backPointer)->base))->addPage(entry->type, entry->submode); |
4215 | - } |
4216 | - else |
4217 | - { |
4218 | - (dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(entry->backPointer)->base))->removePage(entry->type, entry->submode); |
4219 | - } |
4220 | - } |
4221 | -} |
4222 | - |
4223 | -static void |
4224 | -sp_color_notebook_init (SPColorNotebook *colorbook) |
4225 | -{ |
4226 | - SP_COLOR_SELECTOR(colorbook)->base = new ColorNotebook( SP_COLOR_SELECTOR(colorbook) ); |
4227 | - |
4228 | - if ( SP_COLOR_SELECTOR(colorbook)->base ) |
4229 | - { |
4230 | - SP_COLOR_SELECTOR(colorbook)->base->init(); |
4231 | - } |
4232 | -} |
4233 | - |
4234 | -void ColorNotebook::init() |
4235 | +namespace Inkscape { |
4236 | +namespace UI { |
4237 | +namespace Widget { |
4238 | + |
4239 | + |
4240 | +ColorNotebook::ColorNotebook(SelectedColor &color) |
4241 | +#if GTK_CHECK_VERSION(3, 0, 0) |
4242 | + : Gtk::Grid() |
4243 | +#else |
4244 | + : Gtk::Table(2, 3, false) |
4245 | +#endif |
4246 | + , _selected_color(color) |
4247 | + |
4248 | +{ |
4249 | + Page *page; |
4250 | + |
4251 | + page = new Page(new ColorScalesFactory(SP_COLOR_SCALES_MODE_RGB), true); |
4252 | + _available_pages.push_back(page); |
4253 | + page = new Page(new ColorScalesFactory(SP_COLOR_SCALES_MODE_HSV), true); |
4254 | + _available_pages.push_back(page); |
4255 | + page = new Page(new ColorScalesFactory(SP_COLOR_SCALES_MODE_CMYK), true); |
4256 | + _available_pages.push_back(page); |
4257 | + page = new Page(new ColorWheelSelectorFactory, true); |
4258 | + _available_pages.push_back(page); |
4259 | +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
4260 | + page = new Page(new ColorICCSelectorFactory, true); |
4261 | + _available_pages.push_back(page); |
4262 | +#endif |
4263 | + |
4264 | + _initUI(); |
4265 | + |
4266 | + _selected_color.signal_changed.connect(sigc::mem_fun(this, &ColorNotebook::_onSelectedColorChanged)); |
4267 | + _selected_color.signal_dragged.connect(sigc::mem_fun(this, &ColorNotebook::_onSelectedColorChanged)); |
4268 | +} |
4269 | + |
4270 | +ColorNotebook::~ColorNotebook() |
4271 | +{ |
4272 | + if (_buttons) { |
4273 | + delete[] _buttons; |
4274 | + _buttons = 0; |
4275 | + } |
4276 | +} |
4277 | + |
4278 | +ColorNotebook::Page::Page(Inkscape::UI::ColorSelectorFactory *selector_factory, bool enabled_full) |
4279 | + : selector_factory(selector_factory) |
4280 | + , enabled_full(enabled_full) |
4281 | +{ |
4282 | +} |
4283 | + |
4284 | + |
4285 | +void ColorNotebook::_initUI() |
4286 | { |
4287 | guint row = 0; |
4288 | - guint i = 0; |
4289 | - guint j = 0; |
4290 | - GType *selector_types = 0; |
4291 | - guint selector_type_count = 0; |
4292 | - |
4293 | - /* tempory hardcoding to get types loaded */ |
4294 | - SP_TYPE_COLOR_SCALES; |
4295 | - SP_TYPE_COLOR_WHEEL_SELECTOR; |
4296 | -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
4297 | - SP_TYPE_COLOR_ICC_SELECTOR; |
4298 | -#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
4299 | - |
4300 | - /* REJON: Comment out the next line to not use the normal GTK Color |
4301 | - wheel. */ |
4302 | - |
4303 | -// SP_TYPE_COLOR_GTKSELECTOR; |
4304 | - |
4305 | - _updating = FALSE; |
4306 | - _updatingrgba = FALSE; |
4307 | - _btn = 0; |
4308 | - _popup = 0; |
4309 | - _trackerList = g_ptr_array_new (); |
4310 | - |
4311 | - _book = gtk_notebook_new (); |
4312 | - gtk_widget_show (_book); |
4313 | - |
4314 | - // Dont show the notebook tabs, use radiobuttons instead |
4315 | - gtk_notebook_set_show_border (GTK_NOTEBOOK (_book), false); |
4316 | - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (_book), false); |
4317 | - |
4318 | - selector_types = g_type_children (SP_TYPE_COLOR_SELECTOR, &selector_type_count); |
4319 | - |
4320 | - for ( i = 0; i < selector_type_count; i++ ) |
4321 | - { |
4322 | - if (!g_type_is_a (selector_types[i], SP_TYPE_COLOR_NOTEBOOK)) |
4323 | - { |
4324 | - guint howmany = 1; |
4325 | - gpointer klass = g_type_class_ref (selector_types[i]); |
4326 | - if ( klass && SP_IS_COLOR_SELECTOR_CLASS(klass) ) |
4327 | - { |
4328 | - SPColorSelectorClass *ck = SP_COLOR_SELECTOR_CLASS (klass); |
4329 | - howmany = MAX (1, ck->submode_count); |
4330 | - for ( j = 0; j < howmany; j++ ) |
4331 | - { |
4332 | - SPColorNotebookTracker *entry = reinterpret_cast< SPColorNotebookTracker* > (malloc(sizeof(SPColorNotebookTracker))); |
4333 | - if ( entry ) |
4334 | - { |
4335 | - memset( entry, 0, sizeof(SPColorNotebookTracker) ); |
4336 | - entry->name = ck->name[j]; |
4337 | - entry->type = selector_types[i]; |
4338 | - entry->submode = j; |
4339 | - entry->enabledFull = TRUE; |
4340 | - entry->enabledBrief = TRUE; |
4341 | - entry->backPointer = SP_COLOR_NOTEBOOK(_csel); |
4342 | - |
4343 | - g_ptr_array_add (_trackerList, entry); |
4344 | - } |
4345 | - } |
4346 | - } |
4347 | - } |
4348 | - } |
4349 | - |
4350 | -#if GTK_CHECK_VERSION(3,0,0) |
4351 | + |
4352 | + Gtk::Notebook *notebook = Gtk::manage(new Gtk::Notebook); |
4353 | + notebook->show(); |
4354 | + notebook->set_show_border(false); |
4355 | + notebook->set_show_tabs(false); |
4356 | + _book = GTK_WIDGET(notebook->gobj()); |
4357 | + |
4358 | +#if GTK_CHECK_VERSION(3, 0, 0) |
4359 | _buttonbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2); |
4360 | gtk_box_set_homogeneous(GTK_BOX(_buttonbox), TRUE); |
4361 | #else |
4362 | - _buttonbox = gtk_hbox_new (TRUE, 2); |
4363 | + _buttonbox = gtk_hbox_new(TRUE, 2); |
4364 | #endif |
4365 | |
4366 | - gtk_widget_show (_buttonbox); |
4367 | - _buttons = new GtkWidget *[_trackerList->len]; |
4368 | + gtk_widget_show(_buttonbox); |
4369 | + _buttons = new GtkWidget *[_available_pages.size()]; |
4370 | |
4371 | - for ( i = 0; i < _trackerList->len; i++ ) |
4372 | - { |
4373 | - SPColorNotebookTracker *entry = |
4374 | - reinterpret_cast< SPColorNotebookTracker* > (g_ptr_array_index (_trackerList, i)); |
4375 | - if ( entry ) |
4376 | - { |
4377 | - addPage(entry->type, entry->submode); |
4378 | - } |
4379 | + for (int i = 0; static_cast<size_t>(i) < _available_pages.size(); i++) { |
4380 | + _addPage(_available_pages[i]); |
4381 | } |
4382 | |
4383 | -#if GTK_CHECK_VERSION(3,0,0) |
4384 | - GtkWidget* table = gtk_grid_new(); |
4385 | -#else |
4386 | - GtkWidget* table = gtk_table_new(2, 3, FALSE); |
4387 | -#endif |
4388 | - |
4389 | - gtk_widget_show (table); |
4390 | - |
4391 | - gtk_box_pack_start (GTK_BOX (_csel), table, TRUE, TRUE, 0); |
4392 | - |
4393 | - sp_set_font_size_smaller (_buttonbox); |
4394 | - |
4395 | -#if GTK_CHECK_VERSION(3,0,0) |
4396 | - #if GTK_CHECK_VERSION(3,12,0) |
4397 | + sp_set_font_size_smaller(_buttonbox); |
4398 | + |
4399 | +#if GTK_CHECK_VERSION(3, 0, 0) |
4400 | + #if GTK_CHECK_VERSION(3, 12, 0) |
4401 | gtk_widget_set_margin_start(_buttonbox, XPAD); |
4402 | gtk_widget_set_margin_end(_buttonbox, XPAD); |
4403 | - #else |
4404 | + #else |
4405 | gtk_widget_set_margin_left(_buttonbox, XPAD); |
4406 | gtk_widget_set_margin_right(_buttonbox, XPAD); |
4407 | - #endif |
4408 | + #endif |
4409 | gtk_widget_set_margin_top(_buttonbox, YPAD); |
4410 | gtk_widget_set_margin_bottom(_buttonbox, YPAD); |
4411 | gtk_widget_set_hexpand(_buttonbox, TRUE); |
4412 | gtk_widget_set_valign(_buttonbox, GTK_ALIGN_CENTER); |
4413 | - gtk_grid_attach(GTK_GRID(table), _buttonbox, 0, row, 2, 1); |
4414 | + attach(*Glib::wrap(_buttonbox), 0, row, 2, 1); |
4415 | #else |
4416 | - gtk_table_attach (GTK_TABLE (table), _buttonbox, 0, 2, row, row + 1, |
4417 | - static_cast<GtkAttachOptions>(GTK_EXPAND|GTK_FILL), |
4418 | - static_cast<GtkAttachOptions>(0), |
4419 | - XPAD, YPAD); |
4420 | + attach(*Glib::wrap(_buttonbox), 0, 2, row, row + 1, Gtk::EXPAND | Gtk::FILL, static_cast<Gtk::AttachOptions>(0), |
4421 | + XPAD, YPAD); |
4422 | #endif |
4423 | |
4424 | row++; |
4425 | |
4426 | -#if GTK_CHECK_VERSION(3,0,0) |
4427 | - #if GTK_CHECK_VERSION(3,12,0) |
4428 | - gtk_widget_set_margin_start(_book, XPAD*2); |
4429 | - gtk_widget_set_margin_end(_book, XPAD*2); |
4430 | - #else |
4431 | - gtk_widget_set_margin_left(_book, XPAD*2); |
4432 | - gtk_widget_set_margin_right(_book, XPAD*2); |
4433 | - #endif |
4434 | +#if GTK_CHECK_VERSION(3, 0, 0) |
4435 | +#if GTK_CHECK_VERSION(3, 12, 0) |
4436 | + gtk_widget_set_margin_start(_book, XPAD * 2); |
4437 | + gtk_widget_set_margin_end(_book, XPAD * 2); |
4438 | +#else |
4439 | + gtk_widget_set_margin_left(_book, XPAD * 2); |
4440 | + gtk_widget_set_margin_right(_book, XPAD * 2); |
4441 | +#endif |
4442 | gtk_widget_set_margin_top(_book, YPAD); |
4443 | gtk_widget_set_margin_bottom(_book, YPAD); |
4444 | gtk_widget_set_hexpand(_book, TRUE); |
4445 | gtk_widget_set_vexpand(_book, TRUE); |
4446 | - gtk_grid_attach(GTK_GRID(table), _book, 0, row, 2, 1); |
4447 | + attach(*notebook, 0, row, 2, 1); |
4448 | #else |
4449 | - gtk_table_attach (GTK_TABLE (table), _book, 0, 2, row, row + 1, |
4450 | - static_cast<GtkAttachOptions>(GTK_EXPAND|GTK_FILL), |
4451 | - static_cast<GtkAttachOptions>(GTK_EXPAND|GTK_FILL), |
4452 | - XPAD*2, YPAD); |
4453 | + attach(*notebook, 0, 2, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, XPAD * 2, YPAD); |
4454 | #endif |
4455 | |
4456 | // restore the last active page |
4457 | Inkscape::Preferences *prefs = Inkscape::Preferences::get(); |
4458 | _setCurrentPage(prefs->getInt("/colorselector/page", 0)); |
4459 | - |
4460 | - { |
4461 | - gboolean found = FALSE; |
4462 | - |
4463 | - _popup = gtk_menu_new(); |
4464 | - GtkMenu *menu = GTK_MENU (_popup); |
4465 | - |
4466 | - for ( i = 0; i < _trackerList->len; i++ ) |
4467 | - { |
4468 | - SPColorNotebookTracker *entry = reinterpret_cast< SPColorNotebookTracker* > (g_ptr_array_index (_trackerList, i)); |
4469 | - if ( entry ) |
4470 | - { |
4471 | - GtkWidget *item = gtk_check_menu_item_new_with_label (_(entry->name)); |
4472 | - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), entry->enabledFull); |
4473 | - gtk_widget_show (item); |
4474 | - gtk_menu_shell_append (GTK_MENU_SHELL(menu), item); |
4475 | - |
4476 | - g_signal_connect (G_OBJECT (item), "activate", |
4477 | - G_CALLBACK (sp_color_notebook_menuitem_response), |
4478 | - reinterpret_cast< gpointer > (entry) ); |
4479 | - found = TRUE; |
4480 | - } |
4481 | - } |
4482 | - |
4483 | - GtkWidget *arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_NONE); |
4484 | - gtk_widget_show (arrow); |
4485 | - |
4486 | - _btn = gtk_button_new (); |
4487 | - gtk_widget_show (_btn); |
4488 | - gtk_container_add (GTK_CONTAINER (_btn), arrow); |
4489 | - |
4490 | - GtkWidget *align = gtk_alignment_new (1.0, 0.0, 0.0, 0.0); |
4491 | - gtk_widget_show (align); |
4492 | - gtk_container_add (GTK_CONTAINER (align), _btn); |
4493 | - |
4494 | - // uncomment to reenable the "show/hide modes" menu, |
4495 | - // but first fix it so it remembers its settings in prefs and does not take that much space (entire vertical column!) |
4496 | - //gtk_table_attach (GTK_TABLE (table), align, 2, 3, row, row + 1, GTK_FILL, GTK_FILL, XPAD, YPAD); |
4497 | - |
4498 | - g_signal_connect_swapped(G_OBJECT(_btn), "event", G_CALLBACK (sp_color_notebook_menu_handler), G_OBJECT(_csel)); |
4499 | - if ( !found ) |
4500 | - { |
4501 | - gtk_widget_set_sensitive (_btn, FALSE); |
4502 | - } |
4503 | - } |
4504 | - |
4505 | row++; |
4506 | |
4507 | -#if GTK_CHECK_VERSION(3,0,0) |
4508 | +#if GTK_CHECK_VERSION(3, 0, 0) |
4509 | GtkWidget *rgbabox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
4510 | #else |
4511 | - GtkWidget *rgbabox = gtk_hbox_new (FALSE, 0); |
4512 | + GtkWidget *rgbabox = gtk_hbox_new(FALSE, 0); |
4513 | #endif |
4514 | |
4515 | #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
4516 | /* Create color management icons */ |
4517 | - _box_colormanaged = gtk_event_box_new (); |
4518 | - GtkWidget *colormanaged = gtk_image_new_from_icon_name ("color-management-icon", GTK_ICON_SIZE_SMALL_TOOLBAR); |
4519 | - gtk_container_add (GTK_CONTAINER (_box_colormanaged), colormanaged); |
4520 | - gtk_widget_set_tooltip_text (_box_colormanaged, _("Color Managed")); |
4521 | - gtk_widget_set_sensitive (_box_colormanaged, false); |
4522 | + _box_colormanaged = gtk_event_box_new(); |
4523 | + GtkWidget *colormanaged = gtk_image_new_from_icon_name("color-management-icon", GTK_ICON_SIZE_SMALL_TOOLBAR); |
4524 | + gtk_container_add(GTK_CONTAINER(_box_colormanaged), colormanaged); |
4525 | + gtk_widget_set_tooltip_text(_box_colormanaged, _("Color Managed")); |
4526 | + gtk_widget_set_sensitive(_box_colormanaged, false); |
4527 | gtk_box_pack_start(GTK_BOX(rgbabox), _box_colormanaged, FALSE, FALSE, 2); |
4528 | |
4529 | - _box_outofgamut = gtk_event_box_new (); |
4530 | - GtkWidget *outofgamut = gtk_image_new_from_icon_name ("out-of-gamut-icon", GTK_ICON_SIZE_SMALL_TOOLBAR); |
4531 | - gtk_container_add (GTK_CONTAINER (_box_outofgamut), outofgamut); |
4532 | - gtk_widget_set_tooltip_text (_box_outofgamut, _("Out of gamut!")); |
4533 | - gtk_widget_set_sensitive (_box_outofgamut, false); |
4534 | + _box_outofgamut = gtk_event_box_new(); |
4535 | + GtkWidget *outofgamut = gtk_image_new_from_icon_name("out-of-gamut-icon", GTK_ICON_SIZE_SMALL_TOOLBAR); |
4536 | + gtk_container_add(GTK_CONTAINER(_box_outofgamut), outofgamut); |
4537 | + gtk_widget_set_tooltip_text(_box_outofgamut, _("Out of gamut!")); |
4538 | + gtk_widget_set_sensitive(_box_outofgamut, false); |
4539 | gtk_box_pack_start(GTK_BOX(rgbabox), _box_outofgamut, FALSE, FALSE, 2); |
4540 | |
4541 | - _box_toomuchink = gtk_event_box_new (); |
4542 | - GtkWidget *toomuchink = gtk_image_new_from_icon_name ("too-much-ink-icon", GTK_ICON_SIZE_SMALL_TOOLBAR); |
4543 | - gtk_container_add (GTK_CONTAINER (_box_toomuchink), toomuchink); |
4544 | - gtk_widget_set_tooltip_text (_box_toomuchink, _("Too much ink!")); |
4545 | - gtk_widget_set_sensitive (_box_toomuchink, false); |
4546 | + _box_toomuchink = gtk_event_box_new(); |
4547 | + GtkWidget *toomuchink = gtk_image_new_from_icon_name("too-much-ink-icon", GTK_ICON_SIZE_SMALL_TOOLBAR); |
4548 | + gtk_container_add(GTK_CONTAINER(_box_toomuchink), toomuchink); |
4549 | + gtk_widget_set_tooltip_text(_box_toomuchink, _("Too much ink!")); |
4550 | + gtk_widget_set_sensitive(_box_toomuchink, false); |
4551 | gtk_box_pack_start(GTK_BOX(rgbabox), _box_toomuchink, FALSE, FALSE, 2); |
4552 | -#endif //defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
4553 | +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
4554 | |
4555 | |
4556 | /* Color picker */ |
4557 | - GtkWidget *picker = gtk_image_new_from_icon_name ("color-picker", GTK_ICON_SIZE_SMALL_TOOLBAR); |
4558 | - _btn_picker = gtk_button_new (); |
4559 | + GtkWidget *picker = gtk_image_new_from_icon_name("color-picker", GTK_ICON_SIZE_SMALL_TOOLBAR); |
4560 | + _btn_picker = gtk_button_new(); |
4561 | gtk_button_set_relief(GTK_BUTTON(_btn_picker), GTK_RELIEF_NONE); |
4562 | - gtk_widget_show (_btn); |
4563 | - gtk_container_add (GTK_CONTAINER (_btn_picker), picker); |
4564 | - gtk_widget_set_tooltip_text (_btn_picker, _("Pick colors from image")); |
4565 | + gtk_container_add(GTK_CONTAINER(_btn_picker), picker); |
4566 | + gtk_widget_set_tooltip_text(_btn_picker, _("Pick colors from image")); |
4567 | gtk_box_pack_start(GTK_BOX(rgbabox), _btn_picker, FALSE, FALSE, 2); |
4568 | - g_signal_connect(G_OBJECT(_btn_picker), "clicked", G_CALLBACK(ColorNotebook::_picker_clicked), _csel); |
4569 | + g_signal_connect(G_OBJECT(_btn_picker), "clicked", G_CALLBACK(ColorNotebook::_onPickerClicked), this); |
4570 | |
4571 | /* Create RGBA entry and color preview */ |
4572 | - _rgbal = gtk_label_new_with_mnemonic (_("RGBA_:")); |
4573 | - gtk_misc_set_alignment (GTK_MISC (_rgbal), 1.0, 0.5); |
4574 | + _rgbal = gtk_label_new_with_mnemonic(_("RGBA_:")); |
4575 | + gtk_misc_set_alignment(GTK_MISC(_rgbal), 1.0, 0.5); |
4576 | gtk_box_pack_start(GTK_BOX(rgbabox), _rgbal, TRUE, TRUE, 2); |
4577 | |
4578 | - _rgbae = gtk_entry_new (); |
4579 | - sp_dialog_defocus_on_enter (_rgbae); |
4580 | - gtk_entry_set_max_length (GTK_ENTRY (_rgbae), 8); |
4581 | - gtk_entry_set_width_chars (GTK_ENTRY (_rgbae), 8); |
4582 | - gtk_widget_set_tooltip_text (_rgbae, _("Hexadecimal RGBA value of the color")); |
4583 | - gtk_box_pack_start(GTK_BOX(rgbabox), _rgbae, FALSE, FALSE, 0); |
4584 | - gtk_label_set_mnemonic_widget (GTK_LABEL(_rgbal), _rgbae); |
4585 | + ColorEntry *rgba_entry = Gtk::manage(new ColorEntry(_selected_color)); |
4586 | + sp_dialog_defocus_on_enter(GTK_WIDGET(rgba_entry->gobj())); |
4587 | + gtk_box_pack_start(GTK_BOX(rgbabox), GTK_WIDGET(rgba_entry->gobj()), FALSE, FALSE, 0); |
4588 | + gtk_label_set_mnemonic_widget(GTK_LABEL(_rgbal), GTK_WIDGET(rgba_entry->gobj())); |
4589 | |
4590 | - sp_set_font_size_smaller (rgbabox); |
4591 | - gtk_widget_show_all (rgbabox); |
4592 | + sp_set_font_size_smaller(rgbabox); |
4593 | + gtk_widget_show_all(rgbabox); |
4594 | |
4595 | #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
4596 | - //the "too much ink" icon is initially hidden |
4597 | + // the "too much ink" icon is initially hidden |
4598 | gtk_widget_hide(GTK_WIDGET(_box_toomuchink)); |
4599 | -#endif //defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
4600 | +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
4601 | |
4602 | -#if GTK_CHECK_VERSION(3,0,0) |
4603 | - #if GTK_CHECK_VERSION(3,12,0) |
4604 | +#if GTK_CHECK_VERSION(3, 0, 0) |
4605 | + #if GTK_CHECK_VERSION(3, 12, 0) |
4606 | gtk_widget_set_margin_start(rgbabox, XPAD); |
4607 | gtk_widget_set_margin_end(rgbabox, XPAD); |
4608 | - #else |
4609 | + #else |
4610 | gtk_widget_set_margin_left(rgbabox, XPAD); |
4611 | gtk_widget_set_margin_right(rgbabox, XPAD); |
4612 | - #endif |
4613 | + #endif |
4614 | gtk_widget_set_margin_top(rgbabox, YPAD); |
4615 | gtk_widget_set_margin_bottom(rgbabox, YPAD); |
4616 | - gtk_grid_attach(GTK_GRID(table), rgbabox, 0, row, 2, 1); |
4617 | + attach(*Glib::wrap(rgbabox), 0, row, 2, 1); |
4618 | #else |
4619 | - gtk_table_attach (GTK_TABLE (table), rgbabox, 0, 2, row, row + 1, GTK_FILL, GTK_SHRINK, XPAD, YPAD); |
4620 | + attach(*Glib::wrap(rgbabox), 0, 2, row, row + 1, Gtk::FILL, Gtk::SHRINK, XPAD, YPAD); |
4621 | #endif |
4622 | |
4623 | #ifdef SPCS_PREVIEW |
4624 | - _p = sp_color_preview_new (0xffffffff); |
4625 | - gtk_widget_show (_p); |
4626 | - gtk_table_attach (GTK_TABLE (table), _p, 2, 3, row, row + 1, GTK_FILL, GTK_FILL, XPAD, YPAD); |
4627 | + _p = sp_color_preview_new(0xffffffff); |
4628 | + gtk_widget_show(_p); |
4629 | + attach(*Glib::wrap(_p), 2, 3, row, row + 1, Gtk::FILL, Gtk::FILL, XPAD, YPAD); |
4630 | #endif |
4631 | |
4632 | - _switchId = g_signal_connect(G_OBJECT (_book), "switch-page", |
4633 | - G_CALLBACK (sp_color_notebook_switch_page), SP_COLOR_NOTEBOOK(_csel)); |
4634 | - |
4635 | - _entryId = g_signal_connect (G_OBJECT (_rgbae), "changed", G_CALLBACK (ColorNotebook::_rgbaEntryChangedHook), _csel); |
4636 | -} |
4637 | - |
4638 | -static void sp_color_notebook_dispose(GObject *object) |
4639 | -{ |
4640 | - if (G_OBJECT_CLASS(sp_color_notebook_parent_class)->dispose) |
4641 | - G_OBJECT_CLASS(sp_color_notebook_parent_class)->dispose(object); |
4642 | -} |
4643 | - |
4644 | -ColorNotebook::~ColorNotebook() |
4645 | -{ |
4646 | - if ( _trackerList ) |
4647 | - { |
4648 | - g_ptr_array_free (_trackerList, TRUE); |
4649 | - _trackerList = 0; |
4650 | - } |
4651 | - |
4652 | - if ( _switchId ) |
4653 | - { |
4654 | - if ( _book ) |
4655 | - { |
4656 | - g_signal_handler_disconnect (_book, _switchId); |
4657 | - _switchId = 0; |
4658 | - } |
4659 | - } |
4660 | - |
4661 | - if ( _buttons ) |
4662 | - { |
4663 | - delete [] _buttons; |
4664 | - _buttons = 0; |
4665 | - } |
4666 | - |
4667 | -} |
4668 | - |
4669 | -static void |
4670 | -sp_color_notebook_show_all (GtkWidget *widget) |
4671 | -{ |
4672 | - gtk_widget_show (widget); |
4673 | -} |
4674 | - |
4675 | -static void sp_color_notebook_hide(GtkWidget *widget) |
4676 | -{ |
4677 | - gtk_widget_hide(widget); |
4678 | -} |
4679 | - |
4680 | -GtkWidget *sp_color_notebook_new() |
4681 | -{ |
4682 | - SPColorNotebook *colorbook = SP_COLOR_NOTEBOOK(g_object_new (SP_TYPE_COLOR_NOTEBOOK, NULL)); |
4683 | - |
4684 | - return GTK_WIDGET(colorbook); |
4685 | -} |
4686 | - |
4687 | -ColorNotebook::ColorNotebook( SPColorSelector* csel ) |
4688 | - : ColorSelector( csel ) |
4689 | -{ |
4690 | -} |
4691 | - |
4692 | -SPColorSelector* ColorNotebook::getCurrentSelector() |
4693 | -{ |
4694 | - SPColorSelector* csel = NULL; |
4695 | - gint current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (_book)); |
4696 | - |
4697 | - if ( current_page >= 0 ) |
4698 | - { |
4699 | - GtkWidget* widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (_book), current_page); |
4700 | - if ( SP_IS_COLOR_SELECTOR (widget) ) |
4701 | - { |
4702 | - csel = SP_COLOR_SELECTOR (widget); |
4703 | - } |
4704 | - } |
4705 | - |
4706 | - return csel; |
4707 | -} |
4708 | - |
4709 | -void ColorNotebook::_colorChanged() |
4710 | -{ |
4711 | - SPColorSelector* cselPage = getCurrentSelector(); |
4712 | - if ( cselPage ) |
4713 | - { |
4714 | - cselPage->base->setColorAlpha( _color, _alpha ); |
4715 | - } |
4716 | - |
4717 | - _updateRgbaEntry( _color, _alpha ); |
4718 | -} |
4719 | - |
4720 | -void ColorNotebook::_picker_clicked(GtkWidget * /*widget*/, SPColorNotebook * /*colorbook*/) |
4721 | + g_signal_connect(G_OBJECT(_book), "switch-page", G_CALLBACK(ColorNotebook::_onPageSwitched), this); |
4722 | +} |
4723 | + |
4724 | +void ColorNotebook::_onPickerClicked(GtkWidget * /*widget*/, ColorNotebook * /*colorbook*/) |
4725 | { |
4726 | // Set the dropper into a "one click" mode, so it reverts to the previous tool after a click |
4727 | Inkscape::Preferences *prefs = Inkscape::Preferences::get(); |
4728 | @@ -535,283 +258,113 @@ |
4729 | Inkscape::UI::Tools::sp_toggle_dropper(SP_ACTIVE_DESKTOP); |
4730 | } |
4731 | |
4732 | -void ColorNotebook::_rgbaEntryChangedHook(GtkEntry *entry, SPColorNotebook *colorbook) |
4733 | -{ |
4734 | - (dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base))->_rgbaEntryChanged( entry ); |
4735 | -} |
4736 | - |
4737 | -void ColorNotebook::_rgbaEntryChanged(GtkEntry* entry) |
4738 | -{ |
4739 | - if (_updating) return; |
4740 | - if (_updatingrgba) return; |
4741 | - |
4742 | - const gchar *t = gtk_entry_get_text( entry ); |
4743 | - |
4744 | - if (t) { |
4745 | - Glib::ustring text = t; |
4746 | - bool changed = false; |
4747 | - if (!text.empty() && text[0] == '#') { |
4748 | - changed = true; |
4749 | - text.erase(0,1); |
4750 | - if (text.size() == 6) { |
4751 | - // it was a standard RGB hex |
4752 | - unsigned int alph = SP_COLOR_F_TO_U(_alpha); |
4753 | - gchar* tmp = g_strdup_printf("%02x", alph); |
4754 | - text += tmp; |
4755 | - g_free(tmp); |
4756 | - } |
4757 | - } |
4758 | - gchar* str = g_strdup(text.c_str()); |
4759 | - gchar* end = 0; |
4760 | - guint64 rgba = g_ascii_strtoull( str, &end, 16 ); |
4761 | - if ( end != str ) { |
4762 | - ptrdiff_t len = end - str; |
4763 | - if ( len < 8 ) { |
4764 | - rgba = rgba << ( 4 * ( 8 - len ) ); |
4765 | - } |
4766 | - _updatingrgba = TRUE; |
4767 | - if ( changed ) { |
4768 | - gtk_entry_set_text( entry, str ); |
4769 | - } |
4770 | - SPColor color( rgba ); |
4771 | - setColorAlpha( color, SP_RGBA32_A_F(rgba), true ); |
4772 | - _updatingrgba = FALSE; |
4773 | - } |
4774 | - g_free(str); |
4775 | - } |
4776 | -} |
4777 | +void ColorNotebook::_onButtonClicked(GtkWidget *widget, ColorNotebook *nb) |
4778 | +{ |
4779 | + if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { |
4780 | + return; |
4781 | + } |
4782 | + |
4783 | + for (gint i = 0; i < gtk_notebook_get_n_pages(GTK_NOTEBOOK(nb->_book)); i++) { |
4784 | + if (nb->_buttons[i] == widget) { |
4785 | + gtk_notebook_set_current_page(GTK_NOTEBOOK(nb->_book), i); |
4786 | + } |
4787 | + } |
4788 | +} |
4789 | + |
4790 | +void ColorNotebook::_onSelectedColorChanged() { _updateICCButtons(); } |
4791 | + |
4792 | +void ColorNotebook::_onPageSwitched(GtkNotebook *notebook, GtkWidget *page, guint page_num, ColorNotebook *colorbook) |
4793 | +{ |
4794 | + if (colorbook) { |
4795 | + // remember the page we switched to |
4796 | + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); |
4797 | + prefs->setInt("/colorselector/page", page_num); |
4798 | + } |
4799 | +} |
4800 | + |
4801 | |
4802 | // TODO pass in param so as to avoid the need for SP_ACTIVE_DOCUMENT |
4803 | -void ColorNotebook::_updateRgbaEntry( const SPColor& color, gfloat alpha ) |
4804 | +void ColorNotebook::_updateICCButtons() |
4805 | { |
4806 | - g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) ); |
4807 | + SPColor color = _selected_color.color(); |
4808 | + gfloat alpha = _selected_color.alpha(); |
4809 | + |
4810 | + g_return_if_fail((0.0 <= alpha) && (alpha <= 1.0)); |
4811 | |
4812 | #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
4813 | /* update color management icon*/ |
4814 | - gtk_widget_set_sensitive (_box_colormanaged, color.icc != NULL); |
4815 | + gtk_widget_set_sensitive(_box_colormanaged, color.icc != NULL); |
4816 | |
4817 | /* update out-of-gamut icon */ |
4818 | - gtk_widget_set_sensitive (_box_outofgamut, false); |
4819 | - if (color.icc){ |
4820 | - Inkscape::ColorProfile* target_profile = SP_ACTIVE_DOCUMENT->profileManager->find(color.icc->colorProfile.c_str()); |
4821 | - if ( target_profile ) |
4822 | + gtk_widget_set_sensitive(_box_outofgamut, false); |
4823 | + if (color.icc) { |
4824 | + Inkscape::ColorProfile *target_profile = |
4825 | + SP_ACTIVE_DOCUMENT->profileManager->find(color.icc->colorProfile.c_str()); |
4826 | + if (target_profile) |
4827 | gtk_widget_set_sensitive(_box_outofgamut, target_profile->GamutCheck(color)); |
4828 | } |
4829 | |
4830 | /* update too-much-ink icon */ |
4831 | - gtk_widget_set_sensitive (_box_toomuchink, false); |
4832 | - if (color.icc){ |
4833 | - Inkscape::ColorProfile* prof = SP_ACTIVE_DOCUMENT->profileManager->find(color.icc->colorProfile.c_str()); |
4834 | - if ( prof && CMSSystem::isPrintColorSpace(prof) ) { |
4835 | + gtk_widget_set_sensitive(_box_toomuchink, false); |
4836 | + if (color.icc) { |
4837 | + Inkscape::ColorProfile *prof = SP_ACTIVE_DOCUMENT->profileManager->find(color.icc->colorProfile.c_str()); |
4838 | + if (prof && CMSSystem::isPrintColorSpace(prof)) { |
4839 | gtk_widget_show(GTK_WIDGET(_box_toomuchink)); |
4840 | double ink_sum = 0; |
4841 | - for (unsigned int i=0; i<color.icc->colors.size(); i++){ |
4842 | + for (unsigned int i = 0; i < color.icc->colors.size(); i++) { |
4843 | ink_sum += color.icc->colors[i]; |
4844 | } |
4845 | |
4846 | - /* Some literature states that when the sum of paint values exceed 320%, it is considered to be a satured color, |
4847 | - which means the paper can get too wet due to an excessive ammount of ink. This may lead to several issues |
4848 | + /* Some literature states that when the sum of paint values exceed 320%, it is considered to be a satured |
4849 | + color, |
4850 | + which means the paper can get too wet due to an excessive ammount of ink. This may lead to several |
4851 | + issues |
4852 | such as misalignment and poor quality of printing in general.*/ |
4853 | - if ( ink_sum > 3.2 ) |
4854 | - gtk_widget_set_sensitive (_box_toomuchink, true); |
4855 | - } else { |
4856 | + if (ink_sum > 3.2) |
4857 | + gtk_widget_set_sensitive(_box_toomuchink, true); |
4858 | + } |
4859 | + else { |
4860 | gtk_widget_hide(GTK_WIDGET(_box_toomuchink)); |
4861 | } |
4862 | } |
4863 | -#endif //defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
4864 | - |
4865 | - if ( !_updatingrgba ) |
4866 | - { |
4867 | - gchar s[32]; |
4868 | - guint32 rgba; |
4869 | - |
4870 | - /* Update RGBA entry */ |
4871 | - rgba = color.toRGBA32( alpha ); |
4872 | - |
4873 | - g_snprintf (s, 32, "%08x", rgba); |
4874 | - const gchar* oldText = gtk_entry_get_text( GTK_ENTRY( _rgbae ) ); |
4875 | - if ( strcmp( oldText, s ) != 0 ) |
4876 | - { |
4877 | - g_signal_handler_block( _rgbae, _entryId ); |
4878 | - gtk_entry_set_text( GTK_ENTRY(_rgbae), s ); |
4879 | - g_signal_handler_unblock( _rgbae, _entryId ); |
4880 | - } |
4881 | - } |
4882 | +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) |
4883 | } |
4884 | |
4885 | void ColorNotebook::_setCurrentPage(int i) |
4886 | { |
4887 | gtk_notebook_set_current_page(GTK_NOTEBOOK(_book), i); |
4888 | |
4889 | - if (_buttons && _trackerList && (static_cast<size_t>(i) < _trackerList->len) ) { |
4890 | + if (_buttons && (static_cast<size_t>(i) < _available_pages.size())) { |
4891 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(_buttons[i]), TRUE); |
4892 | } |
4893 | } |
4894 | |
4895 | -void ColorNotebook::_buttonClicked(GtkWidget *widget, SPColorNotebook *colorbook) |
4896 | -{ |
4897 | - ColorNotebook* nb = dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base); |
4898 | - |
4899 | - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget))) { |
4900 | - return; |
4901 | - } |
4902 | - |
4903 | - for(gint i = 0; i < gtk_notebook_get_n_pages (GTK_NOTEBOOK (nb->_book)); i++) { |
4904 | - if (nb->_buttons[i] == widget) { |
4905 | - gtk_notebook_set_current_page (GTK_NOTEBOOK (nb->_book), i); |
4906 | - } |
4907 | - } |
4908 | -} |
4909 | - |
4910 | -void ColorNotebook::_entryGrabbed (SPColorSelector *, SPColorNotebook *colorbook) |
4911 | -{ |
4912 | - ColorNotebook* nb = dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base); |
4913 | - nb->_grabbed(); |
4914 | -} |
4915 | - |
4916 | -void ColorNotebook::_entryDragged (SPColorSelector *csel, SPColorNotebook *colorbook) |
4917 | -{ |
4918 | - gboolean oldState; |
4919 | - ColorNotebook* nb = dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base); |
4920 | - |
4921 | - oldState = nb->_dragging; |
4922 | - |
4923 | - nb->_dragging = TRUE; |
4924 | - nb->_entryModified( csel, colorbook ); |
4925 | - |
4926 | - nb->_dragging = oldState; |
4927 | -} |
4928 | - |
4929 | -void ColorNotebook::_entryReleased (SPColorSelector *, SPColorNotebook *colorbook) |
4930 | -{ |
4931 | - ColorNotebook* nb = dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base); |
4932 | - nb->_released(); |
4933 | -} |
4934 | - |
4935 | -void ColorNotebook::_entryChanged (SPColorSelector *csel, SPColorNotebook *colorbook) |
4936 | -{ |
4937 | - gboolean oldState; |
4938 | - ColorNotebook* nb = dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base); |
4939 | - |
4940 | - oldState = nb->_dragging; |
4941 | - |
4942 | - nb->_dragging = FALSE; |
4943 | - nb->_entryModified( csel, colorbook ); |
4944 | - |
4945 | - nb->_dragging = oldState; |
4946 | -} |
4947 | - |
4948 | -void ColorNotebook::_entryModified (SPColorSelector *csel, SPColorNotebook *colorbook) |
4949 | -{ |
4950 | - g_return_if_fail (colorbook != NULL); |
4951 | - g_return_if_fail (SP_IS_COLOR_NOTEBOOK (colorbook)); |
4952 | - g_return_if_fail (csel != NULL); |
4953 | - g_return_if_fail (SP_IS_COLOR_SELECTOR (csel)); |
4954 | - |
4955 | - ColorNotebook* nb = dynamic_cast<ColorNotebook*>(SP_COLOR_SELECTOR(colorbook)->base); |
4956 | - SPColor color; |
4957 | - gfloat alpha = 1.0; |
4958 | - |
4959 | - csel->base->getColorAlpha( color, alpha ); |
4960 | - nb->_updateRgbaEntry( color, alpha ); |
4961 | - nb->_updateInternals( color, alpha, nb->_dragging ); |
4962 | -} |
4963 | - |
4964 | -GtkWidget* ColorNotebook::addPage(GType page_type, guint submode) |
4965 | -{ |
4966 | - GtkWidget *page; |
4967 | - |
4968 | - page = sp_color_selector_new( page_type ); |
4969 | - if ( page ) |
4970 | - { |
4971 | - GtkWidget* tab_label = 0; |
4972 | - SPColorSelector* csel; |
4973 | - |
4974 | - csel = SP_COLOR_SELECTOR (page); |
4975 | - if ( submode > 0 ) |
4976 | - { |
4977 | - csel->base->setSubmode( submode ); |
4978 | - } |
4979 | - gtk_widget_show (page); |
4980 | - int index = csel->base ? csel->base->getSubmode() : 0; |
4981 | - const gchar* str = _(SP_COLOR_SELECTOR_GET_CLASS (csel)->name[index]); |
4982 | -// g_message( "Hitting up for tab for '%s'", str ); |
4983 | - tab_label = gtk_label_new(_(str)); |
4984 | - gint pageNum = gtk_notebook_append_page( GTK_NOTEBOOK (_book), page, tab_label ); |
4985 | - |
4986 | - // Add a button for each page |
4987 | - _buttons[pageNum] = gtk_radio_button_new_with_label(NULL, _(str)); |
4988 | - gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(_buttons[pageNum]), FALSE); |
4989 | - if (pageNum > 0) { |
4990 | - GSList *group = gtk_radio_button_get_group (GTK_RADIO_BUTTON(_buttons[0])); |
4991 | - gtk_radio_button_set_group (GTK_RADIO_BUTTON(_buttons[pageNum]), group); |
4992 | - } |
4993 | - gtk_widget_show (_buttons[pageNum]); |
4994 | - gtk_box_pack_start (GTK_BOX (_buttonbox), _buttons[pageNum], TRUE, TRUE, 0); |
4995 | - |
4996 | - g_signal_connect (G_OBJECT (_buttons[pageNum]), "clicked", G_CALLBACK (_buttonClicked), _csel); |
4997 | - g_signal_connect (G_OBJECT (page), "grabbed", G_CALLBACK (_entryGrabbed), _csel); |
4998 | - g_signal_connect (G_OBJECT (page), "dragged", G_CALLBACK (_entryDragged), _csel); |
4999 | - g_signal_connect (G_OBJECT (page), "released", G_CALLBACK (_entryReleased), _csel); |
5000 | - g_signal_connect (G_OBJECT (page), "changed", G_CALLBACK (_entryChanged), _csel); |
Mostly looks good. We reviewed the first 5000 lines (the view was truncated there). Saw a bunch of minor white space issues. Reviewed at hackfest.
We are really looking forward to getting this in for 0.92!