diff --git a/.gitignore b/.gitignore index 82e5be2..610f050 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.4c *.bin *.rdbg +start.bat *.c backup* diff --git a/core_main.cpp b/core_main.cpp index 3f5cd4b..5053c4d 100644 --- a/core_main.cpp +++ b/core_main.cpp @@ -9,6 +9,7 @@ In the future - [ ] Cleanup - [ ] Remove tuple stuff or cleanup, in the future might replace it with a better implementation + - [ ] Add ability to do i: int = 0 inside for loops - [ ] Conditional compilation - [ ] Expand macros diff --git a/examples/drawing_to_screen_using_windows_api.core b/examples/drawing_to_screen_using_windows_api.core index 184e89d..700cdb4 100644 --- a/examples/drawing_to_screen_using_windows_api.core +++ b/examples/drawing_to_screen_using_windows_api.core @@ -1,36 +1,41 @@ #import "Base.core" #import "Arena.core" -#import "Windows.core" #import "KERNEL32.core" #import "GDI32.core" #import "USER32.core" -#import "WINMM.core" -Vec2I :: struct;; x: S64; y: S64 +WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nShowCmd: int): int + screen_size_x: int = 1280 + screen_size_y: int = 720 -AppIsRunning := true -Windows_Bitmap :: struct - size: Vec2I - data: *U32 - hdc: HDC - dib: HBITMAP + arena: Arena + window_name := StringToString16(&arena, "Have a wonderful day!") + w := WNDCLASSW{ + lpfnWndProc = WindowProc, + hInstance = hInstance, + lpszClassName = window_name.str, + } + Assert(RegisterClassW(&w) != 0) -Bitmap :: struct - size: Vec2I - data: *U32 - -CreateBitmap :: (size: Vec2I, bottom_up: Bool = true): Windows_Bitmap - result: Windows_Bitmap = {size = size} - if bottom_up == false - result.size.y = -result.size.y + window := CreateWindowExW( + dwExStyle = 0, hWndParent = 0, hMenu = 0, lpParam = 0, + X = CW_USEDEFAULT, Y = CW_USEDEFAULT, nWidth = screen_size_x, nHeight = screen_size_y, + lpClassName = window_name.str, + lpWindowName = window_name.str, + dwStyle = WS_OVERLAPPEDWINDOW, + hInstance = hInstance + ) + Assert(window != 0) + ShowWindow(window, nShowCmd) + window_dc := GetDC(window) header_size: U32 = SizeOf(BITMAPINFOHEADER) Assert(header_size == 40) bminfo := BITMAPINFO{ BITMAPINFOHEADER{ biSize = header_size, - biWidth = size.x->LONG, - biHeight = size.y->LONG, + biWidth = screen_size_x->LONG, + biHeight = screen_size_y->LONG, biPlanes = 1, biBitCount = 32, biCompression = BI_RGB, @@ -39,46 +44,9 @@ CreateBitmap :: (size: Vec2I, bottom_up: Bool = true): Windows_Bitmap } } - hdc := GetDC(0) - result.dib = CreateDIBSection(hdc, &bminfo, DIB_RGB_COLORS, (&result.data)->**void, 0, 0) - result.hdc = CreateCompatibleDC(hdc) - return result - -WindowProc :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT - if msg == WM_DESTROY - PostQuitMessage(0) - AppIsRunning = false - return 0 - else;; return DefWindowProcW(hwnd, msg, wparam, lparam) - -WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nShowCmd: int): int - if good_scheduling := false, timeBeginPeriod(1) == TIMERR_NOERROR - good_scheduling = true - - arena: Arena - - window_name := StringToString16(&arena, "Have a wonderful day! 你好世界 ") - w := WNDCLASSW{ - lpfnWndProc = WindowProc, - hInstance = hInstance, - lpszClassName = window_name.str, - } - Assert(RegisterClassW(&w) != 0) - - screen_size: Vec2I = {1280, 720} - window := CreateWindowExW( - dwExStyle = 0, hWndParent = 0, hMenu = 0, lpParam = 0, - X = CW_USEDEFAULT, Y = CW_USEDEFAULT, nWidth = screen_size.x->int, nHeight = screen_size.y->int, - lpClassName = window_name.str, - lpWindowName = window_name.str, - dwStyle = WS_OVERLAPPEDWINDOW, - hInstance = hInstance - ) - Assert(window != 0) - ShowWindow(window, nShowCmd) - - window_dc := GetDC(window) - bitmap := CreateBitmap(screen_size) + pixels: *U32 + bitmap_dib := CreateDIBSection(window_dc, &bminfo, DIB_RGB_COLORS, (&pixels)->**void, 0, 0) + bitmap_hdc := CreateCompatibleDC(window_dc) for AppIsRunning msg: MSG @@ -86,14 +54,23 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS TranslateMessage(&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 + for y := 0->int, y < screen_size_y, y+=1 + for x := 0->int, x < screen_size_x, x+=1 + pixels[x + y*screen_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) + SelectObject(bitmap_hdc, bitmap_dib) + BitBlt(window_dc, 0, 0, screen_size_x, screen_size_y, bitmap_hdc, 0, 0, SRCCOPY) Sleep(100) if CStringCompare(lpCmdLine, "testing") return 0 return 0 + + +AppIsRunning := true +WindowProc :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT + if msg == WM_DESTROY + PostQuitMessage(0) + AppIsRunning = false + return 0 + else;; return DefWindowProcW(hwnd, msg, wparam, lparam) \ No newline at end of file diff --git a/modules/Base.core b/modules/Base.core index 862b8bf..a793969 100644 --- a/modules/Base.core +++ b/modules/Base.core @@ -18,6 +18,11 @@ AlignUp :: (size: SizeU, align: SizeU): SizeU result := size + GetAlignOffset(size, align) return result +ZeroMemory :: (p: *void, size: SizeU) + pcast := p->*U8 + for i := 0->SizeU, i < size, i++ + pcast[i] = 0 + // // Unicode // diff --git a/modules/GDI32.core b/modules/GDI32.core index ae1dcde..f7e5807 100644 --- a/modules/GDI32.core +++ b/modules/GDI32.core @@ -36,4 +36,6 @@ WHITENESS :: 0x00FF0062 /* dest = WHITE */ CreateDIBSection :: #foreign (hdc: HDC, pbmi: *BITMAPINFO, usage: UINT, ppvBits: **VOID, hSection: HANDLE, offset: DWORD): HBITMAP 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 \ No newline at end of file +BitBlt :: #foreign (hdc: HDC, x: int, y: int, cx: int, cy: int, hdcSrc: HDC, x1: int, y1: int, ro: DWORD): BOOL +DeleteDC :: #foreign (hdc: HDC): BOOL +DeleteObject :: #foreign (ho : HGDIOBJ): BOOL \ No newline at end of file