[zr] start moving to the new version

This commit is contained in:
radius 2016-04-18 18:00:13 -05:00
parent 47b37e949f
commit ddd8e29d87
4 changed files with 1413 additions and 0 deletions

362
menu/drivers/nk_common.c Normal file
View File

@ -0,0 +1,362 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2016 - Daniel De Matteis
* Copyright (C) 2014-2015 - Jean-Andr<EFBFBD> Santoni
* Copyright (C) 2016 - Andr<EFBFBD>s Su<EFBFBD>rez
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <streams/file_stream.h>
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#include "nk_common.h"
#include "../menu_display.h"
#include "../../gfx/video_shader_driver.h"
#include "../../gfx/drivers/gl_shaders/pipeline_zahnrad.glsl.vert.h"
#include "../../gfx/drivers/gl_shaders/pipeline_zahnrad.glsl.frag.h"
struct nk_font font;
struct nk_user_font usrfnt;
struct nk_allocator nk_alloc;
struct nk_device device;
struct nk_image nk_common_image_load(const char *filename)
{
int x,y,n;
GLuint tex;
unsigned char *data = stbi_load(filename, &x, &y, &n, 0);
if (!data) printf("Failed to load image: %s\n", filename);
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
#endif
stbi_image_free(data);
return nk_image_id((int)tex);
}
char* nk_common_file_load(const char* path, size_t* size)
{
void *buf;
ssize_t *length = (ssize_t*)size;
filestream_read_file(path, &buf, length);
return (char*)buf;
}
NK_API void nk_common_device_init(struct nk_device *dev)
{
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
GLint status;
dev->prog = glCreateProgram();
dev->vert_shdr = glCreateShader(GL_VERTEX_SHADER);
dev->frag_shdr = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(dev->vert_shdr, 1, &zahnrad_vertex_shader, 0);
glShaderSource(dev->frag_shdr, 1, &zahnrad_fragment_shader, 0);
glCompileShader(dev->vert_shdr);
glCompileShader(dev->frag_shdr);
glGetShaderiv(dev->vert_shdr, GL_COMPILE_STATUS, &status);
glGetShaderiv(dev->frag_shdr, GL_COMPILE_STATUS, &status);
glAttachShader(dev->prog, dev->vert_shdr);
glAttachShader(dev->prog, dev->frag_shdr);
glLinkProgram(dev->prog);
glGetProgramiv(dev->prog, GL_LINK_STATUS, &status);
dev->uniform_proj = glGetUniformLocation(dev->prog, "ProjMtx");
dev->attrib_pos = glGetAttribLocation(dev->prog, "Position");
dev->attrib_uv = glGetAttribLocation(dev->prog, "TexCoord");
dev->attrib_col = glGetAttribLocation(dev->prog, "Color");
{
/* buffer setup */
GLsizei vs = sizeof(struct nk_draw_vertex);
size_t vp = offsetof(struct nk_draw_vertex, position);
size_t vt = offsetof(struct nk_draw_vertex, uv);
size_t vc = offsetof(struct nk_draw_vertex, col);
glGenBuffers(1, &dev->vbo);
glGenBuffers(1, &dev->ebo);
glGenVertexArrays(1, &dev->vao);
glBindVertexArray(dev->vao);
glBindBuffer(GL_ARRAY_BUFFER, dev->vbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo);
glEnableVertexAttribArray((GLuint)dev->attrib_pos);
glEnableVertexAttribArray((GLuint)dev->attrib_uv);
glEnableVertexAttribArray((GLuint)dev->attrib_col);
glVertexAttribPointer((GLuint)dev->attrib_pos, 2, GL_FLOAT, GL_FALSE, vs, (void*)vp);
glVertexAttribPointer((GLuint)dev->attrib_uv, 2, GL_FLOAT, GL_FALSE, vs, (void*)vt);
glVertexAttribPointer((GLuint)dev->attrib_col, 4, GL_UNSIGNED_BYTE, GL_TRUE, vs, (void*)vc);
}
glBindTexture(GL_TEXTURE_2D, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindVertexArray(0);
#endif
}
struct nk_user_font nk_common_font(
struct nk_device *dev,
struct nk_font *font,
const char *path,
unsigned int font_height,
const nk_rune *range)
{
int glyph_count;
int img_width, img_height;
struct nk_font_glyph *glyphes;
struct nk_baked_font baked_font;
struct nk_user_font user_font;
struct nk_recti custom;
memset(&baked_font, 0, sizeof(baked_font));
memset(&user_font, 0, sizeof(user_font));
memset(&custom, 0, sizeof(custom));
{
struct texture_image ti;
/* bake and upload font texture */
struct nk_font_config config;
void *img, *tmp;
size_t ttf_size;
size_t tmp_size, img_size;
const char *custom_data = "....";
char *ttf_blob = nk_common_file_load(path, &ttf_size);
/* setup font configuration */
memset(&config, 0, sizeof(config));
config.ttf_blob = ttf_blob;
config.ttf_size = ttf_size;
config.font = &baked_font;
config.coord_type = NK_COORD_UV;
config.range = range;
config.pixel_snap = nk_false;
config.size = (float)font_height;
config.spacing = nk_vec2(0,0);
config.oversample_h = 1;
config.oversample_v = 1;
/* query needed amount of memory for the font baking process */
nk_font_bake_memory(&tmp_size, &glyph_count, &config, 1);
glyphes = (struct nk_font_glyph*)
calloc(sizeof(struct nk_font_glyph), (size_t)glyph_count);
tmp = calloc(1, tmp_size);
/* pack all glyphes and return needed image width, height and memory size*/
custom.w = 2; custom.h = 2;
nk_font_bake_pack(&img_size,
&img_width,&img_height,&custom,tmp,tmp_size,&config, 1, &nk_alloc);
/* bake all glyphes and custom white pixel into image */
img = calloc(1, img_size);
nk_font_bake(img, img_width,
img_height, tmp, tmp_size, glyphes, glyph_count, &config, 1);
nk_font_bake_custom_data(img,
img_width, img_height, custom, custom_data, 2, 2, '.', 'X');
{
/* convert alpha8 image into rgba8 image */
void *img_rgba = calloc(4, (size_t)(img_height * img_width));
nk_font_bake_convert(img_rgba, img_width, img_height, img);
free(img);
img = img_rgba;
}
/* upload baked font image */
ti.pixels = (uint32_t*)img;
ti.width = (GLsizei)img_width;
ti.height = (GLsizei)img_height;
video_driver_texture_load(&ti,
TEXTURE_FILTER_MIPMAP_NEAREST, (uintptr_t*)&dev->font_tex);
free(ttf_blob);
free(tmp);
free(img);
}
/* default white pixel in a texture which is needed to draw primitives */
dev->null.texture.id = (int)dev->font_tex;
dev->null.uv = nk_vec2((custom.x + 0.5f)/(float)img_width,
(custom.y + 0.5f)/(float)img_height);
/* setup font with glyphes. IMPORTANT: the font only references the glyphes
this was done to have the possibility to have multible fonts with one
total glyph array. Not quite sure if it is a good thing since the
glyphes have to be freed as well. */
nk_font_init(font,
(float)font_height, '?', glyphes,
&baked_font, dev->null.texture);
user_font = nk_font_ref(font);
return user_font;
}
void nk_common_device_shutdown(struct nk_device *dev)
{
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
glDetachShader(dev->prog, dev->vert_shdr);
glDetachShader(dev->prog, dev->frag_shdr);
glDeleteShader(dev->vert_shdr);
glDeleteShader(dev->frag_shdr);
glDeleteProgram(dev->prog);
glDeleteTextures(1, &dev->font_tex);
glDeleteBuffers(1, &dev->vbo);
glDeleteBuffers(1, &dev->ebo);
#endif
}
void nk_common_device_draw(struct nk_device *dev,
struct nk_context *ctx, int width, int height,
enum nk_anti_aliasing AA)
{
video_shader_ctx_info_t shader_info;
struct nk_buffer vbuf, ebuf;
struct nk_convert_config config;
uintptr_t last_prog;
const struct nk_draw_command *cmd = NULL;
void *vertices = NULL;
void *elements = NULL;
const nk_draw_index *offset = NULL;
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
GLint last_tex;
GLint last_ebo, last_vbo, last_vao;
GLfloat ortho[4][4] = {
{2.0f, 0.0f, 0.0f, 0.0f},
{0.0f,-2.0f, 0.0f, 0.0f},
{0.0f, 0.0f,-1.0f, 0.0f},
{-1.0f,1.0f, 0.0f, 1.0f},
};
ortho[0][0] /= (GLfloat)width;
ortho[1][1] /= (GLfloat)height;
/* save previous opengl state */
glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&last_prog);
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_tex);
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_vao);
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_ebo);
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vbo);
#endif
menu_display_ctl(MENU_DISPLAY_CTL_BLEND_BEGIN, NULL);
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
glActiveTexture(GL_TEXTURE0);
#endif
/* setup program */
shader_info.data = NULL;
shader_info.idx = dev->prog;
shader_info.set_active = false;
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
glUniformMatrix4fv(dev->uniform_proj, 1, GL_FALSE, &ortho[0][0]);
/* convert from command queue into draw list and draw to screen */
/* allocate vertex and element buffer */
glBindVertexArray(dev->vao);
glBindBuffer(GL_ARRAY_BUFFER, dev->vbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo);
glBufferData(GL_ARRAY_BUFFER, MAX_VERTEX_MEMORY, NULL, GL_STREAM_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_ELEMENT_MEMORY, NULL, GL_STREAM_DRAW);
/* load draw vertices & elements directly into vertex + element buffer */
vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
#endif
/* fill converting configuration */
memset(&config, 0, sizeof(config));
config.global_alpha = 1.0f;
config.shape_AA = AA;
config.line_AA = AA;
config.circle_segment_count = 22;
config.line_thickness = 1.0f;
config.null = dev->null;
/* setup buffers to load vertices and elements */
nk_buffer_init_fixed(&vbuf, vertices, MAX_VERTEX_MEMORY);
nk_buffer_init_fixed(&ebuf, elements, MAX_ELEMENT_MEMORY);
nk_convert(ctx, &dev->cmds, &vbuf, &ebuf, &config);
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
glUnmapBuffer(GL_ARRAY_BUFFER);
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
#endif
/* iterate over and execute each draw command */
nk_draw_foreach(cmd, ctx, &dev->cmds)
{
if (!cmd->elem_count)
continue;
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.id);
glScissor((GLint)cmd->clip_rect.x,
height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h),
(GLint)cmd->clip_rect.w, (GLint)cmd->clip_rect.h);
glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count,
GL_UNSIGNED_SHORT, offset);
#endif
offset += cmd->elem_count;
}
nk_clear(ctx);
/* restore old state */
shader_info.data = NULL;
shader_info.idx = (GLint)last_prog;
shader_info.set_active = false;
video_shader_driver_ctl(SHADER_CTL_USE, &shader_info);
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
glBindTexture(GL_TEXTURE_2D, (GLuint)last_tex);
glBindBuffer(GL_ARRAY_BUFFER, (GLuint)last_vbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, (GLuint)last_ebo);
glBindVertexArray((GLuint)last_vao);
#endif
menu_display_ctl(MENU_DISPLAY_CTL_BLEND_END, NULL);
}
void* nk_common_mem_alloc(nk_handle unused, size_t size)
{
(void)unused;
return calloc(1, size);
}
void nk_common_mem_free(nk_handle unused, void *ptr)
{
(void)unused;
free(ptr);
}

