</head>
<body>
- <canvas id="prez_canvas">This browser does not support the HTML5 Canvas.</canvas>
+ <canvas id="prez_canvas" ondragover="prez_dragover_handler(event);">This browser does not support the HTML5 Canvas.</canvas>
</body>
</html>
let canvasElem;
let canvasCtx;
let __loaded_images = [];
+let presentation_source;
const MAGIC_CANVAS_NUMBER = 0x5052455A;
+function prez_dragover_handler(ev) {
+ ev.preventDefault();
+ return false;
+}
+
function push_event_to_buffer(esp, event_size, event_kind, data) {
let WASM_U32 = new Uint32Array(wasm_instance.exports.memory.buffer);
push_event_to_buffer(esp, event_size, 0x06, [ window.innerWidth, window.innerHeight ]);
});
+ document.getElementById("prez_canvas").addEventListener("drop", async (ev) => {
+ ev.preventDefault();
+
+ presentation_source = await ev.dataTransfer.items[0].getAsFile().arrayBuffer();
+ push_event_to_buffer(esp, event_size, 0x08, [ presentation_source.byteLength ]);
+
+ return false;
+ });
+
push_event_to_buffer(esp, event_size, 0x06, [ window.innerWidth, window.innerHeight ]);
document.oncontextmenu = (e) => {
e.preventDefault = true;
return false;
};
+ },
+
+ copy_presentation_source(dest_ptr, dest_len) {
+ if (dest_len < presentation_source.byteLength) return;
+
+ let wasm_u8 = new Uint8Array(wasm_instance.exports.memory.buffer);
+ let source = new Uint8Array(presentation_source);
+
+ wasm_u8.set(source, dest_ptr);
}
}
--- /dev/null
+[slide] [background 60 60 60]
+[text_style undefind font_name "monospace" font_size 48 font_attr bold centered]
+[y 50] Drop a presentation file here!
KeyUp :: 0x05;
Resize :: 0x06;
+
+ FileDropped :: 0x08;
}
DomEvent :: struct {
height : u32;
}
+FileDroppedEvent :: struct {
+ use event : DomEvent;
+
+ file_size : u32;
+}
+
Event :: struct #union {
use dom : DomEvent;
keyboard : KeyboardEvent;
mouse : MouseEvent;
resize : ResizeEvent;
+ file : FileDroppedEvent;
}
clear_event :: (ev: ^Event) {
poll_events :: () {
use event.DomEventKind
- redraw = 2;
-
ev: event.Event;
- while event.poll(^ev) do switch ev.kind {
- case Resize {
- printf("New window size: %i, %i\n", ev.resize.width, ev.resize.height);
+ while event.poll(^ev) {
+ redraw = 1;
- use Canvas
- set_size(canvas, ev.resize.width, ev.resize.height);
- }
+ switch ev.kind {
+ case Resize {
+ use Canvas
+ set_size(canvas, ev.resize.width, ev.resize.height);
+ }
- case MouseDown {
- printf("Mouse down: %i, %i\n", ev.mouse.pos_x, ev.mouse.pos_y);
+ case MouseDown {
+ use event.MouseButton
+ switch ev.mouse.button {
+ case Right do slideshow_advance_slide(^the_slideshow, -1);
+ case #default do slideshow_advance_slide(^the_slideshow, 1);
+ }
+ }
- use event.MouseButton
- switch ev.mouse.button {
- case Right do slideshow_advance_slide(^the_slideshow, -1);
- case #default do slideshow_advance_slide(^the_slideshow, 1);
+ case KeyDown {
+ switch ev.keyboard.keycode {
+ case 0x25 do slideshow_advance_slide(^the_slideshow, -1);
+ case 0x27 do slideshow_advance_slide(^the_slideshow, 1);
+ }
}
- }
- case KeyDown {
- printf("Keydown: %i\n", ev.keyboard.keycode);
+ case FileDropped {
+ printf("New slideshow was dropped! %i bytes in size\n", ev.file.file_size);
- switch ev.keyboard.keycode {
- case 0x25 do slideshow_advance_slide(^the_slideshow, -1);
- case 0x27 do slideshow_advance_slide(^the_slideshow, 1);
- }
- }
+ source := memory.make_slice(u8, ev.file.file_size);
+ defer cfree(source.data);
- case #default do redraw = 0;
+ copy_presentation_source :: (source: [] u8) -> void #foreign "event" "copy_presentation_source" ---
+ copy_presentation_source(source);
- } else {
- redraw = 0;
+ slideshow_reset(^the_slideshow);
+ parse_slideshow(source, ^the_slideshow);
+ }
+ }
}
}
event.init();
the_slideshow = slideshow_make();
- parse_slideshow(#file_contents "test.prez", ^the_slideshow);
+ parse_slideshow(#file_contents "initial.prez", ^the_slideshow);
start_loop :: () -> void #foreign "host" "start_loop" ---
start_loop();
read_byte(^show_reader);
command_name := read_word(^show_reader, allocator=parse_alloc);
- printf("Parsing command: %s\n", command_name);
if command_name == "slide" {
prev_slide := ^slideshow.slides[slideshow.slides.count - 1];
current_slide.items[current_item_idx] = new_slide_image;
current_item_idx += 1;
}
+ elseif command_name == "rect" {
+ new_slide_rect := slideshow_make_item(slideshow);
+ new_slide_rect.kind = Slide_Item.Kind.Rect;
+ parse_rect_style(^show_reader, ^new_slide_rect.rect, parse_alloc);
+
+ current_slide.items[current_item_idx] = new_slide_rect;
+ current_item_idx += 1;
+ }
else {
printf("******** Unknown command: '%s'.\n", command_name);
}
if style_name == "color" {
r, g, b := parse_color(reader);
text_style.color = Color.{ r, g, b };
- printf("Parsed color: %f %f %f\n", r, g, b);
}
elseif style_name == "font_size" {
text_style.font_size = read_u32(reader);
elseif style_name == "centered" do text_style.justify = Slide_Item_Text.Justify.Center;
elseif style_name == "right" do text_style.justify = Slide_Item_Text.Justify.Right;
else {
- use package core { printf as pf }
- pf("Unknown style option: '%s'\n", style_name);
+ printf("Unknown style option: '%s'\n", style_name);
advance_line(reader);
break;
}
image_style.width = cast(f32) width / 100;
}
else {
- use package core { printf as pf }
- pf("Unknown style option: '%s'\n", style_name);
+ printf("Unknown style option: '%s'\n", style_name);
+ advance_line(reader);
+ break;
+ }
+ }
+}
+
+#private_file
+parse_rect_style :: (reader: ^io.Reader, rect_style: ^Slide_Item_Rect, parse_alloc := context.allocator) {
+ use io
+
+ while !stream_end_of_file(reader.stream) && peek_byte(reader) != #char "]" {
+ skip_whitespace(reader);
+ defer skip_whitespace(reader);
+ style_name := read_word(reader, allocator=parse_alloc);
+
+ if style_name == "x" {
+ x := read_u32(reader);
+ rect_style.x = cast(f32) x / 100;
+ }
+ elseif style_name == "y" {
+ y := read_u32(reader);
+ rect_style.y = cast(f32) y / 100;
+ }
+ elseif style_name == "w" {
+ w := read_u32(reader);
+ rect_style.w = cast(f32) w / 100;
+ }
+ elseif style_name == "h" {
+ h := read_u32(reader);
+ rect_style.h = cast(f32) h / 100;
+ }
+ elseif style_name == "color" {
+ r, g, b := parse_color(reader);
+ rect_style.color = Color.{ r, g, b };
+ }
+ else {
+ printf("Unknown style option: '%s'\n", style_name);
advance_line(reader);
break;
}
Undefined;
Text;
Image;
+ Rect;
}
use base: Slide_Item_Base;
text : Slide_Item_Text;
image : Slide_Item_Image;
+ rect : Slide_Item_Rect;
}
Slide_Item_Base :: struct {
// so the height of the image is automatically determined.
}
+Slide_Item_Rect :: struct {
+ use base := Slide_Item_Base.{ Slide_Item.Kind.Rect };
+
+ color : Color;
+
+ x, y : f32; // Between 0 and 1
+ w, h : f32; // Between 0 and 1
+}
+
slideshow_make :: (allocator := context.allocator) -> Slideshow {
draw_image(canvas, html_image.handle, x, y, w, h);
}
}
+
+ case Rect {
+ use Canvas
+
+ width, height := cast(f32) get_width(canvas), cast(f32) get_height(canvas);
+
+ x := rect.x * width;
+ y := rect.y * height;
+ w := rect.w * width;
+ h := rect.h * height;
+
+ fill_rect(canvas, x, y, w, h, rect.color.r, rect.color.g, rect.color.b, rect.color.a);
+ }
}
+++ /dev/null
-
-[define_text_style normal_text color 255 255 255 font_size 36 font_name "Arial" left padding 10]
-[define_text_style bold_title color 255 255 255 font_attr bold font_size 72 font_name "Arial" centered]
-
-[load_image first_image "images/first.jpg"]
-
-# ------------------------------------------------------------------
-[slide]
-[background 25 25 40]
-[text_style bold_title]
-[y 50]
-First slide title!
-
-# ------------------------------------------------------------------
-[slide]
-[background 40 25 25]
-[text_style bold_title]
-[y 10]
-Second slide title!
-
-[text_style normal_text]
-[y 20]
-Some normal looking text is here.
-
-# Robustness: This shouldn't be necessary to declare.
-
-[text_style normal_text font_attr bold]
-[y 25]
-Some more normal looking text is here.
-
-[image first_image x 30 y 30 width 40]
-
-# ------------------------------------------------------------------
-[slide]
-[text_style bold_title color 255 50 50 font_size 96 font_attr italic]
-[y 10]
-Bigger image!
-
-[image first_image x 25 width 50 y 15]