Skip to content

Commit

Permalink
Implement MUSIALIZER_ACT_ON_PRESS feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim committed May 8, 2024
1 parent 070b88c commit c848672
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions nob.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ void generate_default_config(Nob_String_Builder *content)
nob_sb_append_cstr(content, "\n");
nob_sb_append_cstr(content, "//// Unfinished feature that enables capturing sound from the mic.\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_MICROPHONE\n");
nob_sb_append_cstr(content, "\n");
nob_sb_append_cstr(content, "//// Activate UI buttons on Press instead of Release just as John Carmack explained https://twitter.com/ID_AA_Carmack/status/1787850053912064005\n");
nob_sb_append_cstr(content, "// #define MUSIALIZER_ACT_ON_PRESS\n");
}

int main(int argc, char **argv)
Expand Down
8 changes: 7 additions & 1 deletion src/plug.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ typedef struct {
float out_smooth[FFT_SIZE];
float out_smear[FFT_SIZE];

#ifndef MUSIALIZER_ACT_ON_PRESS
uint64_t active_button_id;
#endif // MUSIALIZER_ACT_ON_PRESS

Popup_Tray pt;

Expand Down Expand Up @@ -690,8 +692,9 @@ static int button_with_id(uint64_t id, Rectangle boundary)
{
Vector2 mouse = GetMousePosition();
int hoverover = CheckCollisionPointRec(mouse, boundary);
int clicked = 0;

#ifndef MUSIALIZER_ACT_ON_PRESS
int clicked = 0;
if (p->active_button_id == 0) {
if (hoverover && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
p->active_button_id = id;
Expand All @@ -702,6 +705,9 @@ static int button_with_id(uint64_t id, Rectangle boundary)
if (hoverover) clicked = 1;
}
}
#else
int clicked = hoverover && IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
#endif // MUSIALIZER_ACT_ON_PRESS

return (clicked<<1) | hoverover;
}
Expand Down

0 comments on commit c848672

Please sign in to comment.