00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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 }
00106
00107
#endif // UTEXTLAYOUT_HPP