00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_XRB_TEXTWIDGET_HPP_)
00012 #define _XRB_TEXTWIDGET_HPP_
00013
00014 #include "xrb.hpp"
00015
00016 #include "xrb_color.hpp"
00017 #include "xrb_widget.hpp"
00018 #include "xrb_font.hpp"
00019 #include "xrb_resourcelibrary.hpp"
00020
00021 namespace Xrb
00022 {
00023
00024 class TextWidget : public Widget
00025 {
00026 public:
00027
00030 TextWidget (
00031 std::string const &text,
00032 ContainerWidget *const parent,
00033 std::string const &name = "TextWidget");
00034 virtual ~TextWidget () { }
00035
00036
00037
00038
00039
00042 inline std::string const &Text () const { return m_text; }
00048 inline Color const &TextColor () const { return m_text_color; }
00051 inline Resource<Font> const &GetFont () const { return m_font; }
00057 inline bool IsMinWidthFixedToTextWidth () const { return m_is_min_width_fixed_to_text_width; }
00063 inline bool IsMaxWidthFixedToTextWidth () const { return m_is_max_width_fixed_to_text_width; }
00069 inline bool IsMinHeightFixedToTextHeight () const { return m_is_min_height_fixed_to_text_height; }
00075 inline bool IsMaxHeightFixedToTextHeight () const { return m_is_max_height_fixed_to_text_height; }
00076
00077
00078
00079
00080
00081 inline SignalReceiver1<std::string const &> const *ReceiverSetText () { return &m_receiver_set_text; }
00082 inline SignalReceiver1<std::string> const *ReceiverSetTextV () { return &m_receiver_set_text_v; }
00083
00084
00085
00086
00087
00088 virtual void SetText (std::string const &text);
00089 void SetTextColor (Color const &color);
00090 void SetFont (Resource<Font> const &font);
00091 void SetFontFacePath (std::string const &font_face_path);
00092 void SetFontHeightRatio (Float font_height_ratio);
00093 void SetFontHeight (ScreenCoord font_height);
00094 void SetIsMinWidthFixedToTextWidth (bool is_min_width_fixed_to_text_width);
00095 void SetIsMaxWidthFixedToTextWidth (bool is_max_width_fixed_to_text_width);
00096 void SetIsWidthFixedToTextWidth (bool is_width_fixed_to_text_width);
00097 void SetIsMinHeightFixedToTextHeight (bool is_min_height_fixed_to_text_height);
00098 void SetIsMaxHeightFixedToTextHeight (bool is_max_height_fixed_to_text_height);
00099 void SetIsHeightFixedToTextHeight (bool is_height_fixed_to_text_height);
00100 void SetIsMinSizeFixedToTextSize (bool is_min_size_fixed_to_text_size);
00101 void SetIsMaxSizeFixedToTextSize (bool is_max_size_fixed_to_text_size);
00102 void SetIsSizeFixedToTextSize (bool is_size_fixed_to_text_size);
00103
00104 virtual void Draw (RenderContext const &render_context) const = 0;
00105
00106 protected:
00107
00108 inline Color const &RenderTextColor () const { return m_render_text_color; }
00109 inline Resource<Font> const &RenderFont () const { return m_render_font; }
00110
00111 inline void SetRenderTextColor (Color const &render_text_color) { m_render_text_color = render_text_color; }
00112 virtual void SetRenderFont (Resource<Font> const &render_font);
00113
00114
00115 virtual void HandleChangedFont ();
00116 virtual void HandleChangedFrameMargins ();
00117 virtual void HandleChangedContentMargins ();
00118
00119 virtual void UpdateRenderTextColor ();
00120 virtual void UpdateRenderFont ();
00121
00122
00123
00124 virtual ScreenCoordRect TextRect () const;
00125
00126
00127 virtual void UpdateMinAndMaxSizesFromText ();
00128
00129
00130 std::string m_text;
00131
00132 bool m_is_min_width_fixed_to_text_width;
00133
00134 bool m_is_max_width_fixed_to_text_width;
00135
00136 bool m_is_min_height_fixed_to_text_height;
00137
00138 bool m_is_max_height_fixed_to_text_height;
00139
00140 private:
00141
00142 void SetTextV (std::string text) { SetText(text); }
00143
00144
00145 Resource<Font> m_font;
00146
00147 Resource<Font> m_render_font;
00148
00149 Color m_text_color;
00150
00151 Color m_render_text_color;
00152
00153
00154
00155
00156
00157 SignalReceiver1<std::string const &> m_receiver_set_text;
00158 SignalReceiver1<std::string> m_receiver_set_text_v;
00159
00160 };
00161
00162 }
00163
00164 #endif // !defined(_XRB_TEXTWIDGET_HPP_)
00165