Mouse

micro::mouse tracks per-frame button state, cursor position, and scroll wheel input. Attach one to a window and query it in your game loop.

Setup

micro::window win{"Input demo", 800, 600};
micro::mouse  mouse{win};

win.run([&](float dt) {
    if (mouse.is_button_pressed(micro::mouse_button::left)) {
        fire_at(mouse.position());
    }
});

Querying button state

bool is_button_down    (mouse_button b) const noexcept;
bool is_button_up      (mouse_button b) const noexcept;
bool is_button_pressed (mouse_button b) const noexcept;
bool is_button_released(mouse_button b) const noexcept;

Buttons

enum class mouse_button : uint8_t {
    left,    // primary button
    middle,  // scroll wheel click
    right,   // secondary button
    x1,      // extra back button
    x2,      // extra forward button
};

Cursor position

[[nodiscard]] pointf position() const noexcept;

Returns the cursor position in window coordinates. When the renderer has a logical size, convert with renderer::to_logical() before comparing to game objects:

auto logical_pos = rend.to_logical(mouse.position());

Scroll wheel

[[nodiscard]] point wheel() const noexcept;

Returns the accumulated scroll delta for the current frame. Resets to zero at the start of each new frame.

  • wheel().x — horizontal scroll, positive = right
  • wheel().y — vertical scroll, positive = away from user (scroll up)
camera.zoom += mouse.wheel().y * zoom_speed;