diff options
author | David Robillard <d@drobilla.net> | 2023-01-12 10:30:10 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-01-14 11:53:28 -0500 |
commit | bd4f79646f623e929e6aa22bea028952b515aeef (patch) | |
tree | e2dcc2635bb2b12b9c552755b35a0343005ce88a /src/common.c | |
parent | 786a28e4a2bc9fce95a8d2e6cd1a4c76d2ae1a0f (diff) | |
download | pugl-bd4f79646f623e929e6aa22bea028952b515aeef.tar.gz pugl-bd4f79646f623e929e6aa22bea028952b515aeef.tar.bz2 pugl-bd4f79646f623e929e6aa22bea028952b515aeef.zip |
Add general string hint interface
This replaces the window title and class name APIs with a more general one that
can be easily extended to other things, like icon names, more detailed
application hints, and so on.
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/src/common.c b/src/common.c index 7113461..eafb07a 100644 --- a/src/common.c +++ b/src/common.c @@ -52,7 +52,7 @@ puglNewWorld(PuglWorldType type, PuglWorldFlags flags) world->startTime = puglGetTime(world); world->type = type; - puglSetString(&world->className, "Pugl"); + puglSetString(&world->strings[PUGL_CLASS_NAME], "Pugl"); return world; } @@ -61,7 +61,11 @@ void puglFreeWorld(PuglWorld* const world) { puglFreeWorldInternals(world); - free(world->className); + + for (size_t i = 0; i < PUGL_NUM_STRING_HINTS; ++i) { + free(world->strings[i]); + } + free(world->views); free(world); } @@ -79,16 +83,26 @@ puglGetWorldHandle(PuglWorld* world) } PuglStatus -puglSetClassName(PuglWorld* const world, const char* const name) +puglSetWorldString(PuglWorld* const world, + const PuglStringHint key, + const char* const value) { - puglSetString(&world->className, name); + if ((unsigned)key < 0 || (unsigned)key >= PUGL_NUM_STRING_HINTS) { + return PUGL_BAD_PARAMETER; + } + + puglSetString(&world->strings[key], value); return PUGL_SUCCESS; } const char* -puglGetClassName(const PuglWorld* world) +puglGetWorldString(const PuglWorld* const world, const PuglStringHint key) { - return world->className; + if ((unsigned)key < 0 || (unsigned)key >= PUGL_NUM_STRING_HINTS) { + return NULL; + } + + return world->strings[key]; } static void @@ -161,7 +175,10 @@ puglFreeView(PuglView* view) } } - free(view->title); + for (size_t i = 0; i < PUGL_NUM_STRING_HINTS; ++i) { + free(view->strings[i]); + } + puglFreeViewInternals(view); free(view); } @@ -239,6 +256,29 @@ puglGetViewHint(const PuglView* view, PuglViewHint hint) return PUGL_DONT_CARE; } +PuglStatus +puglSetViewString(PuglView* const view, + const PuglStringHint key, + const char* const value) +{ + if ((unsigned)key < 0 || (unsigned)key >= PUGL_NUM_STRING_HINTS) { + return PUGL_BAD_PARAMETER; + } + + puglSetString(&view->strings[key], value); + return puglViewStringChanged(view, key, view->strings[key]); +} + +const char* +puglGetViewString(const PuglView* const view, const PuglStringHint key) +{ + if ((unsigned)key < 0 || (unsigned)key >= PUGL_NUM_STRING_HINTS) { + return NULL; + } + + return view->strings[key]; +} + PuglRect puglGetFrame(const PuglView* view) { @@ -267,12 +307,6 @@ puglGetFrame(const PuglView* view) return frame; } -const char* -puglGetWindowTitle(const PuglView* const view) -{ - return view->title; -} - PuglStatus puglSetParentWindow(PuglView* view, PuglNativeView parent) { |