| 1 |
/* |
| 2 |
* Copyright (C) 2004 Ivo Danihelka ([email protected]) |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
*/ |
| 9 |
#include "Title.h" |
| 10 |
|
| 11 |
#include "Font.h" |
| 12 |
#include "Color.h" |
| 13 |
#include "OptionAgent.h" |
| 14 |
#include "StringTool.h" |
| 15 |
|
| 16 |
//----------------------------------------------------------------- |
| 17 |
/** |
| 18 |
* Create new title to draw. |
| 19 |
* X is centred. |
| 20 |
* Y is baseY above bottom screen border. |
| 21 |
* |
| 22 |
* @param baseY number of pixels from the bottom border |
| 23 |
* @param finalY final position, it changes when next subtitle is added |
| 24 |
* @param bonusTime bonus time for subtitle under bottom border |
| 25 |
* @param limitY max Y distance from bottom border |
| 26 |
* @param content subtitle content |
| 27 |
* @param font subtitle font (shared) |
| 28 |
* @param color subtitle color (shared) |
| 29 |
*/ |
| 30 |
Title::Title(int baseY, int finalY, int bonusTime, int limitY, |
| 31 |
const std::string &content, Font *font, const Color *color) |
| 32 |
: m_content(content) |
| 33 |
{ |
| 34 |
m_font = font; |
| 35 |
m_surface = m_font->renderTextOutlined(content, *color); |
| 36 |
|
| 37 |
int text_width = m_font->calcTextWidth(content); |
| 38 |
|
| 39 |
m_screenW = OptionAgent::agent()->getAsInt("screen_width"); |
| 40 |
m_screenH = OptionAgent::agent()->getAsInt("screen_height"); |
| 41 |
m_x = (m_screenW - text_width) / 2; |
| 42 |
m_y = m_screenH - baseY; |
| 43 |
m_finalY = m_screenH - finalY; |
| 44 |
m_limitY = m_screenH - limitY; |
| 45 |
m_mintime = StringTool::utf8Length(m_content) * TIME_PER_CHAR; |
| 46 |
if (m_mintime < TIME_MIN) { |
| 47 |
m_mintime = TIME_MIN; |
| 48 |
} |
| 49 |
m_mintime += bonusTime; |
| 50 |
} |
| 51 |
//----------------------------------------------------------------- |
| 52 |
Title::~Title() |
| 53 |
{ |
| 54 |
SDL_FreeSurface(m_surface); |
| 55 |
} |
| 56 |
//----------------------------------------------------------------- |
| 57 |
/** |
| 58 |
* Draw model. |
| 59 |
*/ |
| 60 |
void |
| 61 |
Title::drawOn(SDL_Surface *screen) |
| 62 |
{ |
| 63 |
//TODO: wavy text |
| 64 |
SDL_Rect rect; |
| 65 |
rect.x = m_x; |
| 66 |
rect.y = m_y; |
| 67 |
|
| 68 |
SDL_BlitSurface(m_surface, NULL, screen, &rect); |
| 69 |
} |
| 70 |
//----------------------------------------------------------------- |
| 71 |
/** |
| 72 |
* Shift up until title is on limit. |
| 73 |
* Decrease m_mintime. |
| 74 |
*/ |
| 75 |
void |
| 76 |
Title::shiftUp(int rate) |
| 77 |
{ |
| 78 |
m_mintime--; |
| 79 |
m_y -= rate; |
| 80 |
if (m_y < m_finalY) { |
| 81 |
m_y = m_finalY; |
| 82 |
} |
| 83 |
} |
| 84 |
//----------------------------------------------------------------- |
| 85 |
void |
| 86 |
Title::shiftFinalUp(int rate) |
| 87 |
{ |
| 88 |
m_finalY -= rate; |
| 89 |
} |
| 90 |
//----------------------------------------------------------------- |
| 91 |
/** |
| 92 |
* Return Y position from the bottom border. |
| 93 |
*/ |
| 94 |
int |
| 95 |
Title::getY() const |
| 96 |
{ |
| 97 |
return m_screenH - m_y; |
| 98 |
} |
| 99 |
//----------------------------------------------------------------- |
| 100 |
/** |
| 101 |
* Whether title was long enough on screen. |
| 102 |
*/ |
| 103 |
bool |
| 104 |
Title::isGone() |
| 105 |
{ |
| 106 |
return (m_mintime < 0 || m_y < m_limitY); |
| 107 |
} |
| 108 |
|