Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/actions/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ int main()
asw::display::present();
}

asw::core::cleanup();
asw::core::shutdown();

return 0;
}
2 changes: 1 addition & 1 deletion examples/controller/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ int main()
asw::display::present();
}

asw::core::cleanup();
asw::core::shutdown();

return 0;
}
10 changes: 6 additions & 4 deletions examples/keyboard/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ int main()
while (!asw::core::is_exiting()) {
asw::core::update();

const auto& keyboard = asw::input::get_keyboard();

// --- Movement (held) ---
if (asw::input::get_key(asw::input::Key::W) || asw::input::get_key(asw::input::Key::Up)) {
pos.y -= speed;
Expand Down Expand Up @@ -68,15 +70,15 @@ int main()
}

// --- Text input ---
if (!asw::input::text_input.empty()) {
asw::log::info("Text input: {}", asw::input::text_input);
if (!asw::input::get_text_input().empty()) {
asw::log::info("Text input: {}", asw::input::get_text_input());
}

// --- Draw ---
asw::display::clear(asw::color::darkslategray);

// Box - turns cyan when any key is held
const bool any_held = asw::input::keyboard.any_pressed;
const bool any_held = keyboard.any_pressed;
asw::draw::rect_fill(
{ pos, { box_size, box_size } }, any_held ? asw::color::cyan : asw::color::white);
asw::draw::rect({ pos, { box_size, box_size } }, asw::color::gray);
Expand All @@ -99,7 +101,7 @@ int main()
asw::display::present();
}

asw::core::cleanup();
asw::core::shutdown();

return 0;
}
23 changes: 12 additions & 11 deletions examples/mouse/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// @brief Mouse input example
///
/// Demonstrates:
/// - Reading mouse position and delta via asw::input::mouse
/// - Reading mouse position and delta via mouse
/// - Polling buttons with get_mouse_button_down() / get_mouse_button_up() / get_mouse_button()
/// - Scroll wheel via mouse.z
/// - Changing cursor style with set_cursor()
Expand All @@ -28,27 +28,28 @@ int main()

while (!asw::core::is_exiting()) {
asw::core::update();
const auto& mouse = asw::input::get_mouse();

// --- Button events ---
if (asw::input::get_mouse_button_down(asw::input::MouseButton::Left)) {
circle_color = asw::color::red;
asw::log::info("Left button pressed at ({:.0f}, {:.0f})", asw::input::mouse.position.x,
asw::input::mouse.position.y);
asw::log::info(
"Left button pressed at ({:.0f}, {:.0f})", mouse.position.x, mouse.position.y);
}
if (asw::input::get_mouse_button_down(asw::input::MouseButton::Right)) {
circle_color = asw::color::blue;
asw::log::info("Right button pressed at ({:.0f}, {:.0f})", asw::input::mouse.position.x,
asw::input::mouse.position.y);
asw::log::info(
"Right button pressed at ({:.0f}, {:.0f})", mouse.position.x, mouse.position.y);
}
if (asw::input::get_mouse_button_up(asw::input::MouseButton::Left)
|| asw::input::get_mouse_button_up(asw::input::MouseButton::Right)) {
circle_color = asw::color::white;
}

// --- Scroll wheel ---
if (asw::input::mouse.z != 0.0F) {
radius = std::clamp(radius + asw::input::mouse.z * 5.0F, 5.0F, 150.0F);
asw::log::info("Scroll: {:.1f} radius: {:.0f}", asw::input::mouse.z, radius);
if (mouse.z != 0.0F) {
radius = std::clamp(radius + mouse.z * 5.0F, 5.0F, 150.0F);
asw::log::info("Scroll: {:.1f} radius: {:.0f}", mouse.z, radius);
}

// --- Cursor style based on button held ---
Expand All @@ -67,7 +68,7 @@ int main()
// --- Draw ---
asw::display::clear(asw::color::darkslategray);

const auto& mp = asw::input::mouse.position;
const auto& mp = mouse.position;

// Crosshair lines
const auto win = asw::display::get_logical_size();
Expand All @@ -79,7 +80,7 @@ int main()
asw::draw::circle(mp, radius, asw::color::white);

// Delta indicator (shows mouse movement direction)
const auto& delta = asw::input::mouse.change;
const auto& delta = mouse.change;
if (delta.x != 0.0F || delta.y != 0.0F) {
asw::draw::line(
mp, { mp.x + delta.x * 10.0F, mp.y + delta.y * 10.0F }, asw::color::yellow);
Expand All @@ -103,7 +104,7 @@ int main()
asw::display::present();
}

asw::core::cleanup();
asw::core::shutdown();

return 0;
}
2 changes: 1 addition & 1 deletion examples/primitives/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int main()
asw::display::present();
}

asw::core::cleanup();
asw::core::shutdown();

return 0;
}
2 changes: 1 addition & 1 deletion include/asw/modules/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool is_exiting();

/// @brief Cleanup resources used by the core module. Should be called on application exit.
///
void cleanup();
void shutdown();

} // namespace asw::core

Expand Down
28 changes: 24 additions & 4 deletions include/asw/modules/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,31 @@

namespace asw::display {

/// @brief The renderer for the display module.
extern asw::Renderer* renderer;
/// @brief Initialize the display module. Called by asw::core::init().
///
/// @param width The logical width of the display.
/// @param height The logical height of the display.
/// @param scale The initial window scale factor.
///
void _init(int width, int height, int scale);

/// @brief The window for the display module.
extern asw::Window* window;
/// @brief Shut down the display module. Called by asw::core::shutdown().
/// Nulls the renderer and window pointers before destroying them, so any
/// outstanding shared_ptr asset deleters see a null renderer and become no-ops.
///
void _shutdown();

/// @brief Get the SDL renderer.
///
/// @return Pointer to the SDL_Renderer, or nullptr if not initialized.
///
asw::Renderer* get_renderer();

/// @brief Get the SDL window.
///
/// @return Pointer to the SDL_Window, or nullptr if not initialized.
///
asw::Window* get_window();

/// @brief Set the title of the window.
///
Expand Down
23 changes: 17 additions & 6 deletions include/asw/modules/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,11 @@ using MouseState = struct MouseState {
std::array<bool, NUM_MOUSE_BUTTONS> down { false };
};

/// @brief Global mouse state.
extern MouseState mouse;
/// @brief Get the current mouse state.
///
/// @return Const reference to the current MouseState.
///
const MouseState& get_mouse();

/// @brief Check if a mouse button is down.
///
Expand Down Expand Up @@ -354,9 +357,11 @@ using KeyState = struct KeyState {
int last_pressed { -1 };
};

/// @brief Global keyboard state.
/// @brief Get the current keyboard state.
///
/// @return Const reference to the current KeyState.
///
extern KeyState keyboard;
const KeyState& get_keyboard();

/// @brief Check if a key is down.
///
Expand Down Expand Up @@ -474,14 +479,20 @@ int get_controller_count();
/// @brief Get the name of a controller.
std::string get_controller_name(uint32_t index);

/// @brief Text input received this frame.
extern std::string text_input;
/// @brief Get the text input received this frame.
///
/// @return Const reference to the text input string.
///
const std::string& get_text_input();

/// @brief Reset all input states. Called by the core.
void reset();

/// Event Hooks

/// @brief Append text to this frame's text input. Called by the core.
void _append_text(const char* text);

/// @brief Key down hook
void _key_down(SDL_Scancode scancode);

Expand Down
Loading
Loading