forked from rime/weasel
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathFullScreenLayout.cpp
More file actions
118 lines (107 loc) · 4.06 KB
/
FullScreenLayout.cpp
File metadata and controls
118 lines (107 loc) · 4.06 KB
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
#include "stdafx.h"
#include "FullScreenLayout.h"
using namespace weasel;
void weasel::FullScreenLayout::DoLayout(CDCHandle dc) {
if (_context.empty()) {
int width = 0, height = 0;
UpdateStatusIconLayout(&width, &height);
_contentSize.SetSize(width, height);
return;
}
CRect workArea;
HMONITOR hMonitor = MonitorFromRect(mr_inputPos, MONITOR_DEFAULTTONEAREST);
if (hMonitor) {
MONITORINFO info;
info.cbSize = sizeof(MONITORINFO);
if (GetMonitorInfo(hMonitor, &info)) {
workArea = info.rcWork;
}
}
int step = 32;
do {
m_layout->DoLayout(dc);
} while (AdjustFontPoint(dc, workArea, step));
mark_height = m_layout->mark_height;
mark_width = m_layout->mark_width;
mark_gap = m_layout->mark_gap;
int offsetx = (workArea.Width() - m_layout->GetContentSize().cx) / 2;
int offsety = (workArea.Height() - m_layout->GetContentSize().cy) / 2;
_preeditRect = m_layout->GetPreeditRect();
_preeditRect.OffsetRect(offsetx, offsety);
_auxiliaryRect = m_layout->GetAuxiliaryRect();
_auxiliaryRect.OffsetRect(offsetx, offsety);
_highlightRect = m_layout->GetHighlightRect();
_highlightRect.OffsetRect(offsetx, offsety);
_prePageRect = m_layout->GetPrepageRect();
_prePageRect.OffsetRect(offsetx, offsety);
_nextPageRect = m_layout->GetNextpageRect();
_nextPageRect.OffsetRect(offsetx, offsety);
_range = m_layout->GetPreeditRange();
_beforesz = m_layout->GetBeforeSize();
_hilitedsz = m_layout->GetHilitedSize();
_aftersz = m_layout->GetAfterSize();
for (auto i = 0, n = (int)_context.cinfo.candies.size();
i < n && i < MAX_CANDIDATES_COUNT; ++i) {
_candidateLabelRects[i] = m_layout->GetCandidateLabelRect(i);
_candidateLabelRects[i].OffsetRect(offsetx, offsety);
_candidateTextRects[i] = m_layout->GetCandidateTextRect(i);
_candidateTextRects[i].OffsetRect(offsetx, offsety);
_candidateCommentRects[i] = m_layout->GetCandidateCommentRect(i);
_candidateCommentRects[i].OffsetRect(offsetx, offsety);
_candidateRects[i] = m_layout->GetCandidateRect(i);
_candidateRects[i].OffsetRect(offsetx, offsety);
}
_statusIconRect = m_layout->GetStatusIconRect();
_contentSize.SetSize(workArea.Width(), workArea.Height());
_contentRect.SetRect(0, 0, workArea.Width(), workArea.Height());
_contentRect.DeflateRect(offsetX, offsetY);
}
bool FullScreenLayout::AdjustFontPoint(CDCHandle dc,
const CRect& workArea,
int& step) {
if (_context.empty() || step == 0)
return false;
{
int fontPointLabel;
int fontPoint;
int fontPointComment;
if (pDWR_->pLabelTextFormat != NULL)
fontPointLabel = (int)(pDWR_->pLabelTextFormat->GetFontSize() /
pDWR_->dpiScaleFontPoint);
else
fontPointLabel = 0;
if (pDWR_->pTextFormat != NULL)
fontPoint =
(int)(pDWR_->pTextFormat->GetFontSize() / pDWR_->dpiScaleFontPoint);
else
fontPoint = 0;
if (pDWR_->pCommentTextFormat != NULL)
fontPointComment = (int)(pDWR_->pCommentTextFormat->GetFontSize() /
pDWR_->dpiScaleFontPoint);
else
fontPointComment = 0;
CSize sz = m_layout->GetContentSize();
if (sz.cx > workArea.Width() - offsetX * 2 ||
sz.cy > workArea.Height() - offsetY * 2) {
if (step > 0) {
step = -(step >> 1);
}
fontPoint += step;
fontPointLabel += step;
fontPointComment += step;
pDWR_->InitResources(_style, fontPointLabel, fontPoint, fontPointComment);
return true;
} else if (sz.cx <= (workArea.Width() - offsetX * 2) * 31 / 32 &&
sz.cy <= (workArea.Height() - offsetY * 2) * 31 / 32) {
if (step < 0) {
step = -step >> 1;
}
fontPoint += step;
fontPointLabel += step;
fontPointComment += step;
pDWR_->InitResources(_style, fontPointLabel, fontPoint, fontPointComment);
return true;
}
return false;
}
}