From d8e2b7df2122393885ce87cf345d3e627e50d172 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Wed, 17 Feb 2021 10:20:29 -0600 Subject: [PATCH] started working on notion of slides --- src/build.onyx | 1 + src/prez.onyx | 6 ++--- src/slides.onyx | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 src/slides.onyx diff --git a/src/build.onyx b/src/build.onyx index 92729c6..84315f8 100644 --- a/src/build.onyx +++ b/src/build.onyx @@ -8,3 +8,4 @@ use package build_opts as build_opts #load "src/prez" #load "src/events" +#load "src/slides" diff --git a/src/prez.onyx b/src/prez.onyx index 9703b20..c5b7ec1 100644 --- a/src/prez.onyx +++ b/src/prez.onyx @@ -57,7 +57,7 @@ draw_centered_text :: (text: str, y_baseline: f32) { x := (width - font_metrics.width) / 2; - fill_text(canvas, text, x, y_baseline); + fill_text(canvas, text, x, y_baseline * height); } dirty_display := true @@ -71,7 +71,7 @@ poll_events :: () { printf("New window size: %i, %i\n", ev.resize.width, ev.resize.height); dirty_display = true; - use Canvas; + use Canvas set_size(canvas, ev.resize.width, ev.resize.height); } @@ -92,7 +92,7 @@ loop :: () -> void #export "loop" { Canvas.clear(canvas, 0.1, 0.1, 0.1); Canvas.set_font(canvas, "bold 72px Arial"); - draw_centered_text("Hello, World! This is a long title!", 100); + draw_centered_text("Hello, World! This is a long title!", .3); Canvas.set_font(canvas, "bold 48px Arial"); draw_centered_text("This is some more text.", 170); diff --git a/src/slides.onyx b/src/slides.onyx new file mode 100644 index 0000000..2808212 --- /dev/null +++ b/src/slides.onyx @@ -0,0 +1,66 @@ +use package core + +Color :: struct { + r, g, b, a: f32; +} + +Slideshow :: struct { + // A basic arena that should store everything related to slides. + // This makes it easy to free everything at once. + arena : alloc.arena.ArenaState; + + title : str; + slides : [..] Slide; + + current_slide : i32; +} + +Slide :: struct { + foreground, background: Color; + font_name : str; + + items : [] ^Slide_Item; +} + +Slide_Item :: struct #union { + Kind :: enum { + Undefined; + Text; + } + + base: Slide_Item_Base; + text: Slide_Item_Text; +} + +Slide_Item_Base :: struct { + kind : Slide_Item.Kind; +} + +Slide_Item_Text :: struct { + use base : Slide_Item_Base; + + Justify :: enum { Left; Center; Right; } + + text : str; + y_pos : f32; // Between 0 and 1 + justify : Justify; +} + + + +slideshow_make :: (allocator := context.allocator) -> Slideshow { + slideshow: Slideshow; + slideshow.title = "Untitled Slideshow"; + + slideshow.arena = alloc.arena.make(allocator, arena_size = 16 * 1024); + + array.init(^slideshow.slides, 4); + + return slideshow; +} + +slideshow_get_current_slide :: (use s: ^Slideshow) -> ^Slide { + current_slide = math.clamp(current_slide, 0, slides.count - 1); + + return ^slides[current_slide]; +} -- 2.25.1