diff options
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 111 |
1 files changed, 60 insertions, 51 deletions
diff --git a/src/common.c b/src/common.c index 2e6e0e6..c8ac3d4 100644 --- a/src/common.c +++ b/src/common.c @@ -4,14 +4,13 @@ // Common implementations of public API functions in the core library #include "internal.h" - #include "platform.h" #include "types.h" -#include "pugl/pugl.h" +#include <pugl/pugl.h> -#include <limits.h> #include <stdbool.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> @@ -105,27 +104,37 @@ puglGetWorldString(const PuglWorld* const world, const PuglStringHint key) } static void -puglSetDefaultHints(PuglHints hints) +puglSetDefaultHints(PuglView* const view) { - hints[PUGL_CONTEXT_API] = PUGL_OPENGL_API; - hints[PUGL_CONTEXT_VERSION_MAJOR] = 2; - hints[PUGL_CONTEXT_VERSION_MINOR] = 0; - hints[PUGL_CONTEXT_PROFILE] = PUGL_OPENGL_CORE_PROFILE; - hints[PUGL_CONTEXT_DEBUG] = PUGL_FALSE; - hints[PUGL_RED_BITS] = 8; - hints[PUGL_GREEN_BITS] = 8; - hints[PUGL_BLUE_BITS] = 8; - hints[PUGL_ALPHA_BITS] = 8; - hints[PUGL_DEPTH_BITS] = 0; - hints[PUGL_STENCIL_BITS] = 0; - hints[PUGL_SAMPLE_BUFFERS] = PUGL_DONT_CARE; - hints[PUGL_SAMPLES] = 0; - hints[PUGL_DOUBLE_BUFFER] = PUGL_TRUE; - hints[PUGL_SWAP_INTERVAL] = PUGL_DONT_CARE; - hints[PUGL_RESIZABLE] = PUGL_FALSE; - hints[PUGL_IGNORE_KEY_REPEAT] = PUGL_FALSE; - hints[PUGL_REFRESH_RATE] = PUGL_DONT_CARE; - hints[PUGL_VIEW_TYPE] = PUGL_DONT_CARE; + view->hints[PUGL_CONTEXT_API] = PUGL_OPENGL_API; + view->hints[PUGL_CONTEXT_VERSION_MAJOR] = 2; + view->hints[PUGL_CONTEXT_VERSION_MINOR] = 0; + view->hints[PUGL_CONTEXT_PROFILE] = PUGL_OPENGL_CORE_PROFILE; + view->hints[PUGL_CONTEXT_DEBUG] = PUGL_FALSE; + view->hints[PUGL_RED_BITS] = 8; + view->hints[PUGL_GREEN_BITS] = 8; + view->hints[PUGL_BLUE_BITS] = 8; + view->hints[PUGL_ALPHA_BITS] = 8; + view->hints[PUGL_DEPTH_BITS] = 0; + view->hints[PUGL_STENCIL_BITS] = 0; + view->hints[PUGL_SAMPLE_BUFFERS] = PUGL_DONT_CARE; + view->hints[PUGL_SAMPLES] = 0; + view->hints[PUGL_DOUBLE_BUFFER] = PUGL_TRUE; + view->hints[PUGL_SWAP_INTERVAL] = PUGL_DONT_CARE; + view->hints[PUGL_RESIZABLE] = PUGL_FALSE; + view->hints[PUGL_IGNORE_KEY_REPEAT] = PUGL_FALSE; + view->hints[PUGL_REFRESH_RATE] = PUGL_DONT_CARE; + view->hints[PUGL_VIEW_TYPE] = PUGL_DONT_CARE; + + for (unsigned i = 0U; i < PUGL_NUM_POSITION_HINTS; ++i) { + view->positionHints[i].x = INT16_MIN; + view->positionHints[i].y = INT16_MIN; + } + + for (unsigned i = 0U; i < PUGL_NUM_SIZE_HINTS; ++i) { + view->sizeHints[i].width = 0U; + view->sizeHints[i].height = 0U; + } } PuglView* @@ -137,13 +146,8 @@ puglNewView(PuglWorld* const world) return NULL; } - view->world = world; - view->sizeHints[PUGL_MIN_SIZE].width = 1; - view->sizeHints[PUGL_MIN_SIZE].height = 1; - view->defaultX = INT_MIN; - view->defaultY = INT_MIN; - - puglSetDefaultHints(view->hints); + view->world = world; + puglSetDefaultHints(view); // Enlarge world view list const size_t newNumViews = world->numViews + 1U; @@ -286,32 +290,37 @@ puglGetViewString(const PuglView* const view, const PuglStringHint key) return view->strings[key]; } -PuglRect -puglGetFrame(const PuglView* view) +PuglPoint +puglGetPositionHint(const PuglView* const view, const PuglPositionHint hint) { - if (view->lastConfigure.type == PUGL_CONFIGURE) { - // Return the last configured frame - const PuglRect frame = {view->lastConfigure.x, - view->lastConfigure.y, - view->lastConfigure.width, - view->lastConfigure.height}; - return frame; + if (hint == PUGL_CURRENT_POSITION) { + PuglPoint pos = {0, 0}; + if (view->lastConfigure.type == PUGL_CONFIGURE) { + pos.x = view->lastConfigure.x; + pos.y = view->lastConfigure.y; + } else { + const PuglPoint defaultPos = view->positionHints[PUGL_DEFAULT_POSITION]; + if (puglIsValidPosition(defaultPos.x, defaultPos.y)) { + pos.x = defaultPos.x; + pos.y = defaultPos.y; + } + } + return pos; } - // Get the default position if set, or fallback to (0, 0) - int x = view->defaultX; - int y = view->defaultY; - if (!puglIsValidPosition(x, y)) { - x = 0; - y = 0; + return view->positionHints[hint]; +} + +PuglArea +puglGetSizeHint(const PuglView* const view, const PuglSizeHint hint) +{ + if (hint == PUGL_CURRENT_SIZE && view->lastConfigure.type == PUGL_CONFIGURE) { + const PuglArea area = {view->lastConfigure.width, + view->lastConfigure.height}; + return area; } - // Return the default frame, sanitized if necessary - const PuglRect frame = {(PuglCoord)x, - (PuglCoord)y, - view->sizeHints[PUGL_DEFAULT_SIZE].width, - view->sizeHints[PUGL_DEFAULT_SIZE].height}; - return frame; + return view->sizeHints[hint]; } PuglStatus |