mirror of
https://github.com/cellos51/balatro-gba.git
synced 2026-04-22 23:34:06 -05:00
* Added wrapping to selection grid * Added return value to on_selection_changed to allow aborting on wrap * Extracted button code to button.c/.h * Bounds checking changes for selection_grid_move_selection_horz() --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Rickey <ric@rf3.xyz>
76 lines
2.0 KiB
C
76 lines
2.0 KiB
C
/**
|
|
* @file button.h
|
|
*
|
|
* @brief A button structure containing the common button functionalities
|
|
*/
|
|
|
|
#ifndef BUTTON_H
|
|
#define BUTTON_H
|
|
|
|
#include <tonc_types.h>
|
|
|
|
#define BTN_HIGHLIGHT_COLOR 0xFFFF
|
|
|
|
#define BUTTON_SFX_VOLUME 154 // 60% of MM_FULL_VOLUME
|
|
|
|
/**
|
|
* @brief The function to be called when the button is pressed
|
|
*/
|
|
typedef void (*ButtonOnPressedFunc)(void);
|
|
|
|
/**
|
|
* @brief Returns true if the button should be activated when pressed.
|
|
*/
|
|
typedef bool (*ButtonCanBePressedFunc)(void);
|
|
|
|
/**
|
|
* @brief A button representation
|
|
*/
|
|
typedef struct
|
|
{
|
|
// Using u8 for the palette indices to make sure they don't overflow pal_bg_mem
|
|
|
|
/**
|
|
* @brief Palette index of the button border whose color is updated depending on highlight.
|
|
*/
|
|
u8 border_pal_idx;
|
|
|
|
/**
|
|
* @brief Palette index of the color of the button itself, used for the border when not
|
|
* highlighted.
|
|
*/
|
|
u8 button_pal_idx;
|
|
|
|
/**
|
|
* @brief Called when the button is pressed if @ref can_be_pressed, don't call this directly,
|
|
* call @ref button_press() instead.
|
|
* Should not be set to NULL.
|
|
*/
|
|
ButtonOnPressedFunc on_pressed;
|
|
|
|
/**
|
|
* @brief Returns true if the button should be activated when pressed.
|
|
* Can be NULL if button can always be pressed.
|
|
*/
|
|
ButtonCanBePressedFunc can_be_pressed;
|
|
} Button;
|
|
|
|
/**
|
|
* @brief Set the button highlight on or off.
|
|
* @param button The button to modify. No-op on NULL.
|
|
* @param highlight true to highlight, false to unhighlight.
|
|
*/
|
|
void button_set_highlight(Button* button, bool highlight);
|
|
|
|
/**
|
|
* @brief Execute a button press, by calling the button's @ref on_pressed function.
|
|
* This checks the button's @ref can_be_pressed function and will do nothing if
|
|
* returns false.
|
|
*
|
|
* Button presses should go through this function rather than directly call @ref on_pressed.
|
|
*
|
|
* @param button The button being pressed. No-op on NULL.
|
|
*/
|
|
void button_press(Button* button);
|
|
|
|
#endif // BUTTON_H
|