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 gtk.c.functions;
35 public  import gtk.c.types;
36 public  import gtkc.gtktypes;
37 private import gtkd.Loader;
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(bool transferOwnership = false)
66 	{
67 		if (transferOwnership)
68 			ownedRef = false;
69 		return gtkGradient;
70 	}
71 
72 	/** the main Gtk struct as a void* */
73 	protected void* getStruct()
74 	{
75 		return cast(void*)gtkGradient;
76 	}
77 
78 	/**
79 	 * Sets our main struct and passes it to the parent class.
80 	 */
81 	public this (GtkGradient* gtkGradient, bool ownedRef = false)
82 	{
83 		this.gtkGradient = gtkGradient;
84 		this.ownedRef = ownedRef;
85 	}
86 
87 	~this ()
88 	{
89 		if ( Linker.isLoaded(LIBRARY_GTK) && ownedRef )
90 			gtk_gradient_unref(gtkGradient);
91 	}
92 
93 
94 	/** */
95 	public static GType getType()
96 	{
97 		return gtk_gradient_get_type();
98 	}
99 
100 	/**
101 	 * Creates a new linear gradient along the line defined by (x0, y0) and (x1, y1). Before using the gradient
102 	 * a number of stop colors must be added through gtk_gradient_add_color_stop().
103 	 *
104 	 * Deprecated: #GtkGradient is deprecated.
105 	 *
106 	 * Params:
107 	 *     x0 = X coordinate of the starting point
108 	 *     y0 = Y coordinate of the starting point
109 	 *     x1 = X coordinate of the end point
110 	 *     y1 = Y coordinate of the end point
111 	 *
112 	 * Returns: A newly created #GtkGradient
113 	 *
114 	 * Since: 3.0
115 	 *
116 	 * Throws: ConstructionException GTK+ fails to create the object.
117 	 */
118 	public this(double x0, double y0, double x1, double y1)
119 	{
120 		auto p = gtk_gradient_new_linear(x0, y0, x1, y1);
121 
122 		if(p is null)
123 		{
124 			throw new ConstructionException("null returned by new_linear");
125 		}
126 
127 		this(cast(GtkGradient*) p);
128 	}
129 
130 	/**
131 	 * Creates a new radial gradient along the two circles defined by (x0, y0, radius0) and
132 	 * (x1, y1, radius1). Before using the gradient a number of stop colors must be added
133 	 * through gtk_gradient_add_color_stop().
134 	 *
135 	 * Deprecated: #GtkGradient is deprecated.
136 	 *
137 	 * Params:
138 	 *     x0 = X coordinate of the start circle
139 	 *     y0 = Y coordinate of the start circle
140 	 *     radius0 = radius of the start circle
141 	 *     x1 = X coordinate of the end circle
142 	 *     y1 = Y coordinate of the end circle
143 	 *     radius1 = radius of the end circle
144 	 *
145 	 * Returns: A newly created #GtkGradient
146 	 *
147 	 * Since: 3.0
148 	 *
149 	 * Throws: ConstructionException GTK+ fails to create the object.
150 	 */
151 	public this(double x0, double y0, double radius0, double x1, double y1, double radius1)
152 	{
153 		auto p = gtk_gradient_new_radial(x0, y0, radius0, x1, y1, radius1);
154 
155 		if(p is null)
156 		{
157 			throw new ConstructionException("null returned by new_radial");
158 		}
159 
160 		this(cast(GtkGradient*) p);
161 	}
162 
163 	/**
164 	 * Adds a stop color to @gradient.
165 	 *
166 	 * Deprecated: #GtkGradient is deprecated.
167 	 *
168 	 * Params:
169 	 *     offset = offset for the color stop
170 	 *     color = color to use
171 	 *
172 	 * Since: 3.0
173 	 */
174 	public void addColorStop(double offset, SymbolicColor color)
175 	{
176 		gtk_gradient_add_color_stop(gtkGradient, offset, (color is null) ? null : color.getSymbolicColorStruct());
177 	}
178 
179 	/**
180 	 * Increases the reference count of @gradient.
181 	 *
182 	 * Deprecated: #GtkGradient is deprecated.
183 	 *
184 	 * Returns: The same @gradient
185 	 *
186 	 * Since: 3.0
187 	 */
188 	public Gradient doref()
189 	{
190 		auto p = gtk_gradient_ref(gtkGradient);
191 
192 		if(p is null)
193 		{
194 			return null;
195 		}
196 
197 		return ObjectG.getDObject!(Gradient)(cast(GtkGradient*) p, true);
198 	}
199 
200 	/**
201 	 * If @gradient is resolvable, @resolved_gradient will be filled in
202 	 * with the resolved gradient as a cairo_pattern_t, and %TRUE will
203 	 * be returned. Generally, if @gradient can’t be resolved, it is
204 	 * due to it being defined on top of a named color that doesn't
205 	 * exist in @props.
206 	 *
207 	 * Deprecated: #GtkGradient is deprecated.
208 	 *
209 	 * Params:
210 	 *     props = #GtkStyleProperties to use when resolving named colors
211 	 *     resolvedGradient = return location for the resolved pattern
212 	 *
213 	 * Returns: %TRUE if the gradient has been resolved
214 	 *
215 	 * Since: 3.0
216 	 */
217 	public bool resolve(StyleProperties props, out Pattern resolvedGradient)
218 	{
219 		cairo_pattern_t* outresolvedGradient = null;
220 
221 		auto p = gtk_gradient_resolve(gtkGradient, (props is null) ? null : props.getStylePropertiesStruct(), &outresolvedGradient) != 0;
222 
223 		resolvedGradient = new Pattern(outresolvedGradient);
224 
225 		return p;
226 	}
227 
228 	/** */
229 	public Pattern resolveForContext(StyleContext context)
230 	{
231 		auto p = gtk_gradient_resolve_for_context(gtkGradient, (context is null) ? null : context.getStyleContextStruct());
232 
233 		if(p is null)
234 		{
235 			return null;
236 		}
237 
238 		return new Pattern(cast(cairo_pattern_t*) p);
239 	}
240 
241 	/**
242 	 * Creates a string representation for @gradient that is suitable
243 	 * for using in GTK CSS files.
244 	 *
245 	 * Deprecated: #GtkGradient is deprecated.
246 	 *
247 	 * Returns: A string representation for @gradient
248 	 */
249 	public override string toString()
250 	{
251 		auto retStr = gtk_gradient_to_string(gtkGradient);
252 
253 		scope(exit) Str.freeString(retStr);
254 		return Str.toString(retStr);
255 	}
256 
257 	/**
258 	 * Decreases the reference count of @gradient, freeing its memory
259 	 * if the reference count reaches 0.
260 	 *
261 	 * Deprecated: #GtkGradient is deprecated.
262 	 *
263 	 * Since: 3.0
264 	 */
265 	public void unref()
266 	{
267 		gtk_gradient_unref(gtkGradient);
268 	}
269 }