updates with more onyx features
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 4 Mar 2021 00:50:53 +0000 (18:50 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 4 Mar 2021 00:50:53 +0000 (18:50 -0600)
dist/index.js
dist/prez.wasm
src/show_parser.onyx
src/slides.onyx

index c44496f601db28e7adb49b92ced381c82e3d2bd8..c02d304fa2c352ff998fdd0b2a16b8bd2ee6a955 100644 (file)
@@ -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 = () => {
index 24c3d339b4c3326c7b557dd2cac89a2cb87ee5be..93479d653d230f0b63f8ad01ed794781b4a9892c 100644 (file)
Binary files a/dist/prez.wasm and b/dist/prez.wasm differ
index 591d6935154f36d80be98194ce00c65b29a4304f..c065bf260b7ba74f1c1786dd3d5736765e618eeb 100644 (file)
@@ -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);
index 413ba1a25a84312474c518f7e5ed60aa01563df9..72136c2dfe04e69df7add248f212d546956807c3 100644 (file)
@@ -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) {