X-Git-Url: http://git.draconx.ca/gitweb/rrace.git/blobdiff_plain/aebcc2d9a4090d8136f750463b1cfbb73916d717..4ba1a1949117408cf81132b4f168a4e7f0a79ac3:/src/motif_ui.c diff --git a/src/motif_ui.c b/src/motif_ui.c index 4559ff6..a49dfec 100644 --- a/src/motif_ui.c +++ b/src/motif_ui.c @@ -24,6 +24,7 @@ #include "motif.h" #include "motifstr.h" #include "motifgui.h" +#include "xcounter.h" #define SPLIT_NUMERATOR 75 #define SPLIT_DENOMINATOR 100 @@ -95,11 +96,35 @@ ResizeGameArea(Widget form, XEvent *e, String *args, Cardinal *num_args) XtVaSetValues(goal, XmNwidth, goalsz, XmNheight, goalsz, (char *)NULL); } +static char *timer_text(int_fast32_t ms, char *buf) +{ + unsigned min, sec; + + sec = ms / 1000, ms %= 1000; + min = sec / 60, sec %= 60; + sprintf(buf, "Time: %u:%.2u.%.3u", min, sec, (unsigned)ms); + + return buf; +} + +void ui_timer_update(struct app_state *state, int_fast32_t ms) +{ + char buf[100]; + + if (ms < 0) { + xcounter_simple_update(state->timer, "\n"); + return; + } + + xcounter_simple_update(state->timer, timer_text(ms, buf)); +} + static void configure_mainwin(struct app_state *state, Widget form) { Widget gamearea = XtNameToWidget(form, &tree_strtab[gameArea]); Widget goalarea = XtNameToWidget(form, &tree_strtab[goalArea]); XtActionsRec resize_rec; + char xc_template[100]; assert(gamearea && goalarea); XtVaSetValues(form, XmNfractionBase, SPLIT_DENOMINATOR, (char *)NULL); @@ -116,6 +141,17 @@ static void configure_mainwin(struct app_state *state, Widget form) XmNtopWidget, gamearea, (char *)NULL); + state->timer = XtNameToWidget(form, &tree_strtab[timeDisplay]); + XtVaSetValues(state->timer, XmNleftAttachment, XmATTACH_WIDGET, + XmNleftWidget, gamearea, + XmNtopAttachment, XmATTACH_WIDGET, + XmNtopWidget, goalarea, + XmNrightAttachment, XmATTACH_FORM, + (char *)NULL); + + xcounter_simple_setup(state->timer, timer_text(20000, xc_template)); + ui_timer_update(state, -1); + resize_rec.string = "ResizeGameArea"; resize_rec.proc = ResizeGameArea; XtAppAddActions(XtWidgetToApplicationContext(form), &resize_rec, 1); @@ -123,6 +159,12 @@ static void configure_mainwin(struct app_state *state, Widget form) ": ResizeGameArea()\n" ": ResizeGameArea()\n" )); + + /* + * Performing the initial update of the layout seems to avoid + * some weird problems on Motif 2.1 + */ + ResizeGameArea(form, 0, 0, 0); } static Widget create_widget(const struct ui_widget *item, Widget parent,