summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/graph.c66
-rwxr-xr-xexamples/gravity.c11
-rwxr-xr-xexamples/ui.c18
3 files changed, 77 insertions, 18 deletions
diff --git a/examples/graph.c b/examples/graph.c
new file mode 100755
index 0000000..c7b2877
--- /dev/null
+++ b/examples/graph.c
@@ -0,0 +1,66 @@
+#if 0 /*
+#/ ================================================================
+#/
+#/ graph.c
+#/
+#/ ================================================================
+#/
+#/ Self-compilation shell script
+#/
+SRC=${0##*./}
+BIN=${SRC%.*}
+gcc \
+ -Wall -Wextra -Werror -pedantic \
+ -Wno-old-style-declaration \
+ -Wno-missing-braces \
+ -Wno-unused-variable \
+ -Wno-unused-but-set-variable \
+ -Wno-unused-parameter \
+ -Wno-overlength-strings \
+ -O3 \
+ -fsanitize=undefined,address,leak -mshstk \
+ -lX11 -lm \
+ -o $BIN $SRC && \
+ ./$BIN $@ && rm $BIN
+exit $? # */
+#endif
+
+#include "../graphics.c"
+
+i32 main(i32 argc, c8 **argv) {
+ (void) argc;
+ (void) argv;
+
+ platform = (Platform) {
+ .title = "Graph",
+ .frame_width = 960,
+ .frame_height = 720,
+ };
+
+ u32 WHITE = u32_from_rgb(1.f, 1.f, 1.f);
+ u32 BLACK = u32_from_rgb(0.f, 0.f, 0.f);
+ u32 RED = u32_from_rgb(1.f, 0.f, 0.f);
+ u32 BLUE = u32_from_rgb(0.f, 0.f, 1.f);
+
+ p_init();
+
+ while (!platform.done) {
+ p_wait_events();
+
+ i64 x = platform.frame_width / 2;
+ i64 y = platform.frame_height / 2;
+
+ fill_rectangle(OP_SET, WHITE, 0, 0, platform.frame_width, platform.frame_height);
+
+ fill_triangle(OP_SET, RED, 100, 100, 200, 100, 150, 200);
+
+ fill_line(OP_SET, BLUE, 100, 300, 300, 500, 30);
+
+ fill_ellipse(OP_SET, BLACK, x - 140, y - 100, 280, 200);
+
+ p_render_frame();
+ }
+
+ p_cleanup();
+ return 0;
+}
diff --git a/examples/gravity.c b/examples/gravity.c
index 8bc45e0..246aab1 100755
--- a/examples/gravity.c
+++ b/examples/gravity.c
@@ -40,13 +40,6 @@ typedef struct {
Entity entities[10 * 1024 * 1024];
} World;
-i64 time_milliseconds() {
- struct timespec t;
- timespec_get(&t, TIME_UTC);
-
- return (i64) t.tv_sec * 1000ll + (i64) t.tv_nsec / 1000000ll;
-}
-
i32 main(i32 argc, c8 **argv) {
(void) argc;
(void) argv;
@@ -64,12 +57,12 @@ i32 main(i32 argc, c8 **argv) {
srand(time(0));
static World world = {0};
- i64 time_0 = time_milliseconds();
+ i64 time_0 = p_time();
while (!platform.done) {
p_handle_events();
- i64 time_elapsed = time_milliseconds() - time_0;
+ i64 time_elapsed = p_time() - time_0;
time_0 += time_elapsed;
if (platform.key_pressed[BUTTON_LEFT]) {
diff --git a/examples/ui.c b/examples/ui.c
index 0847af3..4730a9d 100755
--- a/examples/ui.c
+++ b/examples/ui.c
@@ -59,12 +59,12 @@ i32 main(i32 argc, c8 **argv) {
if (platform.cursor_x >= 40 && platform.cursor_x < 100 && platform.cursor_y >= 40 && platform.cursor_y < 100) {
button_0_down = platform.key_down[BUTTON_LEFT];
if (button_0_down)
- draw_panel(OP_SET, 0xffffff, 40, 40, 60, 60);
+ fill_rectangle(OP_SET, 0xffffff, 40, 40, 60, 60);
else
- draw_panel(OP_SET, 0x00ff00, 40, 40, 60, 60);
+ fill_rectangle(OP_SET, 0x00ff00, 40, 40, 60, 60);
} else {
button_0_down = 0;
- draw_panel(OP_SET, 0x208020, 40, 40, 60, 60);
+ fill_rectangle(OP_SET, 0x208020, 40, 40, 60, 60);
}
if (platform.cursor_x >= 40 && platform.cursor_x < 100 && platform.cursor_y >= 120 && platform.cursor_y < 180) {
@@ -72,17 +72,17 @@ i32 main(i32 argc, c8 **argv) {
if (platform.key_pressed[BUTTON_LEFT])
button_1_checked = !button_1_checked;
if (button_1_down)
- draw_panel(OP_SET, 0xffffff, 40, 120, 60, 60);
+ fill_rectangle(OP_SET, 0xffffff, 40, 120, 60, 60);
else if (button_1_checked)
- draw_panel(OP_SET, 0xff8080, 40, 120, 60, 60);
+ fill_rectangle(OP_SET, 0xff8080, 40, 120, 60, 60);
else
- draw_panel(OP_SET, 0x80ff80, 40, 120, 60, 60);
+ fill_rectangle(OP_SET, 0x80ff80, 40, 120, 60, 60);
} else {
button_1_down = 0;
if (button_1_checked)
- draw_panel(OP_SET, 0xff0000, 40, 120, 60, 60);
+ fill_rectangle(OP_SET, 0xff0000, 40, 120, 60, 60);
else
- draw_panel(OP_SET, 0x00ff00, 40, 120, 60, 60);
+ fill_rectangle(OP_SET, 0x00ff00, 40, 120, 60, 60);
}
i64 w = platform.frame_width / 2;
@@ -246,7 +246,7 @@ i32 main(i32 argc, c8 **argv) {
draw_text_area(0, x0 + 8, y0 - 8, w, h, 10., 10., text_len, text);
draw_text_area(color, x0, y0, w, h, 10., 10., text_len, text);
- draw_text_cursor(0xffffff, x0, y0, w, h, 10., 10., cursor, selection, text_len, text);
+ draw_selection_cursor(0xffffff, x0, y0, w, h, 10., 10., cursor, selection, text_len, text);
p_render_frame();
}