| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: MIT |
| 3 | |
| 4 | enum OrbiterState { front, back } |
| 5 | |
| 6 | export component Orbiter { |
| 7 | in property <OrbiterState> state: OrbiterState.front; |
| 8 | in-out property source <=> img.source; |
| 9 | in-out property colorize <=> img.colorize; |
| 10 | in property <angle> orbit-rotation: 0deg; |
| 11 | in property <angle> offset: 45deg; |
| 12 | in property <length> radius: 220px; |
| 13 | property <angle> internal-rotation: orbit-rotation + offset; |
| 14 | in property <angle> orbit-attack: 180deg; |
| 15 | in property <length> ball-size: 60px; |
| 16 | property <length> zPos: sin(internal-rotation) * radius; |
| 17 | out property <float> scale: 0.3 + 0.7 * (zPos + radius) / (2 * radius); |
| 18 | property <bool> infront: internal-rotation.mod(360deg) < 180deg; |
| 19 | |
| 20 | function isVisible() -> bool { |
| 21 | if (infront && state == OrbiterState.front) || (!infront && state == OrbiterState.back) { |
| 22 | return true; |
| 23 | } else { |
| 24 | return false; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | visible: isVisible(); |
| 29 | |
| 30 | Rectangle { |
| 31 | x: cos(orbit-attack) * cos(internal-rotation) * radius; |
| 32 | y: sin(orbit-attack) * cos(internal-rotation) * radius; |
| 33 | img := Image { |
| 34 | width: root.ball-size * scale; |
| 35 | height: root.ball-size * scale; |
| 36 | source: @image-url("images/sphere-small.png" ); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | } |
| 41 | |