~brandontschaefer/unity/bump-to-new-nux-abi

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
 * Copyright (C) 2010-2012 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Jay Taoko <jay.taoko@canonical.com>
 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
 */

#ifndef UNITYSHARED_STATICCAIROTEXT_H
#define UNITYSHARED_STATICCAIROTEXT_H

#include <pango/pango.h>
#include <string>

#include <Nux/Nux.h>
#include <Nux/View.h>

#include "unity-shared/Introspectable.h"

namespace unity
{
class Validator;

class StaticCairoText : public nux::View, public unity::debug::Introspectable
{
  NUX_DECLARE_OBJECT_TYPE (StaticCairoText, nux::View);
public:
  enum EllipsizeState
  {
    NUX_ELLIPSIZE_END,
    NUX_ELLIPSIZE_START,
    NUX_ELLIPSIZE_MIDDLE,
    NUX_ELLIPSIZE_NONE,
  };

  enum AlignState
  {
    NUX_ALIGN_LEFT,
    NUX_ALIGN_CENTRE,
    NUX_ALIGN_RIGHT,
    NUX_ALIGN_TOP = NUX_ALIGN_LEFT,
    NUX_ALIGN_BOTTOM = NUX_ALIGN_RIGHT
  };

  enum UnderlineState
  {
    NUX_UNDERLINE_NONE,
    NUX_UNDERLINE_SINGLE,
    NUX_UNDERLINE_DOUBLE,
    NUX_UNDERLINE_LOW
  };

  StaticCairoText(std::string const& text, NUX_FILE_LINE_PROTO);
  StaticCairoText(std::string const& text, bool escape_text, NUX_FILE_LINE_PROTO);
  ~StaticCairoText();

  void PreLayoutManagement();

  long PostLayoutManagement(long layoutResult);

  void Draw(nux::GraphicsEngine& gfxContext,
            bool             forceDraw);

  void DrawContent(nux::GraphicsEngine& gfxContext,
                   bool             forceDraw);

  // public API
  void SetText(std::string const& text, bool escape_text = false);
  void SetTextAlpha(unsigned int alpha);
  void SetTextColor(nux::Color const& textColor);
  void SetTextEllipsize(EllipsizeState state);
  void SetTextAlignment(AlignState state);
  void SetTextVerticalAlignment(AlignState state);

  void SetFont(std::string const& font);
  void SetFontSize(int);
  void SetFontWeight(PangoWeight);
  std::string GetFont();

  void SetUnderline(UnderlineState underline);
  void SetLines(int maximum_lines);
  void SetLineSpacing(float line_spacing);

  std::string GetText() const;
  nux::Color GetTextColor() const;

  int GetLineCount() const;
  int GetBaseline() const;

  void GetTextExtents(int& width, int& height) const;
  nux::Size GetTextExtents() const;

  void SetScale(double);
  double GetScale() const;

  sigc::signal<void, StaticCairoText*> sigTextChanged;
  sigc::signal<void, StaticCairoText*> sigTextColorChanged;
  sigc::signal<void, StaticCairoText*> sigFontChanged;

  void SetAcceptKeyNavFocus(bool accept);

  void SetMaximumSize(int w, int h);
  void SetMaximumWidth(int w);

  static std::string GetEscapedText(std::string const& text);

protected:
  // Key navigation
  virtual bool AcceptKeyNavFocus();

  std::vector<unsigned> GetTextureStartIndices();
  std::vector<unsigned> GetTextureEndIndices();

  // From debug::Introspectable
  std::string GetName() const;
  void AddProperties(debug::IntrospectionData&);

private:
  struct Impl;
  Impl* pimpl;
};
}

#endif // STATICCAIROTEXT_H