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.Renderer;
26 
27 private import cairo.Region;
28 private import gdk.Surface;
29 private import gdk.Texture;
30 private import glib.ConstructionException;
31 private import glib.ErrorG;
32 private import glib.GException;
33 private import gobject.ObjectG;
34 private import graphene.Rect;
35 private import gsk.RenderNode;
36 private import gsk.c.functions;
37 public  import gsk.c.types;
38 
39 
40 /**
41  * `GskRenderer` is a class that renders a scene graph defined via a
42  * tree of [class@Gsk.RenderNode] instances.
43  * 
44  * Typically you will use a `GskRenderer` instance to repeatedly call
45  * [method@Gsk.Renderer.render] to update the contents of its associated
46  * [class@Gdk.Surface].
47  * 
48  * It is necessary to realize a `GskRenderer` instance using
49  * [method@Gsk.Renderer.realize] before calling [method@Gsk.Renderer.render],
50  * in order to create the appropriate windowing system resources needed
51  * to render the scene.
52  */
53 public class Renderer : ObjectG
54 {
55 	/** the main Gtk struct */
56 	protected GskRenderer* gskRenderer;
57 
58 	/** Get the main Gtk struct */
59 	public GskRenderer* getRendererStruct(bool transferOwnership = false)
60 	{
61 		if (transferOwnership)
62 			ownedRef = false;
63 		return gskRenderer;
64 	}
65 
66 	/** the main Gtk struct as a void* */
67 	protected override void* getStruct()
68 	{
69 		return cast(void*)gskRenderer;
70 	}
71 
72 	/**
73 	 * Sets our main struct and passes it to the parent class.
74 	 */
75 	public this (GskRenderer* gskRenderer, bool ownedRef = false)
76 	{
77 		this.gskRenderer = gskRenderer;
78 		super(cast(GObject*)gskRenderer, ownedRef);
79 	}
80 
81 
82 	/** */
83 	public static GType getType()
84 	{
85 		return gsk_renderer_get_type();
86 	}
87 
88 	/**
89 	 * Creates an appropriate `GskRenderer` instance for the given @surface.
90 	 *
91 	 * If the `GSK_RENDERER` environment variable is set, GSK will
92 	 * try that renderer first, before trying the backend-specific
93 	 * default. The ultimate fallback is the cairo renderer.
94 	 *
95 	 * The renderer will be realized before it is returned.
96 	 *
97 	 * Params:
98 	 *     surface = a `GdkSurface`
99 	 *
100 	 * Returns: a `GskRenderer`
101 	 *
102 	 * Throws: ConstructionException GTK+ fails to create the object.
103 	 */
104 	public this(Surface surface)
105 	{
106 		auto __p = gsk_renderer_new_for_surface((surface is null) ? null : surface.getSurfaceStruct());
107 
108 		if(__p is null)
109 		{
110 			throw new ConstructionException("null returned by new_for_surface");
111 		}
112 
113 		this(cast(GskRenderer*) __p, true);
114 	}
115 
116 	/**
117 	 * Retrieves the `GdkSurface` set using gsk_enderer_realize().
118 	 *
119 	 * If the renderer has not been realized yet, %NULL will be returned.
120 	 *
121 	 * Returns: a `GdkSurface`
122 	 */
123 	public Surface getSurface()
124 	{
125 		auto __p = gsk_renderer_get_surface(gskRenderer);
126 
127 		if(__p is null)
128 		{
129 			return null;
130 		}
131 
132 		return ObjectG.getDObject!(Surface)(cast(GdkSurface*) __p);
133 	}
134 
135 	/**
136 	 * Checks whether the @renderer is realized or not.
137 	 *
138 	 * Returns: %TRUE if the `GskRenderer` was realized, and %FALSE otherwise
139 	 */
140 	public bool isRealized()
141 	{
142 		return gsk_renderer_is_realized(gskRenderer) != 0;
143 	}
144 
145 	/**
146 	 * Creates the resources needed by the @renderer to render the scene
147 	 * graph.
148 	 *
149 	 * Params:
150 	 *     surface = the `GdkSurface` renderer will be used on
151 	 *
152 	 * Throws: GException on failure.
153 	 */
154 	public bool realize(Surface surface)
155 	{
156 		GError* err = null;
157 
158 		auto __p = gsk_renderer_realize(gskRenderer, (surface is null) ? null : surface.getSurfaceStruct(), &err) != 0;
159 
160 		if (err !is null)
161 		{
162 			throw new GException( new ErrorG(err) );
163 		}
164 
165 		return __p;
166 	}
167 
168 	/**
169 	 * Renders the scene graph, described by a tree of `GskRenderNode` instances,
170 	 * ensuring that the given @region gets redrawn.
171 	 *
172 	 * Renderers must ensure that changes of the contents given by the @root
173 	 * node as well as the area given by @region are redrawn. They are however
174 	 * free to not redraw any pixel outside of @region if they can guarantee that
175 	 * it didn't change.
176 	 *
177 	 * The @renderer will acquire a reference on the `GskRenderNode` tree while
178 	 * the rendering is in progress.
179 	 *
180 	 * Params:
181 	 *     root = a `GskRenderNode`
182 	 *     region = the `cairo_region_t` that must be redrawn or %NULL
183 	 *         for the whole window
184 	 */
185 	public void render(RenderNode root, Region region)
186 	{
187 		gsk_renderer_render(gskRenderer, (root is null) ? null : root.getRenderNodeStruct(), (region is null) ? null : region.getRegionStruct());
188 	}
189 
190 	/**
191 	 * Renders the scene graph, described by a tree of `GskRenderNode` instances,
192 	 * to a `GdkTexture`.
193 	 *
194 	 * The @renderer will acquire a reference on the `GskRenderNode` tree while
195 	 * the rendering is in progress.
196 	 *
197 	 * If you want to apply any transformations to @root, you should put it into a
198 	 * transform node and pass that node instead.
199 	 *
200 	 * Params:
201 	 *     root = a `GskRenderNode`
202 	 *     viewport = the section to draw or %NULL to use @root's bounds
203 	 *
204 	 * Returns: a `GdkTexture` with the rendered contents of @root.
205 	 */
206 	public Texture renderTexture(RenderNode root, Rect viewport)
207 	{
208 		auto __p = gsk_renderer_render_texture(gskRenderer, (root is null) ? null : root.getRenderNodeStruct(), (viewport is null) ? null : viewport.getRectStruct());
209 
210 		if(__p is null)
211 		{
212 			return null;
213 		}
214 
215 		return ObjectG.getDObject!(Texture)(cast(GdkTexture*) __p, true);
216 	}
217 
218 	/**
219 	 * Releases all the resources created by gsk_renderer_realize().
220 	 */
221 	public void unrealize()
222 	{
223 		gsk_renderer_unrealize(gskRenderer);
224 	}
225 }