GBAlatro
A Demake of Balatro for the GBA
Loading...
Searching...
No Matches
button.c
1#include "button.h"
2
3#include "audio_utils.h"
4#include "soundbank.h"
5
6#include <tonc.h>
7
8void button_set_highlight(Button* button, bool highlight)
9{
10 if (button == NULL)
11 return;
12
13 u16 set_color = highlight ? BTN_HIGHLIGHT_COLOR : pal_bg_mem[button->button_pal_idx];
14
15 memset16(&pal_bg_mem[button->border_pal_idx], set_color, 1);
16}
17
18void button_press(Button* button)
19{
20 if (button == NULL || button->on_pressed == NULL ||
21 (button->can_be_pressed != NULL && !button->can_be_pressed()))
22 {
23 return;
24 }
25
26 play_sfx(SFX_BUTTON, MM_BASE_PITCH_RATE, BUTTON_SFX_VOLUME);
27
28 button->on_pressed();
29}
Utilities for using maxmod to play sound effects.
#define MM_BASE_PITCH_RATE
The default pitch rate for the sound effect played.
Definition audio_utils.h:37
void play_sfx(mm_word id, mm_word rate, mm_byte volume)
Play a sound effect, wrapper for mmEffectEx() See https://maxmod.org/ref/functions/mm_sound_effect....
A button structure containing the common button functionalities Including highlight and pressing func...
void button_press(Button *button)
Execute a button press, by calling the button's on_pressed function. This checks the button's can_be_...
Definition button.c:18
void button_set_highlight(Button *button, bool highlight)
Set the button highlight on or off.
Definition button.c:8
A button representation.
Definition button.h:31
ButtonOnPressedFunc on_pressed
Called when the button is pressed if can_be_pressed, don't call this directly, call button_press() in...
Definition button.h:50
u8 button_pal_idx
Palette index of the color of the button itself, used for the border when not highlighted.
Definition button.h:43
u8 border_pal_idx
Palette index of the button border whose color is updated depending on highlight.
Definition button.h:37
ButtonCanBePressedFunc can_be_pressed
Returns true if the button should be activated when pressed. Can be NULL if button can always be pres...
Definition button.h:56