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

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

imlib: make JCFont use vec2i classes.

File size: 1.3 KB
RevLine 
[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
[555]7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
[56]9 */
10
[555]11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
[56]14
[2]15#include <ctype.h>
16
[512]17#include "common.h"
18
[481]19#include "fonts.h"
[56]20
[668]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);
[2]25}
26
[668]27void JCFont::PutChar(image *screen, vec2i pos, char ch, int color)
[2]28{
[668]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);
[2]36}
37
38JCFont::JCFont(image *letters)
39{
[668]40    m_size = (letters->Size() + vec2i(1)) / vec2i(32, 8);
[2]41
[668]42    image tmp(m_size);
[124]43
[668]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    }
[2]52}
53
54JCFont::~JCFont()
55{
[668]56    for (int ch = 0; ch < 256; ch++)
57        delete m_data[ch];
[2]58}
59
Note: See TracBrowser for help on using the repository browser.