Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cfwl_checkboxtp.cpp
Go to the documentation of this file.
1// Copyright 2014 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "xfa/fwl/theme/cfwl_checkboxtp.h"
8
9#include <math.h>
10
11#include <iterator>
12
13#include "core/fxge/cfx_path.h"
14#include "xfa/fde/cfde_textout.h"
15#include "xfa/fgas/graphics/cfgas_gecolor.h"
16#include "xfa/fgas/graphics/cfgas_gegraphics.h"
17#include "xfa/fgas/graphics/cfgas_gepath.h"
18#include "xfa/fwl/cfwl_checkbox.h"
19#include "xfa/fwl/cfwl_themebackground.h"
20#include "xfa/fwl/cfwl_themetext.h"
21#include "xfa/fwl/cfwl_widget.h"
22
23namespace {
24
25constexpr int kSignPath = 100;
26
27CFX_PointF ScaleBezierPoint(const CFX_PointF& point) {
28 CFX_PointF scaled_point(point);
29 scaled_point.x *= FXSYS_BEZIER;
30 scaled_point.y *= FXSYS_BEZIER;
31 return scaled_point;
32}
33
34} // namespace
35
36CFWL_CheckBoxTP::CFWL_CheckBoxTP() = default;
37
38CFWL_CheckBoxTP::~CFWL_CheckBoxTP() = default;
39
40void CFWL_CheckBoxTP::DrawText(const CFWL_ThemeText& pParams) {
41 EnsureTTOInitialized(pParams.GetWidget()->GetThemeProvider());
42 m_pTextOut->SetTextColor(pParams.m_dwStates & CFWL_PartState::kDisabled
46}
47
48void CFWL_CheckBoxTP::DrawSignCheck(CFGAS_GEGraphics* pGraphics,
49 const CFX_RectF& rtSign,
50 FX_ARGB argbFill,
51 const CFX_Matrix& matrix) {
52 EnsureCheckPathInitialized(rtSign.width);
53 DCHECK(m_pCheckPath);
54
55 CFX_Matrix mt;
56 mt.Translate(rtSign.left, rtSign.top);
57 mt.Concat(matrix);
58
59 CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
60 pGraphics->SetFillColor(CFGAS_GEColor(argbFill));
61 pGraphics->FillPath(*m_pCheckPath, CFX_FillRenderOptions::FillType::kWinding,
62 mt);
63}
64
65void CFWL_CheckBoxTP::DrawSignCircle(CFGAS_GEGraphics* pGraphics,
66 const CFX_RectF& rtSign,
67 FX_ARGB argbFill,
68 const CFX_Matrix& matrix) {
69 CFGAS_GEPath path;
70 path.AddEllipse(rtSign);
71
72 CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
73 pGraphics->SetFillColor(CFGAS_GEColor(argbFill));
75}
76
77void CFWL_CheckBoxTP::DrawSignCross(CFGAS_GEGraphics* pGraphics,
78 const CFX_RectF& rtSign,
79 FX_ARGB argbFill,
80 const CFX_Matrix& matrix) {
81 CFGAS_GEPath path;
82 const float fRight = rtSign.right();
83 const float fBottom = rtSign.bottom();
84 path.AddLine(rtSign.TopLeft(), CFX_PointF(fRight, fBottom));
85 path.AddLine(CFX_PointF(rtSign.left, fBottom),
86 CFX_PointF(fRight, rtSign.top));
87
88 CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
89 pGraphics->SetStrokeColor(CFGAS_GEColor(argbFill));
90 pGraphics->SetLineWidth(1.0f);
91 pGraphics->StrokePath(path, matrix);
92}
93
94void CFWL_CheckBoxTP::DrawSignDiamond(CFGAS_GEGraphics* pGraphics,
95 const CFX_RectF& rtSign,
96 FX_ARGB argbFill,
97 const CFX_Matrix& matrix) {
98 CFGAS_GEPath path;
99 const float fWidth = rtSign.width;
100 const float fHeight = rtSign.height;
101 const float fBottom = rtSign.bottom();
102 path.MoveTo(CFX_PointF(rtSign.left + fWidth / 2, rtSign.top));
103 path.LineTo(CFX_PointF(rtSign.left, rtSign.top + fHeight / 2));
104 path.LineTo(CFX_PointF(rtSign.left + fWidth / 2, fBottom));
105 path.LineTo(CFX_PointF(rtSign.right(), rtSign.top + fHeight / 2));
106 path.LineTo(CFX_PointF(rtSign.left + fWidth / 2, rtSign.top));
107
108 CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
109 pGraphics->SetFillColor(CFGAS_GEColor(argbFill));
111}
112
113void CFWL_CheckBoxTP::DrawSignSquare(CFGAS_GEGraphics* pGraphics,
114 const CFX_RectF& rtSign,
115 FX_ARGB argbFill,
116 const CFX_Matrix& matrix) {
117 CFGAS_GEPath path;
118 path.AddRectangle(rtSign.left, rtSign.top, rtSign.width, rtSign.height);
119
120 CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
121 pGraphics->SetFillColor(CFGAS_GEColor(argbFill));
123}
124
125void CFWL_CheckBoxTP::DrawSignStar(CFGAS_GEGraphics* pGraphics,
126 const CFX_RectF& rtSign,
127 FX_ARGB argbFill,
128 const CFX_Matrix& matrix) {
129 CFGAS_GEPath path;
130 float fBottom = rtSign.bottom();
131 float fRadius = (rtSign.top - fBottom) / (1 + cosf(FXSYS_PI / 5.0f));
132 CFX_PointF ptCenter((rtSign.left + rtSign.right()) / 2.0f,
133 (rtSign.top + fBottom) / 2.0f);
134
135 CFX_PointF points[5];
136 float fAngle = FXSYS_PI / 10.0f;
137 for (auto& point : points) {
138 point =
139 ptCenter + CFX_PointF(fRadius * cosf(fAngle), fRadius * sinf(fAngle));
140 fAngle += FXSYS_PI * 2 / 5.0f;
141 }
142
143 path.MoveTo(points[0]);
144 int next = 0;
145 for (size_t i = 0; i < std::size(points); ++i) {
146 next = (next + 2) % std::size(points);
147 path.LineTo(points[next]);
148 }
149
150 CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
151 pGraphics->SetFillColor(CFGAS_GEColor(argbFill));
153}
154
155void CFWL_CheckBoxTP::EnsureCheckPathInitialized(float fCheckLen) {
156 if (m_pCheckPath)
157 return;
158
159 m_pCheckPath = std::make_unique<CFGAS_GEPath>();
160
161 float fWidth = kSignPath;
162 float fHeight = -kSignPath;
163 float fBottom = kSignPath;
164 CFX_PointF pt1(fWidth / 15.0f, fBottom + fHeight * 2 / 5.0f);
165 CFX_PointF pt2(fWidth / 4.5f, fBottom + fHeight / 16.0f);
166 CFX_PointF pt3(fWidth / 3.0f, fBottom);
167 CFX_PointF pt4(fWidth * 14 / 15.0f, fBottom + fHeight * 15 / 16.0f);
168 CFX_PointF pt5(fWidth / 3.6f, fBottom + fHeight / 3.5f);
169 CFX_PointF pt12(fWidth / 7.0f, fBottom + fHeight * 2 / 7.0f);
170 CFX_PointF pt21(fWidth / 5.0f, fBottom + fHeight / 5.0f);
171 CFX_PointF pt23(fWidth / 4.4f, fBottom + fHeight * 0 / 16.0f);
172 CFX_PointF pt32(fWidth / 4.0f, fBottom);
173 CFX_PointF pt34(fWidth * (1 / 7.0f + 7 / 15.0f),
174 fBottom + fHeight * 4 / 5.0f);
175 CFX_PointF pt43(fWidth * (1 / 7.0f + 7 / 15.0f),
176 fBottom + fHeight * 4 / 5.0f);
177 CFX_PointF pt45(fWidth * 7 / 15.0f, fBottom + fHeight * 8 / 7.0f);
178 CFX_PointF pt54(fWidth / 3.4f, fBottom + fHeight / 3.5f);
179 CFX_PointF pt51(fWidth / 3.6f, fBottom + fHeight / 4.0f);
180 CFX_PointF pt15(fWidth / 3.5f, fBottom + fHeight * 3.5f / 5.0f);
181 m_pCheckPath->MoveTo(pt1);
182
183 CFX_PointF p1 = ScaleBezierPoint(pt12 - pt1);
184 CFX_PointF p2 = ScaleBezierPoint(pt21 - pt2);
185 m_pCheckPath->BezierTo(pt1 + p1, pt2 + p2, pt2);
186
187 p1 = ScaleBezierPoint(pt23 - pt2);
188 p2 = ScaleBezierPoint(pt32 - pt3);
189 m_pCheckPath->BezierTo(pt2 + p1, pt3 + p2, pt3);
190
191 p1 = ScaleBezierPoint(pt34 - pt3);
192 p2 = ScaleBezierPoint(pt43 - pt4);
193 m_pCheckPath->BezierTo(pt3 + p1, pt4 + p2, pt4);
194
195 p1 = ScaleBezierPoint(pt45 - pt4);
196 p2 = ScaleBezierPoint(pt54 - pt5);
197 m_pCheckPath->BezierTo(pt4 + p1, pt5 + p2, pt5);
198
199 p1 = ScaleBezierPoint(pt51 - pt5);
200 p2 = ScaleBezierPoint(pt15 - pt1);
201 m_pCheckPath->BezierTo(pt5 + p1, pt1 + p2, pt1);
202
203 float fScale = fCheckLen / kSignPath;
204 CFX_Matrix mt;
205 mt.Scale(fScale, fScale);
206 m_pCheckPath->TransformBy(mt);
207}
208
209void CFWL_CheckBoxTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
211 return;
212
213 if ((pParams.m_dwStates & CFWL_PartState::kChecked) ||
214 (pParams.m_dwStates & CFWL_PartState::kNeutral)) {
215 DrawCheckSign(pParams.GetWidget(), pParams.GetGraphics(),
216 pParams.m_PartRect, pParams.m_dwStates, pParams.m_matrix);
217 }
218}
219
220void CFWL_CheckBoxTP::DrawCheckSign(CFWL_Widget* pWidget,
221 CFGAS_GEGraphics* pGraphics,
222 const CFX_RectF& pRtBox,
223 Mask<CFWL_PartState> iState,
224 const CFX_Matrix& matrix) {
225 CFX_RectF rtSign(pRtBox);
226 uint32_t dwColor =
227 iState & CFWL_PartState::kNeutral ? 0xFFA9A9A9 : 0xFF000000;
228 uint32_t dwStyle = pWidget->GetStyleExts();
229 rtSign.Deflate(rtSign.width / 4, rtSign.height / 4);
230 switch (dwStyle & FWL_STYLEEXT_CKB_SignShapeMask) {
232 DrawSignCheck(pGraphics, rtSign, dwColor, matrix);
233 break;
235 DrawSignCircle(pGraphics, rtSign, dwColor, matrix);
236 break;
238 DrawSignCross(pGraphics, rtSign, dwColor, matrix);
239 break;
241 DrawSignDiamond(pGraphics, rtSign, dwColor, matrix);
242 break;
244 DrawSignSquare(pGraphics, rtSign, dwColor, matrix);
245 break;
247 DrawSignStar(pGraphics, rtSign, dwColor, matrix);
248 break;
249 default:
250 break;
251 }
252}
#define FWL_STYLEEXT_CKB_SignShapeMask
#define FWL_STYLEEXT_CKB_SignShapeSquare
#define FWL_STYLEEXT_CKB_SignShapeCheck
#define FWL_STYLEEXT_CKB_SignShapeStar
#define FWL_STYLEEXT_CKB_SignShapeCircle
#define FWL_STYLEEXT_CKB_SignShapeDiamond
#define FWL_STYLEEXT_CKB_SignShapeCross
CFWL_PartState
#define FWLTHEME_CAPACITY_TextDisColor
Definition cfwl_utils.h:25
#define FWLTHEME_CAPACITY_TextColor
Definition cfwl_utils.h:24
CFGAS_GEColor(const FX_ARGB argb)
StateRestorer(CFGAS_GEGraphics *graphics)
void FillPath(const CFGAS_GEPath &path, CFX_FillRenderOptions::FillType fill_type, const CFX_Matrix &matrix)
void SetLineWidth(float lineWidth)
void SetStrokeColor(const CFGAS_GEColor &color)
void SetFillColor(const CFGAS_GEColor &color)
void StrokePath(const CFGAS_GEPath &path, const CFX_Matrix &matrix)
void AddLine(const CFX_PointF &p1, const CFX_PointF &p2)
void MoveTo(const CFX_PointF &point)
void AddRectangle(float left, float top, float width, float height)
void AddEllipse(const CFX_RectF &rect)
void LineTo(const CFX_PointF &point)
void DrawBackground(const CFWL_ThemeBackground &pParams) override
void DrawText(const CFWL_ThemeText &pParams) override
~CFWL_CheckBoxTP() override
CFGAS_GEGraphics * GetGraphics() const
CFWL_Widget * GetWidget() const
CFX_RectF m_PartRect
CFX_Matrix m_matrix
Part GetPart() const
void EnsureTTOInitialized(IFWL_ThemeProvider *pProvider)
virtual void DrawText(const CFWL_ThemeText &pParams)
uint32_t GetStyleExts() const
void Scale(float sx, float sy)
void Translate(float x, float y)
void Concat(const CFX_Matrix &right)
CFX_RectF(const CFX_RectF &other)=default
float bottom() const
float right() const
void Deflate(float x, float y)
#define FXSYS_BEZIER
Definition fx_system.h:44
#define FXSYS_PI
Definition fx_system.h:43