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

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

style: remove trailing spaces, fix copyright statements.

File size: 1.8 KB
RevLine 
[56]1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
[494]4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
[56]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
[2]13#include <ctype.h>
14
[481]15#include "fonts.h"
[56]16
[2]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
[39]32void texture_font::put_string(image *screen, int x, int y, char const *st)
[2]33{ while (*st)
34  { put_char(screen,x,y,*st);
35    st++;
36    x+=tl;
37  }
38}
39
40
[39]41void JCFont::put_string(image *screen, int x, int y, char const *st, int color)
[2]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{
[4]52  if (let[(int)ch])
[2]53  {
54    if (color>=0)
[4]55      let[(int)ch]->put_color(screen,x,y,color);
56    else let[(int)ch]->put_image(screen,x,y);
[2]57  }
58}
59
60JCFont::JCFont(image *letters)
61{
62  tl=(letters->width()+1)/32;
[124]63  th=(letters->height()+1)/8;
[2]64
65  image tmp(tl,th);
[124]66
[2]67  int ch;
[124]68
[494]69  for (ch=0; ch<256; ch++)
[124]70  {
71    tmp.clear();
[2]72    letters->put_part(&tmp,0,0,((int)ch%32)*tl,((int)ch/32)*th,
[124]73              ((int)ch%32)*tl+tl-1,((int)ch/32)*th+th-1,1);
[2]74    let[ch]=new trans_image(&tmp,"JCfont");
[124]75  }
[2]76}
77
78JCFont::~JCFont()
79{
80  int ch;
[494]81  for (ch=0; ch<256; ch++)
[124]82    delete let[ch];
[2]83}
84
Note: See TracBrowser for help on using the repository browser.