1 /* 2 * Holotz's Castle 3 * Copyright (C) 2004 Juan Carlos Seijo P�rez 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License as published by the Free 7 * Software Foundation; either version 2 of the License, or (at your option) 8 * any later version. 9 * 10 * This program is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 59 17 * Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * 19 * Juan Carlos Seijo P�rez 20 * jacob@mainreactor.net 21 */ 22 23 /** Text messages for Holotz's Castle. Base class. 24 * @file HCText.h 25 * @author Juan Carlos Seijo P�rez 26 * @date 25/06/2004 27 * @version 0.0.1 - 25/06/2004 - Primera versi�n. 28 */ 29 30 #ifndef _HCTEXT_INCLUDED 31 #define _HCTEXT_INCLUDED 32 33 #include <JLib/Graphics/JDrawable.h> 34 #include <JLib/Graphics/JImage.h> 35 #include <JLib/Graphics/JFont.h> 36 #include <HCTheme.h> 37 38 typedef enum HCTextType 39 { 40 HCTEXTTYPE_DIALOG, /**< Dialog balloon. */ 41 HCTEXTTYPE_NARRATIVE, /**< Narrative frame. */ 42 HCTEXTTYPE_COUNT, /**< Number of different types. */ 43 }; 44 45 /** Encapsulates a generic text message. 46 */ 47 class HCText : public JDrawable 48 { 49 protected: 50 JFont *font; /**< Font to render the text with. */ 51 JImage text; /**< Rendered text. */ 52 HCTheme *theme; /**< Theme of the text object. */ 53 HCTextType type; /**< Type of text object. */ 54 s32 subtype; /**< Subtype within the theme. */ 55 bool left; /**< Peak direction. */ 56 float *trackX; /**< Tracked x position. */ 57 float *trackY; /**< Tracked y position. */ 58 59 JTimer timer; /**< Timer for fades. */ 60 static s32 textSpeed; /**< Text duration factor [1-10]. */ 61 static s32 minDelay; /**< Minimum delay for text. */ 62 static s32 maxAlpha; /**< Maximum alpha value. */ 63 64 public: 65 /** Creates an empty text object. Init must be called before using it. 66 */ HCText()67 HCText() : font(0), theme(0), type(HCTEXTTYPE_DIALOG), 68 subtype(0), left(true), trackX(&pos.x), trackY(&pos.y) 69 {} 70 71 /** Initializes the object. 72 * @param _type The type of text object. 73 * @param _text Text to draw. 74 * @param _theme Theme from where to load the images. 75 * @param _font Font to use to render the text. 76 * @param a The Alignment of the text. 77 * @param _left Peak direction (only for dialog frames). 78 * @return <b>true</b> if successful, <b>false</b> if not. 79 */ 80 bool Init(HCTextType _type, const char *_text, HCTheme *_theme, 81 JFont *_font, JFontAlign a, bool _left = true, s32 _subtype = 0, 82 u8 r = 255, u8 g = 255, u8 b = 255); 83 84 /** Gets the type of this text. 85 * @return Type of this text. 86 */ Type()87 const HCTextType & Type() {return type;} 88 89 /** Sets the type of this text. 90 * @param newType New type of this text. 91 */ Type(const HCTextType & newType)92 void Type(const HCTextType &newType) {type = newType;} 93 94 /** Gets the subtype of this text. 95 * @return Subtype of this text. 96 */ Subtype()97 s32 Subtype() {return subtype;} 98 99 /** Sets the subtype of this text. 100 * @param newSubtype New type of this text. 101 */ Subtype(s32 newSubtype)102 void Subtype(s32 newSubtype) {subtype = newSubtype;} 103 104 /** Positions this object. 105 * @param x New x coordinate. 106 * @param y New y coordinate. 107 */ Pos(float x,float y)108 virtual void Pos(float x, float y) 109 {pos.x = x; pos.y = y; text.Pos(x, y); } 110 111 /** Draws the object. 112 */ 113 virtual void Draw(); 114 115 /** Updates the object. 116 * @return 2 if disappeared, 1 if following something, 0 otherwise. 117 */ 118 virtual s32 Update(); 119 120 /** Follows the given coordinates such that every time the coordinates change, 121 * this text moves. If 0 is passed, the no tracking is made. 122 * @param xTrack Pointer to the x position to track. 123 * @param yTrack Pointer to the y position to track. 124 */ 125 void Track(float *x = 0, float *y = 0); 126 127 /** Chechs whether this text is visible or not. 128 * @return <b>true</b> if it's visible, <b>false</b> otherwise. 129 */ Visible()130 bool Visible() {return text.Alpha() > 0;} 131 132 /** Gets this text's image. 133 * @return This text's image. 134 */ Image()135 JImage& Image() {return text;} 136 137 /** Sets the text speed. The value varies from 1 (slow) to 10 (fast). 138 * @param speed New value for speed. 139 */ Speed(s32 speed)140 static void Speed(s32 speed) {textSpeed = speed;} 141 142 /** Gets the text speed. The value varies from 1 (slow) to 10 (fast). 143 * @return speed New value for speed. 144 */ Speed()145 static s32 Speed() {return textSpeed;} 146 147 /** Prepares the text to be displayed. 148 */ 149 void Reset(); 150 151 /** Skips the text. 152 */ Skip()153 void Skip() {timer.Start(1);} 154 155 /** Frees resources. 156 */ 157 void Destroy(); 158 159 /** Destroys the object. 160 */ ~HCText()161 virtual ~HCText() {Destroy();} 162 }; 163 164 #endif // _HCTEXT_INCLUDED 165