Apply API migration: rename window/control messages, update draw APIs - #42
Conversation
corepunch
commented
Apr 20, 2026
- 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>
There was a problem hiding this comment.
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 passrect_t const *(often viaR(...)). - Updated app/window creation APIs (new
hinstance_targ) and replacedmain()withgem_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). |
| 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)); | ||
| } |
There was a problem hiding this comment.
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.
| switch (msg) { | ||
| case kWindowMessageCreate: | ||
| case evCreate: | ||
| win->userdata = malloc(sizeof(items_t)); |
There was a problem hiding this comment.
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.
| win->userdata = malloc(sizeof(items_t)); | |
| win->userdata = calloc(1, sizeof(items_t)); | |
| if (!win->userdata) return false; |
| return true; | ||
| case kToolBarMessageButtonClick: | ||
| case tbButtonClick: | ||
| free(win->userdata); |
There was a problem hiding this comment.
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).
| free(win->userdata); |
|
@copilot Build fails: Building liborion via ui/Makefile... |
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.