From b221fff192341153fe3dbddc482f23fc7e46e8c3 Mon Sep 17 00:00:00 2001 From: Milo Turner Date: Wed, 4 Mar 2020 20:32:01 -0500 Subject: [PATCH] [window] more structured way of doing 'demo drawing' --- src/ax.h | 2 ++ src/ctxt/ctxt.c | 17 +++++++++++++++++ src/ctxt/window.c | 10 ++++++---- src/ctxt/window.h | 5 +++++ test/main.c | 1 + 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/ax.h b/src/ax.h index e31e85d..2922344 100644 --- a/src/ax.h +++ b/src/ax.h @@ -57,6 +57,8 @@ void ax_set_window_size( int ax_select_window(struct ax_ctxt* ax, struct ax_window* win); +int ax_show_demo(struct ax_ctxt* ax); + /* ----------------------------------------------------------------------------- * Cursor * -------------------------------------------------------------------------- */ diff --git a/src/ctxt/ctxt.c b/src/ctxt/ctxt.c index 8bad25f..14ae3e8 100644 --- a/src/ctxt/ctxt.c +++ b/src/ctxt/ctxt.c @@ -252,6 +252,23 @@ int ax_select_window(struct ax_ctxt* ax, struct ax_window* win) return 0; } +int ax_show_demo(struct ax_ctxt* ax) +{ + if (ax->sel_win == NULL) { + ax->err = "no window slected"; + return 1; + } + if (ax->sel_thm == NULL) { + ax->err = "no theme slected"; + return 1; + } + log_writelnf(ax->root_lg, + "drawing demo graphics (win=%p, thm=%p)", + ax->sel_win, ax->sel_thm); + ax__window_draw_demo(ax->sel_win, ax->sel_thm); + return 0; +} + /* ----------------------------------------------------------------------------- * Backend worker thread * -------------------------------------------------------------------------- */ diff --git a/src/ctxt/window.c b/src/ctxt/window.c index a41d22d..e718107 100644 --- a/src/ctxt/window.c +++ b/src/ctxt/window.c @@ -2,6 +2,7 @@ #include "../concurrent/msg.h" #include "../concurrent/msgq.h" #include "../geom/graphics.h" +#include "../ctxt/theme.h" static inline const char* default_title(struct rgn* rgn) { @@ -25,8 +26,6 @@ struct ax_window_builder* ax__window_builder_new(struct rgn* rgn) return winb; } -static void draw_demo(struct ax_graphics* gr); - struct ax_window* ax__window_builder_finish( struct ax_window_builder* winb, struct rgn* dst_rgn, @@ -37,7 +36,7 @@ struct ax_window* ax__window_builder_finish( pthread_mutex_init(&win->mx, NULL); rgn_pin(dst_rgn, &win->mx, (void*) pthread_mutex_destroy); win->graphics = ax__graphics_new(dst_rgn); - draw_demo(win->graphics); + // draw_demo(win->graphics); struct ax_msg_make_window* m = msgq_begin_send_typed(req_window_mq, ax_msg_make_window); @@ -51,8 +50,11 @@ struct ax_window* ax__window_builder_finish( return win; } -static void draw_demo(struct ax_graphics* gr) +void ax__window_draw_demo( + struct ax_window* win, + struct ax_theme* thm) { + struct ax_graphics* gr = win->graphics; struct ax_glyph* g; ax__graphics_clear(gr, 0xffffff); diff --git a/src/ctxt/window.h b/src/ctxt/window.h index b09eb8c..13ee3ed 100644 --- a/src/ctxt/window.h +++ b/src/ctxt/window.h @@ -7,6 +7,7 @@ struct msgq; struct ax_backend; +struct ax_theme; struct ax_graphics; #define WINDOW_BUILDER_DESIRED_REGION_SIZE SMALL @@ -61,3 +62,7 @@ static inline void ax__window_set_flag( winb->flags &= ~((int) f); } } + +void ax__window_draw_demo( + struct ax_window* win, + struct ax_theme* thm); diff --git a/test/main.c b/test/main.c index 36f99fa..9675cd4 100644 --- a/test/main.c +++ b/test/main.c @@ -69,6 +69,7 @@ int main(void) GUARD(ax_select_theme(ax, thm)); GUARD(ax_select_window(ax, win)); + GUARD(ax_show_demo(ax)); struct sub* ev_sub = ax__backend_sub_events(ax->bac, rgn); for (bool quit = false; !quit; ) {