summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/font.scm50
-rw-r--r--examples/fonts/AUTHORS2
-rw-r--r--examples/fonts/Boxy-Bold.ttfbin14432 -> 0 bytes
3 files changed, 42 insertions, 10 deletions
diff --git a/examples/font.scm b/examples/font.scm
index 465600c..2398b36 100644
--- a/examples/font.scm
+++ b/examples/font.scm
@@ -1,22 +1,56 @@
(use-modules (srfi srfi-9)
(figl gl)
+ (2d agenda)
+ (2d fps)
(2d color)
(2d font)
(2d game)
+ (2d mouse)
+ (2d signals)
(2d vector2)
(2d window))
(load "common.scm")
-(define textbox
- (make-textbox (load-font "fonts/Boxy-Bold.ttf" 48)
- "The quick brown fox jumped over the lazy dog."
- (vector2 240 160)
- white
- 'left
- 200))
+(define font (load-default-font 18))
+(define position (vector2 320 240))
+(define text "The quick brown fox jumped over the lazy dog.")
+(define label (make-label font text position #:anchor 'center))
-(add-hook! draw-hook (lambda (dt alpha) (draw-textbox textbox)))
+(define fps-label-position (vector2 0 0))
+(define (make-fps-label)
+ (make-label font (format #f "FPS: ~d" (fps)) fps-label-position))
+(define fps-label (make-fps-label))
+
+(define mouse-label-position (vector2 0 20))
+(define mouse-label
+ (signal-map (lambda (p)
+ (let ((text (format #f "Mouse: (~d, ~d)" (vx p) (vy p))))
+ (make-label font text mouse-label-position)))
+ mouse-position))
+
+(define gc-label-position (vector2 0 40))
+(define gc-counter (make-root-signal 0))
+(define gc-label
+ (signal-map (lambda (counter)
+ (let ((text (format #f "GCs: ~d" counter)))
+ (make-label font text gc-label-position)))
+ gc-counter))
+
+(add-hook! after-gc-hook
+ (lambda ()
+ (signal-set! gc-counter (1+ (signal-ref gc-counter)))))
+
+(schedule-interval game-agenda
+ (lambda ()
+ (set! fps-label (make-fps-label)))
+ 60)
+
+(add-hook! draw-hook (lambda (dt alpha)
+ (draw-label label)
+ (draw-label fps-label)
+ (draw-label (signal-ref mouse-label))
+ (draw-label (signal-ref gc-label))))
(with-window (make-window #:title "Fonts")
(run-game-loop))
diff --git a/examples/fonts/AUTHORS b/examples/fonts/AUTHORS
deleted file mode 100644
index 0f278b8..0000000
--- a/examples/fonts/AUTHORS
+++ /dev/null
@@ -1,2 +0,0 @@
-Clint Bellanger and William Thompson
-http://opengameart.org/content/boxy-bold-truetype-font \ No newline at end of file
diff --git a/examples/fonts/Boxy-Bold.ttf b/examples/fonts/Boxy-Bold.ttf
deleted file mode 100644
index 8076dc5..0000000
--- a/examples/fonts/Boxy-Bold.ttf
+++ /dev/null
Binary files differ