From ed4bc0cc146f53450f076532b73281dcfe07bf04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ma=C5=A1karinec?= Date: Thu, 20 Jun 2024 16:19:39 +0200 Subject: [PATCH] examples -> demos, create samples --- {examples => demos}/extensions/global.um | 0 {examples => demos}/extensions/main.c | 0 {examples => demos}/extensions/main.um | 0 {examples => demos}/extensions/main.umi | Bin .../flappy/ComicNeue-Regular.ttf | Bin {examples => demos}/flappy/gfx/bg.png | Bin {examples => demos}/flappy/gfx/bird.png | Bin {examples => demos}/flappy/gfx/button.png | Bin {examples => demos}/flappy/gfx/pipe.png | Bin {examples => demos}/flappy/main.um | 0 {examples => demos}/flappy/sfx/hitHurt.wav | Bin {examples => demos}/flappy/sfx/jump.wav | Bin {examples => demos}/hello-world/main.um | 0 {examples => demos}/platformer/game/bees.um | 0 {examples => demos}/platformer/game/env.um | 0 {examples => demos}/platformer/game/game.um | 0 {examples => demos}/platformer/game/player.um | 0 {examples => demos}/platformer/global.um | 0 {examples => demos}/platformer/main.um | 0 {examples => demos}/platformer/res/bee.png | Bin {examples => demos}/platformer/res/coin.png | Bin {examples => demos}/platformer/res/flag.png | Bin {examples => demos}/platformer/res/hat.png | Bin {examples => demos}/platformer/res/plant.png | Bin .../platformer/res/platformertiles.png | Bin {examples => demos}/platformer/res/tile.png | Bin {examples => demos}/platformer/scene.um | 0 .../platformer/shaders/lava.frag | 0 .../platformer/shaders/lava.vert | 0 {examples => demos}/platformer/strings.um | 0 {examples => demos}/platformer/tilemap.txt | 0 {examples => demos}/pomodoro/Alarm.wav | Bin {examples => demos}/pomodoro/AlarmOld.wav | Bin {examples => demos}/pomodoro/Font.ttf | Bin {examples => demos}/pomodoro/main.um | 0 {examples => demos}/pomodoro/rectbase.png | Bin {examples => demos}/space-shooter/bullet.um | 0 {examples => demos}/space-shooter/effects.um | 0 {examples => demos}/space-shooter/enemy.um | 0 {examples => demos}/space-shooter/game.um | 0 .../space-shooter/gfx/enemy.png | Bin .../space-shooter/gfx/hearth.png | Bin .../space-shooter/gfx/marediv-regular.ttf | Bin .../space-shooter/gfx/ship1.png | Bin .../space-shooter/gfx/ship2.png | Bin {examples => demos}/space-shooter/global.um | 0 {examples => demos}/space-shooter/hud.um | 0 {examples => demos}/space-shooter/main.um | 0 {examples => demos}/space-shooter/menu.um | 0 {examples => demos}/space-shooter/player.um | 0 {examples => demos}/space-shooter/score | 0 .../space-shooter/sfx/block.wav | Bin .../space-shooter/sfx/dmgsound.wav | Bin .../space-shooter/sfx/explosion.wav | Bin .../space-shooter/sfx/laser.wav | Bin .../space-shooter/sfx/shoot.wav | Bin {examples => demos}/space-shooter/sound.um | 0 {examples => demos}/space-shooter/star.um | 0 {examples => demos}/tetris/Changelog | 0 {examples => demos}/tetris/Clear.wav | Bin {examples => demos}/tetris/ClearMega.wav | Bin ...ingeCopyrightSoListenToThisMonstrosity.wav | Bin {examples => demos}/tetris/Placement.wav | Bin {examples => demos}/tetris/Rotation.wav | Bin {examples => demos}/tetris/background.um | 0 {examples => demos}/tetris/bag.um | 0 {examples => demos}/tetris/bg_tile.png | Bin {examples => demos}/tetris/crazytext.um | 0 {examples => demos}/tetris/falling_piece.um | 0 {examples => demos}/tetris/field.um | 0 {examples => demos}/tetris/fx.um | 0 {examples => demos}/tetris/gameplay.um | 0 {examples => demos}/tetris/global.um | 0 {examples => demos}/tetris/latch.um | 0 {examples => demos}/tetris/main.um | 0 {examples => demos}/tetris/piece.um | 0 {examples => demos}/tetris/presets.um | 0 examples/README.md | 9 - samples/basic/main.um | 14 + samples/input/keyboard/main.um | 46 ++ src/staembed.c | 584 +----------------- umka/ui.um | 3 +- 82 files changed, 77 insertions(+), 579 deletions(-) rename {examples => demos}/extensions/global.um (100%) rename {examples => demos}/extensions/main.c (100%) rename {examples => demos}/extensions/main.um (100%) rename {examples => demos}/extensions/main.umi (100%) rename {examples => demos}/flappy/ComicNeue-Regular.ttf (100%) rename {examples => demos}/flappy/gfx/bg.png (100%) rename {examples => demos}/flappy/gfx/bird.png (100%) rename {examples => demos}/flappy/gfx/button.png (100%) rename {examples => demos}/flappy/gfx/pipe.png (100%) rename {examples => demos}/flappy/main.um (100%) rename {examples => demos}/flappy/sfx/hitHurt.wav (100%) rename {examples => demos}/flappy/sfx/jump.wav (100%) rename {examples => demos}/hello-world/main.um (100%) rename {examples => demos}/platformer/game/bees.um (100%) rename {examples => demos}/platformer/game/env.um (100%) rename {examples => demos}/platformer/game/game.um (100%) rename {examples => demos}/platformer/game/player.um (100%) rename {examples => demos}/platformer/global.um (100%) rename {examples => demos}/platformer/main.um (100%) rename {examples => demos}/platformer/res/bee.png (100%) rename {examples => demos}/platformer/res/coin.png (100%) rename {examples => demos}/platformer/res/flag.png (100%) rename {examples => demos}/platformer/res/hat.png (100%) rename {examples => demos}/platformer/res/plant.png (100%) rename {examples => demos}/platformer/res/platformertiles.png (100%) rename {examples => demos}/platformer/res/tile.png (100%) rename {examples => demos}/platformer/scene.um (100%) rename {examples => demos}/platformer/shaders/lava.frag (100%) rename {examples => demos}/platformer/shaders/lava.vert (100%) rename {examples => demos}/platformer/strings.um (100%) rename {examples => demos}/platformer/tilemap.txt (100%) rename {examples => demos}/pomodoro/Alarm.wav (100%) rename {examples => demos}/pomodoro/AlarmOld.wav (100%) rename {examples => demos}/pomodoro/Font.ttf (100%) rename {examples => demos}/pomodoro/main.um (100%) rename {examples => demos}/pomodoro/rectbase.png (100%) rename {examples => demos}/space-shooter/bullet.um (100%) rename {examples => demos}/space-shooter/effects.um (100%) rename {examples => demos}/space-shooter/enemy.um (100%) rename {examples => demos}/space-shooter/game.um (100%) rename {examples => demos}/space-shooter/gfx/enemy.png (100%) rename {examples => demos}/space-shooter/gfx/hearth.png (100%) rename {examples => demos}/space-shooter/gfx/marediv-regular.ttf (100%) rename {examples => demos}/space-shooter/gfx/ship1.png (100%) rename {examples => demos}/space-shooter/gfx/ship2.png (100%) rename {examples => demos}/space-shooter/global.um (100%) rename {examples => demos}/space-shooter/hud.um (100%) rename {examples => demos}/space-shooter/main.um (100%) rename {examples => demos}/space-shooter/menu.um (100%) rename {examples => demos}/space-shooter/player.um (100%) rename {examples => demos}/space-shooter/score (100%) rename {examples => demos}/space-shooter/sfx/block.wav (100%) rename {examples => demos}/space-shooter/sfx/dmgsound.wav (100%) rename {examples => demos}/space-shooter/sfx/explosion.wav (100%) rename {examples => demos}/space-shooter/sfx/laser.wav (100%) rename {examples => demos}/space-shooter/sfx/shoot.wav (100%) rename {examples => demos}/space-shooter/sound.um (100%) rename {examples => demos}/space-shooter/star.um (100%) rename {examples => demos}/tetris/Changelog (100%) rename {examples => demos}/tetris/Clear.wav (100%) rename {examples => demos}/tetris/ClearMega.wav (100%) rename {examples => demos}/tetris/IDontWantToInfringeCopyrightSoListenToThisMonstrosity.wav (100%) rename {examples => demos}/tetris/Placement.wav (100%) rename {examples => demos}/tetris/Rotation.wav (100%) rename {examples => demos}/tetris/background.um (100%) rename {examples => demos}/tetris/bag.um (100%) rename {examples => demos}/tetris/bg_tile.png (100%) rename {examples => demos}/tetris/crazytext.um (100%) rename {examples => demos}/tetris/falling_piece.um (100%) rename {examples => demos}/tetris/field.um (100%) rename {examples => demos}/tetris/fx.um (100%) rename {examples => demos}/tetris/gameplay.um (100%) rename {examples => demos}/tetris/global.um (100%) rename {examples => demos}/tetris/latch.um (100%) rename {examples => demos}/tetris/main.um (100%) rename {examples => demos}/tetris/piece.um (100%) rename {examples => demos}/tetris/presets.um (100%) delete mode 100644 examples/README.md create mode 100644 samples/basic/main.um create mode 100644 samples/input/keyboard/main.um diff --git a/examples/extensions/global.um b/demos/extensions/global.um similarity index 100% rename from examples/extensions/global.um rename to demos/extensions/global.um diff --git a/examples/extensions/main.c b/demos/extensions/main.c similarity index 100% rename from examples/extensions/main.c rename to demos/extensions/main.c diff --git a/examples/extensions/main.um b/demos/extensions/main.um similarity index 100% rename from examples/extensions/main.um rename to demos/extensions/main.um diff --git a/examples/extensions/main.umi b/demos/extensions/main.umi similarity index 100% rename from examples/extensions/main.umi rename to demos/extensions/main.umi diff --git a/examples/flappy/ComicNeue-Regular.ttf b/demos/flappy/ComicNeue-Regular.ttf similarity index 100% rename from examples/flappy/ComicNeue-Regular.ttf rename to demos/flappy/ComicNeue-Regular.ttf diff --git a/examples/flappy/gfx/bg.png b/demos/flappy/gfx/bg.png similarity index 100% rename from examples/flappy/gfx/bg.png rename to demos/flappy/gfx/bg.png diff --git a/examples/flappy/gfx/bird.png b/demos/flappy/gfx/bird.png similarity index 100% rename from examples/flappy/gfx/bird.png rename to demos/flappy/gfx/bird.png diff --git a/examples/flappy/gfx/button.png b/demos/flappy/gfx/button.png similarity index 100% rename from examples/flappy/gfx/button.png rename to demos/flappy/gfx/button.png diff --git a/examples/flappy/gfx/pipe.png b/demos/flappy/gfx/pipe.png similarity index 100% rename from examples/flappy/gfx/pipe.png rename to demos/flappy/gfx/pipe.png diff --git a/examples/flappy/main.um b/demos/flappy/main.um similarity index 100% rename from examples/flappy/main.um rename to demos/flappy/main.um diff --git a/examples/flappy/sfx/hitHurt.wav b/demos/flappy/sfx/hitHurt.wav similarity index 100% rename from examples/flappy/sfx/hitHurt.wav rename to demos/flappy/sfx/hitHurt.wav diff --git a/examples/flappy/sfx/jump.wav b/demos/flappy/sfx/jump.wav similarity index 100% rename from examples/flappy/sfx/jump.wav rename to demos/flappy/sfx/jump.wav diff --git a/examples/hello-world/main.um b/demos/hello-world/main.um similarity index 100% rename from examples/hello-world/main.um rename to demos/hello-world/main.um diff --git a/examples/platformer/game/bees.um b/demos/platformer/game/bees.um similarity index 100% rename from examples/platformer/game/bees.um rename to demos/platformer/game/bees.um diff --git a/examples/platformer/game/env.um b/demos/platformer/game/env.um similarity index 100% rename from examples/platformer/game/env.um rename to demos/platformer/game/env.um diff --git a/examples/platformer/game/game.um b/demos/platformer/game/game.um similarity index 100% rename from examples/platformer/game/game.um rename to demos/platformer/game/game.um diff --git a/examples/platformer/game/player.um b/demos/platformer/game/player.um similarity index 100% rename from examples/platformer/game/player.um rename to demos/platformer/game/player.um diff --git a/examples/platformer/global.um b/demos/platformer/global.um similarity index 100% rename from examples/platformer/global.um rename to demos/platformer/global.um diff --git a/examples/platformer/main.um b/demos/platformer/main.um similarity index 100% rename from examples/platformer/main.um rename to demos/platformer/main.um diff --git a/examples/platformer/res/bee.png b/demos/platformer/res/bee.png similarity index 100% rename from examples/platformer/res/bee.png rename to demos/platformer/res/bee.png diff --git a/examples/platformer/res/coin.png b/demos/platformer/res/coin.png similarity index 100% rename from examples/platformer/res/coin.png rename to demos/platformer/res/coin.png diff --git a/examples/platformer/res/flag.png b/demos/platformer/res/flag.png similarity index 100% rename from examples/platformer/res/flag.png rename to demos/platformer/res/flag.png diff --git a/examples/platformer/res/hat.png b/demos/platformer/res/hat.png similarity index 100% rename from examples/platformer/res/hat.png rename to demos/platformer/res/hat.png diff --git a/examples/platformer/res/plant.png b/demos/platformer/res/plant.png similarity index 100% rename from examples/platformer/res/plant.png rename to demos/platformer/res/plant.png diff --git a/examples/platformer/res/platformertiles.png b/demos/platformer/res/platformertiles.png similarity index 100% rename from examples/platformer/res/platformertiles.png rename to demos/platformer/res/platformertiles.png diff --git a/examples/platformer/res/tile.png b/demos/platformer/res/tile.png similarity index 100% rename from examples/platformer/res/tile.png rename to demos/platformer/res/tile.png diff --git a/examples/platformer/scene.um b/demos/platformer/scene.um similarity index 100% rename from examples/platformer/scene.um rename to demos/platformer/scene.um diff --git a/examples/platformer/shaders/lava.frag b/demos/platformer/shaders/lava.frag similarity index 100% rename from examples/platformer/shaders/lava.frag rename to demos/platformer/shaders/lava.frag diff --git a/examples/platformer/shaders/lava.vert b/demos/platformer/shaders/lava.vert similarity index 100% rename from examples/platformer/shaders/lava.vert rename to demos/platformer/shaders/lava.vert diff --git a/examples/platformer/strings.um b/demos/platformer/strings.um similarity index 100% rename from examples/platformer/strings.um rename to demos/platformer/strings.um diff --git a/examples/platformer/tilemap.txt b/demos/platformer/tilemap.txt similarity index 100% rename from examples/platformer/tilemap.txt rename to demos/platformer/tilemap.txt diff --git a/examples/pomodoro/Alarm.wav b/demos/pomodoro/Alarm.wav similarity index 100% rename from examples/pomodoro/Alarm.wav rename to demos/pomodoro/Alarm.wav diff --git a/examples/pomodoro/AlarmOld.wav b/demos/pomodoro/AlarmOld.wav similarity index 100% rename from examples/pomodoro/AlarmOld.wav rename to demos/pomodoro/AlarmOld.wav diff --git a/examples/pomodoro/Font.ttf b/demos/pomodoro/Font.ttf similarity index 100% rename from examples/pomodoro/Font.ttf rename to demos/pomodoro/Font.ttf diff --git a/examples/pomodoro/main.um b/demos/pomodoro/main.um similarity index 100% rename from examples/pomodoro/main.um rename to demos/pomodoro/main.um diff --git a/examples/pomodoro/rectbase.png b/demos/pomodoro/rectbase.png similarity index 100% rename from examples/pomodoro/rectbase.png rename to demos/pomodoro/rectbase.png diff --git a/examples/space-shooter/bullet.um b/demos/space-shooter/bullet.um similarity index 100% rename from examples/space-shooter/bullet.um rename to demos/space-shooter/bullet.um diff --git a/examples/space-shooter/effects.um b/demos/space-shooter/effects.um similarity index 100% rename from examples/space-shooter/effects.um rename to demos/space-shooter/effects.um diff --git a/examples/space-shooter/enemy.um b/demos/space-shooter/enemy.um similarity index 100% rename from examples/space-shooter/enemy.um rename to demos/space-shooter/enemy.um diff --git a/examples/space-shooter/game.um b/demos/space-shooter/game.um similarity index 100% rename from examples/space-shooter/game.um rename to demos/space-shooter/game.um diff --git a/examples/space-shooter/gfx/enemy.png b/demos/space-shooter/gfx/enemy.png similarity index 100% rename from examples/space-shooter/gfx/enemy.png rename to demos/space-shooter/gfx/enemy.png diff --git a/examples/space-shooter/gfx/hearth.png b/demos/space-shooter/gfx/hearth.png similarity index 100% rename from examples/space-shooter/gfx/hearth.png rename to demos/space-shooter/gfx/hearth.png diff --git a/examples/space-shooter/gfx/marediv-regular.ttf b/demos/space-shooter/gfx/marediv-regular.ttf similarity index 100% rename from examples/space-shooter/gfx/marediv-regular.ttf rename to demos/space-shooter/gfx/marediv-regular.ttf diff --git a/examples/space-shooter/gfx/ship1.png b/demos/space-shooter/gfx/ship1.png similarity index 100% rename from examples/space-shooter/gfx/ship1.png rename to demos/space-shooter/gfx/ship1.png diff --git a/examples/space-shooter/gfx/ship2.png b/demos/space-shooter/gfx/ship2.png similarity index 100% rename from examples/space-shooter/gfx/ship2.png rename to demos/space-shooter/gfx/ship2.png diff --git a/examples/space-shooter/global.um b/demos/space-shooter/global.um similarity index 100% rename from examples/space-shooter/global.um rename to demos/space-shooter/global.um diff --git a/examples/space-shooter/hud.um b/demos/space-shooter/hud.um similarity index 100% rename from examples/space-shooter/hud.um rename to demos/space-shooter/hud.um diff --git a/examples/space-shooter/main.um b/demos/space-shooter/main.um similarity index 100% rename from examples/space-shooter/main.um rename to demos/space-shooter/main.um diff --git a/examples/space-shooter/menu.um b/demos/space-shooter/menu.um similarity index 100% rename from examples/space-shooter/menu.um rename to demos/space-shooter/menu.um diff --git a/examples/space-shooter/player.um b/demos/space-shooter/player.um similarity index 100% rename from examples/space-shooter/player.um rename to demos/space-shooter/player.um diff --git a/examples/space-shooter/score b/demos/space-shooter/score similarity index 100% rename from examples/space-shooter/score rename to demos/space-shooter/score diff --git a/examples/space-shooter/sfx/block.wav b/demos/space-shooter/sfx/block.wav similarity index 100% rename from examples/space-shooter/sfx/block.wav rename to demos/space-shooter/sfx/block.wav diff --git a/examples/space-shooter/sfx/dmgsound.wav b/demos/space-shooter/sfx/dmgsound.wav similarity index 100% rename from examples/space-shooter/sfx/dmgsound.wav rename to demos/space-shooter/sfx/dmgsound.wav diff --git a/examples/space-shooter/sfx/explosion.wav b/demos/space-shooter/sfx/explosion.wav similarity index 100% rename from examples/space-shooter/sfx/explosion.wav rename to demos/space-shooter/sfx/explosion.wav diff --git a/examples/space-shooter/sfx/laser.wav b/demos/space-shooter/sfx/laser.wav similarity index 100% rename from examples/space-shooter/sfx/laser.wav rename to demos/space-shooter/sfx/laser.wav diff --git a/examples/space-shooter/sfx/shoot.wav b/demos/space-shooter/sfx/shoot.wav similarity index 100% rename from examples/space-shooter/sfx/shoot.wav rename to demos/space-shooter/sfx/shoot.wav diff --git a/examples/space-shooter/sound.um b/demos/space-shooter/sound.um similarity index 100% rename from examples/space-shooter/sound.um rename to demos/space-shooter/sound.um diff --git a/examples/space-shooter/star.um b/demos/space-shooter/star.um similarity index 100% rename from examples/space-shooter/star.um rename to demos/space-shooter/star.um diff --git a/examples/tetris/Changelog b/demos/tetris/Changelog similarity index 100% rename from examples/tetris/Changelog rename to demos/tetris/Changelog diff --git a/examples/tetris/Clear.wav b/demos/tetris/Clear.wav similarity index 100% rename from examples/tetris/Clear.wav rename to demos/tetris/Clear.wav diff --git a/examples/tetris/ClearMega.wav b/demos/tetris/ClearMega.wav similarity index 100% rename from examples/tetris/ClearMega.wav rename to demos/tetris/ClearMega.wav diff --git a/examples/tetris/IDontWantToInfringeCopyrightSoListenToThisMonstrosity.wav b/demos/tetris/IDontWantToInfringeCopyrightSoListenToThisMonstrosity.wav similarity index 100% rename from examples/tetris/IDontWantToInfringeCopyrightSoListenToThisMonstrosity.wav rename to demos/tetris/IDontWantToInfringeCopyrightSoListenToThisMonstrosity.wav diff --git a/examples/tetris/Placement.wav b/demos/tetris/Placement.wav similarity index 100% rename from examples/tetris/Placement.wav rename to demos/tetris/Placement.wav diff --git a/examples/tetris/Rotation.wav b/demos/tetris/Rotation.wav similarity index 100% rename from examples/tetris/Rotation.wav rename to demos/tetris/Rotation.wav diff --git a/examples/tetris/background.um b/demos/tetris/background.um similarity index 100% rename from examples/tetris/background.um rename to demos/tetris/background.um diff --git a/examples/tetris/bag.um b/demos/tetris/bag.um similarity index 100% rename from examples/tetris/bag.um rename to demos/tetris/bag.um diff --git a/examples/tetris/bg_tile.png b/demos/tetris/bg_tile.png similarity index 100% rename from examples/tetris/bg_tile.png rename to demos/tetris/bg_tile.png diff --git a/examples/tetris/crazytext.um b/demos/tetris/crazytext.um similarity index 100% rename from examples/tetris/crazytext.um rename to demos/tetris/crazytext.um diff --git a/examples/tetris/falling_piece.um b/demos/tetris/falling_piece.um similarity index 100% rename from examples/tetris/falling_piece.um rename to demos/tetris/falling_piece.um diff --git a/examples/tetris/field.um b/demos/tetris/field.um similarity index 100% rename from examples/tetris/field.um rename to demos/tetris/field.um diff --git a/examples/tetris/fx.um b/demos/tetris/fx.um similarity index 100% rename from examples/tetris/fx.um rename to demos/tetris/fx.um diff --git a/examples/tetris/gameplay.um b/demos/tetris/gameplay.um similarity index 100% rename from examples/tetris/gameplay.um rename to demos/tetris/gameplay.um diff --git a/examples/tetris/global.um b/demos/tetris/global.um similarity index 100% rename from examples/tetris/global.um rename to demos/tetris/global.um diff --git a/examples/tetris/latch.um b/demos/tetris/latch.um similarity index 100% rename from examples/tetris/latch.um rename to demos/tetris/latch.um diff --git a/examples/tetris/main.um b/demos/tetris/main.um similarity index 100% rename from examples/tetris/main.um rename to demos/tetris/main.um diff --git a/examples/tetris/piece.um b/demos/tetris/piece.um similarity index 100% rename from examples/tetris/piece.um rename to demos/tetris/piece.um diff --git a/examples/tetris/presets.um b/demos/tetris/presets.um similarity index 100% rename from examples/tetris/presets.um rename to demos/tetris/presets.um diff --git a/examples/README.md b/examples/README.md deleted file mode 100644 index a721aaf5..00000000 --- a/examples/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# examples - -- hello world - opening a window, canvas -- space shooter - complete-ish game showing most of tophat's features -- platformer - tilemaps, collision resolution, enemies -- tetris - a block stacking game -- pomodoro - a pomodoro time tracking app, font rendering, advanced canvas usage -- item-list - a custom ui element -- extensions - C FFI diff --git a/samples/basic/main.um b/samples/basic/main.um new file mode 100644 index 00000000..1031fed6 --- /dev/null +++ b/samples/basic/main.um @@ -0,0 +1,14 @@ + +import ( + "canvas.um" + "th.um" + "window.um" +) + +fn init*() { + window::setup("Hello Tophat!", 640, 480) + + window::onFrame.register({ + canvas::drawText("Hello Tophat!", { 5, 5 }, th::black, 4) + }) +} diff --git a/samples/input/keyboard/main.um b/samples/input/keyboard/main.um new file mode 100644 index 00000000..d04aab98 --- /dev/null +++ b/samples/input/keyboard/main.um @@ -0,0 +1,46 @@ + +import ( + "canvas.um" + "input.um" + "th.um" + "window.um" +) + +pressCount := 0 +repeatCount := 0 +releaseCount := 0 + +fn init*() { + window::setup("Keyboard Input Sample", 640, 480) + + window::onFrame.register({ + p := th::Vf2{ 5, 5 } + + if input::isPressed(.space) { + canvas::drawText("SPACE IS PRESSED", p, th::green, 4) + } else { + canvas::drawText("SPACE IS NOT PRESSED", p, th::red, 4) + } + + p.y += 44 + + if input::isJustPressed(.space) { + pressCount++ + } + + if input::isPressedRepeat(.space) { + repeatCount++ + } + + if input::isJustReleased(.space) { + releaseCount++ + } + + canvas::drawText(sprintf("PRESS COUNT: %4d", pressCount), p, th::black, 4) + p.y += 44 + canvas::drawText(sprintf("REPEAT COUNT: %4d", repeatCount), p, th::black, 4) + p.y += 44 + canvas::drawText(sprintf("RELEASE COUNT: %4d", releaseCount), p, th::black, 4) + p.y += 44 + }) +} diff --git a/src/staembed.c b/src/staembed.c index e982b05b..e5344d0a 100644 --- a/src/staembed.c +++ b/src/staembed.c @@ -3057,8 +3057,7 @@ const char *th_em_modulesrc[] = { "", "//~~\n" "// `ui.um` offers an immediate GUI library suitable both for simple game menus\n" -"// and more complex applications. See the [tutorial](/tut/spritesheet.html)\n" -"// for example usage.\n" +"// and more complex applications.\n" "//~~\n" "\n" "import (\n" @@ -6599,572 +6598,21 @@ const char *th_em_moduledocs[] = { "\n" "\n" "", -"## \n" -"\n" -"```\n" -"```\n" -"\n" -"`ui.um` offers an immediate GUI library suitable both for simple game menus\n" -"and more complex applications. See the [tutorial](/tut/spritesheet.html)\n" -"for example usage.\n" -"\n" -"\n" -"## struct BoxStyle\n" -"\n" -"```\n" -"type BoxStyle* = struct {\n" -"\timg: image::Image\n" -"\touter, inner: rect::Rect\n" -"\tscale: th::fu\n" -"\tcolor: uint32\n" -"}\n" -"```\n" -"\n" -"`BoxStyle` describes how a box within the GUI is styled. In this case box\n" -"can be anything, ranging from a button to a container. By default the box\n" -"is drawn using the `image.Image.drawNinepatch` method. However if the image\n" -"is invalid, a rectangle with color `color` is drawn.\n" -"\n" -"\n" -"## interface Font\n" -"\n" -"```\n" -"type Font* = interface {\n" -"\tdraw(text: str, pos: th::Vf2, color: uint32, scale: th::fu = 1.0)\n" -"\tmeasure(test: str): th::Vf2\n" -"}\n" -"```\n" -"\n" -"This interface is used by all elements that draw text. A `font.Font`\n" -"implements this interface.\n" -"\n" -"\n" -"## struct PixelFont\n" -"\n" -"```\n" -"type PixelFont* = struct { }\n" -"```\n" -"\n" -"This struct implement the `Font` interface using the `canvas.um` pixel font.\n" -"\n" -"\n" -"## struct Style\n" -"\n" -"```\n" -"type Style* = struct {\n" -"\t// current font\n" -"\tft: Font\n" -"\t// font scale\n" -"\tftScale: th::fu\n" -"\t// text color\n" -"\tftColor: uint32\n" -"\n" -"\t// Positive box - i. e. unpressed button\n" -"\tposBox: BoxStyle\n" -"\t// Negative box - i. e. pressed button, text box\n" -"\tnegBox: BoxStyle\n" -"\t// Used to draw containers\n" -"\tcontainerBox: BoxStyle\n" -"}\n" -"```\n" -"\n" -"`Style` is used as a global state for styling the GUI.\n" -"\n" -"\n" -"## interface Container\n" -"\n" -"```\n" -"type Container* = interface {\n" -"\t// This adds a rectangle to the container, and returns the rectangle\n" -"\t// which was actually added (the container can modify the rectangle).\n" -"\t// See individual containers for further documentation.\n" -"\tpushRect(r: rect::Rect): rect::Rect\n" -"\tgetDims(): rect::Rect\n" -"}\n" -"```\n" -"\n" -"Containers are used to layout elements or other containers.\n" -"\n" -"\n" -"## struct Gui\n" -"\n" -"```\n" -"type Gui* = struct {\n" -"\t// user context passed to layout functions\n" -"\tctx: any\n" -"\n" -"\t// the index of the current selection. TODO implement properly\n" -"\tselection: int\n" -"\t// true, if the layout is being evaluated, not drawn\n" -"\tisEval: bool\n" -"\t// contains more unexported fields\n" -"```\n" -"\n" -"This is the main struct of any UI. Styles and containers are in a stack.\n" -"\n" -"\n" -"## fn mk\n" -"\n" -"```\n" -"fn mk*(r: rect::Rect, s: Style): Gui\n" -"```\n" -"\n" -"Creates a new gui spanning `r`, with style `s`.\n" -"\n" -"\n" -"## type LayoutFn\n" -"\n" -"```\n" -"type LayoutFn* = fn(gui: ^Gui)\n" -"```\n" -"\n" -"The layout function calls different element or container methods to create\n" -"the user interface itself. It is called in the `eval` and `draw`.\n" -"\n" -"\n" -"## fn BoxStyle.draw\n" -"\n" -"```\n" -"fn (this: ^BoxStyle) draw*(r: rect::Rect) {\n" -"```\n" -"\n" -"Draws a rectangle using a BoxStyle\n" -"\n" -"\n" -"## fn Gui.pushStyle\n" -"\n" -"```\n" -"fn (this: ^Gui) pushStyle*(s: Style) {\n" -"```\n" -"\n" -"Pushes a style onto the style stack.\n" -"\n" -"\n" -"## fn Gui.popStyle\n" -"\n" -"```\n" -"fn (this: ^Gui) popStyle*() {\n" -"```\n" -"\n" -"Pops a style from the style stack.\n" -"\n" -"\n" -"## fn Gui.getStyle\n" -"\n" -"```\n" -"fn (this: ^Gui) getStyle*(): ^Style {\n" -"```\n" -"\n" -"Returns a pointer to the style atop the style stack.\n" -"\n" -"\n" -"## fn Gui.getContainer\n" -"\n" -"```\n" -"fn (this: ^Gui) getContainer*(): Container {\n" -"```\n" -"\n" -"Returns the container atop the container stack.\n" -"\n" -"\n" -"## fn Gui.pushRect\n" -"\n" -"```\n" -"fn (this: ^Gui) pushRect*(r: rect::Rect): rect::Rect {\n" -"```\n" -"\n" -"Shortcut to `this.getContainer().pushRect(r)`\n" -"\n" -"\n" -"## fn Gui.getDims\n" -"\n" -"```\n" -"fn (this: ^Gui) getDims*(): rect::Rect {\n" -"```\n" -"\n" -"Shortcut to `this.getContainer().getDims(r)`\n" -"\n" -"\n" -"## fn Gui.dupStyle\n" -"\n" -"```\n" -"fn (this: ^Gui) dupStyle*() {\n" -"```\n" -"\n" -"Duplicates the current style.\n" -"\n" -"\n" -"## fn Gui.pushContainer\n" -"\n" -"```\n" -"fn (this: ^Gui) pushContainer*(c: Container) {\n" -"```\n" -"\n" -"Pushes a container onto the container stack.\n" -"\n" -"\n" -"## fn Gui.popContainer\n" -"\n" -"```\n" -"fn (this: ^Gui) popContainer*() {\n" -"```\n" -"\n" -"Pops a container from the container stack.\n" -"\n" -"\n" -"## fn Gui.eval\n" -"\n" -"```\n" -"fn (this: ^Gui) eval*(layout: LayoutFn) {\n" -"```\n" -"\n" -"Runs the evaluation phase on `layout`.\n" -"\n" -"\n" -"## fn Gui.draw\n" -"\n" -"```\n" -"fn (this: ^Gui) draw*(layout: LayoutFn) {\n" -"```\n" -"\n" -"Runs the draw phase on `layout`.\n" -"\n" -"\n" -"## enum BoxGrow\n" -"\n" -"```\n" -"type BoxGrow* = enum {\n" -"\tdimension\n" -"\tsubdiv\n" -"\tspan\n" -"\tpxSpan\n" -"}\n" -"```\n" -"\n" -"The different types of \"growing\" the box can do.\n" -"\n" -"\n" -"## enum BoxDirection\n" -"\n" -"```\n" -"type BoxDir* = enum {\n" -"\tdown\n" -"\tright\n" -"\tup\n" -"\tleft\n" -"}\n" -"```\n" -"\n" -"Direction in which the box will grow.\n" -"\n" -"\n" -"## struct BoxConfig\n" -"\n" -"```\n" -"type BoxConfig* = struct {\n" -"\t// dimension to grow by if `BoxGrowDimension` is used\n" -"\tdimension: th::fu\n" -"\t// number of subdivisions if `BoxGrowSubdivisions` is used\n" -"\tsubdivisions: uint\n" -"\t// the grow type\n" -"\tgrowType: BoxGrow\n" -"\t// the grow direction\n" -"\tdir: BoxDir\n" -"\t// Specifies the values used with BoxGrowSpan nad BoxGrowPxSpan.\n" -"\t// If BoxGrowSpan is used, 1 equals the size of the box divided by the sum\n" -"\t// of all spans.\n" -"\t// If BoxGrowPxSpan is used, 1 equals one pixel.\n" -"\tspan: []th::fu\n" -"\t// rect passed to the current container\n" -"\trect: rect::Rect\n" -"\t// padding inserted after each element\n" -"\tpadding: th::fu\n" -"}\n" -"```\n" -"\n" -"Configuration of the `Box` container.\n" -"\n" -"\n" -"## struct Box\n" -"\n" -"```\n" -"type Box* = struct {\n" -"\tgrow: th::fu\n" -"\tspanCursor: int\n" -"\tdm: rect::Rect\n" -"\tcfg: BoxConfig\n" -"}\n" -"```\n" -"\n" -"`Box` is the main layout. It puts the elements next to each other,\n" -"according to the config.\n" -"\n" -"If the dimensions of the rect passed to `pushRect` are non zero, they will\n" -"be kept. Position is always forced.\n" -"\n" -"\n" -"## fn Gui.box\n" -"\n" -"```\n" -"fn (gui: ^Gui) box*(cfg: BoxConfig = {\n" -"\tdimension: 30,\n" -"\tgrowType: BoxGrow.dimension,\n" -"\tdir: BoxDir.down }) {\n" -"```\n" -"\n" -"Adds the `Box` container to the gui.\n" -"\n" -"\n" -"## struct StackConfig\n" -"\n" -"```\n" -"type StackConfig* = struct {\n" -"\trect: rect::Rect\n" -"\tpadding: th::fu\n" -"}\n" -"```\n" -"\n" -"Configuration for the `Stack` container.\n" -"\n" -"\n" -"## struct Stack\n" -"\n" -"```\n" -"type Stack* = struct {\n" -"\tdm: rect::Rect\n" -"\tcfg: StackConfig\n" -"}\n" -"```\n" -"\n" -"The stack container puts elements on top of each other.\n" -"If a property of the rect passed to `pushRect` is zero, it will be changed\n" -"to an equivalent property of the containers\' dimensions (minus the padding),\n" -"else it will stay the same. This means stack can be used either to put\n" -"multiple elements/containers on top of each other, or for absolutely\n" -"positioned elements.\n" -"\n" -"\n" -"## fn Gui.stack\n" -"\n" -"```\n" -"fn (gui: ^Gui) stack*(cfg: StackConfig = {}) {\n" -"```\n" -"\n" -"Adds the `Stack` container to the gui.\n" -"\n" -"\n" -"## struct ScrollAreaConfig\n" -"\n" -"```\n" -"type ScrollAreaConfig* = struct {\n" -"\trect: rect::Rect\n" -"\t// scroll speed. Default is 1\n" -"\tspeed: real32\n" -"\t// if true, scrolling will be horizontal\n" -"\thorizontal: bool\n" -"}\n" -"```\n" -"\n" -"Configuration for the scroll area.\n" -"\n" -"\n" -"## struct ScrollArea\n" -"\n" -"```\n" -"type ScrollArea* = struct {\n" -"\tdm: rect::Rect\n" -"\tcfg: ScrollAreaConfig\n" -"\tscroll: ^real32\n" -"\tmaxScroll: real32\n" -"}\n" -"```\n" -"\n" -"Scroll area is a container which allows the user to scroll. It acts as a\n" -"stack container, but all the elements are shifted by the scroll.\n" -"\n" -"\n" -"## fn Gui.scrollArea\n" -"\n" -"```\n" -"fn (gui: ^Gui) scrollArea*(scroll: ^real32, maxScroll: real32, cfg: ScrollAreaConfig = {}) {\n" -"```\n" -"\n" -"Pushes a scroll area. `scroll` is both input and output value. Both `scroll`\n" -"and `maxScroll` are in pixels.\n" -"\n" -"\n" -"## struct ButtonConfig\n" -"\n" -"```\n" -"type ButtonConfig* = struct {\n" -"\trect: rect::Rect\n" -"}\n" -"```\n" -"\n" -"Configuration for the button.\n" -"\n" -"\n" -"## fn Gui.button\n" -"\n" -"```\n" -"fn (gui: ^Gui) button*(cfg: ButtonConfig = {}): bool {\n" -"```\n" -"\n" -"Adds a button to the gui. The button acts like a `Stack` container, but it\n" -"is drawn using the pos/nexBox styles and handles clicks. If the button is\n" -"pressed and the gui is in the eval phase, the return value will be true.\n" -"\n" -"\n" -"## struct LabelConfig\n" -"\n" -"```\n" -"type LabelConfig* = struct {\n" -"\t// centers the label along the X axis, enables `stretchX`\n" -"\tcenterX: bool\n" -"\t// centers the label along the Y axis, enables `stretchY`\n" -"\tcenterY: bool\n" -"\t// if false, the rect passed to `pushRect` will have the width of\n" -"\t// the text, else it will be 0\n" -"\tstretchX: bool\n" -"\t// if false, the rect passed to `pushRect` will have the height of\n" -"\t// the text, else it will be 0\n" -"\tstretchY: bool\n" -"\t// forces the rectangle the label will use\n" -"\trect: rect::Rect\n" -"}\n" -"```\n" -"\n" -"\n" -"\n" -"## fn Gui.label\n" -"\n" -"```\n" -"fn (gui: ^Gui) label*(text: str, cfg: LabelConfig = {\n" -"```\n" -"\n" -"Draws a label using the current font style.\n" -"\n" -"\n" -"## fn Gui.qbutton\n" -"\n" -"```\n" -"fn (gui: ^Gui) qbutton*(text: str, cfg: ButtonConfig = {}): bool {\n" -"```\n" -"\n" -"Adds a button with a label to gui.\n" -"\n" -"\n" -"## struct TextBoxConfig\n" -"\n" -"```\n" -"type TextBoxConfig* = struct {\n" -"\t// force the rect of the text box\n" -"\trect: rect::Rect\n" -"}\n" -"```\n" -"\n" -"\n" -"\n" -"## struct TextBox\n" -"\n" -"```\n" -"type TextBox* = struct {\n" -"\t// index of the cursor\n" -"\tcursor: int\n" -"\t// contains other unexported rules...\n" -"```\n" -"\n" -"\n" -"\n" -"## fn TextBox.clear\n" -"\n" -"```\n" -"fn (this: ^TextBox) clear*() {\n" -"```\n" -"\n" -"Clears the textbox\n" -"\n" -"\n" -"## fn TextBox.getBuf()\n" -"\n" -"```\n" -"fn (this: ^TextBox) getBuf*(): str {\n" -"```\n" -"\n" -"Get the content of the textbox.\n" -"\n" -"\n" -"## fn TextBox.setBuf()\n" -"\n" -"```\n" -"fn (this: ^TextBox) setBuf*(s: str) {\n" -"```\n" -"\n" -"Get the content of the textbox.\n" -"\n" -"\n" -"## fn Gui.textBox\n" -"\n" -"```\n" -"fn (gui: ^Gui) textBox*(tb: ^TextBox, cfg: TextBoxConfig = {}) {\n" -"```\n" -"\n" -"Adds a single line textbox to the gui.\n" -"TODO:\n" -"* right-to-left unicode is not supported.\n" -"* no selection\n" -"* multiline\n" -"* copy paste (now implemented but in a limited way due to the lack of selection)\n" -"* common input shortcuts\n" -"- ctrl+delete / ctrl+backspace (delete word)\n" -"\n" -"\n" -"## struct ImageConfig\n" -"\n" -"```\n" -"type ImageConfig* = struct {\n" -"\tstretchX, stretchY: bool\n" -"\tcenterX, centerY: bool\n" -"\tcolor: uint32\n" -"\tscale: th::Vf2\n" -"\trect: rect::Rect\n" -"}\n" -"```\n" -"\n" -"Configuration for the images element. Behaves similarly to labels.\n" -"\n" -"\n" -"## fn Gui.image\n" -"\n" -"```\n" -"fn (gui: ^Gui) image*(i: image::Image, cfg: ImageConfig = {\n" -"\tstretchX: true,\n" -"\tstretchY: true,\n" -"\tcolor: th::white,\n" -"\tscale: { 1, 1 } }) {\n" -"```\n" -"\n" -"Draws an image.\n" -"\n" -"\n" -"## fn getDefaultStyle\n" -"\n" -"```\n" -"fn getDefaultStyle*(): Style {\n" -"```\n" -"\n" -"Returns the default tophat ui style.\n" -"\n" -"\n" -"## fn mk\n" -"\n" -"```\n" -"fn mk*(r: rect::Rect, s: Style): Gui {\n" -"```\n" -"\n" -"Creates a GUI instance.\n" -"\n" -"\n" +"mmdoc - universal documentation utility\n" +"usage: mmdoc [ options ] file\n" +"\t-b (defaults to ~~)\n" +"\t-e (defaults to ~~)\n" +"\t-c (defaults to //)\n" +"\t-u (%d is substituted to line number)\n" +"\t-l (defaults to \"\")\n" +"\t-h - export to html\n" +"\t-s - export to standalone html\n" +"\n" +"Example:\n" +"\t//~~my_function\n" +"\t// Description of my function\n" +"\tvoid my_function() {\n" +"\t//~~\n" "", }; static uint32_t th_em_placeholder_data_2[] = {0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff0a35d0, 0xff3f0cf8, 0xff3f0cf8, 0xffef0cf8, 0xffef0cf8, 0xffd00a20, 0xffd00a20, 0xffd0d00a, 0xffd0d00a, 0xff3dd00a, 0xff3dd00a, 0xff0ac0d0, 0xff0ac0d0, 0xff3f0cf8, 0xff3f0cf8, 0xffef0cf8, 0xffef0cf8, 0xffd00a20, 0xffd00a20, 0xffd0d00a, 0xffd0d00a, 0xff3dd00a, 0xff3dd00a, 0xff0ac0d0, 0xff0ac0d0, 0xff3f0cf8, 0xff3f0cf8, 0xffef0cf8, 0xffef0cf8, 0xffd00a20, 0xffd00a20, 0xffd0d00a, 0xffd0d00a, 0xff3dd00a, 0xff3dd00a, 0xff0ac0d0, 0xff0ac0d0, 0xff3f0cf8, 0xff3f0cf8, 0xffef0cf8, 0xffef0cf8, 0xffd00a20, 0xffd00a20, 0xffd0d00a, 0xffd0d00a, 0xff3dd00a, 0xff3dd00a, 0xff0ac0d0, 0xff0ac0d0, 0xff3f0cf8, 0xff3f0cf8, 0xffef0cf8, 0xffef0cf8, 0xffd00a20, 0xffd00a20, 0xffd0d00a, 0xffd0d00a, 0xff3dd00a, 0xff3dd00a, 0xff0ac0d0, 0xff0ac0d0, 0xff3f0cf8, 0xff3f0cf8, 0xffef0cf8, 0xffef0cf8, 0xffd00a20, 0xffd00a20, 0xffd0d00a, 0xffd0d00a, 0xff3dd00a, 0xff3dd00a, 0xff0ac0d0, 0xff0ac0d0, 0xff3f0cf8, 0xff3f0cf8, 0xffef0cf8, 0xffef0cf8, 0xffd00a20, 0xffd00a20, 0xffd0d00a, 0xffd0d00a, 0xff3dd00a, 0xff3dd00a, 0xff0ac0d0, 0xff0ac0d0, 0xff3f0cf8, 0xff3f0cf8, 0xffef0cf8, 0xffef0cf8, 0xffd00a20, 0xffd00a20, 0xffd0d00a, 0xffd0d00a, 0xff3dd00a, 0xff3dd00a, 0xff0ac0d0, 0xff0ac0d0, 0xff3f0cf8, 0xff3f0cf8, 0xffef0cf8, 0xffef0cf8, 0xffd00a20, 0xffd00a20, 0xffd0d00a, 0xffd0d00a, 0xff3dd00a, 0xff3dd00a, 0xff0ac0d0, 0xff0ac0d0, 0xff3f0cf8, 0xff3f0cf8, 0xffef0cf8, 0xffef0cf8, 0xffd00a20, 0xffd00a20, 0xffd0d00a, 0xffd0d00a, 0xff3dd00a, 0xff3dd00a, 0xff0ac0d0, 0xff0ac0d0}; diff --git a/umka/ui.um b/umka/ui.um index 7afa3c24..346075fd 100644 --- a/umka/ui.um +++ b/umka/ui.um @@ -1,7 +1,6 @@ //~~ // `ui.um` offers an immediate GUI library suitable both for simple game menus -// and more complex applications. See the [tutorial](/tut/ui.html) -// for example usage. +// and more complex applications. //~~ import (