Skip to content

Commit

Permalink
fix: window origin set to center
Browse files Browse the repository at this point in the history
Also, added abort statements if important stuff is not properly initialized.
  • Loading branch information
iWas-Coder committed Dec 22, 2024
1 parent 3270466 commit 12efedf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/carbon_win_macos.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ void carbon_win_open(u16 width, u16 height, const char *title) {
@autoreleasepool {
carbon_win__app = [NSApplication sharedApplication];
[carbon_win__app setActivationPolicy:NSApplicationActivationPolicyRegular];
NSRect frame = NSMakeRect(0, 0, width, height);
NSRect frame = NSMakeRect(([NSScreen mainScreen].frame.size.width / 2) - (width / 2),
([NSScreen mainScreen].frame.size.height / 2) - (height / 2),
width,
height);
carbon_win__window = [[NSWindow alloc]
initWithContentRect:frame
styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable)
Expand Down Expand Up @@ -53,7 +56,8 @@ void carbon_win_close(void) {

void carbon_win_update(CBN_DrawCanvas dc) {
@autoreleasepool {
if (!carbon_win__view) return;
if (!carbon_win__view) CARBON_ASSERT(0 && "Window is not properly initialized");
if (!dc.pixels) CARBON_ASSERT(0 && "DrawCanvas has no valid pixel array");
// Lock and use the provided draw canvas to update the window
NSBitmapImageRep *image_repr = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:(u8 **) &dc.pixels
Expand Down

0 comments on commit 12efedf

Please sign in to comment.