Scoop API

scoop:scoop.desktop:0.1.0

src/images.scoop

Selected production source · src/images.scoop

1package scoop.desktop
3import scoop.window.DesktopImage
5internal fun <R> withDesktopImage(image: DesktopImage?, action: (Ptr<Unit>?) -> R): R {
6 when (image) {
7 case None -> return action(None)
8 case Some(val value) -> @Unsafe
9 {
10 val native =
11 desktopCreated(
12 nativeImageCreate(
13 value.size.width,
14 value.size.height,
15 if (value.template)
16 1
17 else
18 0
19 ),
20 "desktop image"
21 )
22 try {
23 for (representation in value.representations)
24 representation.pixels.withDataPointer {
25 pixels,
26 _ -> @Unsafe
27 {
28 desktopStatus(
29 nativeImageAdd(
30 native,
31 representation.size.width,
32 representation.size.height,
33 pixels
34 ),
35 "desktop image pixels"
36 )
37 }
38 }
39 return action(Some(native))
40 } finally {
41 nativeImageDestroy(native)
42 }
43 }
44 }
47internal fun sameDesktopImage(left: DesktopImage?, right: DesktopImage?): Boolean =
48 when ((left, right)) {
49 case(Some(val a), Some(val b)) -> a === b
50 case(None, None) -> true
51 else -> false
52 }