4 #include <gmath/gmath.h>
15 long start_time, show_until;
20 static Message *msglist;
22 static long timeout = 2000;
23 static long trans_time = 250;
24 static dtx_font *font;
26 void set_message_timeout(long tm)
31 void show_message(const char *fmt, ...)
35 show_messagev(timeout, Vec3(1, 1, 1), fmt, ap);
39 void show_message(long timeout, const Vec3 &color, const char *fmt, ...)
43 show_messagev(timeout, color, fmt, ap);
47 void show_messagev(long timeout, const Vec3 &color, const char *fmt, va_list ap)
53 vsnprintf(buf, sizeof buf, fmt, ap);
55 Message *msg = new Message;
56 int len = strlen(buf);
57 msg->str = new char[len + 1];
58 memcpy(msg->str, buf, len + 1);
59 msg->start_time = time_msec;
60 msg->show_until = time_msec + timeout;
65 Message *prev = &dummy;
66 while(prev->next && prev->next->show_until < msg->show_until) {
69 msg->next = prev->next;
78 while(msglist && msglist->show_until <= time_msec) {
79 Message *msg = msglist;
85 dtx_use_font(font, FONTSZ);
87 glMatrixMode(GL_PROJECTION);
90 glOrtho(0, win_width, -win_height, 0, -1, 1);
91 glMatrixMode(GL_MODELVIEW);
95 glPushAttrib(GL_ENABLE_BIT);
96 glDisable(GL_LIGHTING);
97 glDisable(GL_DEPTH_TEST);
99 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
102 Message *msg = msglist;
104 long t = time_msec - msg->start_time;
105 long dur = msg->show_until - msg->start_time;
106 float alpha = smoothstep(0, trans_time, t) *
107 (1.0 - smoothstep(dur - trans_time, dur, t));
108 glColor4f(msg->color.x, msg->color.y, msg->color.z, alpha);
109 glTranslatef(0, -dtx_line_height(), 0);
110 dtx_string(msg->str);
116 glMatrixMode(GL_PROJECTION);
118 glMatrixMode(GL_MODELVIEW);
124 static bool done_init;
125 if(done_init) return true;
129 if(!(font = dtx_open_font("data/ui.font", 0))) {
130 fprintf(stderr, "failed to open font: data/ui.font\n");
133 dtx_prepare_range(font, FONTSZ, 32, 127);