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