Nuklear now allows custom vertex layouts
I removed the default vertex type and instead create an API to allow the user to specify the vertex struct layout. Of course you are still bound on what the library actual has on vertex data but the type and sequence of the data is now configurable. This commit is quite experiental and could introduce some bugs, but so far it look fine.
This commit is contained in:
parent
210bc49b25
commit
1b9779ce51
@ -1,5 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
- 2016/09/02 (1.13) - Changed nuklear to not have any default vertex layout and
|
||||
instead made it user provided. The range of types to convert
|
||||
to is quite limited at the moment, but I would be more than
|
||||
happy to accept PRs to add additional.
|
||||
- 2016/08/30 (1.12) - Removed unused variables
|
||||
- 2016/08/30 (1.12) - Fixed C++ build errors
|
||||
- 2016/08/30 (1.12) - Removed mouse dragging from SDL demo since it does not work correctly
|
||||
|
@ -1,25 +0,0 @@
|
||||
# Install
|
||||
BIN = demo
|
||||
|
||||
# Flags
|
||||
CFLAGS = -std=c89 -pedantic
|
||||
|
||||
SRC = main.c
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
BIN := $(BIN).exe
|
||||
LIBS = -lmingw32 -lallegro -lallegro_primitives -lm
|
||||
else
|
||||
UNAME_S := $(shell uname -s)
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
LIBS = -lallegro -lallegro_primitives -lallegro_main -framework OpenGL -lm -lGLEW
|
||||
else
|
||||
LIBS = -lallegro -lallegro_primitives -lallegro_main -lGL -lm -lGLU -lGLEW
|
||||
endif
|
||||
endif
|
||||
|
||||
$(BIN):
|
||||
@mkdir -p bin
|
||||
rm -f bin/$(BIN) $(OBJS)
|
||||
$(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) $(LIBS)
|
@ -1,167 +0,0 @@
|
||||
/* nuklear - v1.09 - 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_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_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 */
|
||||
/* Load Cursor: if you uncomment cursor loading please hide the cursor */
|
||||
{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_load_all_cursors(ctx, atlas->cursors);*/
|
||||
/*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"))
|
||||
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;
|
||||
}
|
||||
|
@ -1,312 +0,0 @@
|
||||
/*
|
||||
* Nuklear - v1.00 - public domain
|
||||
* no warrenty implied; use at your own risk.
|
||||
* authored from 2015-2016 by Micha Mettke
|
||||
*/
|
||||
/*
|
||||
* ==============================================================
|
||||
*
|
||||
* API
|
||||
*
|
||||
* ===============================================================
|
||||
*/
|
||||
#ifndef NK_ALLEGRO_H_
|
||||
#define NK_ALLEGRO_H_
|
||||
|
||||
#include <allegro5/allegro.h>
|
||||
NK_API struct nk_context* nk_allegro_init(ALLEGRO_DISPLAY *win, int max_vertex_memory, int max_element_memory);
|
||||
NK_API void nk_allegro_font_stash_begin(struct nk_font_atlas **atlas);
|
||||
NK_API void nk_allegro_font_stash_end(void);
|
||||
|
||||
NK_API void nk_allegro_handle_event(ALLEGRO_EVENT *evt);
|
||||
NK_API void nk_allegro_render(enum nk_anti_aliasing);
|
||||
NK_API void nk_allegro_shutdown(void);
|
||||
|
||||
NK_API void nk_allegro_device_destroy(void);
|
||||
NK_API void nk_allegro_device_create(int max_vertex_memory, int max_elemnt_memory);
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ==============================================================
|
||||
*
|
||||
* IMPLEMENTATION
|
||||
*
|
||||
* ===============================================================
|
||||
*/
|
||||
#ifdef NK_ALLEGRO_IMPLEMENTATION
|
||||
|
||||
#include <allegro5/allegro_primitives.h>
|
||||
|
||||
struct nk_allegro_device {
|
||||
ALLEGRO_BITMAP *texture;
|
||||
ALLEGRO_VERTEX_DECL *vertex_decl;
|
||||
struct nk_draw_null_texture null;
|
||||
struct nk_buffer cmds;
|
||||
void *vertex_buffer;
|
||||
void *element_buffer;
|
||||
int max_vertex_memory;
|
||||
int max_element_memory;
|
||||
};
|
||||
|
||||
struct nk_allegro_vertex {
|
||||
struct nk_vec2 pos;
|
||||
struct nk_vec2 uv;
|
||||
ALLEGRO_COLOR col;
|
||||
};
|
||||
|
||||
static struct {
|
||||
ALLEGRO_DISPLAY *win;
|
||||
struct nk_allegro_device dev;
|
||||
struct nk_context ctx;
|
||||
struct nk_font_atlas atlas;
|
||||
} allegro;
|
||||
|
||||
|
||||
NK_API void
|
||||
nk_allegro_device_create(int max_vertex_memory, int max_element_memory)
|
||||
{
|
||||
struct nk_allegro_device *dev = &allegro.dev;
|
||||
ALLEGRO_VERTEX_ELEMENT elems[] = {
|
||||
{ALLEGRO_PRIM_POSITION, ALLEGRO_PRIM_FLOAT_2, offsetof(struct nk_allegro_vertex, pos)},
|
||||
{ALLEGRO_PRIM_TEX_COORD, ALLEGRO_PRIM_FLOAT_2, offsetof(struct nk_allegro_vertex, uv)},
|
||||
{ALLEGRO_PRIM_COLOR_ATTR, 0, offsetof(struct nk_allegro_vertex, col)},
|
||||
{0,0,0}
|
||||
};
|
||||
dev->vertex_decl = al_create_vertex_decl(elems, sizeof(struct nk_allegro_vertex));
|
||||
dev->vertex_buffer = calloc((size_t)max_vertex_memory, 1);
|
||||
dev->element_buffer = calloc((size_t)max_element_memory, 1);
|
||||
dev->max_vertex_memory = max_vertex_memory;
|
||||
dev->max_element_memory = max_element_memory;
|
||||
nk_buffer_init_default(&dev->cmds);
|
||||
}
|
||||
|
||||
static void
|
||||
nk_allegro_device_upload_atlas(const void *image, int width, int height)
|
||||
{
|
||||
/* create allegro font bitmap */
|
||||
ALLEGRO_BITMAP *bitmap = 0;
|
||||
struct nk_allegro_device *dev = &allegro.dev;
|
||||
int flags = al_get_new_bitmap_flags();
|
||||
int fmt = al_get_new_bitmap_format();
|
||||
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP|ALLEGRO_MIN_LINEAR|ALLEGRO_MAG_LINEAR);
|
||||
al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE);
|
||||
bitmap = al_create_bitmap(width, height);
|
||||
al_set_new_bitmap_flags(flags);
|
||||
al_set_new_bitmap_format(fmt);
|
||||
assert(bitmap);
|
||||
|
||||
{/* copy font texture into bitmap */
|
||||
ALLEGRO_LOCKED_REGION * locked_img;
|
||||
locked_img = al_lock_bitmap(bitmap, al_get_bitmap_format(bitmap), ALLEGRO_LOCK_WRITEONLY);
|
||||
assert(locked_img);
|
||||
memcpy(locked_img->data, image, sizeof(uint32_t)*(size_t)(width*height));
|
||||
al_unlock_bitmap(bitmap);}
|
||||
|
||||
/* convert software texture into hardware texture */
|
||||
dev->texture = al_clone_bitmap(bitmap);
|
||||
al_destroy_bitmap(bitmap);
|
||||
assert(dev->texture);
|
||||
}
|
||||
|
||||
NK_API void
|
||||
nk_allegro_render(enum nk_anti_aliasing AA)
|
||||
{
|
||||
int op, src, dst;
|
||||
struct nk_allegro_device *dev = &allegro.dev;
|
||||
struct nk_context *ctx = &allegro.ctx;
|
||||
al_get_blender(&op, &src, &dst);
|
||||
al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
|
||||
|
||||
{
|
||||
const struct nk_draw_command *cmd;
|
||||
struct nk_buffer vbuf, ebuf;
|
||||
int offset = 0;
|
||||
struct nk_allegro_vertex *vertices = 0;
|
||||
int *indices = 0;
|
||||
|
||||
/* fill converting configuration */
|
||||
struct nk_convert_config config;
|
||||
memset(&config, 0, sizeof(config));
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
config.circle_segment_count = 22;
|
||||
config.arc_segment_count = 22;
|
||||
config.curve_segment_count = 22;
|
||||
config.null = dev->null;
|
||||
|
||||
/* convert from command into hardware format */
|
||||
nk_buffer_init_fixed(&vbuf, dev->vertex_buffer, (nk_size)dev->max_vertex_memory);
|
||||
nk_buffer_init_fixed(&ebuf, dev->element_buffer, (nk_size)dev->max_element_memory);
|
||||
nk_convert(ctx, &dev->cmds, &vbuf, &ebuf, &config);
|
||||
|
||||
{
|
||||
/* <sign> allegro does not support 32-bit packed color */
|
||||
unsigned int i = 0;
|
||||
struct nk_draw_vertex *verts = (struct nk_draw_vertex*)dev->vertex_buffer;
|
||||
vertices = (struct nk_allegro_vertex*)calloc(sizeof(struct nk_allegro_vertex), ctx->draw_list.vertex_count);
|
||||
for (i = 0; i < ctx->draw_list.vertex_count; ++i) {
|
||||
nk_byte *c;
|
||||
vertices[i].pos = verts[i].position;
|
||||
vertices[i].uv = verts[i].uv;
|
||||
c = (nk_byte*)&verts[i].col;
|
||||
vertices[i].col = al_map_rgba(c[0], c[1], c[2], c[3]);
|
||||
}
|
||||
}
|
||||
{
|
||||
/* <massive sign> allegro does not support 16-bit indices:
|
||||
* @OPT: define nk_draw_index as int to fix this issue. */
|
||||
unsigned int i = 0;
|
||||
nk_draw_index *elements = (nk_draw_index*)dev->element_buffer;
|
||||
indices = (int*)calloc(sizeof(int), ctx->draw_list.element_count);
|
||||
for (i = 0; i < ctx->draw_list.element_count; ++i)
|
||||
indices[i] = elements[i];
|
||||
}
|
||||
|
||||
/* iterate over and execute each draw command */
|
||||
nk_draw_foreach(cmd, ctx, &dev->cmds)
|
||||
{
|
||||
ALLEGRO_BITMAP *texture = (ALLEGRO_BITMAP*)cmd->texture.ptr;
|
||||
if (!cmd->elem_count) continue;
|
||||
al_set_clipping_rectangle((int)cmd->clip_rect.x, (int)cmd->clip_rect.y,
|
||||
(int)cmd->clip_rect.w, (int)cmd->clip_rect.h);
|
||||
al_draw_indexed_prim(vertices, dev->vertex_decl, texture, &indices[offset],
|
||||
(int)cmd->elem_count, ALLEGRO_PRIM_TRIANGLE_LIST);
|
||||
offset += cmd->elem_count;
|
||||
}
|
||||
|
||||
free(vertices);
|
||||
free(indices);
|
||||
nk_clear(ctx);
|
||||
}
|
||||
al_set_blender(op, src, dst);
|
||||
al_set_clipping_rectangle(0,0, al_get_display_width(allegro.win),
|
||||
al_get_display_height(allegro.win));
|
||||
}
|
||||
|
||||
NK_API void
|
||||
nk_allegro_device_destroy(void)
|
||||
{
|
||||
struct nk_allegro_device *dev = &allegro.dev;
|
||||
free(dev->vertex_buffer);
|
||||
free(dev->element_buffer);
|
||||
nk_buffer_free(&dev->cmds);
|
||||
}
|
||||
|
||||
|
||||
NK_API struct nk_context*
|
||||
nk_allegro_init(ALLEGRO_DISPLAY *win, int max_vertex_memory, int max_element_memory)
|
||||
{
|
||||
allegro.win = win;
|
||||
nk_init_default(&allegro.ctx, 0);
|
||||
nk_allegro_device_create(max_vertex_memory, max_element_memory);
|
||||
return &allegro.ctx;
|
||||
}
|
||||
|
||||
NK_API void
|
||||
nk_allegro_font_stash_begin(struct nk_font_atlas **atlas)
|
||||
{
|
||||
nk_font_atlas_init_default(&allegro.atlas);
|
||||
nk_font_atlas_begin(&allegro.atlas);
|
||||
*atlas = &allegro.atlas;
|
||||
}
|
||||
|
||||
NK_API void
|
||||
nk_allegro_font_stash_end(void)
|
||||
{
|
||||
const void *image; int w, h;
|
||||
image = nk_font_atlas_bake(&allegro.atlas, &w, &h, NK_FONT_ATLAS_RGBA32);
|
||||
nk_allegro_device_upload_atlas(image, w, h);
|
||||
nk_font_atlas_end(&allegro.atlas, nk_handle_ptr(allegro.dev.texture), &allegro.dev.null);
|
||||
if (allegro.atlas.default_font)
|
||||
nk_style_set_font(&allegro.ctx, &allegro.atlas.default_font->handle);
|
||||
}
|
||||
|
||||
|
||||
NK_API void
|
||||
nk_allegro_handle_event(ALLEGRO_EVENT *evt)
|
||||
{
|
||||
struct nk_context *ctx = &allegro.ctx;
|
||||
if ((evt->type == ALLEGRO_EVENT_KEY_UP ||
|
||||
evt->type == ALLEGRO_EVENT_KEY_DOWN) &&
|
||||
evt->keyboard.display == allegro.win)
|
||||
{
|
||||
/* key handler */
|
||||
int down = (evt->type == ALLEGRO_EVENT_KEY_UP);
|
||||
int sym = evt->keyboard.keycode;
|
||||
if (sym == ALLEGRO_KEY_RSHIFT || sym == ALLEGRO_KEY_LSHIFT)
|
||||
nk_input_key(ctx, NK_KEY_SHIFT, down);
|
||||
else if (sym == ALLEGRO_KEY_DELETE)
|
||||
nk_input_key(ctx, NK_KEY_DEL, down);
|
||||
else if (sym == ALLEGRO_KEY_ENTER)
|
||||
nk_input_key(ctx, NK_KEY_ENTER, down);
|
||||
else if (sym == ALLEGRO_KEY_TAB)
|
||||
nk_input_key(ctx, NK_KEY_TAB, down);
|
||||
else if (sym == ALLEGRO_KEY_BACKSPACE)
|
||||
nk_input_key(ctx, NK_KEY_BACKSPACE, down);
|
||||
else if (sym == ALLEGRO_KEY_LEFT) {
|
||||
if (evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL)
|
||||
nk_input_key(ctx, NK_KEY_TEXT_WORD_LEFT, down);
|
||||
else nk_input_key(ctx, NK_KEY_LEFT, down);
|
||||
} else if (sym == ALLEGRO_KEY_RIGHT) {
|
||||
if (evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL)
|
||||
nk_input_key(ctx, NK_KEY_TEXT_WORD_RIGHT, down);
|
||||
else nk_input_key(ctx, NK_KEY_RIGHT, down);
|
||||
} else if (sym == ALLEGRO_KEY_HOME) {
|
||||
nk_input_key(ctx, NK_KEY_TEXT_START, down);
|
||||
nk_input_key(ctx, NK_KEY_SCROLL_START, down);
|
||||
} else if (sym == ALLEGRO_KEY_END) {
|
||||
nk_input_key(ctx, NK_KEY_TEXT_END, down);
|
||||
nk_input_key(ctx, NK_KEY_SCROLL_END, down);
|
||||
} else if (sym == ALLEGRO_KEY_C)
|
||||
nk_input_key(ctx, NK_KEY_COPY, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
else if (sym == ALLEGRO_KEY_PGUP)
|
||||
nk_input_key(ctx, NK_KEY_SCROLL_UP, down);
|
||||
else if (sym == ALLEGRO_KEY_PGDN)
|
||||
nk_input_key(ctx, NK_KEY_SCROLL_DOWN, down);
|
||||
else if (sym == ALLEGRO_KEY_V)
|
||||
nk_input_key(ctx, NK_KEY_PASTE, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
else if (sym == ALLEGRO_KEY_X)
|
||||
nk_input_key(ctx, NK_KEY_CUT, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
else if (sym == ALLEGRO_KEY_Z)
|
||||
nk_input_key(ctx, NK_KEY_TEXT_UNDO, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
else if (sym == ALLEGRO_KEY_R)
|
||||
nk_input_key(ctx, NK_KEY_TEXT_REDO, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
else if (sym == ALLEGRO_KEY_X)
|
||||
nk_input_key(ctx, NK_KEY_CUT, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
else if (sym == ALLEGRO_KEY_B)
|
||||
nk_input_key(ctx, NK_KEY_TEXT_LINE_START, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
else if (sym == ALLEGRO_KEY_E)
|
||||
nk_input_key(ctx, NK_KEY_TEXT_LINE_END, down && evt->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL);
|
||||
|
||||
} else if (evt->type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN ||
|
||||
evt->type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
|
||||
/* button handler */
|
||||
int down = evt->type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN;
|
||||
const int x = evt->mouse.x, y = evt->mouse.y;
|
||||
if (evt->mouse.button == 1)
|
||||
nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down);
|
||||
if (evt->mouse.button == 2)
|
||||
nk_input_button(ctx, NK_BUTTON_RIGHT, x, y, down);
|
||||
} else if (evt->type == ALLEGRO_EVENT_MOUSE_AXES) {
|
||||
/* mouse motion */
|
||||
nk_input_motion(ctx, evt->mouse.x, evt->mouse.y);
|
||||
} else if (evt->type == ALLEGRO_EVENT_KEY_CHAR) {
|
||||
/* text input */
|
||||
if (evt->keyboard.display == allegro.win)
|
||||
if (evt->keyboard.unichar > 32 && evt->keyboard.unichar < 0x10000)
|
||||
nk_input_unicode(ctx, (nk_rune)evt->keyboard.unichar);
|
||||
}
|
||||
}
|
||||
|
||||
NK_API void
|
||||
nk_allegro_shutdown(void)
|
||||
{
|
||||
if (allegro.dev.texture)
|
||||
al_destroy_bitmap(allegro.dev.texture);
|
||||
free(allegro.dev.vertex_buffer);
|
||||
free(allegro.dev.element_buffer);
|
||||
}
|
||||
|
||||
#endif
|
@ -49,6 +49,12 @@ NK_API void nk_d3d11_shutdown(void);
|
||||
#include "nuklear_d3d11_vertex_shader.h"
|
||||
#include "nuklear_d3d11_pixel_shader.h"
|
||||
|
||||
struct nk_d3d11_vertex {
|
||||
float position[2];
|
||||
float uv[2];
|
||||
nk_byte col[4];
|
||||
};
|
||||
|
||||
static struct
|
||||
{
|
||||
struct nk_context ctx;
|
||||
@ -77,7 +83,7 @@ NK_API void
|
||||
nk_d3d11_render(ID3D11DeviceContext *context, enum nk_anti_aliasing AA)
|
||||
{
|
||||
const float blend_factor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
const UINT stride = sizeof(struct nk_draw_vertex);
|
||||
const UINT stride = sizeof(struct nk_d3d11_vertex);
|
||||
const UINT offset = 0;
|
||||
|
||||
ID3D11DeviceContext_IASetInputLayout(context, d3d11.input_layout);
|
||||
@ -435,9 +441,9 @@ nk_d3d11_init(ID3D11Device *device, int width, int height, unsigned int max_vert
|
||||
|
||||
/* input layout */
|
||||
{const D3D11_INPUT_ELEMENT_DESC layout[] = {
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, offsetof(struct nk_draw_vertex, position), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(struct nk_draw_vertex, uv), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, offsetof(struct nk_draw_vertex, col), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, offsetof(struct nk_d3d11_vertex, position), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(struct nk_d3d11_vertex, uv), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, offsetof(struct nk_d3d11_vertex, col), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
hr = ID3D11Device_CreateInputLayout(device,layout, ARRAYSIZE(layout), nk_d3d11_vertex_shader, sizeof(nk_d3d11_vertex_shader), &d3d11.input_layout);
|
||||
NK_ASSERT(SUCCEEDED(hr));}
|
||||
|
@ -51,6 +51,12 @@ struct nk_glfw_device {
|
||||
GLuint font_tex;
|
||||
};
|
||||
|
||||
struct nk_glfw_vertex {
|
||||
float position[2];
|
||||
float uv[2];
|
||||
nk_byte col[4];
|
||||
};
|
||||
|
||||
static struct nk_glfw {
|
||||
GLFWwindow *win;
|
||||
int width, height;
|
||||
@ -103,26 +109,35 @@ nk_glfw3_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
{
|
||||
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);
|
||||
GLsizei vs = sizeof(struct nk_glfw_vertex);
|
||||
size_t vp = offsetof(struct nk_glfw_vertex, position);
|
||||
size_t vt = offsetof(struct nk_glfw_vertex, uv);
|
||||
size_t vc = offsetof(struct nk_glfw_vertex, col);
|
||||
|
||||
/* convert from command queue into draw list and draw to screen */
|
||||
const struct nk_draw_command *cmd;
|
||||
const nk_draw_index *offset = NULL;
|
||||
struct nk_buffer vbuf, ebuf;
|
||||
|
||||
/* fill converting configuration */
|
||||
/* fill convert configuration */
|
||||
struct nk_convert_config config;
|
||||
memset(&config, 0, sizeof(config));
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
static const struct nk_draw_vertex_layout_element vertex_layout[] = {
|
||||
{NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, position)},
|
||||
{NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, uv)},
|
||||
{NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_glfw_vertex, col)},
|
||||
{NK_VERTEX_LAYOUT_END}
|
||||
};
|
||||
NK_MEMSET(&config, 0, sizeof(config));
|
||||
config.vertex_layout = vertex_layout;
|
||||
config.vertex_size = sizeof(struct nk_glfw_vertex);
|
||||
config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex);
|
||||
config.null = dev->null;
|
||||
config.circle_segment_count = 22;
|
||||
config.curve_segment_count = 22;
|
||||
config.arc_segment_count = 22;
|
||||
config.null = dev->null;
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
|
||||
/* convert shapes into vertexes */
|
||||
nk_buffer_init_default(&vbuf);
|
||||
|
@ -62,6 +62,12 @@ struct nk_glfw_device {
|
||||
GLuint font_tex;
|
||||
};
|
||||
|
||||
struct nk_glfw_vertex {
|
||||
float position[2];
|
||||
float uv[2];
|
||||
nk_byte col[4];
|
||||
};
|
||||
|
||||
static struct nk_glfw {
|
||||
GLFWwindow *win;
|
||||
int width, height;
|
||||
@ -136,10 +142,10 @@ nk_glfw3_device_create(void)
|
||||
|
||||
{
|
||||
/* 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);
|
||||
GLsizei vs = sizeof(struct nk_glfw_vertex);
|
||||
size_t vp = offsetof(struct nk_glfw_vertex, position);
|
||||
size_t vt = offsetof(struct nk_glfw_vertex, uv);
|
||||
size_t vc = offsetof(struct nk_glfw_vertex, col);
|
||||
|
||||
glGenBuffers(1, &dev->vbo);
|
||||
glGenBuffers(1, &dev->ebo);
|
||||
@ -236,16 +242,25 @@ nk_glfw3_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element
|
||||
vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
{
|
||||
/* fill converting configuration */
|
||||
/* fill convert configuration */
|
||||
struct nk_convert_config config;
|
||||
memset(&config, 0, sizeof(config));
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
static const struct nk_draw_vertex_layout_element vertex_layout[] = {
|
||||
{NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, position)},
|
||||
{NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_glfw_vertex, uv)},
|
||||
{NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_glfw_vertex, col)},
|
||||
{NK_VERTEX_LAYOUT_END}
|
||||
};
|
||||
NK_MEMSET(&config, 0, sizeof(config));
|
||||
config.vertex_layout = vertex_layout;
|
||||
config.vertex_size = sizeof(struct nk_glfw_vertex);
|
||||
config.vertex_alignment = NK_ALIGNOF(struct nk_glfw_vertex);
|
||||
config.null = dev->null;
|
||||
config.circle_segment_count = 22;
|
||||
config.curve_segment_count = 22;
|
||||
config.arc_segment_count = 22;
|
||||
config.null = dev->null;
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
|
||||
/* setup buffers to load vertices and elements */
|
||||
{struct nk_buffer vbuf, ebuf;
|
||||
|
@ -37,6 +37,12 @@ struct nk_sdl_device {
|
||||
GLuint font_tex;
|
||||
};
|
||||
|
||||
struct nk_sdl_vertex {
|
||||
float position[2];
|
||||
float uv[2];
|
||||
nk_byte col[4];
|
||||
};
|
||||
|
||||
static struct nk_sdl {
|
||||
SDL_Window *win;
|
||||
struct nk_sdl_device ogl;
|
||||
@ -92,10 +98,10 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
{
|
||||
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);
|
||||
GLsizei vs = sizeof(struct nk_sdl_vertex);
|
||||
size_t vp = offsetof(struct nk_sdl_vertex, position);
|
||||
size_t vt = offsetof(struct nk_sdl_vertex, uv);
|
||||
size_t vc = offsetof(struct nk_sdl_vertex, col);
|
||||
|
||||
/* convert from command queue into draw list and draw to screen */
|
||||
const struct nk_draw_command *cmd;
|
||||
@ -104,14 +110,23 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
|
||||
|
||||
/* fill converting configuration */
|
||||
struct nk_convert_config config;
|
||||
memset(&config, 0, sizeof(config));
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
static const struct nk_draw_vertex_layout_element vertex_layout[] = {
|
||||
{NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_sdl_vertex, position)},
|
||||
{NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_sdl_vertex, uv)},
|
||||
{NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_sdl_vertex, col)},
|
||||
{NK_VERTEX_LAYOUT_END}
|
||||
};
|
||||
NK_MEMSET(&config, 0, sizeof(config));
|
||||
config.vertex_layout = vertex_layout;
|
||||
config.vertex_size = sizeof(struct nk_sdl_vertex);
|
||||
config.vertex_alignment = NK_ALIGNOF(struct nk_sdl_vertex);
|
||||
config.null = dev->null;
|
||||
config.circle_segment_count = 22;
|
||||
config.curve_segment_count = 22;
|
||||
config.arc_segment_count = 22;
|
||||
config.null = dev->null;
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
|
||||
/* convert shapes into vertexes */
|
||||
nk_buffer_init_default(&vbuf);
|
||||
|
@ -53,6 +53,12 @@ struct nk_sdl_device {
|
||||
GLuint font_tex;
|
||||
};
|
||||
|
||||
struct nk_sdl_vertex {
|
||||
float position[2];
|
||||
float uv[2];
|
||||
nk_byte col[4];
|
||||
};
|
||||
|
||||
static struct nk_sdl {
|
||||
SDL_Window *win;
|
||||
struct nk_sdl_device ogl;
|
||||
@ -120,10 +126,10 @@ nk_sdl_device_create(void)
|
||||
|
||||
{
|
||||
/* 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);
|
||||
GLsizei vs = sizeof(struct nk_sdl_vertex);
|
||||
size_t vp = offsetof(struct nk_sdl_vertex, position);
|
||||
size_t vt = offsetof(struct nk_sdl_vertex, uv);
|
||||
size_t vc = offsetof(struct nk_sdl_vertex, col);
|
||||
|
||||
glGenBuffers(1, &dev->vbo);
|
||||
glGenBuffers(1, &dev->ebo);
|
||||
@ -228,16 +234,25 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
|
||||
vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
{
|
||||
/* fill converting configuration */
|
||||
/* fill convert configuration */
|
||||
struct nk_convert_config config;
|
||||
memset(&config, 0, sizeof(config));
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
static const struct nk_draw_vertex_layout_element vertex_layout[] = {
|
||||
{NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_sdl_vertex, position)},
|
||||
{NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_sdl_vertex, uv)},
|
||||
{NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_sdl_vertex, col)},
|
||||
{NK_VERTEX_LAYOUT_END}
|
||||
};
|
||||
NK_MEMSET(&config, 0, sizeof(config));
|
||||
config.vertex_layout = vertex_layout;
|
||||
config.vertex_size = sizeof(struct nk_sdl_vertex);
|
||||
config.vertex_alignment = NK_ALIGNOF(struct nk_sdl_vertex);
|
||||
config.null = dev->null;
|
||||
config.circle_segment_count = 22;
|
||||
config.curve_segment_count = 22;
|
||||
config.arc_segment_count = 22;
|
||||
config.null = dev->null;
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
|
||||
/* setup buffers to load vertices and elements */
|
||||
{struct nk_buffer vbuf, ebuf;
|
||||
@ -330,17 +345,6 @@ NK_API int
|
||||
nk_sdl_handle_event(SDL_Event *evt)
|
||||
{
|
||||
struct nk_context *ctx = &sdl.ctx;
|
||||
|
||||
/* optional grabbing behavior */
|
||||
if (ctx->input.mouse.grab) {
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
ctx->input.mouse.grab = 0;
|
||||
} else if (ctx->input.mouse.ungrab) {
|
||||
int x = (int)ctx->input.mouse.prev.x, y = (int)ctx->input.mouse.prev.y;
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
SDL_WarpMouseInWindow(sdl.win, x, y);
|
||||
ctx->input.mouse.ungrab = 0;
|
||||
}
|
||||
if (evt->type == SDL_KEYUP || evt->type == SDL_KEYDOWN) {
|
||||
/* key events */
|
||||
int down = evt->type == SDL_KEYDOWN;
|
||||
|
@ -48,6 +48,12 @@ NK_API void nk_x11_shutdown(void);
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
struct nk_x11_vertex {
|
||||
float position[2];
|
||||
float uv[2];
|
||||
nk_byte col[4];
|
||||
};
|
||||
|
||||
struct nk_x11_device {
|
||||
struct nk_buffer cmds;
|
||||
struct nk_draw_null_texture null;
|
||||
@ -109,26 +115,35 @@ nk_x11_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
{
|
||||
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);
|
||||
GLsizei vs = sizeof(struct nk_x11_vertex);
|
||||
size_t vp = offsetof(struct nk_x11_vertex, position);
|
||||
size_t vt = offsetof(struct nk_x11_vertex, uv);
|
||||
size_t vc = offsetof(struct nk_x11_vertex, col);
|
||||
|
||||
/* convert from command queue into draw list and draw to screen */
|
||||
const struct nk_draw_command *cmd;
|
||||
const nk_draw_index *offset = NULL;
|
||||
struct nk_buffer vbuf, ebuf;
|
||||
|
||||
/* fill converting configuration */
|
||||
/* fill convert configuration */
|
||||
struct nk_convert_config config;
|
||||
memset(&config, 0, sizeof(config));
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
static const struct nk_draw_vertex_layout_element vertex_layout[] = {
|
||||
{NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_x11_vertex, position)},
|
||||
{NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_x11_vertex, uv)},
|
||||
{NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_x11_vertex, col)},
|
||||
{NK_VERTEX_LAYOUT_END}
|
||||
};
|
||||
NK_MEMSET(&config, 0, sizeof(config));
|
||||
config.vertex_layout = vertex_layout;
|
||||
config.vertex_size = sizeof(struct nk_x11_vertex);
|
||||
config.vertex_alignment = NK_ALIGNOF(struct nk_x11_vertex);
|
||||
config.null = dev->null;
|
||||
config.circle_segment_count = 22;
|
||||
config.curve_segment_count = 22;
|
||||
config.arc_segment_count = 22;
|
||||
config.null = dev->null;
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
|
||||
/* convert shapes into vertexes */
|
||||
nk_buffer_init_default(&vbuf);
|
||||
|
@ -158,6 +158,12 @@ struct opengl_info {
|
||||
};
|
||||
#endif
|
||||
|
||||
struct nk_x11_vertex {
|
||||
float position[2];
|
||||
float uv[2];
|
||||
nk_byte col[4];
|
||||
};
|
||||
|
||||
struct nk_x11_device {
|
||||
#ifdef NK_XLIB_LOAD_OPENGL_EXTENSIONS
|
||||
struct opengl_info info;
|
||||
@ -398,10 +404,10 @@ nk_x11_device_create(void)
|
||||
|
||||
{
|
||||
/* 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);
|
||||
GLsizei vs = sizeof(struct nk_x11_vertex);
|
||||
size_t vp = offsetof(struct nk_x11_vertex, position);
|
||||
size_t vt = offsetof(struct nk_x11_vertex, uv);
|
||||
size_t vc = offsetof(struct nk_x11_vertex, col);
|
||||
|
||||
glGenBuffers(1, &dev->vbo);
|
||||
glGenBuffers(1, &dev->ebo);
|
||||
@ -505,16 +511,25 @@ nk_x11_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_b
|
||||
vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
{
|
||||
/* fill converting configuration */
|
||||
/* fill convert configuration */
|
||||
struct nk_convert_config config;
|
||||
memset(&config, 0, sizeof(config));
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
static const struct nk_draw_vertex_layout_element vertex_layout[] = {
|
||||
{NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_x11_vertex, position)},
|
||||
{NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_x11_vertex, uv)},
|
||||
{NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_x11_vertex, col)},
|
||||
{NK_VERTEX_LAYOUT_END}
|
||||
};
|
||||
NK_MEMSET(&config, 0, sizeof(config));
|
||||
config.vertex_layout = vertex_layout;
|
||||
config.vertex_size = sizeof(struct nk_x11_vertex);
|
||||
config.vertex_alignment = NK_ALIGNOF(struct nk_x11_vertex);
|
||||
config.null = dev->null;
|
||||
config.circle_segment_count = 22;
|
||||
config.curve_segment_count = 22;
|
||||
config.arc_segment_count = 22;
|
||||
config.null = dev->null;
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
|
||||
/* setup buffers to load vertices and elements */
|
||||
{struct nk_buffer vbuf, ebuf;
|
||||
|
395
nuklear.h
395
nuklear.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Nuklear - v1.12 - public domain
|
||||
Nuklear - v1.13 - public domain
|
||||
no warrenty implied; use at your own risk.
|
||||
authored from 2015-2016 by Micha Mettke
|
||||
|
||||
@ -314,9 +314,11 @@ struct nk_draw_list;
|
||||
struct nk_user_font;
|
||||
struct nk_panel;
|
||||
struct nk_context;
|
||||
struct nk_draw_vertex_layout_element;
|
||||
|
||||
enum {nk_false, nk_true};
|
||||
struct nk_color {nk_byte r,g,b,a;};
|
||||
struct nk_colorf {float r,g,b,a;};
|
||||
struct nk_vec2 {float x,y;};
|
||||
struct nk_vec2i {short x, y;};
|
||||
struct nk_rect {float x,y,w,h;};
|
||||
@ -365,6 +367,9 @@ struct nk_convert_config {
|
||||
unsigned int arc_segment_count; /* number of segments used for arcs: default to 22 */
|
||||
unsigned int curve_segment_count; /* number of segments used for curves: default to 22 */
|
||||
struct nk_draw_null_texture null; /* handle to texture with a white pixel for shape drawing */
|
||||
const struct nk_draw_vertex_layout_element *vertex_layout; /* describes the vertex output format and packing */
|
||||
nk_size vertex_size; /* sizeof one vertex for vertex packing */
|
||||
nk_size vertex_alignment; /* vertex alignment: Can be optained by NK_ALIGNOF */
|
||||
};
|
||||
|
||||
enum nk_symbol_type {
|
||||
@ -1733,8 +1738,6 @@ NK_API int nk_input_is_key_down(const struct nk_input*, enum nk_keys);
|
||||
things than this library provides by default.
|
||||
*/
|
||||
typedef unsigned short nk_draw_index;
|
||||
typedef nk_uint nk_draw_vertex_color;
|
||||
|
||||
enum nk_draw_list_stroke {
|
||||
NK_STROKE_OPEN = nk_false,
|
||||
/* build up path has no connection back to the beginning */
|
||||
@ -1742,10 +1745,45 @@ enum nk_draw_list_stroke {
|
||||
/* build up path has a connection back to the beginning */
|
||||
};
|
||||
|
||||
struct nk_draw_vertex {
|
||||
struct nk_vec2 position;
|
||||
struct nk_vec2 uv;
|
||||
nk_draw_vertex_color col;
|
||||
enum nk_draw_vertex_layout_attribute {
|
||||
NK_VERTEX_POSITION,
|
||||
NK_VERTEX_COLOR,
|
||||
NK_VERTEX_TEXCOORD,
|
||||
NK_VERTEX_ATTRIBUTE_COUNT
|
||||
};
|
||||
|
||||
enum nk_draw_vertex_layout_format {
|
||||
NK_FORMAT_SCHAR,
|
||||
NK_FORMAT_SSHORT,
|
||||
NK_FORMAT_SINT,
|
||||
NK_FORMAT_UCHAR,
|
||||
NK_FORMAT_USHORT,
|
||||
NK_FORMAT_UINT,
|
||||
NK_FORMAT_FLOAT,
|
||||
NK_FORMAT_DOUBLE,
|
||||
|
||||
NK_FORMAT_COLOR_BEGIN,
|
||||
NK_FORMAT_R8G8B8 = NK_FORMAT_COLOR_BEGIN,
|
||||
NK_FORMAT_R16G15B16,
|
||||
NK_FORMAT_R32G32B32,
|
||||
|
||||
NK_FORMAT_R8G8B8A8,
|
||||
NK_FORMAT_R16G15B16A16,
|
||||
NK_FORMAT_R32G32B32A32,
|
||||
NK_FORMAT_R32G32B32A32_FLOAT,
|
||||
NK_FORMAT_R32G32B32A32_DOUBLE,
|
||||
|
||||
NK_FORMAT_RGB32,
|
||||
NK_FORMAT_RGBA32,
|
||||
NK_FORMAT_COLOR_END = NK_FORMAT_RGBA32,
|
||||
NK_FORMAT_COUNT
|
||||
};
|
||||
|
||||
#define NK_VERTEX_LAYOUT_END NK_VERTEX_ATTRIBUTE_COUNT,NK_FORMAT_COUNT,-1
|
||||
struct nk_draw_vertex_layout_element {
|
||||
enum nk_draw_vertex_layout_attribute attribute;
|
||||
enum nk_draw_vertex_layout_format format;
|
||||
int offset;
|
||||
};
|
||||
|
||||
struct nk_draw_command {
|
||||
@ -1761,10 +1799,7 @@ struct nk_draw_command {
|
||||
};
|
||||
|
||||
struct nk_draw_list {
|
||||
float global_alpha;
|
||||
enum nk_anti_aliasing shape_AA;
|
||||
enum nk_anti_aliasing line_AA;
|
||||
struct nk_draw_null_texture null;
|
||||
struct nk_convert_config config;
|
||||
struct nk_rect clip_rect;
|
||||
struct nk_buffer *buffer;
|
||||
struct nk_buffer *vertices;
|
||||
@ -1783,7 +1818,7 @@ struct nk_draw_list {
|
||||
|
||||
/* draw list */
|
||||
NK_API void nk_draw_list_init(struct nk_draw_list*);
|
||||
NK_API void nk_draw_list_setup(struct nk_draw_list*, float global_alpha, enum nk_anti_aliasing, enum nk_anti_aliasing, struct nk_draw_null_texture, struct nk_buffer *cmds, struct nk_buffer *vert, struct nk_buffer *elem);
|
||||
NK_API void nk_draw_list_setup(struct nk_draw_list *canvas, const struct nk_convert_config *config, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements);
|
||||
NK_API void nk_draw_list_clear(struct nk_draw_list*);
|
||||
|
||||
/* drawing */
|
||||
@ -2719,6 +2754,19 @@ template<typename T> struct nk_alignof{struct Big {T x; char c;}; enum {
|
||||
#define NK_DTOA nk_dtoa
|
||||
#endif
|
||||
|
||||
#define NK_SCHAR_MIN -127
|
||||
#define NK_SCHAR_MAX 127
|
||||
#define NK_UCHAR_MIN 0
|
||||
#define NK_UCHAR_MAX 256
|
||||
#define NK_SSHORT_MIN -32767
|
||||
#define NK_SSHORT_MAX 32767
|
||||
#define NK_USHORT_MIN 0
|
||||
#define NK_USHORT_MAX 65535
|
||||
#define NK_SINT_MIN -2147483647
|
||||
#define NK_SINT_MAX 2147483647
|
||||
#define NK_UINT_MIN 0
|
||||
#define NK_UINT_MAX 4294967295
|
||||
|
||||
/* Make sure correct type size:
|
||||
* This will fire with a negative subscript error if the type sizes
|
||||
* are set incorrectly by the compiler, and compile out if not */
|
||||
@ -3938,7 +3986,7 @@ nk_hsva_bv(const nk_byte *c)
|
||||
NK_API struct nk_color
|
||||
nk_hsva_f(float h, float s, float v, float a)
|
||||
{
|
||||
struct nk_colorf {float r,g,b;} out = {0,0,0};
|
||||
struct nk_colorf out = {0,0,0,0};
|
||||
float p, q, t, f;
|
||||
int i;
|
||||
|
||||
@ -5762,19 +5810,14 @@ nk_draw_list_init(struct nk_draw_list *list)
|
||||
}
|
||||
|
||||
NK_API void
|
||||
nk_draw_list_setup(struct nk_draw_list *canvas, float global_alpha,
|
||||
enum nk_anti_aliasing line_AA, enum nk_anti_aliasing shape_AA,
|
||||
struct nk_draw_null_texture null, struct nk_buffer *cmds,
|
||||
struct nk_buffer *vertices, struct nk_buffer *elements)
|
||||
nk_draw_list_setup(struct nk_draw_list *canvas, const struct nk_convert_config *config,
|
||||
struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements)
|
||||
{
|
||||
canvas->null = null;
|
||||
canvas->clip_rect = nk_null_rect;
|
||||
canvas->vertices = vertices;
|
||||
canvas->elements = elements;
|
||||
canvas->buffer = cmds;
|
||||
canvas->line_AA = line_AA;
|
||||
canvas->shape_AA = shape_AA;
|
||||
canvas->global_alpha = global_alpha;
|
||||
canvas->config = *config;
|
||||
canvas->elements = elements;
|
||||
canvas->vertices = vertices;
|
||||
canvas->clip_rect = nk_null_rect;
|
||||
}
|
||||
|
||||
NK_API const struct nk_draw_command*
|
||||
@ -5920,7 +5963,7 @@ nk_draw_list_add_clip(struct nk_draw_list *list, struct nk_rect rect)
|
||||
NK_ASSERT(list);
|
||||
if (!list) return;
|
||||
if (!list->cmd_count) {
|
||||
nk_draw_list_push_command(list, rect, list->null.texture);
|
||||
nk_draw_list_push_command(list, rect, list->config.null.texture);
|
||||
} else {
|
||||
struct nk_draw_command *prev = nk_draw_list_command_last(list);
|
||||
if (prev->elem_count == 0)
|
||||
@ -5969,17 +6012,14 @@ nk_draw_list_push_userdata(struct nk_draw_list *list, nk_handle userdata)
|
||||
}
|
||||
#endif
|
||||
|
||||
NK_INTERN struct nk_draw_vertex*
|
||||
NK_INTERN void*
|
||||
nk_draw_list_alloc_vertices(struct nk_draw_list *list, nk_size count)
|
||||
{
|
||||
struct nk_draw_vertex *vtx;
|
||||
NK_STORAGE const nk_size vtx_align = NK_ALIGNOF(struct nk_draw_vertex);
|
||||
NK_STORAGE const nk_size vtx_size = sizeof(struct nk_draw_vertex);
|
||||
void *vtx;
|
||||
NK_ASSERT(list);
|
||||
if (!list) return 0;
|
||||
|
||||
vtx = (struct nk_draw_vertex*)
|
||||
nk_buffer_alloc(list->vertices, NK_BUFFER_FRONT, vtx_size*count, vtx_align);
|
||||
vtx = nk_buffer_alloc(list->vertices, NK_BUFFER_FRONT,
|
||||
list->config.vertex_size*count, list->config.vertex_alignment);
|
||||
if (!vtx) return 0;
|
||||
list->vertex_count += (unsigned int)count;
|
||||
return vtx;
|
||||
@ -6004,14 +6044,151 @@ nk_draw_list_alloc_elements(struct nk_draw_list *list, nk_size count)
|
||||
return ids;
|
||||
}
|
||||
|
||||
NK_INTERN struct nk_draw_vertex
|
||||
nk_draw_vertex(struct nk_vec2 pos, struct nk_vec2 uv, nk_draw_vertex_color col)
|
||||
static int
|
||||
nk_draw_vertex_layout_element_is_end_of_layout(
|
||||
const struct nk_draw_vertex_layout_element *element)
|
||||
{
|
||||
struct nk_draw_vertex out;
|
||||
out.position = pos;
|
||||
out.uv = uv;
|
||||
out.col = col;
|
||||
return out;
|
||||
return (element->attribute == NK_VERTEX_ATTRIBUTE_COUNT ||
|
||||
element->format == NK_FORMAT_COUNT ||
|
||||
element->offset < 0);
|
||||
}
|
||||
|
||||
static void
|
||||
nk_draw_vertex_color(void *attribute, const float *values,
|
||||
enum nk_draw_vertex_layout_format format)
|
||||
{
|
||||
/* if this triggers you tried to provide a value format for a color */
|
||||
NK_ASSERT(format >= NK_FORMAT_COLOR_BEGIN);
|
||||
NK_ASSERT(format <= NK_FORMAT_COLOR_END);
|
||||
if (format < NK_FORMAT_COLOR_BEGIN && format > NK_FORMAT_COLOR_END) return;
|
||||
|
||||
switch (format) {
|
||||
case NK_FORMAT_R8G8B8A8:
|
||||
case NK_FORMAT_R8G8B8: {
|
||||
struct nk_color col = nk_rgba_fv(values);
|
||||
NK_MEMCPY(attribute, &col.r, sizeof(col));
|
||||
} break;
|
||||
case NK_FORMAT_R16G15B16: {
|
||||
nk_ushort col[3];
|
||||
col[0] = (nk_ushort)NK_CLAMP(NK_USHORT_MIN, values[0] * NK_USHORT_MAX, NK_USHORT_MAX);
|
||||
col[1] = (nk_ushort)NK_CLAMP(NK_USHORT_MIN, values[1] * NK_USHORT_MAX, NK_USHORT_MAX);
|
||||
col[2] = (nk_ushort)NK_CLAMP(NK_USHORT_MIN, values[2] * NK_USHORT_MAX, NK_USHORT_MAX);
|
||||
NK_MEMCPY(attribute, col, sizeof(col));
|
||||
} break;
|
||||
case NK_FORMAT_R16G15B16A16: {
|
||||
nk_ushort col[4];
|
||||
col[0] = (nk_ushort)NK_CLAMP(NK_USHORT_MIN, values[0] * NK_USHORT_MAX, NK_USHORT_MAX);
|
||||
col[1] = (nk_ushort)NK_CLAMP(NK_USHORT_MIN, values[1] * NK_USHORT_MAX, NK_USHORT_MAX);
|
||||
col[2] = (nk_ushort)NK_CLAMP(NK_USHORT_MIN, values[2] * NK_USHORT_MAX, NK_USHORT_MAX);
|
||||
col[3] = (nk_ushort)NK_CLAMP(NK_USHORT_MIN, values[3] * NK_USHORT_MAX, NK_USHORT_MAX);
|
||||
NK_MEMCPY(attribute, col, sizeof(col));
|
||||
} break;
|
||||
case NK_FORMAT_R32G32B32: {
|
||||
nk_uint col[3];
|
||||
col[0] = (nk_uint)NK_CLAMP(NK_UINT_MIN, values[0] * NK_UINT_MAX, NK_UINT_MAX);
|
||||
col[1] = (nk_uint)NK_CLAMP(NK_UINT_MIN, values[1] * NK_UINT_MAX, NK_UINT_MAX);
|
||||
col[2] = (nk_uint)NK_CLAMP(NK_UINT_MIN, values[2] * NK_UINT_MAX, NK_UINT_MAX);
|
||||
NK_MEMCPY(attribute, col, sizeof(col));
|
||||
} break;
|
||||
case NK_FORMAT_R32G32B32A32: {
|
||||
nk_uint col[4];
|
||||
col[0] = (nk_uint)NK_CLAMP(NK_UINT_MIN, values[0] * NK_UINT_MAX, NK_UINT_MAX);
|
||||
col[1] = (nk_uint)NK_CLAMP(NK_UINT_MIN, values[1] * NK_UINT_MAX, NK_UINT_MAX);
|
||||
col[2] = (nk_uint)NK_CLAMP(NK_UINT_MIN, values[2] * NK_UINT_MAX, NK_UINT_MAX);
|
||||
col[3] = (nk_uint)NK_CLAMP(NK_UINT_MIN, values[3] * NK_UINT_MAX, NK_UINT_MAX);
|
||||
NK_MEMCPY(attribute, col, sizeof(col));
|
||||
} break;
|
||||
case NK_FORMAT_R32G32B32A32_FLOAT:
|
||||
NK_MEMCPY(attribute, values, sizeof(float)*4);
|
||||
break;
|
||||
case NK_FORMAT_R32G32B32A32_DOUBLE: {
|
||||
double col[4];
|
||||
col[0] = (double)NK_SATURATE(values[0]);
|
||||
col[1] = (double)NK_SATURATE(values[1]);
|
||||
col[2] = (double)NK_SATURATE(values[2]);
|
||||
col[3] = (double)NK_SATURATE(values[3]);
|
||||
NK_MEMCPY(attribute, col, sizeof(col));
|
||||
} break;
|
||||
case NK_FORMAT_RGB32:
|
||||
case NK_FORMAT_RGBA32: {
|
||||
struct nk_color col = nk_rgba_fv(values);
|
||||
nk_uint color = nk_color_u32(col);
|
||||
NK_MEMCPY(attribute, &color, sizeof(color));
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nk_draw_vertex_element(void *dst, const float *values, int value_count,
|
||||
enum nk_draw_vertex_layout_format format)
|
||||
{
|
||||
int value_index;
|
||||
void *attribute = dst;
|
||||
/* if this triggers you tried to provide a color format for a value */
|
||||
NK_ASSERT(format < NK_FORMAT_COLOR_BEGIN);
|
||||
if (format >= NK_FORMAT_COLOR_BEGIN && format <= NK_FORMAT_COLOR_END) return;
|
||||
for (value_index = 0; value_index < value_count; ++value_index) {
|
||||
switch (format) {
|
||||
case NK_FORMAT_SCHAR: {
|
||||
char value = (char)NK_CLAMP(NK_SCHAR_MIN, values[value_index], NK_SCHAR_MAX);
|
||||
NK_MEMCPY(attribute, &value, sizeof(value));
|
||||
attribute = (void*)((char*)attribute + sizeof(char));
|
||||
} break;
|
||||
case NK_FORMAT_SSHORT: {
|
||||
nk_short value = (nk_short)NK_CLAMP(NK_SSHORT_MIN, values[value_index], NK_SSHORT_MAX);
|
||||
NK_MEMCPY(attribute, &value, sizeof(value));
|
||||
attribute = (void*)((char*)attribute + sizeof(value));
|
||||
} break;
|
||||
case NK_FORMAT_SINT: {
|
||||
nk_int value = (nk_int)NK_CLAMP(NK_SINT_MIN, values[value_index], NK_SINT_MAX);
|
||||
NK_MEMCPY(attribute, &value, sizeof(value));
|
||||
attribute = (void*)((char*)attribute + sizeof(nk_int));
|
||||
} break;
|
||||
case NK_FORMAT_UCHAR: {
|
||||
unsigned char value = (unsigned char)NK_CLAMP(NK_UCHAR_MIN, values[value_index], NK_UCHAR_MAX);
|
||||
NK_MEMCPY(attribute, &value, sizeof(value));
|
||||
attribute = (void*)((char*)attribute + sizeof(unsigned char));
|
||||
} break;
|
||||
case NK_FORMAT_USHORT: {
|
||||
nk_ushort value = (nk_ushort)NK_CLAMP(NK_USHORT_MIN, values[value_index], NK_USHORT_MAX);
|
||||
NK_MEMCPY(attribute, &value, sizeof(value));
|
||||
attribute = (void*)((char*)attribute + sizeof(value));
|
||||
} break;
|
||||
case NK_FORMAT_UINT: {
|
||||
nk_uint value = (nk_uint)NK_CLAMP(NK_UINT_MIN, values[value_index], NK_UINT_MAX);
|
||||
NK_MEMCPY(attribute, &value, sizeof(value));
|
||||
attribute = (void*)((char*)attribute + sizeof(nk_uint));
|
||||
} break;
|
||||
case NK_FORMAT_FLOAT:
|
||||
NK_MEMCPY(attribute, &values[value_index], sizeof(values[value_index]));
|
||||
attribute = (void*)((char*)attribute + sizeof(float));
|
||||
break;
|
||||
case NK_FORMAT_DOUBLE: {
|
||||
double value = (double)values[value_index];
|
||||
NK_MEMCPY(attribute, &value, sizeof(value));
|
||||
attribute = (void*)((char*)attribute + sizeof(double));
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NK_INTERN void*
|
||||
nk_draw_vertex(void *dst, const struct nk_convert_config *config,
|
||||
struct nk_vec2 pos, struct nk_vec2 uv, struct nk_colorf color)
|
||||
{
|
||||
void *result = (void*)((char*)dst + config->vertex_size);
|
||||
const struct nk_draw_vertex_layout_element *elem_iter = config->vertex_layout;
|
||||
while (!nk_draw_vertex_layout_element_is_end_of_layout(elem_iter)) {
|
||||
void *address = (void*)((char*)dst + elem_iter->offset);
|
||||
switch (elem_iter->attribute) {
|
||||
case NK_VERTEX_POSITION: nk_draw_vertex_element(address, &pos.x, 2, elem_iter->format); break;
|
||||
case NK_VERTEX_TEXCOORD: nk_draw_vertex_element(address, &uv.x, 2, elem_iter->format); break;
|
||||
case NK_VERTEX_COLOR: nk_draw_vertex_color(address, &color.r, elem_iter->format); break;
|
||||
default: break;
|
||||
}
|
||||
elem_iter++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NK_API void
|
||||
@ -6021,12 +6198,12 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
|
||||
{
|
||||
nk_size count;
|
||||
int thick_line;
|
||||
nk_draw_vertex_color col;
|
||||
struct nk_colorf col;
|
||||
struct nk_colorf col_trans;
|
||||
NK_ASSERT(list);
|
||||
if (!list || points_count < 2) return;
|
||||
|
||||
color.a = (nk_byte)((float)color.a * list->global_alpha);
|
||||
col = nk_color_u32(color);
|
||||
color.a = (nk_byte)((float)color.a * list->config.global_alpha);
|
||||
count = points_count;
|
||||
if (!closed) count = points_count-1;
|
||||
thick_line = thickness > 1.0f;
|
||||
@ -6035,12 +6212,16 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
|
||||
nk_draw_list_push_userdata(list, list->userdata);
|
||||
#endif
|
||||
|
||||
color.a = (nk_byte)((float)color.a * list->config.global_alpha);
|
||||
nk_color_fv(&col.r, color);
|
||||
col_trans = col;
|
||||
col_trans.a = 0;
|
||||
|
||||
if (aliasing == NK_ANTI_ALIASING_ON) {
|
||||
/* ANTI-ALIASED STROKE */
|
||||
const float AA_SIZE = 1.0f;
|
||||
NK_STORAGE const nk_size pnt_align = NK_ALIGNOF(struct nk_vec2);
|
||||
NK_STORAGE const nk_size pnt_size = sizeof(struct nk_vec2);
|
||||
const nk_draw_vertex_color col_trans = col & 0x00ffffff;
|
||||
|
||||
/* allocate vertices and elements */
|
||||
nk_size i1 = 0;
|
||||
@ -6048,7 +6229,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
|
||||
nk_size index = list->vertex_count;
|
||||
const nk_size idx_count = (thick_line) ? (count * 18) : (count * 12);
|
||||
const nk_size vtx_count = (thick_line) ? (points_count * 4): (points_count *3);
|
||||
struct nk_draw_vertex *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
|
||||
void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
|
||||
nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
|
||||
|
||||
nk_size size;
|
||||
@ -6064,7 +6245,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
|
||||
nk_buffer_alloc(list->vertices, NK_BUFFER_FRONT, size, pnt_align);
|
||||
NK_ASSERT(normals);
|
||||
if (!normals) return;
|
||||
vtx = (struct nk_draw_vertex*)(void*)((nk_byte*)list->vertices->memory.ptr + vertex_offset);
|
||||
vtx = (void*)((nk_byte*)list->vertices->memory.ptr + vertex_offset);
|
||||
temp = normals + points_count;
|
||||
|
||||
/* calculate normals */
|
||||
@ -6131,11 +6312,10 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
|
||||
|
||||
/* fill vertices */
|
||||
for (i = 0; i < points_count; ++i) {
|
||||
const struct nk_vec2 uv = list->null.uv;
|
||||
vtx[0] = nk_draw_vertex(points[i], uv, col);
|
||||
vtx[1] = nk_draw_vertex(temp[i*2+0], uv, col_trans);
|
||||
vtx[2] = nk_draw_vertex(temp[i*2+1], uv, col_trans);
|
||||
vtx += 3;
|
||||
const struct nk_vec2 uv = list->config.null.uv;
|
||||
vtx = nk_draw_vertex(vtx, &list->config, points[i], uv, col);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+0], uv, col_trans);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+1], uv, col_trans);
|
||||
}
|
||||
} else {
|
||||
nk_size idx1, i;
|
||||
@ -6197,15 +6377,13 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
|
||||
|
||||
/* add vertices */
|
||||
for (i = 0; i < points_count; ++i) {
|
||||
const struct nk_vec2 uv = list->null.uv;
|
||||
vtx[0] = nk_draw_vertex(temp[i*4+0], uv, col_trans);
|
||||
vtx[1] = nk_draw_vertex(temp[i*4+1], uv, col);
|
||||
vtx[2] = nk_draw_vertex(temp[i*4+2], uv, col);
|
||||
vtx[3] = nk_draw_vertex(temp[i*4+3], uv, col_trans);
|
||||
vtx += 4;
|
||||
const struct nk_vec2 uv = list->config.null.uv;
|
||||
vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+0], uv, col_trans);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+1], uv, col);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+2], uv, col);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+3], uv, col_trans);
|
||||
}
|
||||
}
|
||||
|
||||
/* free temporary normals + points */
|
||||
nk_buffer_reset(list->vertices, NK_BUFFER_FRONT);
|
||||
} else {
|
||||
@ -6214,13 +6392,13 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
|
||||
nk_size idx = list->vertex_count;
|
||||
const nk_size idx_count = count * 6;
|
||||
const nk_size vtx_count = count * 4;
|
||||
struct nk_draw_vertex *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
|
||||
void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
|
||||
nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
|
||||
if (!vtx || !ids) return;
|
||||
|
||||
for (i1 = 0; i1 < count; ++i1) {
|
||||
float dx, dy;
|
||||
const struct nk_vec2 uv = list->null.uv;
|
||||
const struct nk_vec2 uv = list->config.null.uv;
|
||||
const nk_size i2 = ((i1+1) == points_count) ? 0 : i1 + 1;
|
||||
const struct nk_vec2 p1 = points[i1];
|
||||
const struct nk_vec2 p2 = points[i2];
|
||||
@ -6238,11 +6416,10 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
|
||||
dx = diff.x * (thickness * 0.5f);
|
||||
dy = diff.y * (thickness * 0.5f);
|
||||
|
||||
vtx[0] = nk_draw_vertex(nk_vec2(p1.x + dy, p1.y - dx), uv, col);
|
||||
vtx[1] = nk_draw_vertex(nk_vec2(p2.x + dy, p2.y - dx), uv, col);
|
||||
vtx[2] = nk_draw_vertex(nk_vec2(p2.x - dy, p2.y + dx), uv, col);
|
||||
vtx[3] = nk_draw_vertex(nk_vec2(p1.x - dy, p1.y + dx), uv, col);
|
||||
vtx += 4;
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(p1.x + dy, p1.y - dx), uv, col);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(p2.x + dy, p2.y - dx), uv, col);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(p2.x - dy, p2.y + dx), uv, col);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(p1.x - dy, p1.y + dx), uv, col);
|
||||
|
||||
ids[0] = (nk_draw_index)(idx+0); ids[1] = (nk_draw_index)(idx+1);
|
||||
ids[2] = (nk_draw_index)(idx+2); ids[3] = (nk_draw_index)(idx+0);
|
||||
@ -6258,9 +6435,11 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list,
|
||||
const struct nk_vec2 *points, const unsigned int points_count,
|
||||
struct nk_color color, enum nk_anti_aliasing aliasing)
|
||||
{
|
||||
struct nk_colorf col;
|
||||
struct nk_colorf col_trans;
|
||||
|
||||
NK_STORAGE const nk_size pnt_align = NK_ALIGNOF(struct nk_vec2);
|
||||
NK_STORAGE const nk_size pnt_size = sizeof(struct nk_vec2);
|
||||
nk_draw_vertex_color col;
|
||||
NK_ASSERT(list);
|
||||
if (!list || points_count < 3) return;
|
||||
|
||||
@ -6268,8 +6447,11 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list,
|
||||
nk_draw_list_push_userdata(list, list->userdata);
|
||||
#endif
|
||||
|
||||
color.a = (nk_byte)((float)color.a * list->global_alpha);
|
||||
col = nk_color_u32(color);
|
||||
color.a = (nk_byte)((float)color.a * list->config.global_alpha);
|
||||
nk_color_fv(&col.r, color);
|
||||
col_trans = col;
|
||||
col_trans.a = 0;
|
||||
|
||||
if (aliasing == NK_ANTI_ALIASING_ON) {
|
||||
nk_size i = 0;
|
||||
nk_size i0 = 0;
|
||||
@ -6277,11 +6459,10 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list,
|
||||
|
||||
const float AA_SIZE = 1.0f;
|
||||
nk_size vertex_offset = 0;
|
||||
const nk_draw_vertex_color col_trans = col & 0x00ffffff;
|
||||
nk_size index = list->vertex_count;
|
||||
const nk_size idx_count = (points_count-2)*3 + points_count*6;
|
||||
const nk_size vtx_count = (points_count*2);
|
||||
struct nk_draw_vertex *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
|
||||
void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
|
||||
nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
|
||||
|
||||
unsigned int vtx_inner_idx = (unsigned int)(index + 0);
|
||||
@ -6290,6 +6471,7 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list,
|
||||
nk_size size = 0;
|
||||
if (!vtx || !ids) return;
|
||||
|
||||
|
||||
/* temporary allocate normals */
|
||||
vertex_offset = (nk_size)((nk_byte*)vtx - (nk_byte*)list->vertices->memory.ptr);
|
||||
nk_buffer_mark(list->vertices, NK_BUFFER_FRONT);
|
||||
@ -6298,7 +6480,7 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list,
|
||||
nk_buffer_alloc(list->vertices, NK_BUFFER_FRONT, size, pnt_align);
|
||||
NK_ASSERT(normals);
|
||||
if (!normals) return;
|
||||
vtx = (struct nk_draw_vertex*)(void*)((nk_byte*)list->vertices->memory.ptr + vertex_offset);
|
||||
vtx = (void*)((nk_byte*)list->vertices->memory.ptr + vertex_offset);
|
||||
|
||||
/* add elements */
|
||||
for (i = 2; i < points_count; i++) {
|
||||
@ -6327,11 +6509,10 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list,
|
||||
|
||||
/* add vertices + indexes */
|
||||
for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) {
|
||||
const struct nk_vec2 uv = list->null.uv;
|
||||
const struct nk_vec2 uv = list->config.null.uv;
|
||||
struct nk_vec2 n0 = normals[i0];
|
||||
struct nk_vec2 n1 = normals[i1];
|
||||
struct nk_vec2 dm = nk_vec2_muls(nk_vec2_add(n0, n1), 0.5f);
|
||||
|
||||
float dmr2 = dm.x*dm.x + dm.y*dm.y;
|
||||
if (dmr2 > 0.000001f) {
|
||||
float scale = 1.0f / dmr2;
|
||||
@ -6341,9 +6522,8 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list,
|
||||
dm = nk_vec2_muls(dm, AA_SIZE * 0.5f);
|
||||
|
||||
/* add vertices */
|
||||
vtx[0] = nk_draw_vertex(nk_vec2_sub(points[i1], dm), uv, col);
|
||||
vtx[1] = nk_draw_vertex(nk_vec2_add(points[i1], dm), uv, col_trans);
|
||||
vtx += 2;
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2_sub(points[i1], dm), uv, col);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2_add(points[i1], dm), uv, col_trans);
|
||||
|
||||
/* add indexes */
|
||||
ids[0] = (nk_draw_index)(vtx_inner_idx+(i1<<1));
|
||||
@ -6361,13 +6541,12 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list,
|
||||
nk_size index = list->vertex_count;
|
||||
const nk_size idx_count = (points_count-2)*3;
|
||||
const nk_size vtx_count = points_count;
|
||||
struct nk_draw_vertex *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
|
||||
void *vtx = nk_draw_list_alloc_vertices(list, vtx_count);
|
||||
nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count);
|
||||
|
||||
if (!vtx || !ids) return;
|
||||
for (i = 0; i < vtx_count; ++i) {
|
||||
vtx[0] = nk_draw_vertex(points[i], list->null.uv, col);
|
||||
vtx++;
|
||||
}
|
||||
for (i = 0; i < vtx_count; ++i)
|
||||
vtx = nk_draw_vertex(vtx, &list->config, points[i], list->config.null.uv, col);
|
||||
for (i = 2; i < points_count; ++i) {
|
||||
ids[0] = (nk_draw_index)index;
|
||||
ids[1] = (nk_draw_index)(index+ i - 1);
|
||||
@ -6398,8 +6577,8 @@ nk_draw_list_path_line_to(struct nk_draw_list *list, struct nk_vec2 pos)
|
||||
nk_draw_list_add_clip(list, nk_null_rect);
|
||||
|
||||
cmd = nk_draw_list_command_last(list);
|
||||
if (cmd && cmd->texture.ptr != list->null.texture.ptr)
|
||||
nk_draw_list_push_image(list, list->null.texture);
|
||||
if (cmd && cmd->texture.ptr != list->config.null.texture.ptr)
|
||||
nk_draw_list_push_image(list, list->config.null.texture);
|
||||
|
||||
points = nk_draw_list_alloc_path(list, 1);
|
||||
if (!points) return;
|
||||
@ -6467,8 +6646,8 @@ NK_API void
|
||||
nk_draw_list_path_curve_to(struct nk_draw_list *list, struct nk_vec2 p2,
|
||||
struct nk_vec2 p3, struct nk_vec2 p4, unsigned int num_segments)
|
||||
{
|
||||
unsigned int i_step;
|
||||
float t_step;
|
||||
unsigned int i_step;
|
||||
struct nk_vec2 p1;
|
||||
|
||||
NK_ASSERT(list);
|
||||
@ -6498,7 +6677,7 @@ nk_draw_list_path_fill(struct nk_draw_list *list, struct nk_color color)
|
||||
NK_ASSERT(list);
|
||||
if (!list) return;
|
||||
points = (struct nk_vec2*)nk_buffer_memory(list->buffer);
|
||||
nk_draw_list_fill_poly_convex(list, points, list->path_count, color, list->shape_AA);
|
||||
nk_draw_list_fill_poly_convex(list, points, list->path_count, color, list->config.shape_AA);
|
||||
nk_draw_list_path_clear(list);
|
||||
}
|
||||
|
||||
@ -6511,7 +6690,7 @@ nk_draw_list_path_stroke(struct nk_draw_list *list, struct nk_color color,
|
||||
if (!list) return;
|
||||
points = (struct nk_vec2*)nk_buffer_memory(list->buffer);
|
||||
nk_draw_list_stroke_poly_line(list, points, list->path_count, color,
|
||||
closed, thickness, list->line_AA);
|
||||
closed, thickness, list->config.line_AA);
|
||||
nk_draw_list_path_clear(list);
|
||||
}
|
||||
|
||||
@ -6553,18 +6732,21 @@ nk_draw_list_fill_rect_multi_color(struct nk_draw_list *list, struct nk_rect rec
|
||||
struct nk_color left, struct nk_color top, struct nk_color right,
|
||||
struct nk_color bottom)
|
||||
{
|
||||
nk_draw_vertex_color col_left = nk_color_u32(left);
|
||||
nk_draw_vertex_color col_top = nk_color_u32(top);
|
||||
nk_draw_vertex_color col_right = nk_color_u32(right);
|
||||
nk_draw_vertex_color col_bottom = nk_color_u32(bottom);
|
||||
void *vtx;
|
||||
struct nk_colorf col_left, col_top;
|
||||
struct nk_colorf col_right, col_bottom;
|
||||
|
||||
nk_color_fv(&col_left.r, left);
|
||||
nk_color_fv(&col_right.r, right);
|
||||
nk_color_fv(&col_top.r, top);
|
||||
nk_color_fv(&col_bottom.r, bottom);
|
||||
|
||||
struct nk_draw_vertex *vtx;
|
||||
nk_draw_index *idx;
|
||||
nk_draw_index index;
|
||||
NK_ASSERT(list);
|
||||
if (!list) return;
|
||||
|
||||
nk_draw_list_push_image(list, list->null.texture);
|
||||
nk_draw_list_push_image(list, list->config.null.texture);
|
||||
index = (nk_draw_index)list->vertex_count;
|
||||
vtx = nk_draw_list_alloc_vertices(list, 4);
|
||||
idx = nk_draw_list_alloc_elements(list, 6);
|
||||
@ -6574,10 +6756,10 @@ nk_draw_list_fill_rect_multi_color(struct nk_draw_list *list, struct nk_rect rec
|
||||
idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0);
|
||||
idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3);
|
||||
|
||||
vtx[0] = nk_draw_vertex(nk_vec2(rect.x, rect.y), list->null.uv, col_left);
|
||||
vtx[1] = nk_draw_vertex(nk_vec2(rect.x + rect.w, rect.y), list->null.uv, col_top);
|
||||
vtx[2] = nk_draw_vertex(nk_vec2(rect.x + rect.w, rect.y + rect.h), list->null.uv, col_right);
|
||||
vtx[3] = nk_draw_vertex(nk_vec2(rect.x, rect.y + rect.h), list->null.uv, col_bottom);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y), list->config.null.uv, col_left);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y), list->config.null.uv, col_top);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y + rect.h), list->config.null.uv, col_right);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y + rect.h), list->config.null.uv, col_bottom);
|
||||
}
|
||||
|
||||
NK_API void
|
||||
@ -6645,17 +6827,19 @@ nk_draw_list_push_rect_uv(struct nk_draw_list *list, struct nk_vec2 a,
|
||||
struct nk_vec2 c, struct nk_vec2 uva, struct nk_vec2 uvc,
|
||||
struct nk_color color)
|
||||
{
|
||||
nk_draw_vertex_color col = nk_color_u32(color);
|
||||
struct nk_draw_vertex *vtx;
|
||||
void *vtx;
|
||||
struct nk_vec2 uvb;
|
||||
struct nk_vec2 uvd;
|
||||
struct nk_vec2 b;
|
||||
struct nk_vec2 d;
|
||||
|
||||
struct nk_colorf col;
|
||||
nk_draw_index *idx;
|
||||
nk_draw_index index;
|
||||
NK_ASSERT(list);
|
||||
if (!list) return;
|
||||
|
||||
nk_color_fv(&col.r, color);
|
||||
uvb = nk_vec2(uvc.x, uva.y);
|
||||
uvd = nk_vec2(uva.x, uvc.y);
|
||||
b = nk_vec2(c.x, a.y);
|
||||
@ -6670,10 +6854,10 @@ nk_draw_list_push_rect_uv(struct nk_draw_list *list, struct nk_vec2 a,
|
||||
idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0);
|
||||
idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3);
|
||||
|
||||
vtx[0] = nk_draw_vertex(a, uva, col);
|
||||
vtx[1] = nk_draw_vertex(b, uvb, col);
|
||||
vtx[2] = nk_draw_vertex(c, uvc, col);
|
||||
vtx[3] = nk_draw_vertex(d, uvd, col);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, a, uva, col);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, b, uvb, col);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, c, uvc, col);
|
||||
vtx = nk_draw_vertex(vtx, &list->config, d, uvd, col);
|
||||
}
|
||||
|
||||
NK_API void
|
||||
@ -6722,7 +6906,7 @@ nk_draw_list_add_text(struct nk_draw_list *list, const struct nk_user_font *font
|
||||
if (!glyph_len) return;
|
||||
|
||||
/* draw every glyph image */
|
||||
fg.a = (nk_byte)((float)fg.a * list->global_alpha);
|
||||
fg.a = (nk_byte)((float)fg.a * list->config.global_alpha);
|
||||
while (text_len <= len && glyph_len) {
|
||||
float gx, gy, gh, gw;
|
||||
float char_width = 0;
|
||||
@ -6760,11 +6944,12 @@ nk_convert(struct nk_context *ctx, struct nk_buffer *cmds,
|
||||
NK_ASSERT(vertices);
|
||||
NK_ASSERT(elements);
|
||||
NK_ASSERT(config);
|
||||
if (!ctx || !cmds || !vertices || !elements || !config)
|
||||
NK_ASSERT(config->vertex_layout);
|
||||
NK_ASSERT(config->vertex_size);
|
||||
if (!ctx || !cmds || !vertices || !elements || !config || !config->vertex_layout)
|
||||
return;
|
||||
|
||||
nk_draw_list_setup(&ctx->draw_list, config->global_alpha, config->line_AA,
|
||||
config->shape_AA, config->null, cmds, vertices, elements);
|
||||
nk_draw_list_setup(&ctx->draw_list, config, cmds, vertices, elements);
|
||||
nk_foreach(cmd, ctx)
|
||||
{
|
||||
#ifdef NK_INCLUDE_COMMAND_USERDATA
|
||||
|
Loading…
Reference in New Issue
Block a user