[WASAPI] fix stream types and frequencies enumeration
[xbmc.git] / xbmc / guilib / GUIFont.h
blob1a855ca78d6dd43855e99c0c76a6744dfcef6557
1 /*
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.
7 */
9 #pragma once
11 /*!
12 \file GUIFont.h
13 \brief
16 #include "utils/ColorUtils.h"
18 #include <assert.h>
19 #include <math.h>
20 #include <stdint.h>
21 #include <string>
22 #include <vector>
24 typedef uint32_t character_t;
25 typedef std::vector<character_t> vecText;
27 class CGUIFontTTF;
28 class CGraphicContext;
30 ///
31 /// \defgroup kodi_gui_font_alignment Font alignment flags
32 /// \ingroup python_xbmcgui_control_radiobutton
33 /// @{
34 /// @brief Flags for alignment
35 ///
36 /// Flags are used as bits to have several together, e.g. `XBFONT_LEFT | XBFONT_CENTER_Y`
37 ///
38 // clang-format off
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)
46 // clang-format on
47 /// @}
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;
61 class CScrollInfo
63 public:
64 CScrollInfo(unsigned int wait = 50,
65 float pos = 0,
66 int speed = defaultSpeed,
67 const std::string& scrollSuffix = " | ");
69 void SetSpeed(int speed) { m_pixelSpeed = speed * 0.001f; }
70 void Reset()
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;
77 // privates:
78 m_averageFrameTime = 1000.f / fabs((float)defaultSpeed);
79 m_lastFrameTime = 0;
80 m_textWidth = 0;
81 m_totalWidth = 0;
82 m_widthValid = false;
83 m_loopCount = 0;
85 float GetPixelsPerFrame();
87 float m_pixelPos;
88 float m_pixelSpeed;
89 unsigned int m_waitTime;
90 unsigned int m_initialWait;
91 float m_initialPos;
92 vecText m_suffix;
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;
101 private:
102 float m_averageFrameTime;
103 uint32_t m_lastFrameTime;
107 \ingroup textures
108 \brief
110 class CGUIFont
112 public:
113 CGUIFont(const std::string& strFontName,
114 uint32_t style,
115 KODI::UTILS::COLOR::Color textColor,
116 KODI::UTILS::COLOR::Color shadowColor,
117 float lineSpacing,
118 float origHeight,
119 CGUIFontTTF* font);
120 virtual ~CGUIFont();
122 std::string& GetFontName();
124 void DrawText(float x,
125 float y,
126 KODI::UTILS::COLOR::Color color,
127 KODI::UTILS::COLOR::Color shadowColor,
128 const vecText& text,
129 uint32_t alignment,
130 float maxPixelWidth)
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,
138 float y,
139 const std::vector<KODI::UTILS::COLOR::Color>& colors,
140 KODI::UTILS::COLOR::Color shadowColor,
141 const vecText& text,
142 uint32_t alignment,
143 float maxPixelWidth);
145 void DrawScrollingText(float x,
146 float y,
147 const std::vector<KODI::UTILS::COLOR::Color>& colors,
148 KODI::UTILS::COLOR::Color shadowColor,
149 const vecText& text,
150 uint32_t alignment,
151 float maxPixelWidth,
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;
165 void Begin();
166 void End();
168 uint32_t GetStyle() const { return m_style; }
170 CGUIFontTTF* GetFont() const { return m_font; }
172 void SetFont(CGUIFontTTF* font);
174 protected:
175 std::string m_strFontName;
176 uint32_t m_style;
177 KODI::UTILS::COLOR::Color m_shadowColor;
178 KODI::UTILS::COLOR::Color m_textColor;
179 float m_lineSpacing;
180 float m_origHeight;
181 CGUIFontTTF* m_font; // the font object has the size information
183 private:
184 bool ClippedRegionIsEmpty(
185 CGraphicContext& context, float x, float y, float width, uint32_t alignment) const;