1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*
* Convenience class for GtkColorButton.
*
* Copyright (C) 2009 Mark Lee <libdesktop-agnostic@lazymalevolence.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author : Mark Lee <libdesktop-agnostic@lazymalevolence.com>
*/
using DesktopAgnostic;
namespace DesktopAgnostic.UI
{
public class ColorButton : Gtk.ColorButton
{
private static Color ZERO = new Color.from_values (0, 0, 0, ushort.MAX);
private ulong da_color_signal;
public Color da_color { get; set; default = ZERO; }
public ColorButton.with_color (Color color)
{
this.color = color.color;
this.alpha = color.alpha;
this.on_color_set ();
}
protected override void
constructed ()
{
this.use_alpha = true;
this.da_color_signal = Signal.connect (this, "notify::da-color",
(Callback)this.on_da_color_changed,
null);
this.color_set.connect (this.on_color_set);
}
private void
on_da_color_changed (ParamSpec pspec)
{
if (this._da_color == null)
{
this.color = ZERO.color;
this.alpha = ZERO.alpha;
}
else
{
this.color = this.da_color.color;
this.alpha = this.da_color.alpha;
}
}
/**
* Emits the non-internal signal callbacks for the da-color property.
*/
private void
da_color_notify ()
{
// don't run on_da_color_changed
SignalHandler.block (this, this.da_color_signal);
this.notify_property ("da-color");
SignalHandler.unblock (this, this.da_color_signal);
}
/**
* Updates the da-color property when the color is updated via the UI.
*/
private void
on_color_set ()
{
if (this._da_color == null || this._da_color == ZERO)
{
this._da_color = new Color (this.color, (ushort)this.alpha);
}
else
{
this._da_color.color = this.color;
this._da_color.alpha = this.alpha;
}
this.da_color_notify ();
}
public new void
set_color (Gdk.Color color)
{
if (this._da_color == null || this._da_color == ZERO)
{
this._da_color = new Color (color, ushort.MAX);
}
else
{
this._da_color.alpha = alpha;
}
this.da_color_notify ();
}
public new void
set_alpha (uint16 alpha)
{
if (this._da_color == null || this._da_color == ZERO)
{
this._da_color = new Color (ZERO.color, alpha);
}
else
{
this._da_color.alpha = alpha;
}
this.da_color_notify ();
base.set_alpha (alpha);
}
}
}
// vim: set ts=2 sts=2 sw=2 ai cindent :
|