File tree Expand file tree Collapse file tree 3 files changed +87
-1
lines changed Expand file tree Collapse file tree 3 files changed +87
-1
lines changed Original file line number Diff line number Diff line change
1
+ import ScreenshotsHelper.collectScreenshots
2
+
1
3
plugins {
2
4
org.openrndr.extra.convention.`kotlin- multiplatform`
3
5
}
4
6
5
7
kotlin {
8
+ jvm {
9
+ @Suppress(" UNUSED_VARIABLE" )
10
+ val demo by compilations.getting {
11
+ // TODO: Move demos to /jvmDemo
12
+ defaultSourceSet {
13
+ kotlin.srcDir(" src/demo/kotlin" )
14
+ }
15
+ collectScreenshots { }
16
+ }
17
+ testRuns[" test" ].executionTask {
18
+ useJUnitPlatform {
19
+ includeEngines(" spek2" )
20
+ }
21
+ }
22
+ }
23
+
6
24
sourceSets {
7
25
@Suppress(" UNUSED_VARIABLE" )
8
26
val commonMain by getting {
@@ -15,5 +33,12 @@ kotlin {
15
33
implementation(libs.kotlin.reflect)
16
34
}
17
35
}
36
+
37
+ @Suppress(" UNUSED_VARIABLE" )
38
+ val jvmDemo by getting {
39
+ dependencies {
40
+ implementation(project(" :orx-camera" ))
41
+ }
42
+ }
18
43
}
19
- }
44
+ }
Original file line number Diff line number Diff line change
1
+ package org.openrndr.extra.camera
2
+
3
+ import org.openrndr.Extension
4
+ import org.openrndr.Program
5
+ import org.openrndr.draw.Drawer
6
+ import org.openrndr.math.Matrix44
7
+ import org.openrndr.math.transforms.buildTransform
8
+
9
+ /* *
10
+ * The [Camera2D] extension enables:
11
+ * - **panning** the view by moving the mouse while a mouse button is pressed
12
+ * - **zooming** in and out by using the mouse wheel
13
+ *
14
+ * Usage: `extend(Camera2D())`
15
+ */
16
+ class Camera2D : Extension {
17
+ override var enabled = true
18
+ var view = Matrix44 .IDENTITY
19
+ override fun setup (program : Program ) {
20
+ program.mouse.dragged.listen {
21
+ view = buildTransform { translate(it.dragDisplacement) } * view
22
+ }
23
+ program.mouse.scrolled.listen {
24
+ val scaleFactor = 1.0 - it.rotation.y * 0.03
25
+ view = buildTransform {
26
+ translate(it.position)
27
+ scale(scaleFactor)
28
+ translate(- it.position)
29
+ } * view
30
+ }
31
+ }
32
+
33
+ override fun beforeDraw (drawer : Drawer , program : Program ) {
34
+ drawer.view = view
35
+ }
36
+ }
Original file line number Diff line number Diff line change
1
+ import org.openrndr.application
2
+ import org.openrndr.color.ColorRGBa
3
+ import org.openrndr.draw.loadFont
4
+ import org.openrndr.extra.camera.Camera2D
5
+
6
+ /* *
7
+ * # Camera2D demo
8
+ *
9
+ * click and drag the mouse for panning, use the mouse wheel for zooming
10
+ */
11
+ fun main () = application {
12
+ program {
13
+ val font = loadFont(" demo-data/fonts/IBMPlexMono-Regular.ttf" , 72.0 )
14
+
15
+ extend(Camera2D ())
16
+ extend {
17
+ drawer.circle(drawer.bounds.center, 300.0 )
18
+
19
+ drawer.fontMap = font
20
+ drawer.fill = ColorRGBa .PINK
21
+ drawer.text(" click and drag mouse" , 50.0 , 400.0 )
22
+ drawer.text(" use mouse wheel" , 50.0 , 500.0 )
23
+ }
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments