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 | |
---|
21 | void JCFont::PutString(image *screen, ivec2 pos, char const *st, int color) |
---|
22 | { |
---|
23 | for ( ; *st; st++, pos.x += m_size.x) |
---|
24 | PutChar(screen, pos, *st, color); |
---|
25 | } |
---|
26 | |
---|
27 | void JCFont::PutChar(image *screen, ivec2 pos, char ch, int color) |
---|
28 | { |
---|
29 | if (!m_data[(int)ch]) |
---|
30 | return; |
---|
31 | |
---|
32 | if (color >= 0) |
---|
33 | m_data[(int)ch]->PutColor(screen, pos, color); |
---|
34 | else |
---|
35 | m_data[(int)ch]->PutImage(screen, pos); |
---|
36 | } |
---|
37 | |
---|
38 | JCFont::JCFont(image *letters) |
---|
39 | { |
---|
40 | m_size = (letters->Size() + ivec2(1)) / ivec2(32, 8); |
---|
41 | |
---|
42 | image tmp(m_size); |
---|
43 | |
---|
44 | for (int ch = 0; ch < 256; ch++) |
---|
45 | { |
---|
46 | tmp.clear(); |
---|
47 | tmp.PutPart(letters, ivec2(0), |
---|
48 | ivec2(ch % 32, ch / 32) * m_size, |
---|
49 | ivec2(ch % 32 + 1, ch / 32 + 1) * m_size, 1); |
---|
50 | m_data[ch] = new TransImage(&tmp, "JCfont"); |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | JCFont::~JCFont() |
---|
55 | { |
---|
56 | for (int ch = 0; ch < 256; ch++) |
---|
57 | delete m_data[ch]; |
---|
58 | } |
---|
59 | |
---|