83
menu/drivers/nk_common.h Normal file
View File

@ -0,0 +1,83 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2016 - Daniel De Matteis
* Copyright (C) 2014-2015 - Jean-André Santoni
* Copyright (C) 2016 - Andrés Suárez
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#define NK_IMPLEMENTATION
#include "../../deps/zahnrad/nuklear.h"
#include "../../deps/stb/stb_image.h"
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
#include "../../gfx/common/gl_common.h"
#endif
#define MAX_VERTEX_MEMORY (512 * 1024)
#define MAX_ELEMENT_MEMORY (128 * 1024)
#define NK_SYSTEM_TAB_END NK_SYSTEM_TAB_SETTINGS
struct nk_device
{
struct nk_buffer cmds;
struct nk_draw_null_texture null;
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
GLuint vbo, vao, ebo;
GLuint prog;
GLuint vert_shdr;
GLuint frag_shdr;
GLint attrib_pos;
GLint attrib_uv;
GLint attrib_col;
GLint uniform_proj;
GLuint font_tex;
#endif
};
extern struct nk_font font;
extern struct nk_user_font usrfnt;
extern struct nk_allocator nk_alloc;
extern struct nk_device device;
struct nk_image nk_common_image_load(const char *filename);
char* nk_common_file_load(const char* path, size_t* size);
void nk_common_device_init(struct nk_device *dev);
struct nk_user_font nk_common_font(
struct nk_device *dev,
struct nk_font *font,
const char *path,
unsigned int font_height,
const nk_rune *range);
void nk_common_device_shutdown(struct nk_device *dev);
void nk_common_device_draw(struct nk_device *dev,
struct nk_context *ctx, int width, int height,
enum nk_anti_aliasing AA);
void* nk_common_mem_alloc(nk_handle unused, size_t size);
void nk_common_mem_free(nk_handle unused, void *ptr);

868
menu/drivers/nk_menu.c Normal file
View File

