Gama C Library
Gama C API Documentation
joystick.h File Reference

Defines the theme and functionality for a virtual joystick widget. More...

#include "../animate.h"
#include "../draw.h"

Go to the source code of this file.

Data Structures

struct  gmwJoystickTheme
 Structure defining the visual theme for a joystick widget. More...

Functions

int gm_joystick_anim (double x, double y, double radius, gmPos *pos, gmPos *vpos)
 Creates and renders an animated joystick widget that can be manipulated with the mouse.
int gmw_joystick (double x, double y, double radius, gmPos *pos)
 Creates and renders a joystick widget that can be manipulated with the mouse (non-animated version).

Variables

gmwJoystickTheme gmwJoystick
 Global joystick theme instance with default values.

Detailed Description

Defines the theme and functionality for a virtual joystick widget.

This file provides structures for customizing the appearance of an on-screen joystick and a function to render an interactive joystick that responds to mouse input, outputting its normalized position.

Function Documentation

◆ gm_joystick_anim()

int gm_joystick_anim ( double x,
double y,
double radius,
gmPos * pos,
gmPos * vpos )

Creates and renders an animated joystick widget that can be manipulated with the mouse.

This function draws a virtual joystick on screen, tracks mouse interaction, and outputs its normalized logical position. The visual knob position is animated smoothly.

Parameters
xThe x-coordinate of the joystick's center.
yThe y-coordinate of the joystick's center.
radiusThe radius of the joystick base circle.
posPointer to a gmPos structure to store the joystick's logical position (normalized to -1.0 to 1.0 in X and Y).
vposPointer to a gmPos structure for the animated visual knob position. If NULL, pos is used for both logical and visual position.
Returns
1 if the joystick is currently hovered over, 0 otherwise.

◆ gmw_joystick()

int gmw_joystick ( double x,
double y,
double radius,
gmPos * pos )

Creates and renders a joystick widget that can be manipulated with the mouse (non-animated version).

This is a simplified wrapper around gm_joystick_anim that does not use a separate visual position for animation, making the knob snap to position.

Parameters
xThe x-coordinate of the joystick's center.
yThe y-coordinate of the joystick's center.
radiusThe radius of the joystick base.
posPointer to a gmPos structure to store the joystick's logical position (normalized to -1.0 to 1.0 in X and Y).
Returns
1 if the joystick is currently hovered over, 0 otherwise.

Variable Documentation

◆ gmwJoystick

gmwJoystickTheme gmwJoystick
Initial value:
= {
.enabled = 1,
.scale = 1.0,
.background = 0x3A2A3AE0,
.border = 0x7F4F7FFF,
.focussed = {.scale = 1.05, .border = 0xAA77AAFF},
.active = {.scale = 0.95, .border = 0x7F4F7FFF},
.knob = 0xAA77AAFF,
.knob_border = 0x6F3F6FFF,
.border_width = 0.01}

Global joystick theme instance with default values.