00001 /* 00002 * glut-font-effects.h 00003 * 00004 * Copyright (C) 2010 Thomas A. Vaughan 00005 * All rights reserved. 00006 * 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the <organization> nor the 00016 * names of its contributors may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY 00020 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY 00023 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00026 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 */ 00031 00032 #ifndef WAVE_GLUT_GLUT_FONT_EFFECTS_H__ 00033 #define WAVE_GLUT_GLUT_FONT_EFFECTS_H__ 00034 00035 // includes -------------------------------------------------------------------- 00036 #include "glut-font.h" 00037 00038 #include "color/color.h" 00039 00040 00041 namespace glut { 00042 00043 //////////////////////////////////////////////////////////////////////////////// 00044 /// 00045 /// \ingroup glut_font 00046 /// \defgroup glut_font_effects Glut Font Effects 00047 /// 00048 /// Font effects based on the \ref glut_font library. 00049 /// 00050 //////////////////////////////////////////////////////////////////////////////// 00051 00052 /*@{*/ 00053 00054 00055 //////////////////////////////////////////////////////////////////////////////// 00056 // 00057 // public API 00058 // 00059 //////////////////////////////////////////////////////////////////////////////// 00060 00061 /// general base class for font effect objects. Usually these exist to provide 00062 /// effects for a given set (multiple lines) of text. 00063 class FontEffect { 00064 public: 00065 // virtual destructor -------------------------------------------------- 00066 virtual ~FontEffect(void) throw(); 00067 00068 // glut::FontEffect class interface methods ---------------------------- 00069 00070 /// tick the effect. Caller provides time in seconds since the previous 00071 /// call. Implementors should ignore zero or negative time deltas 00072 /// (these can happen if system clocks reset etc.). Usually this is 00073 /// called per frame of animation, with deltaSeconds on the order 00074 /// of a few milliseconds. 00075 virtual void tick(IN float deltaSeconds) = 0; 00076 00077 /// draw. Usually called each frame. 00078 virtual void render(void) = 0; 00079 00080 /// reset (restart) the effect 00081 virtual void reset(void) = 0; 00082 00083 /// advance the effect. Effects usually advance on their own. Clients 00084 /// can call this method if they need to move the effect on faster 00085 /// (for instance, user is pushing the "next" button). Often this 00086 /// will fast-forward to the next line, for instance. In some 00087 /// cases this is equivalent to calling complete() below. 00088 virtual void advance(void) = 0; 00089 00090 /// complete the effect. Client can use this to fast-forward the effect 00091 /// to get to the end. Again, this is often used so that users can 00092 /// skip any animations so they can move ahead quicker. 00093 virtual void complete(void) = 0; 00094 }; 00095 00096 00097 /// this font effect will write out lines of text one character at a time. 00098 /// The lines parameter can contain multiple lines of text, separated by 00099 /// newline characters. 00100 smart_ptr<FontEffect> getCharacterAdvanceEffect(IN smart_ptr<Font>& font, 00101 IN const char * lines, 00102 IN int millisecondsPerCharacter, 00103 IN const glut_color_t& color); 00104 00105 00106 /// given a long sequence of words in a given font, this routine returns the 00107 /// same words, only with line breaks inserted so that a single line is 00108 /// never longer than the specified width. Note that really long words 00109 /// won't be broken up (you'll have a single line with a word that is 00110 /// too long). 00111 void breakLongString(IN const char * text, 00112 IN Font * font, 00113 IN int maxPixelWidth, 00114 OUT std::string& output); 00115 00116 00117 }; // glut namespace 00118 00119 00120 #endif // WAVE_GLUT_GLUT_FONT_EFFECTS_H__ 00121