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