From 89af2b1e3910196c4cad47c3748c1a2920b3faf9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 4 Aug 2019 20:28:28 +0200 Subject: Rename remaining init functions This finishes the removal of the init/set split. While these ones are superficial, the general idea here is to provide general functions that work before or after window creation where possible. This prevents the situation where ever more dynamic counterparts to existing init functions get added over time. --- pugl/detail/implementation.c | 17 ++++++----- pugl/pugl.h | 68 ++++++++++++++++++++++++++++++++++---------- test/pugl_cairo_test.c | 6 ++-- test/pugl_test.c | 24 ++++++++-------- 4 files changed, 78 insertions(+), 37 deletions(-) diff --git a/pugl/detail/implementation.c b/pugl/detail/implementation.c index 1f027a9..3cefa37 100644 --- a/pugl/detail/implementation.c +++ b/pugl/detail/implementation.c @@ -136,25 +136,28 @@ puglGetWorld(PuglView* view) return view->world; } -void -puglInitWindowHint(PuglView* view, PuglWindowHint hint, int value) +PuglStatus +puglSetViewHint(PuglView* view, PuglViewHint hint, int value) { if (hint < PUGL_NUM_WINDOW_HINTS) { view->hints[hint] = value; } + + return PUGL_SUCCESS; } -void -puglInitWindowParent(PuglView* view, PuglNativeWindow parent) +PuglStatus +puglSetParentWindow(PuglView* view, PuglNativeWindow parent) { view->parent = parent; + return PUGL_SUCCESS; } -int -puglInitBackend(PuglView* view, const PuglBackend* backend) +PuglStatus +puglSetBackend(PuglView* view, const PuglBackend* backend) { view->backend = backend; - return 0; + return PUGL_SUCCESS; } void diff --git a/pugl/pugl.h b/pugl/pugl.h index 112b11b..e8de39b 100644 --- a/pugl/pugl.h +++ b/pugl/pugl.h @@ -107,7 +107,7 @@ typedef enum { PUGL_IGNORE_KEY_REPEAT, /**< True if key repeat events are ignored */ PUGL_NUM_WINDOW_HINTS -} PuglWindowHint; +} PuglViewHint; /** Special window hint value. @@ -116,7 +116,7 @@ typedef enum { PUGL_DONT_CARE = -1, /**< Use best available value */ PUGL_FALSE = 0, /**< Explicitly false */ PUGL_TRUE = 1 /**< Explicitly true */ -} PuglWindowHintValue; +} PuglViewHintValue; /** A rectangle. @@ -529,16 +529,21 @@ PUGL_API PuglWorld* puglGetWorld(PuglView* view); /** - Set a hint before creating a window. + Set a hint to configure window properties. + + This only has an effect when called before puglCreateWindow(). */ -PUGL_API void -puglInitWindowHint(PuglView* view, PuglWindowHint hint, int value); +PUGL_API PuglStatus +puglSetViewHint(PuglView* view, PuglViewHint hint, int value); /** Set the parent window before creating a window (for embedding). + + This only works when called before creating the window with + puglCreateWindow(), reparenting is not supported. */ -PUGL_API void -puglInitWindowParent(PuglView* view, PuglNativeWindow parent); +PUGL_API PuglStatus +puglSetParentWindow(PuglView* view, PuglNativeWindow parent); /** Set the graphics backend to use. @@ -548,8 +553,8 @@ puglInitWindowParent(PuglView* view, PuglNativeWindow parent); puglGlBackend() and puglCairoBackend(), declared in pugl_gl_backend.h and pugl_cairo_backend.h, respectively. */ -PUGL_API int -puglInitBackend(PuglView* view, const PuglBackend* backend); +PUGL_API PuglStatus +puglSetBackend(PuglView* view, const PuglBackend* backend); /** @} @@ -871,12 +876,12 @@ puglInitTransientFor(PuglView* view, uintptr_t parent) /** Enable or disable resizing before creating a window. - @deprecated Use puglInitWindowHint() with @ref PUGL_RESIZABLE. + @deprecated Use puglSetViewHint() with @ref PUGL_RESIZABLE. */ -static inline PUGL_DEPRECATED_BY("puglInitWindowHint") void +static inline PUGL_DEPRECATED_BY("puglSetViewHint") void puglInitResizable(PuglView* view, bool resizable) { - puglInitWindowHint(view, PUGL_RESIZABLE, resizable); + puglSetViewHint(view, PUGL_RESIZABLE, resizable); } /** @@ -897,12 +902,45 @@ puglGetSize(PuglView* view, int* width, int* height) /** Ignore synthetic repeated key events. - @deprecated Use puglInitWindowHint() with @ref PUGL_IGNORE_KEY_REPEAT. + @deprecated Use puglSetViewHint() with @ref PUGL_IGNORE_KEY_REPEAT. */ -static inline PUGL_DEPRECATED_BY("puglInitWindowHint") void +static inline PUGL_DEPRECATED_BY("puglSetViewHint") void puglIgnoreKeyRepeat(PuglView* view, bool ignore) { - puglInitWindowHint(view, PUGL_IGNORE_KEY_REPEAT, ignore); + puglSetViewHint(view, PUGL_IGNORE_KEY_REPEAT, ignore); +} + +/** + Set a hint before creating a window. + + @deprecated Use puglSetWindowHint(). +*/ +static inline PUGL_DEPRECATED_BY("puglSetViewHint") void +puglInitWindowHint(PuglView* view, PuglViewHint hint, int value) +{ + puglSetViewHint(view, hint, value); +} + +/** + Set the parent window before creating a window (for embedding). + + @deprecated Use puglSetWindowParent(). +*/ +static inline PUGL_DEPRECATED_BY("puglSetParentWindow") void +puglInitWindowParent(PuglView* view, PuglNativeWindow parent) +{ + puglSetParentWindow(view, parent); +} + +/** + Set the graphics backend to use. + + @deprecated Use puglSetBackend(). +*/ +static inline PUGL_DEPRECATED_BY("puglSetBackend") int +puglInitBackend(PuglView* view, const PuglBackend* backend) +{ + return puglSetBackend(view, backend); } /** diff --git a/test/pugl_cairo_test.c b/test/pugl_cairo_test.c index 52cbbbd..278a74d 100644 --- a/test/pugl_cairo_test.c +++ b/test/pugl_cairo_test.c @@ -212,10 +212,10 @@ main(int argc, char** argv) PuglView* view = puglNewView(world); puglSetFrame(view, frame); puglSetMinSize(view, 256, 256); - puglInitWindowHint(view, PUGL_RESIZABLE, resizable); - puglInitBackend(view, puglCairoBackend()); + puglSetViewHint(view, PUGL_RESIZABLE, resizable); + puglSetBackend(view, puglCairoBackend()); - puglInitWindowHint(view, PUGL_IGNORE_KEY_REPEAT, ignoreKeyRepeat); + puglSetViewHint(view, PUGL_IGNORE_KEY_REPEAT, ignoreKeyRepeat); puglSetEventFunc(view, onEvent); if (puglCreateWindow(view, "Pugl Test")) { diff --git a/test/pugl_test.c b/test/pugl_test.c index e291df7..6c4e3e8 100644 --- a/test/pugl_test.c +++ b/test/pugl_test.c @@ -320,13 +320,13 @@ main(int argc, char** argv) puglSetFrame(app.parent, parentFrame); puglSetMinSize(app.parent, borderWidth * 3, borderWidth * 3); puglSetAspectRatio(app.parent, 1, 1, 16, 9); - puglInitBackend(app.parent, puglGlBackend()); + puglSetBackend(app.parent, puglGlBackend()); - puglInitWindowHint(app.parent, PUGL_RESIZABLE, resizable); - puglInitWindowHint(app.parent, PUGL_SAMPLES, samples); - puglInitWindowHint(app.parent, PUGL_DOUBLE_BUFFER, doubleBuffer); - puglInitWindowHint(app.parent, PUGL_SWAP_INTERVAL, doubleBuffer); - puglInitWindowHint(app.parent, PUGL_IGNORE_KEY_REPEAT, ignoreKeyRepeat); + puglSetViewHint(app.parent, PUGL_RESIZABLE, resizable); + puglSetViewHint(app.parent, PUGL_SAMPLES, samples); + puglSetViewHint(app.parent, PUGL_DOUBLE_BUFFER, doubleBuffer); + puglSetViewHint(app.parent, PUGL_SWAP_INTERVAL, doubleBuffer); + puglSetViewHint(app.parent, PUGL_IGNORE_KEY_REPEAT, ignoreKeyRepeat); puglSetHandle(app.parent, &app); puglSetEventFunc(app.parent, onParentEvent); @@ -338,13 +338,13 @@ main(int argc, char** argv) } puglSetFrame(app.child, getChildFrame(parentFrame)); - puglInitWindowParent(app.child, puglGetNativeWindow(app.parent)); + puglSetParentWindow(app.child, puglGetNativeWindow(app.parent)); - puglInitWindowHint(app.child, PUGL_SAMPLES, samples); - puglInitWindowHint(app.child, PUGL_DOUBLE_BUFFER, doubleBuffer); - puglInitWindowHint(app.child, PUGL_SWAP_INTERVAL, 0); - puglInitBackend(app.child, puglGlBackend()); - puglInitWindowHint(app.child, PUGL_IGNORE_KEY_REPEAT, ignoreKeyRepeat); + puglSetViewHint(app.child, PUGL_SAMPLES, samples); + puglSetViewHint(app.child, PUGL_DOUBLE_BUFFER, doubleBuffer); + puglSetViewHint(app.child, PUGL_SWAP_INTERVAL, 0); + puglSetBackend(app.child, puglGlBackend()); + puglSetViewHint(app.child, PUGL_IGNORE_KEY_REPEAT, ignoreKeyRepeat); puglSetHandle(app.child, &app); puglSetEventFunc(app.child, onEvent); -- cgit v1.2.1