mirror of
https://github.com/zserge/fenster.git
synced 2025-07-25 13:16:13 +03:00
Corrected window resize for WIN32 target.
clears display and letterboxes results
This commit is contained in:
46
fenster.h
46
fenster.h
@ -22,6 +22,8 @@ struct fenster {
|
|||||||
const char *title;
|
const char *title;
|
||||||
const int width;
|
const int width;
|
||||||
const int height;
|
const int height;
|
||||||
|
int display_width;
|
||||||
|
int display_height;
|
||||||
uint32_t *buf;
|
uint32_t *buf;
|
||||||
int keys[256]; /* keys are mostly ASCII, but arrows are 17..20 */
|
int keys[256]; /* keys are mostly ASCII, but arrows are 17..20 */
|
||||||
int mod; /* mod is 4 bits mask, ctrl=1, shift=2, alt=4, meta=8 */
|
int mod; /* mod is 4 bits mask, ctrl=1, shift=2, alt=4, meta=8 */
|
||||||
@ -165,6 +167,9 @@ FENSTER_API int fenster_loop(struct fenster *f) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
|
#ifndef MIN
|
||||||
|
#define MIN(a, b) ((a)<(b)? (a) : (b))
|
||||||
|
#endif
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static const uint8_t FENSTER_KEYCODES[] = {0,27,49,50,51,52,53,54,55,56,57,48,45,61,8,9,81,87,69,82,84,89,85,73,79,80,91,93,10,0,65,83,68,70,71,72,74,75,76,59,39,96,0,92,90,88,67,86,66,78,77,44,46,47,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,17,3,0,20,0,19,0,5,18,4,26,127};
|
static const uint8_t FENSTER_KEYCODES[] = {0,27,49,50,51,52,53,54,55,56,57,48,45,61,8,9,81,87,69,82,84,89,85,73,79,80,91,93,10,0,65,83,68,70,71,72,74,75,76,59,39,96,0,92,90,88,67,86,66,78,77,44,46,47,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,17,3,0,20,0,19,0,5,18,4,26,127};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
@ -173,22 +178,37 @@ static LRESULT CALLBACK fenster_wndproc(HWND hwnd, UINT msg, WPARAM wParam,
|
|||||||
struct fenster *f = (struct fenster *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
struct fenster *f = (struct fenster *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case WM_PAINT: {
|
case WM_PAINT: {
|
||||||
|
float scale = MIN((float)f->display_width/f->width, (float)f->display_height/f->height);
|
||||||
|
BITMAPINFO bmi = {
|
||||||
|
.bmiHeader.biSize = sizeof(BITMAPINFOHEADER),
|
||||||
|
.bmiHeader.biBitCount = 32,
|
||||||
|
.bmiHeader.biCompression = BI_RGB,
|
||||||
|
.bmiHeader.biPlanes = 1,
|
||||||
|
.bmiHeader.biWidth = f->width,
|
||||||
|
.bmiHeader.biHeight = -f->height
|
||||||
|
};
|
||||||
|
int xorigin,yorigin,draw_width,draw_height;
|
||||||
|
draw_width = f->width*scale;
|
||||||
|
draw_height = f->height*scale;
|
||||||
|
xorigin=(f->display_width-draw_width)/2;
|
||||||
|
yorigin=(f->display_height-draw_height)/2;
|
||||||
|
StretchDIBits(GetDC(hwnd),
|
||||||
|
xorigin, yorigin, draw_width, draw_height,
|
||||||
|
0, 0, f->width, f->height,
|
||||||
|
f->buf, &bmi, DIB_RGB_COLORS, SRCCOPY);
|
||||||
|
ValidateRect(hwnd,0);
|
||||||
|
} break;
|
||||||
|
case WM_SIZE:
|
||||||
|
{
|
||||||
|
f->display_width = LOWORD(lParam);
|
||||||
|
f->display_height = HIWORD(lParam);
|
||||||
PAINTSTRUCT ps;
|
PAINTSTRUCT ps;
|
||||||
HDC hdc = BeginPaint(hwnd, &ps);
|
HDC hdc = BeginPaint(hwnd, &ps);
|
||||||
HDC memdc = CreateCompatibleDC(hdc);
|
HBRUSH brush = CreateSolidBrush(RGB(0, 0, 0));
|
||||||
HBITMAP hbmp = CreateCompatibleBitmap(hdc, f->width, f->height);
|
FillRect(hdc, &ps.rcPaint, brush);
|
||||||
HBITMAP oldbmp = SelectObject(memdc, hbmp);
|
DeleteObject(brush);
|
||||||
BITMAPINFO bi = {{sizeof(bi), f->width, -f->height, 1, 32, BI_RGB}};
|
|
||||||
bi.bmiColors[0].rgbRed = 0xff;
|
|
||||||
bi.bmiColors[1].rgbGreen = 0xff;
|
|
||||||
bi.bmiColors[2].rgbBlue = 0xff;
|
|
||||||
SetDIBitsToDevice(memdc, 0, 0, f->width, f->height, 0, 0, 0, f->height,
|
|
||||||
f->buf, (BITMAPINFO *)&bi, DIB_RGB_COLORS);
|
|
||||||
BitBlt(hdc, 0, 0, f->width, f->height, memdc, 0, 0, SRCCOPY);
|
|
||||||
SelectObject(memdc, oldbmp);
|
|
||||||
DeleteObject(hbmp);
|
|
||||||
DeleteDC(memdc);
|
|
||||||
EndPaint(hwnd, &ps);
|
EndPaint(hwnd, &ps);
|
||||||
|
RedrawWindow(hwnd, 0, 0, RDW_INVALIDATE | RDW_UPDATENOW);
|
||||||
} break;
|
} break;
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
DestroyWindow(hwnd);
|
DestroyWindow(hwnd);
|
||||||
|
Reference in New Issue
Block a user