From 0ad448f1c71da7bc522012a894f02c9864e448d6 Mon Sep 17 00:00:00 2001 From: hikari Date: Sat, 30 Apr 2022 11:21:37 +0300 Subject: [PATCH 1/4] sys/windows: add a couple of procedures and types --- core/image/common.odin | 2 +- core/sys/windows/gdi32.odin | 5 +++++ core/sys/windows/types.odin | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/image/common.odin b/core/image/common.odin index 8c77ec48a..9955f0ee1 100644 --- a/core/image/common.odin +++ b/core/image/common.odin @@ -1131,4 +1131,4 @@ write_bytes :: proc(buf: ^bytes.Buffer, data: []u8) -> (err: compress.General_Er return compress.General_Error.Resize_Failed } return nil -} \ No newline at end of file +} diff --git a/core/sys/windows/gdi32.odin b/core/sys/windows/gdi32.odin index 15d5567c7..8c686f2dc 100644 --- a/core/sys/windows/gdi32.odin +++ b/core/sys/windows/gdi32.odin @@ -62,5 +62,10 @@ foreign gdi32 { ChoosePixelFormat :: proc(hdc: HDC, ppfd: ^PIXELFORMATDESCRIPTOR) -> c_int --- SwapBuffers :: proc(HDC) -> BOOL --- + SetDCBrushColor :: proc(hdc: HDC, color: COLORREF) -> COLORREF --- PatBlt :: proc(hdc: HDC, x, y, w, h: c_int, rop: DWORD) -> BOOL --- } + +RGB :: proc(r, g, b: u8) -> COLORREF { + return COLORREF(COLORREF(r) | COLORREF(g) << 8 | COLORREF(b) << 16) +} diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index 6bded29e1..4093fd3f9 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -55,6 +55,8 @@ UINT_PTR :: uintptr ULONG :: c_ulong UCHAR :: BYTE NTSTATUS :: c.long +COLORREF :: DWORD +LPCOLORREF :: ^COLORREF LPARAM :: LONG_PTR WPARAM :: UINT_PTR LRESULT :: LONG_PTR From 40bea95fb0c1f561f2bb53c967c698823c8c951b Mon Sep 17 00:00:00 2001 From: hikari Date: Sat, 30 Apr 2022 12:41:04 +0300 Subject: [PATCH 2/4] sys/windows: add GetDCBrushColor --- core/sys/windows/gdi32.odin | 1 + 1 file changed, 1 insertion(+) diff --git a/core/sys/windows/gdi32.odin b/core/sys/windows/gdi32.odin index 8c686f2dc..eb863b586 100644 --- a/core/sys/windows/gdi32.odin +++ b/core/sys/windows/gdi32.odin @@ -63,6 +63,7 @@ foreign gdi32 { SwapBuffers :: proc(HDC) -> BOOL --- SetDCBrushColor :: proc(hdc: HDC, color: COLORREF) -> COLORREF --- + GetDCBrushColor :: proc(hdc: HDC) -> COLORREF --- PatBlt :: proc(hdc: HDC, x, y, w, h: c_int, rop: DWORD) -> BOOL --- } From 8c7f3fd1e6f9b04da2b01e25bd7a5dee6feeee28 Mon Sep 17 00:00:00 2001 From: hikari Date: Sat, 30 Apr 2022 13:34:11 +0300 Subject: [PATCH 3/4] sys/windows: change macro and add comment --- core/sys/windows/gdi32.odin | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/sys/windows/gdi32.odin b/core/sys/windows/gdi32.odin index eb863b586..bec5225a7 100644 --- a/core/sys/windows/gdi32.odin +++ b/core/sys/windows/gdi32.odin @@ -67,6 +67,8 @@ foreign gdi32 { PatBlt :: proc(hdc: HDC, x, y, w, h: c_int, rop: DWORD) -> BOOL --- } -RGB :: proc(r, g, b: u8) -> COLORREF { - return COLORREF(COLORREF(r) | COLORREF(g) << 8 | COLORREF(b) << 16) +// Windows colors are packed as ABGR +RGB :: #force_inline proc "contextless" (r, g, b: u8) -> COLORREF { + res: [4]u8 = {0, rgb.b, rgb.g, rgb.r} + return transmute(COLORREF)res } From d2bac0c35e8f7c2347b6bd3763d64de6e902494b Mon Sep 17 00:00:00 2001 From: hikari Date: Sat, 30 Apr 2022 13:40:38 +0300 Subject: [PATCH 4/4] sys/windows: fix build issues --- core/sys/windows/gdi32.odin | 2 +- core/sys/windows/types.odin | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/sys/windows/gdi32.odin b/core/sys/windows/gdi32.odin index bec5225a7..e728503d2 100644 --- a/core/sys/windows/gdi32.odin +++ b/core/sys/windows/gdi32.odin @@ -69,6 +69,6 @@ foreign gdi32 { // Windows colors are packed as ABGR RGB :: #force_inline proc "contextless" (r, g, b: u8) -> COLORREF { - res: [4]u8 = {0, rgb.b, rgb.g, rgb.r} + res: [4]u8 = {0, b, g, r} return transmute(COLORREF)res } diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index 4093fd3f9..c3e461ba0 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -55,7 +55,7 @@ UINT_PTR :: uintptr ULONG :: c_ulong UCHAR :: BYTE NTSTATUS :: c.long -COLORREF :: DWORD +COLORREF :: DWORD // Windows colors are packed as ABGR LPCOLORREF :: ^COLORREF LPARAM :: LONG_PTR WPARAM :: UINT_PTR