summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/tilereg-title.cc
blob: 244adfcba0a1483704f066634f1a6c403ee58bf3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "AppHdr.h"

#ifdef USE_TILE_LOCAL

#include "tilereg-title.h"

#include "files.h"
#include "libutil.h"
#include "macro.h"
#include "random.h"

static const string _get_title_image()
{
    vector<string> files = get_title_files();
    return files[random2(files.size())];
}

TitleRegion::TitleRegion(int width, int height, FontWrapper* font) :
    m_buf(true, false), m_font_buf(font)
{
    // set the texture for the title image
    m_buf.set_tex(&m_img);

    sx = sy = 0;
    dx = dy = 1;

    if (!m_img.load_texture(_get_title_image().c_str(), MIPMAP_NONE))
        return;

    if ((int)m_img.orig_width() < width && (int)m_img.orig_height() < height)
    {
        // Center
        wx = width;
        wy = height;
        ox = (wx - m_img.orig_width()) / 2;
        oy = (wy - m_img.orig_height()) / 2;

        GLWPrim rect(0, 0, m_img.width(), m_img.height());
        rect.set_tex(0, 0, 1, 1);
        m_buf.add_primitive(rect);
    }
    else
    {
        // scale to fit
        if (width < height)
        {
            // taller than wide (scale to fit width; leave top/bottom borders)
            ox = 0;
            oy = (height - m_img.orig_height()*width/m_img.orig_width())/2;
            wx = m_img.width()*width/m_img.orig_width();
            wy = m_img.height()*width/m_img.orig_width();
        }
        else
        {
            // wider than tall (so scale to fit height; leave left/right borders)
            oy = 0;
            ox = (width - m_img.orig_width()*height/m_img.orig_height())/2;
            wx = m_img.width()*height/m_img.orig_height();
            wy = m_img.height()*height/m_img.orig_height();
        }

        GLWPrim rect(0, 0, wx, wy);
        rect.set_tex(0, 0, 1, 1);
        m_buf.add_primitive(rect);
    }
}

void TitleRegion::render()
{
#ifdef DEBUG_TILES_REDRAW
    cprintf("rendering TitleRegion\n");
#endif
    set_transform();
    m_buf.draw();
    m_font_buf.draw();
}

void TitleRegion::run()
{
    mouse_control mc(MOUSE_MODE_MORE);
    getchm();
}

/**
 * We only want to show one line of message by default so clear the
 * font buffer before adding the new message.
 */
void TitleRegion::update_message(string message)
{
    m_font_buf.clear();
    m_font_buf.add(message, VColour::white, 0, 0);
}

#endif