source: abuse/trunk/src/imlib/fonts.cpp @ 661

Last change on this file since 661 was 661, checked in by Sam Hocevar, 12 years ago

imlib: refactor image::PutPart? and image::PutPartMasked?, get rid of
unused methods image::PutPartXrev? and image::fill_image.

File size: 1.9 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
9 */
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <ctype.h>
16
17#include "common.h"
18
19#include "fonts.h"
20
21texture_font::texture_font(image *letters, image *font_pattern)
22{ fntpat=font_pattern;
23  let=letters;
24  tl=(let->Size().x+1)/32;
25  th=(let->Size().y+1)/8;
26}
27
28void texture_font::put_char(image *screen,  int x, int y, char ch)
29{ if (fntpat)
30    screen->PutPartMasked(fntpat, vec2i(x, y), let,
31       vec2i(((int)ch%32)*tl,((int)ch/32)*th), vec2i(0,0), vec2i(tl-1,th-1));
32  else screen->PutPart(let, vec2i(x, y), vec2i(((int)ch%32)*tl, ((int)ch/32)*th),
33     vec2i(((int)ch%32)*tl+tl-1, ((int)ch/32)*th+th-1), 1);
34}
35
36void texture_font::put_string(image *screen, int x, int y, char const *st)
37{ while (*st)
38  { put_char(screen,x,y,*st);
39    st++;
40    x+=tl;
41  }
42}
43
44
45void JCFont::put_string(image *screen, int x, int y, char const *st, int color)
46{ while (*st)
47  { put_char(screen,x,y,*st,color);
48    st++;
49    x+=tl;
50  }
51}
52
53
54void JCFont::put_char(image *screen,  int x, int y, char ch, int color)
55{
56  if (let[(int)ch])
57  {
58    if (color>=0)
59      let[(int)ch]->PutColor(screen,vec2i(x,y),color);
60    else let[(int)ch]->PutImage(screen,vec2i(x,y));
61  }
62}
63
64JCFont::JCFont(image *letters)
65{
66  tl=(letters->Size().x+1)/32;
67  th=(letters->Size().y+1)/8;
68
69  image tmp(vec2i(tl,th));
70
71  int ch;
72
73  for (ch=0; ch<256; ch++)
74  {
75    tmp.clear();
76    tmp.PutPart(letters, vec2i(0, 0), vec2i(((int)ch%32)*tl, ((int)ch/32)*th),
77                vec2i(((int)ch%32)*tl+tl-1, ((int)ch/32)*th+th-1), 1);
78    let[ch] = new TransImage(&tmp, "JCfont");
79  }
80}
81
82JCFont::~JCFont()
83{
84  int ch;
85  for (ch=0; ch<256; ch++)
86    delete let[ch];
87}
88
Note: See TracBrowser for help on using the repository browser.