static void canvas_begin(struct nk_context *ctx, struct nk_canvas *canvas, nk_flags flags, uint32_t x, uint32_t y, uint32_t width, uint32_t height, struct nk_color background_color){ /* save style properties which will be overwritten */ canvas->panel_padding = ctx->style.window.padding; canvas->item_spacing = ctx->style.window.spacing; canvas->window_background = ctx->style.window.fixed_background; /* use the complete window space and set background */ ctx->style.window.spacing = nk_vec2(0,0); ctx->style.window.padding = nk_vec2(0,0); ctx->style.window.fixed_background = nk_style_item_color(background_color); /* create/update window and set position + size */ flags = flags & ~NK_WINDOW_DYNAMIC; nk_begin(ctx, "Window", nk_rect(x, y, width, height), NK_WINDOW_NO_SCROLLBAR|flags); //nk_window_set_bounds(ctx, nk_rect(x, y, width, height)); /* allocate the complete window space for drawing */ {struct nk_rect total_space; total_space = nk_window_get_content_region(ctx); nk_layout_row_dynamic(ctx, total_space.h, 1); nk_widget(&total_space, ctx); canvas->painter = nk_window_get_canvas(ctx);} }
NK_API struct nk_vec2 nk_widget_size(struct nk_context *ctx) { struct nk_rect bounds; NK_ASSERT(ctx); NK_ASSERT(ctx->current); if (!ctx || !ctx->current) return nk_vec2(0,0); nk_layout_peek(&bounds, ctx); return nk_vec2(bounds.w, bounds.h); }
static void hat_widget(struct nk_context* nk, unsigned char state) { float radius; struct nk_rect area; struct nk_vec2 center; if (nk_widget(&area, nk) != NK_WIDGET_VALID) return; center = nk_vec2(area.x + area.w / 2.f, area.y + area.h / 2.f); radius = NK_MIN(area.w, area.h) / 2.f; nk_stroke_circle(nk_window_get_canvas(nk), nk_rect(center.x - radius, center.y - radius, radius * 2.f, radius * 2.f), 1.f, nk_rgb(175, 175, 175)); if (state) { const float angles[] = { 0.f, 0.f, NK_PI * 1.5f, NK_PI * 1.75f, NK_PI, 0.f, NK_PI * 1.25f, 0.f, NK_PI * 0.5f, NK_PI * 0.25f, 0.f, 0.f, NK_PI * 0.75f, 0.f, }; const float cosa = nk_cos(angles[state]); const float sina = nk_sin(angles[state]); const struct nk_vec2 p0 = nk_vec2(0.f, -radius); const struct nk_vec2 p1 = nk_vec2( radius / 2.f, -radius / 3.f); const struct nk_vec2 p2 = nk_vec2(-radius / 2.f, -radius / 3.f); nk_fill_triangle(nk_window_get_canvas(nk), center.x + cosa * p0.x + sina * p0.y, center.y + cosa * p0.y - sina * p0.x, center.x + cosa * p1.x + sina * p1.y, center.y + cosa * p1.y - sina * p1.x, center.x + cosa * p2.x + sina * p2.y, center.y + cosa * p2.y - sina * p2.x, nk_rgb(175, 175, 175)); } }
void nk_menu_wnd_main(nk_menu_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 */ /* main menu */ nk_menubar_begin(ctx); nk_layout_row_begin(ctx, NK_STATIC, 25, 1); nk_layout_row_push(ctx, 100); nk_layout_row_push(ctx, 60); nk_menubar_end(ctx); } /* save position and size to restore after context reset */ nk_menu_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); }
/* =============================================================== * * GRID * * ===============================================================*/ static void grid_demo(struct nk_context *ctx, struct media *media) { static char text[3][64]; static int text_len[3]; static const char *items[] = {"Item 0","item 1","item 2"}; static int selected_item = 0; static int check = 1; int i; nk_style_set_font(ctx, &media->font_20->handle); if (nk_begin(ctx, "Grid Demo", nk_rect(600, 350, 275, 250), NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_MOVABLE| NK_WINDOW_NO_SCROLLBAR)) { nk_style_set_font(ctx, &media->font_18->handle); nk_layout_row_dynamic(ctx, 30, 2); nk_label(ctx, "Floating point:", NK_TEXT_RIGHT); nk_edit_string(ctx, NK_EDIT_FIELD, text[0], &text_len[0], 64, nk_filter_float); nk_label(ctx, "Hexadecimal:", NK_TEXT_RIGHT); nk_edit_string(ctx, NK_EDIT_FIELD, text[1], &text_len[1], 64, nk_filter_hex); nk_label(ctx, "Binary:", NK_TEXT_RIGHT); nk_edit_string(ctx, NK_EDIT_FIELD, text[2], &text_len[2], 64, nk_filter_binary); nk_label(ctx, "Checkbox:", NK_TEXT_RIGHT); nk_checkbox_label(ctx, "Check me", &check); nk_label(ctx, "Combobox:", NK_TEXT_RIGHT); if (nk_combo_begin_label(ctx, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) { nk_layout_row_dynamic(ctx, 25, 1); for (i = 0; i < 3; ++i) if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT)) selected_item = i; nk_combo_end(ctx); } } nk_end(ctx); nk_style_set_font(ctx, &media->font_14->handle); }
/* =============================================================== * * DEMO * * ===============================================================*/ int main(void) { /* Platform */ sf::ContextSettings settings(24, 8, 4, 2, 2); sf::Window win(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Demo", sf::Style::Default, settings); win.setVerticalSyncEnabled(true); win.setActive(true); glViewport(0, 0, win.getSize().x, win.getSize().y); /* GUI */ struct nk_context *ctx; ctx = nk_sfml_init(&win); /* Load Fonts: if none of these are loaded a default font will be used */ /* Load Cursor: if you uncomment cursor loading please hide the cursor */ struct nk_font_atlas *atlas; nk_sfml_font_stash_begin(&atlas); /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 14, 0);*/ /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ nk_sfml_font_stash_end(); /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ /*nk_style_set_font(ctx, &droid->handle);*/ /* style.c */ #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ #endif struct nk_colorf bg; bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; while (win.isOpen()) { /* Input */ sf::Event evt; nk_input_begin(ctx); while(win.pollEvent(evt)) { if(evt.type == sf::Event::Closed) win.close(); else if(evt.type == sf::Event::Resized) glViewport(0, 0, evt.size.width, evt.size.height); nk_sfml_handle_event(&evt); } nk_input_end(ctx); /* GUI */ if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { enum {EASY, HARD}; static int op = EASY; static int property = 20; nk_layout_row_static(ctx, 30, 80, 1); if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); nk_layout_row_dynamic(ctx, 20, 1); nk_label(ctx, "background:", NK_TEXT_LEFT); nk_layout_row_dynamic(ctx, 25, 1); if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) { nk_layout_row_dynamic(ctx, 120, 1); bg = nk_color_picker(ctx, bg, NK_RGBA); nk_layout_row_dynamic(ctx, 25, 1); bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f); bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f); bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f); bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f); nk_combo_end(ctx); } } nk_end(ctx); /* -------------- EXAMPLES ---------------- */ #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif #ifdef INCLUDE_NODE_EDITOR node_editor(ctx); #endif /* ----------------------------------------- */ /* Draw */ win.setActive(true); nk_color_fv(bg, background); glClear(GL_COLOR_BUFFER_BIT); glClearColor(bg.r, bg.g, bg.b, bg.a); /* IMPORTANT: `nk_sfml_render` modifies some global OpenGL state * with blending, scissor, face culling and depth test and defaults everything * back into a default state. Make sure to either save and restore or * reset your own state after drawing rendering the UI. */ nk_sfml_render(NK_ANTI_ALIASING_ON); win.display(); } nk_sfml_shutdown(); return 0; }
/* =============================================================== * * DEMO * * ===============================================================*/ int main(int argc, char* argv[]) { /* Platform */ SDL_Window *win; SDL_GLContext glContext; struct nk_color background; int win_width, win_height; int running = 1; /* GUI */ struct nk_context *ctx; /* SDL setup */ SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "0"); SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_EVENTS); SDL_GL_SetAttribute (SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); win = SDL_CreateWindow("Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN|SDL_WINDOW_ALLOW_HIGHDPI); glContext = SDL_GL_CreateContext(win); SDL_GetWindowSize(win, &win_width, &win_height); /* OpenGL setup */ glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); glewExperimental = 1; if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to setup GLEW\n"); exit(1); } ctx = nk_sdl_init(win); /* Load Fonts: if none of these are loaded a default font will be used */ /* Load Cursor: if you uncomment cursor loading please hide the cursor */ {struct nk_font_atlas *atlas; nk_sdl_font_stash_begin(&atlas); /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 16, 0);*/ /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ nk_sdl_font_stash_end(); /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ /*nk_style_set_font(ctx, &roboto->handle)*/;} /* style.c */ /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ background = nk_rgb(28,48,62); while (running) { /* Input */ SDL_Event evt; nk_input_begin(ctx); while (SDL_PollEvent(&evt)) { if (evt.type == SDL_QUIT) goto cleanup; nk_sdl_handle_event(&evt); } nk_input_end(ctx); /* GUI */ {struct nk_panel layout; if (nk_begin(ctx, &layout, "Demo", nk_rect(200, 200, 210, 250), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { enum {EASY, HARD}; static int op = EASY; static int property = 20; nk_layout_row_static(ctx, 30, 80, 1); if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); {struct nk_panel combo; nk_layout_row_dynamic(ctx, 20, 1); nk_label(ctx, "background:", NK_TEXT_LEFT); nk_layout_row_dynamic(ctx, 25, 1); if (nk_combo_begin_color(ctx, &combo, background, nk_vec2(nk_widget_width(ctx),400))) { nk_layout_row_dynamic(ctx, 120, 1); background = nk_color_picker(ctx, background, NK_RGBA); nk_layout_row_dynamic(ctx, 25, 1); background.r = (nk_byte)nk_propertyi(ctx, "#R:", 0, background.r, 255, 1,1); background.g = (nk_byte)nk_propertyi(ctx, "#G:", 0, background.g, 255, 1,1); background.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, background.b, 255, 1,1); background.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, background.a, 255, 1,1); nk_combo_end(ctx); }} } nk_end(ctx);} /* -------------- EXAMPLES ---------------- */ /*calculator(ctx);*/ /*overview(ctx);*/ /*node_editor(ctx);*/ /* ----------------------------------------- */ /* Draw */ {float bg[4]; nk_color_fv(bg, background); SDL_GetWindowSize(win, &win_width, &win_height); glViewport(0, 0, win_width, win_height); glClear(GL_COLOR_BUFFER_BIT); glClearColor(bg[0], bg[1], bg[2], bg[3]); /* IMPORTANT: `nk_sdl_render` modifies some global OpenGL state * with blending, scissor, face culling, depth test and viewport and * defaults everything back into a default state. * Make sure to either a.) save and restore or b.) reset your own state after * rendering the UI. */ nk_sdl_render(NK_ANTI_ALIASING_ON, MAX_VERTEX_MEMORY, MAX_ELEMENT_MEMORY); SDL_GL_SwapWindow(win);} } cleanup: nk_sdl_shutdown(); SDL_GL_DeleteContext(glContext); SDL_DestroyWindow(win); SDL_Quit(); return 0; }
int main(void) { /* Platform */ int running = 1; struct XWindow win; GLXContext glContext; struct nk_context *ctx; struct nk_colorf bg; memset(&win, 0, sizeof(win)); win.dpy = XOpenDisplay(NULL); if (!win.dpy) die("Failed to open X display\n"); { /* check glx version */ int glx_major, glx_minor; if (!glXQueryVersion(win.dpy, &glx_major, &glx_minor)) die("[X11]: Error: Failed to query OpenGL version\n"); if ((glx_major == 1 && glx_minor < 3) || (glx_major < 1)) die("[X11]: Error: Invalid GLX version!\n"); } { /* find and pick matching framebuffer visual */ int fb_count; static GLint attr[] = { GLX_X_RENDERABLE, True, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_DOUBLEBUFFER, True, None }; GLXFBConfig *fbc; fbc = glXChooseFBConfig(win.dpy, DefaultScreen(win.dpy), attr, &fb_count); if (!fbc) die("[X11]: Error: failed to retrieve framebuffer configuration\n"); { /* pick framebuffer with most samples per pixel */ int i; int fb_best = -1, best_num_samples = -1; for (i = 0; i < fb_count; ++i) { XVisualInfo *vi = glXGetVisualFromFBConfig(win.dpy, fbc[i]); if (vi) { int sample_buffer, samples; glXGetFBConfigAttrib(win.dpy, fbc[i], GLX_SAMPLE_BUFFERS, &sample_buffer); glXGetFBConfigAttrib(win.dpy, fbc[i], GLX_SAMPLES, &samples); if ((fb_best < 0) || (sample_buffer && samples > best_num_samples)) fb_best = i, best_num_samples = samples; } } win.fbc = fbc[fb_best]; XFree(fbc); win.vis = glXGetVisualFromFBConfig(win.dpy, win.fbc); } } { /* create window */ win.cmap = XCreateColormap(win.dpy, RootWindow(win.dpy, win.vis->screen), win.vis->visual, AllocNone); win.swa.colormap = win.cmap; win.swa.background_pixmap = None; win.swa.border_pixel = 0; win.swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPress | ButtonReleaseMask| ButtonMotionMask | Button1MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask| PointerMotionMask| StructureNotifyMask; win.win = XCreateWindow(win.dpy, RootWindow(win.dpy, win.vis->screen), 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, win.vis->depth, InputOutput, win.vis->visual, CWBorderPixel|CWColormap|CWEventMask, &win.swa); if (!win.win) die("[X11]: Failed to create window\n"); XFree(win.vis); XStoreName(win.dpy, win.win, "Demo"); XMapWindow(win.dpy, win.win); win.wm_delete_window = XInternAtom(win.dpy, "WM_DELETE_WINDOW", False); XSetWMProtocols(win.dpy, win.win, &win.wm_delete_window, 1); } { /* create opengl context */ typedef GLXContext(*glxCreateContext)(Display*, GLXFBConfig, GLXContext, Bool, const int*); int(*old_handler)(Display*, XErrorEvent*) = XSetErrorHandler(gl_error_handler); const char *extensions_str = glXQueryExtensionsString(win.dpy, DefaultScreen(win.dpy)); glxCreateContext create_context = (glxCreateContext) glXGetProcAddressARB((const GLubyte*)"glXCreateContextAttribsARB"); gl_err = nk_false; if (!has_extension(extensions_str, "GLX_ARB_create_context") || !create_context) { fprintf(stdout, "[X11]: glXCreateContextAttribARB() not found...\n"); fprintf(stdout, "[X11]: ... using old-style GLX context\n"); glContext = glXCreateNewContext(win.dpy, win.fbc, GLX_RGBA_TYPE, 0, True); } else { GLint attr[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 2, GLX_CONTEXT_MINOR_VERSION_ARB, 2, None }; glContext = create_context(win.dpy, win.fbc, 0, True, attr); XSync(win.dpy, False); if (gl_err || !glContext) { /* Could not create GL 3.0 context. Fallback to old 2.x context. * If a version below 3.0 is requested, implementations will * return the newest context version compatible with OpenGL * version less than version 3.0.*/ attr[1] = 1; attr[3] = 0; gl_err = nk_false; fprintf(stdout, "[X11] Failed to create OpenGL 3.0 context\n"); fprintf(stdout, "[X11] ... using old-style GLX context!\n"); glContext = create_context(win.dpy, win.fbc, 0, True, attr); } } XSync(win.dpy, False); XSetErrorHandler(old_handler); if (gl_err || !glContext) die("[X11]: Failed to create an OpenGL context\n"); glXMakeCurrent(win.dpy, win.win, glContext); } ctx = nk_x11_init(win.dpy, win.win); /* Load Fonts: if none of these are loaded a default font will be used */ /* Load Cursor: if you uncomment cursor loading please hide the cursor */ {struct nk_font_atlas *atlas; nk_x11_font_stash_begin(&atlas); /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 14, 0);*/ /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ nk_x11_font_stash_end(); /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ /*nk_style_set_font(ctx, &droid->handle);*/} #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ #endif bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; while (running) { /* Input */ XEvent evt; nk_input_begin(ctx); while (XPending(win.dpy)) { XNextEvent(win.dpy, &evt); if (evt.type == ClientMessage) goto cleanup; if (XFilterEvent(&evt, win.win)) continue; nk_x11_handle_event(&evt); } nk_input_end(ctx); /* GUI */ if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { enum {EASY, HARD}; static int op = EASY; static int property = 20; nk_layout_row_static(ctx, 30, 80, 1); if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); nk_layout_row_dynamic(ctx, 20, 1); nk_label(ctx, "background:", NK_TEXT_LEFT); nk_layout_row_dynamic(ctx, 25, 1); if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) { nk_layout_row_dynamic(ctx, 120, 1); bg = nk_color_picker(ctx, bg, NK_RGBA); nk_layout_row_dynamic(ctx, 25, 1); bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f); bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f); bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f); bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f); nk_combo_end(ctx); } } nk_end(ctx); /* -------------- EXAMPLES ---------------- */ #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif #ifdef INCLUDE_NODE_EDITOR node_editor(ctx); #endif /* ----------------------------------------- */ /* Draw */ XGetWindowAttributes(win.dpy, win.win, &win.attr); glViewport(0, 0, win.width, win.height); glClear(GL_COLOR_BUFFER_BIT); glClearColor(bg.r, bg.g, bg.b, bg.a); /* IMPORTANT: `nk_x11_render` modifies some global OpenGL state * with blending, scissor, face culling, depth test and viewport and * defaults everything back into a default state. * Make sure to either a.) save and restore or b.) reset your own state after * rendering the UI. */ nk_x11_render(NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER); glXSwapBuffers(win.dpy, win.win); } cleanup: nk_x11_shutdown(); glXMakeCurrent(win.dpy, 0, 0); glXDestroyContext(win.dpy, glContext); XUnmapWindow(win.dpy, win.win); XFreeColormap(win.dpy, win.cmap); XDestroyWindow(win.dpy, win.win); XCloseDisplay(win.dpy); return 0; }
int main(void) { /* Platform */ static GLFWwindow *win; int width = 0, height = 0; struct nk_context *ctx; struct nk_colorf bg; /* GLFW */ glfwSetErrorCallback(error_callback); if (!glfwInit()) { fprintf(stdout, "[GFLW] failed to init!\n"); exit(1); } win = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Demo", NULL, NULL); glfwMakeContextCurrent(win); glfwGetWindowSize(win, &width, &height); /* GUI */ ctx = nk_glfw3_init(win, NK_GLFW3_INSTALL_CALLBACKS); /* Load Fonts: if none of these are loaded a default font will be used */ /* Load Cursor: if you uncomment cursor loading please hide the cursor */ {struct nk_font_atlas *atlas; nk_glfw3_font_stash_begin(&atlas); /*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/ /*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 14, 0);*/ /*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/ /*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/ /*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/ /*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/ nk_glfw3_font_stash_end(); /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ /*nk_style_set_font(ctx, &droid->handle);*/} #ifdef INCLUDE_STYLE /*set_style(ctx, THEME_WHITE);*/ /*set_style(ctx, THEME_RED);*/ /*set_style(ctx, THEME_BLUE);*/ /*set_style(ctx, THEME_DARK);*/ #endif bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; while (!glfwWindowShouldClose(win)) { /* Input */ glfwPollEvents(); nk_glfw3_new_frame(); /* GUI */ if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) { enum {EASY, HARD}; static int op = EASY; static int property = 20; nk_layout_row_static(ctx, 30, 80, 1); if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); nk_layout_row_dynamic(ctx, 20, 1); nk_label(ctx, "background:", NK_TEXT_LEFT); nk_layout_row_dynamic(ctx, 25, 1); if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) { nk_layout_row_dynamic(ctx, 120, 1); bg = nk_color_picker(ctx, bg, NK_RGBA); nk_layout_row_dynamic(ctx, 25, 1); bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f); bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f); bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f); bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f); nk_combo_end(ctx); } } nk_end(ctx); /* -------------- EXAMPLES ---------------- */ #ifdef INCLUDE_CALCULATOR calculator(ctx); #endif #ifdef INCLUDE_OVERVIEW overview(ctx); #endif #ifdef INCLUDE_NODE_EDITOR node_editor(ctx); #endif /* ----------------------------------------- */ /* Draw */ glfwGetWindowSize(win, &width, &height); glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT); glClearColor(bg.r, bg.g, bg.b, bg.a); /* IMPORTANT: `nk_glfw_render` modifies some global OpenGL state * with blending, scissor, face culling and depth test and defaults everything * back into a default state. Make sure to either save and restore or * reset your own state after drawing rendering the UI. */ nk_glfw3_render(NK_ANTI_ALIASING_ON); glfwSwapBuffers(win); } nk_glfw3_shutdown(); glfwTerminate(); return 0; }
/* =============================================================== * * BASIC DEMO * * ===============================================================*/ static void basic_demo(struct nk_context *ctx, struct media *media) { static int image_active; static int check0 = 1; static int check1 = 0; static size_t prog = 80; static int selected_item = 0; static int selected_image = 3; static int selected_icon = 0; static const char *items[] = {"Item 0","item 1","item 2"}; static int piemenu_active = 0; static struct nk_vec2 piemenu_pos; int i = 0; nk_style_set_font(ctx, &media->font_20->handle); nk_begin(ctx, "Basic Demo", nk_rect(320, 50, 275, 610), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_TITLE); /*------------------------------------------------ * POPUP BUTTON *------------------------------------------------*/ ui_header(ctx, media, "Popup & Scrollbar & Images"); ui_widget(ctx, media, 35); if (nk_button_image_label(ctx, media->dir, "Images", NK_TEXT_CENTERED)) image_active = !image_active; /*------------------------------------------------ * SELECTED IMAGE *------------------------------------------------*/ ui_header(ctx, media, "Selected Image"); ui_widget_centered(ctx, media, 100); nk_image(ctx, media->images[selected_image]); /*------------------------------------------------ * IMAGE POPUP *------------------------------------------------*/ if (image_active) { struct nk_panel popup; if (nk_popup_begin(ctx, NK_POPUP_STATIC, "Image Popup", 0, nk_rect(265, 0, 320, 220))) { nk_layout_row_static(ctx, 82, 82, 3); for (i = 0; i < 9; ++i) { if (nk_button_image(ctx, media->images[i])) { selected_image = i; image_active = 0; nk_popup_close(ctx); } } nk_popup_end(ctx); } } /*------------------------------------------------ * COMBOBOX *------------------------------------------------*/ ui_header(ctx, media, "Combo box"); ui_widget(ctx, media, 40); if (nk_combo_begin_label(ctx, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) { nk_layout_row_dynamic(ctx, 35, 1); for (i = 0; i < 3; ++i) if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT)) selected_item = i; nk_combo_end(ctx); } ui_widget(ctx, media, 40); if (nk_combo_begin_image_label(ctx, items[selected_icon], media->images[selected_icon], nk_vec2(nk_widget_width(ctx), 200))) { nk_layout_row_dynamic(ctx, 35, 1); for (i = 0; i < 3; ++i) if (nk_combo_item_image_label(ctx, media->images[i], items[i], NK_TEXT_RIGHT)) selected_icon = i; nk_combo_end(ctx); } /*------------------------------------------------ * CHECKBOX *------------------------------------------------*/ ui_header(ctx, media, "Checkbox"); ui_widget(ctx, media, 30); nk_checkbox_label(ctx, "Flag 1", &check0); ui_widget(ctx, media, 30); nk_checkbox_label(ctx, "Flag 2", &check1); /*------------------------------------------------ * PROGRESSBAR *------------------------------------------------*/ ui_header(ctx, media, "Progressbar"); ui_widget(ctx, media, 35); nk_progress(ctx, &prog, 100, nk_true); /*------------------------------------------------ * PIEMENU *------------------------------------------------*/ if (nk_input_is_mouse_click_down_in_rect(&ctx->input, NK_BUTTON_RIGHT, nk_window_get_bounds(ctx),nk_true)){ piemenu_pos = ctx->input.mouse.pos; piemenu_active = 1; } if (piemenu_active) { int ret = ui_piemenu(ctx, piemenu_pos, 140, &media->menu[0], 6); if (ret == -2) piemenu_active = 0; if (ret != -1) { fprintf(stdout, "piemenu selected: %d\n", ret); piemenu_active = 0; } } nk_style_set_font(ctx, &media->font_14->handle); nk_end(ctx); }
void draw_credits_tab(struct nk_context *ctx, int *tab_screen_height, struct credits_tab *credits) { static struct time before_time, after_time; const float start_time_ratio[] = { 0.005f, 0.26f, 0.18f, 0.1f, 0.25f, 0.18f }; const float atleast_atmost_ratio[] = { 0.005f, 0.28, 0.1f, 0.36f, 0.1f, 0.1f }; static int start_atleast_int, start_atmost_int; *tab_screen_height = 472; //Start Credits Group nk_layout_row_dynamic(ctx, 210, 1); if(nk_group_begin(ctx, "Start Credits", NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) { nk_layout_row_dynamic(ctx, 20, 1); nk_checkbox_label(ctx, "Enable, write below text as soon as possible.", &credits->is_start_text); nk_layout_row_dynamic(ctx, 85, 1); nk_edit_string(ctx, NK_EDIT_BOX, credits->start_text, &credits->start_text_len, 1000, nk_filter_ascii); nk_layout_row(ctx, NK_DYNAMIC, 25, 6, start_time_ratio); nk_spacing(ctx, 1); nk_checkbox_label(ctx, "Before (MM:SS)", &credits->is_before); if (nk_combo_begin_label(ctx, credits->before_time_buffer, nk_vec2(100, 100))) { nk_layout_row_dynamic(ctx, 25, 1); sprintf(credits->before_time_buffer, "%02d:%02d", before_time.minutes, before_time.seconds); before_time.seconds = nk_propertyi(ctx, "#S:", 0, before_time.seconds, 60, 1, 1); before_time.minutes = nk_propertyi(ctx, "#M:", 0, before_time.minutes, 60, 1, 1); nk_combo_end(ctx); } nk_spacing(ctx, 1); nk_checkbox_label(ctx, "After (MM:SS)", &credits->is_after); if (nk_combo_begin_label(ctx, credits->after_time_buffer, nk_vec2(100, 100))) { nk_layout_row_dynamic(ctx, 25, 1); sprintf(credits->after_time_buffer, "%02d:%02d", after_time.minutes, after_time.seconds); after_time.seconds = nk_propertyi(ctx, "#S:", 0, after_time.seconds, 60, 1, 1); after_time.minutes = nk_propertyi(ctx, "#M:", 0, after_time.minutes, 60, 1, 1); nk_combo_end(ctx); } nk_layout_row(ctx, NK_DYNAMIC, 25, 6, atleast_atmost_ratio); nk_spacing(ctx, 1); nk_label(ctx, "Display credits at least", NK_TEXT_LEFT); nk_edit_string(ctx, NK_EDIT_SIMPLE, credits->start_atleast_sec, &credits->start_atleast_sec_len, 3, nk_filter_decimal); nk_label(ctx, "seconds and not longer than", NK_TEXT_CENTERED); nk_edit_string(ctx, NK_EDIT_SIMPLE, credits->start_atmost_sec, &credits->start_atmost_sec_len, 3, nk_filter_decimal); nk_label(ctx, "seconds", NK_TEXT_RIGHT); nk_group_end(ctx); } //End Credits Group nk_layout_row_dynamic(ctx, 180, 1); if(nk_group_begin(ctx, "End Credits", NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) { nk_layout_row_dynamic(ctx, 20, 1); nk_checkbox_label(ctx, "Enable, write below text after last caption and as close as possible to video end.", &credits->is_end_text); nk_layout_row_dynamic(ctx, 85, 1); nk_edit_string(ctx, NK_EDIT_BOX, credits->end_text, &credits->end_text_len, 1000, nk_filter_ascii); nk_layout_row(ctx,NK_DYNAMIC, 25, 6, atleast_atmost_ratio); nk_spacing(ctx, 1); nk_label(ctx, "Display credits at least", NK_TEXT_LEFT); nk_edit_string(ctx, NK_EDIT_SIMPLE, credits->end_atleast_sec, &credits->end_atleast_sec_len, 3, nk_filter_decimal); nk_label(ctx, "seconds and not longer than", NK_TEXT_CENTERED); nk_edit_string(ctx, NK_EDIT_SIMPLE, credits->end_atmost_sec, &credits->end_atmost_sec_len, 3, nk_filter_decimal); nk_label(ctx, "seconds", NK_TEXT_RIGHT); nk_group_end(ctx); } }
void draw_output_tab(struct nk_context *ctx, int *tab_screen_height, struct output_tab *output, struct main_tab *main_settings) { const float roll_limit_ratio[] = { 0.55f, 0.45f }; nk_flags active; static int len; static int cap_len; static int color_len = 6; const float gen_enc_ratio[] = { 0.701f, 0.302f }; const float type_ratio[] = { 0.3f,0.7f }; const float out_file_ratio[] = { 0.3f,0.53f,0.17f }; const float cap_file_ratio[] = { 0.2f,0.63f,0.17f }; const float delay_ratio[] = { 0.5f, 0.2f, 0.3f }; const float color_roll_ratio[] = { 0.6f,0.401f }; const float color_check_ratio[] = { 0.6f,0.23f,0.07f,0.1f }; *tab_screen_height = 472; nk_layout_row(ctx, NK_DYNAMIC, 160, 2, gen_enc_ratio); //General Group if (nk_group_begin(ctx, "General", NK_WINDOW_TITLE |NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_BORDER)) { int delay_secs = atoi(output->delay_sec_buffer); //Output Type nk_layout_row(ctx, NK_DYNAMIC, 20, 2, type_ratio); nk_label(ctx, "Output Type:", NK_TEXT_LEFT); output->type_select = nk_combo(ctx, output->type, 13, output->type_select, 25, nk_vec2(225, 200)); //Output File nk_layout_row(ctx, NK_DYNAMIC, 25, 3, out_file_ratio); nk_checkbox_label(ctx, "Output File:", &output->is_filename); nk_edit_string(ctx, NK_EDIT_SIMPLE, output->filename, &output->filename_len, 255, nk_filter_ascii); if (nk_button_label(ctx, "Browse")) { main_settings->scaleWindowForFileBrowser = nk_true; output->is_output_browser_active = nk_true; } //Subtitle Delay nk_layout_row(ctx, NK_DYNAMIC, 25, 3, delay_ratio); nk_checkbox_label(ctx, "Add delay in subtitles for", &output->is_delay); delay_secs = nk_propertyi(ctx, "", 0, delay_secs, 1000, 1, 1); sprintf(output->delay_sec_buffer, "%d", delay_secs); nk_label(ctx, "seconds", NK_TEXT_LEFT); //Export XDS info nk_layout_row_dynamic(ctx, 25, 1); nk_checkbox_label(ctx, "Export XDS information (transcripts)", &output->is_export_xds); nk_group_end(ctx); } //Encoding Group if (nk_group_begin(ctx, "Encoding", NK_WINDOW_TITLE |NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_BORDER)) { static int option = UTF; nk_layout_row_dynamic(ctx, 20, 1); if (nk_option_label(ctx, "Latin", output->encoding == LATIN)) { output->encoding = LATIN; } nk_layout_row_dynamic(ctx, 20, 1); if (nk_option_label(ctx, "Unicode", output->encoding == UNIC)) { output->encoding = UNIC; } nk_layout_row_dynamic(ctx, 20, 1); if (nk_option_label(ctx, "UTF-8", output->encoding == UTF)) { output->encoding = UTF; } nk_layout_row_dynamic(ctx, 20, 1); nk_checkbox_label(ctx, "Byte Order Mark*", &output->is_bom); nk_layout_row_dynamic(ctx, 20, 1); nk_label(ctx, "*( For UNIX programs )", NK_TEXT_LEFT); nk_group_end(ctx); } nk_layout_row(ctx, NK_DYNAMIC, 100, 2, gen_enc_ratio); //Capitalization Group if(nk_group_begin(ctx, "Capitalization", NK_WINDOW_TITLE|NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_BORDER)) { nk_layout_row_dynamic(ctx, 20, 1); nk_checkbox_label(ctx, "Standard capitalization rules.", &output->is_cap_standard); nk_layout_row(ctx, NK_DYNAMIC, 25, 3, cap_file_ratio); nk_checkbox_label(ctx, "Cap file:", &output->is_cap_file); nk_edit_string(ctx, NK_EDIT_SIMPLE, output->cap_dictionary, &output->cap_dictionary_len, 255, nk_filter_ascii); if (nk_button_label(ctx, "Browse")) { main_settings->scaleWindowForFileBrowser = nk_true; output->is_cap_browser_active = nk_true; } nk_group_end(ctx); } //Line Endings if (nk_group_begin(ctx, "Line Endings:", NK_WINDOW_TITLE | NK_WINDOW_NO_SCROLLBAR |NK_WINDOW_BORDER)) { nk_layout_row_dynamic(ctx, 20, 1); if (nk_option_label(ctx, "CRLF (Windows)", output->line_ending == CRLF)) { output->line_ending = CRLF; } nk_layout_row_dynamic(ctx, 25, 1); if (nk_option_label(ctx, "LF (UNIX-like)", output->line_ending == LF)) { output->line_ending = LF; } nk_group_end(ctx); } nk_layout_row(ctx, NK_DYNAMIC, 170, 2, color_roll_ratio); //Colors and Styles Group if (nk_group_begin(ctx, "Colors and Styles", NK_WINDOW_TITLE | NK_WINDOW_BORDER)) { nk_layout_row_dynamic(ctx, 20, 1); nk_checkbox_label(ctx, "Center Text (remove left and right spaces)", &output->is_center); nk_layout_row_dynamic(ctx, 20, 1); nk_checkbox_label(ctx, "Add dash (-) when speaker changes (for .srt)", &output->is_dash); nk_layout_row_dynamic(ctx, 20, 1); nk_checkbox_label(ctx, "Don't add typesetting tags(bold, italic, etc.)", &output->no_typesetting); nk_layout_row_dynamic(ctx, 20, 1); if(nk_option_label(ctx, "Don't add color information", output->font_color == NO_COLOR)) { output->font_color = NO_COLOR; } nk_layout_row(ctx, NK_DYNAMIC, 20, 4, color_check_ratio); if (nk_option_label(ctx, "Default color (RRGGBB)#", output->font_color == DEFAULT_COLOR)) { output->font_color = DEFAULT_COLOR; } active = nk_edit_string(ctx, NK_EDIT_FIELD|NK_EDIT_SIG_ENTER, output->color_hex, &color_len, 7, nk_filter_hex); nk_label(ctx, "or", NK_TEXT_CENTERED); if (nk_button_color(ctx, output->color_rgb)) output->color_popup = nk_true; if (show_color_from_picker) { sprintf(output->color_hex, "%02X%02X%02X", output->color_rgb.r, output->color_rgb.g, output->color_rgb.b); show_color_from_picker = nk_false; } /*if (active & NK_EDIT_COMMITED) { output->color_rgb.r = (int)strtol(strncat(output->color_hex[0], output->color_hex[1], 2), NULL, 16); output->color_rgb.g = (int)strtol(strncat(output->color_hex[2], output->color_hex[3], 2), NULL, 16); output->color_rgb.b = (int)strtol(strncat(output->color_hex[4], output->color_hex[5], 2), NULL, 16); printf("%d%d%d", output->color_rgb.r, output->color_rgb.g, output->color_rgb.b); }*/ nk_group_end(ctx); } //Roll-up Captions Group if (nk_group_begin(ctx, "Roll-up Captions", NK_WINDOW_TITLE | NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_BORDER)) { nk_layout_row_dynamic(ctx, 25, 1); if (nk_option_label(ctx, "Letters appear in realtime", output->onetime_or_realtime == REALTIME)) { output->onetime_or_realtime = REALTIME; } nk_layout_row_dynamic(ctx, 25, 1); nk_label(ctx, "(Allows duplication of content)", NK_TEXT_LEFT); nk_layout_row(ctx, NK_DYNAMIC, 20, 2, roll_limit_ratio); nk_label(ctx, "Limit visible lines", NK_TEXT_LEFT); output->roll_limit_select = nk_combo(ctx, output->roll_limit, 4, output->roll_limit_select, 25, nk_vec2(80, 80)); nk_layout_row_dynamic(ctx, 20, 1); if (nk_option_label(ctx, "Letters appear line by line", output->onetime_or_realtime == ONETIME)) { output->onetime_or_realtime = ONETIME; } nk_layout_row_dynamic(ctx, 25, 1); nk_label(ctx, "(No duplication of content)", NK_TEXT_LEFT); nk_group_end(ctx); } }
/*Tab specific functions*/ void draw_input_tab(struct nk_context *ctx, int *tab_screen_height, struct input_tab *input, struct decoders_tab *decoders) { const float screenful_limit_ratio[] = { 0.47f, 0.3f }; static struct time from_time, until_time; const float stream_type_pid_ratio[] = { 0.7f,0.3f }; const float mpeg_type_ratio[] = { 0.7f,0.3f }; const float teletext_page_ratio[] = { 0.75f,0.25f }; const float stream_teletext_ratio[] = { 0.5f, 0.501f }; const float wait_data_ratio[] = { 0.6f, 0.25f, 0.15f }; const float gen_type_ratio[] = { 0.3f, 0.7f }; const float gen_time_ratio[] = { 0.6f ,0.401f}; const char *split_type[] = { "Individual Files", "Parts of same video. Cut by generic tool", "Parts of same video. Cut by video tool" }; static int split_num; *tab_screen_height = 472; nk_layout_row(ctx, NK_DYNAMIC, 150, 2, gen_time_ratio); //General Group if (nk_group_begin(ctx, "General", NK_WINDOW_TITLE | NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_BORDER)) { //Input Type nk_layout_row(ctx, NK_DYNAMIC, 25, 2, gen_type_ratio); nk_label(ctx, "Input Type:", NK_TEXT_LEFT); input->type_select = nk_combo(ctx, input->type, 9, input->type_select, 25, nk_vec2(225, 200)); //Split Type nk_layout_row(ctx, NK_DYNAMIC, 25, 2, gen_type_ratio); nk_label(ctx, "Split Type:", NK_TEXT_LEFT); split_num = nk_combo(ctx, split_type, 3, split_num, 25, nk_vec2(240, 200)); if (split_num == 2) input->is_split = nk_true; nk_layout_row_dynamic(ctx, 20, 1); nk_checkbox_label(ctx, "Live Stream.*", &input->is_live_stream); nk_layout_row(ctx, NK_DYNAMIC, 21, 3, wait_data_ratio); nk_label(ctx, "*Wait when no data arrives for", NK_TEXT_LEFT); nk_edit_string(ctx, NK_EDIT_SIMPLE, input->wait_data_sec, &input->wait_data_sec_len, 999, nk_filter_decimal); nk_label(ctx, "sec", NK_TEXT_LEFT); nk_group_end(ctx); } //Timing Group if (nk_group_begin(ctx, "Timing", NK_WINDOW_TITLE | NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_BORDER)) { //Process From nk_layout_row_dynamic(ctx, 20, 1); nk_checkbox_label(ctx, "Process From: (HH:MM:SS)", &input->is_process_from); nk_layout_row_dynamic(ctx, 25, 1); if (nk_combo_begin_label(ctx, input->from_time_buffer, nk_vec2(180, 250))) { sprintf(input->from_time_buffer, "%02d:%02d:%02d", from_time.hours, from_time.minutes, from_time.seconds); nk_layout_row_dynamic(ctx, 25, 1); from_time.seconds = nk_propertyi(ctx, "#Seconds:", 0, from_time.seconds, 60, 1, 1); from_time.minutes = nk_propertyi(ctx, "#Minutes:", 0, from_time.minutes, 60, 1, 1); from_time.hours = nk_propertyi(ctx, "#Hours:", 0, from_time.hours, 99, 1, 1); nk_combo_end(ctx); } //Process Until nk_layout_row_dynamic(ctx, 20, 1); nk_checkbox_label(ctx, "Process Until: (HH:MM:SS)", &input->is_process_until); nk_layout_row_dynamic(ctx, 25, 1); if (nk_combo_begin_label(ctx, input->until_time_buffer, nk_vec2(180, 250))) { sprintf(input->until_time_buffer, "%02d:%02d:%02d", until_time.hours, until_time.minutes, until_time.seconds); nk_layout_row_dynamic(ctx, 25, 1); until_time.seconds = nk_propertyi(ctx, "#Seconds:", 0, until_time.seconds, 60, 1, 1); until_time.minutes = nk_propertyi(ctx, "#Minutes:", 0, until_time.minutes, 60, 1, 1); until_time.hours = nk_propertyi(ctx, "#Hours:", 0, until_time.hours, 99, 1, 1); nk_combo_end(ctx); } nk_group_end(ctx); } nk_layout_row(ctx, NK_DYNAMIC, 150, 2, stream_teletext_ratio); //Elementary Stream Group if (nk_group_begin(ctx, "Elementary Stream", NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_TITLE | NK_WINDOW_BORDER)) { nk_layout_row_dynamic(ctx, 20, 1); if (nk_option_label(ctx, "Auto", input->elementary_stream == AUTO_DETECT)) { input->elementary_stream = AUTO_DETECT; } nk_layout_row(ctx, NK_DYNAMIC, 25, 2, stream_type_pid_ratio); if (nk_option_label(ctx, "Process stream of type:", input->elementary_stream == STREAM_TYPE)) { input->elementary_stream = STREAM_TYPE; } nk_edit_string(ctx, NK_EDIT_SIMPLE, input->stream_type, &input->stream_type_len, 9, nk_filter_decimal); nk_layout_row(ctx, NK_DYNAMIC, 25, 2, stream_type_pid_ratio); if (nk_option_label(ctx, "Process stream with PID:", input->elementary_stream == STREAM_PID)) { input->elementary_stream = STREAM_PID; } nk_edit_string(ctx, NK_EDIT_SIMPLE, input->stream_pid, &input->stream_pid_len, 9, nk_filter_decimal); nk_layout_row(ctx, NK_DYNAMIC, 25, 2, mpeg_type_ratio); nk_checkbox_label(ctx, "Assume MPEG type is:", &input->is_assume_mpeg); nk_edit_string(ctx, NK_EDIT_SIMPLE, input->mpeg_type, &input->mpeg_type_len, 9, nk_filter_decimal); if(input->teletext_decoder == FORCE) { input->elementary_stream = STREAM_PID; } nk_group_end(ctx); } //Teletext Group if (nk_group_begin(ctx, "Teletext", NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_TITLE | NK_WINDOW_BORDER)) { if(decoders->teletext_dvb == DVB){ nk_layout_row_dynamic(ctx, 40, 1); nk_label_colored_wrap(ctx, "Teletext is disabled in Decoders->Teletext or DVB.", nk_rgb(255, 56, 38)); } else { nk_layout_row_dynamic(ctx, 20, 1); if (nk_option_label(ctx, "Auto", input->teletext_decoder == AUTO_DECODE)) { input->teletext_decoder = AUTO_DECODE; } nk_layout_row_dynamic(ctx, 25, 1); if (nk_option_label(ctx, "Force Teletext decoder", input->teletext_decoder == FORCE)) { input->teletext_decoder = FORCE; } nk_layout_row_dynamic(ctx, 25, 1); if (nk_option_label(ctx, "Disable Teletext decoder", input->teletext_decoder == DISABLE)) { input->teletext_decoder = DISABLE; } nk_layout_row(ctx, NK_DYNAMIC, 20, 2, teletext_page_ratio); nk_checkbox_label(ctx, "Process Teletext Page #", &input->is_process_teletext_page); nk_edit_string(ctx, NK_EDIT_SIMPLE, input->teletext_page_number, &input->teletext_page_numer_len, 99999, nk_filter_decimal); } nk_group_end(ctx); } //Screenfuls limit group nk_layout_row(ctx, NK_DYNAMIC, 95, 2, stream_teletext_ratio); if (nk_group_begin(ctx, "'Screenfuls' limit", NK_WINDOW_BORDER | NK_WINDOW_TITLE | NK_WINDOW_NO_SCROLLBAR)) { int screenful_limits = atoi(input->screenful_limit_buffer); nk_layout_row_dynamic(ctx, 20, 1); if (nk_option_label(ctx, "No limit", input->is_limit == NO_LIMIT)) { input->is_limit = NO_LIMIT; } nk_layout_row(ctx, NK_DYNAMIC, 25, 2, screenful_limit_ratio); if (nk_option_label(ctx, "Screenful Limit:", input->is_limit == LIMITED)) { input->is_limit = LIMITED; } screenful_limits = nk_propertyi(ctx, "", 0, screenful_limits, 999, 1, 1); sprintf(input->screenful_limit_buffer, "%d", screenful_limits); nk_group_end(ctx); } //Clock group if (nk_group_begin(ctx, "Clock", NK_WINDOW_BORDER | NK_WINDOW_TITLE | NK_WINDOW_NO_SCROLLBAR)) { nk_layout_row_dynamic(ctx, 20, 3); if (nk_option_label(ctx, "Auto", input->clock_input == AUTO)) { input->clock_input = AUTO; } if (nk_option_label(ctx, "GOP", input->clock_input == GOP)) { input->clock_input = GOP; } if (nk_option_label(ctx, "PTS", input->clock_input == PTS)) { input->clock_input = PTS; } nk_group_end(ctx); } }
void draw_burned_subs_tab(struct nk_context *ctx, int *tab_screen_height, struct burned_subs_tab *burned_subs) { *tab_screen_height = 472; const float color_mode_ratio[] = { 0.65f, 0.351f}; const float preset_ratio[] = { 0.4f, 0.5f }; const float custom_ratio[] = { 0.4f, 0.5f}; const float delay_ratio[] = { 0.4f, 0.2f, 0.2f }; const float threshold_ratio[] = { 0.9f, 0.1f }; static char buffer[5]; nk_layout_row_dynamic(ctx, 30, 1); #if ENABLE_OCR nk_checkbox_label(ctx, "Enable Burned-in Subtitle Extraction", &burned_subs->is_burned_subs); #else nk_label_colored(ctx, "Required Library not found. Cannot perform Burned subtitle extraction.", NK_TEXT_LEFT, nk_rgb(255, 56, 38)); #endif nk_layout_row(ctx, NK_DYNAMIC, 140, 2, color_mode_ratio); if(nk_group_begin(ctx, "Subtitle Color", NK_WINDOW_TITLE | NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_BORDER)) { nk_layout_row(ctx, NK_DYNAMIC, 25, 2, preset_ratio); if(nk_option_label(ctx, "Preset color:", burned_subs->color_type == PRESET)){ burned_subs->color_type = PRESET; } burned_subs->subs_color_select = nk_combo(ctx, burned_subs->subs_color, 7, burned_subs->subs_color_select, 25, nk_vec2(100, 100)); nk_layout_row(ctx, NK_DYNAMIC, 25, 2, custom_ratio); if(nk_option_label(ctx, "Custom Hue:", burned_subs->color_type == CUSTOM)){ burned_subs->color_type = CUSTOM; } nk_edit_string(ctx, NK_EDIT_SIMPLE, burned_subs->custom_hue, &burned_subs->custom_hue_len, 4, nk_filter_decimal); nk_layout_row_dynamic(ctx, 20, 1); nk_label_wrap(ctx, "Custom Hue can be between 1 and 360"); nk_layout_row_dynamic(ctx, 20, 1); nk_label_wrap(ctx, "Refer to HSV color chart."); nk_group_end(ctx); } if(nk_group_begin(ctx, "OCR mode", NK_WINDOW_TITLE|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) { nk_layout_row_dynamic(ctx, 25, 1); if(nk_option_label(ctx, "Frame - wise", burned_subs->ocr_mode == FRAME_WISE)){ burned_subs->ocr_mode = FRAME_WISE; } nk_layout_row_dynamic(ctx, 25, 1); if(nk_option_label(ctx, "Word - wise", burned_subs->ocr_mode == WORD_WISE)){ burned_subs->ocr_mode = WORD_WISE; } nk_layout_row_dynamic(ctx, 25, 1); if(nk_option_label(ctx, "Letter - wise", burned_subs->ocr_mode == LETTER_WISE)){ burned_subs->ocr_mode = LETTER_WISE; } if(burned_subs->is_italic) { burned_subs->ocr_mode = WORD_WISE; } nk_group_end(ctx); } nk_layout_row_dynamic(ctx, 120, 1); if(nk_group_begin(ctx, "Minimum Subtitle Duration", NK_WINDOW_TITLE|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) { nk_layout_row(ctx, NK_DYNAMIC, 25, 3, delay_ratio); nk_label(ctx, "Set the minimum subtitle duration to:", NK_TEXT_LEFT); nk_edit_string(ctx, NK_EDIT_SIMPLE, burned_subs->min_duration, &burned_subs->min_duration_len, 4, nk_filter_float); nk_label(ctx, "seconds", NK_TEXT_LEFT); nk_layout_row_dynamic(ctx, 25, 1); nk_label(ctx, "Lower values give better results but take more time.", NK_TEXT_LEFT); nk_layout_row_dynamic(ctx, 25, 1); nk_label(ctx, "0.5 is the recommended value.", NK_TEXT_LEFT); nk_group_end(ctx); } if(!burned_subs->subs_color_select && burned_subs->color_type == PRESET) { nk_layout_row_dynamic(ctx, 60, 1); if(nk_group_begin(ctx, "Luminance Threshold", NK_WINDOW_TITLE|NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_BORDER)) { nk_layout_row(ctx, NK_DYNAMIC, 20, 2, threshold_ratio); nk_slider_int(ctx, 0, &burned_subs->luminance_threshold, 100, 1); sprintf(buffer, "%d", burned_subs->luminance_threshold); nk_label(ctx, buffer, NK_TEXT_LEFT); nk_group_end(ctx); } } nk_layout_row_dynamic(ctx, 60, 1); if(nk_group_begin(ctx, "Confidence Threshold", NK_WINDOW_TITLE|NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_BORDER)) { nk_layout_row(ctx, NK_DYNAMIC, 20, 2, threshold_ratio); nk_slider_int(ctx, 0, &burned_subs->confidence_threshold, 100, 1); sprintf(buffer, "%d", burned_subs->confidence_threshold); nk_label(ctx, buffer, NK_TEXT_LEFT); nk_group_end(ctx); } nk_layout_row_dynamic(ctx, 30, 1); nk_checkbox_label(ctx, "Enable italics detection.", &burned_subs->is_italic); }
static int node_editor(struct nk_context *ctx) { int n = 0; struct nk_rect total_space; const struct nk_input *in = &ctx->input; struct nk_command_buffer *canvas; struct node *updated = 0; struct node_editor *nodedit = &nodeEditor; if (!nodeEditor.initialized) { node_editor_init(&nodeEditor); nodeEditor.initialized = 1; } if (nk_begin(ctx, "NodeEdit", nk_rect(0, 0, 800, 600), NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) { /* allocate complete window space */ canvas = nk_window_get_canvas(ctx); total_space = nk_window_get_content_region(ctx); nk_layout_space_begin(ctx, NK_STATIC, total_space.h, nodedit->node_count); { struct node *it = nodedit->begin; struct nk_rect size = nk_layout_space_bounds(ctx); struct nk_panel *node = 0; if (nodedit->show_grid) { /* display grid */ float x, y; const float grid_size = 32.0f; const struct nk_color grid_color = nk_rgb(50, 50, 50); for (x = (float)fmod(size.x - nodedit->scrolling.x, grid_size); x < size.w; x += grid_size) nk_stroke_line(canvas, x+size.x, size.y, x+size.x, size.y+size.h, 1.0f, grid_color); for (y = (float)fmod(size.y - nodedit->scrolling.y, grid_size); y < size.h; y += grid_size) nk_stroke_line(canvas, size.x, y+size.y, size.x+size.w, y+size.y, 1.0f, grid_color); } /* execute each node as a movable group */ while (it) { /* calculate scrolled node window position and size */ nk_layout_space_push(ctx, nk_rect(it->bounds.x - nodedit->scrolling.x, it->bounds.y - nodedit->scrolling.y, it->bounds.w, it->bounds.h)); /* execute node window */ if (nk_group_begin(ctx, it->name, NK_WINDOW_MOVABLE|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_TITLE)) { /* always have last selected node on top */ node = nk_window_get_panel(ctx); if (nk_input_mouse_clicked(in, NK_BUTTON_LEFT, node->bounds) && (!(it->prev && nk_input_mouse_clicked(in, NK_BUTTON_LEFT, nk_layout_space_rect_to_screen(ctx, node->bounds)))) && nodedit->end != it) { updated = it; } /* ================= NODE CONTENT =====================*/ nk_layout_row_dynamic(ctx, 25, 1); nk_button_color(ctx, it->color); it->color.r = (nk_byte)nk_propertyi(ctx, "#R:", 0, it->color.r, 255, 1,1); it->color.g = (nk_byte)nk_propertyi(ctx, "#G:", 0, it->color.g, 255, 1,1); it->color.b = (nk_byte)nk_propertyi(ctx, "#B:", 0, it->color.b, 255, 1,1); it->color.a = (nk_byte)nk_propertyi(ctx, "#A:", 0, it->color.a, 255, 1,1); /* ====================================================*/ nk_group_end(ctx); } { /* node connector and linking */ float space; struct nk_rect bounds; bounds = nk_layout_space_rect_to_local(ctx, node->bounds); bounds.x += nodedit->scrolling.x; bounds.y += nodedit->scrolling.y; it->bounds = bounds; /* output connector */ space = node->bounds.h / (float)((it->output_count) + 1); for (n = 0; n < it->output_count; ++n) { struct nk_rect circle; circle.x = node->bounds.x + node->bounds.w-4; circle.y = node->bounds.y + space * (float)(n+1); circle.w = 8; circle.h = 8; nk_fill_circle(canvas, circle, nk_rgb(100, 100, 100)); /* start linking process */ if (nk_input_has_mouse_click_down_in_rect(in, NK_BUTTON_LEFT, circle, nk_true)) { nodedit->linking.active = nk_true; nodedit->linking.node = it; nodedit->linking.input_id = it->ID; nodedit->linking.input_slot = n; } /* draw curve from linked node slot to mouse position */ if (nodedit->linking.active && nodedit->linking.node == it && nodedit->linking.input_slot == n) { struct nk_vec2 l0 = nk_vec2(circle.x + 3, circle.y + 3); struct nk_vec2 l1 = in->mouse.pos; nk_stroke_curve(canvas, l0.x, l0.y, l0.x + 50.0f, l0.y, l1.x - 50.0f, l1.y, l1.x, l1.y, 1.0f, nk_rgb(100, 100, 100)); } } /* input connector */ space = node->bounds.h / (float)((it->input_count) + 1); for (n = 0; n < it->input_count; ++n) { struct nk_rect circle; circle.x = node->bounds.x-4; circle.y = node->bounds.y + space * (float)(n+1); circle.w = 8; circle.h = 8; nk_fill_circle(canvas, circle, nk_rgb(100, 100, 100)); if (nk_input_is_mouse_released(in, NK_BUTTON_LEFT) && nk_input_is_mouse_hovering_rect(in, circle) && nodedit->linking.active && nodedit->linking.node != it) { nodedit->linking.active = nk_false; node_editor_link(nodedit, nodedit->linking.input_id, nodedit->linking.input_slot, it->ID, n); } } } it = it->next; } /* reset linking connection */ if (nodedit->linking.active && nk_input_is_mouse_released(in, NK_BUTTON_LEFT)) { nodedit->linking.active = nk_false; nodedit->linking.node = NULL; fprintf(stdout, "linking failed\n"); } /* draw each link */ for (n = 0; n < nodedit->link_count; ++n) { struct node_link *link = &nodedit->links[n]; struct node *ni = node_editor_find(nodedit, link->input_id); struct node *no = node_editor_find(nodedit, link->output_id); float spacei = node->bounds.h / (float)((ni->output_count) + 1); float spaceo = node->bounds.h / (float)((no->input_count) + 1); struct nk_vec2 l0 = nk_layout_space_to_screen(ctx, nk_vec2(ni->bounds.x + ni->bounds.w, 3.0f + ni->bounds.y + spacei * (float)(link->input_slot+1))); struct nk_vec2 l1 = nk_layout_space_to_screen(ctx, nk_vec2(no->bounds.x, 3.0f + no->bounds.y + spaceo * (float)(link->output_slot+1))); l0.x -= nodedit->scrolling.x; l0.y -= nodedit->scrolling.y; l1.x -= nodedit->scrolling.x; l1.y -= nodedit->scrolling.y; nk_stroke_curve(canvas, l0.x, l0.y, l0.x + 50.0f, l0.y, l1.x - 50.0f, l1.y, l1.x, l1.y, 1.0f, nk_rgb(100, 100, 100)); } if (updated) { /* reshuffle nodes to have least recently selected node on top */ node_editor_pop(nodedit, updated); node_editor_push(nodedit, updated); } /* node selection */ if (nk_input_mouse_clicked(in, NK_BUTTON_LEFT, nk_layout_space_bounds(ctx))) { it = nodedit->begin; nodedit->selected = NULL; nodedit->bounds = nk_rect(in->mouse.pos.x, in->mouse.pos.y, 100, 200); while (it) { struct nk_rect b = nk_layout_space_rect_to_screen(ctx, it->bounds); b.x -= nodedit->scrolling.x; b.y -= nodedit->scrolling.y; if (nk_input_is_mouse_hovering_rect(in, b)) nodedit->selected = it; it = it->next; } } /* contextual menu */ if (nk_contextual_begin(ctx, 0, nk_vec2(100, 220), nk_window_get_bounds(ctx))) { const char *grid_option[] = {"Show Grid", "Hide Grid"}; nk_layout_row_dynamic(ctx, 25, 1); if (nk_contextual_item_label(ctx, "New", NK_TEXT_CENTERED)) node_editor_add(nodedit, "New", nk_rect(400, 260, 180, 220), nk_rgb(255, 255, 255), 1, 2); if (nk_contextual_item_label(ctx, grid_option[nodedit->show_grid],NK_TEXT_CENTERED)) nodedit->show_grid = !nodedit->show_grid; nk_contextual_end(ctx); } } nk_layout_space_end(ctx); /* window content scrolling */ if (nk_input_is_mouse_hovering_rect(in, nk_window_get_bounds(ctx)) && nk_input_is_mouse_down(in, NK_BUTTON_MIDDLE)) { nodedit->scrolling.x += in->mouse.delta.x; nodedit->scrolling.y += in->mouse.delta.y; } } nk_end(ctx); return !nk_window_is_closed(ctx, "NodeEdit"); }
static void button_demo(struct nk_context *ctx, struct media *media) { static int option = 1; static int toggle0 = 1; static int toggle1 = 0; static int toggle2 = 1; nk_style_set_font(ctx, &media->font_20->handle); nk_begin(ctx, "Button Demo", nk_rect(50,50,255,610), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_TITLE); /*------------------------------------------------ * MENU *------------------------------------------------*/ nk_menubar_begin(ctx); { /* toolbar */ nk_layout_row_static(ctx, 40, 40, 4); if (nk_menu_begin_image(ctx, "Music", media->play, nk_vec2(110,120))) { /* settings */ nk_layout_row_dynamic(ctx, 25, 1); nk_menu_item_image_label(ctx, media->play, "Play", NK_TEXT_RIGHT); nk_menu_item_image_label(ctx, media->stop, "Stop", NK_TEXT_RIGHT); nk_menu_item_image_label(ctx, media->pause, "Pause", NK_TEXT_RIGHT); nk_menu_item_image_label(ctx, media->next, "Next", NK_TEXT_RIGHT); nk_menu_item_image_label(ctx, media->prev, "Prev", NK_TEXT_RIGHT); nk_menu_end(ctx); } nk_button_image(ctx, media->tools); nk_button_image(ctx, media->cloud); nk_button_image(ctx, media->pen); } nk_menubar_end(ctx); /*------------------------------------------------ * BUTTON *------------------------------------------------*/ ui_header(ctx, media, "Push buttons"); ui_widget(ctx, media, 35); if (nk_button_label(ctx, "Push me")) fprintf(stdout, "pushed!\n"); ui_widget(ctx, media, 35); if (nk_button_image_label(ctx, media->rocket, "Styled", NK_TEXT_CENTERED)) fprintf(stdout, "rocket!\n"); /*------------------------------------------------ * REPEATER *------------------------------------------------*/ ui_header(ctx, media, "Repeater"); ui_widget(ctx, media, 35); if (nk_button_label(ctx, "Press me")) fprintf(stdout, "pressed!\n"); /*------------------------------------------------ * TOGGLE *------------------------------------------------*/ ui_header(ctx, media, "Toggle buttons"); ui_widget(ctx, media, 35); if (nk_button_image_label(ctx, (toggle0) ? media->checked: media->unchecked, "Toggle", NK_TEXT_LEFT)) toggle0 = !toggle0; ui_widget(ctx, media, 35); if (nk_button_image_label(ctx, (toggle1) ? media->checked: media->unchecked, "Toggle", NK_TEXT_LEFT)) toggle1 = !toggle1; ui_widget(ctx, media, 35); if (nk_button_image_label(ctx, (toggle2) ? media->checked: media->unchecked, "Toggle", NK_TEXT_LEFT)) toggle2 = !toggle2; /*------------------------------------------------ * RADIO *------------------------------------------------*/ ui_header(ctx, media, "Radio buttons"); ui_widget(ctx, media, 35); if (nk_button_symbol_label(ctx, (option == 0)?NK_SYMBOL_CIRCLE_OUTLINE:NK_SYMBOL_CIRCLE_SOLID, "Select", NK_TEXT_LEFT)) option = 0; ui_widget(ctx, media, 35); if (nk_button_symbol_label(ctx, (option == 1)?NK_SYMBOL_CIRCLE_OUTLINE:NK_SYMBOL_CIRCLE_SOLID, "Select", NK_TEXT_LEFT)) option = 1; ui_widget(ctx, media, 35); if (nk_button_symbol_label(ctx, (option == 2)?NK_SYMBOL_CIRCLE_OUTLINE:NK_SYMBOL_CIRCLE_SOLID, "Select", NK_TEXT_LEFT)) option = 2; /*------------------------------------------------ * CONTEXTUAL *------------------------------------------------*/ nk_style_set_font(ctx, &media->font_18->handle); if (nk_contextual_begin(ctx, NK_WINDOW_NO_SCROLLBAR, nk_vec2(150, 300), nk_window_get_bounds(ctx))) { nk_layout_row_dynamic(ctx, 30, 1); if (nk_contextual_item_image_label(ctx, media->copy, "Clone", NK_TEXT_RIGHT)) fprintf(stdout, "pressed clone!\n"); if (nk_contextual_item_image_label(ctx, media->del, "Delete", NK_TEXT_RIGHT)) fprintf(stdout, "pressed delete!\n"); if (nk_contextual_item_image_label(ctx, media->convert, "Convert", NK_TEXT_RIGHT)) fprintf(stdout, "pressed convert!\n"); if (nk_contextual_item_image_label(ctx, media->edit, "Edit", NK_TEXT_RIGHT)) fprintf(stdout, "pressed edit!\n"); nk_contextual_end(ctx); } nk_style_set_font(ctx, &media->font_14->handle); nk_end(ctx); }
CharacterDialoguePopup::UpdateResult CharacterDialoguePopup::update(struct nk_context* ctx) { auto renderer = FARender::Renderer::get(); auto boxTex = renderer->loadImage(this->mWide ? "data/textbox.cel" : "data/textbox2.cel"); int32_t screenW, screenH; renderer->getWindowDimensions(screenW, screenH); nk_flags flags = NK_WINDOW_NO_SCROLLBAR; auto dialogRectangle = nk_rect(screenW / 2.0f - (boxTex->getWidth() / 2.0f), screenH / 2.0f - (boxTex->getHeight() / 2.0f), boxTex->getWidth(), boxTex->getHeight()); UpdateResult result = UpdateResult::DoNothing; mGuiManager.nk_fa_begin_image_window(ctx, "dialog", dialogRectangle, flags, boxTex->getNkImage(), [&]() { // apply black checkerboard in background { auto blackTex = renderer->loadImage("resources/black.png"); auto cbRect = nk_rect(dialogRectangle.x + 3, dialogRectangle.y + 3, dialogRectangle.w - 6, dialogRectangle.h - 6); ScopedApplyEffect effect(ctx, EffectType::checkerboarded); auto nkImage = nk_subimage_handle(blackTex->getNkImage().handle, blackTex->getWidth(), blackTex->getHeight(), cbRect); nk_draw_image(nk_window_get_canvas(ctx), cbRect, &nkImage, nk_rgb(0, 0, 0)); } nk_layout_row_dynamic(ctx, 30, 1); DialogData data = getDialogData(); for (const auto& line : data.introduction) GuiManager::smallText(ctx, line.c_str()); // fill the rest of the window struct nk_rect bounds = nk_widget_bounds(ctx); struct nk_rect panelSize = nk_window_get_bounds(ctx); float contentHeight = panelSize.h + panelSize.y - bounds.y; nk_layout_row_dynamic(ctx, contentHeight, 1); Misc::ScopedSetter<nk_style> styleSetter(ctx->style); // setup style for scrollbar { constexpr int32_t scrollUpButtonIndex = 9; constexpr int32_t scrollDownButtonIndex = 8; constexpr int32_t scrollbarBackgroundIndex = 13; // TODO: the "cursor" of the scrollbar is still the default nuklear look, which should change auto sliderImg = renderer->loadImage("data/textslid.cel"); // TODO: this image should repeat, not stretch ctx->style.scrollv.normal = nk_style_item_image(sliderImg->getNkImage(scrollbarBackgroundIndex)); ctx->style.scrollv.active = ctx->style.scrollv.normal; ctx->style.scrollv.hover = ctx->style.scrollv.normal; ctx->style.scrollv.cursor_active = ctx->style.scrollv.cursor_normal; ctx->style.scrollv.cursor_hover = ctx->style.scrollv.cursor_normal; ctx->style.scrollv.show_buttons = true; ctx->style.scrollv.dec_button.normal = nk_style_item_image(sliderImg->getNkImage(scrollUpButtonIndex)); ctx->style.scrollv.dec_symbol = NK_SYMBOL_NONE; ctx->style.scrollv.inc_button.normal = nk_style_item_image(sliderImg->getNkImage(scrollDownButtonIndex)); ctx->style.scrollv.inc_symbol = NK_SYMBOL_NONE; ctx->style.scrollv.dec_button.active = ctx->style.scrollv.dec_button.normal; ctx->style.scrollv.dec_button.hover = ctx->style.scrollv.dec_button.normal; ctx->style.scrollv.inc_button.active = ctx->style.scrollv.inc_button.normal; ctx->style.scrollv.inc_button.hover = ctx->style.scrollv.inc_button.normal; ctx->style.window.group_padding = nk_vec2(10, 10); ctx->style.window.scrollbar_size = nk_vec2(sliderImg->getWidth(), 0); } nk_group_scrolled_begin(ctx, &mScroll, "dialog_main", 0); { if (mDialogMenu.update(ctx, data.dialogOptions, mScroll) == MouseAndClickMenu::Result::Activated) result = data.dialogActions[mDialogMenu.getSelectedIndex()](); } nk_group_scrolled_end(ctx); }, true); return result; }
/* =============================================================== * * CUSTOM WIDGET * * ===============================================================*/ static int ui_piemenu(struct nk_context *ctx, struct nk_vec2 pos, float radius, struct nk_image *icons, int item_count) { int ret = -1; struct nk_rect total_space; struct nk_rect bounds; int active_item = 0; /* pie menu popup */ struct nk_color border = ctx->style.window.border_color; struct nk_style_item background = ctx->style.window.fixed_background; ctx->style.window.fixed_background = nk_style_item_hide(); ctx->style.window.border_color = nk_rgba(0,0,0,0); total_space = nk_window_get_content_region(ctx); ctx->style.window.spacing = nk_vec2(0,0); ctx->style.window.padding = nk_vec2(0,0); if (nk_popup_begin(ctx, NK_POPUP_STATIC, "piemenu", NK_WINDOW_NO_SCROLLBAR, nk_rect(pos.x - total_space.x - radius, pos.y - radius - total_space.y, 2*radius,2*radius))) { int i = 0; struct nk_command_buffer* out = nk_window_get_canvas(ctx); const struct nk_input *in = &ctx->input; total_space = nk_window_get_content_region(ctx); ctx->style.window.spacing = nk_vec2(4,4); ctx->style.window.padding = nk_vec2(8,8); nk_layout_row_dynamic(ctx, total_space.h, 1); nk_widget(&bounds, ctx); /* outer circle */ nk_fill_circle(out, bounds, nk_rgb(50,50,50)); { /* circle buttons */ float step = (2 * 3.141592654f) / (float)(MAX(1,item_count)); float a_min = 0; float a_max = step; struct nk_vec2 center = nk_vec2(bounds.x + bounds.w / 2.0f, bounds.y + bounds.h / 2.0f); struct nk_vec2 drag = nk_vec2(in->mouse.pos.x - center.x, in->mouse.pos.y - center.y); float angle = (float)atan2(drag.y, drag.x); if (angle < -0.0f) angle += 2.0f * 3.141592654f; active_item = (int)(angle/step); for (i = 0; i < item_count; ++i) { struct nk_rect content; float rx, ry, dx, dy, a; nk_fill_arc(out, center.x, center.y, (bounds.w/2.0f), a_min, a_max, (active_item == i) ? nk_rgb(45,100,255): nk_rgb(60,60,60)); /* separator line */ rx = bounds.w/2.0f; ry = 0; dx = rx * (float)cos(a_min) - ry * (float)sin(a_min); dy = rx * (float)sin(a_min) + ry * (float)cos(a_min); nk_stroke_line(out, center.x, center.y, center.x + dx, center.y + dy, 1.0f, nk_rgb(50,50,50)); /* button content */ a = a_min + (a_max - a_min)/2.0f; rx = bounds.w/2.5f; ry = 0; content.w = 30; content.h = 30; content.x = center.x + ((rx * (float)cos(a) - ry * (float)sin(a)) - content.w/2.0f); content.y = center.y + (rx * (float)sin(a) + ry * (float)cos(a) - content.h/2.0f); nk_draw_image(out, content, &icons[i], nk_rgb(255,255,255)); a_min = a_max; a_max += step; } } { /* inner circle */ struct nk_rect inner; inner.x = bounds.x + bounds.w/2 - bounds.w/4; inner.y = bounds.y + bounds.h/2 - bounds.h/4; inner.w = bounds.w/2; inner.h = bounds.h/2; nk_fill_circle(out, inner, nk_rgb(45,45,45)); /* active icon content */ bounds.w = inner.w / 2.0f; bounds.h = inner.h / 2.0f; bounds.x = inner.x + inner.w/2 - bounds.w/2; bounds.y = inner.y + inner.h/2 - bounds.h/2; nk_draw_image(out, bounds, &icons[active_item], nk_rgb(255,255,255)); } nk_layout_space_end(ctx); if (!nk_input_is_mouse_down(&ctx->input, NK_BUTTON_RIGHT)) { nk_popup_close(ctx); ret = active_item; } } else ret = -2; ctx->style.window.spacing = nk_vec2(4,4); ctx->style.window.padding = nk_vec2(8,8); nk_popup_end(ctx); ctx->style.window.fixed_background = background; ctx->style.window.border_color = border; return ret; }
NK_API int nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len, struct nk_image img, struct nk_vec2 size) { struct nk_window *win; struct nk_style *style; struct nk_input *in; struct nk_rect header; int is_clicked = nk_false; enum nk_widget_layout_states s; const struct nk_style_item *background; struct nk_text text; NK_ASSERT(ctx); NK_ASSERT(ctx->current); NK_ASSERT(ctx->current->layout); if (!ctx || !ctx->current || !ctx->current->layout) return 0; win = ctx->current; style = &ctx->style; s = nk_widget(&header, ctx); if (!s) return 0; in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) is_clicked = nk_true; /* draw combo box header background and border */ if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) { background = &style->combo.active; text.text = style->combo.label_active; } else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) { background = &style->combo.hover; text.text = style->combo.label_hover; } else { background = &style->combo.normal; text.text = style->combo.label_normal; } if (background->type == NK_STYLE_ITEM_IMAGE) { text.background = nk_rgba(0,0,0,0); nk_draw_image(&win->buffer, header, &background->data.image, nk_white); } else { text.background = background->data.color; nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); } { struct nk_rect content; struct nk_rect button; struct nk_rect label; struct nk_rect image; enum nk_symbol_type sym; if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) sym = style->combo.sym_hover; else if (is_clicked) sym = style->combo.sym_active; else sym = style->combo.sym_normal; /* calculate button */ button.w = header.h - 2 * style->combo.button_padding.y; button.x = (header.x + header.w - header.h) - style->combo.button_padding.x; button.y = header.y + style->combo.button_padding.y; button.h = button.w; content.x = button.x + style->combo.button.padding.x; content.y = button.y + style->combo.button.padding.y; content.w = button.w - 2 * style->combo.button.padding.x; content.h = button.h - 2 * style->combo.button.padding.y; nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state, &ctx->style.combo.button, sym, style->font); /* draw image */ image.x = header.x + style->combo.content_padding.x; image.y = header.y + style->combo.content_padding.y; image.h = header.h - 2 * style->combo.content_padding.y; image.w = image.h; nk_draw_image(&win->buffer, image, &img, nk_white); /* draw label */ text.padding = nk_vec2(0,0); label.x = image.x + image.w + style->combo.spacing.x + style->combo.content_padding.x; label.y = header.y + style->combo.content_padding.y; label.w = (button.x - style->combo.content_padding.x) - label.x; label.h = header.h - 2 * style->combo.content_padding.y; nk_widget_text(&win->buffer, label, selected, len, &text, NK_TEXT_LEFT, style->font); } return nk_combo_begin(ctx, win, size, is_clicked, header); }