00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_XRB_LABEL_HPP_)
00012 #define _XRB_LABEL_HPP_
00013
00014 #include "xrb.hpp"
00015
00016 #include "xrb_ntuple.hpp"
00017 #include "xrb_textwidget.hpp"
00018
00019 namespace Xrb
00020 {
00021
00022 typedef NTuple<Alignment, 2> Alignment2;
00023
00029 class Label : public TextWidget
00030 {
00031 public:
00032
00038 Label (
00039 std::string const &text,
00040 ContainerWidget *const parent,
00041 std::string const &name = "Label");
00046 Label (
00047 Resource<GLTexture> const &picture,
00048 ContainerWidget *const parent,
00049 std::string const &name = "Label");
00052 virtual ~Label () { }
00053
00054
00055
00056
00057
00064 inline Alignment2 const &GetAlignment () const { return m_alignment; }
00067 inline bool WordWrap () const { return m_word_wrap; }
00070 inline bool IsPictureLabel () const { return m_is_picture_label; }
00074 inline Resource<GLTexture> const &Picture () const { return m_picture; }
00080 inline bool PictureKeepsAspectRatio () const { return m_picture_keeps_aspect_ratio; }
00081
00082
00083
00084
00085
00086 virtual void SetText (std::string const &text);
00087 void SetAlignment (Alignment2 const &alignment);
00088 void SetAlignment (Uint32 component, Alignment alignment);
00089 virtual void SetWordWrap (bool word_wrap);
00090 virtual void SetPicture (std::string const &picture_name);
00091 virtual void SetPicture (Resource<GLTexture> const &picture);
00092 inline void SetPictureKeepsAspectRatio (bool picture_keeps_aspect_ratio) { m_picture_keeps_aspect_ratio = picture_keeps_aspect_ratio; }
00093
00094 virtual void Draw (RenderContext const &render_context) const;
00095 virtual ScreenCoordVector2 Resize (ScreenCoordVector2 const &size);
00096
00097 protected:
00098
00099 void DrawText (RenderContext const &render_context) const;
00100 void DrawPicture (RenderContext const &render_context) const;
00101
00102 inline Resource<GLTexture> const &RenderPicture () const { return m_render_picture; }
00103
00104 virtual void SetRenderFont (Resource<Font> const &render_font);
00105 void SetRenderPicture (Resource<GLTexture> const &render_picture);
00106
00107 virtual void HandleChangedFrameMargins ();
00108 virtual void HandleChangedContentMargins ();
00109
00110 virtual void UpdateRenderFont ();
00111 virtual void UpdateRenderPicture ();
00112
00113 virtual ScreenCoordRect TextRect () const;
00114 virtual void UpdateMinAndMaxSizesFromText ();
00115
00116 inline void DirtyTextFormatting () { m_text_formatting_update_required = true; }
00117
00118 private:
00119
00120 void UpdateCachedFormattedText () const;
00121
00122
00123 mutable std::string m_cached_formatted_text;
00124
00125 mutable std::string const *m_line_format_vector_source;
00126
00127 mutable Font::LineFormatVector m_line_format_vector;
00128
00129
00130 mutable bool m_text_formatting_update_required;
00131
00132 Alignment2 m_alignment;
00133
00134 bool m_word_wrap;
00135
00136 bool m_is_picture_label;
00137
00138 Resource<GLTexture> m_picture;
00139
00140 Resource<GLTexture> m_render_picture;
00141
00142
00143 bool m_picture_keeps_aspect_ratio;
00144 };
00145
00146 }
00147
00148 #endif // !defined(_XRB_LABEL_HPP_)
00149