Ejemplo n.º 1
0
void nk_wnd_main(nk_menu_handle_t *nk, const char* title)
{
   unsigned i;
   video_shader_ctx_t shader_info;
   struct nk_panel layout;
   struct nk_context *ctx = &nk->ctx;
   const int id           = NK_WND_MAIN;
   settings_t *settings  = config_get_ptr();
   char core_basename[PATH_MAX_LENGTH] = {0};

   static char picker_filter[PATH_MAX_LENGTH];
   static char picker_title[PATH_MAX_LENGTH];
   static char* picker_startup_dir;

   int len_core, len_content = 0;

   strlcpy(core_basename, path_basename(core), sizeof(core_basename));

   if (!out)
      out = core;

   if (!string_is_empty(core))
      len_core = strlen(path_basename(core));
   if (!string_is_empty(content))
      len_content = strlen(content);

   if (nk->window[NK_WND_FILE_PICKER].open)
   {
      if (nk_wnd_file_picker(nk, picker_title, picker_startup_dir, out, picker_filter))
      {
         RARCH_LOG ("%s selected\n", out);
         nk_window_close(&nk->ctx, picker_title);
      }
   }


   if (nk_begin(ctx, &layout, title, nk_rect(240, 10, 600, 400),
         NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_MOVABLE|
         NK_WINDOW_SCALABLE|NK_WINDOW_BORDER))
   {
      nk_layout_row_dynamic(ctx, 30, 1);
      nk_label(ctx,"Core:", NK_TEXT_LEFT);
      nk_layout_row(ctx, NK_DYNAMIC, 30, 3, ratio);
      nk_edit_string(ctx, NK_EDIT_SIMPLE, core_basename, &len_core, 64, nk_filter_default);
      if (nk_button_text(ctx, "...", 3, NK_BUTTON_DEFAULT))
      {
         out = core;
         strlcpy(picker_title, "Select core", sizeof(picker_title));
         strlcpy(picker_filter, ".dll", sizeof(picker_filter));
         picker_startup_dir = settings->directory.libretro;
         nk->window[NK_WND_FILE_PICKER].open = true;
      }
      nk_layout_row_dynamic(ctx, 30, 1);
      nk_label(ctx,"Content:", NK_TEXT_LEFT);
      nk_layout_row(ctx, NK_DYNAMIC, 30, 3, ratio);
      nk_edit_string(ctx, NK_EDIT_SIMPLE, content, &len_content, 64, nk_filter_default);
      if (nk_button_text(ctx, "...", 3, NK_BUTTON_DEFAULT))
      {
         out = content;
         strlcpy(picker_title, "Select content", sizeof(picker_title));
         strlcpy(picker_filter, ".zip", sizeof(picker_filter));
         picker_startup_dir = settings->directory.menu_content;
         nk->window[NK_WND_FILE_PICKER].open = true;
      }
   }

   /* save position and size to restore after context reset */
   nk_wnd_set_state(nk, id, nk_window_get_position(ctx), nk_window_get_size(ctx));
   nk_end(ctx);
}
Ejemplo n.º 2
0
bool nk_wnd_file_picker(nk_menu_handle_t *nk, char* title, char* in, char* out, char* filter)
{
   struct nk_panel layout;
   struct nk_context                 *ctx = &nk->ctx;
   const int id                      = NK_WND_FILE_PICKER;
   int i                             = 0;
   static file_list_t *drives        = NULL;
   static struct string_list *files  = NULL;
   settings_t *settings              = config_get_ptr();
   bool ret                          = false;

   if (!drives)
   {
      drives = (file_list_t*)calloc(1, sizeof(file_list_t));
      frontend_driver_parse_drive_list(drives, false);
   }

   if (!string_is_empty(in) && string_is_empty(path))
   {
      strlcpy(path, in, sizeof(path));
      files = dir_list_new(path, filter, true, settings->bools.show_hidden_files, true, false);
   }

   if (!assets_loaded)
      load_icons(nk);

   if (nk_begin(ctx, title, nk_rect(10, 10, 500, 400),
         NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_MOVABLE|
         NK_WINDOW_BORDER))
   {
      nk_layout_row_dynamic(ctx, 30, 4);

      if (drives->size == 0)
      {
         if(nk_button_image_label(ctx, icons.disk, "/", 
            NK_TEXT_CENTERED))
         {
            fill_pathname_join(path, "/",
                  "", sizeof(path));
            files = dir_list_new(path, filter, true, settings->bools.show_hidden_files, true, false);
         }
      }
      else
      {
         for (i = 0; i < drives->size; i++)
         {
            if(nk_button_image_label(ctx, icons.disk, drives->list[i].path, 
               NK_TEXT_CENTERED))
            {
               fill_pathname_join(path, drives->list[i].path,
                     "", sizeof(path));
               files = dir_list_new(path, filter, true, settings->bools.show_hidden_files, true, false);
            }
         }
      }

      nk_layout_row_dynamic(ctx, 30, 1);
      if (files)
      {
         for (i = 0; i < files->size; i++)
         {
            if (nk_button_image_label(ctx, path_is_directory(files->elems[i].data) ? 
               icons.folder : icons.file, path_basename(files->elems[i].data), 
               NK_TEXT_RIGHT))
            {
               strlcpy (path, files->elems[i].data, sizeof(path));
               if (path_is_directory (path))
                  files = dir_list_new(path, filter, true, settings->bools.show_hidden_files, true, false);
            }
         }
      }
      nk_layout_row_dynamic(ctx, 30, 1);
      {
         if (nk_button_text(ctx, "OK", 2))
         {
            ret = true;
            strlcpy(out, path, sizeof(path));
            nk->window[NK_WND_FILE_PICKER].open = false;
            path[0] = '\0';
         }
      }
   }

   /* sort the dir list with directories first */
   dir_list_sort(files, true);

   /* copy the path variable to out*/

   /* save position and size to restore after context reset */
   nk_wnd_set_state(nk, id, nk_window_get_position(ctx), nk_window_get_size(ctx));
   nk_end(ctx);

   return ret;
}
/* nuklear - v1.00 - public domain */
static void
calculator(struct nk_context *ctx)
{
    if (nk_begin(ctx, "Calculator", nk_rect(10, 10, 180, 250),
        NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_MOVABLE))
    {
        static int set = 0, prev = 0, op = 0;
        static const char numbers[] = "789456123";
        static const char ops[] = "+-*/";
        static double a = 0, b = 0;
        static double *current = &a;

        size_t i = 0;
        int solve = 0;
        {int len; char buffer[256];
        nk_layout_row_dynamic(ctx, 35, 1);
        len = snprintf(buffer, 256, "%.2f", *current);
        nk_edit_string(ctx, NK_EDIT_SIMPLE, buffer, &len, 255, nk_filter_float);
        buffer[len] = 0;
        *current = atof(buffer);}

        nk_layout_row_dynamic(ctx, 35, 4);
        for (i = 0; i < 16; ++i) {
            if (i >= 12 && i < 15) {
                if (i > 12) continue;
                if (nk_button_label(ctx, "C")) {
                    a = b = op = 0; current = &a; set = 0;
                } if (nk_button_label(ctx, "0")) {
                    *current = *current*10.0f; set = 0;
                } if (nk_button_label(ctx, "=")) {
                    solve = 1; prev = op; op = 0;
                }
            } else if (((i+1) % 4)) {
                if (nk_button_text(ctx, &numbers[(i/4)*3+i%4], 1)) {
                    *current = *current * 10.0f + numbers[(i/4)*3+i%4] - '0';
                    set = 0;
                }
            } else if (nk_button_text(ctx, &ops[i/4], 1)) {
                if (!set) {
                    if (current != &b) {
                        current = &b;
                    } else {
                        prev = op;
                        solve = 1;
                    }
                }
                op = ops[i/4];
                set = 1;
            }
        }
        if (solve) {
            if (prev == '+') a = a + b;
            if (prev == '-') a = a - b;
            if (prev == '*') a = a * b;
            if (prev == '/') a = a / b;
            current = &a;
            if (set) current = &b;
            b = 0; set = 0;
        }
    }
    nk_end(ctx);
}