Skip to content

Commit

Permalink
Add fenster_resize
Browse files Browse the repository at this point in the history
fix windows warnings
  • Loading branch information
CardealRusso authored Oct 19, 2024
1 parent 2c25951 commit 0f234ef
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Code is distributed under MIT license, feel free to use it in your proprietary p
- Platform-agnostic structure for audio
- Mouse: Left, Right, Middle, Scrollup/down
- Window resize (buf size is handled internally)
- Added: fenster_sync
- Added: fenster_sync, fenster_resize
- Changed: array on modkeys, mouse pos

```C
Expand All @@ -28,4 +28,5 @@ struct fenster {
};

FENSTER_API void fenster_sync(struct fenster *f, int fps);
FENSTER_API void fenster_resize(struct fenster *f, int width, int height);
```
1 change: 1 addition & 0 deletions src/fenster/fenster.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ FENSTER_API void fenster_close(struct fenster *f);
FENSTER_API void fenster_sleep(int64_t ms);
FENSTER_API int64_t fenster_time(void);
FENSTER_API void fenster_sync(struct fenster *f, int fps);
FENSTER_API void fenster_resize(struct fenster *f, int width, int height);

#define fenster_pixel(f, x, y) ((f)->buf[((y) * (f)->width) + (x)])

Expand Down
7 changes: 6 additions & 1 deletion src/fenster/fenster_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,9 @@ FENSTER_API void fenster_sync(struct fenster *f, int fps) {

f->lastsync = fenster_time();
}
#endif /* FENSTER_LINUX_H */

FENSTER_API void fenster_resize(struct fenster *f, int width, int height) {
XResizeWindow(f->dpy, f->w, width, height);
XFlush(f->dpy);
}
#endif /* FENSTER_LINUX_H */
8 changes: 7 additions & 1 deletion src/fenster/fenster_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,10 @@ FENSTER_API void fenster_sync(struct fenster *f, int fps) {

f->lastsync = fenster_time();
}
#endif /* FENSTER_MAC_H */

FENSTER_API void fenster_resize(struct fenster *f, int width, int height) {
NSRect frame = NSMakeRect(0, 0, width, height);
msg2(void, f->wnd, "setContentSize:", NSSize, frame.size, id, nil);
msg(void, f->wnd, "center");
}
#endif /* FENSTER_MAC_H */
11 changes: 10 additions & 1 deletion src/fenster/fenster_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static LRESULT CALLBACK fenster_wndproc(HWND hwnd, UINT msg, WPARAM wParam,
HDC memdc = CreateCompatibleDC(hdc);
HBITMAP hbmp = CreateCompatibleBitmap(hdc, f->width, f->height);
HBITMAP oldbmp = SelectObject(memdc, hbmp);
BINFO bi = {{sizeof(bi), f->width, -f->height, 1, 32, BI_BITFIELDS}};
BINFO bi = {{sizeof(BITMAPINFOHEADER), f->width, -f->height, 1, 32, BI_BITFIELDS, 0, 0, 0, 0, 0}, {{0}}};
bi.bmiColors[0].rgbRed = 0xff;
bi.bmiColors[1].rgbGreen = 0xff;
bi.bmiColors[2].rgbBlue = 0xff;
Expand Down Expand Up @@ -153,4 +153,13 @@ FENSTER_API void fenster_sync(struct fenster *f, int fps) {

f->lastsync = fenster_time();
}

FENSTER_API void fenster_resize(struct fenster *f, int width, int height) {
RECT rect = {0, 0, width, height};
AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, FALSE, WS_EX_CLIENTEDGE);
SetWindowPos(f->hwnd, NULL, 0, 0,
rect.right - rect.left,
rect.bottom - rect.top,
SWP_NOMOVE | SWP_NOZORDER);
}
#endif /* FENSTER_WINDOWS_H */

0 comments on commit 0f234ef

Please sign in to comment.