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 	alias doref = ref_;
180 	/**
181 	 * Increases the reference count of @gradient.
182 	 *
183 	 * Deprecated: #GtkGradient is deprecated.
184 	 *
185 	 * Returns: The same @gradient
186 	 *
187 	 * Since: 3.0
188 	 */
189 	public Gradient ref_()
190 	{
191 		auto p = gtk_gradient_ref(gtkGradient);
192 
193 		if(p is null)
194 		{
195 			return null;
196 		}
197 
198 		return ObjectG.getDObject!(Gradient)(cast(GtkGradient*) p, true);
199 	}
200 
201 	/**
202 	 * If @gradient is resolvable, @resolved_gradient will be filled in
203 	 * with the resolved gradient as a cairo_pattern_t, and %TRUE will
204 	 * be returned. Generally, if @gradient can’t be resolved, it is
205 	 * due to it being defined on top of a named color that doesn't
206 	 * exist in @props.
207 	 *
208 	 * Deprecated: #GtkGradient is deprecated.
209 	 *
210 	 * Params:
211 	 *     props = #GtkStyleProperties to use when resolving named colors
212 	 *     resolvedGradient = return location for the resolved pattern
213 	 *
214 	 * Returns: %TRUE if the gradient has been resolved
215 	 *
216 	 * Since: 3.0
217 	 */
218 	public bool resolve(StyleProperties props, out Pattern resolvedGradient)
219 	{
220 		cairo_pattern_t* outresolvedGradient = null;
221 
222 		auto p = gtk_gradient_resolve(gtkGradient, (props is null) ? null : props.getStylePropertiesStruct(), &outresolvedGradient) != 0;
223 
224 		resolvedGradient = new Pattern(outresolvedGradient);
225 
226 		return p;
227 	}
228 
229 	/** */
230 	public Pattern resolveForContext(StyleContext context)
231 	{
232 		auto p = gtk_gradient_resolve_for_context(gtkGradient, (context is null) ? null : context.getStyleContextStruct());
233 
234 		if(p is null)
235 		{
236 			return null;
237 		}
238 
239 		return new Pattern(cast(cairo_pattern_t*) p);
240 	}
241 
242 	/**
243 	 * Creates a string representation for @gradient that is suitable
244 	 * for using in GTK CSS files.
245 	 *
246 	 * Deprecated: #GtkGradient is deprecated.
247 	 *
248 	 * Returns: A string representation for @gradient
249 	 */
250 	public override string toString()
251 	{
252 		auto retStr = gtk_gradient_to_string(gtkGradient);
253 
254 		scope(exit) Str.freeString(retStr);
255 		return Str.toString(retStr);
256 	}
257 
258 	/**
259 	 * Decreases the reference count of @gradient, freeing its memory
260 	 * if the reference count reaches 0.
261 	 *
262 	 * Deprecated: #GtkGradient is deprecated.
263 	 *
264 	 * Since: 3.0
265 	 */
266 	public void unref()
267 	{
268 		gtk_gradient_unref(gtkGradient);
269 	}
270 }