1// Package gdk was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gdk
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/gobject/types"
12)
13
14// The list of functions that can be implemented for the `GdkPaintable`
15// interface.
16//
17// Note that apart from the [vfunc@Gdk.Paintable.snapshot] function,
18// no virtual function of this interface is mandatory to implement, though it
19// is a good idea to implement [vfunc@Gdk.Paintable.get_current_image]
20// for non-static paintables and [vfunc@Gdk.Paintable.get_flags] if the
21// image is not dynamic as the default implementation returns no flags and
22// that will make the implementation likely quite slow.
23type PaintableInterface struct {
24 _ structs.HostLayout
25
26 GIface uintptr
27
28 xSnapshot uintptr
29
30 xGetCurrentImage uintptr
31
32 xGetFlags uintptr
33
34 xGetIntrinsicWidth uintptr
35
36 xGetIntrinsicHeight uintptr
37
38 xGetIntrinsicAspectRatio uintptr
39}
40
41func (x *PaintableInterface) GoPointer() uintptr {
42 return uintptr(unsafe.Pointer(x))
43}
44
45// OverrideSnapshot sets the "snapshot" callback function.
46// Snapshot the paintable. The given @width and @height are
47//
48// guaranteed to be larger than 0.0. The resulting snapshot must modify
49// only the area in the rectangle from (0,0) to (width, height).
50// This is the only function that must be implemented for this interface.
51func (x *PaintableInterface) OverrideSnapshot(cb func(Paintable, *Snapshot, float64, float64)) {
52 if cb == nil {
53 x.xSnapshot = 0
54 } else {
55 x.xSnapshot = purego.NewCallback(func(PaintableVarp uintptr, SnapshotVarp uintptr, WidthVarp float64, HeightVarp float64) {
56 cb(&PaintableBase{Ptr: PaintableVarp}, SnapshotNewFromInternalPtr(SnapshotVarp), WidthVarp, HeightVarp)
57 })
58 }
59}
60
61// GetSnapshot gets the "snapshot" callback function.
62// Snapshot the paintable. The given @width and @height are
63//
64// guaranteed to be larger than 0.0. The resulting snapshot must modify
65// only the area in the rectangle from (0,0) to (width, height).
66// This is the only function that must be implemented for this interface.
67func (x *PaintableInterface) GetSnapshot() func(Paintable, *Snapshot, float64, float64) {
68 if x.xSnapshot == 0 {
69 return nil
70 }
71 var rawCallback func(PaintableVarp uintptr, SnapshotVarp uintptr, WidthVarp float64, HeightVarp float64)
72 purego.RegisterFunc(&rawCallback, x.xSnapshot)
73 return func(PaintableVar Paintable, SnapshotVar *Snapshot, WidthVar float64, HeightVar float64) {
74 rawCallback(PaintableVar.GoPointer(), SnapshotVar.GoPointer(), WidthVar, HeightVar)
75 }
76}
77
78// OverrideGetCurrentImage sets the "get_current_image" callback function.
79// return a `GdkPaintable` that does not change over
80//
81// time. This means the `GDK_PAINTABLE_STATIC_SIZE` and
82// `GDK_PAINTABLE_STATIC_CONTENTS` flag are set.
83func (x *PaintableInterface) OverrideGetCurrentImage(cb func(Paintable) *PaintableBase) {
84 if cb == nil {
85 x.xGetCurrentImage = 0
86 } else {
87 x.xGetCurrentImage = purego.NewCallback(func(PaintableVarp uintptr) uintptr {
88 ret := cb(&PaintableBase{Ptr: PaintableVarp})
89 if ret == nil {
90 return 0
91 }
92 return ret.GoPointer()
93 })
94 }
95}
96
97// GetGetCurrentImage gets the "get_current_image" callback function.
98// return a `GdkPaintable` that does not change over
99//
100// time. This means the `GDK_PAINTABLE_STATIC_SIZE` and
101// `GDK_PAINTABLE_STATIC_CONTENTS` flag are set.
102func (x *PaintableInterface) GetGetCurrentImage() func(Paintable) *PaintableBase {
103 if x.xGetCurrentImage == 0 {
104 return nil
105 }
106 var rawCallback func(PaintableVarp uintptr) uintptr
107 purego.RegisterFunc(&rawCallback, x.xGetCurrentImage)
108 return func(PaintableVar Paintable) *PaintableBase {
109 rawRet := rawCallback(PaintableVar.GoPointer())
110 if rawRet == 0 {
111 return nil
112 }
113 ret := &PaintableBase{}
114 ret.Ptr = rawRet
115 return ret
116 }
117}
118
119// OverrideGetFlags sets the "get_flags" callback function.
120// Get the flags for this instance. See [flags@Gdk.PaintableFlags]
121//
122// for details.
123func (x *PaintableInterface) OverrideGetFlags(cb func(Paintable) PaintableFlags) {
124 if cb == nil {
125 x.xGetFlags = 0
126 } else {
127 x.xGetFlags = purego.NewCallback(func(PaintableVarp uintptr) PaintableFlags {
128 return cb(&PaintableBase{Ptr: PaintableVarp})
129 })
130 }
131}
132
133// GetGetFlags gets the "get_flags" callback function.
134// Get the flags for this instance. See [flags@Gdk.PaintableFlags]
135//
136// for details.
137func (x *PaintableInterface) GetGetFlags() func(Paintable) PaintableFlags {
138 if x.xGetFlags == 0 {
139 return nil
140 }
141 var rawCallback func(PaintableVarp uintptr) PaintableFlags
142 purego.RegisterFunc(&rawCallback, x.xGetFlags)
143 return func(PaintableVar Paintable) PaintableFlags {
144 return rawCallback(PaintableVar.GoPointer())
145 }
146}
147
148// OverrideGetIntrinsicWidth sets the "get_intrinsic_width" callback function.
149// The preferred width for this object to be
150//
151// snapshot at or 0 if none. This is purely a hint. The object must still
152// be able to render at any size.
153func (x *PaintableInterface) OverrideGetIntrinsicWidth(cb func(Paintable) int) {
154 if cb == nil {
155 x.xGetIntrinsicWidth = 0
156 } else {
157 x.xGetIntrinsicWidth = purego.NewCallback(func(PaintableVarp uintptr) int {
158 return cb(&PaintableBase{Ptr: PaintableVarp})
159 })
160 }
161}
162
163// GetGetIntrinsicWidth gets the "get_intrinsic_width" callback function.
164// The preferred width for this object to be
165//
166// snapshot at or 0 if none. This is purely a hint. The object must still
167// be able to render at any size.
168func (x *PaintableInterface) GetGetIntrinsicWidth() func(Paintable) int {
169 if x.xGetIntrinsicWidth == 0 {
170 return nil
171 }
172 var rawCallback func(PaintableVarp uintptr) int
173 purego.RegisterFunc(&rawCallback, x.xGetIntrinsicWidth)
174 return func(PaintableVar Paintable) int {
175 return rawCallback(PaintableVar.GoPointer())
176 }
177}
178
179// OverrideGetIntrinsicHeight sets the "get_intrinsic_height" callback function.
180// The preferred height for this object to be
181//
182// snapshot at or 0 if none. This is purely a hint. The object must still
183// be able to render at any size.
184func (x *PaintableInterface) OverrideGetIntrinsicHeight(cb func(Paintable) int) {
185 if cb == nil {
186 x.xGetIntrinsicHeight = 0
187 } else {
188 x.xGetIntrinsicHeight = purego.NewCallback(func(PaintableVarp uintptr) int {
189 return cb(&PaintableBase{Ptr: PaintableVarp})
190 })
191 }
192}
193
194// GetGetIntrinsicHeight gets the "get_intrinsic_height" callback function.
195// The preferred height for this object to be
196//
197// snapshot at or 0 if none. This is purely a hint. The object must still
198// be able to render at any size.
199func (x *PaintableInterface) GetGetIntrinsicHeight() func(Paintable) int {
200 if x.xGetIntrinsicHeight == 0 {
201 return nil
202 }
203 var rawCallback func(PaintableVarp uintptr) int
204 purego.RegisterFunc(&rawCallback, x.xGetIntrinsicHeight)
205 return func(PaintableVar Paintable) int {
206 return rawCallback(PaintableVar.GoPointer())
207 }
208}
209
210// OverrideGetIntrinsicAspectRatio sets the "get_intrinsic_aspect_ratio" callback function.
211// The preferred aspect ratio for this object
212//
213// or 0 if none. If both [vfunc@Gdk.Paintable.get_intrinsic_width]
214// and [vfunc@Gdk.Paintable.get_intrinsic_height] return non-zero
215// values, this function should return the aspect ratio computed from those.
216func (x *PaintableInterface) OverrideGetIntrinsicAspectRatio(cb func(Paintable) float64) {
217 if cb == nil {
218 x.xGetIntrinsicAspectRatio = 0
219 } else {
220 x.xGetIntrinsicAspectRatio = purego.NewCallback(func(PaintableVarp uintptr) float64 {
221 return cb(&PaintableBase{Ptr: PaintableVarp})
222 })
223 }
224}
225
226// GetGetIntrinsicAspectRatio gets the "get_intrinsic_aspect_ratio" callback function.
227// The preferred aspect ratio for this object
228//
229// or 0 if none. If both [vfunc@Gdk.Paintable.get_intrinsic_width]
230// and [vfunc@Gdk.Paintable.get_intrinsic_height] return non-zero
231// values, this function should return the aspect ratio computed from those.
232func (x *PaintableInterface) GetGetIntrinsicAspectRatio() func(Paintable) float64 {
233 if x.xGetIntrinsicAspectRatio == 0 {
234 return nil
235 }
236 var rawCallback func(PaintableVarp uintptr) float64
237 purego.RegisterFunc(&rawCallback, x.xGetIntrinsicAspectRatio)
238 return func(PaintableVar Paintable) float64 {
239 return rawCallback(PaintableVar.GoPointer())
240 }
241}
242
243// An interface for content that can be painted.
244//
245// The content of a `GdkPaintable` can be painted anywhere at any size
246// without requiring any sort of layout. The interface is inspired by
247// similar concepts elsewhere, such as
248// [ClutterContent](https://developer.gnome.org/clutter/stable/ClutterContent.html),
249// [HTML/CSS Paint Sources](https://www.w3.org/TR/css-images-4/#paint-source),
250// or [SVG Paint Servers](https://www.w3.org/TR/SVG2/pservers.html).
251//
252// A `GdkPaintable` can be snapshot at any time and size using
253// [method@Gdk.Paintable.snapshot]. How the paintable interprets that size and
254// if it scales or centers itself into the given rectangle is implementation
255// defined, though if you are implementing a `GdkPaintable` and don't know what
256// to do, it is suggested that you scale your paintable ignoring any potential
257// aspect ratio.
258//
259// The contents that a `GdkPaintable` produces may depend on the [class@Gdk.Snapshot]
260// passed to it. For example, paintables may decide to use more detailed images
261// on higher resolution screens or when OpenGL is available. A `GdkPaintable`
262// will however always produce the same output for the same snapshot.
263//
264// A `GdkPaintable` may change its contents, meaning that it will now produce
265// a different output with the same snapshot. Once that happens, it will call
266// [method@Gdk.Paintable.invalidate_contents] which will emit the
267// [signal@Gdk.Paintable::invalidate-contents] signal. If a paintable is known
268// to never change its contents, it will set the %GDK_PAINTABLE_STATIC_CONTENTS
269// flag. If a consumer cannot deal with changing contents, it may call
270// [method@Gdk.Paintable.get_current_image] which will return a static
271// paintable and use that.
272//
273// A paintable can report an intrinsic (or preferred) size or aspect ratio it
274// wishes to be rendered at, though it doesn't have to. Consumers of the interface
275// can use this information to layout thepaintable appropriately. Just like the
276// contents, the size of a paintable can change. A paintable will indicate this
277// by calling [method@Gdk.Paintable.invalidate_size] which will emit the
278// [signal@Gdk.Paintable::invalidate-size] signal. And just like for contents,
279// if a paintable is known to never change its size, it will set the
280// %GDK_PAINTABLE_STATIC_SIZE flag.
281//
282// Besides API for applications, there are some functions that are only
283// useful for implementing subclasses and should not be used by applications:
284// [method@Gdk.Paintable.invalidate_contents],
285// [method@Gdk.Paintable.invalidate_size],
286// [func@Gdk.Paintable.new_empty].
287type Paintable interface {
288 GoPointer() uintptr
289 SetGoPointer(uintptr)
290 ComputeConcreteSize(SpecifiedWidthVar float64, SpecifiedHeightVar float64, DefaultWidthVar float64, DefaultHeightVar float64, ConcreteWidthVar *float64, ConcreteHeightVar *float64)
291 GetCurrentImage() *PaintableBase
292 GetFlags() PaintableFlags
293 GetIntrinsicAspectRatio() float64
294 GetIntrinsicHeight() int
295 GetIntrinsicWidth() int
296 InvalidateContents()
297 InvalidateSize()
298 Snapshot(SnapshotVar *Snapshot, WidthVar float64, HeightVar float64)
299}
300
301var xPaintableGLibType func() types.GType
302
303func PaintableGLibType() types.GType {
304 return xPaintableGLibType()
305}
306
307type PaintableBase struct {
308 Ptr uintptr
309}
310
311func (x *PaintableBase) GoPointer() uintptr {
312 if x == nil {
313 return 0
314 }
315 return x.Ptr
316}
317
318func (x *PaintableBase) SetGoPointer(ptr uintptr) {
319 x.Ptr = ptr
320}
321
322// Compute a concrete size for the `GdkPaintable`.
323//
324// Applies the sizing algorithm outlined in the
325// [CSS Image spec](https://drafts.csswg.org/css-images-3/#default-sizing)
326// to the given @paintable. See that link for more details.
327//
328// It is not necessary to call this function when both @specified_width
329// and @specified_height are known, but it is useful to call this
330// function in GtkWidget:measure implementations to compute the
331// other dimension when only one dimension is given.
332func (x *PaintableBase) ComputeConcreteSize(SpecifiedWidthVar float64, SpecifiedHeightVar float64, DefaultWidthVar float64, DefaultHeightVar float64, ConcreteWidthVar *float64, ConcreteHeightVar *float64) {
333
334 XGdkPaintableComputeConcreteSize(x.GoPointer(), SpecifiedWidthVar, SpecifiedHeightVar, DefaultWidthVar, DefaultHeightVar, ConcreteWidthVar, ConcreteHeightVar)
335
336}
337
338// Gets an immutable paintable for the current contents displayed by @paintable.
339//
340// This is useful when you want to retain the current state of an animation,
341// for example to take a screenshot of a running animation.
342//
343// If the @paintable is already immutable, it will return itself.
344func (x *PaintableBase) GetCurrentImage() *PaintableBase {
345 var cls *PaintableBase
346
347 cret := XGdkPaintableGetCurrentImage(x.GoPointer())
348
349 if cret == 0 {
350 return nil
351 }
352 cls = &PaintableBase{}
353 cls.Ptr = cret
354 return cls
355}
356
357// Get flags for the paintable.
358//
359// This is oftentimes useful for optimizations.
360//
361// See [flags@Gdk.PaintableFlags] for the flags and what they mean.
362func (x *PaintableBase) GetFlags() PaintableFlags {
363
364 cret := XGdkPaintableGetFlags(x.GoPointer())
365 return cret
366}
367
368// Gets the preferred aspect ratio the @paintable would like to be displayed at.
369//
370// The aspect ratio is the width divided by the height, so a value of 0.5
371// means that the @paintable prefers to be displayed twice as high as it
372// is wide. Consumers of this interface can use this to preserve aspect
373// ratio when displaying the paintable.
374//
375// This is a purely informational value and does not in any way limit the
376// values that may be passed to [method@Gdk.Paintable.snapshot].
377//
378// Usually when a @paintable returns nonzero values from
379// [method@Gdk.Paintable.get_intrinsic_width] and
380// [method@Gdk.Paintable.get_intrinsic_height] the aspect ratio
381// should conform to those values, though that is not required.
382//
383// If the @paintable does not have a preferred aspect ratio,
384// it returns 0. Negative values are never returned.
385func (x *PaintableBase) GetIntrinsicAspectRatio() float64 {
386
387 cret := XGdkPaintableGetIntrinsicAspectRatio(x.GoPointer())
388 return cret
389}
390
391// Gets the preferred height the @paintable would like to be displayed at.
392//
393// Consumers of this interface can use this to reserve enough space to draw
394// the paintable.
395//
396// This is a purely informational value and does not in any way limit the
397// values that may be passed to [method@Gdk.Paintable.snapshot].
398//
399// If the @paintable does not have a preferred height, it returns 0.
400// Negative values are never returned.
401func (x *PaintableBase) GetIntrinsicHeight() int {
402
403 cret := XGdkPaintableGetIntrinsicHeight(x.GoPointer())
404 return cret
405}
406
407// Gets the preferred width the @paintable would like to be displayed at.
408//
409// Consumers of this interface can use this to reserve enough space to draw
410// the paintable.
411//
412// This is a purely informational value and does not in any way limit the
413// values that may be passed to [method@Gdk.Paintable.snapshot].
414//
415// If the @paintable does not have a preferred width, it returns 0.
416// Negative values are never returned.
417func (x *PaintableBase) GetIntrinsicWidth() int {
418
419 cret := XGdkPaintableGetIntrinsicWidth(x.GoPointer())
420 return cret
421}
422
423// Called by implementations of `GdkPaintable` to invalidate their contents.
424//
425// Unless the contents are invalidated, implementations must guarantee that
426// multiple calls of [method@Gdk.Paintable.snapshot] produce the same output.
427//
428// This function will emit the [signal@Gdk.Paintable::invalidate-contents]
429// signal.
430//
431// If a @paintable reports the %GDK_PAINTABLE_STATIC_CONTENTS flag,
432// it must not call this function.
433func (x *PaintableBase) InvalidateContents() {
434
435 XGdkPaintableInvalidateContents(x.GoPointer())
436
437}
438
439// Called by implementations of `GdkPaintable` to invalidate their size.
440//
441// As long as the size is not invalidated, @paintable must return the same
442// values for its intrinsic width, height and aspect ratio.
443//
444// This function will emit the [signal@Gdk.Paintable::invalidate-size]
445// signal.
446//
447// If a @paintable reports the %GDK_PAINTABLE_STATIC_SIZE flag,
448// it must not call this function.
449func (x *PaintableBase) InvalidateSize() {
450
451 XGdkPaintableInvalidateSize(x.GoPointer())
452
453}
454
455// Snapshots the given paintable with the given @width and @height.
456//
457// The paintable is drawn at the current (0,0) offset of the @snapshot.
458// If @width and @height are not larger than zero, this function will
459// do nothing.
460func (x *PaintableBase) Snapshot(SnapshotVar *Snapshot, WidthVar float64, HeightVar float64) {
461
462 XGdkPaintableSnapshot(x.GoPointer(), SnapshotVar.GoPointer(), WidthVar, HeightVar)
463
464}
465
466var XGdkPaintableComputeConcreteSize func(uintptr, float64, float64, float64, float64, *float64, *float64)
467var XGdkPaintableGetCurrentImage func(uintptr) uintptr
468var XGdkPaintableGetFlags func(uintptr) PaintableFlags
469var XGdkPaintableGetIntrinsicAspectRatio func(uintptr) float64
470var XGdkPaintableGetIntrinsicHeight func(uintptr) int
471var XGdkPaintableGetIntrinsicWidth func(uintptr) int
472var XGdkPaintableInvalidateContents func(uintptr)
473var XGdkPaintableInvalidateSize func(uintptr)
474var XGdkPaintableSnapshot func(uintptr, uintptr, float64, float64)
475
476// Flags about a paintable object.
477//
478// Implementations use these for optimizations such as caching.
479type PaintableFlags int
480
481var xPaintableFlagsGLibType func() types.GType
482
483func PaintableFlagsGLibType() types.GType {
484 return xPaintableFlagsGLibType()
485}
486
487const (
488
489 // The size is immutable.
490 // The [signal@Gdk.Paintable::invalidate-size] signal will never be
491 // emitted.
492 PaintableStaticSizeValue PaintableFlags = 1
493 // The content is immutable.
494 // The [signal@Gdk.Paintable::invalidate-contents] signal will never be
495 // emitted.
496 PaintableStaticContentsValue PaintableFlags = 2
497)
498
499var xPaintableNewEmpty func(int, int) uintptr
500
501// Returns a paintable that has the given intrinsic size and draws nothing.
502//
503// This is often useful for implementing the
504// [vfunc@Gdk.Paintable.get_current_image] virtual function
505// when the paintable is in an incomplete state (like a
506// [GtkMediaStream](../gtk4/class.MediaStream.html) before receiving
507// the first frame).
508func PaintableNewEmpty(IntrinsicWidthVar int, IntrinsicHeightVar int) *PaintableBase {
509 var cls *PaintableBase
510
511 cret := xPaintableNewEmpty(IntrinsicWidthVar, IntrinsicHeightVar)
512
513 if cret == 0 {
514 return nil
515 }
516 cls = &PaintableBase{}
517 cls.Ptr = cret
518 return cls
519}
520
521func init() {
522 core.SetPackageName("GDK", "gtk4")
523 core.SetSharedLibraries("GDK", []string{"libgtk-4.so.1"})
524 var libs []uintptr
525 for _, libPath := range core.GetPaths("GDK") {
526 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
527 if err != nil {
528 panic(err)
529 }
530 libs = append(libs, lib)
531 }
532
533 core.PuregoSafeRegister(&xPaintableFlagsGLibType, libs, "gdk_paintable_flags_get_type")
534
535 core.PuregoSafeRegister(&xPaintableNewEmpty, libs, "gdk_paintable_new_empty")
536
537 core.PuregoSafeRegister(&xPaintableGLibType, libs, "gdk_paintable_get_type")
538
539 core.PuregoSafeRegister(&XGdkPaintableComputeConcreteSize, libs, "gdk_paintable_compute_concrete_size")
540 core.PuregoSafeRegister(&XGdkPaintableGetCurrentImage, libs, "gdk_paintable_get_current_image")
541 core.PuregoSafeRegister(&XGdkPaintableGetFlags, libs, "gdk_paintable_get_flags")
542 core.PuregoSafeRegister(&XGdkPaintableGetIntrinsicAspectRatio, libs, "gdk_paintable_get_intrinsic_aspect_ratio")
543 core.PuregoSafeRegister(&XGdkPaintableGetIntrinsicHeight, libs, "gdk_paintable_get_intrinsic_height")
544 core.PuregoSafeRegister(&XGdkPaintableGetIntrinsicWidth, libs, "gdk_paintable_get_intrinsic_width")
545 core.PuregoSafeRegister(&XGdkPaintableInvalidateContents, libs, "gdk_paintable_invalidate_contents")
546 core.PuregoSafeRegister(&XGdkPaintableInvalidateSize, libs, "gdk_paintable_invalidate_size")
547 core.PuregoSafeRegister(&XGdkPaintableSnapshot, libs, "gdk_paintable_snapshot")
548
549}