Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

Title.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "Title.h"
00010 
00011 #include "Font.h"
00012 #include "Color.h"
00013 #include "OptionAgent.h"
00014 
00015 //-----------------------------------------------------------------
00016 /**
00017  * Create new title to draw.
00018  * X is centred.
00019  * Y is baseY above bottom screen border.
00020  *
00021  * @param baseY number of pixels from the bottom border
00022  * @param finalY final position, it changes when next subtitle is added
00023  * @param bonusTime bonus time for subtitle under bottom border
00024  * @param limitY max Y distance from bottom border
00025  * @param content subtitle content
00026  * @param font subtitle font (shared)
00027  * @param color subtitle color (shared)
00028  */
00029 Title::Title(int baseY, int finalY, int bonusTime, int limitY,
00030         const std::string &content, Font *font, const Color *color)
00031 : m_content(content)
00032 {
00033     m_font = font;
00034     m_surface = m_font->renderTextOutlined(content, *color);
00035 
00036     int text_width = m_font->calcTextWidth(content);
00037 
00038     m_screenW = OptionAgent::agent()->getAsInt("screen_width");
00039     m_screenH = OptionAgent::agent()->getAsInt("screen_height");
00040     m_x = (m_screenW - text_width) / 2;
00041     m_y = m_screenH - baseY;
00042     m_finalY = m_screenH - finalY;
00043     m_limitY = m_screenH - limitY;
00044     m_mintime = m_content.size() * TIME_PER_CHAR;
00045     if (m_mintime < TIME_MIN) {
00046         m_mintime = TIME_MIN;
00047     }
00048     m_mintime += bonusTime;
00049 }
00050 //-----------------------------------------------------------------
00051 Title::~Title()
00052 {
00053     SDL_FreeSurface(m_surface);
00054 }
00055 //-----------------------------------------------------------------
00056 /**
00057  * Draw model.
00058  */
00059     void
00060 Title::drawOn(SDL_Surface *screen)
00061 {
00062     //TODO: wavy text
00063     SDL_Rect rect;
00064     rect.x = m_x;
00065     rect.y = m_y;
00066 
00067     SDL_BlitSurface(m_surface, NULL, screen, &rect);
00068 }
00069 //-----------------------------------------------------------------
00070 /**
00071  * Shift up until title is on limit.
00072  * Decrease m_mintime.
00073  */
00074     void
00075 Title::shiftUp(int rate)
00076 {
00077     m_mintime--;
00078     m_y -= rate;
00079     if (m_y < m_finalY) {
00080         m_y = m_finalY;
00081     }
00082 }
00083 //-----------------------------------------------------------------
00084     void
00085 Title::shiftFinalUp(int rate)
00086 {
00087     m_finalY -= rate;
00088 }
00089 //-----------------------------------------------------------------
00090 /**
00091  * Return Y position from the bottom border.
00092  */
00093 int
00094 Title::getY() const
00095 {
00096     return m_screenH - m_y;
00097 }
00098 //-----------------------------------------------------------------
00099 /**
00100  * Whether title was long enough on screen.
00101  */
00102     bool
00103 Title::isGone()
00104 {
00105     //TEST: long time
00106     return (m_mintime < 0 || m_y < m_limitY);
00107     //return m_y < m_limitY;
00108 }
00109 

Generated on Wed Jun 1 09:54:31 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2