Last active
June 22, 2026 05:40
-
-
Save Lightnet/44090467158a1e1b22fc710932ea84cc to your computer and use it in GitHub Desktop.
sample transparent window image test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // zig 0.16.0 | |
| const rl = @import("raylib"); // https://github.com/raylib-zig/raylib-zig | |
| const std = @import("std"); | |
| pub fn main() !void { | |
| // Set configuration flags BEFORE initializing the window | |
| rl.setConfigFlags(.{ | |
| .window_undecorated = true, | |
| .window_transparent = true, | |
| .window_topmost = true, | |
| }); | |
| const screenWidth = 800; | |
| const screenHeight = 450; | |
| rl.initWindow(screenWidth, screenHeight, "raylib-zig transparent window"); | |
| defer rl.closeWindow(); | |
| // 1. Load the PNG texture from your assets path | |
| const catTexture = try rl.loadTexture("assets/4-1.png"); | |
| defer rl.unloadTexture(catTexture); | |
| // State variables for tracking the drag action | |
| const dragPosition = rl.Vector2{ .x = 100, .y = 100 }; | |
| var isDragging = false; | |
| var mouseOffset = rl.Vector2{ .x = 0, .y = 0 }; | |
| rl.setTargetFPS(60); | |
| while (!rl.windowShouldClose()) { | |
| // --- 1. DRAG LOGIC --- | |
| const mousePos = rl.getMousePosition(); | |
| // Define the clickable bounding box where your pet is drawn | |
| const petHitbox = rl.Rectangle{ | |
| .x = dragPosition.x, | |
| .y = dragPosition.y, | |
| .width = @floatFromInt(catTexture.width), | |
| .height = @floatFromInt(catTexture.height), | |
| }; | |
| if (rl.isMouseButtonPressed(.left)) { | |
| // Check if player clicked directly inside the pet's boundaries | |
| if (rl.checkCollisionPointRec(mousePos, petHitbox)) { | |
| isDragging = true; | |
| // Save where inside the sprite the user clicked to prevent jumping | |
| mouseOffset = mousePos; | |
| } | |
| } | |
| if (isDragging) { | |
| if (rl.isMouseButtonDown(.left)) { | |
| // Get the current overall window position on your monitor | |
| const windowPos = rl.getWindowPosition(); | |
| // Calculate how much the mouse moved inside the window frame | |
| const deltaX = mousePos.x - mouseOffset.x; | |
| const deltaY = mousePos.y - mouseOffset.y; | |
| // Move the actual operating system window on your monitor screen | |
| rl.setWindowPosition(@intFromFloat(windowPos.x + deltaX), @intFromFloat(windowPos.y + deltaY)); | |
| } else { | |
| isDragging = false; | |
| } | |
| } | |
| // --- 2. RENDERING --- | |
| rl.beginDrawing(); | |
| defer rl.endDrawing(); | |
| rl.clearBackground(.blank); | |
| // Draw the texture at your tracked structural drag coordinates | |
| rl.drawTexture(catTexture, @intFromFloat(dragPosition.x), @intFromFloat(dragPosition.y), .white); | |
| rl.drawText("Click and drag the pet to move the window!", 190, 200, 20, .light_gray); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment