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 gsk.RenderNode;
26 
27 private import cairo.Context;
28 private import glib.Bytes;
29 private import glib.ErrorG;
30 private import glib.GException;
31 private import glib.MemorySlice;
32 private import glib.Str;
33 private import gobject.ObjectG;
34 private import graphene.Rect;
35 private import gsk.c.functions;
36 public  import gsk.c.types;
37 private import gtkd.Loader;
38 
39 
40 /**
41  * `GskRenderNode` is the basic block in a scene graph to be
42  * rendered using `GskRenderer`.
43  * 
44  * Each node has a parent, except the top-level node; each node may have
45  * children nodes.
46  * 
47  * Each node has an associated drawing surface, which has the size of
48  * the rectangle set when creating it.
49  * 
50  * Render nodes are meant to be transient; once they have been associated
51  * to a [class@Gsk.Renderer] it's safe to release any reference you have on
52  * them. All [class@Gsk.RenderNode]s are immutable, you can only specify their
53  * properties during construction.
54  */
55 public class RenderNode
56 {
57 	/** the main Gtk struct */
58 	protected GskRenderNode* gskRenderNode;
59 	protected bool ownedRef;
60 
61 	/** Get the main Gtk struct */
62 	public GskRenderNode* getRenderNodeStruct(bool transferOwnership = false)
63 	{
64 		if (transferOwnership)
65 			ownedRef = false;
66 		return gskRenderNode;
67 	}
68 
69 	/** the main Gtk struct as a void* */
70 	protected void* getStruct()
71 	{
72 		return cast(void*)gskRenderNode;
73 	}
74 
75 	/**
76 	 * Sets our main struct and passes it to the parent class.
77 	 */
78 	public this (GskRenderNode* gskRenderNode, bool ownedRef = false)
79 	{
80 		this.gskRenderNode = gskRenderNode;
81 		this.ownedRef = ownedRef;
82 	}
83 
84 	~this ()
85 	{
86 		if ( Linker.isLoaded(LIBRARY_GSK) && ownedRef )
87 			gsk_render_node_unref(gskRenderNode);
88 	}
89 
90 
91 	/** */
92 	public static GType getType()
93 	{
94 		return gsk_render_node_get_type();
95 	}
96 
97 	/**
98 	 * Loads data previously created via gsk_render_node_serialize().
99 	 *
100 	 * For a discussion of the supported format, see that function.
101 	 *
102 	 * Params:
103 	 *     bytes = the bytes containing the data
104 	 *     errorFunc = Callback on parsing errors or %NULL
105 	 *     userData = user_data for @error_func
106 	 *
107 	 * Returns: a new `GskRenderNode` or %NULL on
108 	 *     error.
109 	 */
110 	public static RenderNode deserialize(Bytes bytes, GskParseErrorFunc errorFunc, void* userData)
111 	{
112 		auto __p = gsk_render_node_deserialize((bytes is null) ? null : bytes.getBytesStruct(), errorFunc, userData);
113 
114 		if(__p is null)
115 		{
116 			return null;
117 		}
118 
119 		return ObjectG.getDObject!(RenderNode)(cast(GskRenderNode*) __p, true);
120 	}
121 
122 	/**
123 	 * Draw the contents of @node to the given cairo context.
124 	 *
125 	 * Typically, you'll use this function to implement fallback rendering
126 	 * of `GskRenderNode`s on an intermediate Cairo context, instead of using
127 	 * the drawing context associated to a `GdkSurface`'s rendering buffer.
128 	 *
129 	 * For advanced nodes that cannot be supported using Cairo, in particular
130 	 * for nodes doing 3D operations, this function may fail.
131 	 *
132 	 * Params:
133 	 *     cr = cairo context to draw to
134 	 */
135 	public void draw(Context cr)
136 	{
137 		gsk_render_node_draw(gskRenderNode, (cr is null) ? null : cr.getContextStruct());
138 	}
139 
140 	/**
141 	 * Retrieves the boundaries of the @node.
142 	 *
143 	 * The node will not draw outside of its boundaries.
144 	 *
145 	 * Params:
146 	 *     bounds = return location for the boundaries
147 	 */
148 	public void getBounds(out Rect bounds)
149 	{
150 		graphene_rect_t* outbounds = sliceNew!graphene_rect_t();
151 
152 		gsk_render_node_get_bounds(gskRenderNode, outbounds);
153 
154 		bounds = ObjectG.getDObject!(Rect)(outbounds, true);
155 	}
156 
157 	/**
158 	 * Returns the type of the @node.
159 	 *
160 	 * Returns: the type of the `GskRenderNode`
161 	 */
162 	public GskRenderNodeType getNodeType()
163 	{
164 		return gsk_render_node_get_node_type(gskRenderNode);
165 	}
166 
167 	alias doref = ref_;
168 	/**
169 	 * Acquires a reference on the given `GskRenderNode`.
170 	 *
171 	 * Returns: the `GskRenderNode` with an additional reference
172 	 */
173 	public RenderNode ref_()
174 	{
175 		auto __p = gsk_render_node_ref(gskRenderNode);
176 
177 		if(__p is null)
178 		{
179 			return null;
180 		}
181 
182 		return ObjectG.getDObject!(RenderNode)(cast(GskRenderNode*) __p, true);
183 	}
184 
185 	/**
186 	 * Serializes the @node for later deserialization via
187 	 * gsk_render_node_deserialize(). No guarantees are made about the format
188 	 * used other than that the same version of GTK will be able to deserialize
189 	 * the result of a call to gsk_render_node_serialize() and
190 	 * gsk_render_node_deserialize() will correctly reject files it cannot open
191 	 * that were created with previous versions of GTK.
192 	 *
193 	 * The intended use of this functions is testing, benchmarking and debugging.
194 	 * The format is not meant as a permanent storage format.
195 	 *
196 	 * Returns: a #GBytes representing the node.
197 	 */
198 	public Bytes serialize()
199 	{
200 		auto __p = gsk_render_node_serialize(gskRenderNode);
201 
202 		if(__p is null)
203 		{
204 			return null;
205 		}
206 
207 		return new Bytes(cast(GBytes*) __p, true);
208 	}
209 
210 	/**
211 	 * Releases a reference on the given `GskRenderNode`.
212 	 *
213 	 * If the reference was the last, the resources associated to the @node are
214 	 * freed.
215 	 */
216 	public void unref()
217 	{
218 		gsk_render_node_unref(gskRenderNode);
219 	}
220 
221 	/**
222 	 * This function is equivalent to calling gsk_render_node_serialize()
223 	 * followed by g_file_set_contents().
224 	 *
225 	 * See those two functions for details on the arguments.
226 	 *
227 	 * It is mostly intended for use inside a debugger to quickly dump a render
228 	 * node to a file for later inspection.
229 	 *
230 	 * Params:
231 	 *     filename = the file to save it to.
232 	 *
233 	 * Returns: %TRUE if saving was successful
234 	 *
235 	 * Throws: GException on failure.
236 	 */
237 	public bool writeToFile(string filename)
238 	{
239 		GError* err = null;
240 
241 		auto __p = gsk_render_node_write_to_file(gskRenderNode, Str.toStringz(filename), &err) != 0;
242 
243 		if (err !is null)
244 		{
245 			throw new GException( new ErrorG(err) );
246 		}
247 
248 		return __p;
249 	}
250 }