Skip to content

Apply API migration: rename window/control messages, update draw APIs - #42

Merged
corepunch merged 2 commits into
mainfrom
copilot/migrate-orion-ui-submodule
Apr 20, 2026
Merged

Apply API migration: rename window/control messages, update draw APIs#42
corepunch merged 2 commits into
mainfrom
copilot/migrate-orion-ui-submodule

Conversation

@corepunch

Copy link
Copy Markdown
Owner
  • Renamed all kWindowMessage* → ev* event constants (sed)
  • Renamed kButton*, kComboBox*, kToolBar*, kScrollBar*, kStatusBar* → short forms
  • Renamed kColor* → br* system color constants
  • Updated fill_rect/draw_rect/draw_rect_ex to use rect_t* with R() macro
  • Updated show_dialog signature to use int w, int h instead of rect_t*
  • Removed toolbar_button_t; use toolbar_item_t with TOOLBAR_ITEM_BUTTON
  • Replaced tbButtonClick active-loop with tbSetActiveButton send_message
  • Removed extern _focused/_captured; use g_ui_runtime.focused/.captured
  • Added hinstance_t argument to create_window calls (pass 0 or hinstance)
  • Replaced main() with gem_init/gem_shutdown + GEM_STANDALONE_MAIN
  • Fixed wi_stuff.c: kEventLeftMouseDragged/Up and running → g_ui_runtime.running
  • Added ui/user/rect.h include to gamefont.c for R() macro

- Renamed all kWindowMessage* → ev* event constants (sed)
- Renamed kButton*, kComboBox*, kToolBar*, kScrollBar*, kStatusBar* → short forms
- Renamed kColor* → br* system color constants
- Updated fill_rect/draw_rect/draw_rect_ex to use rect_t* with R() macro
- Updated show_dialog signature to use int w, int h instead of rect_t*
- Removed toolbar_button_t; use toolbar_item_t with TOOLBAR_ITEM_BUTTON
- Replaced tbButtonClick active-loop with tbSetActiveButton send_message
- Removed extern _focused/_captured; use g_ui_runtime.focused/.captured
- Added hinstance_t argument to create_window calls (pass 0 or hinstance)
- Replaced main() with gem_init/gem_shutdown + GEM_STANDALONE_MAIN
- Fixed wi_stuff.c: kEventLeftMouseDragged/Up and running → g_ui_runtime.running
- Added ui/user/rect.h include to gamefont.c for R() macro

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: corepunch <83646194+corepunch@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates DOOM-ED’s editor/mapview code to a newer UI API by renaming message/event constants, updating drawing helpers to take rect_t* (via R()), and adapting window creation / app entry to the gem_* + GEM_STANDALONE_MAIN model.

Changes:

  • Updated window/control message constants (e.g., kWindowMessage*ev*, toolbar/button notifications, focus/capture globals).
  • Updated drawing calls (fill_rect, draw_rect, draw_rect_ex) to pass rect_t const * (often via R(...)).
  • Updated app/window creation APIs (new hinstance_t arg) and replaced main() with gem_init/gem_shutdown + GEM_STANDALONE_MAIN.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
mapview/wi_stuff.c Updates input event names and uses g_ui_runtime.running for shutdown.
mapview/texture.c Updates create_window calls for new hinstance_t parameter.
mapview/map.h Updates public API signatures (show_dialog, draw helpers) and removes toolbar_button_t forward decl.
mapview/main.c Switches to gem_init/gem_shutdown and GEM_STANDALONE_MAIN; passes hinstance_t into window creation.
mapview/gamefont.c Adopts R() macro for rect-based drawing and adjusts includes.
editor/windows/things.c Migrates to ev* messages and new toolbar item API (toolbar_item_t, tbSetItems, tbSetActiveButton).
editor/windows/texatlas.c Migrates to rect-based drawing and ev* messages for texture atlas windows.
editor/windows/statbar.c Migrates message constants to ev*.
editor/windows/sprite.c Uses g_ui_runtime.focused, rect-based drawing, and updated command/button constants.
editor/windows/project.c Migrates message constants and switches to rect-based fill_rect.
editor/windows/perfcounter.c Migrates paint message constant to evPaint.
editor/windows/inspector/insp_vertex.c Migrates to ev* and edUpdate.
editor/windows/inspector/insp_thing.c Updates show_dialog call signature and migrates notifications/messages (btn*, edUpdate, ev*).
editor/windows/inspector/insp_sector.c Migrates toolbar to toolbar_item_t + tbSetItems and updates colors/message constants.
editor/windows/inspector/insp_line.c Migrates to ev* and edUpdate.
editor/windows/game.c Updates create_window signature, rect-based drawing, and uses g_ui_runtime.focused/.captured.
editor/editor_input.c Migrates create messages to evCreate and uses g_ui_runtime.focused for focus preservation.
editor/editor_draw.c Removes reliance on _focused extern (now via runtime state elsewhere).

