Skip to content

Feature Request: Mouse Event Handlers #15

Description

@Natuworkguy

This issue proposes adding dedicated mouse event handlers to the ABS Engine entity lifecycle system, specifically hover and click events exposed through clearly named class constants.

Proposed Event Constants

The following constants should be added to the event naming convention:

  • L_CLICKED -- left mouse button click
  • MIDDLE_CLICKED -- middle mouse button click
  • R_CLICKED -- right mouse button click
  • MOUSE_HOVERED -- mouse cursor is positioned over the entity's rectangle

Motivation

Currently, the event lifecycle function on entity scripts receives raw Pygame events. Detecting whether the mouse is interacting with a specific entity requires the script author to manually check mouse position against the entity's rect and filter event types by hand. This is repetitive boilerplate that every interactive entity ends up duplicating.

Adding first-class mouse event constants would:

  • Reduce boilerplate. Script authors could check for L_CLICKED or MOUSE_HOVERED the same way they handle any other engine event, without writing manual rect-vs-position hit tests.
  • Improve consistency. The naming convention mirrors the existing event system and gives mouse interactions a predictable, discoverable API.
  • Lower the barrier for new developers. Someone building their first interactive entity should not need to know the internals of Pygame's mouse event system. A clear, engine-level abstraction makes the engine friendlier to use.
  • Enable cleaner entity scripts. Scripts stay focused on game logic rather than input plumbing, which aligns with the intent of the three-function lifecycle design (init, update, event).

Implementation Notes

  • Hover detection can use the existing rect system. Each tick, the scene (or the entity's internal update_rect step) can check whether the mouse position falls within the entity's rect and fire MOUSE_HOVERED accordingly.
  • Click detection can be handled inside the event propagation path. When a Pygame mouse button event is received, the engine checks whether the cursor is within the entity's rect before dispatching L_CLICKED, MIDDLE_CLICKED, or R_CLICKED to that entity's event function.
  • This keeps all hit-testing logic inside the engine and out of user scripts.

Acceptance Criteria

  • L_CLICKED, MIDDLE_CLICKED, and R_CLICKED fire on the correct mouse button press when the cursor is within the entity's rect
  • MOUSE_HOVERED fires each tick the cursor is within the entity's rect
  • Events are delivered through the existing event lifecycle function
  • No external dependencies are introduced

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions