2 * Copyright (C) 2003-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
16 #include "utils/ColorUtils.h"
24 typedef uint32_t character_t
;
25 typedef std::vector
<character_t
> vecText
;
28 class CGraphicContext
;
31 /// \defgroup kodi_gui_font_alignment Font alignment flags
32 /// \ingroup python_xbmcgui_control_radiobutton
34 /// @brief Flags for alignment
36 /// Flags are used as bits to have several together, e.g. `XBFONT_LEFT | XBFONT_CENTER_Y`
39 constexpr int XBFONT_LEFT
= 0; ///< Align X left
40 constexpr int XBFONT_RIGHT
= (1 << 0); ///< Align X right
41 constexpr int XBFONT_CENTER_X
= (1 << 1); ///< Align X center
42 constexpr int XBFONT_CENTER_Y
= (1 << 2); ///< Align Y center
43 constexpr int XBFONT_TRUNCATED
= (1 << 3); ///< Truncated text from right (text end with ellipses)
44 constexpr int XBFONT_JUSTIFIED
= (1 << 4); ///< Justify text
45 constexpr int XBFONT_TRUNCATED_LEFT
= (1 << 5); ///< Truncated text from left (text start with ellipses)
49 // flags for font style. lower 16 bits are the unicode code
50 // points, 16-24 are color bits and 24-32 are style bits
51 constexpr int FONT_STYLE_NORMAL
= 0;
52 constexpr int FONT_STYLE_BOLD
= (1 << 0);
53 constexpr int FONT_STYLE_ITALICS
= (1 << 1);
54 constexpr int FONT_STYLE_LIGHT
= (1 << 2);
55 constexpr int FONT_STYLE_UPPERCASE
= (1 << 3);
56 constexpr int FONT_STYLE_LOWERCASE
= (1 << 4);
57 constexpr int FONT_STYLE_CAPITALIZE
= (1 << 5);
58 constexpr int FONT_STYLE_MASK
= 0xFF;
59 constexpr int FONT_STYLES_COUNT
= 7;
64 CScrollInfo(unsigned int wait
= 50,
66 int speed
= defaultSpeed
,
67 const std::string
& scrollSuffix
= " | ");
69 void SetSpeed(int speed
) { m_pixelSpeed
= speed
* 0.001f
; }
72 m_waitTime
= m_initialWait
;
73 // pixelPos is where we start the current letter, so is measured
74 // to the left of the text rendering's left edge. Thus, a negative
75 // value will mean the text starts to the right
76 m_pixelPos
= -m_initialPos
;
78 m_averageFrameTime
= 1000.f
/ fabs((float)defaultSpeed
);
85 float GetPixelsPerFrame();
89 unsigned int m_waitTime
;
90 unsigned int m_initialWait
;
93 mutable float m_textWidth
;
94 mutable float m_totalWidth
;
95 mutable bool m_widthValid
;
97 unsigned int m_loopCount
;
99 static const int defaultSpeed
= 60;
102 float m_averageFrameTime
;
103 uint32_t m_lastFrameTime
;
113 CGUIFont(const std::string
& strFontName
,
115 KODI::UTILS::COLOR::Color textColor
,
116 KODI::UTILS::COLOR::Color shadowColor
,
122 std::string
& GetFontName();
124 void DrawText(float x
,
126 KODI::UTILS::COLOR::Color color
,
127 KODI::UTILS::COLOR::Color shadowColor
,
132 std::vector
<KODI::UTILS::COLOR::Color
> colors
;
133 colors
.push_back(color
);
134 DrawText(x
, y
, colors
, shadowColor
, text
, alignment
, maxPixelWidth
);
137 void DrawText(float x
,
139 const std::vector
<KODI::UTILS::COLOR::Color
>& colors
,
140 KODI::UTILS::COLOR::Color shadowColor
,
143 float maxPixelWidth
);
145 void DrawScrollingText(float x
,
147 const std::vector
<KODI::UTILS::COLOR::Color
>& colors
,
148 KODI::UTILS::COLOR::Color shadowColor
,
152 const CScrollInfo
& scrollInfo
);
154 bool UpdateScrollInfo(const vecText
& text
, CScrollInfo
& scrollInfo
);
156 float GetTextWidth(const vecText
& text
);
157 float GetCharWidth(character_t ch
);
158 float GetTextHeight(int numLines
) const;
159 float GetTextBaseLine() const;
160 float GetLineHeight() const;
162 //! get font scale factor (rendered height / original height)
163 float GetScaleFactor() const;
168 uint32_t GetStyle() const { return m_style
; }
170 CGUIFontTTF
* GetFont() const { return m_font
; }
172 void SetFont(CGUIFontTTF
* font
);
175 std::string m_strFontName
;
177 KODI::UTILS::COLOR::Color m_shadowColor
;
178 KODI::UTILS::COLOR::Color m_textColor
;
181 CGUIFontTTF
* m_font
; // the font object has the size information
184 bool ClippedRegionIsEmpty(
185 CGraphicContext
& context
, float x
, float y
, float width
, uint32_t alignment
) const;