5 #include "cgmath/cgmath.h"
12 long start_time, show_until;
17 static struct message *msglist;
25 static struct text *txlist;
27 static long timeout = 2000;
28 static long trans_time = 250;
31 void set_message_timeout(long tm)
36 void osd_printf(const char *fmt, ...)
40 show_messagev(timeout, 1, 1, 1, fmt, ap);
44 void show_message(long timeout, float r, float g, float b, const char *fmt, ...)
48 show_messagev(timeout, r, g, b, fmt, ap);
52 void show_messagev(long timeout, float r, float g, float b, const char *fmt, va_list ap)
59 vsnprintf(buf, sizeof buf, fmt, ap);
61 if(!(msg = malloc(sizeof *msg))) {
62 perror("failed to allocate memory");
66 if(!(msg->str = malloc(len + 1))) {
67 perror("failed to allocate memory");
70 memcpy(msg->str, buf, len + 1);
71 msg->start_time = time_msec;
72 msg->show_until = time_msec + timeout;
78 struct message *prev = &dummy;
79 while(prev->next && prev->next->show_until < msg->show_until) {
82 msg->next = prev->next;
87 void print_text(float x, float y, float r, float g, float b, const char *fmt, ...)
91 print_textv(x, y, r, g, b, fmt, ap);
95 void print_textv(float x, float y, float r, float g, float b, const char *fmt, va_list ap)
101 vsnprintf(buf, sizeof buf, fmt, ap);
103 if(!(tx = malloc(sizeof *tx))) {
104 perror("failed to allocate memory");
108 if(!(tx->str = malloc(len + 1))) {
109 perror("failed to allocate memory");
112 memcpy(tx->str, buf, len + 1);
127 while(msglist && msglist->show_until <= time_msec) {
128 struct message *msg = msglist;
134 dtx_use_font(fnt_ui, fnt_ui_size);
136 glMatrixMode(GL_PROJECTION);
139 glOrtho(0, win_width, -win_height, 0, -1, 1);
140 glMatrixMode(GL_MODELVIEW);
144 glPushAttrib(GL_ENABLE_BIT);
145 glDisable(GL_LIGHTING);
146 glDisable(GL_DEPTH_TEST);
148 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
151 struct message *msg = msglist;
153 long t = time_msec - msg->start_time;
154 long dur = msg->show_until - msg->start_time;
155 float alpha = cgm_smoothstep(0, trans_time, t) *
156 (1.0 - cgm_smoothstep(dur - trans_time, dur, t));
157 glColor4f(msg->color.x, msg->color.y, msg->color.z, alpha);
158 glTranslatef(0, -dtx_line_height(), 0);
159 dtx_string(msg->str);
164 struct text *tx = txlist;
165 txlist = txlist->next;
167 glMatrixMode(GL_MODELVIEW);
169 glTranslatef(tx->pos.x, tx->pos.y, 0);
171 glColor3f(tx->color.x, tx->color.y, tx->color.z);
180 glMatrixMode(GL_PROJECTION);
182 glMatrixMode(GL_MODELVIEW);