From: Brendan Hansen Date: Thu, 4 Mar 2021 00:50:53 +0000 (-0600) Subject: updates with more onyx features X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=4d3803aaec21a360ca9c5aa7091fc26c9f209403;p=onyx-prez.git updates with more onyx features --- diff --git a/dist/index.js b/dist/index.js index c44496f..c02d304 100644 --- a/dist/index.js +++ b/dist/index.js @@ -239,7 +239,7 @@ let import_obj = { console.log(str); }, - exit(status) { console.warn("Attempted to call host.exit()."); }, + exit(status) { console.warn("Attempted to call host.exit()."); debugger; }, start_loop() { let loop = () => { diff --git a/dist/prez.wasm b/dist/prez.wasm index 24c3d33..93479d6 100644 Binary files a/dist/prez.wasm and b/dist/prez.wasm differ diff --git a/src/show_parser.onyx b/src/show_parser.onyx index 591d693..c065bf2 100644 --- a/src/show_parser.onyx +++ b/src/show_parser.onyx @@ -77,7 +77,7 @@ parse_slideshow :: (source: str, slideshow: ^Slideshow) { } elseif command_name == "background" { r, g, b := parse_color(^parse_context); - current_slide.background = Color.{ r, g, b }; + current_slide.background = .{ r, g, b }; } elseif command_name == "y" { y := parse_numeric_value(^parse_context); @@ -209,7 +209,7 @@ parse_text_style :: (use pc: ^ParseContext, text_style: ^Slide_Item_Text, parse_ if style_name == "color" { r, g, b := parse_color(pc); - text_style.color = Color.{ r, g, b }; + text_style.color = .{ r, g, b }; } elseif style_name == "font_size" { text_style.font_size = parse_numeric_value(pc); @@ -268,7 +268,7 @@ parse_image_style :: (use pc: ^ParseContext, image_style: ^Slide_Item_Image, par } elseif style_name == "border_color" { r, g, b := parse_color(pc); - image_style.border_color = Color.{ r, g, b }; + image_style.border_color = .{ r, g, b }; } else { printf("Unknown style option: '%s'\n", style_name); @@ -305,7 +305,7 @@ parse_rect_style :: (use pc: ^ParseContext, rect_style: ^Slide_Item_Rect, parse_ } elseif style_name == "color" { r, g, b := parse_color(pc); - rect_style.color = Color.{ r, g, b }; + rect_style.color = .{ r, g, b }; } else { printf("Unknown style option: '%s'\n", style_name); diff --git a/src/slides.onyx b/src/slides.onyx index 413ba1a..72136c2 100644 --- a/src/slides.onyx +++ b/src/slides.onyx @@ -4,6 +4,7 @@ HTML_Image :: struct { handle: i32 = -1; width: i32 = 1; // To avoid dividing by 0 height: i32 = 1; + size_initialized := false; } Color :: struct { @@ -115,7 +116,7 @@ slideshow_init :: (use s: ^Slideshow, allocator := context.allocator) { arena = alloc.arena.make(allocator, arena_size = 16 * 1024); array.init(^slides, 4); - map.init(^image_map, default = HTML_Image.{}); + map.init(^image_map, default=.{}); } slideshow_reset :: (use s: ^Slideshow) { @@ -165,11 +166,14 @@ slideshow_insert_slide :: (use s: ^Slideshow, at := -1) -> ^Slide { slideshow_make_item :: (use s: ^Slideshow) -> ^Slide_Item { allocator := alloc.arena.make_allocator(^arena); - ret := new(Slide_Item, allocator = allocator); + ret := new(Slide_Item, allocator=allocator, initialize=false); memory.set(ret, 0, sizeof Slide_Item); return ret; } +// @Cleanup +use package core.intrinsics.wasm { __initialize } + slideshow_load_image :: (use s: ^Slideshow, image_name: str, image_path: str) -> HTML_Image { if map.has(^image_map, image_name) { printf("Warning: the image '%s' was already defined.", image_name); @@ -178,6 +182,7 @@ slideshow_load_image :: (use s: ^Slideshow, image_name: str, image_path: str) -> html_image_load :: (path: str, out_image: ^HTML_Image) -> void #foreign "html" "load_image" --- image: HTML_Image; + __initialize(^image); html_image_load(image_path, ^image); map.put(^image_map, image_name, image); @@ -282,16 +287,13 @@ slide_item_render :: (use slide_item: ^Slide_Item, slide: ^Slide, width: f32, he } case Image { - if html_image := map.get(^the_slideshow.image_map, image.name); html_image.handle != -1 { - // @Speed: There is a much better way of doing this... - // @Robustness: Currently, because HTML images are asynchronously loaded, - // the image dimensions are not known when the load_image call is made. - // These means that the dimensions need to be queried later once the image - // has been loaded. The real bad thing here, is that the 'html_image' being - // passed is a local copy from the image_map. This means everytime this image - // is drawn, it has to requery the image dimensions... Uck... - store_image_size :: (html_image: ^HTML_Image) -> void #foreign "html" "store_image_size" --- - store_image_size(^html_image); + if html_image := map.get_ptr(^the_slideshow.image_map, image.name); html_image != null { + if !html_image.size_initialized { + store_image_size :: (html_image: ^HTML_Image) -> void #foreign "html" "store_image_size" --- + store_image_size(html_image); + + html_image.size_initialized = true; + } x := image.x * width; y := image.y * height; @@ -380,12 +382,8 @@ Slide_Animation_Swipe :: struct { t : f32 = 0; dt : f32 = 0.03; - make :: (allocator := context.allocator) -> ^Slide_Animation_Swipe { - anim := new(Slide_Animation_Swipe, allocator=allocator); - *anim = Slide_Animation_Swipe.{}; - - return anim; + return new(Slide_Animation_Swipe, allocator=allocator); } init :: (use anim: ^Slide_Animation_Swipe, source := -1, target := -1) { @@ -433,10 +431,7 @@ Slide_Animation_Fade :: struct { make :: (allocator := context.allocator) -> ^Slide_Animation_Fade { - anim := new(Slide_Animation_Fade, allocator=allocator); - *anim = Slide_Animation_Fade.{}; - - return anim; + return new(Slide_Animation_Fade, allocator=allocator); } init :: (use anim: ^Slide_Animation_Fade, source := -1, target := -1) { @@ -484,10 +479,7 @@ Slide_Animation_Wiper :: struct { draw_line := false; make :: (allocator := context.allocator) -> ^Slide_Animation_Wiper { - anim := new(Slide_Animation_Wiper, allocator=allocator); - *anim = Slide_Animation_Wiper.{}; - - return anim; + return new(Slide_Animation_Wiper, allocator=allocator); } init :: (use anim: ^Slide_Animation_Wiper, source := -1, target := -1) {