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

Last change on this file since 668 was 668, checked in by Sam Hocevar, 8 years ago

imlib: make JCFont use vec2i classes.

File size: 1.3 KB
Line 
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
21void JCFont::PutString(image *screen, vec2i pos, char const *st, int color)
22{
23    for ( ; *st; st++, pos.x += m_size.x)
24        PutChar(screen, pos, *st, color);
25}
26
27void JCFont::PutChar(image *screen, vec2i 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
38JCFont::JCFont(image *letters)
39{
40    m_size = (letters->Size() + vec2i(1)) / vec2i(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, vec2i(0),
48                    vec2i(ch % 32, ch / 32) * m_size,
49                    vec2i(ch % 32 + 1, ch / 32 + 1) * m_size, 1);
50        m_data[ch] = new TransImage(&tmp, "JCfont");
51    }
52}
53
54JCFont::~JCFont()
55{
56    for (int ch = 0; ch < 256; ch++)
57        delete m_data[ch];
58}
59
Note: See TracBrowser for help on using the repository browser.