165 lines
5.8 KiB
C
165 lines
5.8 KiB
C
/* nuklear - v1.00 - public domain */
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
#include <math.h>
|
|
#include <assert.h>
|
|
#include <math.h>
|
|
#include <limits.h>
|
|
#include <time.h>
|
|
|
|
/* macros */
|
|
#define WINDOW_WIDTH 1200
|
|
#define WINDOW_HEIGHT 800
|
|
|
|
#define MAX_VERTEX_MEMORY 512 * 1024
|
|
#define MAX_ELEMENT_MEMORY 128 * 1024
|
|
|
|
#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
|
|
#define NK_ALLEGRO_IMPLEMENTATION
|
|
#include "../../nuklear.h"
|
|
#include "nuklear_allegro.h"
|
|
|
|
#define UNUSED(a) (void)a
|
|
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
|
#define MAX(a,b) ((a) < (b) ? (b) : (a))
|
|
#define LEN(a) (sizeof(a)/sizeof(a)[0])
|
|
|
|
/* ===============================================================
|
|
*
|
|
* EXAMPLE
|
|
*
|
|
* ===============================================================*/
|
|
/* This are some code examples to provide a small overview of what can be
|
|
* done with this library. To try out an example uncomment the include
|
|
* and the corresponding function. */
|
|
/*#include "../style.c"*/
|
|
/*#include "../calculator.c"*/
|
|
/*#include "../overview.c"*/
|
|
/*#include "../node_editor.c"*/
|
|
|
|
/* ===============================================================
|
|
*
|
|
* DEMO
|
|
*
|
|
* ===============================================================*/
|
|
int
|
|
main(void)
|
|
{
|
|
int running = 1;
|
|
struct nk_context *ctx;
|
|
struct nk_color background;
|
|
ALLEGRO_DISPLAY *display;
|
|
ALLEGRO_EVENT_QUEUE *queue;
|
|
|
|
/* Allegro */
|
|
al_init();
|
|
al_install_keyboard();
|
|
al_install_mouse();
|
|
al_init_primitives_addon();
|
|
display = al_create_display(WINDOW_WIDTH, WINDOW_HEIGHT);
|
|
al_set_window_title(display, "nuklear");
|
|
|
|
queue = al_create_event_queue();
|
|
al_register_event_source(queue, al_get_display_event_source(display));
|
|
al_register_event_source(queue, al_get_keyboard_event_source());
|
|
al_register_event_source(queue, al_get_mouse_event_source());
|
|
|
|
ctx = nk_allegro_init(display, MAX_VERTEX_MEMORY, MAX_ELEMENT_MEMORY);
|
|
/* Load Fonts: if none of these are loaded a default font will be used */
|
|
{struct nk_font_atlas *atlas;
|
|
nk_allegro_font_stash_begin(&atlas);
|
|
/*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/
|
|
/*struct nk_font *robot = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Robot-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_allegro_font_stash_end();
|
|
/*nk_style_set_font(ctx, &droid->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 */
|
|
ALLEGRO_EVENT evt;
|
|
nk_input_begin(ctx);
|
|
while (al_get_next_event(queue, &evt)) {
|
|
if (evt.type == ALLEGRO_EVENT_DISPLAY_CLOSE) goto cleanup;
|
|
nk_allegro_handle_event(&evt);
|
|
}
|
|
nk_input_end(ctx);
|
|
|
|
/* GUI */
|
|
{struct nk_panel layout;
|
|
if (nk_begin(ctx, &layout, "Demo", nk_rect(50, 50, 200, 200),
|
|
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", NK_BUTTON_DEFAULT))
|
|
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, 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);
|
|
al_clear_to_color(al_map_rgba_f(bg[0], bg[1], bg[2], bg[3]));
|
|
nk_allegro_render(NK_ANTI_ALIASING_ON);
|
|
al_flip_display();}
|
|
}
|
|
|
|
cleanup:
|
|
/* Cleanup */
|
|
if (queue) al_destroy_event_queue(queue);
|
|
if (display) al_destroy_display(display);
|
|
nk_allegro_shutdown();
|
|
return 0;
|
|
}
|
|
|