27e55dd7984e1e8290cfc2f410ac4da466253920 — octaspire 29 days ago v0.468.0
Work with Nuklear plugin and example
M dev/include/octaspire/dern/octaspire_dern_config.h => dev/include/octaspire/dern/octaspire_dern_config.h +1 -1
@@ 18,7 18,7 @@ #define OCTASPIRE_DERN_CONFIG_H
  
  #define OCTASPIRE_DERN_CONFIG_VERSION_MAJOR "0"
- #define OCTASPIRE_DERN_CONFIG_VERSION_MINOR "467"
+ #define OCTASPIRE_DERN_CONFIG_VERSION_MINOR "468"
  #define OCTASPIRE_DERN_CONFIG_VERSION_PATCH "0"
  
  #define OCTASPIRE_DERN_CONFIG_VERSION_STR "Octaspire Dern version " \

M dev/include/octaspire/dern/octaspire_dern_value.h => dev/include/octaspire/dern/octaspire_dern_value.h +4 -0
@@ 401,6 401,10 @@ bool octaspire_dern_value_as_boolean_get_value(
      octaspire_dern_value_t const * const self);
  
+ void octaspire_dern_value_as_boolean_set_value(
+     octaspire_dern_value_t * const self,
+     bool const value);
+ 
  int32_t octaspire_dern_value_as_integer_get_value(
      octaspire_dern_value_t const * const self);
  

M dev/src/octaspire_dern_value.c => dev/src/octaspire_dern_value.c +8 -0
@@ 1863,6 1863,14 @@ return self->value.boolean;
  }
  
