Back to index

unity  6.0.0
StaticCairoText.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2010-2012 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Jay Taoko <jay.taoko@canonical.com>
00018  * Authored by: Mirco Müller <mirco.mueller@canonical.com>
00019  */
00020 
00021 #ifndef UNITYSHARED_STATICCAIROTEXT_H
00022 #define UNITYSHARED_STATICCAIROTEXT_H
00023 
00024 #include <string>
00025 
00026 #include <Nux/Nux.h>
00027 #include <Nux/View.h>
00028 
00029 namespace nux
00030 {
00031 class Validator;
00032 
00033 class StaticCairoText : public View
00034 {
00035   NUX_DECLARE_OBJECT_TYPE (StaticCairoText, View);
00036 public:
00037   enum EllipsizeState
00038   {
00039     NUX_ELLIPSIZE_END,
00040     NUX_ELLIPSIZE_START,
00041     NUX_ELLIPSIZE_MIDDLE,
00042     NUX_ELLIPSIZE_NONE,
00043   };
00044 
00045   enum AlignState
00046   {
00047     NUX_ALIGN_LEFT,
00048     NUX_ALIGN_CENTRE,
00049     NUX_ALIGN_RIGHT,
00050     NUX_ALIGN_TOP = NUX_ALIGN_LEFT,
00051     NUX_ALIGN_BOTTOM = NUX_ALIGN_RIGHT
00052   };
00053 
00054   StaticCairoText(std::string const& text, NUX_FILE_LINE_PROTO);
00055   ~StaticCairoText();
00056 
00057   void PreLayoutManagement();
00058 
00059   long PostLayoutManagement(long layoutResult);
00060 
00061   void Draw(GraphicsEngine& gfxContext,
00062             bool             forceDraw);
00063 
00064   void DrawContent(GraphicsEngine& gfxContext,
00065                    bool             forceDraw);
00066 
00067   void PostDraw(GraphicsEngine& gfxContext,
00068                 bool             forceDraw);
00069 
00070   // public API
00071   void SetText(std::string const& text);
00072   void SetTextColor(Color const& textColor);
00073   void SetTextEllipsize(EllipsizeState state);
00074   void SetTextAlignment(AlignState state);
00075   void SetTextVerticalAlignment(AlignState state);
00076   void SetFont(std::string const& font);
00077   void SetLines(int maximum_lines);
00078 
00079   std::string GetText() const;
00080   Color GetTextColor() const;
00081 
00082   int GetLineCount() const;
00083   int GetBaseline() const;
00084 
00085   void GetTextExtents(int& width, int& height) const;
00086   Size GetTextExtents() const;
00087 
00088   sigc::signal<void, StaticCairoText*> sigTextChanged;
00089   sigc::signal<void, StaticCairoText*> sigTextColorChanged;
00090   sigc::signal<void, StaticCairoText*> sigFontChanged;
00091 
00092   void SetAcceptKeyNavFocus(bool accept);
00093 
00094 protected:
00095   // Key navigation
00096   virtual bool AcceptKeyNavFocus();
00097 
00098 private:
00099   struct Impl;
00100   Impl* pimpl;
00101 };
00102 }
00103 
00104 #endif // STATICCAIROTEXT_H