|
| 1 | +/******************************************************************************************* |
| 2 | +* |
| 3 | +* raylib [raygui] example - Basic window |
| 4 | +* |
| 5 | +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) |
| 6 | +* |
| 7 | +* Copyright (c) 2022 Rob Loach (@RobLoach) |
| 8 | +* |
| 9 | +********************************************************************************************/ |
| 10 | + |
| 11 | +const r = require('raylib') |
| 12 | + |
| 13 | +// Initialization |
| 14 | +// -------------------------------------------------------------------------------------- |
| 15 | +const screenWidth = 800 |
| 16 | +const screenHeight = 450 |
| 17 | +let showMessageBox = false |
| 18 | +let backgroundColor = r.RAYWHITE |
| 19 | + |
| 20 | +r.InitWindow(screenWidth, screenHeight, 'raylib [raygui] example - basic window') |
| 21 | + |
| 22 | +r.SetTargetFPS(60) |
| 23 | + |
| 24 | +// r.GuiLoadStyleDefault() |
| 25 | +// -------------------------------------------------------------------------------------- |
| 26 | + |
| 27 | +// Main game loop |
| 28 | +while (!r.WindowShouldClose()) { // Detect window close button or ESC key |
| 29 | + // Update |
| 30 | + // ---------------------------------------------------------------------------------- |
| 31 | + // TODO: Update your variables here |
| 32 | + // ---------------------------------------------------------------------------------- |
| 33 | + |
| 34 | + // Draw |
| 35 | + // ---------------------------------------------------------------------------------- |
| 36 | + r.BeginDrawing() |
| 37 | + |
| 38 | + r.ClearBackground(backgroundColor) |
| 39 | + |
| 40 | + if (r.GuiButton(r.Rectangle(30, 100, 200, 30), 'Change Background Color')) { |
| 41 | + showMessageBox = true |
| 42 | + } |
| 43 | + |
| 44 | + if (showMessageBox) { |
| 45 | + switch (r.GuiMessageBox(r.Rectangle(r.GetScreenWidth() / 2 - 200, r.GetScreenHeight() / 2 - 50, 400, 100), 'Change Background Color', 'Do you really want to change the background?', 'Yes;No')) { |
| 46 | + case 0: |
| 47 | + case 2: |
| 48 | + showMessageBox = false |
| 49 | + break |
| 50 | + case 1: // Yes |
| 51 | + backgroundColor = r.Color( |
| 52 | + r.GetRandomValue(0, 255), |
| 53 | + r.GetRandomValue(0, 255), |
| 54 | + r.GetRandomValue(0, 255), |
| 55 | + 255 |
| 56 | + ) |
| 57 | + showMessageBox = false |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + r.EndDrawing() |
| 62 | + // ---------------------------------------------------------------------------------- |
| 63 | +} |
| 64 | + |
| 65 | +// De-Initialization |
| 66 | +// -------------------------------------------------------------------------------------- |
| 67 | +r.CloseWindow() // Close window and OpenGL context |
| 68 | +// -------------------------------------------------------------------------------------- |
0 commit comments