4 #include <gmath/gmath.h>
15 long start_time, show_until;
19 static Message *msglist;
21 static long timeout = 2000;
22 static long trans_time = 250;
23 static dtx_font *font;
25 void set_message_timeout(long tm)
30 void show_message(const char *fmt, ...)
38 vsnprintf(buf, sizeof buf, fmt, ap);
41 Message *msg = new Message;
42 int len = strlen(buf);
43 msg->str = new char[len + 1];
44 memcpy(msg->str, buf, len + 1);
45 msg->start_time = time_msec;
46 msg->show_until = time_msec + timeout;
50 Message *prev = &dummy;
51 while(prev->next && prev->next->show_until < msg->show_until) {
54 msg->next = prev->next;
63 while(msglist && msglist->show_until <= time_msec) {
64 Message *msg = msglist;
70 dtx_use_font(font, FONTSZ);
72 glMatrixMode(GL_PROJECTION);
75 glOrtho(0, win_width, -win_height, 0, -1, 1);
76 glMatrixMode(GL_MODELVIEW);
80 glPushAttrib(GL_ENABLE_BIT);
81 glDisable(GL_LIGHTING);
82 glDisable(GL_DEPTH_TEST);
84 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
87 Message *msg = msglist;
89 long t = time_msec - msg->start_time;
90 long dur = msg->show_until - msg->start_time;
91 float alpha = smoothstep(0, trans_time, t) *
92 (1.0 - smoothstep(dur - trans_time, dur, t));
93 glColor4f(1.0, 0.5, 0.1, alpha);
94 glTranslatef(0, -dtx_line_height(), 0);
101 glMatrixMode(GL_PROJECTION);
103 glMatrixMode(GL_MODELVIEW);
109 static bool done_init;
110 if(done_init) return true;
114 if(!(font = dtx_open_font("data/ui.font", 0))) {
115 fprintf(stderr, "failed to open font: data/ui.font\n");
118 dtx_prepare_range(font, FONTSZ, 32, 127);