Skip to content

Commit

Permalink
fix: intro segfault & button mouse detection
Browse files Browse the repository at this point in the history
  • Loading branch information
zoogies committed Dec 21, 2024
1 parent ac19874 commit 122e1ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 198,6 @@ sometime in the future we should make it so clicking on overstacked ents will cy

LAST FINAL BEFORE TAR:

- change button bounds to check inside true computed location
- change audiosource to check inside true computed location
- debug intro cutscene
- change audiosource to check inside true computed location and test it (not playing at all rn)
- etc
16 changes: 7 additions & 9 deletions engine/src/ecs/button.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 53,17 @@ void ye_system_button(SDL_Event event){
struct ye_entity *entity = itr->entity;
struct ye_component_button *button = entity->button;

// if the button is inactive, skip it
if(!button->active)
// if inactive, skip it
if(!button->active || !entity->active) {
itr = itr->next;
continue;
}

// get the position of the button
struct ye_rectf pos = ye_get_position(entity, YE_COMPONENT_BUTTON);
struct ye_point_rectf pos = ye_get_position2(entity, YE_COMPONENT_BUTTON);

// check if the mouse is hovering over the button
if(
mouseX >= pos.x && mouseX <= pos.x pos.w && // within width
mouseY >= pos.y && mouseY <= pos.y pos.h // within height
)
{
if(ye_pointf_in_point_rectf((struct ye_pointf){mouseX, mouseY}, pos)) {
// if within the bounds, we are hovering
button->is_hovered = true;

Expand All @@ -82,7 80,7 @@ void ye_system_button(SDL_Event event){
// update was_pressed for the next run
button->_was_pressed = button->is_pressed;
}
else{
else {
button->is_hovered = false;
button->is_pressed = false;
button->is_clicked = false;
Expand Down
2 changes: 1 addition & 1 deletion engine/src/ecs/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 828,7 @@ void ye_renderer_v2(SDL_Renderer *renderer) {
Shift matrix to transfer from "local" to "world" space
*/
mat3_t world_matrix = lla_mat3_identity();
if(rend->relative) {
if(rend->relative && trans) {
world_matrix = lla_mat3_translate(world_matrix, (vec2_t){.data = {trans->x, trans->y}}); // apply transform if it's relative to it
}
world_matrix = lla_mat3_translate(world_matrix, (vec2_t){.data = {rend->rect.x, rend->rect.y}}); // always offset renderer pos
Expand Down

0 comments on commit 122e1ec

Please sign in to comment.