- Your Widget Set For OpenGL
Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Related Pages

utextlayout.hpp

00001 /*************************************************************************** 00002 LibUFO - UI For OpenGL 00003 copyright : (C) 2001-2005 by Johannes Schmidt 00004 email : schmidtjf at users.sourceforge.net 00005 ------------------- 00006 00007 file : include/ufo/text/utextlayout.hpp 00008 begin : Sun Mar 20 2005 00009 $Id: utextlayout.hpp,v 1.1 2005/05/21 15:40:00 schmidtjf Exp $ 00010 ***************************************************************************/ 00011 00012 /*************************************************************************** 00013 * This library is free software; you can redistribute it and/or * 00014 * modify it under the terms of the GNU Lesser General Public * 00015 * License as published by the Free Software Foundation; either * 00016 * version 2.1 of the License, or (at your option) any later version. * 00017 * * 00018 * This library is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00021 * Lesser General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU Lesser General Public * 00024 * License along with this library; if not, write to the Free Software * 00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 00026 ***************************************************************************/ 00027 00028 #ifndef UTEXTLAYOUT_HPP 00029 #define UTEXTLAYOUT_HPP 00030 00031 #include "../uobject.hpp" 00032 00033 #include "../font/ufont.hpp" 00034 #include "../util/urectangle.hpp" 00035 00036 namespace ufo { 00037 00038 class UGraphics; 00039 00040 class UFO_EXPORT UTextLine { 00041 public: 00042 UTextLine() : start(0), length(0), height(0), pos(), valid(false) {} 00043 UTextLine(unsigned int offset, unsigned int length, int h, const UPoint & p) 00044 : start(offset), length(length), height(h), pos(p), valid(true) {} 00045 unsigned int getOffset() const { return start; } 00046 unsigned int getLength() const { return length; } 00047 int getHeight() const { return height; } 00048 UPoint getPos() const { return pos; } 00049 bool isValid() const { return valid; } 00050 public: 00051 unsigned int start; 00052 unsigned int length; 00053 int height; 00054 UPoint pos; 00055 bool valid; 00056 }; 00057 00063 class UFO_EXPORT UTextLayout : public UObject { 00064 UFO_DECLARE_DYNAMIC_CLASS(UTextLayout) 00065 public: 00066 UTextLayout(); 00067 void setFont(const UFont & font); 00068 UFont getFont() const; 00069 00071 void setText(const char * text, unsigned int length); 00073 const char * getText(); 00074 unsigned int getLength(); 00075 00076 void setMaximumSize(const UDimension & dim); 00077 UDimension getPreferredSize(const UDimension & maxSize); 00078 00079 void render(UGraphics * g, const URectangle & rect, const UPoint & offset = UPoint()); 00083 URectangle modelToView(int offset); 00087 int viewToModel(const UPoint & pos); 00088 00089 void layout(); 00090 00091 int getLineCount(); 00092 UTextLine getLine(int i); 00093 UTextLine getLineForTextPosition(int i); 00094 protected: 00095 void invalidate(); 00096 private: 00097 const char * m_text; 00098 unsigned int m_length; 00099 UFont m_font; 00100 std::vector<UTextLine> m_lines; 00101 UDimension m_maxSize; 00102 bool m_validLayout; 00103 }; 00104 00105 } // namespace ufo 00106 00107 #endif // UTEXTLAYOUT_HPP

The libUFO Project - written by Johannes Schmidt