Add borderless-win32-odin, lua-dylib-odin
This commit is contained in:
parent
54d7bf4267
commit
654367a6d5
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.exe
|
167
borderless-win32-odin/main.odin
Normal file
167
borderless-win32-odin/main.odin
Normal file
@ -0,0 +1,167 @@
|
||||
package borderless_win
|
||||
|
||||
import "core:os"
|
||||
import win32 "core:sys/windows"
|
||||
|
||||
// foreign import win32ex "system:User32.lib"
|
||||
// @(default_calling_convention="stdcall")
|
||||
// foreign win32ex {
|
||||
// IsZoomed :: proc (hwnd: win32.HWND) -> win32.BOOL ---
|
||||
// }
|
||||
// IsMaximized :: IsZoomed
|
||||
|
||||
WM_NCUAHDRAWCAPTION :: (0x00AE)
|
||||
WM_NCUAHDRAWFRAME :: (0x00AF)
|
||||
|
||||
UserData := struct {
|
||||
dwm_enabled: win32.BOOL,
|
||||
width: i32,
|
||||
height: i32,
|
||||
} {
|
||||
dwm_enabled = false,
|
||||
width = 0,
|
||||
height = 0,
|
||||
}
|
||||
|
||||
handle_nchittest :: proc "stdcall" (hwnd: win32.HWND, lparam: win32.LPARAM) -> win32.LRESULT {
|
||||
// if IsMaximized(hwnd) do return win32.HTCLIENT
|
||||
mouse := win32.POINT{win32.GET_X_LPARAM(lparam), win32.GET_Y_LPARAM(lparam)}
|
||||
win32.ScreenToClient(hwnd, &mouse)
|
||||
frame_size :=
|
||||
win32.GetSystemMetrics(win32.SM_CXFRAME) + win32.GetSystemMetrics(win32.SM_CXPADDEDBORDER)
|
||||
diagonal_width := frame_size * 2 + win32.GetSystemMetrics(win32.SM_CXBORDER)
|
||||
|
||||
if mouse.y < frame_size {
|
||||
if mouse.x < diagonal_width do return win32.HTTOPLEFT
|
||||
if mouse.x >= UserData.width - diagonal_width do return win32.HTTOPRIGHT
|
||||
return win32.HTTOP
|
||||
}
|
||||
|
||||
if mouse.y >= UserData.height - frame_size {
|
||||
if mouse.x < diagonal_width do return win32.HTBOTTOMLEFT
|
||||
if mouse.x >= UserData.width - diagonal_width do return win32.HTBOTTOMRIGHT
|
||||
return win32.HTBOTTOM
|
||||
}
|
||||
|
||||
if mouse.x < frame_size do return win32.HTLEFT
|
||||
if mouse.x >= UserData.width - frame_size do return win32.HTRIGHT
|
||||
return win32.HTCLIENT
|
||||
}
|
||||
|
||||
handle_windowposchanged :: proc "stdcall" (
|
||||
hwnd: win32.HWND,
|
||||
pos: ^win32.WINDOWPOS,
|
||||
) -> win32.LRESULT {
|
||||
client: win32.RECT
|
||||
win32.GetClientRect(hwnd, &client)
|
||||
last_width, last_height := UserData.width, UserData.height
|
||||
UserData.width, UserData.height = client.right, client.bottom
|
||||
client_changed := UserData.width != last_width || UserData.height != last_height
|
||||
|
||||
if client_changed {
|
||||
if UserData.width > last_width do win32.InvalidateRect(hwnd, &(win32.RECT){last_width - 1, 0, last_width, last_height}, true)
|
||||
else do win32.InvalidateRect(hwnd,&(win32.RECT){UserData.width - 1, 0, UserData.width, UserData.height}, true)
|
||||
if UserData.height > last_height do win32.InvalidateRect(hwnd, &(win32.RECT){0, last_height - 1, last_width, last_height}, true)
|
||||
else do win32.InvalidateRect(hwnd, &(win32.RECT){0, UserData.height - 1, UserData.width, UserData.height}, true)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
handle_dwmcompositionchanged :: proc "stdcall" (hwnd: win32.HWND) {
|
||||
enabled: win32.BOOL = false
|
||||
win32.DwmIsCompositionEnabled(&enabled)
|
||||
UserData.dwm_enabled = enabled
|
||||
if enabled {
|
||||
win32.DwmSetWindowAttribute(
|
||||
hwnd,
|
||||
u32(win32.DWMWINDOWATTRIBUTE.DWMWA_NCRENDERING_POLICY),
|
||||
rawptr(uintptr(win32.DWORD(win32.DWMNCRENDERINGPOLICY.DWMNCRP_ENABLED))),
|
||||
size_of(win32.DWORD),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
handle_win32_events :: proc "stdcall" (
|
||||
hwnd: win32.HWND,
|
||||
msg: win32.UINT,
|
||||
wparam: win32.WPARAM,
|
||||
lparam: win32.LPARAM,
|
||||
) -> win32.LRESULT {
|
||||
switch msg {
|
||||
case win32.WM_CLOSE:
|
||||
win32.DestroyWindow(hwnd)
|
||||
return 0
|
||||
case win32.WM_DESTROY:
|
||||
win32.PostQuitMessage(0)
|
||||
return 0
|
||||
case win32.WM_PAINT:
|
||||
ps: win32.PAINTSTRUCT
|
||||
hdc := win32.BeginPaint(hwnd, &ps)
|
||||
win32.FillRect(hdc, &ps.rcPaint, win32.HBRUSH(win32.COLOR_BACKGROUND + uintptr(1)))
|
||||
win32.EndPaint(hwnd, &ps)
|
||||
return 0
|
||||
case win32.WM_NCACTIVATE:
|
||||
return win32.DefWindowProcW(hwnd, msg, wparam, -1)
|
||||
case win32.WM_NCHITTEST:
|
||||
return handle_nchittest(hwnd, lparam)
|
||||
case win32.WM_WINDOWPOSCHANGED:
|
||||
return handle_windowposchanged(hwnd, transmute(^win32.WINDOWPOS)(lparam))
|
||||
case win32.WM_NCCALCSIZE:
|
||||
return 0
|
||||
case win32.WM_NCPAINT:
|
||||
if !UserData.dwm_enabled do return 0
|
||||
case win32.WM_LBUTTONDOWN:
|
||||
win32.ReleaseCapture()
|
||||
win32.SendMessageW(hwnd, win32.WM_NCLBUTTONDOWN, win32.HTCAPTION, 0)
|
||||
case win32.WM_DWMCOMPOSITIONCHANGED:
|
||||
handle_dwmcompositionchanged(hwnd)
|
||||
return 0
|
||||
case WM_NCUAHDRAWCAPTION:
|
||||
return 0
|
||||
case WM_NCUAHDRAWFRAME:
|
||||
return 0
|
||||
}
|
||||
return win32.DefWindowProcW(hwnd, msg, wparam, lparam)
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
hinstance := win32.HINSTANCE(win32.GetModuleHandleW(nil))
|
||||
|
||||
cid := win32.RegisterClassExW(
|
||||
&(win32.WNDCLASSEXW) {
|
||||
cbSize = size_of(win32.WNDCLASSEXW),
|
||||
hInstance = hinstance,
|
||||
hbrBackground = win32.HBRUSH(win32.COLOR_WINDOW + uintptr(1)),
|
||||
lpszClassName = win32.utf8_to_wstring("OdinBorderlessWindow"),
|
||||
hCursor = win32.LoadCursorA(nil, win32.IDC_ARROW),
|
||||
lpfnWndProc = handle_win32_events,
|
||||
},
|
||||
)
|
||||
|
||||
hwnd := win32.CreateWindowExW(
|
||||
0,
|
||||
win32.LPCWSTR(uintptr(cid)),
|
||||
win32.utf8_to_wstring("Borderless Window"),
|
||||
win32.WS_OVERLAPPEDWINDOW | win32.WS_SIZEBOX,
|
||||
win32.CW_USEDEFAULT,
|
||||
win32.CW_USEDEFAULT,
|
||||
win32.CW_USEDEFAULT,
|
||||
win32.CW_USEDEFAULT,
|
||||
nil,
|
||||
nil,
|
||||
hinstance,
|
||||
nil,
|
||||
)
|
||||
handle_dwmcompositionchanged(hwnd)
|
||||
win32.ShowWindow(hwnd, win32.SW_SHOWNORMAL)
|
||||
win32.UpdateWindow(hwnd)
|
||||
|
||||
message: win32.MSG
|
||||
for win32.GetMessageW(&message, nil, 0, 0) != 0 {
|
||||
win32.TranslateMessage(&message)
|
||||
win32.DispatchMessageW(&message)
|
||||
}
|
||||
|
||||
win32.UnregisterClassW(win32.LPCWSTR(uintptr(cid)), hinstance)
|
||||
os.exit(int(message.wParam))
|
||||
}
|
@ -6,18 +6,18 @@ node :: struct($Value: typeid) {
|
||||
next: ^node(Value),
|
||||
}
|
||||
|
||||
to_string :: proc(head: ^node($T)) -> string {
|
||||
to_string :: proc(head: ^node($T), trunc_after: int = 8) -> string {
|
||||
curr := head
|
||||
out: string
|
||||
counter := 0
|
||||
out = fmt.tprintf("[%v]", curr.data)
|
||||
out = fmt.aprintf("[%v]", curr.data)
|
||||
for curr.next != nil{
|
||||
curr = curr.next
|
||||
if counter >= 8 {
|
||||
out = fmt.tprintf("%s -> ... -> [%v]", out, tail(curr.next))
|
||||
if trunc_after > 0 && counter >= trunc_after {
|
||||
out = fmt.aprintf("%s -> ... -> [%v]", out, tail(curr.next))
|
||||
break
|
||||
}
|
||||
out = fmt.tprintf("%s -> [%v]", out, curr.data)
|
||||
out = fmt.aprintf("%s -> [%v]", out, curr.data)
|
||||
counter += 1
|
||||
}
|
||||
|
||||
|
3
lua-dylib-odin/.gitignore
vendored
Normal file
3
lua-dylib-odin/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
args.dll
|
||||
args.exp
|
||||
args.lib
|
2
lua-dylib-odin/build.bat
Normal file
2
lua-dylib-odin/build.bat
Normal file
@ -0,0 +1,2 @@
|
||||
odin build . -build-mode:dll -out:args.dll
|
||||
lua test.lua
|
34
lua-dylib-odin/main.odin
Normal file
34
lua-dylib-odin/main.odin
Normal file
@ -0,0 +1,34 @@
|
||||
package args
|
||||
|
||||
import "base:runtime"
|
||||
import "core:fmt"
|
||||
|
||||
LUA_SHARED :: true
|
||||
import lua "vendor:lua/5.4"
|
||||
|
||||
lua_print_arg_count :: lua.L_Reg {
|
||||
name = "printargcount",
|
||||
func = lua_print_arg_count_proc,
|
||||
}
|
||||
|
||||
lua_print_arg_count_proc :: proc "c" (L: ^lua.State) -> i32 {
|
||||
context = runtime.default_context()
|
||||
top := lua.gettop(L)
|
||||
if top > 0 {
|
||||
fmt.println(top, "arguments were passed to the function", lua_print_arg_count.name)
|
||||
} else {
|
||||
fmt.println("no arguments were passed to the function", lua_print_arg_count.name)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
procs :: []lua.L_Reg{lua_print_arg_count, {nil, nil}}
|
||||
|
||||
@(export)
|
||||
luaopen_args :: proc(L: ^lua.State) -> i32 {
|
||||
lua.L_checkversion(L)
|
||||
lua.L_newlib(L, procs)
|
||||
lua.pushinteger(L, 8008135)
|
||||
lua.setfield(L, -2, "version")
|
||||
return 1
|
||||
}
|
4
lua-dylib-odin/test.lua
Normal file
4
lua-dylib-odin/test.lua
Normal file
@ -0,0 +1,4 @@
|
||||
local a = require'args'
|
||||
print('version', a.version)
|
||||
print('printargcount(1,2,3):')
|
||||
a.printargcount(1,2,3)
|
Loading…
Reference in New Issue
Block a user