1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module pango.PgColor;
26 
27 private import glib.MemorySlice;
28 private import glib.Str;
29 private import glib.c.functions;
30 private import gobject.ObjectG;
31 private import gtkd.Loader;
32 private import pango.c.functions;
33 public  import pango.c.types;
34 
35 
36 /**
37  * The `PangoColor` structure is used to
38  * represent a color in an uncalibrated RGB color-space.
39  */
40 public final class PgColor
41 {
42 	/** the main Gtk struct */
43 	protected PangoColor* pangoColor;
44 	protected bool ownedRef;
45 
46 	/** Get the main Gtk struct */
47 	public PangoColor* getPgColorStruct(bool transferOwnership = false)
48 	{
49 		if (transferOwnership)
50 			ownedRef = false;
51 		return pangoColor;
52 	}
53 
54 	/** the main Gtk struct as a void* */
55 	protected void* getStruct()
56 	{
57 		return cast(void*)pangoColor;
58 	}
59 
60 	/**
61 	 * Sets our main struct and passes it to the parent class.
62 	 */
63 	public this (PangoColor* pangoColor, bool ownedRef = false)
64 	{
65 		this.pangoColor = pangoColor;
66 		this.ownedRef = ownedRef;
67 	}
68 
69 	~this ()
70 	{
71 		if ( Linker.isLoaded(LIBRARY_PANGO) && ownedRef )
72 			pango_color_free(pangoColor);
73 	}
74 
75 
76 	/**
77 	 * value of red component
78 	 */
79 	public @property ushort red()
80 	{
81 		return pangoColor.red;
82 	}
83 
84 	/** Ditto */
85 	public @property void red(ushort value)
86 	{
87 		pangoColor.red = value;
88 	}
89 
90 	/**
91 	 * value of green component
92 	 */
93 	public @property ushort green()
94 	{
95 		return pangoColor.green;
96 	}
97 
98 	/** Ditto */
99 	public @property void green(ushort value)
100 	{
101 		pangoColor.green = value;
102 	}
103 
104 	/**
105 	 * value of blue component
106 	 */
107 	public @property ushort blue()
108 	{
109 		return pangoColor.blue;
110 	}
111 
112 	/** Ditto */
113 	public @property void blue(ushort value)
114 	{
115 		pangoColor.blue = value;
116 	}
117 
118 	/** */
119 	public static GType getType()
120 	{
121 		return pango_color_get_type();
122 	}
123 
124 	/**
125 	 * Creates a copy of @src.
126 	 *
127 	 * The copy should be freed with pango_color_free(). Primarily
128 	 * used by language bindings, not that useful otherwise (since
129 	 * colors can just be copied by assignment in C).
130 	 *
131 	 * Returns: the newly allocated `PangoColor`, which
132 	 *     should be freed with [method@Pango.Color.free], or %NULL if
133 	 *     @src was %NULL.
134 	 */
135 	public PgColor copy()
136 	{
137 		auto __p = pango_color_copy(pangoColor);
138 
139 		if(__p is null)
140 		{
141 			return null;
142 		}
143 
144 		return ObjectG.getDObject!(PgColor)(cast(PangoColor*) __p, true);
145 	}
146 
147 	/**
148 	 * Frees a color allocated by pango_color_copy().
149 	 */
150 	public void free()
151 	{
152 		pango_color_free(pangoColor);
153 		ownedRef = false;
154 	}
155 
156 	/**
157 	 * Fill in the fields of a color from a string specification.
158 	 *
159 	 * The string can either
160 	 * one of a large set of standard names. (Taken from the CSS Color
161 	 * [specification](https://www.w3.org/TR/css-color-4/#named-colors), or it can be
162 	 * a value in the form `#rgb`, `#rrggbb`, `#rrrgggbbb` or `#rrrrggggbbbb`, where
163 	 * `r`, `g` and `b` are hex digits of the red, green, and blue components of the
164 	 * color, respectively. (White in the four forms is `#fff`, `#ffffff`, `#fffffffff`
165 	 * and `#ffffffffffff`.)
166 	 *
167 	 * Params:
168 	 *     spec = a string specifying the new color
169 	 *
170 	 * Returns: %TRUE if parsing of the specifier succeeded, otherwise false.
171 	 */
172 	public bool parse(string spec)
173 	{
174 		return pango_color_parse(pangoColor, Str.toStringz(spec)) != 0;
175 	}
176 
177 	/**
178 	 * Fill in the fields of a color from a string specification.
179 	 *
180 	 * The string can
181 	 * either one of a large set of standard names. (Taken from the CSS Color
182 	 * [specification](https://www.w3.org/TR/css-color-4/#named-colors),
183 	 * or it can be a hexadecimal value in the form `#rgb`, `#rrggbb`, `#rrrgggbbb`
184 	 * or `#rrrrggggbbbb` where `r`, `g` and `b` are hex digits of the red, green,
185 	 * and blue components of the color, respectively. (White in the four
186 	 * forms is `#fff`, `#ffffff`, `#fffffffff` and `#ffffffffffff`.)
187 	 *
188 	 * Additionally, parse strings of the form `#rgba`, `#rrggbbaa`,
189 	 * `#rrrrggggbbbbaaaa`, if @alpha is not %NULL, and set @alpha to the value
190 	 * specified by the hex digits for `a`. If no alpha component is found
191 	 * in @spec, @alpha is set to 0xffff (for a solid color).
192 	 *
193 	 * Params:
194 	 *     alpha = return location for alpha, or %NULL
195 	 *     spec = a string specifying the new color
196 	 *
197 	 * Returns: %TRUE if parsing of the specifier succeeded, otherwise false.
198 	 *
199 	 * Since: 1.46
200 	 */
201 	public bool parseWithAlpha(out ushort alpha, string spec)
202 	{
203 		return pango_color_parse_with_alpha(pangoColor, &alpha, Str.toStringz(spec)) != 0;
204 	}
205 
206 	/**
207 	 * Returns a textual specification of @color.
208 	 *
209 	 * The string is in the hexadecimal form `#rrrrggggbbbb`, where
210 	 * `r`, `g` and `b` are hex digits representing the red, green,
211 	 * and blue components respectively.
212 	 *
213 	 * Returns: a newly-allocated text string that must be freed with g_free().
214 	 *
215 	 * Since: 1.16
216 	 */
217 	public override string toString()
218 	{
219 		auto retStr = pango_color_to_string(pangoColor);
220 
221 		scope(exit) Str.freeString(retStr);
222 		return Str.toString(retStr);
223 	}
224 }