From 1c365945ed2ebd5b9f54eb0c8c5c1c6d97cad712 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 2 Jan 2021 21:09:27 +0100 Subject: Simplify clang-format configuration and format all code --- bindings/cxx/include/pugl/cairo.hpp | 2 +- bindings/cxx/include/pugl/gl.hpp | 8 +- bindings/cxx/include/pugl/pugl.hpp | 858 +++++++++++++++++------------------ bindings/cxx/include/pugl/stub.hpp | 2 +- bindings/cxx/include/pugl/vulkan.hpp | 120 ++--- 5 files changed, 485 insertions(+), 505 deletions(-) (limited to 'bindings') diff --git a/bindings/cxx/include/pugl/cairo.hpp b/bindings/cxx/include/pugl/cairo.hpp index 7416589..126bfe3 100644 --- a/bindings/cxx/include/pugl/cairo.hpp +++ b/bindings/cxx/include/pugl/cairo.hpp @@ -33,7 +33,7 @@ namespace pugl { inline const PuglBackend* cairoBackend() noexcept { - return puglCairoBackend(); + return puglCairoBackend(); } /** diff --git a/bindings/cxx/include/pugl/gl.hpp b/bindings/cxx/include/pugl/gl.hpp index d8459a8..c845d80 100644 --- a/bindings/cxx/include/pugl/gl.hpp +++ b/bindings/cxx/include/pugl/gl.hpp @@ -37,28 +37,28 @@ using GlFunc = PuglGlFunc; inline GlFunc getProcAddress(const char* name) noexcept { - return puglGetProcAddress(name); + return puglGetProcAddress(name); } /// @copydoc puglEnterContext inline Status enterContext(View& view) noexcept { - return static_cast(puglEnterContext(view.cobj())); + return static_cast(puglEnterContext(view.cobj())); } /// @copydoc puglLeaveContext inline Status leaveContext(View& view) noexcept { - return static_cast(puglLeaveContext(view.cobj())); + return static_cast(puglLeaveContext(view.cobj())); } /// @copydoc puglGlBackend inline const PuglBackend* glBackend() noexcept { - return puglGlBackend(); + return puglGlBackend(); } /** diff --git a/bindings/cxx/include/pugl/pugl.hpp b/bindings/cxx/include/pugl/pugl.hpp index 1a07734..9e65589 100644 --- a/bindings/cxx/include/pugl/pugl.hpp +++ b/bindings/cxx/include/pugl/pugl.hpp @@ -22,9 +22,9 @@ #include #if defined(PUGL_HPP_THROW_FAILED_CONSTRUCTION) -# include +# include #elif defined(PUGL_HPP_ASSERT_CONSTRUCTION) -# include +# include #endif namespace pugl { @@ -46,34 +46,34 @@ template Free> class Wrapper { public: - Wrapper(const Wrapper&) = delete; - Wrapper& operator=(const Wrapper&) = delete; + Wrapper(const Wrapper&) = delete; + Wrapper& operator=(const Wrapper&) = delete; - Wrapper(Wrapper&& wrapper) noexcept - : _ptr{wrapper._ptr} - { - wrapper._ptr = nullptr; - } + Wrapper(Wrapper&& wrapper) noexcept + : _ptr{wrapper._ptr} + { + wrapper._ptr = nullptr; + } - Wrapper& operator=(Wrapper&& wrapper) noexcept - { - _ptr = wrapper._ptr; - wrapper._ptr = nullptr; - return *this; - } + Wrapper& operator=(Wrapper&& wrapper) noexcept + { + _ptr = wrapper._ptr; + wrapper._ptr = nullptr; + return *this; + } - ~Wrapper() noexcept { Free(_ptr); } + ~Wrapper() noexcept { Free(_ptr); } - T* cobj() noexcept { return _ptr; } - const T* cobj() const noexcept { return _ptr; } + T* cobj() noexcept { return _ptr; } + const T* cobj() const noexcept { return _ptr; } protected: - explicit Wrapper(T* ptr) noexcept - : _ptr{ptr} - {} + explicit Wrapper(T* ptr) noexcept + : _ptr{ptr} + {} private: - T* _ptr; + T* _ptr; }; } // namespace detail @@ -97,11 +97,11 @@ using Rect = PuglRect; ///< @copydoc PuglRect */ template struct Event final : Base { - /// The type of the corresponding C event structure - using BaseEvent = Base; + /// The type of the corresponding C event structure + using BaseEvent = Base; - /// The `type` field of the corresponding C event structure - static constexpr const PuglEventType type = t; + /// The `type` field of the corresponding C event structure + static constexpr const PuglEventType type = t; }; using Mod = PuglMod; ///< @copydoc PuglMod @@ -189,18 +189,18 @@ using LoopLeaveEvent = Event; /// @copydoc PuglStatus enum class Status { - success, ///< @copydoc PUGL_SUCCESS - failure, ///< @copydoc PUGL_FAILURE - unknownError, ///< @copydoc PUGL_UNKNOWN_ERROR - badBackend, ///< @copydoc PUGL_BAD_BACKEND - badConfiguration, ///< @copydoc PUGL_BAD_CONFIGURATION - badParameter, ///< @copydoc PUGL_BAD_PARAMETER - backendFailed, ///< @copydoc PUGL_BACKEND_FAILED - registrationFailed, ///< @copydoc PUGL_REGISTRATION_FAILED - realizeFailed, ///< @copydoc PUGL_REALIZE_FAILED - setFormatFailed, ///< @copydoc PUGL_SET_FORMAT_FAILED - createContextFailed, ///< @copydoc PUGL_CREATE_CONTEXT_FAILED - unsupportedType, ///< @copydoc PUGL_UNSUPPORTED_TYPE + success, ///< @copydoc PUGL_SUCCESS + failure, ///< @copydoc PUGL_FAILURE + unknownError, ///< @copydoc PUGL_UNKNOWN_ERROR + badBackend, ///< @copydoc PUGL_BAD_BACKEND + badConfiguration, ///< @copydoc PUGL_BAD_CONFIGURATION + badParameter, ///< @copydoc PUGL_BAD_PARAMETER + backendFailed, ///< @copydoc PUGL_BACKEND_FAILED + registrationFailed, ///< @copydoc PUGL_REGISTRATION_FAILED + realizeFailed, ///< @copydoc PUGL_REALIZE_FAILED + setFormatFailed, ///< @copydoc PUGL_SET_FORMAT_FAILED + createContextFailed, ///< @copydoc PUGL_CREATE_CONTEXT_FAILED + unsupportedType, ///< @copydoc PUGL_UNSUPPORTED_TYPE }; static_assert(Status(PUGL_UNSUPPORTED_TYPE) == Status::unsupportedType, ""); @@ -209,7 +209,7 @@ static_assert(Status(PUGL_UNSUPPORTED_TYPE) == Status::unsupportedType, ""); inline const char* strerror(const Status status) noexcept { - return puglStrerror(static_cast(status)); + return puglStrerror(static_cast(status)); } /** @@ -220,15 +220,15 @@ strerror(const Status status) noexcept /// @copydoc PuglWorldType enum class WorldType { - program, ///< @copydoc PUGL_PROGRAM - module, ///< @copydoc PUGL_MODULE + program, ///< @copydoc PUGL_PROGRAM + module, ///< @copydoc PUGL_MODULE }; static_assert(WorldType(PUGL_MODULE) == WorldType::module, ""); /// @copydoc PuglWorldFlag enum class WorldFlag { - threads = PUGL_WORLD_THREADS, ///< @copydoc PUGL_WORLD_THREADS + threads = PUGL_WORLD_THREADS, ///< @copydoc PUGL_WORLD_THREADS }; static_assert(WorldFlag(PUGL_WORLD_THREADS) == WorldFlag::threads, ""); @@ -241,25 +241,25 @@ using WorldFlags = PuglWorldFlags; ///< @copydoc PuglWorldFlags class FailedConstructionError : public std::exception { public: - FailedConstructionError(const char* const msg) noexcept - : _msg{msg} - {} + FailedConstructionError(const char* const msg) noexcept + : _msg{msg} + {} - virtual const char* what() const noexcept override; + virtual const char* what() const noexcept override; private: - const char* _msg; + const char* _msg; }; -# define PUGL_CHECK_CONSTRUCTION(cond, msg) \ - do { \ - if (!(cond)) { \ - throw FailedConstructionError(msg); \ - } \ - } while (0) +# define PUGL_CHECK_CONSTRUCTION(cond, msg) \ + do { \ + if (!(cond)) { \ + throw FailedConstructionError(msg); \ + } \ + } while (0) #elif defined(PUGL_HPP_ASSERT_CONSTRUCTION) -# define PUGL_CHECK_CONSTRUCTION(cond, msg) assert(cond); +# define PUGL_CHECK_CONSTRUCTION(cond, msg) assert(cond); #else /** Configurable macro for handling construction failure. @@ -272,55 +272,55 @@ private: Otherwise, this does nothing. */ -# define PUGL_CHECK_CONSTRUCTION(cond, msg) +# define PUGL_CHECK_CONSTRUCTION(cond, msg) #endif /// @copydoc PuglWorld class World : public detail::Wrapper { public: - World(const World&) = delete; - World& operator=(const World&) = delete; - - World(World&&) = delete; - World& operator=(World&&) = delete; - - ~World() = default; - - World(WorldType type, WorldFlag flag) - : Wrapper{puglNewWorld(static_cast(type), - static_cast(flag))} - { - PUGL_CHECK_CONSTRUCTION(cobj(), "Failed to create pugl::World"); - } - - World(WorldType type, WorldFlags flags) - : Wrapper{puglNewWorld(static_cast(type), flags)} - { - PUGL_CHECK_CONSTRUCTION(cobj(), "Failed to create pugl::World"); - } - - explicit World(WorldType type) - : World{type, WorldFlags{}} - {} - - /// @copydoc puglGetNativeWorld - void* nativeWorld() noexcept { return puglGetNativeWorld(cobj()); } - - /// @copydoc puglSetClassName - Status setClassName(const char* const name) noexcept - { - return static_cast(puglSetClassName(cobj(), name)); - } - - /// @copydoc puglGetTime - double time() const noexcept { return puglGetTime(cobj()); } - - /// @copydoc puglUpdate - Status update(const double timeout) noexcept - { - return static_cast(puglUpdate(cobj(), timeout)); - } + World(const World&) = delete; + World& operator=(const World&) = delete; + + World(World&&) = delete; + World& operator=(World&&) = delete; + + ~World() = default; + + World(WorldType type, WorldFlag flag) + : Wrapper{puglNewWorld(static_cast(type), + static_cast(flag))} + { + PUGL_CHECK_CONSTRUCTION(cobj(), "Failed to create pugl::World"); + } + + World(WorldType type, WorldFlags flags) + : Wrapper{puglNewWorld(static_cast(type), flags)} + { + PUGL_CHECK_CONSTRUCTION(cobj(), "Failed to create pugl::World"); + } + + explicit World(WorldType type) + : World{type, WorldFlags{}} + {} + + /// @copydoc puglGetNativeWorld + void* nativeWorld() noexcept { return puglGetNativeWorld(cobj()); } + + /// @copydoc puglSetClassName + Status setClassName(const char* const name) noexcept + { + return static_cast(puglSetClassName(cobj(), name)); + } + + /// @copydoc puglGetTime + double time() const noexcept { return puglGetTime(cobj()); } + + /// @copydoc puglUpdate + Status update(const double timeout) noexcept + { + return static_cast(puglUpdate(cobj(), timeout)); + } }; /** @@ -334,22 +334,22 @@ using NativeView = PuglNativeView; ///< @copydoc PuglNativeView /// @copydoc PuglViewHint enum class ViewHint { - useCompatProfile, ///< @copydoc PUGL_USE_COMPAT_PROFILE - useDebugContext, ///< @copydoc PUGL_USE_DEBUG_CONTEXT - contextVersionMajor, ///< @copydoc PUGL_CONTEXT_VERSION_MAJOR - contextVersionMinor, ///< @copydoc PUGL_CONTEXT_VERSION_MINOR - redBits, ///< @copydoc PUGL_RED_BITS - greenBits, ///< @copydoc PUGL_GREEN_BITS - blueBits, ///< @copydoc PUGL_BLUE_BITS - alphaBits, ///< @copydoc PUGL_ALPHA_BITS - depthBits, ///< @copydoc PUGL_DEPTH_BITS - stencilBits, ///< @copydoc PUGL_STENCIL_BITS - samples, ///< @copydoc PUGL_SAMPLES - doubleBuffer, ///< @copydoc PUGL_DOUBLE_BUFFER - swapInterval, ///< @copydoc PUGL_SWAP_INTERVAL - resizable, ///< @copydoc PUGL_RESIZABLE - ignoreKeyRepeat, ///< @copydoc PUGL_IGNORE_KEY_REPEAT - refreshRate, ///< @copydoc PUGL_REFRESH_RATE + useCompatProfile, ///< @copydoc PUGL_USE_COMPAT_PROFILE + useDebugContext, ///< @copydoc PUGL_USE_DEBUG_CONTEXT + contextVersionMajor, ///< @copydoc PUGL_CONTEXT_VERSION_MAJOR + contextVersionMinor, ///< @copydoc PUGL_CONTEXT_VERSION_MINOR + redBits, ///< @copydoc PUGL_RED_BITS + greenBits, ///< @copydoc PUGL_GREEN_BITS + blueBits, ///< @copydoc PUGL_BLUE_BITS + alphaBits, ///< @copydoc PUGL_ALPHA_BITS + depthBits, ///< @copydoc PUGL_DEPTH_BITS + stencilBits, ///< @copydoc PUGL_STENCIL_BITS + samples, ///< @copydoc PUGL_SAMPLES + doubleBuffer, ///< @copydoc PUGL_DOUBLE_BUFFER + swapInterval, ///< @copydoc PUGL_SWAP_INTERVAL + resizable, ///< @copydoc PUGL_RESIZABLE + ignoreKeyRepeat, ///< @copydoc PUGL_IGNORE_KEY_REPEAT + refreshRate, ///< @copydoc PUGL_REFRESH_RATE }; static_assert(ViewHint(PUGL_REFRESH_RATE) == ViewHint::refreshRate, ""); @@ -358,13 +358,13 @@ using ViewHintValue = PuglViewHintValue; ///< @copydoc PuglViewHintValue /// @copydoc PuglCursor enum class Cursor { - arrow, ///< @copydoc PUGL_CURSOR_ARROW - caret, ///< @copydoc PUGL_CURSOR_CARET - crosshair, ///< @copydoc PUGL_CURSOR_CROSSHAIR - hand, ///< @copydoc PUGL_CURSOR_HAND - no, ///< @copydoc PUGL_CURSOR_NO - leftRight, ///< @copydoc PUGL_CURSOR_LEFT_RIGHT - upDown, ///< @copydoc PUGL_CURSOR_UP_DOWN + arrow, ///< @copydoc PUGL_CURSOR_ARROW + caret, ///< @copydoc PUGL_CURSOR_CARET + crosshair, ///< @copydoc PUGL_CURSOR_CROSSHAIR + hand, ///< @copydoc PUGL_CURSOR_HAND + no, ///< @copydoc PUGL_CURSOR_NO + leftRight, ///< @copydoc PUGL_CURSOR_LEFT_RIGHT + upDown, ///< @copydoc PUGL_CURSOR_UP_DOWN }; static_assert(Cursor(PUGL_CURSOR_UP_DOWN) == Cursor::upDown, ""); @@ -373,332 +373,312 @@ static_assert(Cursor(PUGL_CURSOR_UP_DOWN) == Cursor::upDown, ""); class View : protected detail::Wrapper { public: - /** - @name Setup - Methods for creating and destroying a view. - @{ - */ - - explicit View(World& world) - : Wrapper{puglNewView(world.cobj())} - , _world(world) - { - PUGL_CHECK_CONSTRUCTION(cobj(), "Failed to create pugl::View"); - } - - const World& world() const noexcept { return _world; } - World& world() noexcept { return _world; } - - /** - Set the object that will be called to handle events. - - This is a type-safe wrapper for the C functions puglSetHandle() and - puglSetEventFunc() that will automatically dispatch events to the - `onEvent` method of `handler` that takes the appropriate event type. - The handler must have such a method defined for every event type, but if - the handler is the view itself, a `using` declaration can be used to - "inherit" the default implementation to avoid having to define every - method. For example: - - @code - class MyView : public pugl::View - { - public: - explicit MyView(pugl::World& world) - : pugl::View{world} - { - setEventHandler(*this); - } - - using pugl::View::onEvent; - - pugl::Status onEvent(const pugl::ConfigureEvent& event) noexcept; - pugl::Status onEvent(const pugl::ExposeEvent& event) noexcept; - }; - @endcode - - This facility is just a convenience, applications may use the C API - directly to set a handle and event function to set up a different - approach for event handling. - */ - template - Status setEventHandler(Handler& handler) - { - puglSetHandle(cobj(), &handler); - return static_cast( - puglSetEventFunc(cobj(), eventFunc)); - } - - /// @copydoc puglSetBackend - Status setBackend(const PuglBackend* backend) noexcept - { - return static_cast(puglSetBackend(cobj(), backend)); - } - - /// @copydoc puglSetViewHint - Status setHint(ViewHint hint, int value) noexcept - { - return static_cast( - puglSetViewHint(cobj(), static_cast(hint), value)); - } - - /// @copydoc puglGetViewHint - int getHint(ViewHint hint) noexcept - { - return puglGetViewHint(cobj(), static_cast(hint)); - } - - /** - @} - @name Frame - Methods for working with the position and size of a view. - @{ - */ - - /// @copydoc puglGetFrame - Rect frame() const noexcept { return puglGetFrame(cobj()); } - - /// @copydoc puglSetFrame - Status setFrame(Rect frame) noexcept - { - return static_cast(puglSetFrame(cobj(), frame)); - } - - /// @copydoc puglSetDefaultSize - Status setDefaultSize(int width, int height) noexcept - { - return static_cast(puglSetDefaultSize(cobj(), width, height)); - } - - /// @copydoc puglSetMinSize - Status setMinSize(int width, int height) noexcept - { - return static_cast(puglSetMinSize(cobj(), width, height)); - } - - /// @copydoc puglSetMaxSize - Status setMaxSize(int width, int height) noexcept - { - return static_cast(puglSetMaxSize(cobj(), width, height)); - } - - /// @copydoc puglSetAspectRatio - Status setAspectRatio(int minX, int minY, int maxX, int maxY) noexcept - { - return static_cast( - puglSetAspectRatio(cobj(), minX, minY, maxX, maxY)); - } - - /** - @} - @name Windows - Methods for working with top-level windows. - @{ - */ - - /// @copydoc puglSetWindowTitle - Status setWindowTitle(const char* title) noexcept - { - return static_cast(puglSetWindowTitle(cobj(), title)); - } - - /// @copydoc puglSetParentWindow - Status setParentWindow(NativeView parent) noexcept - { - return static_cast(puglSetParentWindow(cobj(), parent)); - } - - /// @copydoc puglSetTransientFor - Status setTransientFor(NativeView parent) noexcept - { - return static_cast(puglSetTransientFor(cobj(), parent)); - } - - /// @copydoc puglRealize - Status realize() noexcept - { - return static_cast(puglRealize(cobj())); - } - - /// @copydoc puglShow - Status show() noexcept - { - return static_cast(puglShow(cobj())); - } - - /// @copydoc puglHide - Status hide() noexcept - { - return static_cast(puglHide(cobj())); - } - - /// @copydoc puglGetVisible - bool visible() const noexcept { return puglGetVisible(cobj()); } - - /// @copydoc puglGetNativeWindow - NativeView nativeWindow() noexcept { return puglGetNativeWindow(cobj()); } - - /** - @} - @name Graphics - Methods for working with the graphics context and scheduling - redisplays. - @{ - */ - - /// @copydoc puglGetContext - void* context() noexcept { return puglGetContext(cobj()); } - - /// @copydoc puglPostRedisplay - Status postRedisplay() noexcept - { - return static_cast(puglPostRedisplay(cobj())); - } - - /// @copydoc puglPostRedisplayRect - Status postRedisplayRect(const Rect rect) noexcept - { - return static_cast(puglPostRedisplayRect(cobj(), rect)); - } - - /** - @} - @name Interaction - Methods for interacting with the user and window system. - @{ - */ - - /// @copydoc puglGrabFocus - Status grabFocus() noexcept - { - return static_cast(puglGrabFocus(cobj())); - } - - /// @copydoc puglHasFocus - bool hasFocus() const noexcept { return puglHasFocus(cobj()); } - - /// @copydoc puglSetCursor - Status setCursor(const Cursor cursor) noexcept - { - return static_cast( - puglSetCursor(cobj(), static_cast(cursor))); - } - - /// @copydoc puglRequestAttention - Status requestAttention() noexcept - { - return static_cast(puglRequestAttention(cobj())); - } - - /// @copydoc puglStartTimer - Status startTimer(const uintptr_t id, const double timeout) noexcept - { - return static_cast(puglStartTimer(cobj(), id, timeout)); - } - - /// @copydoc puglStopTimer - Status stopTimer(const uintptr_t id) noexcept - { - return static_cast(puglStopTimer(cobj(), id)); - } - - /** - @} - */ - - PuglView* cobj() noexcept { return Wrapper::cobj(); } - const PuglView* cobj() const noexcept { return Wrapper::cobj(); } + /** + @name Setup + Methods for creating and destroying a view. + @{ + */ + + explicit View(World& world) + : Wrapper{puglNewView(world.cobj())} + , _world(world) + { + PUGL_CHECK_CONSTRUCTION(cobj(), "Failed to create pugl::View"); + } + + const World& world() const noexcept { return _world; } + World& world() noexcept { return _world; } + + /** + Set the object that will be called to handle events. + + This is a type-safe wrapper for the C functions puglSetHandle() and + puglSetEventFunc() that will automatically dispatch events to the + `onEvent` method of `handler` that takes the appropriate event type. + The handler must have such a method defined for every event type, but if + the handler is the view itself, a `using` declaration can be used to + "inherit" the default implementation to avoid having to define every + method. For example: + + @code + class MyView : public pugl::View + { + public: + explicit MyView(pugl::World& world) + : pugl::View{world} + { + setEventHandler(*this); + } + + using pugl::View::onEvent; + + pugl::Status onEvent(const pugl::ConfigureEvent& event) noexcept; + pugl::Status onEvent(const pugl::ExposeEvent& event) noexcept; + }; + @endcode + + This facility is just a convenience, applications may use the C API + directly to set a handle and event function to set up a different + approach for event handling. + */ + template + Status setEventHandler(Handler& handler) + { + puglSetHandle(cobj(), &handler); + return static_cast(puglSetEventFunc(cobj(), eventFunc)); + } + + /// @copydoc puglSetBackend + Status setBackend(const PuglBackend* backend) noexcept + { + return static_cast(puglSetBackend(cobj(), backend)); + } + + /// @copydoc puglSetViewHint + Status setHint(ViewHint hint, int value) noexcept + { + return static_cast( + puglSetViewHint(cobj(), static_cast(hint), value)); + } + + /// @copydoc puglGetViewHint + int getHint(ViewHint hint) noexcept + { + return puglGetViewHint(cobj(), static_cast(hint)); + } + + /** + @} + @name Frame + Methods for working with the position and size of a view. + @{ + */ + + /// @copydoc puglGetFrame + Rect frame() const noexcept { return puglGetFrame(cobj()); } + + /// @copydoc puglSetFrame + Status setFrame(Rect frame) noexcept + { + return static_cast(puglSetFrame(cobj(), frame)); + } + + /// @copydoc puglSetDefaultSize + Status setDefaultSize(int width, int height) noexcept + { + return static_cast(puglSetDefaultSize(cobj(), width, height)); + } + + /// @copydoc puglSetMinSize + Status setMinSize(int width, int height) noexcept + { + return static_cast(puglSetMinSize(cobj(), width, height)); + } + + /// @copydoc puglSetMaxSize + Status setMaxSize(int width, int height) noexcept + { + return static_cast(puglSetMaxSize(cobj(), width, height)); + } + + /// @copydoc puglSetAspectRatio + Status setAspectRatio(int minX, int minY, int maxX, int maxY) noexcept + { + return static_cast( + puglSetAspectRatio(cobj(), minX, minY, maxX, maxY)); + } + + /** + @} + @name Windows + Methods for working with top-level windows. + @{ + */ + + /// @copydoc puglSetWindowTitle + Status setWindowTitle(const char* title) noexcept + { + return static_cast(puglSetWindowTitle(cobj(), title)); + } + + /// @copydoc puglSetParentWindow + Status setParentWindow(NativeView parent) noexcept + { + return static_cast(puglSetParentWindow(cobj(), parent)); + } + + /// @copydoc puglSetTransientFor + Status setTransientFor(NativeView parent) noexcept + { + return static_cast(puglSetTransientFor(cobj(), parent)); + } + + /// @copydoc puglRealize + Status realize() noexcept { return static_cast(puglRealize(cobj())); } + + /// @copydoc puglShow + Status show() noexcept { return static_cast(puglShow(cobj())); } + + /// @copydoc puglHide + Status hide() noexcept { return static_cast(puglHide(cobj())); } + + /// @copydoc puglGetVisible + bool visible() const noexcept { return puglGetVisible(cobj()); } + + /// @copydoc puglGetNativeWindow + NativeView nativeWindow() noexcept { return puglGetNativeWindow(cobj()); } + + /** + @} + @name Graphics + Methods for working with the graphics context and scheduling + redisplays. + @{ + */ + + /// @copydoc puglGetContext + void* context() noexcept { return puglGetContext(cobj()); } + + /// @copydoc puglPostRedisplay + Status postRedisplay() noexcept + { + return static_cast(puglPostRedisplay(cobj())); + } + + /// @copydoc puglPostRedisplayRect + Status postRedisplayRect(const Rect rect) noexcept + { + return static_cast(puglPostRedisplayRect(cobj(), rect)); + } + + /** + @} + @name Interaction + Methods for interacting with the user and window system. + @{ + */ + + /// @copydoc puglGrabFocus + Status grabFocus() noexcept + { + return static_cast(puglGrabFocus(cobj())); + } + + /// @copydoc puglHasFocus + bool hasFocus() const noexcept { return puglHasFocus(cobj()); } + + /// @copydoc puglSetCursor + Status setCursor(const Cursor cursor) noexcept + { + return static_cast( + puglSetCursor(cobj(), static_cast(cursor))); + } + + /// @copydoc puglRequestAttention + Status requestAttention() noexcept + { + return static_cast(puglRequestAttention(cobj())); + } + + /// @copydoc puglStartTimer + Status startTimer(const uintptr_t id, const double timeout) noexcept + { + return static_cast(puglStartTimer(cobj(), id, timeout)); + } + + /// @copydoc puglStopTimer + Status stopTimer(const uintptr_t id) noexcept + { + return static_cast(puglStopTimer(cobj(), id)); + } + + /** + @} + */ + + PuglView* cobj() noexcept { return Wrapper::cobj(); } + const PuglView* cobj() const noexcept { return Wrapper::cobj(); } private: - template - static Status dispatch(Target& target, const PuglEvent* event) - { - switch (event->type) { - case PUGL_NOTHING: - return Status::success; - case PUGL_CREATE: - return target.onEvent(static_cast(event->any)); - case PUGL_DESTROY: - return target.onEvent(static_cast(event->any)); - case PUGL_CONFIGURE: - return target.onEvent( - static_cast(event->configure)); - case PUGL_MAP: - return target.onEvent(static_cast(event->any)); - case PUGL_UNMAP: - return target.onEvent(static_cast(event->any)); - case PUGL_UPDATE: - return target.onEvent(static_cast(event->any)); - case PUGL_EXPOSE: - return target.onEvent( - static_cast(event->expose)); - case PUGL_CLOSE: - return target.onEvent(static_cast(event->any)); - case PUGL_FOCUS_IN: - return target.onEvent( - static_cast(event->focus)); - case PUGL_FOCUS_OUT: - return target.onEvent( - static_cast(event->focus)); - case PUGL_KEY_PRESS: - return target.onEvent( - static_cast(event->key)); - case PUGL_KEY_RELEASE: - return target.onEvent( - static_cast(event->key)); - case PUGL_TEXT: - return target.onEvent(static_cast(event->text)); - case PUGL_POINTER_IN: - return target.onEvent( - static_cast(event->crossing)); - case PUGL_POINTER_OUT: - return target.onEvent( - static_cast(event->crossing)); - case PUGL_BUTTON_PRESS: - return target.onEvent( - static_cast(event->button)); - case PUGL_BUTTON_RELEASE: - return target.onEvent( - static_cast(event->button)); - case PUGL_MOTION: - return target.onEvent( - static_cast(event->motion)); - case PUGL_SCROLL: - return target.onEvent( - static_cast(event->scroll)); - case PUGL_CLIENT: - return target.onEvent( - static_cast(event->client)); - case PUGL_TIMER: - return target.onEvent(static_cast(event->timer)); - case PUGL_LOOP_ENTER: - return target.onEvent( - static_cast(event->any)); - case PUGL_LOOP_LEAVE: - return target.onEvent( - static_cast(event->any)); - } - - return Status::failure; - } - - template - static PuglStatus eventFunc(PuglView* view, const PuglEvent* event) noexcept - { - auto* target = static_cast(puglGetHandle(view)); + template + static Status dispatch(Target& target, const PuglEvent* event) + { + switch (event->type) { + case PUGL_NOTHING: + return Status::success; + case PUGL_CREATE: + return target.onEvent(static_cast(event->any)); + case PUGL_DESTROY: + return target.onEvent(static_cast(event->any)); + case PUGL_CONFIGURE: + return target.onEvent( + static_cast(event->configure)); + case PUGL_MAP: + return target.onEvent(static_cast(event->any)); + case PUGL_UNMAP: + return target.onEvent(static_cast(event->any)); + case PUGL_UPDATE: + return target.onEvent(static_cast(event->any)); + case PUGL_EXPOSE: + return target.onEvent(static_cast(event->expose)); + case PUGL_CLOSE: + return target.onEvent(static_cast(event->any)); + case PUGL_FOCUS_IN: + return target.onEvent(static_cast(event->focus)); + case PUGL_FOCUS_OUT: + return target.onEvent(static_cast(event->focus)); + case PUGL_KEY_PRESS: + return target.onEvent(static_cast(event->key)); + case PUGL_KEY_RELEASE: + return target.onEvent(static_cast(event->key)); + case PUGL_TEXT: + return target.onEvent(static_cast(event->text)); + case PUGL_POINTER_IN: + return target.onEvent( + static_cast(event->crossing)); + case PUGL_POINTER_OUT: + return target.onEvent( + static_cast(event->crossing)); + case PUGL_BUTTON_PRESS: + return target.onEvent( + static_cast(event->button)); + case PUGL_BUTTON_RELEASE: + return target.onEvent( + static_cast(event->button)); + case PUGL_MOTION: + return target.onEvent(static_cast(event->motion)); + case PUGL_SCROLL: + return target.onEvent(static_cast(event->scroll)); + case PUGL_CLIENT: + return target.onEvent(static_cast(event->client)); + case PUGL_TIMER: + return target.onEvent(static_cast(event->timer)); + case PUGL_LOOP_ENTER: + return target.onEvent(static_cast(event->any)); + case PUGL_LOOP_LEAVE: + return target.onEvent(static_cast(event->any)); + } + + return Status::failure; + } + + template + static PuglStatus eventFunc(PuglView* view, const PuglEvent* event) noexcept + { + auto* target = static_cast(puglGetHandle(view)); #ifdef __cpp_exceptions - try { - return static_cast(dispatch(*target, event)); - } catch (...) { - return PUGL_UNKNOWN_ERROR; - } + try { + return static_cast(dispatch(*target, event)); + } catch (...) { + return PUGL_UNKNOWN_ERROR; + } #else - return static_cast(pugl::dispatch(*target, event)); + return static_cast(pugl::dispatch(*target, event)); #endif - } + } - World& _world; + World& _world; }; /** diff --git a/bindings/cxx/include/pugl/stub.hpp b/bindings/cxx/include/pugl/stub.hpp index 8b37da4..6946fe0 100644 --- a/bindings/cxx/include/pugl/stub.hpp +++ b/bindings/cxx/include/pugl/stub.hpp @@ -33,7 +33,7 @@ namespace pugl { inline const PuglBackend* stubBackend() noexcept { - return puglStubBackend(); + return puglStubBackend(); } /** diff --git a/bindings/cxx/include/pugl/vulkan.hpp b/bindings/cxx/include/pugl/vulkan.hpp index 65d1e57..21341b3 100644 --- a/bindings/cxx/include/pugl/vulkan.hpp +++ b/bindings/cxx/include/pugl/vulkan.hpp @@ -49,48 +49,48 @@ namespace pugl { /// @copydoc PuglVulkanLoader class VulkanLoader final - : public detail::Wrapper + : public detail::Wrapper { public: - /** - Create a new dynamic loader for Vulkan functions. - - This dynamically loads the Vulkan library and gets the load functions - from it. - - Note that this constructor does not throw exceptions, though failure is - possible. To check if the Vulkan library failed to load, test this - loader, which is explicitly convertible to `bool`. It is safe to use a - failed loader, but the accessors will always return null. - */ - explicit VulkanLoader(World& world) noexcept - : Wrapper{puglNewVulkanLoader(world.cobj())} - {} - - /** - Return the `vkGetInstanceProcAddr` function. - - @return Null if the Vulkan library failed to load, or does not contain - this function (which is unlikely and indicates a broken system). - */ - PFN_vkGetInstanceProcAddr getInstanceProcAddrFunc() const noexcept - { - return cobj() ? puglGetInstanceProcAddrFunc(cobj()) : nullptr; - } - - /** - Return the `vkGetDeviceProcAddr` function. - - @return Null if the Vulkan library failed to load, or does not contain - this function (which is unlikely and indicates a broken system). - */ - PFN_vkGetDeviceProcAddr getDeviceProcAddrFunc() const noexcept - { - return cobj() ? puglGetDeviceProcAddrFunc(cobj()) : nullptr; - } - - /// Return true if this loader is valid to use - explicit operator bool() const noexcept { return cobj(); } + /** + Create a new dynamic loader for Vulkan functions. + + This dynamically loads the Vulkan library and gets the load functions + from it. + + Note that this constructor does not throw exceptions, though failure is + possible. To check if the Vulkan library failed to load, test this + loader, which is explicitly convertible to `bool`. It is safe to use a + failed loader, but the accessors will always return null. + */ + explicit VulkanLoader(World& world) noexcept + : Wrapper{puglNewVulkanLoader(world.cobj())} + {} + + /** + Return the `vkGetInstanceProcAddr` function. + + @return Null if the Vulkan library failed to load, or does not contain + this function (which is unlikely and indicates a broken system). + */ + PFN_vkGetInstanceProcAddr getInstanceProcAddrFunc() const noexcept + { + return cobj() ? puglGetInstanceProcAddrFunc(cobj()) : nullptr; + } + + /** + Return the `vkGetDeviceProcAddr` function. + + @return Null if the Vulkan library failed to load, or does not contain + this function (which is unlikely and indicates a broken system). + */ + PFN_vkGetDeviceProcAddr getDeviceProcAddrFunc() const noexcept + { + return cobj() ? puglGetDeviceProcAddrFunc(cobj()) : nullptr; + } + + /// Return true if this loader is valid to use + explicit operator bool() const noexcept { return cobj(); } }; /** @@ -102,23 +102,23 @@ public: class StaticStringArray final { public: - using value_type = const char*; - using const_iterator = const char* const*; - using size_type = uint32_t; + using value_type = const char*; + using const_iterator = const char* const*; + using size_type = uint32_t; - StaticStringArray(const char* const* strings, const uint32_t size) noexcept - : _strings{strings} - , _size{size} - {} + StaticStringArray(const char* const* strings, const uint32_t size) noexcept + : _strings{strings} + , _size{size} + {} - const char* const* begin() const noexcept { return _strings; } - const char* const* end() const noexcept { return _strings + _size; } - const char* const* data() const noexcept { return _strings; } - uint32_t size() const noexcept { return _size; } + const char* const* begin() const noexcept { return _strings; } + const char* const* end() const noexcept { return _strings + _size; } + const char* const* data() const noexcept { return _strings; } + uint32_t size() const noexcept { return _size; } private: - const char* const* _strings; - uint32_t _size; + const char* const* _strings; + uint32_t _size; }; /** @@ -132,10 +132,10 @@ private: inline StaticStringArray getInstanceExtensions() noexcept { - uint32_t count = 0; - const char* const* const extensions = puglGetInstanceExtensions(&count); + uint32_t count = 0; + const char* const* const extensions = puglGetInstanceExtensions(&count); - return StaticStringArray{extensions, count}; + return StaticStringArray{extensions, count}; } /// @copydoc puglCreateSurface @@ -146,17 +146,17 @@ createSurface(PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr, const VkAllocationCallbacks* const allocator, VkSurfaceKHR* const surface) noexcept { - const VkResult r = puglCreateSurface( - vkGetInstanceProcAddr, view.cobj(), instance, allocator, surface); + const VkResult r = puglCreateSurface( + vkGetInstanceProcAddr, view.cobj(), instance, allocator, surface); - return (!r && !surface) ? VK_ERROR_INITIALIZATION_FAILED : r; + return (!r && !surface) ? VK_ERROR_INITIALIZATION_FAILED : r; } /// @copydoc puglVulkanBackend inline const PuglBackend* vulkanBackend() noexcept { - return puglVulkanBackend(); + return puglVulkanBackend(); } /** -- cgit v1.2.1