@ -0,0 +1,868 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2016 - Daniel De Matteis
* Copyright (C) 2014-2015 - Jean-André Santoni
* Copyright (C) 2016 - Andrés Suárez
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "nk_menu.h"
#include <stdint.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <file/file_path.h>
#include <string/stdstring.h>
#include <lists/string_list.h>
#include "../menu_driver.h"
#include "../menu_hash.h"
#include "../../gfx/common/gl_common.h"
#include "../../core_info.h"
#include "../../configuration.h"
#include "../../retroarch.h"
#define LEN(a) (sizeof(a)/sizeof(a)[0])
/* gamepad demo variables */
enum widget_id
{
WINDOW_MODE = 0,
MODEL_DETAIL,
TEXTURES,
SHADOWS,
LIGHTNING,
EFFECTS,
CONSOLE,
BRIGHTNESS,
VOLUME,
WIDGET_MAX
};
enum display_settings {
WINDOWED = 0, FULLSCREEN};
enum detail_settings {LOW, MEDIUM, HIGH, EXTRA_HIGH};
enum state_settings {OFF, ON};
const char *display[] = {"Windowed", "Fullscreen"};
const char *state[] = {"Off", "On"};
const char *detail[] = {"Low", "Medium", "High", "Extra High"};
static int window_mode = FULLSCREEN;
static int model_detail = HIGH;
static int texture_detail = EXTRA_HIGH;
static int shadow_detail = HIGH;
static int lighning_detail = LOW;
static int effects_detail = MEDIUM;
static int show_console = ON;
static int brightness = 90;
static int volume = 30;
static int active = WINDOW_MODE;
/* end of gamepad demo variables */
static int ui_selector(struct nk_context *ctx, const char *title, int *selected, const char *items[],
int max, int active)
{
struct nk_vec2 item_padding;
struct nk_rect bounds, label, content, tri, sel;
struct nk_panel *layout;
struct nk_command_buffer *out;
struct nk_color col;
struct nk_vec2 result[3];
nk_size text_len, text_width;
if (!ctx || !ctx->current)
return 0;
layout = nk_window_get_panel(ctx);
out = nk_window_get_canvas(ctx);
if (!nk_widget(&bounds, ctx))
return 0;
item_padding = nk_get_property(ctx, NK_PROPERTY_ITEM_PADDING);
bounds.x += item_padding.x;
bounds.y += item_padding.y;
bounds.w -= 2 * item_padding.x;
bounds.h -= 2 * item_padding.y;
label.h = bounds.h;
label.w = bounds.w / 2.0f;
label.x = bounds.x + item_padding.x;
label.y = bounds.y + label.h/2.0f - (float)ctx->style.font.height/2.0f;
content.x = bounds.x + bounds.w/2.0f;
content.y = bounds.y;
content.w = bounds.w / 2.0f;
content.h = bounds.h;
if (active) nk_draw_rect(out, bounds, 0, nk_rgba(220, 220, 220, 135));
text_len = strlen(title);
col = (active) ? nk_rgba(0, 0, 0, 255): nk_rgba(220,220,220,220);
nk_draw_text(out, label, title, text_len, &ctx->style.font, nk_rgba(0,0,0,0), col);
if (nk_input_is_key_pressed(&ctx->input, NK_KEY_RIGHT) && active)
*selected = MIN(*selected+1, max-1);
else if (nk_input_is_key_pressed(&ctx->input, NK_KEY_LEFT) && active)
*selected = MAX(0, *selected-1);
tri.h = ctx->style.font.height - 2 * item_padding.y;
tri.w = tri.h/2.0f;
tri.x = content.x + item_padding.x;
tri.y = content.y + content.h/2 - tri.h/2.0f;
sel.x = tri.x + item_padding.x;
sel.y = tri.y;
sel.h = content.h;
if (*selected > 0) {
nk_triangle_from_direction(result, tri, 0, 0, NK_LEFT);
nk_draw_triangle(out, result[0].x, result[0].y, result[1].x, result[1].y,
result[2].x, result[2].y, (active) ? nk_rgba(0, 0, 0, 255):
nk_rgba(100, 100, 100, 150));
}
tri.x = content.x + (content.w - item_padding.x) - tri.w;
sel.w = tri.x - sel.x;
if (*selected < max-1) {
nk_triangle_from_direction(result, tri, 0, 0, NK_RIGHT);
nk_draw_triangle(out, result[0].x, result[0].y, result[1].x, result[1].y,
result[2].x, result[2].y, (active) ? nk_rgba(0, 0, 0, 255):
nk_rgba(100, 100, 100, 150));
}
text_width = ctx->style.font.width(ctx->style.font.userdata,
ctx->style.font.height, items[*selected], strlen(items[*selected]));
label.w = MAX(1, (float)text_width);
label.x = (sel.x + (sel.w - label.w) / 2);
label.x = MAX(sel.x, label.x);
label.w = MIN(sel.x + sel.w, label.x + label.w);
if (label.w >= label.x) label.w -= label.x;
nk_draw_text(out, label, items[*selected], strlen(items[*selected]),
&ctx->style.font, nk_rgba(0,0,0,0), col);
return 0;
}
static void ui_slider(struct nk_context *ctx, const char *title, int *value, int max, int active)
{
struct nk_vec2 item_padding;
struct nk_rect bounds, label, content, bar, cursor, tri;
struct nk_panel *layout;
struct nk_command_buffer *out;
struct nk_color col;
nk_size text_len, text_width;
float prog_scale = (float)*value / (float)max;
struct nk_vec2 result[3];
if (!ctx || !ctx->current)
return;
layout = nk_window_get_panel(ctx);
out = nk_window_get_canvas(ctx);
if (!nk_widget(&bounds, ctx))
return;
item_padding = nk_get_property(ctx, NK_PROPERTY_ITEM_PADDING);
bounds.x += item_padding.x;
bounds.y += item_padding.y;
bounds.w -= 2 * item_padding.x;
bounds.h -= 2 * item_padding.y;
label.h = bounds.h;
label.w = bounds.w / 2.0f;
label.x = bounds.x + item_padding.x;
label.y = bounds.y + label.h/2.0f - (float)ctx->style.font.height/2.0f;
content.x = bounds.x + bounds.w/2.0f;
content.y = bounds.y;
content.w = bounds.w / 2.0f;
content.h = bounds.h;
if (active) nk_draw_rect(out, bounds, 0, nk_rgba(220, 220, 220, 135));
text_len = strlen(title);
col = (active) ? nk_rgba(0, 0, 0, 255): nk_rgba(220,220,220,220);
nk_draw_text(out, label, title, text_len, &ctx->style.font, nk_rgba(0,0,0,0), col);
if (nk_input_is_key_pressed(&ctx->input, NK_KEY_LEFT) && active)
*value = MAX(0, *value - 10);
if (nk_input_is_key_pressed(&ctx->input, NK_KEY_RIGHT) && active)
*value = MIN(*value + 10, max);
tri.h = ctx->style.font.height - 2 * item_padding.y;
tri.w = tri.h/2.0f;
tri.x = content.x + item_padding.x;
tri.y = content.y + content.h/2 - tri.h/2.0f;
bar.x = tri.x + 4 * item_padding.x + tri.w;
bar.h = tri.h / 4.0f;
bar.y = tri.y + tri.h/2.0f - bar.h/2.0f;
if (*value > 0) {
nk_triangle_from_direction(result, tri, 0, 0, NK_LEFT);
nk_draw_triangle(out, result[0].x, result[0].y, result[1].x, result[1].y,
result[2].x, result[2].y, (active) ? nk_rgba(0, 0, 0, 255):
nk_rgba(100, 100, 100, 150));
}
tri.x = content.x + (content.w - item_padding.x) - tri.w;
bar.w = (tri.x - bar.x) - 4 * item_padding.x;
if (*value < max)
{
nk_triangle_from_direction(result, tri, 0, 0, NK_RIGHT);
nk_draw_triangle(out, result[0].x, result[0].y, result[1].x, result[1].y,
result[2].x, result[2].y, (active) ? nk_rgba(0, 0, 0, 255):
nk_rgba(100, 100, 100, 150));
}
bar.w = (bar.w - tri.h/2.0f);
if (active)
{
nk_draw_rect(out, bar, 0, nk_rgba(0, 0, 0, 135));
bar.w = bar.w * prog_scale;
bar.y = tri.y; bar.x = bar.x + bar.w; bar.w = tri.h; bar.h = tri.h;
nk_draw_circle(out, bar, nk_rgba(220, 220, 220, 255));
}
else
{
nk_draw_rect(out, bar, 0, nk_rgba(220, 220, 220, 135));
bar.w = bar.w * prog_scale;
bar.y = tri.y; bar.x = bar.x + bar.w; bar.w = tri.h; bar.h = tri.h;
nk_draw_circle(out, bar, nk_rgba(190, 190, 190, 255));
}
}
bool nk_checkbox_bool(struct nk_context* cx, const char* text, bool *active)
{
int x = *active;
bool ret = nk_checkbox(cx, text, &x);
*active = x;
return ret;
}
float nk_checkbox_float(struct nk_context* cx, const char* text, float *active)
{
int x = *active;
float ret = nk_checkbox(cx, text, &x);
*active = x;
return ret;
}
static void nk_labelf(struct nk_context *ctx,
enum nk_text_align align, const char *fmt, ...)
{
char buffer[1024];
va_list args;
va_start(args, fmt);
vsnprintf(buffer, sizeof(buffer), fmt, args);
buffer[1023] = 0;
nk_label(ctx, buffer, align);
va_end(args);
}
void zrmenu_set_style(struct nk_context *ctx, enum zrmenu_theme theme)
{
unsigned i;
for (i = 0; i < NK_ROUNDING_MAX; ++i)
(ctx)->style.rounding[i] = 0;
switch (theme)
{
case THEME_LIGHT:
ctx->style.rounding[NK_ROUNDING_SCROLLBAR] = 0;
ctx->style.properties[NK_PROPERTY_SCROLLBAR_SIZE] = nk_vec2(10,10);
ctx->style.colors[NK_COLOR_TEXT] = nk_rgba(20, 20, 20, 255);
ctx->style.colors[NK_COLOR_TEXT_HOVERING] = nk_rgba(195, 195, 195, 255);
ctx->style.colors[NK_COLOR_TEXT_ACTIVE] = nk_rgba(200, 200, 200, 255);
ctx->style.colors[NK_COLOR_WINDOW] = nk_rgba(202, 212, 214, 215);
ctx->style.colors[NK_COLOR_HEADER] = nk_rgba(137, 182, 224, 220);
ctx->style.colors[NK_COLOR_BORDER] = nk_rgba(140, 159, 173, 0);
ctx->style.colors[NK_COLOR_BUTTON] = nk_rgba(137, 182, 224, 255);
ctx->style.colors[NK_COLOR_BUTTON_HOVER] = nk_rgba(142, 187, 229, 255);
ctx->style.colors[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(147, 192, 234, 255);
ctx->style.colors[NK_COLOR_TOGGLE] = nk_rgba(177, 210, 210, 255);
ctx->style.colors[NK_COLOR_TOGGLE_HOVER] = nk_rgba(245, 245, 245, 255);
ctx->style.colors[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(142, 187, 229, 255);
ctx->style.colors[NK_COLOR_SELECTABLE] = nk_rgba(147, 192, 234, 255);
ctx->style.colors[NK_COLOR_SELECTABLE_HOVER] = nk_rgba(150, 150, 150, 255);
ctx->style.colors[NK_COLOR_SELECTABLE_TEXT] = nk_rgba(70, 70, 70, 255);
ctx->style.colors[NK_COLOR_SLIDER] = nk_rgba(177, 210, 210, 255);
ctx->style.colors[NK_COLOR_SLIDER_CURSOR] = nk_rgba(137, 182, 224, 245);
ctx->style.colors[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(142, 188, 229, 255);
ctx->style.colors[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(147, 193, 234, 255);
ctx->style.colors[NK_COLOR_PROGRESS] = nk_rgba(177, 210, 210, 255);
ctx->style.colors[NK_COLOR_PROGRESS_CURSOR] = nk_rgba(137, 182, 224, 255);
ctx->style.colors[NK_COLOR_PROGRESS_CURSOR_HOVER] = nk_rgba(142, 188, 229, 255);
ctx->style.colors[NK_COLOR_PROGRESS_CURSOR_ACTIVE] = nk_rgba(147, 193, 234, 255);
ctx->style.colors[NK_COLOR_PROPERTY] = nk_rgba(210, 210, 210, 255);
ctx->style.colors[NK_COLOR_PROPERTY_HOVER] = nk_rgba(235, 235, 235, 255);
ctx->style.colors[NK_COLOR_PROPERTY_ACTIVE] = nk_rgba(230, 230, 230, 255);
ctx->style.colors[NK_COLOR_INPUT] = nk_rgba(210, 210, 210, 225);
ctx->style.colors[NK_COLOR_INPUT_CURSOR] = nk_rgba(20, 20, 20, 255);
ctx->style.colors[NK_COLOR_INPUT_TEXT] = nk_rgba(20, 20, 20, 255);
ctx->style.colors[NK_COLOR_COMBO] = nk_rgba(210, 210, 210, 255);
ctx->style.colors[NK_COLOR_HISTO] = nk_rgba(210, 210, 210, 255);
ctx->style.colors[NK_COLOR_HISTO_BARS] = nk_rgba(137, 182, 224, 255);
ctx->style.colors[NK_COLOR_HISTO_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255);
ctx->style.colors[NK_COLOR_PLOT] = nk_rgba(210, 210, 210, 255);
ctx->style.colors[NK_COLOR_PLOT_LINES] = nk_rgba(137, 182, 224, 255);
ctx->style.colors[NK_COLOR_PLOT_HIGHLIGHT] = nk_rgba(255, 0, 0, 255);
ctx->style.colors[NK_COLOR_SCROLLBAR] = nk_rgba(190, 200, 200, 255);
ctx->style.colors[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(64, 84, 95, 255);
ctx->style.colors[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255);
ctx->style.colors[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255);
ctx->style.colors[NK_COLOR_TABLE_LINES] = nk_rgba(100, 100, 100, 255);
ctx->style.colors[NK_COLOR_TAB_HEADER] = nk_rgba(156, 193, 220, 255);
ctx->style.colors[NK_COLOR_SCALER] = nk_rgba(100, 100, 100, 255);
break;
case THEME_DARK:
ctx->style.rounding[NK_ROUNDING_SCROLLBAR] = 0;
ctx->style.properties[NK_PROPERTY_SCROLLBAR_SIZE] = nk_vec2(10,10);
ctx->style.colors[NK_COLOR_TEXT] = nk_rgba(210, 210, 210, 255);
ctx->style.colors[NK_COLOR_TEXT_HOVERING] = nk_rgba(195, 195, 195, 255);
ctx->style.colors[NK_COLOR_TEXT_ACTIVE] = nk_rgba(200, 200, 200, 255);
ctx->style.colors[NK_COLOR_WINDOW] = nk_rgba(45, 53, 56, 215);
ctx->style.colors[NK_COLOR_HEADER] = nk_rgba(46, 46, 46, 255);
ctx->style.colors[NK_COLOR_BORDER] = nk_rgba(46, 46, 46, 0);
ctx->style.colors[NK_COLOR_BUTTON] = nk_rgba(48, 83, 111, 255);
ctx->style.colors[NK_COLOR_BUTTON_HOVER] = nk_rgba(53, 88, 116, 255);
ctx->style.colors[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(58, 93, 121, 255);
ctx->style.colors[NK_COLOR_TOGGLE] = nk_rgba(50, 58, 61, 255);
ctx->style.colors[NK_COLOR_TOGGLE_HOVER] = nk_rgba(55, 63, 66, 255);
ctx->style.colors[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(48, 83, 111, 255);
ctx->style.colors[NK_COLOR_SELECTABLE] = nk_rgba(48, 83, 111, 255);
ctx->style.colors[NK_COLOR_SELECTABLE_HOVER] = nk_rgba(48, 83, 111, 255);
ctx->style.colors[NK_COLOR_SELECTABLE_TEXT] = nk_rgba(210, 210, 210, 255);
ctx->style.colors[NK_COLOR_SLIDER] = nk_rgba(50, 58, 61, 255);
ctx->style.colors[NK_COLOR_SLIDER_CURSOR] = nk_rgba(48, 83, 111, 245);
ctx->style.colors[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255);
ctx->style.colors[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255);
ctx->style.colors[NK_COLOR_PROGRESS] = nk_rgba(50, 58, 61, 255);
ctx->style.colors[NK_COLOR_PROGRESS_CURSOR] = nk_rgba(48, 83, 111, 255);
ctx->style.colors[NK_COLOR_PROGRESS_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255);
ctx->style.colors[NK_COLOR_PROGRESS_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255);
ctx->style.colors[NK_COLOR_PROPERTY] = nk_rgba(50, 58, 61, 255);
ctx->style.colors[NK_COLOR_PROPERTY_HOVER] = nk_rgba(55, 63, 66, 255);
ctx->style.colors[NK_COLOR_PROPERTY_ACTIVE] = nk_rgba(60, 68, 71, 255);
ctx->style.colors[NK_COLOR_INPUT] = nk_rgba(50, 58, 61, 225);
ctx->style.colors[NK_COLOR_INPUT_CURSOR] = nk_rgba(210, 210, 210, 255);
ctx->style.colors[NK_COLOR_INPUT_TEXT] = nk_rgba(210, 210, 210, 255);
ctx->style.colors[NK_COLOR_COMBO] = nk_rgba(50, 58, 61, 255);
ctx->style.colors[NK_COLOR_HISTO] = nk_rgba(50, 58, 61, 255);
ctx->style.colors[NK_COLOR_HISTO_BARS] = nk_rgba(48, 83, 111, 255);
ctx->style.colors[NK_COLOR_HISTO_HIGHLIGHT] = nk_rgba(255, 0, 0, 255);
ctx->style.colors[NK_COLOR_PLOT] = nk_rgba(50, 58, 61, 255);
ctx->style.colors[NK_COLOR_PLOT_LINES] = nk_rgba(48, 83, 111, 255);
ctx->style.colors[NK_COLOR_PLOT_HIGHLIGHT] = nk_rgba(255, 0, 0, 255);
ctx->style.colors[NK_COLOR_SCROLLBAR] = nk_rgba(50, 58, 61, 255);
ctx->style.colors[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(48, 83, 111, 255);
ctx->style.colors[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255);
ctx->style.colors[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255);
ctx->style.colors[NK_COLOR_TABLE_LINES] = nk_rgba(100, 100, 100, 255);
ctx->style.colors[NK_COLOR_TAB_HEADER] = nk_rgba(48, 83, 111, 255);
ctx->style.colors[NK_COLOR_SCALER] = nk_rgba(100, 100, 100, 255);
break;
default:
nk_load_default_style(ctx, NK_DEFAULT_ALL);
}
}
void zrmenu_set_state(zrmenu_handle_t *zr, const int id,
struct nk_vec2 pos, struct nk_vec2 size)
{
zr->window[id].position = pos;
zr->window[id].size = size;
}
void zrmenu_get_state(zrmenu_handle_t *zr, const int id,
struct nk_vec2 *pos, struct nk_vec2 *size)
{
*pos = zr->window[id].position;
*size = zr->window[id].size;
}
void zrmenu_wnd_shader_parameters(zrmenu_handle_t *zr)
{
unsigned i;
video_shader_ctx_t shader_info;
struct nk_panel layout;
struct nk_context *ctx = &zr->ctx;
const int id = ZRMENU_WND_SHADER_PARAMETERS;
settings_t *settings = config_get_ptr();
if (nk_begin(ctx, &layout, "Shader Parameters", nk_rect(240, 10, 300, 400),
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_MOVABLE|
NK_WINDOW_SCALABLE|NK_WINDOW_BORDER))
{
struct nk_panel combo;
static const char *themes[] = {"Dark", "Light"};
enum zrmenu_theme old = zr->theme;
nk_layout_row_dynamic(ctx, 30, 1);
video_shader_driver_ctl(SHADER_CTL_GET_CURRENT_SHADER, &shader_info);
if (shader_info.data)
{
for (i = 0; i < GFX_MAX_PARAMETERS; i++)
{
if (!string_is_empty(shader_info.data->parameters[i].desc))
{
if(shader_info.data->parameters[i].minimum == 0 &&
shader_info.data->parameters[i].maximum == 1 &&
shader_info.data->parameters[i].step == 1)
nk_checkbox_float(ctx, shader_info.data->parameters[i].desc,
&(shader_info.data->parameters[i].current));
else
nk_property_float(ctx, shader_info.data->parameters[i].desc,
shader_info.data->parameters[i].minimum,
&(shader_info.data->parameters[i].current),
shader_info.data->parameters[i].maximum,
shader_info.data->parameters[i].step, 1);
}
}
}
}
/* save position and size to restore after context reset */
zrmenu_set_state(zr, id, nk_window_get_position(ctx), nk_window_get_size(ctx));
nk_end(ctx);
}
void zrmenu_wnd_control(zrmenu_handle_t *zr)
{
struct nk_panel layout;
struct nk_context *ctx = &zr->ctx;
const int id = ZRMENU_WND_CONTROL;
static int wnd_x = 900;
static int wnd_y = 60;
bool ret = (nk_begin(ctx, &layout, "Control",
nk_rect(wnd_x, wnd_y, 350, 520),
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_MOVABLE|
NK_WINDOW_SCALABLE|NK_WINDOW_BORDER));
if (ret)
{
unsigned i;
/* Style */
if (nk_layout_push(ctx, NK_LAYOUT_TAB, "Metrics", NK_MINIMIZED))
{
nk_layout_row_dynamic(ctx, 20, 2);
nk_label(ctx,"Total:", NK_TEXT_LEFT);
nk_labelf(ctx, NK_TEXT_LEFT, "%lu", zr->status.size);
nk_label(ctx,"Used:", NK_TEXT_LEFT);
nk_labelf(ctx, NK_TEXT_LEFT, "%lu", zr->status.allocated);
nk_label(ctx,"Required:", NK_TEXT_LEFT);
nk_labelf(ctx, NK_TEXT_LEFT, "%lu", zr->status.needed);
nk_label(ctx,"Calls:", NK_TEXT_LEFT);
nk_labelf(ctx, NK_TEXT_LEFT, "%lu", zr->status.calls);
nk_layout_pop(ctx);
}
if (nk_layout_push(ctx, NK_LAYOUT_TAB, "Properties", NK_MINIMIZED))
{
nk_layout_row_dynamic(ctx, 22, 3);
for (i = 0; i <= NK_PROPERTY_SCROLLBAR_SIZE; ++i)
{
nk_label(ctx, nk_get_property_name((enum nk_style_properties)i), NK_TEXT_LEFT);
nk_property_float(ctx, "#X:", 0, &ctx->style.properties[i].x, 20, 1, 1);
nk_property_float(ctx, "#Y:", 0, &ctx->style.properties[i].y, 20, 1, 1);
}
nk_layout_pop(ctx);
}
if (nk_layout_push(ctx, NK_LAYOUT_TAB, "Rounding", NK_MINIMIZED))
{
nk_layout_row_dynamic(ctx, 22, 2);
for (i = 0; i < NK_ROUNDING_MAX; ++i)
{
nk_label(ctx, nk_get_rounding_name((enum nk_style_rounding)i), NK_TEXT_LEFT);
nk_property_float(ctx, "#R:", 0, &ctx->style.rounding[i], 20, 1, 1);
}
nk_layout_pop(ctx);
}
}
/* save position and size to restore after context reset */
zrmenu_set_state(zr, id, nk_window_get_position(ctx), nk_window_get_size(ctx));
nk_end(ctx);
}
void zrmenu_wnd_test(zrmenu_handle_t *zr)
{
struct nk_panel layout;
struct nk_context *ctx = &zr->ctx;
const int id = ZRMENU_WND_TEST;
settings_t *settings = config_get_ptr();
if (nk_begin(ctx, &layout, "Test", nk_rect(140, 90, 500, 600),
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_MOVABLE|
NK_WINDOW_SCALABLE|NK_WINDOW_BORDER))
{
unsigned size;
struct nk_panel combo;
menu_entry_t entry;
static const char *themes[] = {"Dark", "Light"};
enum zrmenu_theme old = zr->theme;
nk_layout_row_dynamic(ctx, 30, 2);
if (nk_button_text(ctx, "Quit", NK_BUTTON_DEFAULT))
{
/* event handling */
printf("Pressed Event\n");
rarch_ctl(RARCH_CTL_FORCE_QUIT, NULL);
}
if (nk_button_text(ctx, "Quit", NK_BUTTON_DEFAULT))
{
/* event handling */
printf("Pressed Event\n");
rarch_ctl(RARCH_CTL_FORCE_QUIT, NULL);
}
nk_layout_row_dynamic(ctx, 30, 4);
nk_checkbox_bool(ctx, "Show FPS", &(settings->fps_show));
nk_checkbox_bool(ctx, "Show FPS", &(settings->fps_show));
nk_checkbox_bool(ctx, "Show FPS", &(settings->fps_show));
nk_checkbox_bool(ctx, "Show FPS", &(settings->fps_show));
nk_layout_row_dynamic(ctx, 30, 2);
nk_label(ctx, "Volume:", NK_TEXT_LEFT);
nk_slider_float(ctx, -80, &settings->audio.volume, 12, 0.5);
nk_layout_row_dynamic(ctx, 30, 1);
nk_property_int(ctx, "Max Users:", 1, (int*)&(settings->input.max_users),
MAX_USERS, 1, 1);
if (nk_combo_begin_text(ctx, &combo, themes[zr->theme], 200))
{
nk_layout_row_dynamic(ctx, 25, 1);
zr->theme = nk_combo_item(ctx, themes[THEME_DARK], NK_TEXT_CENTERED)
? THEME_DARK : zr->theme;
zr->theme = nk_combo_item(ctx, themes[THEME_LIGHT], NK_TEXT_CENTERED)
? THEME_LIGHT : zr->theme;
if (old != zr->theme) zrmenu_set_style(ctx, zr->theme);
nk_combo_end(ctx);
}
nk_label(ctx, "History:", NK_TEXT_LEFT);
size = menu_entries_get_size();
if (nk_combo_begin_text(ctx, &combo, "", 180))
{
unsigned i;
for (i = 0; i < size; i++)
{
menu_entry_get(&entry, 0, i, NULL, true);
nk_layout_row_dynamic(ctx, 25, 1);
nk_combo_item(ctx, entry.path, NK_TEXT_LEFT);
}
nk_combo_end(ctx);
}
}
/* save position and size to restore after context reset */
zrmenu_set_state(zr, id, nk_window_get_position(ctx), nk_window_get_size(ctx));
nk_end(ctx);
}
void zrmenu_wnd_main(zrmenu_handle_t *zr)
{
struct nk_panel layout;
struct nk_context *ctx = &zr->ctx;
const int id = ZRMENU_WND_MAIN;
settings_t *settings = config_get_ptr();
if (nk_begin(ctx, &layout, "Main", nk_rect(-1, -1, 120, zr->size.x + 1),
NK_WINDOW_NO_SCROLLBAR))
{
struct nk_panel menu;
struct nk_panel node, context_menu;
/* context menu */
if (nk_contextual_begin(ctx, &context_menu, 0, nk_vec2(100, 220),
nk_window_get_bounds(ctx)))
{
nk_layout_row_dynamic(ctx, 25, 1);
if (nk_contextual_item(ctx, "Test 1", NK_TEXT_CENTERED))
printf("test \n");
if (nk_contextual_item(ctx, "Test 2",NK_TEXT_CENTERED))
printf("test \n");
nk_contextual_end(ctx);
}
/* main menu */
nk_menubar_begin(ctx);
nk_layout_row_begin(ctx, NK_STATIC, 25, 1);
nk_layout_row_push(ctx, 100);
if (nk_menu_text_begin(ctx, &menu, "Menu", NK_TEXT_LEFT|NK_TEXT_MIDDLE, 120))
{
nk_layout_row_dynamic(ctx, 25, 1);
if (nk_menu_item(ctx, NK_TEXT_LEFT, "Test"))
printf("test \n");
if (nk_menu_item(ctx, NK_TEXT_LEFT, "About"))
printf("test \n");
if (nk_menu_item(ctx, NK_TEXT_LEFT, "Exit"))
rarch_ctl(RARCH_CTL_FORCE_QUIT, NULL);
nk_menu_end(ctx);
}
if (nk_menu_text_begin(ctx, &menu, "Window", NK_TEXT_LEFT|NK_TEXT_MIDDLE, 120))
{
nk_layout_row_dynamic(ctx, 25, 1);
if (nk_menu_item(ctx, NK_TEXT_LEFT, "Control"))
{
nk_window_close(ctx, "Control");
zr->window[ZRMENU_WND_CONTROL].open =
!zr->window[ZRMENU_WND_CONTROL].open;
}
if (nk_menu_item(ctx, NK_TEXT_LEFT, "Shader Parameters"))
{
nk_window_close(ctx, "Shader Parameters");
zr->window[ZRMENU_WND_SHADER_PARAMETERS].open =
!zr->window[ZRMENU_WND_SHADER_PARAMETERS].open;
}
if (nk_menu_item(ctx, NK_TEXT_LEFT, "Test Window"))
{
nk_window_close(ctx, "Test");
zr->window[ZRMENU_WND_TEST].open =
!zr->window[ZRMENU_WND_TEST].open;
}
if (nk_menu_item(ctx, NK_TEXT_LEFT, "Wizard"))
{
nk_window_close(ctx, "Test");
zr->window[ZRMENU_WND_WIZARD].open =
!zr->window[ZRMENU_WND_WIZARD].open;
}
nk_menu_end(ctx);
}
nk_layout_row_push(ctx, 60);
nk_menubar_end(ctx);
}
/* save position and size to restore after context reset */
zrmenu_set_state(zr, id, nk_window_get_position(ctx), nk_window_get_size(ctx));
if (zr->size_changed)
nk_window_set_size(ctx, nk_vec2(nk_window_get_size(ctx).x, zr->size.y));
nk_end(ctx);
}
void zrmenu_wnd_wizard(zrmenu_handle_t *zr)
{
struct nk_panel layout;
struct nk_context *ctx = &zr->ctx;
const int id = ZRMENU_WND_WIZARD;
static int width = 800;
static int height = 600;
static int panel = 0;
settings_t *settings = config_get_ptr();
if (nk_begin(ctx, &layout, "Setup Wizard", nk_rect(zr->size.x/2 -width/2,
zr->size.y/2 - height/2, width, height),
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_MOVABLE|
NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR))
{
/* uncomment this to hide the panel backgrounds
nk_push_color(ctx, NK_COLOR_WINDOW, nk_rgba(0,0,0,0)); */
struct nk_panel sub;
switch (panel)
{
case 0:
nk_layout_row_begin(ctx, NK_DYNAMIC, height * 0.80f, 2);
nk_layout_row_push(ctx, 0.15f);
if (nk_group_begin(ctx, &sub, "", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR))
{
nk_layout_space_begin(ctx, NK_STATIC, width * 0.15f, 1);
nk_layout_space_push(ctx, nk_rect(0, 0, width * 0.15f, width * 0.15f));
nk_image(ctx, zr->icons.invader);
nk_layout_space_end(ctx);
nk_group_end(ctx);
}
nk_layout_row_push(ctx, 0.85f);
if (nk_group_begin(ctx, &sub, "", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR))
{
nk_layout_row_dynamic(ctx, 14, 15);
nk_image(ctx, zr->icons.page_on);
nk_image(ctx, zr->icons.page_off);
nk_image(ctx, zr->icons.page_off);
nk_image(ctx, zr->icons.page_off);
nk_image(ctx, zr->icons.page_off);
nk_layout_row_dynamic(ctx, 20, 1);
nk_label(ctx, "Label aligned left", NK_TEXT_LEFT);
nk_label(ctx, "Label aligned centered", NK_TEXT_CENTERED);
nk_label(ctx, "Label aligned right", NK_TEXT_RIGHT);
nk_label_colored(ctx, "Blue text", NK_TEXT_LEFT, nk_rgb(0,0,255));
nk_label_colored(ctx, "Yellow text", NK_TEXT_LEFT, nk_rgb(255,255,0));
nk_text(ctx, "Text without /0", 15, NK_TEXT_RIGHT);
nk_layout_row_dynamic(ctx, 100, 1);
nk_label_wrap(ctx, "This is a very long line to hopefully get this text to be wrapped into multiple lines to show line wrapping, someone should write some text welcoming users to retroarch or something like that in this window, I'm not really good at this");
nk_group_end(ctx);
}
nk_layout_row_end(ctx);
nk_layout_row_dynamic(ctx, 30, 4);
nk_label(ctx,"", NK_TEXT_RIGHT);
nk_label(ctx,"", NK_TEXT_RIGHT);
nk_label(ctx,"", NK_TEXT_RIGHT);
if (nk_button_text(ctx, "Next", NK_BUTTON_DEFAULT))
panel++;
break;
case 1:
nk_layout_row_begin(ctx, NK_DYNAMIC, height * 0.80f, 2);
nk_layout_row_push(ctx, 0.15f);
if (nk_group_begin(ctx, &sub, "", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER))
{
nk_layout_space_begin(ctx, NK_STATIC, width * 0.15f, 1);
nk_layout_space_push(ctx, nk_rect(0, 0, width * 0.15f, width * 0.15f));
nk_layout_space_end(ctx);
nk_group_end(ctx);
}
nk_layout_row_push(ctx, 0.85f);
if (nk_group_begin(ctx, &sub, "", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR))
{
nk_layout_row_dynamic(ctx, 14, 15);
nk_image(ctx, zr->icons.page_on);
nk_image(ctx, zr->icons.page_on);
nk_image(ctx, zr->icons.page_off);
nk_image(ctx, zr->icons.page_off);
nk_image(ctx, zr->icons.page_off);
nk_layout_row_dynamic(ctx, 40, 1);
nk_button_text_image(ctx, zr->icons.folder, settings->libretro, NK_TEXT_CENTERED, NK_BUTTON_DEFAULT);
nk_button_text_image(ctx, zr->icons.folder, settings->libretro, NK_TEXT_CENTERED, NK_BUTTON_DEFAULT);
nk_button_text_image(ctx, zr->icons.folder, settings->libretro, NK_TEXT_CENTERED, NK_BUTTON_DEFAULT);
nk_button_text_image(ctx, zr->icons.folder, settings->libretro, NK_TEXT_CENTERED, NK_BUTTON_DEFAULT);
nk_button_text_image(ctx, zr->icons.folder, settings->libretro, NK_TEXT_CENTERED, NK_BUTTON_DEFAULT);
nk_button_text_image(ctx, zr->icons.folder, settings->libretro, NK_TEXT_CENTERED, NK_BUTTON_DEFAULT);
nk_button_text_image(ctx, zr->icons.folder, settings->libretro, NK_TEXT_CENTERED, NK_BUTTON_DEFAULT);
nk_button_text_image(ctx, zr->icons.folder, settings->libretro, NK_TEXT_CENTERED, NK_BUTTON_DEFAULT);
nk_group_end(ctx);
}
nk_layout_row_end(ctx);
nk_layout_row_dynamic(ctx, 30, 4);
nk_label(ctx,"", NK_TEXT_RIGHT);
nk_label(ctx,"", NK_TEXT_RIGHT);
if (nk_button_text(ctx, "Previous", NK_BUTTON_DEFAULT))
panel--;
if (nk_button_text(ctx, "Next", NK_BUTTON_DEFAULT))
panel++;
break;
case 2:
nk_layout_row_begin(ctx, NK_DYNAMIC, height * 0.80f, 2);
nk_layout_row_push(ctx, 0.15f);
if (nk_group_begin(ctx, &sub, "", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER))
{
nk_layout_space_begin(ctx, NK_STATIC, width * 0.15f, 1);
nk_layout_space_push(ctx, nk_rect(0, 0, width * 0.15f, width * 0.15f));
nk_layout_space_end(ctx);
nk_group_end(ctx);
}
nk_layout_row_push(ctx, 0.85f);
if (nk_group_begin(ctx, &sub, "", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR))
{
nk_layout_row_dynamic(ctx, 14, 15);
nk_image(ctx, zr->icons.page_on);
nk_image(ctx, zr->icons.page_on);
nk_image(ctx, zr->icons.page_on);
nk_image(ctx, zr->icons.page_off);
nk_image(ctx, zr->icons.page_off);
nk_layout_row_dynamic(ctx, 50, 1);
ui_selector(ctx, "Windowed Mode", &window_mode, display, LEN(display), WINDOW_MODE == active);
ui_selector(ctx, "Model Detail", &model_detail, detail, LEN(detail), MODEL_DETAIL == active);
ui_selector(ctx, "Textures", &texture_detail, detail, LEN(detail), TEXTURES == active);
ui_selector(ctx, "Shadows", &shadow_detail, detail, LEN(detail), SHADOWS == active);
ui_selector(ctx, "Lighting", &lighning_detail, detail, LEN(detail), LIGHTNING == active);
ui_selector(ctx, "Effects", &effects_detail, detail, LEN(detail), EFFECTS == active);
ui_selector(ctx, "Console", &show_console, state, LEN(state), CONSOLE == active);
ui_slider(ctx, "Brightness", &brightness, 100, BRIGHTNESS == active);
ui_slider(ctx, "Volume", &volume, 100, VOLUME == active);
if (nk_input_is_key_pressed(&ctx->input, NK_KEY_UP))
active = MAX(0, active-1);
if (nk_input_is_key_pressed(&ctx->input, NK_KEY_DOWN))
active = MIN(active+1, WIDGET_MAX - 2);
nk_group_end(ctx);
}
nk_layout_row_end(ctx);
nk_layout_row_dynamic(ctx, 30, 4);
nk_label(ctx,"", NK_TEXT_RIGHT);
nk_label(ctx,"", NK_TEXT_RIGHT);
if (nk_button_text(ctx, "Previous", NK_BUTTON_DEFAULT))
panel--;
if (nk_button_text(ctx, "Next", NK_BUTTON_DEFAULT))
panel++;
break;
default:
nk_layout_row_begin(ctx, NK_DYNAMIC, height * 0.80f, 2);
nk_layout_row_push(ctx, 0.15f);
if (nk_group_begin(ctx, &sub, "", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER))
{
nk_layout_space_begin(ctx, NK_STATIC, width * 0.15f, 1);
nk_layout_space_push(ctx, nk_rect(0, 0, width * 0.15f, width * 0.15f));
nk_layout_space_end(ctx);
nk_group_end(ctx);
}
nk_layout_row_push(ctx, 0.85f);
if (nk_group_begin(ctx, &sub, "", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR))
{
nk_layout_row_dynamic(ctx, 14, 15);
nk_image(ctx, zr->icons.page_on);
nk_image(ctx, zr->icons.page_on);
nk_image(ctx, zr->icons.page_on);
nk_image(ctx, zr->icons.page_off);
nk_image(ctx, zr->icons.page_off);
nk_layout_row_dynamic(ctx, 40, 1);
nk_group_end(ctx);
}
nk_layout_row_end(ctx);
nk_layout_row_dynamic(ctx, 30, 4);
nk_label(ctx,"", NK_TEXT_RIGHT);
nk_label(ctx,"", NK_TEXT_RIGHT);
if (nk_button_text(ctx, "Previous", NK_BUTTON_DEFAULT))
panel--;
if (nk_button_text(ctx, "Next", NK_BUTTON_DEFAULT))
panel++;
break;
}
nk_reset_colors(ctx);
}
/* save position and size to restore after context reset */
zrmenu_set_state(zr, id, nk_window_get_position(ctx), nk_window_get_size(ctx));
nk_end(ctx);
}

100
menu/drivers/nk_menu.h Normal file
View File

@ -0,0 +1,100 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2016 - Daniel De Matteis
* Copyright (C) 2014-2015 - Jean-André Santoni
* Copyright (C) 2016 - Andrés Suárez
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "nk_common.h"
#include "../menu_display.h"
#include "../menu_input.h"
enum
{
NK_TEXTURE_POINTER = 0,
NK_TEXTURE_LAST
};
enum
{
ZRMENU_WND_MAIN = 0,
ZRMENU_WND_CONTROL,
ZRMENU_WND_SHADER_PARAMETERS,
ZRMENU_WND_TEST,
ZRMENU_WND_WIZARD
};
enum zrmenu_theme
{
THEME_DARK = 0,
THEME_LIGHT
};
struct icons {
struct nk_image folder;
struct nk_image monitor;
struct nk_image gamepad;
struct nk_image settings;
struct nk_image speaker;
struct nk_image invader;
struct nk_image page_on;
struct nk_image page_off;
};
struct window {
bool open;
struct nk_vec2 position;
struct nk_vec2 size;
};
typedef struct zrmenu_handle
{
/* zahnrad mandatory */
void *memory;
struct nk_context ctx;
struct nk_memory_status status;
enum menu_action action;
/* window control variables */
struct nk_vec2 size;
bool size_changed;
struct window window[5];
/* menu driver variables */
char box_message[PATH_MAX_LENGTH];
/* image & theme related variables */
char assets_directory[PATH_MAX_LENGTH];
struct icons icons;
enum zrmenu_theme theme;
struct
{
menu_texture_item bg;
menu_texture_item list[NK_TEXTURE_LAST];
} textures;
gfx_font_raster_block_t list_block;
} zrmenu_handle_t;
void zrmenu_set_style(struct nk_context *ctx, enum zrmenu_theme theme);
void zrmenu_wnd_wizard(zrmenu_handle_t *zr);
void zrmenu_wnd_shader_parameters(zrmenu_handle_t *zr);
void zrmenu_wnd_control(zrmenu_handle_t *zr);
void zrmenu_wnd_test(zrmenu_handle_t *zr);
void zrmenu_wnd_main(zrmenu_handle_t *zr);
static void ui_slider(struct nk_context *ctx, const char *title, int *value, int max, int active);
static int ui_selector(struct nk_context *ctx, const char *title, int *selected, const char *items[], int max, int active);