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

Last change on this file since 494 was 494, checked in by Sam Hocevar, 11 years ago

style: remove trailing spaces, fix copyright statements.

File size: 1.8 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 or
8 *  Jonathan Clark.
9 */
10
11#include "config.h"
12
13#include <ctype.h>
14
15#include "fonts.h"
16
17texture_font::texture_font(image *letters, image *font_pattern)
18{ fntpat=font_pattern;
19  let=letters;
20  tl=(let->width()+1)/32;
21  th=(let->height()+1)/8;
22}
23
24void texture_font::put_char(image *screen,  int x, int y, char ch)
25{ if (fntpat)
26    fntpat->put_part_masked(screen,let, x,y,
27       ((int)ch%32)*tl,((int)ch/32)*th,0,0,tl-1,th-1);
28  else let->put_part(screen,x,y,((int)ch%32)*tl,((int)ch/32)*th,
29     ((int)ch%32)*tl+tl-1,((int)ch/32)*th+th-1,1);
30}
31
32void texture_font::put_string(image *screen, int x, int y, char const *st)
33{ while (*st)
34  { put_char(screen,x,y,*st);
35    st++;
36    x+=tl;
37  }
38}
39
40
41void JCFont::put_string(image *screen, int x, int y, char const *st, int color)
42{ while (*st)
43  { put_char(screen,x,y,*st,color);
44    st++;
45    x+=tl;
46  }
47}
48
49
50void JCFont::put_char(image *screen,  int x, int y, char ch, int color)
51{
52  if (let[(int)ch])
53  {
54    if (color>=0)
55      let[(int)ch]->put_color(screen,x,y,color);
56    else let[(int)ch]->put_image(screen,x,y);
57  }
58}
59
60JCFont::JCFont(image *letters)
61{
62  tl=(letters->width()+1)/32;
63  th=(letters->height()+1)/8;
64
65  image tmp(tl,th);
66
67  int ch;
68
69  for (ch=0; ch<256; ch++)
70  {
71    tmp.clear();
72    letters->put_part(&tmp,0,0,((int)ch%32)*tl,((int)ch/32)*th,
73              ((int)ch%32)*tl+tl-1,((int)ch/32)*th+th-1,1);
74    let[ch]=new trans_image(&tmp,"JCfont");
75  }
76}
77
78JCFont::~JCFont()
79{
80  int ch;
81  for (ch=0; ch<256; ch++)
82    delete let[ch];
83}
84
Note: See TracBrowser for help on using the repository browser.