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

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

Fuck the history, I'm renaming all .hpp files to .h for my own sanity.

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