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 gtk.Gradient;
26 
27 private import cairo.Pattern;
28 private import glib.ConstructionException;
29 private import glib.Str;
30 private import gobject.ObjectG;
31 private import gtk.StyleContext;
32 private import gtk.StyleProperties;
33 private import gtk.SymbolicColor;
34 private import gtkc.Loader;
35 private import gtkc.gtk;
36 public  import gtkc.gtktypes;
37 private import gtkc.paths;
38 
39 
40 /**
41  * GtkGradient is a boxed type that represents a gradient.
42  * It is the result of parsing a
43  * [gradient expression][gtkcssprovider-gradients].
44  * To obtain the gradient represented by a GtkGradient, it has to
45  * be resolved with gtk_gradient_resolve(), which replaces all
46  * symbolic color references by the colors they refer to (in a given
47  * context) and constructs a #cairo_pattern_t value.
48  * 
49  * It is not normally necessary to deal directly with #GtkGradients,
50  * since they are mostly used behind the scenes by #GtkStyleContext and
51  * #GtkCssProvider.
52  * 
53  * #GtkGradient is deprecated. It was used internally by GTK’s CSS engine
54  * to represent gradients. As its handling is not conforming to modern
55  * web standards, it is not used anymore. If you want to use gradients in
56  * your own code, please use Cairo directly.
57  */
58 public class Gradient
59 {
60 	/** the main Gtk struct */
61 	protected GtkGradient* gtkGradient;
62 	protected bool ownedRef;
63 
64 	/** Get the main Gtk struct */
65 	public GtkGradient* getGradientStruct()
66 	{
67 		return gtkGradient;
68 	}
69 
70 	/** the main Gtk struct as a void* */
71 	protected void* getStruct()
72 	{
73 		return cast(void*)gtkGradient;
74 	}
75 
76 	/**
77 	 * Sets our main struct and passes it to the parent class.
78 	 */
79 	public this (GtkGradient* gtkGradient, bool ownedRef = false)
80 	{
81 		this.gtkGradient = gtkGradient;
82 		this.ownedRef = ownedRef;
83 	}
84 
85 	~this ()
86 	{
87 		if (  Linker.isLoaded(LIBRARY.GTK) && ownedRef )
88 		{
89 			gtk_gradient_unref(gtkGradient);
90 		}
91 	}
92 
93 	/**
94 	 */
95 
96 	/** */
97 	public static GType getType()
98 	{
99 		return gtk_gradient_get_type();
100 	}
101 
102 	/**
103 	 * Creates a new linear gradient along the line defined by (x0, y0) and (x1, y1). Before using the gradient
104 	 * a number of stop colors must be added through gtk_gradient_add_color_stop().
105 	 *
106 	 * Deprecated: #GtkGradient is deprecated.
107 	 *
108 	 * Params:
109 	 *     x0 = X coordinate of the starting point
110 	 *     y0 = Y coordinate of the starting point
111 	 *     x1 = X coordinate of the end point
112 	 *     y1 = Y coordinate of the end point
113 	 *
114 	 * Return: A newly created #GtkGradient
115 	 *
116 	 * Since: 3.0
117 	 *
118 	 * Throws: ConstructionException GTK+ fails to create the object.
119 	 */
120 	public this(double x0, double y0, double x1, double y1)
121 	{
122 		auto p = gtk_gradient_new_linear(x0, y0, x1, y1);
123 		
124 		if(p is null)
125 		{
126 			throw new ConstructionException("null returned by new_linear");
127 		}
128 		
129 		this(cast(GtkGradient*) p);
130 	}
131 
132 	/**
133 	 * Creates a new radial gradient along the two circles defined by (x0, y0, radius0) and
134 	 * (x1, y1, radius1). Before using the gradient a number of stop colors must be added
135 	 * through gtk_gradient_add_color_stop().
136 	 *
137 	 * Deprecated: #GtkGradient is deprecated.
138 	 *
139 	 * Params:
140 	 *     x0 = X coordinate of the start circle
141 	 *     y0 = Y coordinate of the start circle
142 	 *     radius0 = radius of the start circle
143 	 *     x1 = X coordinate of the end circle
144 	 *     y1 = Y coordinate of the end circle
145 	 *     radius1 = radius of the end circle
146 	 *
147 	 * Return: A newly created #GtkGradient
148 	 *
149 	 * Since: 3.0
150 	 *
151 	 * Throws: ConstructionException GTK+ fails to create the object.
152 	 */
153 	public this(double x0, double y0, double radius0, double x1, double y1, double radius1)
154 	{
155 		auto p = gtk_gradient_new_radial(x0, y0, radius0, x1, y1, radius1);
156 		
157 		if(p is null)
158 		{
159 			throw new ConstructionException("null returned by new_radial");
160 		}
161 		
162 		this(cast(GtkGradient*) p);
163 	}
164 
165 	/**
166 	 * Adds a stop color to @gradient.
167 	 *
168 	 * Deprecated: #GtkGradient is deprecated.
169 	 *
170 	 * Params:
171 	 *     offset = offset for the color stop
172 	 *     color = color to use
173 	 *
174 	 * Since: 3.0
175 	 */
176 	public void addColorStop(double offset, SymbolicColor color)
177 	{
178 		gtk_gradient_add_color_stop(gtkGradient, offset, (color is null) ? null : color.getSymbolicColorStruct());
179 	}
180 
181 	/**
182 	 * Increases the reference count of @gradient.
183 	 *
184 	 * Deprecated: #GtkGradient is deprecated.
185 	 *
186 	 * Return: The same @gradient
187 	 *
188 	 * Since: 3.0
189 	 */
190 	public Gradient doref()
191 	{
192 		auto p = gtk_gradient_ref(gtkGradient);
193 		
194 		if(p is null)
195 		{
196 			return null;
197 		}
198 		
199 		return ObjectG.getDObject!(Gradient)(cast(GtkGradient*) p, true);
200 	}
201 
202 	/**
203 	 * If @gradient is resolvable, @resolved_gradient will be filled in
204 	 * with the resolved gradient as a cairo_pattern_t, and %TRUE will
205 	 * be returned. Generally, if @gradient can’t be resolved, it is
206 	 * due to it being defined on top of a named color that doesn't
207 	 * exist in @props.
208 	 *
209 	 * Deprecated: #GtkGradient is deprecated.
210 	 *
211 	 * Params:
212 	 *     props = #GtkStyleProperties to use when resolving named colors
213 	 *     resolvedGradient = return location for the resolved pattern
214 	 *
215 	 * Return: %TRUE if the gradient has been resolved
216 	 *
217 	 * Since: 3.0
218 	 */
219 	public bool resolve(StyleProperties props, out Pattern resolvedGradient)
220 	{
221 		cairo_pattern_t* outresolvedGradient = null;
222 		
223 		auto p = gtk_gradient_resolve(gtkGradient, (props is null) ? null : props.getStylePropertiesStruct(), &outresolvedGradient) != 0;
224 		
225 		resolvedGradient = new Pattern(outresolvedGradient);
226 		
227 		return p;
228 	}
229 
230 	/** */
231 	public Pattern resolveForContext(StyleContext context)
232 	{
233 		auto p = gtk_gradient_resolve_for_context(gtkGradient, (context is null) ? null : context.getStyleContextStruct());
234 		
235 		if(p is null)
236 		{
237 			return null;
238 		}
239 		
240 		return new Pattern(cast(cairo_pattern_t*) p);
241 	}
242 
243 	/**
244 	 * Creates a string representation for @gradient that is suitable
245 	 * for using in GTK CSS files.
246 	 *
247 	 * Deprecated: #GtkGradient is deprecated.
248 	 *
249 	 * Return: A string representation for @gradient
250 	 */
251 	public override string toString()
252 	{
253 		auto retStr = gtk_gradient_to_string(gtkGradient);
254 		
255 		scope(exit) Str.freeString(retStr);
256 		return Str.toString(retStr);
257 	}
258 
259 	/**
260 	 * Decreases the reference count of @gradient, freeing its memory
261 	 * if the reference count reaches 0.
262 	 *
263 	 * Deprecated: #GtkGradient is deprecated.
264 	 *
265 	 * Since: 3.0
266 	 */
267 	public void unref()
268 	{
269 		gtk_gradient_unref(gtkGradient);
270 	}
271 }