GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — meos/code/animationdata.cpp at master · croister/meos

Expand file tree

/

animationdata.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
228 lines (193 loc) · 6.19 KB
/

animationdata.cpp

Copy path

File metadata and controls

228 lines (193 loc) · 6.19 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/************************************************************************
MeOS - Orienteering Software
Copyright (C) 2009-2026 Melin Software HB
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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/>.
Melin Software HB - [email protected] - www.melin.nu
Eksoppsvägen 16, SE-75646 UPPSALA, Sweden
************************************************************************/
#include "StdAfx.h"
#include "animationdata.h"
#include "meos_util.h"
#include "Printer.h"
AnimationData::AnimationData(gdioutput &gdi, int timePerPage, int nCol,
int marginPercent, bool animate, bool respectPageBreak) :
nCol(nCol), animate(animate), page(-1), gdiRef(0) {
lastTime = 0;
nextTime = 0;
timeOut = timePerPage;
doAnimation = true;
PageInfo pageInfo;
errorState = false;
gdi.getTargetDimension(width, height);
margin = (width * marginPercent) / 100;
double w = (gdi.getWidth() + 20) *nCol + margin;
double s = width / w;
if ((fabs(s - 1.0) > 1e-3)) {
gdi.scaleSize(s, true, gdioutput::ScaleOperation::NoRefresh);
}
pageInfo.topMargin = 20;
pageInfo.scaleX = 1.0f;
pageInfo.scaleY = 1.0f;
pageInfo.leftMargin = 20;
pageInfo.bottomMargin = 30;
pageInfo.pageY = float(height-margin);
pageInfo.printHeader = false;
pageInfo.yMM2PrintC = pageInfo.xMM2PrintC = 1;
pageInfo.xMM2PrintK = 0;
pageInfo.yMM2PrintK = 0;
list<RectangleInfo> rectangles;
pageInfo.renderPages(gdi.getTL(), rectangles, false, respectPageBreak, pages);
}
AnimationData::~AnimationData() {
if (animationThread && animationThread->joinable()) {
animationThread->join();
animationThread.reset();
}
if (gdiRef) {
gdiRef->removeHandler(this);
}
}
bool AnimationData::takeOver(const shared_ptr<AnimationData> &other) {
delayedTakeOver = other;
return true;
}
void AnimationData::takeOverInternal(const shared_ptr<AnimationData> &other) {
pages.swap(other->pages);
width = other->width;
height = other->height;
nCol = other->nCol;
margin = other->margin;
animate = other->animate;
}
void AnimationData::renderPage(HDC hDC, gdioutput &gdi, uint64_t time) {
bool addTextAnimation = false;
if (doAnimation) {
if (page == -1)
page = 0;
else
page++;
addTextAnimation = true;
nextTime = time + timeOut;
lastTime = time;
gdiRef = &gdi;
gdi.addTimeoutMilli(timeOut, "AnimationData", 0).setHandler(this);
doAnimation = false;
}
if (animationThread && animationThread->joinable()) {
if (!addTextAnimation)
return; // Ignore repaint
if (animationThread) {
animationThread->join();
animationThread.reset();
}
}
if (delayedTakeOver && addTextAnimation) {
takeOverInternal(delayedTakeOver);
delayedTakeOver.reset();
}
size_t sp = nCol * page;
if (sp >= pages.size()) {
sp = 0;
page = 0;
}
int count = 1;
for (size_t i = sp; i < sp + nCol && i < pages.size(); i++) {
int currentRow = 0;
for (auto &text : pages[i].text) {
if (text.ti.yp != currentRow) {
currentRow = text.ti.yp;
count++;
}
}
}
int atime = 400;
if (count < 30)
atime = 800;
else if (count < 50)
atime = 500;
int delay = addTextAnimation && animate ? atime / count : 0;
if (delay == 0 || errorState == true) {
doRender(hDC, gdi, sp, delay);
errorState = false;
}
else {
animationThread = make_shared<std::thread>(&AnimationData::threadRender, this, &gdi, sp, delay);
}
}
void AnimationData::threadRender(gdioutput *gdi, size_t sp, int delay) {
HWND hWnd = gdi->getHWNDTarget();
HDC hDC = GetDC(hWnd);
int x, y;
gdi->getTargetDimension(x, y);
RECT rc;
rc.left = 0;
rc.right = x;
rc.top = 0;
rc.bottom = y;
gdi->drawBackground(hDC, rc);
try {
doRender(hDC, *gdi, sp, delay);
}
catch (...) {
errorState = true;
}
ReleaseDC(hWnd, hDC);
// End thread and notify that it has ended
}
void AnimationData::doRender(HDC hDC, gdioutput &gdi, size_t sp, int delay) {
for (size_t i = sp; i < sp + nCol && i < pages.size(); i++) {
renderSubPage(hDC, gdi, pages[i], margin / 2 + ((i - sp) * width) / nCol, 0, delay);
if (i + 1 < sp + nCol) {
int x = margin / 2 + ((i + 1 - sp) * width) / nCol - 10;
SelectObject(hDC, GetStockObject(DC_BRUSH));
HLS fg, bg;
fg.RGBtoHLS(gdi.getFGColor());
bg.RGBtoHLS(gdi.getBGColor());
if (bg.lightness > fg.lightness)
fg.lighten(1.3);
else
fg.lighten(1.0 / 1.3);
SetDCBrushColor(hDC, fg.HLStoRGB());
Rectangle(hDC, x - 1, 20, x + 1, height - 20);
}
}
}
void AnimationData::renderSubPage(HDC hDC, gdioutput &gdi, RenderedPage &page, int x, int y, int animateDelay) {
int ox = gdi.getOffsetX();
int oy = gdi.getOffsetY();
int top = 10000;
for (const auto &text : page.text) {
if (!text.ti.isFormatInfo()) {
top = min<int>(top, text.ti.yp);
}
}
gdi.setOffsetY(-y+top-margin/2);
gdi.setOffsetX(-x);
int currentRow = 0;
for (auto &text : page.text) {
if (animateDelay>0 && text.ti.yp != currentRow) {
Sleep(animateDelay);
currentRow = text.ti.yp;
}
gdi.RenderString(text.ti, hDC);
}
gdi.setOffsetY(ox);
gdi.setOffsetX(oy);
}
void AnimationData::handle(gdioutput &gdi, BaseInfo &info, GuiEventType type) {
if (pages.size() > size_t(nCol) || delayedTakeOver) {
doAnimation = true;
gdi.refreshFast();
}
gdiRef = &gdi;
gdi.addTimeoutMilli(timeOut, "AnimationData", 0).setHandler(this);
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.