#include "motif.h"
#include "motifstr.h"
#include "motifgui.h"
+#include "xcounter.h"
#define SPLIT_NUMERATOR 75
#define SPLIT_DENOMINATOR 100
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);
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);
"<Configure>: ResizeGameArea()\n"
"<Map>: 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,