Skip to content

Commit d489029

Browse files
committed
Avoid using Gdk.RGBA
1 parent 81a3a00 commit d489029

File tree

3 files changed

+49
-62
lines changed

3 files changed

+49
-62
lines changed

lib/Drawing/Color.vala

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,25 @@ namespace Gala.Drawing {
99
* A class containing an RGBA color and methods for more powerful color manipulation.
1010
*/
1111
public class Color : GLib.Object {
12-
public const Gdk.RGBA LIGHT_BACKGROUND = { (250f / 255f), (250f / 255f), (250f / 255f), 1};
13-
public const Gdk.RGBA DARK_BACKGROUND = { (51 / 255f), (51 / 255f), (51 / 255f), 1};
14-
public const Gdk.RGBA LIGHT_BORDER = { 0, 0, 0, 0.2f};
15-
public const Gdk.RGBA DARK_BORDER = { 0, 0, 0, 0.75f};
16-
public const Gdk.RGBA LIGHT_HIGHLIGHT = { 255, 255, 255, 1};
17-
public const Gdk.RGBA DARK_HIGHLIGHT = { 255, 255, 255, 0.05f};
18-
public const Gdk.RGBA TOOLTIP_BACKGROUND = { 0, 0, 0, 1};
19-
public const Gdk.RGBA TOOLTIP_TEXT_COLOR = { 1, 1, 1, 1};
12+
#if !HAS_MUTTER47
13+
public const Clutter.Color LIGHT_BACKGROUND = { 250, 250, 250, 255};
14+
public const Clutter.Color DARK_BACKGROUND = { 51, 51, 51, 255};
15+
public const Clutter.Color LIGHT_BORDER = { 0, 0, 0, 51};
16+
public const Clutter.Color DARK_BORDER = { 0, 0, 0, 191};
17+
public const Clutter.Color LIGHT_HIGHLIGHT = { 255, 255, 255, 255};
18+
public const Clutter.Color DARK_HIGHLIGHT = { 255, 255, 255, 13};
19+
public const Clutter.Color TOOLTIP_BACKGROUND = { 0, 0, 0, 255};
20+
public const Clutter.Color TOOLTIP_TEXT_COLOR = { 255, 255, 255, 255};
21+
#else
22+
public const Cogl.Color LIGHT_BACKGROUND = { 250, 250, 250, 255};
23+
public const Cogl.Color DARK_BACKGROUND = { 51, 51, 51, 255};
24+
public const Cogl.Color LIGHT_BORDER = { 0, 0, 0, 51};
25+
public const Cogl.Color DARK_BORDER = { 0, 0, 0, 191};
26+
public const Cogl.Color LIGHT_HIGHLIGHT = { 255, 255, 255, 255};
27+
public const Cogl.Color DARK_HIGHLIGHT = { 255, 255, 255, 13};
28+
public const Cogl.Color TOOLTIP_BACKGROUND = { 0, 0, 0, 255};
29+
public const Cogl.Color TOOLTIP_TEXT_COLOR = { 255, 255, 255, 255};
30+
#endif
2031

2132
/**
2233
* The value of the red channel, with 0 being the lowest value and 1.0 being the greatest value.
@@ -93,15 +104,6 @@ namespace Gala.Drawing {
93104
this.A = A;
94105
}
95106

96-
/**
97-
* Constructs a new {@link Gala.Drawing.Color} from a {@link Gdk.RGBA}.
98-
*
99-
* @param color the {@link Gdk.RGBA}
100-
*/
101-
public Color.from_rgba (Gdk.RGBA color) {
102-
set_from_rgba (color);
103-
}
104-
105107
/**
106108
* Constructs a new {@link Gala.Drawing.Color} from a string.
107109
*
@@ -112,14 +114,20 @@ namespace Gala.Drawing {
112114
* * A RGB color in the form “rgb(r,g,b)” (In this case the color will have full opacity)
113115
* * A RGBA color in the form “rgba(r,g,b,a)”
114116
*
115-
* For more details on formatting and how this function works see {@link Gdk.RGBA.parse}
117+
* For more details on formatting and how this function works see {@link Clutter.Color.from_string}
116118
*
117119
* @param color the string specifying the color
118120
*/
119121
public Color.from_string (string color) {
120-
Gdk.RGBA rgba = Gdk.RGBA ();
121-
rgba.parse (color);
122-
set_from_rgba (rgba);
122+
#if !HAS_MUTTER47
123+
var parsed_color = Clutter.Color.from_string (color);
124+
#else
125+
var parsed_color = Cogl.Color.from_string (color);
126+
#endif
127+
R = parsed_color.red / 255.0;
128+
G = parsed_color.green / 255.0;
129+
B = parsed_color.blue / 255.0;
130+
A = parsed_color.alpha / 255.0;
123131
}
124132

125133
/**
@@ -508,13 +516,17 @@ namespace Gala.Drawing {
508516
* Note: that this string representation may lose some precision, since r, g and b are represented
509517
* as 8-bit integers. If this is a concern, you should use a different representation.
510518
*
511-
* This returns the same string as a {@link Gdk.RGBA} would return in {@link Gdk.RGBA.to_string}
519+
* This returns the same string as a {@link Clutter.Color} would return in {@link Clutter.Color.to_string}
512520
*
513521
* @return the text string
514522
*/
515523
public string to_string () {
516-
Gdk.RGBA rgba = {(float)R, (float)G, (float)B, (float)A};
517-
return rgba.to_string ();
524+
#if !HAS_MUTTER47
525+
Clutter.Color color = { (uint8) (R * 255), (uint8) (G * 255), (uint8) (B * 255), (uint8) (A * 255) };
526+
#else
527+
Cogl.Color color = { (uint8) (R * 255), (uint8) (G * 255), (uint8) (B * 255), (uint8) (A * 255) };
528+
#endif
529+
return color.to_string ();
518530
}
519531

520532
/**
@@ -546,12 +558,5 @@ namespace Gala.Drawing {
546558

547559
return (alpha << 24) | (red << 16) | (green << 8) | blue;
548560
}
549-
550-
private void set_from_rgba (Gdk.RGBA color) {
551-
R = color.red;
552-
G = color.green;
553-
B = color.blue;
554-
A = color.alpha;
555-
}
556561
}
557562
}

src/Widgets/MultitaskingView/Tooltip.vala

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,19 @@ public class Gala.Tooltip : Clutter.Actor {
1414
private Gala.Text text_actor;
1515

1616
construct {
17-
#if HAS_MUTTER47
18-
Cogl.Color text_color = {
19-
#else
20-
Clutter.Color text_color = {
21-
#endif
22-
(uint8) Drawing.Color.TOOLTIP_TEXT_COLOR.red * uint8.MAX,
23-
(uint8) Drawing.Color.TOOLTIP_TEXT_COLOR.green * uint8.MAX,
24-
(uint8) Drawing.Color.TOOLTIP_TEXT_COLOR.blue * uint8.MAX,
25-
(uint8) Drawing.Color.TOOLTIP_TEXT_COLOR.alpha * uint8.MAX,
26-
};
27-
2817
text_actor = new Gala.Text () {
2918
margin_left = 6,
3019
margin_top = 6,
3120
margin_bottom = 6,
3221
margin_right = 6,
3322
ellipsize = Pango.EllipsizeMode.MIDDLE,
34-
color = text_color
23+
color = Drawing.Color.TOOLTIP_TEXT_COLOR
3524
};
3625

3726
add_child (text_actor);
3827

3928
layout_manager = new Clutter.BinLayout ();
40-
background_color = {
41-
(uint8) (Drawing.Color.TOOLTIP_BACKGROUND.red * uint8.MAX),
42-
(uint8) (Drawing.Color.TOOLTIP_BACKGROUND.green * uint8.MAX),
43-
(uint8) (Drawing.Color.TOOLTIP_BACKGROUND.blue * uint8.MAX),
44-
(uint8) (Drawing.Color.TOOLTIP_BACKGROUND.alpha * uint8.MAX)
45-
};
29+
background_color = Drawing.Color.TOOLTIP_BACKGROUND;
4630

4731
add_effect (new RoundedCornersEffect (3, 1.0f));
4832
}

src/Widgets/WindowSwitcher/WindowSwitcher.vala

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget, RootTarget {
170170
highlight_color = Drawing.Color.DARK_HIGHLIGHT;
171171
}
172172

173-
background_color.alpha = 0.6f;
174-
175173
#if HAS_MUTTER47
176174
caption.color = Cogl.Color.from_string (caption_color);
177175
#else
@@ -195,19 +193,19 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget, RootTarget {
195193
);
196194

197195
ctx.set_source_rgba (
198-
background_color.red,
199-
background_color.green,
200-
background_color.blue,
201-
background_color.alpha
196+
background_color.red / 255.0,
197+
background_color.green / 255.0,
198+
background_color.blue / 255.0,
199+
0.6
202200
);
203201
ctx.fill_preserve ();
204202

205203
ctx.set_line_width (stroke_width);
206204
ctx.set_source_rgba (
207-
border_color.red,
208-
border_color.green,
209-
border_color.blue,
210-
border_color.alpha
205+
border_color.red / 255.0,
206+
border_color.green / 255.0,
207+
border_color.blue / 255.0,
208+
border_color.alpha / 255.0
211209
);
212210
ctx.stroke ();
213211
ctx.restore ();
@@ -221,9 +219,9 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget, RootTarget {
221219

222220
ctx.set_line_width (stroke_width);
223221
ctx.set_source_rgba (
224-
highlight_color.red,
225-
highlight_color.green,
226-
highlight_color.blue,
222+
highlight_color.red / 255.0,
223+
highlight_color.green / 255.0,
224+
highlight_color.blue / 255.0,
227225
0.3
228226
);
229227
ctx.stroke ();

0 commit comments

Comments
 (0)