[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 | |
---|
[512] | 15 | #include "common.h" |
---|
| 16 | |
---|
[481] | 17 | #include "fonts.h" |
---|
[56] | 18 | |
---|
[2] | 19 | texture_font::texture_font(image *letters, image *font_pattern) |
---|
| 20 | { fntpat=font_pattern; |
---|
| 21 | let=letters; |
---|
[512] | 22 | tl=(let->Size().x+1)/32; |
---|
| 23 | th=(let->Size().y+1)/8; |
---|
[2] | 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 | |
---|
[39] | 34 | void texture_font::put_string(image *screen, int x, int y, char const *st) |
---|
[2] | 35 | { while (*st) |
---|
| 36 | { put_char(screen,x,y,*st); |
---|
| 37 | st++; |
---|
| 38 | x+=tl; |
---|
| 39 | } |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | |
---|
[39] | 43 | void JCFont::put_string(image *screen, int x, int y, char const *st, int color) |
---|
[2] | 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 | { |
---|
[4] | 54 | if (let[(int)ch]) |
---|
[2] | 55 | { |
---|
| 56 | if (color>=0) |
---|
[533] | 57 | let[(int)ch]->PutColor(screen,vec2i(x,y),color); |
---|
| 58 | else let[(int)ch]->PutImage(screen,vec2i(x,y)); |
---|
[2] | 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | JCFont::JCFont(image *letters) |
---|
| 63 | { |
---|
[512] | 64 | tl=(letters->Size().x+1)/32; |
---|
| 65 | th=(letters->Size().y+1)/8; |
---|
[2] | 66 | |
---|
[513] | 67 | image tmp(vec2i(tl,th)); |
---|
[124] | 68 | |
---|
[2] | 69 | int ch; |
---|
[124] | 70 | |
---|
[494] | 71 | for (ch=0; ch<256; ch++) |
---|
[124] | 72 | { |
---|
| 73 | tmp.clear(); |
---|
[2] | 74 | letters->put_part(&tmp,0,0,((int)ch%32)*tl,((int)ch/32)*th, |
---|
[124] | 75 | ((int)ch%32)*tl+tl-1,((int)ch/32)*th+th-1,1); |
---|
[533] | 76 | let[ch]=new TImage(&tmp,"JCfont"); |
---|
[124] | 77 | } |
---|
[2] | 78 | } |
---|
| 79 | |
---|
| 80 | JCFont::~JCFont() |
---|
| 81 | { |
---|
| 82 | int ch; |
---|
[494] | 83 | for (ch=0; ch<256; ch++) |
---|
[124] | 84 | delete let[ch]; |
---|
[2] | 85 | } |
---|
| 86 | |
---|