renamed 'graph' to 'chart' #33
This commit is contained in:
parent
138f6b3af5
commit
d943a32e18
44
demo/demo.c
44
demo/demo.c
|
@ -447,7 +447,7 @@ demo_window(struct zr_layout *layout, struct zr_context *ctx, enum theme *theme)
|
|||
if (zr_layout_push(ctx, ZR_LAYOUT_NODE, "Combo"))
|
||||
{
|
||||
/* Combobox Widgets */
|
||||
static float graph_selection = 8.0f;
|
||||
static float chart_selection = 8.0f;
|
||||
static const char *weapons[] = {"Fist","Pistol","Shotgun","Plasma","BFG"};
|
||||
static size_t current_weapon = 0;
|
||||
static int check_values[5];
|
||||
|
@ -509,21 +509,21 @@ demo_window(struct zr_layout *layout, struct zr_context *ctx, enum theme *theme)
|
|||
zr_combo_end(ctx);
|
||||
}
|
||||
|
||||
/* graph combobox */
|
||||
sprintf(buffer, "%.1f", graph_selection);
|
||||
if (zr_combo_begin_text(ctx, &combo, "Graph", buffer, 250)) {
|
||||
/* chart combobox */
|
||||
sprintf(buffer, "%.1f", chart_selection);
|
||||
if (zr_combo_begin_text(ctx, &combo, "Charts", buffer, 250)) {
|
||||
size_t i = 0;
|
||||
static const float values[]={30.0f,15.0f,25.0f,10.0f,20.0f,40.0f};
|
||||
zr_layout_row_dynamic(ctx, 150, 1);
|
||||
zr_graph_begin(ctx, ZR_GRAPH_COLUMN, LEN(values), 0, 50);
|
||||
zr_chart_begin(ctx, ZR_CHART_COLUMN, LEN(values), 0, 50);
|
||||
for (i = 0; i < LEN(values); ++i) {
|
||||
zr_flags res = zr_graph_push(ctx, values[i]);
|
||||
if (res & ZR_GRAPH_CLICKED) {
|
||||
graph_selection = values[i];
|
||||
zr_flags res = zr_chart_push(ctx, values[i]);
|
||||
if (res & ZR_CHART_CLICKED) {
|
||||
chart_selection = values[i];
|
||||
zr_combo_close(ctx);
|
||||
}
|
||||
}
|
||||
zr_graph_end(ctx);
|
||||
zr_chart_end(ctx);
|
||||
zr_combo_end(ctx);
|
||||
}
|
||||
zr_layout_pop(ctx);
|
||||
|
@ -590,7 +590,7 @@ demo_window(struct zr_layout *layout, struct zr_context *ctx, enum theme *theme)
|
|||
zr_layout_pop(ctx);
|
||||
}
|
||||
|
||||
if (zr_layout_push(ctx, ZR_LAYOUT_TAB, "Graph"))
|
||||
if (zr_layout_push(ctx, ZR_LAYOUT_TAB, "chart"))
|
||||
{
|
||||
float id = 0;
|
||||
static int col_index = -1;
|
||||
|
@ -601,19 +601,19 @@ demo_window(struct zr_layout *layout, struct zr_context *ctx, enum theme *theme)
|
|||
int index = -1;
|
||||
struct zr_rect bounds;
|
||||
|
||||
/* column graph */
|
||||
/* column chart */
|
||||
zr_layout_row_dynamic(ctx, 100, 1);
|
||||
zr_layout_peek(&bounds, ctx);
|
||||
zr_graph_begin(ctx, ZR_GRAPH_COLUMN, 32, 0.0f, 1.0f);
|
||||
zr_chart_begin(ctx, ZR_CHART_COLUMN, 32, 0.0f, 1.0f);
|
||||
for (i = 0; i < 32; ++i) {
|
||||
zr_flags res = zr_graph_push(ctx, (float)fabs(sin(id)));
|
||||
if (res & ZR_GRAPH_HOVERING)
|
||||
zr_flags res = zr_chart_push(ctx, (float)fabs(sin(id)));
|
||||
if (res & ZR_CHART_HOVERING)
|
||||
index = (int)i;
|
||||
if (res & ZR_GRAPH_CLICKED)
|
||||
if (res & ZR_CHART_CLICKED)
|
||||
col_index = (int)i;
|
||||
id += step;
|
||||
}
|
||||
zr_graph_end(ctx);
|
||||
zr_chart_end(ctx);
|
||||
|
||||
if (index != -1) {
|
||||
char buffer[ZR_MAX_NUMBER_BUFFER];
|
||||
|
@ -625,21 +625,21 @@ demo_window(struct zr_layout *layout, struct zr_context *ctx, enum theme *theme)
|
|||
zr_labelf(ctx, ZR_TEXT_LEFT, "Selected value: %.2f", (float)fabs(sin(step * (float)col_index)));
|
||||
}
|
||||
|
||||
/* line graph */
|
||||
/* line chart */
|
||||
id = 0;
|
||||
index = -1;
|
||||
zr_layout_row_dynamic(ctx, 100, 1);
|
||||
zr_layout_peek(&bounds, ctx);
|
||||
zr_graph_begin(ctx, ZR_GRAPH_LINES, 32, -1.0f, 1.0f);
|
||||
zr_chart_begin(ctx, ZR_CHART_LINES, 32, -1.0f, 1.0f);
|
||||
for (i = 0; i < 32; ++i) {
|
||||
zr_flags res = zr_graph_push(ctx, (float)cos(id));
|
||||
if (res & ZR_GRAPH_HOVERING)
|
||||
zr_flags res = zr_chart_push(ctx, (float)cos(id));
|
||||
if (res & ZR_CHART_HOVERING)
|
||||
index = (int)i;
|
||||
if (res & ZR_GRAPH_CLICKED)
|
||||
if (res & ZR_CHART_CLICKED)
|
||||
line_index = (int)i;
|
||||
id += step;
|
||||
}
|
||||
zr_graph_end(ctx);
|
||||
zr_chart_end(ctx);
|
||||
|
||||
if (index != -1) {
|
||||
char buffer[ZR_MAX_NUMBER_BUFFER];
|
||||
|
|
132
zahnrad.c
132
zahnrad.c
|
@ -5774,7 +5774,7 @@ zr_input_is_key_down(const struct zr_input *i, enum zr_keys key)
|
|||
ROUNDING(CHECK, 0.0f)\
|
||||
ROUNDING(INPUT, 0.0f)\
|
||||
ROUNDING(PROPERTY, 10.0f)\
|
||||
ROUNDING(GRAPH, 4.0f)\
|
||||
ROUNDING(CHART, 4.0f)\
|
||||
ROUNDING(SCROLLBAR, 5.0f)
|
||||
|
||||
#define ZR_STYLE_COLOR_MAP(COLOR)\
|
||||
|
@ -9240,11 +9240,11 @@ zr_propertyi(struct zr_context *ctx, const char *name, int min, int val, int max
|
|||
|
||||
/* -------------------------------------------------------------
|
||||
*
|
||||
* GRAPH
|
||||
* CHART
|
||||
*
|
||||
* --------------------------------------------------------------*/
|
||||
void
|
||||
zr_graph_begin(struct zr_context *ctx, enum zr_graph_type type,
|
||||
zr_chart_begin(struct zr_context *ctx, enum zr_chart_type type,
|
||||
zr_size count, float min_value, float max_value)
|
||||
{
|
||||
struct zr_rect bounds = {0, 0, 0, 0};
|
||||
|
@ -9253,45 +9253,45 @@ zr_graph_begin(struct zr_context *ctx, enum zr_graph_type type,
|
|||
struct zr_color color;
|
||||
struct zr_vec2 item_padding;
|
||||
struct zr_window *win = ctx->current;
|
||||
struct zr_graph *graph = &win->layout->graph;
|
||||
struct zr_chart *chart = &win->layout->chart;
|
||||
|
||||
ZR_ASSERT(ctx);
|
||||
ZR_ASSERT(ctx->current);
|
||||
ZR_ASSERT(ctx->current->layout);
|
||||
if (!ctx || !ctx->current || !ctx->current->layout) return;
|
||||
if (!zr_widget(&bounds, ctx)) {
|
||||
zr_zero(graph, sizeof(*graph));
|
||||
zr_zero(chart, sizeof(*chart));
|
||||
return;
|
||||
}
|
||||
|
||||
/* draw graph background */
|
||||
/* draw chart background */
|
||||
config = &ctx->style;
|
||||
out = &win->buffer;
|
||||
item_padding = zr_get_property(ctx, ZR_PROPERTY_ITEM_PADDING);
|
||||
color = (type == ZR_GRAPH_LINES) ?
|
||||
color = (type == ZR_CHART_LINES) ?
|
||||
config->colors[ZR_COLOR_PLOT]: config->colors[ZR_COLOR_HISTO];
|
||||
zr_draw_rect(out, bounds, config->rounding[ZR_ROUNDING_GRAPH], color);
|
||||
zr_draw_rect(out, bounds, config->rounding[ZR_ROUNDING_CHART], color);
|
||||
|
||||
/* setup basic generic graph */
|
||||
zr_zero(graph, sizeof(graph));
|
||||
graph->type = type;
|
||||
graph->index = 0;
|
||||
graph->count = count;
|
||||
graph->min = MIN(min_value, max_value);
|
||||
graph->max = MAX(min_value, max_value);
|
||||
graph->range = graph->max - graph->min;
|
||||
graph->x = bounds.x + item_padding.x;
|
||||
graph->y = bounds.y + item_padding.y;
|
||||
graph->w = bounds.w - 2 * item_padding.x;
|
||||
graph->h = bounds.h - 2 * item_padding.y;
|
||||
graph->w = MAX(graph->w, 2 * item_padding.x);
|
||||
graph->h = MAX(graph->h, 2 * item_padding.y);
|
||||
graph->last.x = 0; graph->last.y = 0;
|
||||
/* setup basic generic chart */
|
||||
zr_zero(chart, sizeof(chart));
|
||||
chart->type = type;
|
||||
chart->index = 0;
|
||||
chart->count = count;
|
||||
chart->min = MIN(min_value, max_value);
|
||||
chart->max = MAX(min_value, max_value);
|
||||
chart->range = chart->max - chart->min;
|
||||
chart->x = bounds.x + item_padding.x;
|
||||
chart->y = bounds.y + item_padding.y;
|
||||
chart->w = bounds.w - 2 * item_padding.x;
|
||||
chart->h = bounds.h - 2 * item_padding.y;
|
||||
chart->w = MAX(chart->w, 2 * item_padding.x);
|
||||
chart->h = MAX(chart->h, 2 * item_padding.y);
|
||||
chart->last.x = 0; chart->last.y = 0;
|
||||
}
|
||||
|
||||
static zr_flags
|
||||
zr_graph_push_line(struct zr_context *ctx, struct zr_window *win,
|
||||
struct zr_graph *g, float value)
|
||||
zr_chart_push_line(struct zr_context *ctx, struct zr_window *win,
|
||||
struct zr_chart *g, float value)
|
||||
{
|
||||
struct zr_command_buffer *out = &win->buffer;
|
||||
const struct zr_style *config = &ctx->style;
|
||||
|
@ -9319,9 +9319,9 @@ zr_graph_push_line(struct zr_context *ctx, struct zr_window *win,
|
|||
color = config->colors[ZR_COLOR_PLOT_LINES];
|
||||
if (!(layout->flags & ZR_WINDOW_ROM) &&
|
||||
ZR_INBOX(i->mouse.pos.x,i->mouse.pos.y, g->last.x-3, g->last.y-3, 6, 6)){
|
||||
ret = zr_input_is_mouse_hovering_rect(i, bounds) ? ZR_GRAPH_HOVERING : 0;
|
||||
ret = zr_input_is_mouse_hovering_rect(i, bounds) ? ZR_CHART_HOVERING : 0;
|
||||
ret |= (i->mouse.buttons[ZR_BUTTON_LEFT].down &&
|
||||
i->mouse.buttons[ZR_BUTTON_LEFT].clicked) ? ZR_GRAPH_CLICKED: 0;
|
||||
i->mouse.buttons[ZR_BUTTON_LEFT].clicked) ? ZR_CHART_CLICKED: 0;
|
||||
color = config->colors[ZR_COLOR_PLOT_HIGHLIGHT];
|
||||
}
|
||||
zr_draw_rect(out, bounds, 0, color);
|
||||
|
@ -9344,9 +9344,9 @@ zr_graph_push_line(struct zr_context *ctx, struct zr_window *win,
|
|||
color = config->colors[ZR_COLOR_PLOT_LINES];
|
||||
if (!(layout->flags & ZR_WINDOW_ROM)) {
|
||||
if (zr_input_is_mouse_hovering_rect(i, bounds)) {
|
||||
ret = ZR_GRAPH_HOVERING;
|
||||
ret = ZR_CHART_HOVERING;
|
||||
ret |= (i->mouse.buttons[ZR_BUTTON_LEFT].down &&
|
||||
i->mouse.buttons[ZR_BUTTON_LEFT].clicked) ? ZR_GRAPH_CLICKED: 0;
|
||||
i->mouse.buttons[ZR_BUTTON_LEFT].clicked) ? ZR_CHART_CLICKED: 0;
|
||||
color = config->colors[ZR_COLOR_PLOT_HIGHLIGHT];
|
||||
}
|
||||
}
|
||||
|
@ -9360,8 +9360,8 @@ zr_graph_push_line(struct zr_context *ctx, struct zr_window *win,
|
|||
}
|
||||
|
||||
static zr_flags
|
||||
zr_graph_push_column(const struct zr_context *ctx, struct zr_window *win,
|
||||
struct zr_graph *graph, float value)
|
||||
zr_chart_push_column(const struct zr_context *ctx, struct zr_window *win,
|
||||
struct zr_chart *chart, float value)
|
||||
{
|
||||
struct zr_command_buffer *out = &win->buffer;
|
||||
const struct zr_style *config = &ctx->style;
|
||||
|
@ -9373,41 +9373,41 @@ zr_graph_push_column(const struct zr_context *ctx, struct zr_window *win,
|
|||
zr_flags ret = 0;
|
||||
struct zr_rect item = {0,0,0,0};
|
||||
|
||||
if (graph->index >= graph->count)
|
||||
if (chart->index >= chart->count)
|
||||
return zr_false;
|
||||
if (graph->count) {
|
||||
float padding = (float)(graph->count-1);
|
||||
item.w = (graph->w - padding) / (float)(graph->count);
|
||||
if (chart->count) {
|
||||
float padding = (float)(chart->count-1);
|
||||
item.w = (chart->w - padding) / (float)(chart->count);
|
||||
}
|
||||
|
||||
/* calculate bounds of the current bar graph entry */
|
||||
/* calculate bounds of the current bar chart entry */
|
||||
color = config->colors[ZR_COLOR_HISTO_BARS];
|
||||
item.h = graph->h * ZR_ABS((value/graph->range));
|
||||
item.h = chart->h * ZR_ABS((value/chart->range));
|
||||
if (value >= 0) {
|
||||
ratio = (value + ZR_ABS(graph->min)) / ZR_ABS(graph->range);
|
||||
item.y = (graph->y + graph->h) - graph->h * ratio;
|
||||
ratio = (value + ZR_ABS(chart->min)) / ZR_ABS(chart->range);
|
||||
item.y = (chart->y + chart->h) - chart->h * ratio;
|
||||
} else {
|
||||
ratio = (value - graph->max) / graph->range;
|
||||
item.y = graph->y + (graph->h * ZR_ABS(ratio)) - item.h;
|
||||
ratio = (value - chart->max) / chart->range;
|
||||
item.y = chart->y + (chart->h * ZR_ABS(ratio)) - item.h;
|
||||
}
|
||||
item.x = graph->x + ((float)graph->index * item.w);
|
||||
item.x = item.x + ((float)graph->index);
|
||||
item.x = chart->x + ((float)chart->index * item.w);
|
||||
item.x = item.x + ((float)chart->index);
|
||||
|
||||
/* user graph bar selection */
|
||||
/* user chart bar selection */
|
||||
if (!(layout->flags & ZR_WINDOW_ROM) &&
|
||||
ZR_INBOX(in->mouse.pos.x,in->mouse.pos.y,item.x,item.y,item.w,item.h)) {
|
||||
ret = ZR_GRAPH_HOVERING;
|
||||
ret = ZR_CHART_HOVERING;
|
||||
ret |= (in->mouse.buttons[ZR_BUTTON_LEFT].down &&
|
||||
in->mouse.buttons[ZR_BUTTON_LEFT].clicked) ? ZR_GRAPH_CLICKED: 0;
|
||||
in->mouse.buttons[ZR_BUTTON_LEFT].clicked) ? ZR_CHART_CLICKED: 0;
|
||||
color = config->colors[ZR_COLOR_HISTO_HIGHLIGHT];
|
||||
}
|
||||
zr_draw_rect(out, item, 0, color);
|
||||
graph->index++;
|
||||
chart->index++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
zr_flags
|
||||
zr_graph_push(struct zr_context *ctx, float value)
|
||||
zr_chart_push(struct zr_context *ctx, float value)
|
||||
{
|
||||
struct zr_window *win;
|
||||
ZR_ASSERT(ctx);
|
||||
|
@ -9416,37 +9416,37 @@ zr_graph_push(struct zr_context *ctx, float value)
|
|||
return zr_false;
|
||||
|
||||
win = ctx->current;
|
||||
switch (win->layout->graph.type) {
|
||||
case ZR_GRAPH_LINES:
|
||||
return zr_graph_push_line(ctx, win, &win->layout->graph, value);
|
||||
case ZR_GRAPH_COLUMN:
|
||||
return zr_graph_push_column(ctx, win, &win->layout->graph, value);
|
||||
case ZR_GRAPH_MAX:
|
||||
switch (win->layout->chart.type) {
|
||||
case ZR_CHART_LINES:
|
||||
return zr_chart_push_line(ctx, win, &win->layout->chart, value);
|
||||
case ZR_CHART_COLUMN:
|
||||
return zr_chart_push_column(ctx, win, &win->layout->chart, value);
|
||||
case ZR_CHART_MAX:
|
||||
default: return zr_false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
zr_graph_end(struct zr_context *ctx)
|
||||
zr_chart_end(struct zr_context *ctx)
|
||||
{
|
||||
struct zr_window *win;
|
||||
struct zr_graph *graph;
|
||||
struct zr_chart *chart;
|
||||
ZR_ASSERT(ctx);
|
||||
ZR_ASSERT(ctx->current);
|
||||
if (!ctx || !ctx->current)
|
||||
return;
|
||||
|
||||
win = ctx->current;
|
||||
graph = &win->layout->graph;
|
||||
graph->type = ZR_GRAPH_MAX;
|
||||
graph->index = 0;
|
||||
graph->count = 0;
|
||||
graph->min = 0;
|
||||
graph->max = 0;
|
||||
graph->x = 0;
|
||||
graph->y = 0;
|
||||
graph->w = 0;
|
||||
graph->h = 0;
|
||||
chart = &win->layout->chart;
|
||||
chart->type = ZR_CHART_MAX;
|
||||
chart->index = 0;
|
||||
chart->count = 0;
|
||||
chart->min = 0;
|
||||
chart->max = 0;
|
||||
chart->x = 0;
|
||||
chart->y = 0;
|
||||
chart->w = 0;
|
||||
chart->h = 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------
|
||||
|
|
32
zahnrad.h
32
zahnrad.h
|
@ -816,7 +816,7 @@ enum zr_style_rounding {
|
|||
ZR_ROUNDING_CHECK,
|
||||
ZR_ROUNDING_INPUT,
|
||||
ZR_ROUNDING_PROPERTY,
|
||||
ZR_ROUNDING_GRAPH,
|
||||
ZR_ROUNDING_CHART,
|
||||
ZR_ROUNDING_SCROLLBAR,
|
||||
ZR_ROUNDING_MAX
|
||||
};
|
||||
|
@ -1023,18 +1023,18 @@ enum zr_edit_types {
|
|||
ZR_EDIT_BOX = (ZR_EDIT_CURSOR|ZR_EDIT_SELECTABLE|ZR_EDIT_CLIPBOARD|ZR_EDIT_MULTILINE)
|
||||
};
|
||||
|
||||
enum zr_graph_type {
|
||||
ZR_GRAPH_LINES,
|
||||
/* Line graph with each data point being connected with its previous and next node */
|
||||
ZR_GRAPH_COLUMN,
|
||||
/* Column graph/Histogram with value represented as bars */
|
||||
ZR_GRAPH_MAX
|
||||
enum zr_chart_type {
|
||||
ZR_CHART_LINES,
|
||||
/* Line chart with each data point being connected with its previous and next node */
|
||||
ZR_CHART_COLUMN,
|
||||
/* Histogram with value represented as bars */
|
||||
ZR_CHART_MAX
|
||||
};
|
||||
|
||||
enum zr_graph_event {
|
||||
ZR_GRAPH_HOVERING = 0x01,
|
||||
enum zr_chart_event {
|
||||
ZR_CHART_HOVERING = 0x01,
|
||||
/* mouse hoveres over current value */
|
||||
ZR_GRAPH_CLICKED = 0x02
|
||||
ZR_CHART_CLICKED = 0x02
|
||||
/* mouse click on current value */
|
||||
};
|
||||
|
||||
|
@ -1057,8 +1057,8 @@ enum zr_layout_node_type {
|
|||
/* a tab is a node with a header */
|
||||
};
|
||||
|
||||
struct zr_graph {
|
||||
enum zr_graph_type type;
|
||||
struct zr_chart {
|
||||
enum zr_chart_type type;
|
||||
/* graph type with either line or column graph */
|
||||
float x, y;
|
||||
/* graph canvas space position */
|
||||
|
@ -1183,7 +1183,7 @@ struct zr_layout {
|
|||
/* window menubar bounds */
|
||||
struct zr_row_layout row;
|
||||
/* currently used window row layout */
|
||||
struct zr_graph graph;
|
||||
struct zr_chart chart;
|
||||
/* graph state */
|
||||
struct zr_popup_buffer popup_buffer;
|
||||
/* output command buffer queuing all popup drawing calls */
|
||||
|
@ -1450,9 +1450,9 @@ int zr_edit_string(struct zr_context*, zr_flags, char *buffer, zr_size *len, zr_
|
|||
int zr_edit_buffer(struct zr_context*, zr_flags, struct zr_buffer*, zr_filter);
|
||||
|
||||
/* simple graph */
|
||||
void zr_graph_begin(struct zr_context*, enum zr_graph_type, zr_size num, float min, float max);
|
||||
zr_flags zr_graph_push(struct zr_context*, float);
|
||||
void zr_graph_end(struct zr_context*);
|
||||
void zr_chart_begin(struct zr_context*, enum zr_chart_type, zr_size num, float min, float max);
|
||||
zr_flags zr_chart_push(struct zr_context*, float);
|
||||
void zr_chart_end(struct zr_context*);
|
||||
|
||||
/*--------------------------------------------------------------
|
||||
* Popups
|
||||
|
|
Loading…
Reference in New Issue