+ void octaspire_dern_value_as_boolean_set_value(
+     octaspire_dern_value_t * const self,
+     bool const value)
+ {
+     octaspire_helpers_verify_true(self->typeTag == OCTASPIRE_DERN_VALUE_TAG_BOOLEAN);
+     self->value.boolean = value;
+ }
+ 
  int32_t octaspire_dern_value_as_integer_get_value(
      octaspire_dern_value_t const * const self)
  {

A release/examples/dern-nuklear-example.dern => release/examples/dern-nuklear-example.dern +80 -0
@@ 0,0 1,80 @@
+ (require 'dern_sdl2)
+ (require 'dern_nuklear)
+ 
+ (sdl2-Init 'VIDEO)
+ 
+ (define dern-nuklear-example-window-width  as {D+800} [window width])
+ (define dern-nuklear-example-window-height as {D+600} [window width])
+ (define dern-nuklear-example-window-zoom   as {D+0.1} [window zoom factor])
+ 
+ (define dern-nuklear-example-window as
+   (sdl2-CreateWindow
+     [Nuklear example]
+     'CENTERED
+     'CENTERED
+     dern-nuklear-example-window-width
+     dern-nuklear-example-window-height)
+   [window])
+ 
+ (define dern-nuklear-example-nuklear-ctx as (nuklear-sdl-init dern-nuklear-example-window) [nuklear context])
+ 
+ (sdl2-glClearColor {D+0} {D+0} {D+0} {D+1})
+ (sdl2-gl-ortho-line-smooth-enable)
+ 
+ (define dern-nuklear-example-enter-ortho as (fn (zoom)
+   (define width  as (/ (* {D+4} dern-nuklear-example-window-width)  (* {D+2} zoom)) [target width])
+   (define height as (/ (* {D+4} dern-nuklear-example-window-height) (* {D+2} zoom)) [target width])
+   (sdl2-gl-ortho-enter (- width) width (- height) height))
+   [enter ortho] '(zoom [zoom factor]) howto-no)
+ 
+ (dern-nuklear-example-enter-ortho dern-nuklear-example-window-zoom)
+ 
+ (define dern-nuklear-example-running               as true [is running or not])
+ (define dern-nuklear-example-target-FPS            as {D+100} [target FPS])
+ (define dern-nuklear-example-target-frame-duration as (/ {D+1.0} dern-nuklear-example-target-FPS) [time for a frame to last])
+ 
+ (define dern-nuklear-example-checkbox-active       as false [is checkbox active or not])
+ 
+ (define dern-nuklear-example-render as (fn ()
+   (if (nuklear-begin dern-nuklear-example-nuklear-ctx [] {D+10} {D+10} {D+780} {D+580})
+     (do
+       (nuklear-layout-row-static dern-nuklear-example-nuklear-ctx {D+30} {D+150} {D+1})
+       (nuklear-label dern-nuklear-example-nuklear-ctx [-- Text --] 'RIGHT)
+       (nuklear-layout-row-static dern-nuklear-example-nuklear-ctx {D+30} {D+150} {D+1})
+       (nuklear-progress dern-nuklear-example-nuklear-ctx {D+125} {D+250} false)
+       (nuklear-layout-row-static dern-nuklear-example-nuklear-ctx {D+90} {D+150} {D+1})
+       (if (nuklear-button-label dern-nuklear-example-nuklear-ctx [Quit Button]) (= dern-nuklear-example-running false))
+       (nuklear-layout-row-static dern-nuklear-example-nuklear-ctx {D+90} {D+150} {D+1})
+       (if (nuklear-checkbox-label dern-nuklear-example-nuklear-ctx [Checkbox] dern-nuklear-example-checkbox-active) (println [Toggled to {}] dern-nuklear-example-checkbox-active))))
+   (nuklear-end dern-nuklear-example-nuklear-ctx)
+   (nuklear-sdl-render)
+   (sdl2-GL-SwapWindow dern-nuklear-example-window))
+   [render] '() howto-no)
+ 
+ (define dern-nuklear-example-update as (fn (dt)
+   (nuklear-input-begin dern-nuklear-example-nuklear-ctx)
+   (define event as (sdl2-PollEvent) [event from sdl2])
+   (if (!= event nil)
+     (nuklear-sdl-handle-event dern-nuklear-example-nuklear-ctx (ln@ event (- (len event) {D+1}))))
+   (nuklear-input-end dern-nuklear-example-nuklear-ctx)
+   (define type  as nil [type of event])
+   (if (and (!= event nil) (> (len event) {D+0})) (= type (ln@ event {D+0})))
+   (if (== type 'QUIT) (= dern-nuklear-example-running false)))
+   [update] '(dt [dt]) howto-no)
+ 
+ (while dern-nuklear-example-running
+   (sdl2-TimerUpdate)
+   (define dt as (sdl2-TimerGetSeconds) [dt])
+   (sdl2-TimerReset)
+   (dern-nuklear-example-render)
+   (dern-nuklear-example-update dt)
+   (sdl2-TimerUpdate)
+   (define current-frame-duration as (sdl2-TimerGetSeconds) [current frame duration])
+   (if (> dern-nuklear-example-target-frame-duration current-frame-duration) (do
+     (define delay-in-seconds as (- dern-nuklear-example-target-frame-duration current-frame-duration) [time to sleep])
+     (if (> delay-in-seconds {D+0})
+         (sdl2-Delay delay-in-seconds))))
+   (= dt (sdl2-TimerGetSeconds)))
+ 
+ (sdl2-Quit)
+ 

M release/how-to-build/OpenBSD.sh => release/how-to-build/OpenBSD.sh +7 -0
@@ 104,6 104,13 @@   
  
+ EXAMPLE_NAME="Dern nuklear plugin"
+ EXAMPLE_ERROR_HINT="OpenBSD: sudo pkg_add sdl2 sdl2-image sdl2-mixer sdl2-ttf"
+ EXAMPLE_SUCCESS_RUN="LD_LIBRARY_PATH=. ./octaspire-dern-repl examples/dern-nuklear-example.dern"
+ echoAndRun "$CC" -O2 -std=c99 -Wall -Wextra -fPIC -shared -DSDL_DISABLE_IMMINTRIN_H -DOCTASPIRE_DERN_AMALGAMATED_IMPLEMENTATION -DOCTASPIRE_DERN_SDL2_PLUGIN_USE_SDL_IMAGE_LIBRARY -DOCTASPIRE_DERN_SDL2_PLUGIN_USE_SDL_MIXER_LIBRARY -DOCTASPIRE_DERN_SDL2_PLUGIN_USE_SDL_TTF_LIBRARY -DOCTASPIRE_DERN_SDL2_PLUGIN_USE_OPENGL2_LIBRARY $(sdl2-config --cflags) -I . -I plugins/external/nuklear -o libdern_nuklear.so plugins/dern_nuklear.c $(sdl2-config --libs) -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lGLU
+ 
+ 
+ 
  # Build Chipmunk library and plugin.
  
  printf "${BLUE}Compiling ${BOLD}Chipmunk library${NOCOLOR}${BLUE}"

M release/octaspire-dern-amalgamated.c => release/octaspire-dern-amalgamated.c +13 -1
@@ 26223,7 26223,7 @@ #define OCTASPIRE_DERN_CONFIG_H
  
  #define OCTASPIRE_DERN_CONFIG_VERSION_MAJOR "0"
- #define OCTASPIRE_DERN_CONFIG_VERSION_MINOR "467"
+ #define OCTASPIRE_DERN_CONFIG_VERSION_MINOR "468"
  #define OCTASPIRE_DERN_CONFIG_VERSION_PATCH "0"
  
  #define OCTASPIRE_DERN_CONFIG_VERSION_STR "Octaspire Dern version " \


@@ 26987,6 26987,10 @@ bool octaspire_dern_value_as_boolean_get_value(
      octaspire_dern_value_t const * const self);
  
+ void octaspire_dern_value_as_boolean_set_value(
+     octaspire_dern_value_t * const self,
+     bool const value);
+ 
  int32_t octaspire_dern_value_as_integer_get_value(
      octaspire_dern_value_t const * const self);
  


@@ 46409,6 46413,14 @@ return self->value.boolean;
  }
  
+ void octaspire_dern_value_as_boolean_set_value(
+     octaspire_dern_value_t * const self,
+     bool const value)
+ {
+     octaspire_helpers_verify_true(self->typeTag == OCTASPIRE_DERN_VALUE_TAG_BOOLEAN);
+     self->value.boolean = value;
+ }
+ 
  int32_t octaspire_dern_value_as_integer_get_value(
      octaspire_dern_value_t const * const self)
  {

M release/plugins/dern_nuklear.c => release/plugins/dern_nuklear.c +251 -0
@@ 398,6 398,192 @@ return octaspire_dern_vm_create_new_value_boolean(vm, true);
  }
  
+ octaspire_dern_value_t *dern_nuklear_button_label(
+     octaspire_dern_vm_t * const vm,
+     octaspire_dern_value_t * const arguments,
+     octaspire_dern_value_t * const environment)
+ {
+     OCTASPIRE_HELPERS_UNUSED_PARAMETER(environment);
+ 
+     size_t const stackLength = octaspire_dern_vm_get_stack_length(vm);
+     char   const * const dernFuncName    = "nuklear-button-label";
+     char   const * const ctxName         = "ctx";
+     size_t const         numExpectedArgs = 2;
+ 
+     size_t const numArgs =
+         octaspire_dern_value_as_vector_get_length(arguments);
+ 
+     if (numArgs != numExpectedArgs)
+     {
+         octaspire_helpers_verify_true(
+             stackLength == octaspire_dern_vm_get_stack_length(vm));
+ 
+         return octaspire_dern_vm_create_new_value_error_format(
+             vm,
+             "Builtin '%s' expects %zu arguments. "
+             "%zu arguments were given.",
+             dernFuncName,
+             numExpectedArgs,
+             numArgs);
+     }
+ 
+     // ctx
+ 
+     octaspire_dern_c_data_or_unpushed_error_t cDataOrError =
+         octaspire_dern_value_as_vector_get_element_at_as_c_data_or_unpushed_error_const(
+             arguments,
+             0,
+             dernFuncName,
+             ctxName,
+             DERN_NUKLEAR_PLUGIN_NAME);
+ 
+     if (cDataOrError.unpushedError)
+     {
+         octaspire_helpers_verify_true(
+             stackLength == octaspire_dern_vm_get_stack_length(vm));
+ 
+         return cDataOrError.unpushedError;
+     }
+ 
+     struct nk_context * const ctx = cDataOrError.cData;
+ 
+     octaspire_helpers_verify_not_null(ctx);
+ 
+     // text
+ 
+     octaspire_dern_value_t const * const secondArg =
+         octaspire_dern_value_as_vector_get_element_at_const(arguments, 1);
+ 
+     octaspire_helpers_verify_not_null(secondArg);
+ 
+     if (!octaspire_dern_value_is_text(secondArg))
+     {
+         octaspire_helpers_verify_true(
+             stackLength == octaspire_dern_vm_get_stack_length(vm));
+ 
+         return octaspire_dern_vm_create_new_value_error_format(
+             vm,
+             "Builtin '%s' expects text (string or symbol) as the second "
+             "argument. Type '%s' was given.",
+             dernFuncName,
+             octaspire_dern_value_helper_get_type_as_c_string(secondArg->typeTag));
+     }
+ 
+     char const * const text = octaspire_dern_value_as_text_get_c_string(secondArg);
+ 
+     bool const result = nk_button_label(ctx, text);
+ 
+     octaspire_helpers_verify_true(
+         stackLength == octaspire_dern_vm_get_stack_length(vm));
+ 
+     return octaspire_dern_vm_create_new_value_boolean(vm, result);
+ }
+ 
+ octaspire_dern_value_t *dern_nuklear_checkbox_label(
+     octaspire_dern_vm_t * const vm,
+     octaspire_dern_value_t * const arguments,
+     octaspire_dern_value_t * const environment)
+ {
+     OCTASPIRE_HELPERS_UNUSED_PARAMETER(environment);
+ 
+     size_t const stackLength = octaspire_dern_vm_get_stack_length(vm);
+     char   const * const dernFuncName    = "nuklear-checkbox-label";
+     char   const * const ctxName         = "ctx";
+     size_t const         numExpectedArgs = 3;
+ 
+     size_t const numArgs =
+         octaspire_dern_value_as_vector_get_length(arguments);
+ 
+     if (numArgs != numExpectedArgs)
+     {
+         octaspire_helpers_verify_true(
+             stackLength == octaspire_dern_vm_get_stack_length(vm));
+ 
+         return octaspire_dern_vm_create_new_value_error_format(
+             vm,
+             "Builtin '%s' expects %zu arguments. "
+             "%zu arguments were given.",
+             dernFuncName,
+             numExpectedArgs,
+             numArgs);
+     }
+ 
+     // ctx
+ 
+     octaspire_dern_c_data_or_unpushed_error_t cDataOrError =
+         octaspire_dern_value_as_vector_get_element_at_as_c_data_or_unpushed_error_const(
+             arguments,
+             0,
+             dernFuncName,
+             ctxName,
+             DERN_NUKLEAR_PLUGIN_NAME);
+ 
+     if (cDataOrError.unpushedError)
+     {
+         octaspire_helpers_verify_true(
+             stackLength == octaspire_dern_vm_get_stack_length(vm));
+ 
+         return cDataOrError.unpushedError;
+     }
+ 
+     struct nk_context * const ctx = cDataOrError.cData;
+ 
+     octaspire_helpers_verify_not_null(ctx);
+ 
+     // text
+ 
+     octaspire_dern_value_t const * const secondArg =
+         octaspire_dern_value_as_vector_get_element_at_const(arguments, 1);
+ 
+     octaspire_helpers_verify_not_null(secondArg);
+ 
+     if (!octaspire_dern_value_is_text(secondArg))
+     {
+         octaspire_helpers_verify_true(
+             stackLength == octaspire_dern_vm_get_stack_length(vm));
+ 
+         return octaspire_dern_vm_create_new_value_error_format(
+             vm,
+             "Builtin '%s' expects text (string or symbol) as the second "
+             "argument. Type '%s' was given.",
+             dernFuncName,
+             octaspire_dern_value_helper_get_type_as_c_string(secondArg->typeTag));
+     }
+ 
+     char const * const text = octaspire_dern_value_as_text_get_c_string(secondArg);
+ 
+     // active
+ 
+     octaspire_dern_value_t * const thirdArg =
+         octaspire_dern_value_as_vector_get_element_at(arguments, 2);
+ 
+     octaspire_helpers_verify_not_null(thirdArg);
+ 
+     if (!octaspire_dern_value_is_boolean(thirdArg))
+     {
+         octaspire_helpers_verify_true(
+             stackLength == octaspire_dern_vm_get_stack_length(vm));
+ 
+         return octaspire_dern_vm_create_new_value_error_format(
+             vm,
+             "Builtin '%s' expects boolean as the third "
+             "argument. Type '%s' was given.",
+             dernFuncName,
+             octaspire_dern_value_helper_get_type_as_c_string(thirdArg->typeTag));
+     }
+ 
+     int active = octaspire_dern_value_as_boolean_get_value(thirdArg);
+ 
+     bool const result = nk_checkbox_label(ctx, text, &active);
+ 
+     octaspire_dern_value_as_boolean_set_value(thirdArg, active == nk_true);
+ 
+     octaspire_helpers_verify_true(
+         stackLength == octaspire_dern_vm_get_stack_length(vm));
+ 
+     return octaspire_dern_vm_create_new_value_boolean(vm, result);
+ }
+ 
  octaspire_dern_value_t *dern_nuklear_progress(
      octaspire_dern_vm_t * const vm,
      octaspire_dern_value_t * const arguments,


@@ 1334,6 1520,70 @@       if (!octaspire_dern_vm_create_and_register_new_builtin(
              vm,
+             "nuklear-button-label",
+             dern_nuklear_button_label,
+             2,
+             "NAME\n"
+             "\tnuklear-button-label\n"
+             "\n"
+             "SYNOPSIS\n"
+             "\t(require 'dern_nuklear)\n"
+             "\n"
+             "\t(nuklear-button-label ctx text) -> true/false or error\n"
+             "\n"
+             "DESCRIPTION\n"
+             "\tDisplay a button label\n"
+             "\n"
+             "ARGUMENTS\n"
+             "\tctx           nuklear context.\n"
+             "\ttext          text to be shown.\n"
+             "\n"
+             "RETURN VALUE\n"
+             "\ttrue/false or error if something went wrong.\n"
+             "\n"
+             "SEE ALSO\n"
+             "\tnuklear-begin\n",
+             false,
+             targetEnv))
+     {
+         return false;
+     }
+ 
+     if (!octaspire_dern_vm_create_and_register_new_builtin(
+             vm,
+             "nuklear-checkbox-label",
+             dern_nuklear_checkbox_label,
+             3,
+             "NAME\n"
+             "\tnuklear-checkbox-label\n"
+             "\n"
+             "SYNOPSIS\n"
+             "\t(require 'dern_nuklear)\n"
+             "\n"
+             "\t(nuklear-checkbox-label ctx text active) -> true/false or error\n"
+             "\n"
+             "DESCRIPTION\n"
+             "\tDisplay a checkbox label\n"
+             "\n"
+             "ARGUMENTS\n"
+             "\tctx           nuklear context.\n"
+             "\ttext          text to be shown.\n"
+             "\tactive        the state before and after.\n"
+             "\n"
+             "RETURN VALUE\n"
+             "\ttrue if checkbox was toggled, false otherwise "
+             "\t(or error if something went wrong).\n"
+             "\n"
+             "SEE ALSO\n"
+             "\tnuklear-begin\n",
+             false,
+             targetEnv))
+     {
+         return false;
+     }
+ 
+     if (!octaspire_dern_vm_create_and_register_new_builtin(
+             vm,
              "nuklear-progress",
              dern_nuklear_progress,
              4,


@@ 1620,3 1870,4 @@       return true;
  }
+ 

M release/plugins/external/nuklear/nuklear.h => release/plugins/external/nuklear/nuklear.h +4 -3
@@ 12149,7 12149,8 @@ int x_off, int y_off, int invert, struct nk_allocator *alloc)
  {
      float scale = scale_x > scale_y ? scale_y : scale_x;
-     int winding_count, *winding_lengths;
+     int winding_count = 0;
+     int *winding_lengths = 0;
      struct nk_tt__point *windings = nk_tt_FlattenCurves(vertices, num_verts,
          flatness_in_pixels / scale, &winding_lengths, &winding_count, alloc);
  


@@ 13064,7 13065,7 @@ #ifdef __clang__
  #pragma clang diagnostic push
  #pragma clang diagnostic ignored "-Woverlength-strings"
- #elif defined(__GNUC__) || defined(__GNUG__)
+ #elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || defined(__GNUG__)
  #pragma GCC diagnostic push
  #pragma GCC diagnostic ignored "-Woverlength-strings"
  #endif


@@ 13196,7 13197,7 @@   #ifdef __clang__
  #pragma clang diagnostic pop
- #elif defined(__GNUC__) || defined(__GNUG__)
+ #elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || defined(__GNUG__)
  #pragma GCC diagnostic pop
  #endif