Comment thread mapview/gamefont.c
Comment on lines 123 to 134
if (char_code < 0 || char_code >= 128 || gamefont_state.font[char_code].texture == 0) {
// Fallback for unsupported characters - draw a solid rectangle
if (c != ' ') { // Skip spaces
draw_rect(white_tex, x, y, CONSOLE_FONT_WIDTH, CONSOLE_FONT_HEIGHT);
draw_rect(white_tex, R(x, y, CONSOLE_FONT_WIDTH, CONSOLE_FONT_HEIGHT));
}
return;
}

font_char_t* ch = &gamefont_state.font[char_code];

draw_rect(ch->texture, x - gamefont_state.font[char_code].x, y - gamefont_state.font[char_code].y, ch->width, ch->height);
draw_rect(ch->texture, R(x - gamefont_state.font[char_code].x, y - gamefont_state.font[char_code].y, ch->width, ch->height));
}

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

draw_rect() is now called without any visible declaration in this translation unit (the previous extern void draw_rect(...) forward declaration was removed). With C99+ this can become a hard compile error (implicit function declaration). Include the header that declares draw_rect (e.g. the draw API header) or restore an appropriate forward declaration.

Copilot uses AI. Check for mistakes.
Comment thread editor/windows/project.c Outdated
switch (msg) {
case kWindowMessageCreate:
case evCreate:
win->userdata = malloc(sizeof(items_t));

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

items_t is allocated with malloc but never initialized, yet collect_proc immediately reads and increments arr->num_items. If num_items contains garbage, this can write out of bounds of items[]. Initialize the allocation (e.g., calloc, or memset after malloc) before calling find_all_maps.

Suggested change
win->userdata = malloc(sizeof(items_t));
win->userdata = calloc(1, sizeof(items_t));
if (!win->userdata) return false;

Copilot uses AI. Check for mistakes.
Comment thread editor/windows/things.c Outdated
return true;
case kToolBarMessageButtonClick:
case tbButtonClick:
free(win->userdata);

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbButtonClick frees win->userdata, but this window proc never assigns/owns win->userdata (it uses userdata2 for lparam). This is at best a no-op (if NULL) and at worst can free memory owned by the framework or another code path. Remove this free, or only free memory that this proc explicitly allocates and owns (ideally in a destroy handler).

Suggested change
free(win->userdata);

Copilot uses AI. Check for mistakes.
@corepunch

Copy link
Copy Markdown
Owner Author

@copilot Build fails:

Building liborion via ui/Makefile...
mkdir -p build/lib
Building platform library...
/Applications/Xcode_16.4.app/Contents/Developer/usr/bin/make -C platform OUTDIR=/Users/runner/work/doom-ed/doom-ed/ui/build/lib
( find macos -name ".m"; find unix -name ".c"; ) | sed 's|.|#include "&"|' | clang -Wall -Wextra -fPIC -I. -DGL_SILENCE_DEPRECATION -x objective-c - -dynamiclib -framework AppKit -framework Cocoa -framework OpenGL -framework IOSurface -framework Security -framework CoreFoundation -install_name @rpath/libplatform.dylib -o /Users/runner/work/doom-ed/doom-ed/ui/build/lib/libplatform.dylib
Creating static library: build/lib/liborion.a
find user kernel commctl -name "
.c" | sort | sed 's/./#include "&"/' |
gcc -Wall -Wextra -std=c11 -I. -DGL_SILENCE_DEPRECATION -D_DEFAULT_SOURCE -Wno-unused-parameter -I/opt/homebrew/include -I/usr/local/include -DHAVE_LUA -I/opt/homebrew/include/lua -x c -c -o build/liborion_unity.o - &&
ar rcs build/lib/liborion.a build/liborion_unity.o &&
rm -f build/liborion_unity.o
In file included from :1:
./commctl/button.c:134:14: warning: unused variable 'focus_outer' [-Wunused-variable]
134 | rect_t focus_outer = rect_inset(win->frame, -1);
| ^~~~~~~~~~~
1 warning generated.
Creating shared library: build/lib/liborion.dylib
find user kernel commctl -name "
.c" | sort | sed 's/.*/#include "&"/' |
gcc -Wall -Wextra -std=c11 -I. -DGL_SILENCE_DEPRECATION -D_DEFAULT_SOURCE -Wno-unused-parameter -I/opt/homebrew/include -I/usr/local/include -DHAVE_LUA -I/opt/homebrew/include/lua -dynamiclib -x c -o build/lib/liborion.dylib - -L/opt/homebrew/lib -L/usr/local/lib -L/opt/homebrew/lib -Lbuild/lib -lplatform -Wl,-rpath,/Users/runner/work/doom-ed/doom-ed/ui/build/lib -lm -framework OpenGL -llua
In file included from :1:
./commctl/button.c:134:14: warning: unused variable 'focus_outer' [-Wunused-variable]
134 | rect_t focus_outer = rect_inset(win->frame, -1);
| ^~~~~~~~~~~
1 warning generated.
mkdir -p build/share
mkdir -p build/bin
Building example: build/bin/filemanager
Building example: build/bin/formeditor
Building example: build/bin/helloworld
Building example: build/bin/imageeditor
Building example: build/bin/taskmanager
Building example: build/bin/terminal
Building example: build/bin/browser
mkdir -p build/gem
Building .gem: build/gem/imageeditor.gem
Building .gem: build/gem/filemanager.gem
Building .gem: build/gem/helloworld.gem
Building .gem: build/gem/terminal.gem
Building .gem: build/gem/formeditor.gem
OK All .gems built and validated
Building Orion Shell: build/bin/orion-shell
Building tool: build/bin/font_atlas
gcc -Wall -Wextra -std=c11 -I. -DGL_SILENCE_DEPRECATION -D_DEFAULT_SOURCE -Wno-unused-parameter -I/opt/homebrew/include -I/usr/local/include -DHAVE_LUA -I/opt/homebrew/include/lua -I. -Itools -o build/bin/font_atlas tools/font_atlas.c
-L/opt/homebrew/lib -L/usr/local/lib -L/opt/homebrew/lib -Lbuild/lib -lorion -Lbuild/lib -lplatform -Wl,-rpath,/Users/runner/work/doom-ed/doom-ed/ui/build/lib -lm -framework OpenGL -llua
All tools built
gcc -Wall -std=gnu17 -DGL_SILENCE_DEPRECATION -I/opt/homebrew/include -I/usr/local/include -I/usr/local/opt/cglm/include -I. -c mapview/bsp.c -o build/mapview/bsp.o
In file included from mapview/bsp.c:2:
./mapview/map.h:41:9: warning: 'SCROLL_SENSITIVITY' macro redefined [-Wmacro-redefined]
41 | #define SCROLL_SENSITIVITY 5
| ^
./ui/user/messages.h:261:9: note: previous definition is here
261 | #define SCROLL_SENSITIVITY 3
| ^
1 warning generated.
gcc -Wall -std=gnu17 -DGL_SILENCE_DEPRECATION -I/opt/homebrew/include -I/usr/local/include -I/usr/local/opt/cglm/include -I. -c mapview/collision.c -o build/mapview/collision.o
In file included from mapview/collision.c:1:
./mapview/map.h:41:9: warning: 'SCROLL_SENSITIVITY' macro redefined [-Wmacro-redefined]
41 | #define SCROLL_SENSITIVITY 5
| ^
./ui/user/messages.h:261:9: note: previous definition is here
261 | #define SCROLL_SENSITIVITY 3
| ^
1 warning generated.
gcc -Wall -std=gnu17 -DGL_SILENCE_DEPRECATION -I/opt/homebrew/include -I/usr/local/include -I/usr/local/opt/cglm/include -I. -c mapview/floor.c -o build/mapview/floor.o
In file included from mapview/floor.c:4:
./mapview/map.h:41:9: warning: 'SCROLL_SENSITIVITY' macro redefined [-Wmacro-redefined]
41 | #define SCROLL_SENSITIVITY 5
| ^
./ui/user/messages.h:261:9: note: previous definition is here
261 | #define SCROLL_SENSITIVITY 3
| ^
1 warning generated.
gcc -Wall -std=gnu17 -DGL_SILENCE_DEPRECATION -I/opt/homebrew/include -I/usr/local/include -I/usr/local/opt/cglm/include -I. -c mapview/gamefont.c -o build/mapview/gamefont.o
mapview/gamefont.c:126:7: error: call to undeclared function 'draw_rect'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
126 | draw_rect(white_tex, R(x, y, CONSOLE_FONT_WIDTH, CONSOLE_FONT_HEIGHT));
| ^
mapview/gamefont.c:133:3: error: call to undeclared function 'draw_rect'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
133 | draw_rect(ch->texture, R(x - gamefont_state.font[char_code].x, y - gamefont_state.font[char_code].y, ch->width, ch->height));
| ^
mapview/gamefont.c:160:43: warning: array subscript is of type 'char' [-Wchar-subscripts]
160 | int char_width = gamefont_state.font[c].width;
| ^~
mapview/gamefont.c:189:43: warning: array subscript is of type 'char' [-Wchar-subscripts]
189 | int char_width = gamefont_state.font[c].width;
| ^~
2 warnings and 2 errors generated.
make: *** [build/mapview/gamefont.o] Error 1

Improve safety and correctness across several modules:

- editor/windows/project.c: Allocate items with calloc and check for allocation failure to avoid uninitialized data and handle OOM.
- editor/windows/things.c: Remove freeing of win->userdata on button click to prevent premature/freeing ownership issues.
- mapview/gamefont.c: Add required draw header and cast characters to unsigned char when indexing font array to avoid negative indices for signed chars; preserves correct glyph widths.
- mapview/map.h: Remove unused/undesired SCROLL_SENSITIVITY macro.

These changes fix potential crashes and incorrect text width calculations and tidy up configuration.
@corepunch
corepunch merged commit 1c86d91 into main Apr 20, 2026
2 checks passed
@corepunch
corepunch deleted the copilot/migrate-orion-ui-submodule branch April 20, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants