Skip to content

Commit a4e125f

Browse files
authored
Merge pull request #942 from RobLoach/math-overview
demo: Use Nuklear math functions for examples
2 parents 4d827bb + 0794152 commit a4e125f

3 files changed

Lines changed: 25 additions & 25 deletions

File tree

demo/common/overview.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ overview(struct nk_context *ctx)
695695
ctx->style.chart.show_markers = show_markers;
696696
if (nk_chart_begin(ctx, NK_CHART_LINES, 32, -1.0f, 1.0f)) {
697697
for (i = 0; i < 32; ++i) {
698-
nk_flags res = nk_chart_push(ctx, (float)cos(id));
698+
nk_flags res = nk_chart_push(ctx, (float)NK_COS(id));
699699
if (res & NK_CHART_HOVERING)
700700
index = (int)i;
701701
if (res & NK_CHART_CLICKED)
@@ -706,17 +706,17 @@ overview(struct nk_context *ctx)
706706
}
707707

708708
if (index != -1)
709-
nk_tooltipf(ctx, "Value: %.2f", (float)cos((float)index*step));
709+
nk_tooltipf(ctx, "Value: %.2f", (float)NK_COS((float)index*step));
710710
if (line_index != -1) {
711711
nk_layout_row_dynamic(ctx, 20, 1);
712-
nk_labelf(ctx, NK_TEXT_LEFT, "Selected value: %.2f", (float)cos((float)index*step));
712+
nk_labelf(ctx, NK_TEXT_LEFT, "Selected value: %.2f", (float)NK_COS((float)index*step));
713713
}
714714

715715
/* column chart */
716716
nk_layout_row_dynamic(ctx, 100, 1);
717717
if (nk_chart_begin(ctx, NK_CHART_COLUMN, 32, 0.0f, 1.0f)) {
718718
for (i = 0; i < 32; ++i) {
719-
nk_flags res = nk_chart_push(ctx, (float)fabs(sin(id)));
719+
nk_flags res = nk_chart_push(ctx, (float)NK_ABS(NK_SIN(id)));
720720
if (res & NK_CHART_HOVERING)
721721
index = (int)i;
722722
if (res & NK_CHART_CLICKED)
@@ -726,10 +726,10 @@ overview(struct nk_context *ctx)
726726
nk_chart_end(ctx);
727727
}
728728
if (index != -1)
729-
nk_tooltipf(ctx, "Value: %.2f", (float)fabs(sin(step * (float)index)));
729+
nk_tooltipf(ctx, "Value: %.2f", (float)NK_ABS(NK_SIN(step * (float)index)));
730730
if (col_index != -1) {
731731
nk_layout_row_dynamic(ctx, 20, 1);
732-
nk_labelf(ctx, NK_TEXT_LEFT, "Selected value: %.2f", (float)fabs(sin(step * (float)col_index)));
732+
nk_labelf(ctx, NK_TEXT_LEFT, "Selected value: %.2f", (float)NK_ABS(NK_SIN(step * (float)col_index)));
733733
}
734734

735735
/* mixed chart */
@@ -738,9 +738,9 @@ overview(struct nk_context *ctx)
738738
nk_chart_add_slot(ctx, NK_CHART_LINES, 32, -1.0f, 1.0f);
739739
nk_chart_add_slot(ctx, NK_CHART_LINES, 32, -1.0f, 1.0f);
740740
for (id = 0, i = 0; i < 32; ++i) {
741-
nk_chart_push_slot(ctx, (float)fabs(sin(id)), 0);
742-
nk_chart_push_slot(ctx, (float)cos(id), 1);
743-
nk_chart_push_slot(ctx, (float)sin(id), 2);
741+
nk_chart_push_slot(ctx, (float)NK_ABS(NK_SIN(id)), 0);
742+
nk_chart_push_slot(ctx, (float)NK_COS(id), 1);
743+
nk_chart_push_slot(ctx, (float)NK_SIN(id), 2);
744744
id += step;
745745
}
746746
}
@@ -752,9 +752,9 @@ overview(struct nk_context *ctx)
752752
nk_chart_add_slot_colored(ctx, NK_CHART_LINES, nk_rgb(0,0,255), nk_rgb(0,0,150),32, -1.0f, 1.0f);
753753
nk_chart_add_slot_colored(ctx, NK_CHART_LINES, nk_rgb(0,255,0), nk_rgb(0,150,0), 32, -1.0f, 1.0f);
754754
for (id = 0, i = 0; i < 32; ++i) {
755-
nk_chart_push_slot(ctx, (float)fabs(sin(id)), 0);
756-
nk_chart_push_slot(ctx, (float)cos(id), 1);
757-
nk_chart_push_slot(ctx, (float)sin(id), 2);
755+
nk_chart_push_slot(ctx, (float)NK_ABS(NK_SIN(id)), 0);
756+
nk_chart_push_slot(ctx, (float)NK_COS(id), 1);
757+
nk_chart_push_slot(ctx, (float)NK_SIN(id), 2);
758758
id += step;
759759
}
760760
}
@@ -1120,8 +1120,8 @@ overview(struct nk_context *ctx)
11201120
if (nk_chart_begin_colored(ctx, NK_CHART_LINES, nk_rgb(255,0,0), nk_rgb(150,0,0), 32, 0.0f, 1.0f)) {
11211121
nk_chart_add_slot_colored(ctx, NK_CHART_LINES, nk_rgb(0,0,255), nk_rgb(0,0,150),32, -1.0f, 1.0f);
11221122
for (i = 0, id = 0; i < 32; ++i) {
1123-
nk_chart_push_slot(ctx, (float)fabs(sin(id)), 0);
1124-
nk_chart_push_slot(ctx, (float)cos(id), 1);
1123+
nk_chart_push_slot(ctx, (float)NK_ABS(NK_SIN(id)), 0);
1124+
nk_chart_push_slot(ctx, (float)NK_COS(id), 1);
11251125
id += step;
11261126
}
11271127
}
@@ -1131,7 +1131,7 @@ overview(struct nk_context *ctx)
11311131
nk_layout_row_dynamic(ctx, 100, 1);
11321132
if (nk_chart_begin_colored(ctx, NK_CHART_COLUMN, nk_rgb(255,0,0), nk_rgb(150,0,0), 32, 0.0f, 1.0f)) {
11331133
for (i = 0, id = 0; i < 32; ++i) {
1134-
nk_chart_push_slot(ctx, (float)fabs(sin(id)), 0);
1134+
nk_chart_push_slot(ctx, (float)NK_ABS(NK_SIN(id)), 0);
11351135
id += step;
11361136
}
11371137
}
@@ -1143,9 +1143,9 @@ overview(struct nk_context *ctx)
11431143
nk_chart_add_slot_colored(ctx, NK_CHART_LINES, nk_rgb(0,0,255), nk_rgb(0,0,150),32, -1.0f, 1.0f);
11441144
nk_chart_add_slot_colored(ctx, NK_CHART_COLUMN, nk_rgb(0,255,0), nk_rgb(0,150,0), 32, 0.0f, 1.0f);
11451145
for (i = 0, id = 0; i < 32; ++i) {
1146-
nk_chart_push_slot(ctx, (float)fabs(sin(id)), 0);
1147-
nk_chart_push_slot(ctx, (float)fabs(cos(id)), 1);
1148-
nk_chart_push_slot(ctx, (float)fabs(sin(id)), 2);
1146+
nk_chart_push_slot(ctx, (float)NK_ABS(NK_SIN(id)), 0);
1147+
nk_chart_push_slot(ctx, (float)NK_ABS(NK_COS(id)), 1);
1148+
nk_chart_push_slot(ctx, (float)NK_ABS(NK_SIN(id)), 2);
11491149
id += step;
11501150
}
11511151
}

example/extended.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,17 @@ ui_piemenu(struct nk_context *ctx, struct nk_vec2 pos, float radius,
127127

128128
/* separator line */
129129
rx = bounds.w/2.0f; ry = 0;
130-
dx = rx * (float)cos(a_min) - ry * (float)sin(a_min);
131-
dy = rx * (float)sin(a_min) + ry * (float)cos(a_min);
130+
dx = rx * (float)NK_COS(a_min) - ry * (float)NK_SIN(a_min);
131+
dy = rx * (float)NK_SIN(a_min) + ry * (float)NK_COS(a_min);
132132
nk_stroke_line(out, center.x, center.y,
133133
center.x + dx, center.y + dy, 1.0f, nk_rgb(50,50,50));
134134

135135
/* button content */
136136
a = a_min + (a_max - a_min)/2.0f;
137137
rx = bounds.w/2.5f; ry = 0;
138138
content.w = 30; content.h = 30;
139-
content.x = center.x + ((rx * (float)cos(a) - ry * (float)sin(a)) - content.w/2.0f);
140-
content.y = center.y + (rx * (float)sin(a) + ry * (float)cos(a) - content.h/2.0f);
139+
content.x = center.x + ((rx * (float)NK_COS(a) - ry * (float)NK_SIN(a)) - content.w/2.0f);
140+
content.y = center.y + (rx * (float)NK_SIN(a) + ry * (float)NK_COS(a) - content.h/2.0f);
141141
nk_draw_image(out, content, &icons[i], nk_rgb(255,255,255));
142142
a_min = a_max; a_max += step;
143143
}

example/skinning.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,9 @@ int main(int argc, char *argv[])
774774
nk_chart_add_slot_colored(&ctx, NK_CHART_LINES, nk_rgb(0,0,255), nk_rgb(0,0,150),32, -1.0f, 1.0f);
775775
nk_chart_add_slot_colored(&ctx, NK_CHART_LINES, nk_rgb(0,255,0), nk_rgb(0,150,0), 32, -1.0f, 1.0f);
776776
for (id = 0, i = 0; i < 32; ++i) {
777-
nk_chart_push_slot(&ctx, (float)fabs(sin(id)), 0);
778-
nk_chart_push_slot(&ctx, (float)cos(id), 1);
779-
nk_chart_push_slot(&ctx, (float)sin(id), 2);
777+
nk_chart_push_slot(&ctx, (float)NK_ABS(NK_SIN(id)), 0);
778+
nk_chart_push_slot(&ctx, (float)NK_COS(id), 1);
779+
nk_chart_push_slot(&ctx, (float)NK_SIN(id), 2);
780780
id += step;
781781
}
782782
}

0 commit comments

Comments
 (0)