Window painting is working!

This commit is contained in:
Krzosa Karol
2022-06-16 09:51:48 +02:00
parent d591cfea6f
commit 2a3284f70e
3 changed files with 50 additions and 21 deletions

View File

@@ -51,3 +51,4 @@ STD_OUTPUT_HANDLE :: 4294967285//(-11)->DWORD
GetStdHandle :: #foreign (nStdHandle: DWORD): HANDLE GetStdHandle :: #foreign (nStdHandle: DWORD): HANDLE
WriteConsoleA :: #foreign (hConsoleOutput: HANDLE,lpBuffer: *VOID,nNumberOfCharsToWrite: DWORD,lpNumberOfCharsWritten: LPDWORD,lpReserve: LPVOID): BOOL WriteConsoleA :: #foreign (hConsoleOutput: HANDLE,lpBuffer: *VOID,nNumberOfCharsToWrite: DWORD,lpNumberOfCharsWritten: LPDWORD,lpReserve: LPVOID): BOOL
WriteConsoleW :: #foreign (hConsoleOutput: HANDLE,lpBuffer: *VOID,nNumberOfCharsToWrite: DWORD,lpNumberOfCharsWritten: LPDWORD,lpReserve: LPVOID): BOOL WriteConsoleW :: #foreign (hConsoleOutput: HANDLE,lpBuffer: *VOID,nNumberOfCharsToWrite: DWORD,lpNumberOfCharsWritten: LPDWORD,lpReserve: LPVOID): BOOL
GetLastError :: #foreign (): DWORD

View File

@@ -2,6 +2,7 @@
RBGQUAD :: struct;; rgbBlue: BYTE; rgbGreen: BYTE; rgbRed: BYTE; rgbReserved: BYTE RBGQUAD :: struct;; rgbBlue: BYTE; rgbGreen: BYTE; rgbRed: BYTE; rgbReserved: BYTE
BITMAPINFOHEADER :: struct;; biSize: DWORD; biWidth: LONG; biHeight: LONG; biPlanes: WORD; biBitCount: WORD; biCompression: DWORD; biSizeImage: DWORD; biXPelsPerMeter: LONG; biYPelsPerMeter: LONG; biClrUsed: DWORD; biClrImportant: DWORD BITMAPINFOHEADER :: struct;; biSize: DWORD; biWidth: LONG; biHeight: LONG; biPlanes: WORD; biBitCount: WORD; biCompression: DWORD; biSizeImage: DWORD; biXPelsPerMeter: LONG; biYPelsPerMeter: LONG; biClrUsed: DWORD; biClrImportant: DWORD
BITMAPINFO :: struct;; bmiHeader: BITMAPINFOHEADER; bmiColors: [1]RBGQUAD BITMAPINFO :: struct;; bmiHeader: BITMAPINFOHEADER; bmiColors: [1]RBGQUAD
HGDIOBJ :: HANDLE
BI_RGB :: 0x0000 BI_RGB :: 0x0000
BI_RLE8 :: 0x0001 BI_RLE8 :: 0x0001
@@ -14,7 +15,25 @@ BI_CMYKRLE8 :: 0x000C
BI_CMYKRLE4 :: 0x000 BI_CMYKRLE4 :: 0x000
DIB_RGB_COLORS :: 0x00 DIB_RGB_COLORS :: 0x00
SRCCOPY :: 0x00CC0020 /* dest = source */
SRCPAINT :: 0x00EE0086 /* dest = source OR dest */
SRCAND :: 0x008800C6 /* dest = source AND dest */
SRCINVERT :: 0x00660046 /* dest = source XOR dest */
SRCERASE :: 0x00440328 /* dest = source AND (NOT dest ) */
NOTSRCCOPY :: 0x00330008 /* dest = (NOT source) */
NOTSRCERASE :: 0x001100A6 /* dest = (NOT src) AND (NOT dest) */
MERGECOPY :: 0x00C000CA /* dest = (source AND pattern) */
MERGEPAINT :: 0x00BB0226 /* dest = (NOT source) OR dest */
PATCOPY :: 0x00F00021 /* dest = pattern */
PATPAINT :: 0x00FB0A09 /* dest = DPSnoo */
PATINVERT :: 0x005A0049 /* dest = pattern XOR dest */
DSTINVERT :: 0x00550009 /* dest = (NOT dest) */
BLACKNESS :: 0x00000042 /* dest = BLACK */
WHITENESS :: 0x00FF0062 /* dest = WHITE */
// #import #foreign "gdi32.lib" @todo // #import #foreign "gdi32.lib" @todo
CreateDIBSection :: #foreign (hdc: HDC, pbmi: *BITMAPINFO, usage: UINT, ppvBits: **VOID, hSection: HANDLE, offset: DWORD): HBITMAP CreateDIBSection :: #foreign (hdc: HDC, pbmi: *BITMAPINFO, usage: UINT, ppvBits: **VOID, hSection: HANDLE, offset: DWORD): HBITMAP
CreateCompatibleDC :: #foreign (hdc: HDC): HDC CreateCompatibleDC :: #foreign (hdc: HDC): HDC
SelectObject :: #foreign (hdc: HDC, h: HGDIOBJ): HGDIOBJ
BitBlt :: #foreign (hdc: HDC, x: int, y: int, cx: int, cy: int, hdcSrc: HDC, x1: int, y1: int, ro: DWORD): BOOL

