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 gdk.PaintableT; 26 27 public import gdk.PaintableIF; 28 public import gdk.Snapshot; 29 public import gdk.c.functions; 30 public import gdk.c.types; 31 public import glib.ConstructionException; 32 public import gobject.ObjectG; 33 public import gobject.Signals; 34 public import std.algorithm; 35 36 37 /** 38 * `GdkPaintable` is a simple interface used by GTK to represent content that 39 * can be painted. 40 * 41 * The content of a `GdkPaintable` can be painted anywhere at any size 42 * without requiring any sort of layout. The interface is inspired by 43 * similar concepts elsewhere, such as 44 * [ClutterContent](https://developer.gnome.org/clutter/stable/ClutterContent.html), 45 * [HTML/CSS Paint Sources](https://www.w3.org/TR/css-images-4/#paint-source), 46 * or [SVG Paint Servers](https://www.w3.org/TR/SVG2/pservers.html). 47 * 48 * A `GdkPaintable` can be snapshot at any time and size using 49 * [method@Gdk.Paintable.snapshot]. How the paintable interprets that size and 50 * if it scales or centers itself into the given rectangle is implementation 51 * defined, though if you are implementing a `GdkPaintable` and don't know what 52 * to do, it is suggested that you scale your paintable ignoring any potential 53 * aspect ratio. 54 * 55 * The contents that a `GdkPaintable` produces may depend on the [class@GdkSnapshot] 56 * passed to it. For example, paintables may decide to use more detailed images 57 * on higher resolution screens or when OpenGL is available. A `GdkPaintable` 58 * will however always produce the same output for the same snapshot. 59 * 60 * A `GdkPaintable` may change its contents, meaning that it will now produce 61 * a different output with the same snapshot. Once that happens, it will call 62 * [method@Gdk.Paintable.invalidate_contents] which will emit the 63 * [signal@GdkPaintable::invalidate-contents] signal. If a paintable is known 64 * to never change its contents, it will set the %GDK_PAINTABLE_STATIC_CONTENTS 65 * flag. If a consumer cannot deal with changing contents, it may call 66 * [method@Gdk.Paintable.get_current_image] which will return a static 67 * paintable and use that. 68 * 69 * A paintable can report an intrinsic (or preferred) size or aspect ratio it 70 * wishes to be rendered at, though it doesn't have to. Consumers of the interface 71 * can use this information to layout thepaintable appropriately. Just like the 72 * contents, the size of a paintable can change. A paintable will indicate this 73 * by calling [method@Gdk.Paintable.invalidate_size] which will emit the 74 * [signal@GdkPaintable::invalidate-size] signal. And just like for contents, 75 * if a paintable is known to never change its size, it will set the 76 * %GDK_PAINTABLE_STATIC_SIZE flag. 77 * 78 * Besides API for applications, there are some functions that are only 79 * useful for implementing subclasses and should not be used by applications: 80 * [method@Gdk.Paintable.invalidate_contents], 81 * [method@Gdk.Paintable.invalidate_size], 82 * [func@Gdk.Paintable.new_empty]. 83 */ 84 public template PaintableT(TStruct) 85 { 86 /** Get the main Gtk struct */ 87 public GdkPaintable* getPaintableStruct(bool transferOwnership = false) 88 { 89 if (transferOwnership) 90 ownedRef = false; 91 return cast(GdkPaintable*)getStruct(); 92 } 93 94 95 /** 96 * Compute a concrete size for the `GdkPaintable`. 97 * 98 * Applies the sizing algorithm outlined in the 99 * [CSS Image spec](https://drafts.csswg.org/css-images-3/#default-sizing) 100 * to the given @paintable. See that link for more details. 101 * 102 * It is not necessary to call this function when both @specified_width 103 * and @specified_height are known, but it is useful to call this 104 * function in GtkWidget:measure implementations to compute the 105 * other dimension when only one dimension is given. 106 * 107 * Params: 108 * specifiedWidth = the width @paintable could be drawn into or 109 * 0.0 if unknown 110 * specifiedHeight = the height @paintable could be drawn into or 111 * 0.0 if unknown 112 * defaultWidth = the width @paintable would be drawn into if 113 * no other constraints were given 114 * defaultHeight = the height @paintable would be drawn into if 115 * no other constraints were given 116 * concreteWidth = will be set to the concrete width 117 * computed. 118 * concreteHeight = will be set to the concrete height 119 * computed. 120 */ 121 public void computeConcreteSize(double specifiedWidth, double specifiedHeight, double defaultWidth, double defaultHeight, out double concreteWidth, out double concreteHeight) 122 { 123 gdk_paintable_compute_concrete_size(getPaintableStruct(), specifiedWidth, specifiedHeight, defaultWidth, defaultHeight, &concreteWidth, &concreteHeight); 124 } 125 126 /** 127 * Gets an immutable paintable for the current contents displayed by @paintable. 128 * 129 * This is useful when you want to retain the current state of an animation, 130 * for example to take a screenshot of a running animation. 131 * 132 * If the @paintable is already immutable, it will return itself. 133 * 134 * Returns: An immutable paintable for the current 135 * contents of @paintable. 136 */ 137 public PaintableIF getCurrentImage() 138 { 139 auto __p = gdk_paintable_get_current_image(getPaintableStruct()); 140 141 if(__p is null) 142 { 143 return null; 144 } 145 146 return ObjectG.getDObject!(PaintableIF)(cast(GdkPaintable*) __p, true); 147 } 148 149 /** 150 * Get flags for the paintable. 151 * 152 * This is oftentimes useful for optimizations. 153 * 154 * See [flags@Gdk.PaintableFlags] for the flags and what they mean. 155 * 156 * Returns: The `GdkPaintableFlags` for this paintable 157 */ 158 public GdkPaintableFlags getFlags() 159 { 160 return gdk_paintable_get_flags(getPaintableStruct()); 161 } 162 163 /** 164 * Gets the preferred aspect ratio the @paintable would like to be displayed at. 165 * 166 * The aspect ratio is the width divided by the height, so a value of 0.5 167 * means that the @paintable prefers to be displayed twice as high as it 168 * is wide. Consumers of this interface can use this to preserve aspect 169 * ratio when displaying the paintable. 170 * 171 * This is a purely informational value and does not in any way limit the 172 * values that may be passed to [method@Gdk.Paintable.snapshot]. 173 * 174 * Usually when a @paintable returns nonzero values from 175 * [method@Gdk.Paintable.get_intrinsic_width] and 176 * [method@Gdk.Paintable.get_intrinsic_height] the aspect ratio 177 * should conform to those values, though that is not required. 178 * 179 * If the @paintable does not have a preferred aspect ratio, 180 * it returns 0. Negative values are never returned. 181 * 182 * Returns: the intrinsic aspect ratio of @paintable or 0 if none. 183 */ 184 public double getIntrinsicAspectRatio() 185 { 186 return gdk_paintable_get_intrinsic_aspect_ratio(getPaintableStruct()); 187 } 188 189 /** 190 * Gets the preferred height the @paintable would like to be displayed at. 191 * 192 * Consumers of this interface can use this to reserve enough space to draw 193 * the paintable. 194 * 195 * This is a purely informational value and does not in any way limit the 196 * values that may be passed to [method@Gdk.Paintable.snapshot]. 197 * 198 * If the @paintable does not have a preferred height, it returns 0. 199 * Negative values are never returned. 200 * 201 * Returns: the intrinsic height of @paintable or 0 if none. 202 */ 203 public int getIntrinsicHeight() 204 { 205 return gdk_paintable_get_intrinsic_height(getPaintableStruct()); 206 } 207 208 /** 209 * Gets the preferred width the @paintable would like to be displayed at. 210 * 211 * Consumers of this interface can use this to reserve enough space to draw 212 * the paintable. 213 * 214 * This is a purely informational value and does not in any way limit the 215 * values that may be passed to [method@Gdk.Paintable.snapshot]. 216 * 217 * If the @paintable does not have a preferred width, it returns 0. 218 * Negative values are never returned. 219 * 220 * Returns: the intrinsic width of @paintable or 0 if none. 221 */ 222 public int getIntrinsicWidth() 223 { 224 return gdk_paintable_get_intrinsic_width(getPaintableStruct()); 225 } 226 227 /** 228 * Called by implementations of `GdkPaintable` to invalidate their contents. 229 * 230 * Unless the contents are invalidated, implementations must guarantee that 231 * multiple calls of [method@Gdk.Paintable.snapshot] produce the same output. 232 * 233 * This function will emit the [signal@Gdk.Paintable::invalidate-contents] 234 * signal. 235 * 236 * If a @paintable reports the %GDK_PAINTABLE_STATIC_CONTENTS flag, 237 * it must not call this function. 238 */ 239 public void invalidateContents() 240 { 241 gdk_paintable_invalidate_contents(getPaintableStruct()); 242 } 243 244 /** 245 * Called by implementations of `GdkPaintable` to invalidate their size. 246 * 247 * As long as the size is not invalidated, @paintable must return the same 248 * values for its intrinsic width, height and aspect ratio. 249 * 250 * This function will emit the [signal@Gdk.Paintable::invalidate-size] 251 * signal. 252 * 253 * If a @paintable reports the %GDK_PAINTABLE_STATIC_SIZE flag, 254 * it must not call this function. 255 */ 256 public void invalidateSize() 257 { 258 gdk_paintable_invalidate_size(getPaintableStruct()); 259 } 260 261 /** 262 * Snapshots the given paintable with the given @width and @height. 263 * 264 * The paintable is drawn at the current (0,0) offset of the @snapshot. 265 * If @width and @height are not larger than zero, this function will 266 * do nothing. 267 * 268 * Params: 269 * snapshot = a `GdkSnapshot` to snapshot to 270 * width = width to snapshot in 271 * height = height to snapshot in 272 */ 273 public void snapshot(Snapshot snapshot, double width, double height) 274 { 275 gdk_paintable_snapshot(getPaintableStruct(), (snapshot is null) ? null : snapshot.getSnapshotStruct(), width, height); 276 } 277 278 /** 279 * Emitted when the contents of the @paintable change. 280 * 281 * Examples for such an event would be videos changing to the next frame or 282 * the icon theme for an icon changing. 283 */ 284 gulong addOnInvalidateContents(void delegate(PaintableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 285 { 286 return Signals.connect(this, "invalidate-contents", dlg, connectFlags ^ ConnectFlags.SWAPPED); 287 } 288 289 /** 290 * Emitted when the intrinsic size of the @paintable changes. 291 * 292 * This means the values reported by at least one of 293 * [method@Gdk.Paintable.get_intrinsic_width], 294 * [method@Gdk.Paintable.get_intrinsic_height] or 295 * [method@Gdk.Paintable.get_intrinsic_aspect_ratio] 296 * has changed. 297 * 298 * Examples for such an event would be a paintable displaying 299 * the contents of a toplevel surface being resized. 300 */ 301 gulong addOnInvalidateSize(void delegate(PaintableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 302 { 303 return Signals.connect(this, "invalidate-size", dlg, connectFlags ^ ConnectFlags.SWAPPED); 304 } 305 }