Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes and Example with twr-con-window #62

Open
wants to merge 55 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
d8f61bd
Started prototyping screen
JohnDog3112 Nov 16, 2024
c9de34e
Finished event parts
JohnDog3112 Nov 16, 2024
7fefa8a
Started adding events to canvas
JohnDog3112 Nov 23, 2024
0fa129a
Added events to d2d canvas
JohnDog3112 Nov 23, 2024
e783738
Added animation_frame event to canvas and started making twrConsoleWi…
JohnDog3112 Nov 23, 2024
cad343b
Got working prototype of window minus extra events and menus
JohnDog3112 Nov 26, 2024
fb6d39d
Pushing previous changes
JohnDog3112 Dec 4, 2024
1a58b3c
Worked on setting up widgets for the window menu
JohnDog3112 Dec 7, 2024
88c1f04
Started implementing second widget prototype idea
JohnDog3112 Dec 12, 2024
c4c7a65
Started moving old menu prototype to new format
JohnDog3112 Dec 13, 2024
bdeddd8
Finished up menu prototype and started making main widget manager
JohnDog3112 Dec 14, 2024
f17e973
Fixed issue with scrolling, added MenuButton, and started adding Sepe…
JohnDog3112 Dec 17, 2024
2dbf7f5
Finished seperator, refactored Menu a bit, and started adding C bindi…
JohnDog3112 Dec 18, 2024
6d31195
Added widget deletion and started adding radio menu
JohnDog3112 Dec 19, 2024
0aef4d1
Added radio menu and fixed bug with menu update propogation
JohnDog3112 Dec 21, 2024
fda95d1
Added leftover files from previos commit
JohnDog3112 Dec 21, 2024
6c5059d
Added menu bar
JohnDog3112 Dec 23, 2024
2c8c501
Started making x,y properties optional
JohnDog3112 Dec 23, 2024
193f220
Finished removing x, y fields from sub-widgets, added submenus, fixed…
JohnDog3112 Dec 27, 2024
ee093ab
Added submenus to the C interface and started doing the same with che…
JohnDog3112 Dec 28, 2024
38814c1
Finished checkbox settings
JohnDog3112 Dec 31, 2024
9aee1eb
Added visibility to widgets and simplified widget settings
JohnDog3112 Dec 31, 2024
7887326
Expanded mouse events to include the button used, fixed resizing issu…
JohnDog3112 Jan 2, 2025
6ed8f5b
Started simplifying menu bar again
JohnDog3112 Jan 11, 2025
3631412
Started simplifying widget API
JohnDog3112 Jan 18, 2025
0ce1f28
Experimented with accessors and setup getters and setters to allow pr…
JohnDog3112 Jan 18, 2025
a19a4a8
Converted most of Menu into WidgetContainer to abstract Menu and Menu…
JohnDog3112 Jan 21, 2025
962aa47
Trimmed MenuBar down using WidgetContainer class
JohnDog3112 Jan 23, 2025
53c4850
Made a bunch of minor tweaks to widgets
JohnDog3112 Jan 23, 2025
63d3fcf
Simplified checkbox and started creating simplified radio menu options
JohnDog3112 Jan 24, 2025
797e94b
Pusing previous changes before refactor
JohnDog3112 Jan 25, 2025
11ced86
Started refactoring how widget interface works
JohnDog3112 Jan 25, 2025
1603cbc
Worked more on refactoring menu items
JohnDog3112 Feb 1, 2025
1cdb931
Finished radio item implementation and fixed some bugs
JohnDog3112 Feb 1, 2025
ff619a5
Moved everything over to using WidgetImpl
JohnDog3112 Feb 1, 2025
cd933a4
Split some getter/setter functions in the Widget interface
JohnDog3112 Feb 1, 2025
40132b1
Did some refactoring, removed old code, and started debugging some we…
JohnDog3112 Feb 2, 2025
fecdca6
Fixed propogation issue, fixed a bug where multiple things could be s…
JohnDog3112 Feb 5, 2025
df1c76f
Added disable option and started adding property lists for the C inte…
JohnDog3112 Feb 6, 2025
3f9da8c
Added C interface for getting and setting widget propertyies by name
JohnDog3112 Feb 8, 2025
f3ae31e
Added more functions for widget properties
JohnDog3112 Feb 12, 2025
61a3616
Experimented with merging sync and async treatment
JohnDog3112 Feb 13, 2025
51d9084
Experimented more with promises
JohnDog3112 Feb 14, 2025
2288cd8
Finished experimentation with FakePromise, fixed memory leaks in getP…
JohnDog3112 Feb 16, 2025
4b4e0a5
Fixed some old code, reworked getting types and access data from prop…
JohnDog3112 Feb 18, 2025
23c8b1e
worked on more test cases for get/set prop
JohnDog3112 Feb 19, 2025
3d264e5
Finished test case for get and set prop
JohnDog3112 Feb 20, 2025
06301d3
Started adding getters/setters for window properties and started maki…
JohnDog3112 Feb 21, 2025
05ed63a
Finished moving to helper functions and did more work on adding tests…
JohnDog3112 Feb 26, 2025
11b1b7a
Continued adding getters/setters for Menu Properties with (untested) …
JohnDog3112 Feb 27, 2025
a009043
Tested getter/setter tests and renamed the get/set functions.
JohnDog3112 Feb 28, 2025
3a2ef47
Did a bit of refactoring and started adding resize events to Windows
JohnDog3112 Mar 1, 2025
6bddf28
Experimented and worked on fixing text centering
JohnDog3112 Mar 5, 2025
a81a105
Experimented more with text alignment and added more tests for resizing
JohnDog3112 Mar 6, 2025
9c29c0a
Worked on figuring out how to allow a WASMModule to be garbage collec…
JohnDog3112 Mar 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions examples/pong/entry-point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,44 @@ static int ANIMATION_LOOP_EVENT_ID = -1;
static int KEY_DOWN_EVENT_ID = -1;
static int KEY_UP_EVENT_ID = -1;
extern "C" {
__attribute__((import_name("registerKeyUpEvent")))
void register_key_up_event(int event_id);
// __attribute__((import_name("registerKeyUpEvent")))
// void register_key_up_event(int event_id);

__attribute__((import_name("registerKeyDownEvent")))
void register_key_down_event(int event_id);
// __attribute__((import_name("registerKeyDownEvent")))
// void register_key_down_event(int event_id);

__attribute__((import_name("registerAnimationLoop")))
void register_animation_loop(int event_id);
// __attribute__((import_name("registerAnimationLoop")))
// void register_animation_loop(int event_id);

__attribute__((import_name("registerMouseMoveEvent")))
void register_mouse_move_event(int event_id, const char* element_id, bool relative);
// __attribute__((import_name("registerMouseMoveEvent")))
// void register_mouse_move_event(int event_id, const char* element_id, bool relative);

__attribute__((import_name("registerMousePressEvent")))
void register_mouse_press_event(int event_id, const char* element_id, bool relative);
// __attribute__((import_name("registerMousePressEvent")))
// void register_mouse_press_event(int event_id, const char* element_id, bool relative);



__attribute__((export_name("initMenu")))
void init_menu() {
MOUSE_MOVE_EVENT_ID = twr_register_callback("menuMouseMoveCallback");
register_mouse_move_event(MOUSE_MOVE_EVENT_ID, "twr_d2dcanvas", true);
// register_mouse_move_event(MOUSE_MOVE_EVENT_ID, "twr_d2dcanvas", true);
d2d_register_event(D2D_MOUSE_MOVE, MOUSE_MOVE_EVENT_ID);

MOUSE_PRESS_EVENT_ID = twr_register_callback("menuMousePressCallback");
register_mouse_press_event(MOUSE_PRESS_EVENT_ID, "twr_d2dcanvas", true);
// register_mouse_press_event(MOUSE_PRESS_EVENT_ID, "twr_d2dcanvas", true);
d2d_register_event(D2D_MOUSE_DOWN, MOUSE_PRESS_EVENT_ID);

ANIMATION_LOOP_EVENT_ID = twr_register_callback("menuAnimationLoopCallback");
register_animation_loop(ANIMATION_LOOP_EVENT_ID);
// register_animation_loop(ANIMATION_LOOP_EVENT_ID);
d2d_register_event(D2D_ANIMATION_FRAME, ANIMATION_LOOP_EVENT_ID);

KEY_DOWN_EVENT_ID = twr_register_callback("menuKeyDownCallback");
register_key_down_event(KEY_DOWN_EVENT_ID);
// register_key_down_event(KEY_DOWN_EVENT_ID);
d2d_register_event(D2D_KEY_DOWN, KEY_DOWN_EVENT_ID);

KEY_UP_EVENT_ID = twr_register_callback("menuKeyUpCallback");
register_key_up_event(KEY_UP_EVENT_ID);
// register_key_up_event(KEY_UP_EVENT_ID);
d2d_register_event(D2D_KEY_UP, KEY_UP_EVENT_ID);

menu.setBounds(d2d_get_canvas_prop("canvasWidth"), d2d_get_canvas_prop("canvasHeight"));
}
Expand Down
2 changes: 1 addition & 1 deletion examples/pong/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</script>
</head>
<body>
<canvas id="twr_d2dcanvas" width="900" height="600"></canvas><br>
<canvas id="twr_d2dcanvas" width="900" height="600" tabindex="1"></canvas><br>
<a id="control_text"></a>

<script type="module">
Expand Down
30 changes: 30 additions & 0 deletions examples/window/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CC := clang
TWRCFLAGS := --target=wasm32 -nostdinc -nostdlib -isystem ../../include
CPPLIB := ../twr-cpp
CFLAGS := -c -Wall -O3 $(TWRCFLAGS) -I $(CPPLIB)
CFLAGS_DEBUG := -c -Wall -g -O0 $(TWRCFLAGS) -I $(CPPLIB)

$(info $(shell mkdir -p out))

.PHONY: default

default: window.wasm window-a.wasm

window.o: window.c
$(CC) $(CFLAGS) $< -o $@

window-a.o: window.c
$(CC) $(CFLAGS) $< -o $@ -DASYNC

window.wasm: window.o
wasm-ld window.o ../../lib-c/twr.a -o window.wasm \
--no-entry --initial-memory=4063232 --max-memory=4063232 \

window-a.wasm: window-a.o
wasm-ld window-a.o ../../lib-c/twr.a -o window-a.wasm \
--no-entry --shared-memory --no-check-features --initial-memory=4063232 --max-memory=4063232 \

clean:
rm -f *.o
rm -f *.wasm
rm -f out/*
56 changes: 56 additions & 0 deletions examples/window/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html>
<head>
<title>Audio Tests</title>

<script type="importmap">
{
"imports": {
"twr-wasm": "../../lib-js/index.js"
}
}
</script>
</head>
<body>
<div id="window-resizable-div" style="resize:both;overflow:hidden;width:640px;height:480px;min-width:200px;min-height:200px;">
<canvas id="window" width="640px" height="480px" tabindex="1"></canvas>
</div>

<script type="module">
"use strict";

import {twrWasmModule, twrWasmModuleAsync, twrConsoleWindow} from "twr-wasm";

const is_async = window.location.hash=="#async";

const modCon = is_async ? twrWasmModuleAsync : twrWasmModule;

const windowCanvas = document.getElementById("window");
if (windowCanvas == undefined) throw new Error(`Window example: Couldn't find window canvas!`);
const windowConsole = new twrConsoleWindow(windowCanvas);
const mod = new modCon({io:{
window: windowConsole,
}});
await mod.loadWasm(is_async ? "./window-a.wasm" : "./window.wasm");

await mod.callC(["init"]);

const windowDiv = document.getElementById("window-resizable-div");
if (windowDiv == undefined) throw new Error(`Window example: couldn't find window canvas div!`);
// window.windowConsole = windowConsole;
let prevDivWidth = windowDiv.clientWidth;
let prevDivHeight = windowDiv.clientHeight;
let resizeObserver = new ResizeObserver(() => {
const width = windowDiv.clientWidth;
const height = windowDiv.clientHeight;
if (width != prevDivWidth || height != prevDivHeight) {
prevDivWidth = width;
prevDivHeight = height;
console.log(`resizing: ${width}, ${height}`);
windowConsole.resizeWindow(width, height);
}
});
resizeObserver.observe(windowDiv);
</script>
</body>
</html>
11 changes: 11 additions & 0 deletions examples/window/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"@parcel/resolver-default": {
"packageExports": true
},
"alias": {
"twr-wasm": "../../lib-js/index.js"
},
"dependencies": {
"twr-wasm": "^2.0.0"
}
}
Loading