source: abuse/branches/lol/src/imlib/fonts.cpp

Last change on this file was 737, checked in by Sam Hocevar, 7 years ago

build: sync with newer Lol Engine changes.

File size: 1.4 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2013 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 HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <ctype.h>
16
17#include "common.h"
18
19#include "imlib/fonts.h"
20
21void JCFont::PutString(AImage *screen, ivec2 pos, String const &st, int color)
22{
23    for (int i = 0; i < st.count(); ++i, pos.x += m_size.x)
24        PutChar(screen, pos, st[i], color);
25}
26
27void JCFont::PutChar(AImage *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
38JCFont::JCFont(AImage *letters)
39{
40    m_size = (letters->Size() + ivec2(1)) / ivec2(32, 8);
41
42    AImage tmp(m_size);
43
44    for (int ch = 0; ch < 256; ch++)
45    {
46        tmp.clear();
47        tmp.PutPart(letters, ivec2::zero,
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
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.