Back to index

nux  3.0.0
StaticText.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 #ifndef STATICTEXT_H
00023 #define STATICTEXT_H
00024 
00025 #include "NuxCore/Size.h"
00026 
00027 #if defined(NUX_OS_WINDOWS)
00028   #define NUX_STATIC_TEXT_USE_DIRECT_WRITE
00029 #elif defined(NUX_OS_LINUX)
00030   #define NUX_STATIC_TEXT_USE_CAIRO
00031 #else
00032   #error Not implemented.
00033 #endif
00034 
00035 namespace nux
00036 {
00037   class CairoGraphics;
00038 
00042   class StaticText: public View
00043   {
00044     NUX_DECLARE_OBJECT_TYPE(StaticText, View);
00045   public:
00046 
00048 
00056     enum TextAlignment
00057     {
00058       ALIGN_CENTER = 0,
00059       ALIGN_LEFT,
00060       ALIGN_RIGHT,
00061     };
00062 
00063     StaticText(const std::string& text, NUX_FILE_LINE_PROTO);
00064     virtual ~StaticText();
00065 
00067 
00070     void SetSizeMatchText(bool size_match_text);
00071 
00073     bool GetSizeMatchText() const;
00074 
00076     void SetText(const std::string& text);
00077 
00079     std::string GetText() const;
00080 
00082 
00087     void SetTextColor(const Color& text_color);
00088     
00090 
00095     Color GetTextColor() const;
00096 
00098 
00103     void SetFontName(const std::string& font_name);
00104 
00106 
00111     std::string GetFontName() const;
00112 
00114     /*
00115         Set the text point size. The value should be greater than 0. Otherwise, the 
00116         text point size is not changed. \n
00117         The default value is 10.
00118 
00119         @param size The text point size.
00120     */
00121     void SetFontSize(int size);
00122     void SetTextPointSize(int size); //deprecated: use SetFontSize
00123 
00125     int GetFontSize() const;
00126     int GetTextPointSize() const; //deprecated: use GetFontSize
00127 
00128     void GetTextLayoutSize(int& width, int& height) const;
00129 
00130     Size GetTextLayoutSize() const;
00131 
00133 
00136     void SetTextAlignment(TextAlignment alignment);
00137 
00139 
00142     TextAlignment GetTextAlignment() const;
00143 
00145 
00151     ObjectPtr<nux::IOpenGLBaseTexture> GetTextTexture();
00152 
00153     sigc::signal<void, StaticText*> text_changed;
00154 
00155   protected:
00156     virtual void ApplyMinWidth();
00157     virtual long ComputeContentSize();
00158     virtual void Draw(GraphicsEngine& graphics_engine, bool forceDraw);
00159 
00160     int text_width_;  
00161     int text_height_; 
00162 
00163     std::string text_;
00164     Color text_color_;
00165 
00166     BaseTexture* rasterized_text_texture_;
00167 
00168     bool size_match_text_;
00169 
00170     int clip_to_width_; 
00171 
00172     float font_size_;
00173     std::string font_name_;
00174     bool update_text_rendering_;
00175 
00176     ObjectPtr<nux::IOpenGLBaseTexture> dw_texture_;
00177     
00178     TextAlignment text_alignment_;
00179 
00180     void SetClipping(int clipping);
00181     int GetClipping() const;
00182 
00183 #if defined(NUX_STATIC_TEXT_USE_DIRECT_WRITE)
00184     Size ComputeTextSize(bool assign = true, bool with_clipping = true);
00185     void RasterizeText(Color color);
00186     void UpdateTextRendering();
00187 
00188     float layout_left_;
00189     float layout_top_;
00190     float dpi_scale_x;
00191     float dpi_scale_y;
00192     
00193 #elif defined (NUX_STATIC_TEXT_USE_CAIRO)
00194     float dpy_;
00195     std::string pango_font_name_;  
00196 
00197     Size ComputeTextSize(bool assign = true, bool with_clipping = true);
00198     void RasterizeText(void* cairo_context, Color color);
00199     void UpdateTextRendering();
00200 
00201     CairoGraphics* cairo_graphics_;
00202 #endif
00203 
00204   private:
00206 
00209     virtual void SetMinimumHeight(){};
00210 
00212 
00215     virtual void SetMaximumHeight(){};
00216 
00218 
00223     Size GetTextSizeNoClip();
00224 
00225     float padding_x_;   
00226     float padding_y_;   
00227     Size no_clip_size_; 
00228   };
00229 
00230 }
00231 
00232 #endif // STATICTEXT_H