2017-02-10 04:54:28 +03:00
|
|
|
/* nuklear - v1.32.0 - public domain */
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2017-03-01 03:32:55 +03:00
|
|
|
#include <SFML/OpenGL.hpp>
|
2017-02-10 04:54:28 +03:00
|
|
|
#include <SFML/Window.hpp>
|
|
|
|
|
|
|
|
#define NK_INCLUDE_FIXED_TYPES
|
|
|
|
#define NK_INCLUDE_STANDARD_IO
|
|
|
|
#define NK_INCLUDE_STANDARD_VARARGS
|
|
|
|
#define NK_INCLUDE_DEFAULT_ALLOCATOR
|
|
|
|
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
|
|
|
|
#define NK_INCLUDE_FONT_BAKING
|
|
|
|
#define NK_INCLUDE_DEFAULT_FONT
|
|
|
|
#define NK_IMPLEMENTATION
|
|
|
|
#define NK_SFML_GL2_IMPLEMENTATION
|
|
|
|
#include "../../nuklear.h"
|
|
|
|
#include "nuklear_sfml_gl2.h"
|
|
|
|
|
2017-02-23 10:02:59 +03:00
|
|
|
#define WINDOW_WIDTH 1200
|
|
|
|
#define WINDOW_HEIGHT 800
|
2017-02-10 04:54:28 +03:00
|
|
|
|
|
|
|
/* ===============================================================
|
|
|
|
*
|
|
|
|
* EXAMPLE
|
|
|
|
*
|
|
|
|
* ===============================================================*/
|
|
|
|
/* This are some code examples to provide a small overview of what can be
|
2018-01-01 19:20:55 +03:00
|
|
|
* done with this library. To try out an example uncomment the defines */
|
|
|
|
/*#define INCLUDE_ALL */
|
|
|
|
/*#define INCLUDE_STYLE */
|
|
|
|
/*#define INCLUDE_CALCULATOR */
|
2021-12-16 18:16:33 +03:00
|
|
|
/*#define INCLUDE_CANVAS */
|
2018-01-01 19:20:55 +03:00
|
|
|
/*#define INCLUDE_OVERVIEW */
|
|
|
|
/*#define INCLUDE_NODE_EDITOR */
|
|
|
|
|
|
|
|
#ifdef INCLUDE_ALL
|
|
|
|
#define INCLUDE_STYLE
|
|
|
|
#define INCLUDE_CALCULATOR
|
2021-12-16 18:16:33 +03:00
|
|
|
#define INCLUDE_CANVAS
|
2018-01-01 19:20:55 +03:00
|
|
|
#define INCLUDE_OVERVIEW
|
|
|
|
#define INCLUDE_NODE_EDITOR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef INCLUDE_STYLE
|
2022-03-14 22:46:44 +03:00
|
|
|
#include "../../demo/common/style.c"
|
2018-01-01 19:20:55 +03:00
|
|
|
#endif
|
|
|
|
#ifdef INCLUDE_CALCULATOR
|
2022-03-14 22:46:44 +03:00
|
|
|
#include "../../demo/common/calculator.c"
|
2018-01-01 19:20:55 +03:00
|
|
|
#endif
|
2021-12-16 18:16:33 +03:00
|
|
|
#ifdef INCLUDE_CANVAS
|
2022-03-14 22:46:44 +03:00
|
|
|
#include "../../demo/common/canvas.c"
|
2021-12-16 18:16:33 +03:00
|
|
|
#endif
|
2018-01-01 19:20:55 +03:00
|
|
|
#ifdef INCLUDE_OVERVIEW
|
2022-03-14 22:46:44 +03:00
|
|
|
#include "../../demo/common/overview.c"
|
2018-01-01 19:20:55 +03:00
|
|
|
#endif
|
|
|
|
#ifdef INCLUDE_NODE_EDITOR
|
2022-03-14 22:46:44 +03:00
|
|
|
#include "../../demo/common/node_editor.c"
|
2018-01-01 19:20:55 +03:00
|
|
|
#endif
|
2017-02-10 04:54:28 +03:00
|
|
|
|
|
|
|
/* ===============================================================
|
|
|
|
*
|
|
|
|
* DEMO
|
|
|
|
*
|
|
|
|
* ===============================================================*/
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
/* Platform */
|
|
|
|
sf::ContextSettings settings(24, 8, 4, 2, 2);
|
2017-03-12 15:30:14 +03:00
|
|
|
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);
|
2017-02-10 04:54:28 +03:00
|
|
|
|
|
|
|
/* GUI */
|
2017-03-12 15:30:14 +03:00
|
|
|
struct nk_context *ctx;
|
|
|
|
ctx = nk_sfml_init(&win);
|
2017-02-10 04:54:28 +03:00
|
|
|
/* 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 */
|
2017-03-12 15:30:14 +03:00
|
|
|
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);*/
|
2017-02-10 04:54:28 +03:00
|
|
|
|
2018-01-05 15:09:27 +03:00
|
|
|
struct nk_colorf bg;
|
|
|
|
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
|
2017-03-12 15:30:14 +03:00
|
|
|
while (win.isOpen())
|
2017-02-10 04:54:28 +03:00
|
|
|
{
|
|
|
|
/* Input */
|
2017-03-12 15:30:14 +03:00
|
|
|
sf::Event evt;
|
2017-02-10 04:54:28 +03:00
|
|
|
nk_input_begin(ctx);
|
2017-03-12 15:30:14 +03:00
|
|
|
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);
|
2017-02-10 04:54:28 +03:00
|
|
|
}
|
|
|
|
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);
|
2018-01-05 15:09:27 +03:00
|
|
|
if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) {
|
2017-02-10 04:54:28 +03:00
|
|
|
nk_layout_row_dynamic(ctx, 120, 1);
|
2018-01-05 15:09:27 +03:00
|
|
|
bg = nk_color_picker(ctx, bg, NK_RGBA);
|
2017-02-10 04:54:28 +03:00
|
|
|
nk_layout_row_dynamic(ctx, 25, 1);
|
2018-01-05 15:09:27 +03:00
|
|
|
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);
|
2017-02-10 04:54:28 +03:00
|
|
|
nk_combo_end(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nk_end(ctx);
|
|
|
|
|
|
|
|
/* -------------- EXAMPLES ---------------- */
|
2018-01-01 19:20:55 +03:00
|
|
|
#ifdef INCLUDE_CALCULATOR
|
|
|
|
calculator(ctx);
|
|
|
|
#endif
|
2021-12-16 18:16:33 +03:00
|
|
|
#ifdef INCLUDE_CANVAS
|
|
|
|
canvas(ctx);
|
|
|
|
#endif
|
2018-01-01 19:20:55 +03:00
|
|
|
#ifdef INCLUDE_OVERVIEW
|
|
|
|
overview(ctx);
|
|
|
|
#endif
|
|
|
|
#ifdef INCLUDE_NODE_EDITOR
|
|
|
|
node_editor(ctx);
|
|
|
|
#endif
|
2017-02-10 04:54:28 +03:00
|
|
|
/* ----------------------------------------- */
|
|
|
|
|
|
|
|
/* Draw */
|
2017-03-12 15:30:14 +03:00
|
|
|
win.setActive(true);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2018-01-05 15:09:27 +03:00
|
|
|
glClearColor(bg.r, bg.g, bg.b, bg.a);
|
2017-03-12 15:30:14 +03:00
|
|
|
/* 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. */
|
2017-03-15 20:19:21 +03:00
|
|
|
nk_sfml_render(NK_ANTI_ALIASING_ON);
|
2017-03-12 15:30:14 +03:00
|
|
|
win.display();
|
2017-02-10 04:54:28 +03:00
|
|
|
}
|
|
|
|
nk_sfml_shutdown();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|