2
* Copyright (C) 2011 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Mirco Müller <mirco.mueller@canonical.com
23
#include <pango/pango.h>
24
#include <json-glib/json-glib.h>
26
#include "DashStyle.h"
29
#define DASH_WIDGETS_FILE DATADIR"/unity/themes/dash-widgets.json"
33
bool DashStyle::ReadColorSingle (JsonNode* root,
34
const gchar* nodeName,
35
const gchar* memberName,
38
JsonObject* object = NULL;
39
JsonNode* node = NULL;
41
if (!root || !nodeName || !memberName || !color)
44
object = json_node_get_object (root);
45
node = json_object_get_member (object, nodeName);
46
object = json_node_get_object (node);
48
const gchar* string = NULL;
49
PangoColor col = {0, 0, 0};
51
string = json_object_get_string_member (object, memberName);
52
pango_color_parse (&col, string);
53
color[R] = (double) col.red / (double) 0xffff;
54
color[G] = (double) col.green / (double) 0xffff;
55
color[B] = (double) col.blue / (double) 0xffff;
60
bool DashStyle::ReadColorArray (JsonNode* root,
61
const gchar* nodeName,
62
const gchar* memberName,
63
double colors[][CHANNELS])
65
JsonObject* object = NULL;
66
JsonNode* node = NULL;
67
JsonArray* array = NULL;
70
if (!root || !nodeName || !memberName || !colors)
73
object = json_node_get_object (root);
74
node = json_object_get_member (object, nodeName);
75
object = json_node_get_object (node);
76
array = json_object_get_array_member (object, memberName);
78
for (i = 0; i < json_array_get_length (array); i++)
80
const gchar* string = NULL;
81
PangoColor color = {0, 0, 0};
82
string = json_array_get_string_element (array, i);
83
pango_color_parse (&color, string);
84
colors[i][R] = (double) color.red / (double) 0xffff;
85
colors[i][G] = (double) color.green / (double) 0xffff;
86
colors[i][B] = (double) color.blue / (double) 0xffff;
92
bool DashStyle::ReadDoubleSingle (JsonNode* root,
93
const gchar* nodeName,
94
const gchar* memberName,
97
JsonObject* object = NULL;
98
JsonNode* node = NULL;
100
if (!root || !nodeName || !memberName || !value)
103
object = json_node_get_object (root);
104
node = json_object_get_member (object, nodeName);
105
object = json_node_get_object (node);
107
*value = json_object_get_double_member (object, memberName);
112
bool DashStyle::ReadDoubleArray (JsonNode* root,
113
const gchar* nodeName,
114
const gchar* memberName,
117
JsonObject* object = NULL;
118
JsonNode* node = NULL;
119
JsonArray* array = NULL;
122
if (!root || !nodeName || !memberName || !values)
125
object = json_node_get_object (root);
126
node = json_object_get_member (object, nodeName);
127
object = json_node_get_object (node);
128
array = json_object_get_array_member (object, memberName);
130
for (i = 0; i < json_array_get_length (array); i++)
131
values[i] = json_array_get_double_element (array, i);
136
bool DashStyle::ReadIntSingle (JsonNode* root,
137
const gchar* nodeName,
138
const gchar* memberName,
141
JsonObject* object = NULL;
142
JsonNode* node = NULL;
144
if (!root || !nodeName || !memberName || !value)
147
object = json_node_get_object (root);
148
node = json_object_get_member (object, nodeName);
149
object = json_node_get_object (node);
151
*value = json_object_get_int_member (object, memberName);
156
bool DashStyle::ReadIntArray (JsonNode* root,
157
const gchar* nodeName,
158
const gchar* memberName,
161
JsonObject* object = NULL;
162
JsonNode* node = NULL;
163
JsonArray* array = NULL;
166
if (!root || !nodeName || !memberName || !values)
169
object = json_node_get_object (root);
170
node = json_object_get_member (object, nodeName);
171
object = json_node_get_object (node);
172
array = json_object_get_array_member (object, memberName);
174
for (i = 0; i < json_array_get_length (array); i++)
175
values[i] = json_array_get_int_element (array, i);
180
bool DashStyle::ReadModeSingle (JsonNode* root,
181
const gchar* nodeName,
182
const gchar* memberName,
185
JsonObject* object = NULL;
186
JsonNode* node = NULL;
187
const gchar* string = NULL;
189
if (!root || !nodeName || !memberName || !mode)
192
object = json_node_get_object (root);
193
node = json_object_get_member (object, nodeName);
194
object = json_node_get_object (node);
196
string = json_object_get_string_member (object, memberName);
197
if (!g_strcmp0 (string, "normal"))
198
*mode = BLEND_MODE_NORMAL ;
200
if (!g_strcmp0 (string, "multiply"))
201
*mode = BLEND_MODE_MULTIPLY ;
203
if (!g_strcmp0 (string, "screen"))
204
*mode = BLEND_MODE_SCREEN ;
209
bool DashStyle::ReadModeArray (JsonNode* root,
210
const gchar* nodeName,
211
const gchar* memberName,
214
JsonObject* object = NULL;
215
JsonNode* node = NULL;
216
JsonArray* array = NULL;
219
if (!root || !nodeName || !memberName || !modes)
222
object = json_node_get_object (root);
223
node = json_object_get_member (object, nodeName);
224
object = json_node_get_object (node);
225
array = json_object_get_array_member (object, memberName);
227
for (i = 0; i < json_array_get_length (array); i++)
229
const gchar* string = NULL;
231
string = json_array_get_string_element (array, i);
233
if (!g_strcmp0 (string, "normal"))
234
modes[i] = BLEND_MODE_NORMAL;
236
if (!g_strcmp0 (string, "multiply"))
237
modes[i] = BLEND_MODE_MULTIPLY;
239
if (!g_strcmp0 (string, "screen"))
240
modes[i] = BLEND_MODE_SCREEN;
246
bool DashStyle::ReadWeightSingle (JsonNode* root,
247
const gchar* nodeName,
248
const gchar* memberName,
251
JsonObject* object = NULL;
252
JsonNode* node = NULL;
253
const gchar* string = NULL;
255
if (!root || !nodeName || !memberName || !weight)
258
object = json_node_get_object (root);
259
node = json_object_get_member (object, nodeName);
260
object = json_node_get_object (node);
262
string = json_object_get_string_member (object, memberName);
263
if (!g_strcmp0 (string, "light"))
264
*weight = FONT_WEIGHT_LIGHT;
266
if (!g_strcmp0 (string, "regular"))
267
*weight = FONT_WEIGHT_REGULAR;
269
if (!g_strcmp0 (string, "bold"))
270
*weight = FONT_WEIGHT_BOLD;
275
bool DashStyle::ReadWeightArray (JsonNode* root,
276
const gchar* nodeName,
277
const gchar* memberName,
280
JsonObject* object = NULL;
281
JsonNode* node = NULL;
282
JsonArray* array = NULL;
285
if (!root || !nodeName || !memberName || !weights)
288
object = json_node_get_object (root);
289
node = json_object_get_member (object, nodeName);
290
object = json_node_get_object (node);
291
array = json_object_get_array_member (object, memberName);
293
for (i = 0; i < json_array_get_length (array); i++)
295
const gchar* string = NULL;
297
string = json_array_get_string_element (array, i);
299
if (!g_strcmp0 (string, "light"))
300
weights[i] = FONT_WEIGHT_LIGHT;
302
if (!g_strcmp0 (string, "regular"))
303
weights[i] = FONT_WEIGHT_REGULAR;
305
if (!g_strcmp0 (string, "bold"))
306
weights[i] = FONT_WEIGHT_BOLD;
312
DashStyle::DashStyle ()
314
JsonParser* parser = NULL;
315
GError* error = NULL;
316
gboolean result = FALSE;
317
JsonNode* root = NULL;
321
parser = json_parser_new ();
322
result = json_parser_load_from_file (parser, DASH_WIDGETS_FILE, &error);
325
g_object_unref (parser);
326
g_warning ("Failure: %s", error->message);
327
g_error_free (error);
333
root = json_parser_get_root (parser); // not ref'ed
335
if (JSON_NODE_TYPE (root) != JSON_NODE_OBJECT)
337
g_warning ("Root node is not an object, fail. It's an: %s",
338
json_node_type_name (root));
339
g_object_unref (parser);
345
ReadDoubleArray (root,
348
_buttonLabelBorderOpacity);
350
ReadColorArray (root,
353
_buttonLabelBorderColor);
355
ReadDoubleArray (root,
358
_buttonLabelBorderSize);
360
ReadDoubleSingle (root,
363
&_buttonLabelTextSize);
365
ReadColorArray (root,
368
_buttonLabelTextColor);
370
ReadDoubleArray (root,
373
_buttonLabelTextOpacity);
375
ReadColorArray (root,
378
_buttonLabelFillColor);
380
ReadDoubleArray (root,
383
_buttonLabelFillOpacity);
385
ReadDoubleArray (root,
388
_buttonLabelOverlayOpacity);
393
_buttonLabelOverlayMode);
398
_buttonLabelBlurSize);
401
ReadColorSingle (root,
406
ReadDoubleSingle (root,
409
&_regularTextOpacity);
411
ReadDoubleSingle (root,
416
ReadModeSingle (root,
421
ReadWeightSingle (root,
424
&_regularTextWeight);
427
ReadDoubleSingle (root,
432
ReadColorSingle (root,
437
ReadDoubleSingle (root,
442
ReadDoubleSingle (root,
445
&_separatorOverlayOpacity);
447
ReadModeSingle (root,
450
&_separatorOverlayMode);
455
&_separatorBlurSize);
457
g_object_unref (parser);
459
// create fallback font-options
460
_defaultFontOptions = NULL;
461
_defaultFontOptions = cairo_font_options_create ();
462
if (cairo_font_options_status (_defaultFontOptions) == CAIRO_STATUS_SUCCESS)
464
cairo_font_options_set_antialias (_defaultFontOptions,
465
CAIRO_ANTIALIAS_GRAY);
466
//CAIRO_ANTIALIAS_SUBPIXEL);
467
cairo_font_options_set_subpixel_order (_defaultFontOptions,
468
CAIRO_SUBPIXEL_ORDER_RGB);
469
cairo_font_options_set_hint_style (_defaultFontOptions,
470
CAIRO_HINT_STYLE_SLIGHT);
471
cairo_font_options_set_hint_metrics (_defaultFontOptions,
472
CAIRO_HINT_METRICS_ON);
476
DashStyle::~DashStyle ()
478
if (cairo_font_options_status (_defaultFontOptions) == CAIRO_STATUS_SUCCESS)
479
cairo_font_options_destroy (_defaultFontOptions);
482
DashStyle* DashStyle::GetDefault()
484
//FIXME - replace with a nice C++ singleton method
485
static DashStyle* default_loader = NULL;
487
if (G_UNLIKELY(!default_loader))
488
default_loader = new DashStyle();
490
return default_loader;
496
double fract = val - (int) val;
499
return (double) ((int) val + 0.5f);
505
DashStyle::RoundedRect (cairo_t* cr,
515
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS &&
516
cairo_surface_get_type (cairo_get_target (cr)) != CAIRO_SURFACE_TYPE_IMAGE)
519
double radius = cornerRadius / aspect;
523
// top-left, right of the corner
524
cairo_move_to (cr, _align (x + radius), _align (y));
526
// top-right, left of the corner
527
cairo_line_to (cr, _align (x + width - radius), _align (y));
529
// top-right, below the corner
531
_align (x + width - radius),
534
-90.0f * G_PI / 180.0f,
535
0.0f * G_PI / 180.0f);
537
// bottom-right, above the corner
538
cairo_line_to (cr, _align (x + width), _align (y + height - radius));
540
// bottom-right, left of the corner
542
_align (x + width - radius),
543
_align (y + height - radius),
545
0.0f * G_PI / 180.0f,
546
90.0f * G_PI / 180.0f);
548
// bottom-left, right of the corner
549
cairo_line_to (cr, _align (x + radius), _align (y + height));
551
// bottom-left, above the corner
554
_align (y + height - radius),
556
90.0f * G_PI / 180.0f,
557
180.0f * G_PI / 180.0f);
559
// top-left, right of the corner
564
180.0f * G_PI / 180.0f,
565
270.0f * G_PI / 180.0f);
569
// top-left, right of the corner
570
cairo_move_to (cr, x + radius, y);
572
// top-right, left of the corner
573
cairo_line_to (cr, x + width - radius, y);
575
// top-right, below the corner
580
-90.0f * G_PI / 180.0f,
581
0.0f * G_PI / 180.0f);
583
// bottom-right, above the corner
584
cairo_line_to (cr, x + width, y + height - radius);
586
// bottom-right, left of the corner
591
0.0f * G_PI / 180.0f,
592
90.0f * G_PI / 180.0f);
594
// bottom-left, right of the corner
595
cairo_line_to (cr, x + radius, y + height);
597
// bottom-left, above the corner
602
90.0f * G_PI / 180.0f,
603
180.0f * G_PI / 180.0f);
605
// top-left, right of the corner
610
180.0f * G_PI / 180.0f,
611
270.0f * G_PI / 180.0f);
615
static inline void _blurinner (guchar* pixel,
634
*zR += (alpha * ((r << zprec) - *zR)) >> aprec;
635
*zG += (alpha * ((g << zprec) - *zG)) >> aprec;
636
*zB += (alpha * ((b << zprec) - *zB)) >> aprec;
637
*zA += (alpha * ((a << zprec) - *zA)) >> aprec;
639
*pixel = *zR >> zprec;
640
*(pixel + 1) = *zG >> zprec;
641
*(pixel + 2) = *zB >> zprec;
642
*(pixel + 3) = *zA >> zprec;
645
static inline void _blurrow (guchar* pixels,
661
scanline = &(pixels[line * width * channels]);
663
zR = *scanline << zprec;
664
zG = *(scanline + 1) << zprec;
665
zB = *(scanline + 2) << zprec;
666
zA = *(scanline + 3) << zprec;
668
for (index = 0; index < width; index ++)
669
_blurinner (&scanline[index * channels], &zR, &zG, &zB, &zA, alpha, aprec,
672
for (index = width - 2; index >= 0; index--)
673
_blurinner (&scanline[index * channels], &zR, &zG, &zB, &zA, alpha, aprec,
677
static inline void _blurcol (guchar* pixels,
697
zR = *((guchar*) ptr ) << zprec;
698
zG = *((guchar*) ptr + 1) << zprec;
699
zB = *((guchar*) ptr + 2) << zprec;
700
zA = *((guchar*) ptr + 3) << zprec;
702
for (index = width; index < (height - 1) * width; index += width)
703
_blurinner ((guchar*) &ptr[index * channels], &zR, &zG, &zB, &zA, alpha,
706
for (index = (height - 2) * width; index >= 0; index -= width)
707
_blurinner ((guchar*) &ptr[index * channels], &zR, &zG, &zB, &zA, alpha,
714
// height image-height
715
// channels image-channels
717
// in-place blur of image 'img' with kernel of approximate radius 'radius'
719
// blurs with two sided exponential impulse response
721
// aprec = precision of alpha parameter in fixed-point format 0.aprec
723
// zprec = precision of state parameters zR,zG,zB and zA in fp format 8.zprec
725
void _expblur (guchar* pixels,
740
// calculate the alpha such that 90% of
741
// the kernel is within the radius.
742
// (Kernel extends to infinity)
743
alpha = (gint) ((1 << aprec) * (1.0f - expf (-2.3f / (radius + 1.f))));
745
for (; row < height; row++)
746
_blurrow (pixels, width, height, channels, row, alpha, aprec, zprec);
748
for(; col < width; col++)
749
_blurcol (pixels, width, height, channels, col, alpha, aprec, zprec);
754
void DashStyle::Blur (cairo_t* cr, int size)
757
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS &&
758
cairo_surface_get_type (cairo_get_target (cr)) != CAIRO_SURFACE_TYPE_IMAGE)
761
cairo_surface_t* surface;
765
cairo_format_t format;
767
surface = cairo_get_target (cr);
769
// before we mess with the surface execute any pending drawing
770
cairo_surface_flush (surface);
772
pixels = cairo_image_surface_get_data (surface);
773
width = cairo_image_surface_get_width (surface);
774
height = cairo_image_surface_get_height (surface);
775
format = cairo_image_surface_get_format (surface);
779
case CAIRO_FORMAT_ARGB32:
780
_expblur (pixels, width, height, 4, size, 16, 7);
783
case CAIRO_FORMAT_RGB24:
784
_expblur (pixels, width, height, 3, size, 16, 7);
787
case CAIRO_FORMAT_A8:
788
_expblur (pixels, width, height, 1, size, 16, 7);
796
// inform cairo we altered the surfaces contents
797
cairo_surface_mark_dirty (surface);
800
void DashStyle::Star (cairo_t* cr, double size)
802
double outter[5][2] = {{0.0, 0.0},
807
double inner[5][2] = {{0.0, 0.0},
812
double angle[5] = {-90.0, -18.0, 54.0, 126.0, 198.0};
813
double outterRadius = size;
814
double innerRadius = size/2.0;
816
for (int i = 0; i < 5; i++)
818
outter[i][0] = outterRadius * cos (angle[i] * M_PI / 180.0);
819
outter[i][1] = outterRadius * sin (angle[i] * M_PI / 180.0);
820
inner[i][0] = innerRadius * cos ((angle[i] + 36.0) * M_PI / 180.0);
821
inner[i][1] = innerRadius * sin ((angle[i] + 36.0) * M_PI / 180.0);
824
cairo_move_to (cr, outter[0][0], outter[0][1]);
825
cairo_line_to (cr, inner[0][0], inner[0][1]);
826
cairo_line_to (cr, outter[1][0], outter[1][1]);
827
cairo_line_to (cr, inner[1][0], inner[1][1]);
828
cairo_line_to (cr, outter[2][0], outter[2][1]);
829
cairo_line_to (cr, inner[2][0], inner[2][1]);
830
cairo_line_to (cr, outter[3][0], outter[3][1]);
831
cairo_line_to (cr, inner[3][0], inner[3][1]);
832
cairo_line_to (cr, outter[4][0], outter[4][1]);
833
cairo_line_to (cr, inner[4][0], inner[4][1]);
834
cairo_close_path (cr);
837
void DashStyle::UseDefaultValues ()
840
_buttonLabelBorderColor[nux::NUX_STATE_NORMAL][R] = 0.53;
841
_buttonLabelBorderColor[nux::NUX_STATE_NORMAL][G] = 1.0;
842
_buttonLabelBorderColor[nux::NUX_STATE_NORMAL][B] = 0.66;
843
_buttonLabelBorderColor[nux::NUX_STATE_ACTIVE][R] = 1.0;
844
_buttonLabelBorderColor[nux::NUX_STATE_ACTIVE][G] = 1.0;
845
_buttonLabelBorderColor[nux::NUX_STATE_ACTIVE][B] = 1.0;
846
_buttonLabelBorderColor[nux::NUX_STATE_PRELIGHT][R] = 0.06;
847
_buttonLabelBorderColor[nux::NUX_STATE_PRELIGHT][G] = 0.13;
848
_buttonLabelBorderColor[nux::NUX_STATE_PRELIGHT][B] = 1.0;
849
_buttonLabelBorderColor[nux::NUX_STATE_SELECTED][R] = 0.07;
850
_buttonLabelBorderColor[nux::NUX_STATE_SELECTED][G] = 0.2;
851
_buttonLabelBorderColor[nux::NUX_STATE_SELECTED][B] = 0.33;
852
_buttonLabelBorderColor[nux::NUX_STATE_INSENSITIVE][R] = 0.39;
853
_buttonLabelBorderColor[nux::NUX_STATE_INSENSITIVE][G] = 0.26;
854
_buttonLabelBorderColor[nux::NUX_STATE_INSENSITIVE][B] = 0.12;
856
_buttonLabelBorderOpacity[nux::NUX_STATE_NORMAL] = 0.5;
857
_buttonLabelBorderOpacity[nux::NUX_STATE_ACTIVE] = 0.8;
858
_buttonLabelBorderOpacity[nux::NUX_STATE_PRELIGHT] = 0.5;
859
_buttonLabelBorderOpacity[nux::NUX_STATE_SELECTED] = 0.5;
860
_buttonLabelBorderOpacity[nux::NUX_STATE_INSENSITIVE] = 0.5;
862
_buttonLabelBorderSize[nux::NUX_STATE_NORMAL] = 0.5;
863
_buttonLabelBorderSize[nux::NUX_STATE_ACTIVE] = 2.0;
864
_buttonLabelBorderSize[nux::NUX_STATE_PRELIGHT] = 0.5;
865
_buttonLabelBorderSize[nux::NUX_STATE_SELECTED] = 0.5;
866
_buttonLabelBorderSize[nux::NUX_STATE_INSENSITIVE] = 0.5;
869
_buttonLabelTextSize = 1.0;
871
_buttonLabelTextColor[nux::NUX_STATE_NORMAL][R] = 1.0;
872
_buttonLabelTextColor[nux::NUX_STATE_NORMAL][G] = 1.0;
873
_buttonLabelTextColor[nux::NUX_STATE_NORMAL][B] = 1.0;
874
_buttonLabelTextColor[nux::NUX_STATE_ACTIVE][R] = 0.0;
875
_buttonLabelTextColor[nux::NUX_STATE_ACTIVE][G] = 0.0;
876
_buttonLabelTextColor[nux::NUX_STATE_ACTIVE][B] = 0.0;
877
_buttonLabelTextColor[nux::NUX_STATE_PRELIGHT][R] = 1.0;
878
_buttonLabelTextColor[nux::NUX_STATE_PRELIGHT][G] = 1.0;
879
_buttonLabelTextColor[nux::NUX_STATE_PRELIGHT][B] = 1.0;
880
_buttonLabelTextColor[nux::NUX_STATE_SELECTED][R] = 1.0;
881
_buttonLabelTextColor[nux::NUX_STATE_SELECTED][G] = 1.0;
882
_buttonLabelTextColor[nux::NUX_STATE_SELECTED][B] = 1.0;
883
_buttonLabelTextColor[nux::NUX_STATE_INSENSITIVE][R] = 1.0;
884
_buttonLabelTextColor[nux::NUX_STATE_INSENSITIVE][G] = 1.0;
885
_buttonLabelTextColor[nux::NUX_STATE_INSENSITIVE][B] = 1.0;
887
_buttonLabelTextOpacity[nux::NUX_STATE_NORMAL] = 1.0;
888
_buttonLabelTextOpacity[nux::NUX_STATE_ACTIVE] = 1.0;
889
_buttonLabelTextOpacity[nux::NUX_STATE_PRELIGHT] = 1.0;
890
_buttonLabelTextOpacity[nux::NUX_STATE_SELECTED] = 1.0;
891
_buttonLabelTextOpacity[nux::NUX_STATE_INSENSITIVE] = 1.0;
893
_buttonLabelFillColor[nux::NUX_STATE_NORMAL][R] = 0.0;
894
_buttonLabelFillColor[nux::NUX_STATE_NORMAL][G] = 0.0;
895
_buttonLabelFillColor[nux::NUX_STATE_NORMAL][B] = 0.0;
896
_buttonLabelFillColor[nux::NUX_STATE_ACTIVE][R] = 0.0;
897
_buttonLabelFillColor[nux::NUX_STATE_ACTIVE][G] = 0.0;
898
_buttonLabelFillColor[nux::NUX_STATE_ACTIVE][B] = 0.0;
899
_buttonLabelFillColor[nux::NUX_STATE_PRELIGHT][R] = 0.0;
900
_buttonLabelFillColor[nux::NUX_STATE_PRELIGHT][G] = 0.0;
901
_buttonLabelFillColor[nux::NUX_STATE_PRELIGHT][B] = 0.0;
902
_buttonLabelFillColor[nux::NUX_STATE_SELECTED][R] = 0.0;
903
_buttonLabelFillColor[nux::NUX_STATE_SELECTED][G] = 0.0;
904
_buttonLabelFillColor[nux::NUX_STATE_SELECTED][B] = 0.0;
905
_buttonLabelFillColor[nux::NUX_STATE_INSENSITIVE][R] = 0.0;
906
_buttonLabelFillColor[nux::NUX_STATE_INSENSITIVE][G] = 0.0;
907
_buttonLabelFillColor[nux::NUX_STATE_INSENSITIVE][B] = 0.0;
909
_buttonLabelFillOpacity[nux::NUX_STATE_NORMAL] = 0.0;
910
_buttonLabelFillOpacity[nux::NUX_STATE_ACTIVE] = 0.0;
911
_buttonLabelFillOpacity[nux::NUX_STATE_PRELIGHT] = 0.0;
912
_buttonLabelFillOpacity[nux::NUX_STATE_SELECTED] = 0.0;
913
_buttonLabelFillOpacity[nux::NUX_STATE_INSENSITIVE] = 0.0;
915
_buttonLabelOverlayOpacity[nux::NUX_STATE_NORMAL] = 0.0;
916
_buttonLabelOverlayOpacity[nux::NUX_STATE_ACTIVE] = 0.3;
917
_buttonLabelOverlayOpacity[nux::NUX_STATE_PRELIGHT] = 0.0;
918
_buttonLabelOverlayOpacity[nux::NUX_STATE_SELECTED] = 0.0;
919
_buttonLabelOverlayOpacity[nux::NUX_STATE_INSENSITIVE] = 0.0;
921
_buttonLabelOverlayMode[nux::NUX_STATE_NORMAL] = BLEND_MODE_NORMAL;
922
_buttonLabelOverlayMode[nux::NUX_STATE_ACTIVE] = BLEND_MODE_NORMAL;
923
_buttonLabelOverlayMode[nux::NUX_STATE_PRELIGHT] = BLEND_MODE_NORMAL;
924
_buttonLabelOverlayMode[nux::NUX_STATE_SELECTED] = BLEND_MODE_NORMAL;
925
_buttonLabelOverlayMode[nux::NUX_STATE_INSENSITIVE] = BLEND_MODE_NORMAL;
927
_buttonLabelBlurSize[nux::NUX_STATE_NORMAL] = 0;
928
_buttonLabelBlurSize[nux::NUX_STATE_ACTIVE] = 5;
929
_buttonLabelBlurSize[nux::NUX_STATE_PRELIGHT] = 0;
930
_buttonLabelBlurSize[nux::NUX_STATE_SELECTED] = 0;
931
_buttonLabelBlurSize[nux::NUX_STATE_INSENSITIVE] = 0;
934
_regularTextColor[R] = 1.0;
935
_regularTextColor[G] = 1.0;
936
_regularTextColor[B] = 1.0;
937
_regularTextOpacity = 1.0;
938
_regularTextSize = 13.0;
939
_regularTextMode = BLEND_MODE_NORMAL;
940
_regularTextWeight = FONT_WEIGHT_LIGHT;
943
_separatorSize = 1.0;
944
_separatorColor[R] = 1.0;
945
_separatorColor[G] = 1.0;
946
_separatorColor[B] = 1.0;
947
_separatorOpacity = 0.15;
948
_separatorOverlayOpacity = 0.47;
949
_separatorOverlayMode = BLEND_MODE_NORMAL;
950
_separatorBlurSize = 6;
953
void DashStyle::ArrowPath (cairo_t* cr, Arrow arrow)
957
double w = cairo_image_surface_get_width (cairo_get_target (cr));
958
double h = cairo_image_surface_get_height (cairo_get_target (cr));
962
// the real shape from the SVG
963
// 3.5/1.5, 20.5/22.5, (17x21)
966
cairo_move_to (cr, xt, yt);
967
cairo_curve_to (cr, xt - 1.511, yt - 1.006, xt - 3.019, yt - 1.971, xt - 4.527, yt - 2.897);
970
cairo_curve_to (cr, 10.213, 5.2, 8.743, 4.335, 7.313, 3.532);
971
cairo_curve_to (cr, 8.743, 4.335, 4.613, 2.051, 3.5, 1.5);
972
cairo_rel_line_to (cr, 0.0, 21.0);
973
cairo_rel_curve_to (cr, 1.164, -0.552, 2.461, -1.229, 3.892, -2.032);
974
cairo_rel_curve_to (cr, 1.431, -0.803, 2.9, -1.682, 4.409, -2.634);
975
cairo_rel_curve_to (cr, 1.51, -0.953, 3.004, -1.932, 4.488, -2.937);
976
cairo_rel_curve_to (cr, 1.481, -1.002, 2.887, -1.981, 4.211, -2.935);
977
cairo_curve_to (cr, 19.176, 11.009, 17.759, 10.03, 16.25, 9.028);
978
cairo_close_path (cr);*/
980
if (arrow == ARROW_LEFT || arrow == ARROW_BOTH)
984
cairo_move_to (cr, _align (x), _align (y));
985
cairo_line_to (cr, _align (x + 5.0), _align (y + 3.5));
986
cairo_line_to (cr, _align (x), _align (y + 7.0));
987
cairo_close_path (cr);
990
if (arrow == ARROW_RIGHT || arrow == ARROW_BOTH)
994
cairo_move_to (cr, _align (x), _align (y));
995
cairo_line_to (cr, _align (x - 5.0), _align (y + 3.5));
996
cairo_line_to (cr, _align (x), _align (y + 7.0));
997
cairo_close_path (cr);
1001
void DashStyle::ButtonOutlinePath (cairo_t* cr, bool align)
1005
double w = cairo_image_surface_get_width (cairo_get_target (cr)) - 4.0;
1006
double h = cairo_image_surface_get_height (cairo_get_target (cr)) - 4.0;
1010
// - these absolute values are the "cost" of getting only a SVG from design
1011
// and not a generic formular how to approximate the curve-shape, thus
1012
// the smallest possible button-size is 22.18x24.0
1013
double width = w - 22.18;
1014
double height = h - 24.0;
1016
xt = x + width + 22.18;
1022
cairo_move_to (cr, _align(xt), _align(yt));
1023
cairo_curve_to (cr, _align(xt - 0.103),
1028
_align(yt - 9.267));
1031
cairo_curve_to (cr, _align (xt - 1.722),
1032
_align (yt - 1.823),
1033
_align (xt - 4.531),
1034
_align (yt - 2.735),
1036
_align (yt - 2.735));
1041
cairo_line_to (cr, _align (xt - width), _align (yt));
1045
cairo_curve_to (cr, _align (xt - 3.748),
1047
_align (xt - 6.507),
1048
_align (yt + 0.912),
1049
_align (xt - 8.279),
1050
_align (yt + 2.735));
1053
cairo_curve_to (cr, _align (xt - 1.773),
1054
_align (yt + 1.822),
1055
_align (xt - 2.708),
1056
_align (yt + 4.911),
1057
_align (xt - 2.811),
1058
_align (yt + 9.267));
1063
cairo_line_to (cr, _align (xt), _align (yt + height));
1067
cairo_curve_to (cr, _align (xt + 0.103),
1068
_align (yt + 4.355),
1069
_align (xt + 1.037),
1070
_align (yt + 7.444),
1071
_align (xt + 2.811),
1072
_align (yt + 9.267));
1075
cairo_curve_to (cr, _align (xt + 1.772),
1076
_align (yt + 1.823),
1077
_align (xt + 4.531),
1078
_align (yt + 2.735),
1080
_align (yt + 2.735));
1085
cairo_line_to (cr, _align (xt + width), _align (yt));
1089
cairo_curve_to (cr, _align (xt + 3.748),
1091
_align (xt + 6.507),
1092
_align (yt - 0.912),
1093
_align (xt + 8.279),
1094
_align (yt - 2.735));
1097
cairo_curve_to (cr, _align (xt + 1.773),
1098
_align (yt - 1.822),
1099
_align (xt + 2.708),
1100
_align (yt - 4.911),
1101
_align (xt + 2.811),
1102
_align (yt - 9.267));
1107
cairo_move_to (cr, x + width + 22.18, y + 12.0);
1108
cairo_rel_curve_to (cr, -0.103, -4.355, -1.037, -7.444, -2.811, -9.267);
1109
cairo_rel_curve_to (cr, -1.722, -1.823, -4.531, -2.735, -8.28, -2.735);
1112
cairo_rel_line_to (cr, -width, 0.0);
1115
cairo_rel_curve_to (cr, -3.748, 0.0, -6.507, 0.912, -8.279, 2.735);
1116
cairo_rel_curve_to (cr, -1.773, 1.822, -2.708, 4.911, -2.811, 9.267);
1119
cairo_rel_line_to (cr, 0.0, height);
1122
cairo_rel_curve_to (cr, 0.103, 4.355, 1.037, 7.444, 2.811, 9.267);
1123
cairo_rel_curve_to (cr, 1.772, 1.823, 4.531, 2.735, 8.28, 2.735);
1126
cairo_rel_line_to (cr, width, 0.0);
1129
cairo_rel_curve_to (cr, 3.748, 0.0, 6.507, -0.912, 8.279, -2.735);
1130
cairo_rel_curve_to (cr, 1.773, -1.822, 2.708, -4.911, 2.811, -9.267);
1134
cairo_close_path (cr);
1137
void DashStyle::RoundedRectSegment (cairo_t* cr,
1141
double cornerRadius,
1148
double radius = cornerRadius / aspect;
1149
double arrow_w = radius / 1.5;
1150
double arrow_h = radius / 2.0;
1155
// top-left, right of the corner
1156
cairo_move_to (cr, x + radius, y);
1159
cairo_line_to (cr, x + width, y);
1161
if (arrow == ARROW_RIGHT && state == nux::NUX_STATE_ACTIVE)
1163
cairo_line_to (cr, x + width, y + height / 2.0 - arrow_h);
1164
cairo_line_to (cr, x + width - arrow_w, y + height / 2.0);
1165
cairo_line_to (cr, x + width, y + height / 2.0 + arrow_h);
1169
cairo_line_to (cr, x + width, y + height);
1171
// bottom-left, right of the corner
1172
cairo_line_to (cr, x + radius, y + height);
1174
// bottom-left, above the corner
1177
y + height - radius,
1179
90.0f * G_PI / 180.0f,
1180
180.0f * G_PI / 180.0f);
1182
// top-left, right of the corner
1187
180.0f * G_PI / 180.0f,
1188
270.0f * G_PI / 180.0f);
1191
case SEGMENT_MIDDLE:
1193
cairo_move_to (cr, x, y);
1196
cairo_line_to (cr, x + width, y);
1198
if ((arrow == ARROW_RIGHT || arrow == ARROW_BOTH) && state == nux::NUX_STATE_ACTIVE)
1200
cairo_line_to (cr, x + width, y + height / 2.0 - arrow_h);
1201
cairo_line_to (cr, x + width - arrow_w, y + height / 2.0);
1202
cairo_line_to (cr, x + width, y + height / 2.0 + arrow_h);
1206
cairo_line_to (cr, x + width, y + height);
1209
cairo_line_to (cr, x, y + height);
1211
if ((arrow == ARROW_LEFT || arrow == ARROW_BOTH) && state == nux::NUX_STATE_ACTIVE)
1213
cairo_line_to (cr, x, y + height / 2.0 + arrow_h);
1214
cairo_line_to (cr, x + arrow_w, y + height / 2.0);
1215
cairo_line_to (cr, x, y + height / 2.0 - arrow_h);
1219
cairo_close_path (cr);
1223
// top-left, right of the corner
1224
cairo_move_to (cr, x, y);
1226
// top-right, left of the corner
1227
cairo_line_to (cr, x + width - radius, y);
1229
// top-right, below the corner
1234
-90.0f * G_PI / 180.0f,
1235
0.0f * G_PI / 180.0f);
1237
// bottom-right, above the corner
1238
cairo_line_to (cr, x + width, y + height - radius);
1240
// bottom-right, left of the corner
1243
y + height - radius,
1245
0.0f * G_PI / 180.0f,
1246
90.0f * G_PI / 180.0f);
1249
cairo_line_to (cr, x, y + height);
1251
if (arrow == ARROW_LEFT && state == nux::NUX_STATE_ACTIVE)
1253
cairo_line_to (cr, x, y + height / 2.0 + arrow_h);
1254
cairo_line_to (cr, x + arrow_w, y + height / 2.0);
1255
cairo_line_to (cr, x, y + height / 2.0 - arrow_h);
1259
cairo_close_path (cr);
1264
void DashStyle::ButtonOutlinePathSegment (cairo_t* cr, Segment segment)
1268
double w = cairo_image_surface_get_width (cairo_get_target (cr));
1269
double h = cairo_image_surface_get_height (cairo_get_target (cr)) - 4.0;
1273
// - these absolute values are the "cost" of getting only a SVG from design
1274
// and not a generic formular how to approximate the curve-shape, thus
1275
// the smallest possible button-size is 22.18x24.0
1276
double width = w - 22.18;
1277
double height = h - 24.0;
1279
xt = x + width + 22.18;
1285
yt -= (9.267 + 2.735);
1286
cairo_move_to (cr, _align (xt), _align (yt));
1287
xt -= (2.811 + 8.28);
1290
cairo_line_to (cr, _align (xt - width), _align (yt));
1294
cairo_curve_to (cr, _align (xt - 3.748),
1296
_align (xt - 6.507),
1297
_align (yt + 0.912),
1298
_align (xt - 8.279),
1299
_align (yt + 2.735));
1302
cairo_curve_to (cr, _align (xt - 1.773),
1303
_align (yt + 1.822),
1304
_align (xt - 2.708),
1305
_align (yt + 4.911),
1306
_align (xt - 2.811),
1307
_align (yt + 9.267));
1312
cairo_line_to (cr, _align (xt), _align (yt + height));
1316
cairo_curve_to (cr, _align (xt + 0.103),
1317
_align (yt + 4.355),
1318
_align (xt + 1.037),
1319
_align (yt + 7.444),
1320
_align (xt + 2.811),
1321
_align (yt + 9.267));
1324
cairo_curve_to (cr, _align (xt + 1.772),
1325
_align (yt + 1.823),
1326
_align (xt + 4.531),
1327
_align (yt + 2.735),
1329
_align (yt + 2.735));
1330
xt += 8.28 + width + 8.279 + 2.811;
1334
cairo_line_to (cr, _align (xt), _align (yt));
1336
cairo_close_path (cr);
1339
case SEGMENT_MIDDLE:
1340
yt -= (9.267 + 2.735);
1341
cairo_move_to (cr, _align (xt), _align (yt));
1342
xt -= (2.811 + 8.28);
1345
cairo_line_to (cr, _align (xt - width - 8.279 - 2.811), _align (yt));
1352
yt += 9.267 + height + 2.735 + 9.267;
1355
cairo_line_to (cr, _align (xt), _align (yt));
1359
xt += 8.28 + width + 8.279 + 2.811;
1361
cairo_line_to (cr, _align (xt), _align (yt));
1363
cairo_close_path (cr);
1368
cairo_move_to (cr, _align(xt), _align(yt));
1369
cairo_curve_to (cr, _align(xt - 0.103),
1374
_align(yt - 9.267));
1377
cairo_curve_to (cr, _align (xt - 1.722),
1378
_align (yt - 1.823),
1379
_align (xt - 4.531),
1380
_align (yt - 2.735),
1382
_align (yt - 2.735));
1383
xt -= (8.28 + width + 8.279 + 2.811);
1387
cairo_line_to (cr, _align (xt), _align (yt));
1390
yt += 9.267 + 2.735 + height + 2.735 + 9.267;
1391
cairo_line_to (cr, _align (xt), _align (yt));
1397
cairo_line_to (cr, _align (xt + width), _align (yt));
1401
cairo_curve_to (cr, _align (xt + 3.748),
1403
_align (xt + 6.507),
1404
_align (yt - 0.912),
1405
_align (xt + 8.279),
1406
_align (yt - 2.735));
1409
cairo_curve_to (cr, _align (xt + 1.773),
1410
_align (yt - 1.822),
1411
_align (xt + 2.708),
1412
_align (yt - 4.911),
1413
_align (xt + 2.811),
1414
_align (yt - 9.267));
1416
cairo_close_path (cr);
1421
void DashStyle::GetTextExtents (int& width,
1425
const std::string text)
1427
cairo_surface_t* surface = NULL;
1429
PangoLayout* layout = NULL;
1430
PangoFontDescription* desc = NULL;
1431
PangoContext* pangoCtx = NULL;
1432
PangoRectangle inkRect = {0, 0, 0, 0};
1434
char* fontName = NULL;
1435
GdkScreen* screen = gdk_screen_get_default(); // is not ref'ed
1436
GtkSettings* settings = gtk_settings_get_default();// is not ref'ed
1438
surface = cairo_image_surface_create(CAIRO_FORMAT_A1, 1, 1);
1439
cr = cairo_create(surface);
1441
cairo_set_font_options(cr, _defaultFontOptions);
1443
cairo_set_font_options(cr, gdk_screen_get_font_options(screen));
1444
layout = pango_cairo_create_layout(cr);
1446
g_object_get(settings, "gtk-font-name", &fontName, NULL);
1448
desc = pango_font_description_from_string("Sans 10");
1451
desc = pango_font_description_from_string(fontName);
1455
pango_layout_set_font_description(layout, desc);
1456
pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
1457
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
1458
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
1460
pango_layout_set_markup(layout, text.c_str(), -1);
1461
pango_layout_set_height(layout, maxHeight);
1462
pango_layout_set_width(layout, maxWidth * PANGO_SCALE);
1464
pangoCtx = pango_layout_get_context(layout); // is not ref'ed
1467
pango_cairo_context_set_font_options(pangoCtx, _defaultFontOptions);
1469
pango_cairo_context_set_font_options(pangoCtx,
1470
gdk_screen_get_font_options(screen));
1472
g_object_get(settings, "gtk-xft-dpi", &dpi, NULL);
1475
// use some default DPI-value
1476
pango_cairo_context_set_resolution(pangoCtx, 96.0f);
1480
pango_cairo_context_set_resolution(pangoCtx,
1481
(float) dpi / (float) PANGO_SCALE);
1483
pango_layout_context_changed(layout);
1484
pango_layout_get_extents(layout, &inkRect, NULL);
1486
width = inkRect.width / PANGO_SCALE;
1487
height = inkRect.height / PANGO_SCALE;
1490
pango_font_description_free(desc);
1491
g_object_unref(layout);
1493
cairo_surface_destroy(surface);
1496
void DashStyle::Text (cairo_t* cr,
1506
PangoLayout* layout = NULL;
1507
PangoFontDescription* desc = NULL;
1508
PangoContext* pangoCtx = NULL;
1510
GdkScreen* screen = gdk_screen_get_default(); // not ref'ed
1511
GtkSettings* settings = gtk_settings_get_default(); // not ref'ed
1512
gchar* fontName = NULL;
1514
w = cairo_image_surface_get_width (cairo_get_target (cr));
1515
h = cairo_image_surface_get_height (cairo_get_target (cr));
1518
cairo_set_font_options(cr, _defaultFontOptions);
1520
cairo_set_font_options(cr, gdk_screen_get_font_options(screen));
1521
layout = pango_cairo_create_layout(cr);
1523
g_object_get(settings, "gtk-font-name", &fontName, NULL);
1525
desc = pango_font_description_from_string("Sans 10");
1527
desc = pango_font_description_from_string(fontName);
1530
switch (_regularTextWeight)
1532
case FONT_WEIGHT_REGULAR:
1533
weight = PANGO_WEIGHT_NORMAL;
1536
case FONT_WEIGHT_LIGHT:
1537
weight = PANGO_WEIGHT_LIGHT;
1540
case FONT_WEIGHT_BOLD:
1541
weight = PANGO_WEIGHT_BOLD;
1544
pango_font_description_set_weight(desc, weight);
1546
pango_layout_set_font_description(layout, desc);
1547
pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
1548
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
1550
pango_layout_set_markup(layout, label.c_str(), -1);
1551
pango_layout_set_width(layout, w * PANGO_SCALE);
1553
pango_layout_set_height(layout, h);
1554
pangoCtx = pango_layout_get_context(layout); // is not ref'ed
1557
pango_cairo_context_set_font_options(pangoCtx, _defaultFontOptions);
1559
pango_cairo_context_set_font_options(pangoCtx,
1560
gdk_screen_get_font_options(screen));
1562
g_object_get(settings, "gtk-xft-dpi", &dpi, NULL);
1565
// use some default DPI-value
1566
pango_cairo_context_set_resolution(pangoCtx, 96.0f);
1570
pango_cairo_context_set_resolution(pangoCtx,
1571
(float) dpi / (float) PANGO_SCALE);
1574
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1575
cairo_set_source_rgba (cr, color[R], color[G], color[B], opacity);
1576
pango_layout_context_changed(layout);
1577
PangoRectangle ink = {0, 0, 0, 0};
1578
PangoRectangle log = {0, 0, 0, 0};
1579
pango_layout_get_extents (layout, &ink, &log);
1580
x = ((double) w - pango_units_to_double (ink.width)) / 2.0;
1581
y = ((double) h - pango_units_to_double (log.height)) / 2.0;
1582
cairo_move_to (cr, x, y);
1583
pango_cairo_show_layout(cr, layout);
1586
pango_font_description_free(desc);
1587
g_object_unref(layout);
1591
cairo_operator_t DashStyle::SetBlendMode (cairo_t* cr, BlendMode mode)
1594
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
1595
return CAIRO_OPERATOR_OVER;
1597
cairo_operator_t old;
1599
old = cairo_get_operator (cr);
1601
if (mode == BLEND_MODE_NORMAL)
1602
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
1604
if (mode == BLEND_MODE_MULTIPLY)
1605
cairo_set_operator (cr, CAIRO_OPERATOR_MULTIPLY);
1607
if (mode == BLEND_MODE_SCREEN)
1608
cairo_set_operator (cr, CAIRO_OPERATOR_SCREEN);
1613
void DashStyle::DrawOverlay (cairo_t* cr,
1619
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS ||
1624
cairo_surface_t* target = NULL;
1625
const unsigned char* data = NULL;
1629
cairo_format_t format = CAIRO_FORMAT_INVALID;
1630
unsigned char* buffer = NULL;
1631
cairo_surface_t* surface = NULL;
1632
cairo_t* blurred_cr = NULL;
1633
cairo_operator_t old = CAIRO_OPERATOR_CLEAR;
1635
// aquire info about image-surface
1636
target = cairo_get_target (cr);
1637
data = cairo_image_surface_get_data (target);
1638
width = cairo_image_surface_get_width (target);
1639
height = cairo_image_surface_get_height (target);
1640
stride = cairo_image_surface_get_stride (target);
1641
format = cairo_image_surface_get_format (target);
1644
buffer = (unsigned char*) calloc (1, height * stride);
1648
// copy initial image-surface
1649
memcpy (buffer, data, height * stride);
1650
surface = cairo_image_surface_create_for_data (buffer,
1655
if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
1657
cairo_surface_destroy (surface);
1663
blurred_cr = cairo_create (surface);
1664
if (cairo_status (blurred_cr) != CAIRO_STATUS_SUCCESS)
1666
cairo_destroy (blurred_cr);
1667
cairo_surface_destroy (surface);
1672
// blur and blend overlay onto initial image-surface
1673
Blur (blurred_cr, blurSize);
1674
//cairo_surface_write_to_png (surface, "/tmp/overlay-surface.png");
1675
cairo_set_source_surface (cr, surface, 0.0, 0.0);
1676
old = SetBlendMode (cr, mode);
1677
cairo_paint_with_alpha (cr, opacity);
1680
cairo_destroy (blurred_cr);
1681
cairo_surface_destroy (surface);
1683
cairo_set_operator (cr, old);
1686
bool DashStyle::Button (cairo_t* cr, nux::State state, std::string label)
1689
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
1692
if (cairo_surface_get_type (cairo_get_target (cr)) != CAIRO_SURFACE_TYPE_IMAGE)
1695
//ButtonOutlinePath (cr, true);
1696
double w = cairo_image_surface_get_width (cairo_get_target (cr));
1697
double h = cairo_image_surface_get_height (cairo_get_target (cr));
1707
if (_buttonLabelFillOpacity[state] != 0.0)
1709
cairo_set_source_rgba (cr,
1710
_buttonLabelFillColor[state][R],
1711
_buttonLabelFillColor[state][G],
1712
_buttonLabelFillColor[state][B],
1713
_buttonLabelFillOpacity[state]);
1714
cairo_fill_preserve (cr);
1716
cairo_set_source_rgba (cr,
1717
_buttonLabelBorderColor[state][R],
1718
_buttonLabelBorderColor[state][G],
1719
_buttonLabelBorderColor[state][B],
1720
_buttonLabelBorderOpacity[state]);
1721
cairo_set_line_width (cr, _buttonLabelBorderSize[state]);
1724
_buttonLabelTextSize,
1725
_buttonLabelTextColor[state],
1726
_buttonLabelTextOpacity[state],
1732
bool DashStyle::StarEmpty (cairo_t* cr, nux::State state)
1735
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
1738
if (cairo_surface_get_type (cairo_get_target (cr)) != CAIRO_SURFACE_TYPE_IMAGE)
1741
double w = cairo_image_surface_get_width (cairo_get_target (cr));
1742
double h = cairo_image_surface_get_height (cairo_get_target (cr));
1743
double radius = .85 * h / 2.0;
1746
cairo_translate (cr, w / 2.0, h / 2.0);
1748
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.2);
1749
cairo_fill_preserve (cr);
1750
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
1757
bool DashStyle::StarHalf (cairo_t* cr, nux::State state)
1760
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
1763
if (cairo_surface_get_type (cairo_get_target (cr)) != CAIRO_SURFACE_TYPE_IMAGE)
1766
double w = cairo_image_surface_get_width (cairo_get_target (cr));
1767
double h = cairo_image_surface_get_height (cairo_get_target (cr));
1768
double radius = .85 * h / 2.0;
1770
cairo_pattern_t* pattern = NULL;
1771
pattern = cairo_pattern_create_linear (0.0, 0.0, w, 0.0);
1772
cairo_pattern_add_color_stop_rgba (pattern, 0.0, 1.0, 1.0, 1.0, 1.0);
1773
cairo_pattern_add_color_stop_rgba (pattern, .5, 1.0, 1.0, 1.0, 1.0);
1774
cairo_pattern_add_color_stop_rgba (pattern, .5 + 0.01, 1.0, 1.0, 1.0, 0.2);
1775
cairo_pattern_add_color_stop_rgba (pattern, 1.0, 1.0, 1.0, 1.0, 0.2);
1776
cairo_set_source (cr, pattern);
1779
cairo_translate (cr, w / 2.0, h / 2.0);
1781
cairo_fill_preserve (cr);
1782
cairo_pattern_destroy (pattern);
1783
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
1790
bool DashStyle::StarFull (cairo_t* cr, nux::State state)
1793
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
1796
if (cairo_surface_get_type (cairo_get_target (cr)) != CAIRO_SURFACE_TYPE_IMAGE)
1799
double w = cairo_image_surface_get_width (cairo_get_target (cr));
1800
double h = cairo_image_surface_get_height (cairo_get_target (cr));
1801
double radius = .85 * h / 2.0;
1804
cairo_translate (cr, w / 2.0, h / 2.0);
1806
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
1807
cairo_fill_preserve (cr);
1808
cairo_stroke (cr); // to make sure it's as "large" as the empty and half ones
1814
bool DashStyle::MultiRangeSegment (cairo_t* cr,
1821
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
1824
if (cairo_surface_get_type (cairo_get_target (cr)) != CAIRO_SURFACE_TYPE_IMAGE)
1827
//ButtonOutlinePathSegment (cr, segment);
1830
double w = cairo_image_surface_get_width (cairo_get_target (cr));
1831
double h = cairo_image_surface_get_height (cairo_get_target (cr)) - 4.0;
1833
if (segment == SEGMENT_LEFT)
1839
if (segment == SEGMENT_RIGHT)
1844
RoundedRectSegment (cr,
1855
if (_buttonLabelFillOpacity[state] != 0.0)
1857
cairo_set_source_rgba (cr,
1858
_buttonLabelFillColor[state][R],
1859
_buttonLabelFillColor[state][G],
1860
_buttonLabelFillColor[state][B],
1861
_buttonLabelFillOpacity[state]);
1862
cairo_fill_preserve (cr);
1864
cairo_set_source_rgba (cr,
1865
_buttonLabelBorderColor[state][R],
1866
_buttonLabelBorderColor[state][G],
1867
_buttonLabelBorderColor[state][B],
1868
_buttonLabelBorderOpacity[state]);
1869
cairo_set_line_width (cr, _buttonLabelBorderSize[state]);
1872
_buttonLabelTextSize,
1873
_buttonLabelTextColor[state],
1874
_buttonLabelTextOpacity[state],
1880
bool DashStyle::TrackViewNumber (cairo_t* cr,
1882
std::string trackNumber)
1885
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
1888
if (cairo_surface_get_type (cairo_get_target (cr)) != CAIRO_SURFACE_TYPE_IMAGE)
1894
bool DashStyle::TrackViewPlay (cairo_t* cr,
1898
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
1901
if (cairo_surface_get_type (cairo_get_target (cr)) != CAIRO_SURFACE_TYPE_IMAGE)
1907
bool DashStyle::TrackViewPause (cairo_t* cr,
1911
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
1914
if (cairo_surface_get_type (cairo_get_target (cr)) != CAIRO_SURFACE_TYPE_IMAGE)
1920
bool DashStyle::TrackViewProgress (cairo_t* cr)
1923
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
1926
if (cairo_surface_get_type (cairo_get_target (cr)) != CAIRO_SURFACE_TYPE_IMAGE)
1932
bool DashStyle::SeparatorVert (cairo_t* cr)
1935
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
1938
if (cairo_surface_get_type (cairo_get_target (cr)) != CAIRO_SURFACE_TYPE_IMAGE)
1941
double w = cairo_image_surface_get_width (cairo_get_target (cr));
1942
double h = cairo_image_surface_get_height (cairo_get_target (cr));
1946
cairo_set_line_width (cr, _separatorSize);
1947
cairo_set_source_rgba (cr,
1952
cairo_move_to (cr, _align (x), _align (y));
1953
cairo_line_to (cr, _align (x), _align (h - 4.0));
1957
_separatorOverlayOpacity,
1958
_separatorOverlayMode,
1959
_separatorBlurSize);
1964
bool DashStyle::SeparatorHoriz (cairo_t* cr)
1967
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
1970
if (cairo_surface_get_type (cairo_get_target (cr)) != CAIRO_SURFACE_TYPE_IMAGE)
1973
double w = cairo_image_surface_get_width (cairo_get_target (cr));
1974
double h = cairo_image_surface_get_height (cairo_get_target (cr));
1978
cairo_set_line_width (cr, _separatorSize);
1979
cairo_set_source_rgba (cr,
1984
cairo_move_to (cr, _align (x), _align (y));
1985
cairo_line_to (cr, _align (w - 4.0), _align (y));
1989
_separatorOverlayOpacity,
1990
_separatorOverlayMode,
1991
_separatorBlurSize);