removed sin & cos dependency
This commit is contained in:
parent
7c37c06e4c
commit
080b59dcc2
|
@ -354,7 +354,7 @@ main(int argc, char *argv[])
|
|||
|
||||
usrfnt = device_init(&dev, font_path, 14,
|
||||
zr_font_default_glyph_ranges());
|
||||
zr_init(&gui.ctx, &alloc, &usrfnt, sin, cos);
|
||||
zr_init(&gui.ctx, &alloc, &usrfnt);
|
||||
}
|
||||
|
||||
while (running) {
|
||||
|
|
|
@ -205,7 +205,7 @@ main(int argc, char *argv[])
|
|||
usrfnt.userdata = zr_handle_ptr(font);
|
||||
usrfnt.width = font_get_width;
|
||||
usrfnt.height = al_get_font_line_height(font);
|
||||
zr_init(&gui.ctx, &alloc, &usrfnt, sin, cos);
|
||||
zr_init(&gui.ctx, &alloc, &usrfnt);
|
||||
}
|
||||
|
||||
while (running) {
|
||||
|
|
|
@ -499,7 +499,7 @@ main(int argc, char *argv[])
|
|||
zr_buffer_init(&device.cmds, &alloc, 1024);
|
||||
usrfnt = font_bake_and_upload(&device, &font, font_path, 14,
|
||||
zr_font_default_glyph_ranges());
|
||||
zr_init(&gui.ctx, &alloc, &usrfnt, sin, cos);
|
||||
zr_init(&gui.ctx, &alloc, &usrfnt);
|
||||
}
|
||||
|
||||
device_init(&device);
|
||||
|
|
|
@ -855,7 +855,7 @@ int main(int argc, char **argv)
|
|||
zr_buffer_init(&device.cmds, &alloc, 4024);
|
||||
usrfnt = font_bake_and_upload(&device, &font, font_path, 14,
|
||||
zr_font_default_glyph_ranges());
|
||||
zr_init(&gui.ctx, &alloc, &usrfnt, sin, cos);
|
||||
zr_init(&gui.ctx, &alloc, &usrfnt);
|
||||
}
|
||||
|
||||
device_init(&device);
|
||||
|
|
|
@ -289,7 +289,7 @@ main(int argc, char *argv[])
|
|||
|
||||
memset(&gui, 0, sizeof gui);
|
||||
gui.memory = calloc(MAX_MEMORY, 1);
|
||||
zr_init_fixed(&gui.ctx, gui.memory, MAX_MEMORY, &usrfnt, sin, cos);
|
||||
zr_init_fixed(&gui.ctx, gui.memory, MAX_MEMORY, &usrfnt);
|
||||
}
|
||||
|
||||
while (running) {
|
||||
|
|
|
@ -469,7 +469,7 @@ main(int argc, char *argv[])
|
|||
zr_buffer_init(&device.cmds, &alloc, 1024);
|
||||
usrfnt = font_bake_and_upload(&device, &font, font_path, 14,
|
||||
zr_font_default_glyph_ranges());
|
||||
zr_init(&gui.ctx, &alloc, &usrfnt, sin, cos);
|
||||
zr_init(&gui.ctx, &alloc, &usrfnt);
|
||||
}
|
||||
|
||||
device_init(&device);
|
||||
|
|
|
@ -420,7 +420,7 @@ main(int argc, char *argv[])
|
|||
font.width = font_get_text_width;
|
||||
memset(&gui, 0, sizeof gui);
|
||||
gui.memory = calloc(MAX_MEMORY, 1);
|
||||
zr_init_fixed(&gui.ctx, gui.memory, MAX_MEMORY, &font, sin, cos);
|
||||
zr_init_fixed(&gui.ctx, gui.memory, MAX_MEMORY, &font);
|
||||
|
||||
while (running) {
|
||||
/* Input */
|
||||
|
|
|
@ -755,7 +755,7 @@ main(int argc, char *argv[])
|
|||
font.userdata.ptr = vg;
|
||||
font.width = font_get_width;
|
||||
font.height = 20;
|
||||
zr_init_fixed(&ctx, memory, MAX_MEMORY, &font, sin, cos);
|
||||
zr_init_fixed(&ctx, memory, MAX_MEMORY, &font);
|
||||
ctx.style.rounding[ZR_ROUNDING_BUTTON] = 3;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -824,7 +823,7 @@ main(int argc, char *argv[])
|
|||
font.userdata.ptr = vg;
|
||||
font.width = font_get_width;
|
||||
nvgTextMetrics(vg, NULL, NULL, &font.height);
|
||||
zr_init_fixed(&ctx, memory, MAX_MEMORY, &font, sin, cos);
|
||||
zr_init_fixed(&ctx, memory, MAX_MEMORY, &font);
|
||||
file_browser_init(&browser, vg);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
|
@ -636,7 +635,7 @@ main(int argc, char *argv[])
|
|||
font.userdata.ptr = vg;
|
||||
nvgTextMetrics(vg, NULL, NULL, &font.height);
|
||||
font.width = font_get_width;
|
||||
zr_init_fixed(&ctx, memory, MAX_MEMORY, &font, sin, cos);
|
||||
zr_init_fixed(&ctx, memory, MAX_MEMORY, &font);
|
||||
ctx.style.header.align = ZR_HEADER_RIGHT;
|
||||
}
|
||||
node_editor_init(&nodedit);
|
||||
|
|
65
zahnrad.c
65
zahnrad.c
|
@ -40,6 +40,13 @@ enum zr_orientation {
|
|||
ZR_HORIZONTAL
|
||||
};
|
||||
|
||||
enum zr_draw_list_stroke {
|
||||
ZR_STROKE_OPEN = zr_false,
|
||||
/* build up path has no connection back to the beginning */
|
||||
ZR_STROKE_CLOSED = zr_true
|
||||
/* build up path has a connection back to the beginning */
|
||||
};
|
||||
|
||||
struct zr_text_selection {
|
||||
int active;
|
||||
/* current selection state */
|
||||
|
@ -305,6 +312,34 @@ zr_inv_sqrt(float number)
|
|||
return conv.f;
|
||||
}
|
||||
|
||||
static double
|
||||
zr_sin(double x)
|
||||
{
|
||||
static const double a0 = +1.91059300966915117e-31;
|
||||
static const double a1 = +1.00086760103908896;
|
||||
static const double a2 = -1.21276126894734565e-2;
|
||||
static const double a3 = -1.38078780785773762e-1;
|
||||
static const double a4 = -2.67353392911981221e-2;
|
||||
static const double a5 = +2.08026600266304389e-2;
|
||||
static const double a6 = -3.03996055049204407e-3;
|
||||
static const double a7 = +1.38235642404333740e-4;
|
||||
return a0 + x * (a1 + x * (a2 + x * (a3 + x * (a4 + x * (a5 + x *(a6 + x * a7))))));
|
||||
}
|
||||
|
||||
static double
|
||||
zr_cos(double x)
|
||||
{
|
||||
static const double a0 = +1.00238601909309722;
|
||||
static const double a1 = -3.81919947353040024e-2;
|
||||
static const double a2 = -3.94382342128062756e-1;
|
||||
static const double a3 = -1.18134036025221444e-1;
|
||||
static const double a4 = +1.07123798512170878e-1;
|
||||
static const double a5 = -1.86637164165180873e-2;
|
||||
static const double a6 = +9.90140908664079833e-4;
|
||||
static const double a7 = -5.23022132118824778e-14;
|
||||
return a0 + x * (a1 + x * (a2 + x * (a3 + x * (a4 + x * (a5 + x *(a6 + x * a7))))));
|
||||
}
|
||||
|
||||
struct zr_rect
|
||||
zr_get_null_rect(void)
|
||||
{
|
||||
|
@ -2024,16 +2059,14 @@ zr_draw_text(struct zr_command_buffer *b, struct zr_rect r,
|
|||
* ===============================================================*/
|
||||
#if ZR_COMPILE_WITH_VERTEX_BUFFER
|
||||
static void
|
||||
zr_canvas_init(struct zr_canvas *list, zr_sin_f sine, zr_cos_f cosine)
|
||||
zr_canvas_init(struct zr_canvas *list)
|
||||
{
|
||||
zr_size i = 0;
|
||||
zr_zero(list, sizeof(*list));
|
||||
list->sin = sine;
|
||||
list->cos = cosine;
|
||||
for (i = 0; i < ZR_LEN(list->circle_vtx); ++i) {
|
||||
const float a = ((float)i / (float)ZR_LEN(list->circle_vtx)) * 2 * ZR_PI;
|
||||
list->circle_vtx[i].x = (float)cosine(a);
|
||||
list->circle_vtx[i].y = (float)sine(a);
|
||||
list->circle_vtx[i].x = (float)zr_cos(a);
|
||||
list->circle_vtx[i].y = (float)zr_sin(a);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2616,8 +2649,12 @@ zr_canvas_path_arc_to(struct zr_canvas *list, struct zr_vec2 center,
|
|||
if (radius == 0.0f) return;
|
||||
for (i = 0; i <= segments; ++i) {
|
||||
const float a = a_min + ((float)i / (float)segments) * (a_max - a_min);
|
||||
const float x = center.x + (float)zr_cos(a) * radius;
|
||||
const float y = center.y + (float)zr_sin(a) * radius;
|
||||
#if 0
|
||||
const float x = center.x + (float)list->cos(a) * radius;
|
||||
const float y = center.y + (float)list->sin(a) * radius;
|
||||
#endif
|
||||
zr_canvas_path_line_to(list, zr_vec2(x, y));
|
||||
}
|
||||
}
|
||||
|
@ -6492,23 +6529,22 @@ zr_clear(struct zr_context *ctx)
|
|||
}
|
||||
|
||||
static void
|
||||
zr_setup(struct zr_context *ctx, const struct zr_user_font *font,
|
||||
zr_sin_f sine, zr_cos_f cosine)
|
||||
zr_setup(struct zr_context *ctx, const struct zr_user_font *font)
|
||||
{
|
||||
zr_zero(ctx, sizeof(*ctx));
|
||||
zr_style_default(&ctx->style, ZR_DEFAULT_ALL, font);
|
||||
#if ZR_COMPILE_WITH_VERTEX_BUFFER
|
||||
if (sine && cosine) zr_canvas_init(&ctx->canvas, sine, cosine);
|
||||
zr_canvas_init(&ctx->canvas);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
zr_init_fixed(struct zr_context *ctx, void *memory, zr_size size,
|
||||
const struct zr_user_font *font, zr_sin_f sine, zr_cos_f cosine)
|
||||
const struct zr_user_font *font)
|
||||
{
|
||||
ZR_ASSERT(memory);
|
||||
if (!memory) return 0;
|
||||
zr_setup(ctx, font, sine, cosine);
|
||||
zr_setup(ctx, font);
|
||||
zr_buffer_init_fixed(&ctx->memory, memory, size);
|
||||
ctx->pool = 0;
|
||||
return 1;
|
||||
|
@ -6516,13 +6552,12 @@ zr_init_fixed(struct zr_context *ctx, void *memory, zr_size size,
|
|||
|
||||
int
|
||||
zr_init_custom(struct zr_context *ctx, struct zr_buffer *cmds,
|
||||
struct zr_buffer *pool, const struct zr_user_font *font,
|
||||
zr_sin_f sine, zr_cos_f cosine)
|
||||
struct zr_buffer *pool, const struct zr_user_font *font)
|
||||
{
|
||||
ZR_ASSERT(cmds);
|
||||
ZR_ASSERT(pool);
|
||||
if (!cmds || !pool) return 0;
|
||||
zr_setup(ctx, font, sine, cosine);
|
||||
zr_setup(ctx, font);
|
||||
ctx->memory = *cmds;
|
||||
if (pool->type == ZR_BUFFER_FIXED) {
|
||||
/* take memory from buffer and alloc fixed pool */
|
||||
|
@ -6543,11 +6578,11 @@ zr_init_custom(struct zr_context *ctx, struct zr_buffer *cmds,
|
|||
|
||||
int
|
||||
zr_init(struct zr_context *ctx, struct zr_allocator *alloc,
|
||||
const struct zr_user_font *font, zr_sin_f sine, zr_cos_f cosine)
|
||||
const struct zr_user_font *font)
|
||||
{
|
||||
ZR_ASSERT(alloc);
|
||||
if (!alloc) return 0;
|
||||
zr_setup(ctx, font, sine, cosine);
|
||||
zr_setup(ctx, font);
|
||||
zr_buffer_init(&ctx->memory, alloc, ZR_DEFAULT_COMMAND_BUFFER_SIZE);
|
||||
ctx->pool = alloc->alloc(alloc->userdata, sizeof(struct zr_pool));
|
||||
zr_pool_init(ctx->pool, alloc, ZR_POOL_DEFAULT_CAPACTIY);
|
||||
|
|
22
zahnrad.h
22
zahnrad.h
|
@ -123,8 +123,6 @@ typedef char zr_glyph[ZR_UTF_SIZE];
|
|||
typedef union {void *ptr; int id;} zr_handle;
|
||||
struct zr_image {zr_handle handle; unsigned short w, h; unsigned short region[4];};
|
||||
struct zr_scroll {unsigned short x, y;};
|
||||
typedef double(*zr_sin_f)(double);
|
||||
typedef double(*zr_cos_f)(double);
|
||||
|
||||
/* pointer */
|
||||
#define zr_ptr_add(t, p, i) ((t*)((void*)((zr_byte*)(p) + (i))))
|
||||
|
@ -361,7 +359,7 @@ struct zr_buffer {
|
|||
struct zr_allocator pool;
|
||||
/* allocator callback for dynamic buffers */
|
||||
enum zr_allocation_type type;
|
||||
/* memory type management type */
|
||||
/* memory management type */
|
||||
struct zr_memory memory;
|
||||
/* memory and size of the current memory block */
|
||||
float grow_factor;
|
||||
|
@ -731,13 +729,6 @@ struct zr_draw_vertex {
|
|||
zr_draw_vertex_color col;
|
||||
};
|
||||
|
||||
enum zr_draw_list_stroke {
|
||||
ZR_STROKE_OPEN = zr_false,
|
||||
/* build up path has no connection back to the beginning */
|
||||
ZR_STROKE_CLOSED = zr_true
|
||||
/* build up path has a connection back to the beginning */
|
||||
};
|
||||
|
||||
struct zr_draw_command {
|
||||
unsigned int elem_count;
|
||||
/* number of elements in the current draw batch */
|
||||
|
@ -761,7 +752,6 @@ struct zr_canvas {
|
|||
/* texture with white pixel for easy primitive drawing */
|
||||
struct zr_rect clip_rect;
|
||||
/* current clipping rectangle */
|
||||
zr_cos_f cos; zr_sin_f sin;
|
||||
/* cosine/sine calculation callback since this library does not use libc */
|
||||
struct zr_buffer *buffer;
|
||||
/* buffer to store draw commands and temporarily store path */
|
||||
|
@ -784,7 +774,6 @@ struct zr_canvas {
|
|||
struct zr_vec2 circle_vtx[12];
|
||||
/* small lookup table for fast circle drawing */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* drawing routines */
|
||||
|
@ -1300,13 +1289,10 @@ struct zr_context {
|
|||
/*--------------------------------------------------------------
|
||||
* CONTEXT
|
||||
* -------------------------------------------------------------*/
|
||||
int zr_init_fixed(struct zr_context*, void *memory, zr_size size,
|
||||
const struct zr_user_font*, zr_sin_f, zr_cos_f);
|
||||
int zr_init_fixed(struct zr_context*, void *memory, zr_size size, const struct zr_user_font*);
|
||||
int zr_init_custom(struct zr_context*, struct zr_buffer *cmds,
|
||||
struct zr_buffer *pool, const struct zr_user_font*,
|
||||
zr_sin_f, zr_cos_f);
|
||||
int zr_init(struct zr_context*, struct zr_allocator*,
|
||||
const struct zr_user_font*, zr_sin_f, zr_cos_f);
|
||||
struct zr_buffer *pool, const struct zr_user_font*);
|
||||
int zr_init(struct zr_context*, struct zr_allocator*, const struct zr_user_font*);
|
||||
void zr_convert(struct zr_context*, struct zr_buffer *cmds,
|
||||
struct zr_buffer *vertexes, struct zr_buffer *elements,
|
||||
struct zr_draw_null_texture , enum zr_anti_aliasing,
|
||||
|
|
Loading…
Reference in New Issue