Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc + update slang #137

Merged
merged 2 commits into from
Dec 9, 2024
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 external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ set(SGL_LOCAL_SLANG OFF CACHE BOOL "Use a local build of slang instead of downlo
set(SGL_LOCAL_SLANG_DIR "${CMAKE_SOURCE_DIR}/../slang" CACHE PATH "Path to a local slang build")
set(SGL_LOCAL_SLANG_BUILD_DIR "build/Debug" CACHE STRING "Build directory of the local slang build")

set(SLANG_VERSION "2024.15.1")
set(SLANG_VERSION "2024.15.2")
set(SLANG_URL_BASE "https://github.com/shader-slang/slang/releases/download/v${SLANG_VERSION}")

if(SGL_WINDOWS)
Expand Down
20 changes: 20 additions & 0 deletions src/sgl/core/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@

namespace sgl {

/// Mouse cursor modes.
enum class CursorMode : uint32_t {
/// The cursor is visible and behaves normally.
normal,
/// The cursor is hidden when over the window.
hidden,
/// The cursor is hidden and locked to the window.
disabled,
};

SGL_ENUM_INFO(
CursorMode,
{
{CursorMode::normal, "normal"},
{CursorMode::hidden, "hidden"},
{CursorMode::disabled, "disabled"},
}
);
SGL_ENUM_REGISTER(CursorMode);

/// Mouse buttons.
enum class MouseButton : uint32_t {
left,
Expand Down
1 change: 1 addition & 0 deletions src/sgl/core/python/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SGL_PY_EXPORT(core_input)
{
using namespace sgl;

nb::sgl_enum<CursorMode>(m, "CursorMode", D_NA(CursorMode));
nb::sgl_enum<MouseButton>(m, "MouseButton", D(MouseButton));
nb::sgl_enum<KeyModifierFlags>(m, "KeyModifierFlags", D(KeyModifierFlags));
nb::sgl_enum<KeyModifier>(m, "KeyModifier", D(KeyModifier));
Expand Down
1 change: 1 addition & 0 deletions src/sgl/core/python/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ SGL_PY_EXPORT(core_window)
window.def("process_events", &Window::process_events, D(Window, process_events));
window.def("set_clipboard", &Window::set_clipboard, "text"_a, D(Window, set_clipboard));
window.def("get_clipboard", &Window::get_clipboard, D(Window, get_clipboard));
window.def_prop_rw("cursor_mode", &Window::cursor_mode, &Window::set_cursor_mode, D_NA(Window, cursor_mode));

window.def_prop_rw("on_resize", &Window::on_resize, &Window::set_on_resize, nb::arg().none(), D(Window, on_resize));
window.def_prop_rw(
Expand Down
20 changes: 20 additions & 0 deletions src/sgl/core/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,26 @@ std::optional<std::string> Window::get_clipboard() const
return text ? std::optional<std::string>(text) : std::nullopt;
}

void Window::set_cursor_mode(CursorMode mode)
{
if (mode != m_cursor_mode) {
m_cursor_mode = mode;
switch (mode) {
case CursorMode::normal:
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
break;
case CursorMode::hidden:
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
break;
case CursorMode::disabled:
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
break;
default:
SGL_UNREACHABLE();
}
}
}

std::string Window::to_string() const
{
return fmt::format(
Expand Down
5 changes: 5 additions & 0 deletions src/sgl/core/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class SGL_API Window : public Object {
/// Get the clipboard content.
std::optional<std::string> get_clipboard() const;

/// The mouse cursor mode.
CursorMode cursor_mode() const { return m_cursor_mode; }
void set_cursor_mode(CursorMode mode);

// events

using ResizeCallback = std::function<void(uint32_t /* width */, uint32_t /* height */)>;
Expand Down Expand Up @@ -152,6 +156,7 @@ class SGL_API Window : public Object {

bool m_should_close{false};

CursorMode m_cursor_mode{CursorMode::normal};
float2 m_mouse_pos{0.f, 0.f};
KeyModifierFlags m_mods{KeyModifierFlags::none};

Expand Down
Loading