Mercurial > hg > dmlib
comparison ppl.c @ 130:1d7dc7c8745c
Move custom bitmap font text rendering functions into PPL code itself.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 04 Oct 2012 09:39:37 +0300 |
parents | 7a59611f9d4f |
children | f721f9f7838a |
comparison
equal
deleted
inserted
replaced
129:975725e3126d | 130:1d7dc7c8745c |
---|---|
156 | 156 |
157 return TRUE; | 157 return TRUE; |
158 } | 158 } |
159 | 159 |
160 | 160 |
161 void dmDrawBMTextConstQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt) | |
162 { | |
163 const char *ptr = fmt; | |
164 DMUnscaledBlitFunc blit = NULL; | |
165 | |
166 while (*ptr) | |
167 { | |
168 int ch = toupper(*ptr++); | |
169 SDL_Surface *glyph; | |
170 | |
171 if (ch == '_') | |
172 { | |
173 xc += 4; | |
174 continue; | |
175 } | |
176 | |
177 if (ch >= 0 && ch < font->nglyphs && (glyph = font->glyphs[ch]) != NULL) | |
178 { | |
179 if (blit == NULL) | |
180 blit = dmGetUnscaledBlitFunc(glyph->format, screen->format, mode); | |
181 | |
182 blit(glyph, xc, yc, screen); | |
183 xc += font->width; | |
184 } | |
185 else | |
186 xc += font->width; | |
187 } | |
188 } | |
189 | |
190 | |
191 void dmDrawBMTextVAQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, va_list ap) | |
192 { | |
193 char *tmp = dm_strdup_vprintf(fmt, ap); | |
194 if (tmp != NULL) | |
195 { | |
196 dmDrawBMTextConstQ(screen, font, mode, xc, yc, tmp); | |
197 dmFree(tmp); | |
198 } | |
199 } | |
200 | |
201 | |
202 void dmDrawBMTextQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, ...) | |
203 { | |
204 va_list ap; | |
205 | |
206 va_start(ap, fmt); | |
207 dmDrawBMTextVAQ(screen, font, mode, xc, yc, fmt, ap); | |
208 va_end(ap); | |
209 } | |
210 | |
211 | |
161 Uint32 dmCol(float r, float g, float b) | 212 Uint32 dmCol(float r, float g, float b) |
162 { | 213 { |
163 return dmMapRGB(engine.screen, 255.0f * r, 255.0f * g, 255.0f * b); | 214 return dmMapRGB(engine.screen, 255.0f * r, 255.0f * g, 255.0f * b); |
164 } | 215 } |
216 | |
165 | 217 |
166 BOOL dmInitializeVideo() | 218 BOOL dmInitializeVideo() |
167 { | 219 { |
168 engine.screen = SDL_SetVideoMode( | 220 engine.screen = SDL_SetVideoMode( |
169 engine.optScrWidth, engine.optScrHeight, engine.optScrDepth, | 221 engine.optScrWidth, engine.optScrHeight, engine.optScrDepth, |
267 if (n->param != jsetNotSet) | 319 if (n->param != jsetNotSet) |
268 sprintf(ptr, "%.2x", n->param); | 320 sprintf(ptr, "%.2x", n->param); |
269 else | 321 else |
270 sprintf(ptr, ".."); | 322 sprintf(ptr, ".."); |
271 | 323 |
272 dmDrawBMTextConst(screen, font, DMD_TRANSPARENT, xc, yc, text); | 324 dmDrawBMTextConstQ(screen, font, DMD_TRANSPARENT, xc, yc, text); |
273 } | 325 } |
274 | 326 |
275 | 327 |
276 void dmDisplayPattern(SDL_Surface *screen, int x0, int y0, int x1, int y1, JSSPattern *pat, int row, int choffs) | 328 void dmDisplayPattern(SDL_Surface *screen, int x0, int y0, int x1, int y1, JSSPattern *pat, int row, int choffs) |
277 { | 329 { |
298 int crow = nrow - midrow + row; | 350 int crow = nrow - midrow + row; |
299 yc = y0 + 2 + (font->height + 1) * nrow; | 351 yc = y0 + 2 + (font->height + 1) * nrow; |
300 | 352 |
301 if (crow >= 0 && crow < pat->nrows) | 353 if (crow >= 0 && crow < pat->nrows) |
302 { | 354 { |
303 dmDrawBMText(screen, font, DMD_TRANSPARENT, x0, yc, "%03d", crow); | 355 dmDrawBMTextQ(screen, font, DMD_TRANSPARENT, x0, yc, "%03d", crow); |
304 | 356 |
305 for (nchannel = 0; nchannel < qwidth; nchannel++) | 357 for (nchannel = 0; nchannel < qwidth; nchannel++) |
306 { | 358 { |
307 if (choffs + nchannel >= pat->nchannels) | 359 if (choffs + nchannel >= pat->nchannels) |
308 break; | 360 break; |
558 } | 610 } |
559 | 611 |
560 dmDrawBox3D(engine.screen, 0, 0, engine.screen->w - 1, engine.screen->h - 1, | 612 dmDrawBox3D(engine.screen, 0, 0, engine.screen->w - 1, engine.screen->h - 1, |
561 col.boxBg, col.box1, col.box2); | 613 col.boxBg, col.box1, col.box2); |
562 | 614 |
563 dmDrawBMText(engine.screen, font, DMD_TRANSPARENT, 5, 5, "%s v%s by ccr/TNSP - (c) Copyright 2012 TNSP", dmProgDesc, dmProgVersion); | 615 dmDrawBMTextQ(engine.screen, font, DMD_TRANSPARENT, 5, 5, "%s v%s by ccr/TNSP - (c) Copyright 2012 TNSP", dmProgDesc, dmProgVersion); |
564 | 616 |
565 | 617 |
566 JSS_LOCK(dev); | 618 JSS_LOCK(dev); |
567 JSS_LOCK(plr); | 619 JSS_LOCK(plr); |
568 | 620 |
569 dmDrawBMText(engine.screen, font, DMD_TRANSPARENT, 5, 5 + 12, | 621 dmDrawBMTextQ(engine.screen, font, DMD_TRANSPARENT, 5, 5 + 12, |
570 "Tempo: %3d | Speed: %3d | Row: %3d | Order: %d", | 622 "Tempo: %3d | Speed: %3d | Row: %3d | Order: %d", |
571 plr->tempo, plr->speed, plr->row, plr->order | 623 plr->tempo, plr->speed, plr->row, plr->order |
572 ); | 624 ); |
573 | 625 |
574 dmDisplayPattern(engine.screen, 5, 30, engine.screen->w - 6, engine.screen->h - 10, | 626 dmDisplayPattern(engine.screen, 5, 30, engine.screen->w - 6, engine.screen->h - 10, |