Gama C Library
Gama C API Documentation
Loading...
Searching...
No Matches
frame.h
Go to the documentation of this file.
1#pragma once
2
3#include "../collision.h"
4#include "../draw.h"
5
6/**
7 * @brief Structure defining the visual theme for a frame widget.
8 */
9typedef struct {
10 int enabled; /**< Whether the frame is enabled */
11
12 gmColor background; /**< Background color when normal */
13 gmColor border; /**< Border color when normal */
14 double scale; /**< Scale factor when normal */
15
16 struct {
17 gmColor background; /**< Background color when focused */
18 gmColor border; /**< Border color when focused */
19 double scale; /**< Scale factor when focused */
20 } focussed;
21
22 struct {
23 gmColor background; /**< Background color when inactive */
24 gmColor border; /**< Border color when inactive */
25 double scale; /**< Scale factor when inactive */
26 } inactive;
27
28 double border_width; /**< Width of the frame border */
30
31/**
32 * @brief Global frame theme instance with default values.
33 */
34gmwFrameTheme gmwFrame = {.enabled = 1,
35
36 // Normal (semi-transparent overlay)
37 .background = 0x2A1E2AE0, // dark purple, ~88% alpha
38 .border = 0xAA77AAAF,
39 .scale = 1.0,
40
41 // Focused (menu panel highlighted)
42 .focussed =
43 {
44 .background = 0x3A2A3AE8,
45 .border = 0xBA87BAAF,
46 .scale = 1.01,
47 },
48
49 // Inactive (background panels)
50 .inactive =
51 {
52 .background = 0x201820C8,
53 .border = 0x6F4F6FAF,
54 .scale = 1.0,
55 },
56
57 .border_width = 0.015};
58
59/**
60 * @brief Creates and renders a frame widget (a bordered panel).
61 * @param x The x-coordinate of the frame's center.
62 * @param y The y-coordinate of the frame's center.
63 * @param width The width of the frame.
64 * @param height The height of the frame.
65 * @return 1 if the frame is currently hovered, 0 otherwise.
66 */
67int gmw_frame(double x, double y, double width, double height) {
68 int enabled = gmwFrame.enabled;
69 int hovered = enabled && gm_mouse_in_rect(x, y, width, height);
70
71 double scale = hovered ? gmwFrame.focussed.scale : gmwFrame.scale;
72
73 gmColor bg = hovered ? gmwFrame.focussed.background : gmwFrame.background;
74
75 gmColor border = hovered ? gmwFrame.focussed.border : gmwFrame.border;
76
77 double sw = width * scale;
78 double sh = height * scale;
79
80 // Border (centered, square)
81 gm_draw_rectangle(x, y, sw + gmwFrame.border_width * 2,
82 sh + gmwFrame.border_width * 2, border);
83
84 // Background (semi-transparent)
85 gm_draw_rectangle(x, y, sw, sh, bg);
86 return hovered;
87}
int gm_mouse_in_rect(const double x, const double y, const double w, const double h)
Definition collision.h:102
unsigned int gmColor
Type definition for color values in RGBA format.
Definition color.h:8
Functions for drawing shapes, text, and images.
int32_t gm_draw_rectangle(double x, double y, double w, double h, gmColor c)
Draws a rectangle.
Definition draw.h:47
gmwFrameTheme gmwFrame
Global frame theme instance with default values.
Definition frame.h:34
int gmw_frame(double x, double y, double width, double height)
Creates and renders a frame widget (a bordered panel).
Definition frame.h:67
Structure defining the visual theme for a frame widget.
Definition frame.h:9
double scale
Definition frame.h:14
int enabled
Definition frame.h:10
double border_width
Definition frame.h:28
gmColor background
Definition frame.h:12
gmColor border
Definition frame.h:13