1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| #include "raylib.h"
int main() { SetConfigFlags(FLAG_WINDOW_TRANSPARENT | FLAG_WINDOW_UNDECORATED | FLAG_WINDOW_TOPMOST); InitWindow(400, 400, "Desktop Widget");
Texture2D img = LoadTexture("bronyaMoe.png"); Shader maskShader = LoadShader(0, "mask.fs");
float roundness = 0.1f; int roundLoc = GetShaderLocation(maskShader, "roundness"); SetShaderValue(maskShader, roundLoc, &roundness, SHADER_UNIFORM_FLOAT);
Vector2 dragOffset = { 0, 0 }; bool isDragging = false;
SetTargetFPS(60);
while (!WindowShouldClose()) { if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { if (CheckCollisionPointRec(GetMousePosition(), Rectangle{ 0, 0, (float)GetScreenWidth(), (float)GetScreenHeight() })) { isDragging = true; dragOffset = GetMousePosition(); } }
if (isDragging) { Vector2 mousePos = GetWindowPosition(); Vector2 delta = GetMousePosition(); SetWindowPosition((int)(mousePos.x + (delta.x - dragOffset.x)), (int)(mousePos.y + (delta.y - dragOffset.y)));
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) isDragging = false; }
BeginDrawing(); ClearBackground(BLANK);
BeginShaderMode(maskShader); DrawTexturePro(img, Rectangle{ 0, 0, (float)img.width, (float)img.height }, Rectangle{ 0, 0, (float)GetScreenWidth(), (float)GetScreenHeight() }, Vector2{ 0, 0 }, 0.0f, WHITE); EndShaderMode();
if (CheckCollisionPointRec(GetMousePosition(), Rectangle{ 0, 0, (float)GetScreenWidth(), (float)GetScreenHeight() })) { DrawRectangleRoundedLines(Rectangle{ 0, 0, (float)GetScreenWidth(), (float)GetScreenHeight() }, 0.1f, 16, SKYBLUE); }
EndDrawing(); }
UnloadTexture(img); UnloadShader(maskShader); CloseWindow();
return 0; }
|