first commit
This commit is contained in:
48
src/game/ecs/component/ui/component_button.c
Normal file
48
src/game/ecs/component/ui/component_button.c
Normal file
@ -0,0 +1,48 @@
|
||||
#include "component_button.h"
|
||||
|
||||
void
|
||||
component_button_add(ComponentButton* self, ECS* ecs)
|
||||
{
|
||||
for (s32 i = 0; i < COMPONENT_BUTTON_DEPENDENCY_COUNT; i++)
|
||||
ecs_component_add(ecs, COMPONENT_BUTTON_DEPENDENCIES[i], self->component.id);
|
||||
}
|
||||
|
||||
void
|
||||
component_button_tick(ComponentButton* self, ECS* ecs)
|
||||
{
|
||||
ComponentTextureQuad* textureQuad;
|
||||
vec2 mousePosition;
|
||||
Rectangle rectangle;
|
||||
|
||||
textureQuad = ecs_component_get(ecs, COMPONENT_TEXTURE_QUAD, self->component.id);
|
||||
|
||||
mouse_buffer_position_get(&ecs->input->mouse, textureQuad->buffer, ecs->renderer, mousePosition);
|
||||
|
||||
component_texture_quad_rectangle_get(textureQuad, &rectangle);
|
||||
|
||||
if (rectangle_has_point(&rectangle, mousePosition))
|
||||
{
|
||||
self->state = BUTTON_STATE_HOVER;
|
||||
|
||||
glm_vec4_copy((f32*)COMPONENT_BUTTON_STATE_HOVER_COLOR, textureQuad->color);
|
||||
|
||||
if (control_held(ecs->control, CONTROL_ACTION_PRIMARY))
|
||||
{
|
||||
if (self->state != BUTTON_STATE_PRESSED)
|
||||
{
|
||||
self->isJustPressed = true;
|
||||
sound_play(&ecs->resources->sounds[SOUND_SELECT]);
|
||||
}
|
||||
else
|
||||
self->isJustPressed = false;
|
||||
|
||||
glm_vec4_copy((f32*)COMPONENT_BUTTON_STATE_PRESSED_COLOR, textureQuad->color);
|
||||
self->state = BUTTON_STATE_PRESSED;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
glm_vec4_copy((f32*)COMPONENT_BUTTON_STATE_NONE_COLOR, textureQuad->color);
|
||||
self->state = BUTTON_STATE_NONE;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user