View File

@@ -100,7 +100,7 @@ string_to_string16 :: (in: String): String16
result.str[result.len] = 0 result.str[result.len] = 0
return result return result
Vec2I :: struct;; x: S32; y: S32 Vec2I :: struct;; x: S64; y: S64
Vec2 :: struct;; x: F32; y: F32 Vec2 :: struct;; x: F32; y: F32
Windows_Bitmap :: struct Windows_Bitmap :: struct
size: Vec2I size: Vec2I
@@ -115,7 +115,7 @@ create_bitmap :: (size: Vec2I, bottom_up: Bool = true): Windows_Bitmap
bminfo := BITMAPINFO{ bminfo := BITMAPINFO{
BITMAPINFOHEADER{ BITMAPINFOHEADER{
biSize = size_of(BITMAPINFOHEADER), biSize = 40, // @todo!!! size_of(BITMAPINFOHEADER),
biWidth = size.x->LONG, biWidth = size.x->LONG,
biHeight = size.y->LONG, biHeight = size.y->LONG,
biPlanes = 1, biPlanes = 1,
@@ -128,6 +128,7 @@ create_bitmap :: (size: Vec2I, bottom_up: Bool = true): Windows_Bitmap
hdc := GetDC(0) hdc := GetDC(0)
result.dib = CreateDIBSection(hdc, &bminfo, DIB_RGB_COLORS, (&result.data)->**void, 0, 0) result.dib = CreateDIBSection(hdc, &bminfo, DIB_RGB_COLORS, (&result.data)->**void, 0, 0)
error := GetLastError()
result.hdc = CreateCompatibleDC(hdc) result.hdc = CreateCompatibleDC(hdc)
return result return result
@@ -135,6 +136,7 @@ app_is_running := true
window_procedure :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT window_procedure :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT
if msg == WM_DESTROY if msg == WM_DESTROY
PostQuitMessage(0) PostQuitMessage(0)
app_is_running = false
return 0 return 0
else;; return DefWindowProcW(hwnd, msg, wparam, lparam) else;; return DefWindowProcW(hwnd, msg, wparam, lparam)
@@ -153,9 +155,7 @@ test_unicode :: ()
assert(result.out_str == 0xF3, "Invalid decode") assert(result.out_str == 0xF3, "Invalid decode")
WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nShowCmd: int): int WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nShowCmd: int): int
bitmap := create_bitmap({1280, 720}) window_name := string_to_string16("Have a wonderful day! 豈 更 車 賈 滑 串 句 龜 ")
window_name := string_to_string16("Have a wonderful day!")
w := WNDCLASSW{ w := WNDCLASSW{
lpfnWndProc = window_procedure, lpfnWndProc = window_procedure,
hInstance = hInstance, hInstance = hInstance,
@@ -165,7 +165,7 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
window := CreateWindowExW( window := CreateWindowExW(
dwExStyle = 0, hWndParent = 0, hMenu = 0, lpParam = 0, dwExStyle = 0, hWndParent = 0, hMenu = 0, lpParam = 0,
X = CW_USEDEFAULT, Y = CW_USEDEFAULT, nWidth = CW_USEDEFAULT, nHeight = CW_USEDEFAULT, X = CW_USEDEFAULT, Y = CW_USEDEFAULT, nWidth = 1280, nHeight = 720,
lpClassName = window_name.str, lpClassName = window_name.str,
lpWindowName = window_name.str, lpWindowName = window_name.str,
dwStyle = WS_OVERLAPPEDWINDOW, dwStyle = WS_OVERLAPPEDWINDOW,
@@ -174,9 +174,18 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
assert(window != 0) assert(window != 0)
ShowWindow(window, nShowCmd) ShowWindow(window, nShowCmd)
window_dc := GetDC(window)
bitmap := create_bitmap({1280, 720})
for app_is_running for app_is_running
msg: MSG msg: MSG
for PeekMessageW(&msg, window, 0, 0, PM_REMOVE) > 0 for PeekMessageW(&msg, window, 0, 0, PM_REMOVE) > 0
TranslateMessage(&msg) TranslateMessage(&msg)
DispatchMessageW(&msg) DispatchMessageW(&msg)
for y := 0, y < bitmap.size.y, y+=1
for x := 0, x < bitmap.size.x, x+=1
bitmap.data[x + y*bitmap.size.x] = 0xFFFF0000
SelectObject(bitmap.hdc, bitmap.dib)
BitBlt(window_dc, 0, 0, (bitmap.size.x)->int, (bitmap.size.y)->int, bitmap.hdc, 0, 0, SRCCOPY)