446 |
andreas |
1 |
/*
|
|
|
2 |
* Copyright (C) 2022, 2023 by Andreas Theofilu <andreas@theosys.at>
|
|
|
3 |
*
|
|
|
4 |
* This program is free software; you can redistribute it and/or modify
|
|
|
5 |
* it under the terms of the GNU General Public License as published by
|
|
|
6 |
* the Free Software Foundation; either version 3 of the License, or
|
|
|
7 |
* (at your option) any later version.
|
|
|
8 |
*
|
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
* GNU General Public License for more details.
|
|
|
13 |
*
|
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
|
15 |
* along with this program; if not, write to the Free Software Foundation,
|
|
|
16 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
#include <string>
|
|
|
20 |
|
|
|
21 |
#include <include/core/SkFont.h>
|
|
|
22 |
#include <include/core/SkFontMetrics.h>
|
|
|
23 |
#include <include/core/SkTextBlob.h>
|
|
|
24 |
#include <include/core/SkRegion.h>
|
|
|
25 |
#include <include/core/SkImageFilter.h>
|
|
|
26 |
#include <include/effects/SkImageFilters.h>
|
|
|
27 |
|
|
|
28 |
#include "tpageinterface.h"
|
|
|
29 |
#include "tsystemsound.h"
|
|
|
30 |
#include "ttpinit.h"
|
|
|
31 |
#include "tconfig.h"
|
|
|
32 |
#include "tresources.h"
|
|
|
33 |
#include "tpagemanager.h"
|
|
|
34 |
#include "tintborder.h"
|
|
|
35 |
#include "terror.h"
|
|
|
36 |
|
|
|
37 |
#if __cplusplus < 201402L
|
|
|
38 |
# error "This module requires at least C++14 standard!"
|
|
|
39 |
#else
|
|
|
40 |
# if __cplusplus < 201703L
|
|
|
41 |
# include <experimental/filesystem>
|
|
|
42 |
namespace fs = std::experimental::filesystem;
|
|
|
43 |
# warning "Support for C++14 and experimental filesystem will be removed in a future version!"
|
|
|
44 |
# else
|
|
|
45 |
# include <filesystem>
|
|
|
46 |
# ifdef __ANDROID__
|
|
|
47 |
namespace fs = std::__fs::filesystem;
|
|
|
48 |
# else
|
|
|
49 |
namespace fs = std::filesystem;
|
|
|
50 |
# endif
|
|
|
51 |
# endif
|
|
|
52 |
#endif
|
|
|
53 |
|
|
|
54 |
using std::string;
|
|
|
55 |
using std::vector;
|
|
|
56 |
|
|
|
57 |
bool TPageInterface::drawText(PAGE_T& pinfo, SkBitmap *img)
|
|
|
58 |
{
|
|
|
59 |
MSG_TRACE("TPageInterface::drawText(PAGE_T& pinfo, SkImage& img)");
|
|
|
60 |
|
|
|
61 |
if (pinfo.sr.empty() || pinfo.sr[0].te.empty())
|
|
|
62 |
return true;
|
|
|
63 |
|
|
|
64 |
MSG_DEBUG("Searching for font number " << pinfo.sr[0].fi << " with text " << pinfo.sr[0].te);
|
|
|
65 |
FONT_T font = mFonts->getFont(pinfo.sr[0].fi);
|
|
|
66 |
|
|
|
67 |
if (font.file.empty())
|
|
|
68 |
{
|
|
|
69 |
MSG_WARNING("No font file name found for font " << pinfo.sr[0].fi);
|
|
|
70 |
return false;
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
SkCanvas canvas(*img, SkSurfaceProps(1, kUnknown_SkPixelGeometry));
|
|
|
74 |
sk_sp<SkTypeface> typeFace = mFonts->getTypeFace(pinfo.sr[0].fi);
|
|
|
75 |
|
|
|
76 |
if (!typeFace)
|
|
|
77 |
{
|
|
|
78 |
MSG_ERROR("Error creating type face " << font.fullName);
|
|
|
79 |
TError::setError();
|
|
|
80 |
return false;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
SkScalar fontSizePt = ((SkScalar)font.size * 1.322); // Calculate points from pixels (close up)
|
|
|
84 |
SkFont skFont(typeFace, fontSizePt); // Skia require the font size in points
|
|
|
85 |
|
|
|
86 |
SkPaint paint;
|
|
|
87 |
paint.setAntiAlias(true);
|
|
|
88 |
SkColor color = TColor::getSkiaColor(pinfo.sr[0].ct);
|
|
|
89 |
paint.setColor(color);
|
|
|
90 |
paint.setStyle(SkPaint::kFill_Style);
|
|
|
91 |
|
|
|
92 |
SkFontMetrics metrics;
|
|
|
93 |
skFont.getMetrics(&metrics);
|
|
|
94 |
int lines = numberLines(pinfo.sr[0].te);
|
|
|
95 |
|
|
|
96 |
if (lines > 1 || pinfo.sr[0].ww)
|
|
|
97 |
{
|
|
|
98 |
vector<string> textLines;
|
|
|
99 |
|
|
|
100 |
if (!pinfo.sr[0].ww)
|
|
|
101 |
textLines = splitLine(pinfo.sr[0].te);
|
|
|
102 |
else
|
|
|
103 |
{
|
|
|
104 |
textLines = splitLine(pinfo.sr[0].te, pinfo.width, pinfo.height, skFont, paint);
|
|
|
105 |
lines = (int)textLines.size();
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
MSG_DEBUG("Calculated number of lines: " << textLines.size());
|
|
|
109 |
int lineHeight = calcLineHeight(pinfo.sr[0].te, skFont);
|
|
|
110 |
int totalHeight = lineHeight * lines;
|
|
|
111 |
|
|
|
112 |
if (totalHeight > pinfo.height)
|
|
|
113 |
{
|
|
|
114 |
lines = pinfo.height / lineHeight;
|
|
|
115 |
totalHeight = lineHeight * lines;
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
MSG_DEBUG("Line height: " << lineHeight << ", total height: " << totalHeight);
|
|
|
119 |
Button::POSITION_t position = calcImagePosition(&pinfo, pinfo.width, totalHeight, Button::SC_TEXT, 0);
|
|
|
120 |
MSG_DEBUG("Position frame: l: " << position.left << ", t: " << position.top << ", w: " << position.width << ", h: " << position.height);
|
|
|
121 |
|
|
|
122 |
if (!position.valid)
|
|
|
123 |
{
|
|
|
124 |
MSG_ERROR("Error calculating the text position!");
|
|
|
125 |
TError::setError();
|
|
|
126 |
return false;
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
vector<string>::iterator iter;
|
|
|
130 |
int line = 0;
|
|
|
131 |
|
|
|
132 |
for (iter = textLines.begin(); iter != textLines.end(); iter++)
|
|
|
133 |
{
|
|
|
134 |
sk_sp<SkTextBlob> blob = SkTextBlob::MakeFromString(iter->c_str(), skFont);
|
|
|
135 |
SkRect rect;
|
|
|
136 |
skFont.measureText(iter->c_str(), iter->length(), SkTextEncoding::kUTF8, &rect, &paint);
|
|
|
137 |
Button::POSITION_t pos = calcImagePosition(&pinfo, rect.width(), lineHeight, Button::SC_TEXT, 1);
|
|
|
138 |
|
|
|
139 |
if (!pos.valid)
|
|
|
140 |
{
|
|
|
141 |
MSG_ERROR("Error calculating the text position!");
|
|
|
142 |
TError::setError();
|
|
|
143 |
return false;
|
|
|
144 |
}
|
|
|
145 |
MSG_DEBUG("Triing to print line: " << *iter);
|
|
|
146 |
|
|
|
147 |
SkScalar startX = (SkScalar)pos.left;
|
|
|
148 |
SkScalar startY = (SkScalar)position.top + lineHeight * line;
|
|
|
149 |
MSG_DEBUG("x=" << startX << ", y=" << startY);
|
|
|
150 |
canvas.drawTextBlob(blob, startX, startY + lineHeight / 2 + 4, paint);
|
|
|
151 |
line++;
|
|
|
152 |
|
|
|
153 |
if (line > lines)
|
|
|
154 |
break;
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
else // single line
|
|
|
158 |
{
|
|
|
159 |
sk_sp<SkTextBlob> blob = SkTextBlob::MakeFromString(pinfo.sr[0].te.c_str(), skFont);
|
|
|
160 |
SkRect rect;
|
|
|
161 |
skFont.measureText(pinfo.sr[0].te.c_str(), pinfo.sr[0].te.length(), SkTextEncoding::kUTF8, &rect, &paint);
|
|
|
162 |
Button::POSITION_t position = calcImagePosition(&pinfo, rect.width(), (rect.height() * (float)lines), Button::SC_TEXT, 0);
|
|
|
163 |
|
|
|
164 |
if (!position.valid)
|
|
|
165 |
{
|
|
|
166 |
MSG_ERROR("Error calculating the text position!");
|
|
|
167 |
TError::setError();
|
|
|
168 |
return false;
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
MSG_DEBUG("Printing line " << pinfo.sr[0].te);
|
|
|
172 |
SkScalar startX = (SkScalar)position.left;
|
|
|
173 |
SkScalar startY = (SkScalar)position.top + metrics.fCapHeight; // + metrics.fLeading; // (metrics.fAscent * -1.0);
|
|
|
174 |
canvas.drawTextBlob(blob, startX, startY, paint);
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
return true;
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
bool TPageInterface::drawFrame(PAGE_T& pinfo, SkBitmap* bm)
|
|
|
181 |
{
|
|
|
182 |
DECL_TRACER("TPageInterface::drawFrame(PAGE_T& pinfo, SkBitmap* bm)");
|
|
|
183 |
|
|
|
184 |
int instance = 0;
|
|
|
185 |
|
|
|
186 |
if (pinfo.sr[instance].bs.empty())
|
|
|
187 |
{
|
|
|
188 |
MSG_DEBUG("No border defined.");
|
|
|
189 |
return false;
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
// First we look into our internal border table
|
|
|
193 |
Border::TIntBorder *intBorder = new Border::TIntBorder;
|
|
|
194 |
|
|
|
195 |
if (intBorder && intBorder->drawBorder(bm, pinfo.sr[instance].bs, pinfo.width, pinfo.height, pinfo.sr[instance].cb))
|
|
|
196 |
{
|
|
|
197 |
delete intBorder;
|
|
|
198 |
return true;
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
if (intBorder)
|
|
|
202 |
{
|
|
|
203 |
delete intBorder;
|
|
|
204 |
intBorder = nullptr;
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
// Try to find the border in the system table
|
|
|
208 |
BORDER_t bd;
|
|
|
209 |
bool classExist = (gPageManager && gPageManager->getSystemDraw());
|
|
|
210 |
|
|
|
211 |
if (!classExist)
|
|
|
212 |
return false;
|
|
|
213 |
|
|
|
214 |
string borderName = pinfo.sr[0].bs;
|
|
|
215 |
|
|
|
216 |
if (!gPageManager->getSystemDraw()->getBorder(borderName, TSystemDraw::LT_OFF, &bd, borderName))
|
|
|
217 |
return false;
|
|
|
218 |
|
|
|
219 |
MSG_DEBUG("System border \"" << borderName << "\" found.");
|
|
|
220 |
SkColor color = TColor::getSkiaColor(pinfo.sr[instance].cb); // border color
|
|
|
221 |
MSG_DEBUG("Button color: #" << std::setw(6) << std::setfill('0') << std::hex << color << std::dec);
|
|
|
222 |
// Load images
|
|
|
223 |
SkBitmap imgB, imgBR, imgR, imgTR, imgT, imgTL, imgL, imgBL;
|
|
|
224 |
|
|
|
225 |
if (!getBorderFragment(bd.b, bd.b_alpha, &imgB, color))
|
|
|
226 |
return false;
|
|
|
227 |
|
|
|
228 |
MSG_DEBUG("Got images \"" << bd.b << "\" and \"" << bd.b_alpha << "\" with size " << imgB.info().width() << " x " << imgB.info().height());
|
|
|
229 |
if (!getBorderFragment(bd.br, bd.br_alpha, &imgBR, color))
|
|
|
230 |
return false;
|
|
|
231 |
|
|
|
232 |
MSG_DEBUG("Got images \"" << bd.br << "\" and \"" << bd.br_alpha << "\" with size " << imgBR.info().width() << " x " << imgBR.info().height());
|
|
|
233 |
if (!getBorderFragment(bd.r, bd.r_alpha, &imgR, color))
|
|
|
234 |
return false;
|
|
|
235 |
|
|
|
236 |
MSG_DEBUG("Got images \"" << bd.r << "\" and \"" << bd.r_alpha << "\" with size " << imgR.info().width() << " x " << imgR.info().height());
|
|
|
237 |
if (!getBorderFragment(bd.tr, bd.tr_alpha, &imgTR, color))
|
|
|
238 |
return false;
|
|
|
239 |
|
|
|
240 |
MSG_DEBUG("Got images \"" << bd.tr << "\" and \"" << bd.tr_alpha << "\" with size " << imgTR.info().width() << " x " << imgTR.info().height());
|
|
|
241 |
if (getBorderFragment(bd.t, bd.t_alpha, &imgT, color))
|
|
|
242 |
return false;
|
|
|
243 |
|
|
|
244 |
MSG_DEBUG("Got images \"" << bd.t << "\" and \"" << bd.t_alpha << "\" with size " << imgT.info().width() << " x " << imgT.info().height());
|
|
|
245 |
if (!getBorderFragment(bd.tl, bd.tl_alpha, &imgTL, color))
|
|
|
246 |
return false;
|
|
|
247 |
|
|
|
248 |
MSG_DEBUG("Got images \"" << bd.tl << "\" and \"" << bd.tl_alpha << "\" with size " << imgTL.info().width() << " x " << imgTL.info().height());
|
|
|
249 |
if (!getBorderFragment(bd.l, bd.l_alpha, &imgL, color))
|
|
|
250 |
return false;
|
|
|
251 |
|
|
|
252 |
MSG_DEBUG("Got images \"" << bd.l << "\" and \"" << bd.l_alpha << "\" with size " << imgL.info().width() << " x " << imgL.info().height());
|
|
|
253 |
if (!getBorderFragment(bd.bl, bd.bl_alpha, &imgBL, color))
|
|
|
254 |
return false;
|
|
|
255 |
|
|
|
256 |
MSG_DEBUG("Got images \"" << bd.bl << "\" and \"" << bd.bl_alpha << "\" with size " << imgBL.info().width() << " x " << imgBL.info().height());
|
|
|
257 |
MSG_DEBUG("Button image size: " << (imgTL.info().width() + imgT.info().width() + imgTR.info().width()) << " x " << (imgTL.info().height() + imgL.info().height() + imgBL.info().height()));
|
|
|
258 |
MSG_DEBUG("Total size: " << pinfo.width << " x " << pinfo.height);
|
|
|
259 |
stretchImageWidth(&imgB, pinfo.width - imgBL.info().width() - imgBR.info().width());
|
|
|
260 |
stretchImageWidth(&imgT, pinfo.width - imgTL.info().width() - imgTR.info().width());
|
|
|
261 |
stretchImageHeight(&imgL, pinfo.height - imgTL.info().height() - imgBL.info().height());
|
|
|
262 |
stretchImageHeight(&imgR, pinfo.height - imgTR.info().height() - imgBR.info().height());
|
|
|
263 |
MSG_DEBUG("Stretched button image size: " << (imgTL.info().width() + imgT.info().width() + imgTR.info().width()) << " x " << (imgTL.info().height() + imgL.info().height() + imgBL.info().height()));
|
|
|
264 |
// Draw the frame
|
|
|
265 |
SkBitmap frame;
|
|
|
266 |
allocPixels(bm->info().width(), bm->info().height(), &frame);
|
|
|
267 |
frame.eraseColor(SK_ColorTRANSPARENT);
|
|
|
268 |
SkCanvas target(*bm, SkSurfaceProps());
|
|
|
269 |
SkCanvas canvas(frame, SkSurfaceProps());
|
|
|
270 |
SkPaint paint;
|
|
|
271 |
|
|
|
272 |
paint.setBlendMode(SkBlendMode::kSrcOver);
|
|
|
273 |
paint.setAntiAlias(true);
|
|
|
274 |
sk_sp<SkImage> _image = SkImages::RasterFromBitmap(imgB); // bottom
|
|
|
275 |
canvas.drawImage(_image, imgBL.info().width(), pinfo.height - imgB.info().height(), SkSamplingOptions(), &paint);
|
|
|
276 |
_image = SkImages::RasterFromBitmap(imgT); // top
|
|
|
277 |
canvas.drawImage(_image, imgTL.info().width(), 0, SkSamplingOptions(), &paint);
|
|
|
278 |
_image = SkImages::RasterFromBitmap(imgBR); // bottom right
|
|
|
279 |
canvas.drawImage(_image, pinfo.width - imgBR.info().width(), pinfo.height - imgBR.info().height(), SkSamplingOptions(), &paint);
|
|
|
280 |
_image = SkImages::RasterFromBitmap(imgTR); // top right
|
|
|
281 |
canvas.drawImage(_image, pinfo.width - imgTR.info().width(), 0, SkSamplingOptions(), &paint);
|
|
|
282 |
_image = SkImages::RasterFromBitmap(imgTL); // top left
|
|
|
283 |
canvas.drawImage(_image, 0, 0, SkSamplingOptions(), &paint);
|
|
|
284 |
_image = SkImages::RasterFromBitmap(imgBL); // bottom left
|
|
|
285 |
canvas.drawImage(_image, 0, pinfo.height - imgBL.info().height(), SkSamplingOptions(), &paint);
|
|
|
286 |
_image = SkImages::RasterFromBitmap(imgL); // left
|
|
|
287 |
canvas.drawImage(_image, 0, imgTL.info().height(), SkSamplingOptions(), &paint);
|
|
|
288 |
_image = SkImages::RasterFromBitmap(imgR); // right
|
|
|
289 |
canvas.drawImage(_image, pinfo.width - imgR.info().width(), imgTR.info().height(), SkSamplingOptions(), &paint);
|
|
|
290 |
|
|
|
291 |
Border::TIntBorder iborder;
|
|
|
292 |
iborder.erasePart(bm, frame, Border::ERASE_OUTSIDE, imgL.info().width());
|
|
|
293 |
_image = SkImages::RasterFromBitmap(frame);
|
|
|
294 |
paint.setBlendMode(SkBlendMode::kSrcATop);
|
|
|
295 |
target.drawImage(_image, 0, 0, SkSamplingOptions(), &paint);
|
|
|
296 |
return true;
|
|
|
297 |
}
|
|
|
298 |
|
|
|
299 |
Button::POSITION_t TPageInterface::calcImagePosition(PAGE_T *page, int width, int height, Button::CENTER_CODE cc, int line)
|
|
|
300 |
{
|
|
|
301 |
DECL_TRACER("TPageInterface::calcImagePosition(PAGE_T *page, int with, int height, CENTER_CODE code, int number)");
|
|
|
302 |
|
|
|
303 |
if (!page)
|
|
|
304 |
return Button::POSITION_t();
|
|
|
305 |
|
|
|
306 |
Button::SR_T act_sr;
|
|
|
307 |
Button::POSITION_t position;
|
|
|
308 |
int ix, iy;
|
|
|
309 |
|
|
|
310 |
if (page->sr.size() == 0)
|
|
|
311 |
{
|
|
|
312 |
if (sr.size() == 0)
|
|
|
313 |
return position;
|
|
|
314 |
|
|
|
315 |
act_sr = sr.at(0);
|
|
|
316 |
}
|
|
|
317 |
else
|
|
|
318 |
act_sr = page->sr.at(0);
|
|
|
319 |
|
|
|
320 |
// int border_size = getBorderSize(act_sr.bs);
|
|
|
321 |
int border_size = 0;
|
|
|
322 |
int code, border = border_size;
|
|
|
323 |
string dbgCC;
|
|
|
324 |
int rwt = 0, rht = 0;
|
|
|
325 |
|
|
|
326 |
switch (cc)
|
|
|
327 |
{
|
|
|
328 |
case Button::SC_ICON:
|
|
|
329 |
code = act_sr.ji;
|
|
|
330 |
ix = act_sr.ix;
|
|
|
331 |
iy = act_sr.iy;
|
|
|
332 |
border = border_size = 0;
|
|
|
333 |
dbgCC = "ICON";
|
|
|
334 |
rwt = width;
|
|
|
335 |
rht = height;
|
|
|
336 |
break;
|
|
|
337 |
|
|
|
338 |
case Button::SC_BITMAP:
|
|
|
339 |
code = act_sr.jb;
|
|
|
340 |
ix = act_sr.bx;
|
|
|
341 |
iy = act_sr.by;
|
|
|
342 |
dbgCC = "BITMAP";
|
|
|
343 |
rwt = std::min(page->width - border * 2, width);
|
|
|
344 |
rht = std::min(page->height - border_size * 2, height);
|
|
|
345 |
break;
|
|
|
346 |
|
|
|
347 |
case Button::SC_TEXT:
|
|
|
348 |
code = act_sr.jt;
|
|
|
349 |
ix = act_sr.tx;
|
|
|
350 |
iy = act_sr.ty;
|
|
|
351 |
dbgCC = "TEXT";
|
|
|
352 |
border += 4;
|
|
|
353 |
rwt = std::min(page->width - border * 2, width);
|
|
|
354 |
rht = std::min(page->height - border_size * 2, height);
|
|
|
355 |
break;
|
|
|
356 |
}
|
|
|
357 |
|
|
|
358 |
if (width > rwt || height > rht)
|
|
|
359 |
position.overflow = true;
|
|
|
360 |
|
|
|
361 |
switch (code)
|
|
|
362 |
{
|
|
|
363 |
case 0: // absolute position
|
|
|
364 |
position.left = ix;
|
|
|
365 |
|
|
|
366 |
if (cc == Button::SC_TEXT && line > 0)
|
|
|
367 |
position.top = iy + height * line;
|
|
|
368 |
else
|
|
|
369 |
position.top = iy;
|
|
|
370 |
|
|
|
371 |
if (cc == Button::SC_BITMAP && ix < 0 && rwt < width)
|
|
|
372 |
position.left *= -1;
|
|
|
373 |
|
|
|
374 |
if (cc == Button::SC_BITMAP && iy < 0 && rht < height)
|
|
|
375 |
position.top += -1;
|
|
|
376 |
|
|
|
377 |
position.width = rwt;
|
|
|
378 |
position.height = rht;
|
|
|
379 |
break;
|
|
|
380 |
|
|
|
381 |
case 1: // top, left
|
|
|
382 |
if (cc == Button::SC_TEXT)
|
|
|
383 |
{
|
|
|
384 |
position.left = border;
|
|
|
385 |
|
|
|
386 |
if (line > 0)
|
|
|
387 |
position.top = height * line;
|
|
|
388 |
else
|
|
|
389 |
position.top = border;
|
|
|
390 |
}
|
|
|
391 |
|
|
|
392 |
position.width = rwt;
|
|
|
393 |
position.height = rht;
|
|
|
394 |
break;
|
|
|
395 |
|
|
|
396 |
case 2: // center, top
|
|
|
397 |
if (cc == Button::SC_TEXT)
|
|
|
398 |
{
|
|
|
399 |
if (line > 0)
|
|
|
400 |
position.top = height * line;
|
|
|
401 |
else
|
|
|
402 |
position.top = border;
|
|
|
403 |
}
|
|
|
404 |
|
|
|
405 |
position.left = (page->width - rwt) / 2;
|
|
|
406 |
position.height = rht;
|
|
|
407 |
position.width = rwt;
|
|
|
408 |
break;
|
|
|
409 |
|
|
|
410 |
case 3: // right, top
|
|
|
411 |
position.left = page->width - rwt;
|
|
|
412 |
|
|
|
413 |
if (cc == Button::SC_TEXT)
|
|
|
414 |
{
|
|
|
415 |
position.left = (((position.left - border) < 0) ? 0 : position.left - border);
|
|
|
416 |
|
|
|
417 |
if (line > 0)
|
|
|
418 |
position.top = height * line;
|
|
|
419 |
else
|
|
|
420 |
position.top = border;
|
|
|
421 |
}
|
|
|
422 |
|
|
|
423 |
position.width = rwt;
|
|
|
424 |
position.height = rht;
|
|
|
425 |
break;
|
|
|
426 |
|
|
|
427 |
case 4: // left, middle
|
|
|
428 |
if (cc == Button::SC_TEXT)
|
|
|
429 |
{
|
|
|
430 |
position.left = border;
|
|
|
431 |
|
|
|
432 |
if (line > 0)
|
|
|
433 |
position.top = ((page->height - rht) / 2) + (height / 2 * line);
|
|
|
434 |
else
|
|
|
435 |
position.top = (page->height - rht) / 2;
|
|
|
436 |
}
|
|
|
437 |
else
|
|
|
438 |
position.top = (page->height - rht) / 2;
|
|
|
439 |
|
|
|
440 |
position.width = rwt;
|
|
|
441 |
position.height = rht;
|
|
|
442 |
break;
|
|
|
443 |
|
|
|
444 |
case 6: // right, middle
|
|
|
445 |
position.left = page->width - rwt;
|
|
|
446 |
|
|
|
447 |
if (cc == Button::SC_TEXT)
|
|
|
448 |
{
|
|
|
449 |
position.left = (((position.left - border) < 0) ? 0 : position.left - border);
|
|
|
450 |
|
|
|
451 |
if (line > 0)
|
|
|
452 |
position.top = ((page->height - rht) / 2) + (height / 2 * line);
|
|
|
453 |
else
|
|
|
454 |
position.top = (page->height - rht) / 2;
|
|
|
455 |
}
|
|
|
456 |
else
|
|
|
457 |
position.top = (page->height - rht) / 2;
|
|
|
458 |
|
|
|
459 |
position.width = rwt;
|
|
|
460 |
position.height = rht;
|
|
|
461 |
break;
|
|
|
462 |
|
|
|
463 |
case 7: // left, bottom
|
|
|
464 |
if (cc == Button::SC_TEXT)
|
|
|
465 |
{
|
|
|
466 |
position.left = border_size;
|
|
|
467 |
|
|
|
468 |
if (line > 0)
|
|
|
469 |
position.top = (page->height - rht) - height * line;
|
|
|
470 |
else
|
|
|
471 |
position.top = page->height - rht;
|
|
|
472 |
}
|
|
|
473 |
else
|
|
|
474 |
position.top = page->height - rht;
|
|
|
475 |
|
|
|
476 |
position.width = rwt;
|
|
|
477 |
position.height = rht;
|
|
|
478 |
break;
|
|
|
479 |
|
|
|
480 |
case 8: // center, bottom
|
|
|
481 |
position.left = (page->width - rwt) / 2;
|
|
|
482 |
|
|
|
483 |
if (cc == Button::SC_TEXT)
|
|
|
484 |
{
|
|
|
485 |
if (line > 0)
|
|
|
486 |
position.top = (page->height - rht) - height * line;
|
|
|
487 |
else
|
|
|
488 |
position.top = page->height - rht;
|
|
|
489 |
}
|
|
|
490 |
else
|
|
|
491 |
position.top = page->height - rht;
|
|
|
492 |
|
|
|
493 |
position.width = rwt;
|
|
|
494 |
position.height = rht;
|
|
|
495 |
break;
|
|
|
496 |
|
|
|
497 |
case 9: // right, bottom
|
|
|
498 |
position.left = page->width - rwt;
|
|
|
499 |
|
|
|
500 |
if (cc == Button::SC_TEXT)
|
|
|
501 |
{
|
|
|
502 |
position.left = (((position.left - border) < 0) ? 0 : position.left - border);
|
|
|
503 |
|
|
|
504 |
if (line > 0)
|
|
|
505 |
position.top = (page->height - rht) - height * line;
|
|
|
506 |
else
|
|
|
507 |
position.top = page->height - rht;
|
|
|
508 |
}
|
|
|
509 |
else
|
|
|
510 |
position.top = page->height - rht;
|
|
|
511 |
break;
|
|
|
512 |
|
|
|
513 |
default: // center, middle
|
|
|
514 |
position.left = (page->width - rwt) / 2;
|
|
|
515 |
|
|
|
516 |
if (cc == Button::SC_TEXT)
|
|
|
517 |
{
|
|
|
518 |
if (line > 0)
|
|
|
519 |
position.top = ((page->height - rht) / 2) + (height / 2 * line);
|
|
|
520 |
else
|
|
|
521 |
position.top = (page->height - rht) / 2;
|
|
|
522 |
}
|
|
|
523 |
else
|
|
|
524 |
position.top = (page->height - rht) / 2;
|
|
|
525 |
|
|
|
526 |
position.width = rwt;
|
|
|
527 |
position.height = rht;
|
|
|
528 |
}
|
|
|
529 |
|
|
|
530 |
MSG_DEBUG("Type: " << dbgCC << ", PosType=" << code << ", Position: x=" << position.left << ", y=" << position.top << ", w=" << position.width << ", h=" << position.height << ", Overflow: " << (position.overflow ? "YES" : "NO"));
|
|
|
531 |
position.valid = true;
|
|
|
532 |
return position;
|
|
|
533 |
}
|
|
|
534 |
|
|
|
535 |
int TPageInterface::calcLineHeight(const string& text, SkFont& font)
|
|
|
536 |
{
|
|
|
537 |
DECL_TRACER("TPageInterface::calcLineHeight(const string& text, SkFont& font)");
|
|
|
538 |
|
|
|
539 |
sk_sp<SkTextBlob> blob = SkTextBlob::MakeFromString(text.c_str(), font);
|
|
|
540 |
SkRect rect = blob.get()->bounds();
|
|
|
541 |
return rect.height();
|
|
|
542 |
}
|
|
|
543 |
|
|
|
544 |
int TPageInterface::numberLines(const string& str)
|
|
|
545 |
{
|
|
|
546 |
DECL_TRACER("TPageInterface::numberLines(const string& str)");
|
|
|
547 |
|
|
|
548 |
int lines = 1;
|
|
|
549 |
|
|
|
550 |
for (size_t i = 0; i < str.length(); i++)
|
|
|
551 |
{
|
|
|
552 |
if (str.at(i) == '\n')
|
|
|
553 |
lines++;
|
|
|
554 |
}
|
|
|
555 |
|
|
|
556 |
MSG_DEBUG("Detected " << lines << " lines.");
|
|
|
557 |
return lines;
|
|
|
558 |
}
|
|
|
559 |
|
|
|
560 |
Button::BUTTONS_T *TPageInterface::addButton(Button::TButton* button)
|
|
|
561 |
{
|
|
|
562 |
DECL_TRACER("*TPageInterface::addButton(TButton* button)");
|
|
|
563 |
|
|
|
564 |
if (!button)
|
|
|
565 |
{
|
|
|
566 |
MSG_ERROR("Parameter is NULL!");
|
|
|
567 |
TError::setError();
|
|
|
568 |
return nullptr;
|
|
|
569 |
}
|
|
|
570 |
|
|
|
571 |
// We try to add this button to the list of system buttons which will
|
|
|
572 |
// succeed only if it is one of the supported system buttons.
|
|
|
573 |
addSysButton(button);
|
|
|
574 |
|
|
|
575 |
try
|
|
|
576 |
{
|
|
|
577 |
Button::BUTTONS_T *chain = new Button::BUTTONS_T;
|
|
|
578 |
chain->button = button;
|
|
|
579 |
chain->next = nullptr;
|
|
|
580 |
chain->previous = nullptr;
|
|
|
581 |
Button::BUTTONS_T *bts = mButtons;
|
|
|
582 |
|
|
|
583 |
if (bts)
|
|
|
584 |
{
|
|
|
585 |
Button::BUTTONS_T *p = bts;
|
|
|
586 |
|
|
|
587 |
while (p && p->next)
|
|
|
588 |
p = p->next;
|
|
|
589 |
|
|
|
590 |
p->next = chain;
|
|
|
591 |
chain->previous = p;
|
|
|
592 |
}
|
|
|
593 |
else
|
|
|
594 |
mButtons = chain;
|
|
|
595 |
|
|
|
596 |
return chain;
|
|
|
597 |
}
|
|
|
598 |
catch (std::exception& e)
|
|
|
599 |
{
|
|
|
600 |
MSG_ERROR("Memory error: " << e.what());
|
|
|
601 |
TError::setError();
|
|
|
602 |
}
|
|
|
603 |
|
|
|
604 |
return nullptr;
|
|
|
605 |
}
|
|
|
606 |
|
|
|
607 |
bool TPageInterface::hasButton(int id)
|
|
|
608 |
{
|
|
|
609 |
DECL_TRACER("TPageInterface::hasButton(int id)");
|
|
|
610 |
|
|
|
611 |
Button::BUTTONS_T *bt = mButtons;
|
|
|
612 |
|
|
|
613 |
while (bt)
|
|
|
614 |
{
|
|
|
615 |
if (bt->button && bt->button->getButtonIndex() == id)
|
|
|
616 |
return true;
|
|
|
617 |
|
|
|
618 |
bt = bt->next;
|
|
|
619 |
}
|
|
|
620 |
|
|
|
621 |
return false;
|
|
|
622 |
}
|
|
|
623 |
|
|
|
624 |
Button::TButton *TPageInterface::getButton(int id)
|
|
|
625 |
{
|
|
|
626 |
DECL_TRACER("TPageInterface::getButton(int id)");
|
|
|
627 |
|
|
|
628 |
Button::BUTTONS_T *bt = mButtons;
|
|
|
629 |
|
|
|
630 |
while (bt)
|
|
|
631 |
{
|
|
|
632 |
if (bt->button && bt->button->getButtonIndex() == id)
|
|
|
633 |
return bt->button;
|
|
|
634 |
|
|
|
635 |
bt = bt->next;
|
|
|
636 |
}
|
|
|
637 |
|
|
|
638 |
return nullptr;
|
|
|
639 |
}
|
|
|
640 |
|
|
|
641 |
vector<Button::TButton *> TPageInterface::getButtons(int ap, int ad)
|
|
|
642 |
{
|
|
|
643 |
DECL_TRACER("TPageInterface::getButtons(int ap, int ad)");
|
|
|
644 |
|
|
|
645 |
vector<Button::TButton *> list;
|
|
|
646 |
Button::BUTTONS_T *bt = mButtons;
|
|
|
647 |
|
|
|
648 |
while (bt)
|
|
|
649 |
{
|
|
|
650 |
if (bt->button->getAddressPort() == ap && bt->button->getAddressChannel() == ad)
|
|
|
651 |
list.push_back(bt->button);
|
|
|
652 |
|
|
|
653 |
bt = bt->next;
|
|
|
654 |
}
|
|
|
655 |
|
|
|
656 |
return list;
|
|
|
657 |
}
|
|
|
658 |
|
|
|
659 |
vector<Button::TButton *> TPageInterface::getAllButtons()
|
|
|
660 |
{
|
|
|
661 |
DECL_TRACER("TPageInterface::getAllButtons()");
|
|
|
662 |
|
|
|
663 |
vector<Button::TButton *> list;
|
|
|
664 |
Button::BUTTONS_T *bt = mButtons;
|
|
|
665 |
|
|
|
666 |
while(bt)
|
|
|
667 |
{
|
|
|
668 |
list.push_back(bt->button);
|
|
|
669 |
bt = bt->next;
|
|
|
670 |
}
|
|
|
671 |
|
|
|
672 |
return list;
|
|
|
673 |
}
|
|
|
674 |
|
|
|
675 |
Button::TButton *TPageInterface::getFirstButton()
|
|
|
676 |
{
|
|
|
677 |
DECL_TRACER("TPageInterface::getFirstButton()");
|
|
|
678 |
|
|
|
679 |
mLastButton = 0;
|
|
|
680 |
|
|
|
681 |
if (mButtons)
|
|
|
682 |
return mButtons->button;
|
|
|
683 |
|
|
|
684 |
return nullptr;
|
|
|
685 |
}
|
|
|
686 |
|
|
|
687 |
Button::TButton *TPageInterface::getNextButton()
|
|
|
688 |
{
|
|
|
689 |
DECL_TRACER("TPageInterface::getNextButton()");
|
|
|
690 |
|
|
|
691 |
Button::BUTTONS_T *but = mButtons;
|
|
|
692 |
int count = 0;
|
|
|
693 |
mLastButton++;
|
|
|
694 |
|
|
|
695 |
while (but)
|
|
|
696 |
{
|
|
|
697 |
if (but->button && count == mLastButton)
|
|
|
698 |
return but->button;
|
|
|
699 |
|
|
|
700 |
but = but->next;
|
|
|
701 |
count++;
|
|
|
702 |
}
|
|
|
703 |
|
|
|
704 |
return nullptr;
|
|
|
705 |
}
|
|
|
706 |
|
|
|
707 |
Button::TButton *TPageInterface::getLastButton()
|
|
|
708 |
{
|
|
|
709 |
DECL_TRACER("TPageInterface::getLastButton()");
|
|
|
710 |
|
|
|
711 |
Button::BUTTONS_T *but = mButtons;
|
|
|
712 |
mLastButton = 0;
|
|
|
713 |
|
|
|
714 |
while (but && but->next)
|
|
|
715 |
{
|
|
|
716 |
mLastButton++;
|
|
|
717 |
but = but->next;
|
|
|
718 |
}
|
|
|
719 |
|
|
|
720 |
if (!but)
|
|
|
721 |
return nullptr;
|
|
|
722 |
|
|
|
723 |
return but->button;
|
|
|
724 |
}
|
|
|
725 |
|
|
|
726 |
Button::TButton *TPageInterface::getPreviousButton()
|
|
|
727 |
{
|
|
|
728 |
DECL_TRACER("TPageInterface::getPreviousButton()");
|
|
|
729 |
|
|
|
730 |
Button::BUTTONS_T *but = mButtons;
|
|
|
731 |
int count = 0;
|
|
|
732 |
|
|
|
733 |
if (mLastButton)
|
|
|
734 |
mLastButton--;
|
|
|
735 |
else
|
|
|
736 |
return nullptr;
|
|
|
737 |
|
|
|
738 |
while (but)
|
|
|
739 |
{
|
|
|
740 |
if (but->button && count == mLastButton)
|
|
|
741 |
return but->button;
|
|
|
742 |
|
|
|
743 |
but = but->next;
|
|
|
744 |
count++;
|
|
|
745 |
}
|
|
|
746 |
|
|
|
747 |
return nullptr;
|
|
|
748 |
}
|
|
|
749 |
|
|
|
750 |
/*
|
|
|
751 |
* Sort the button according to their Z-order.
|
|
|
752 |
* The button with the highest Z-order will be the last button in the chain.
|
|
|
753 |
* The algorithm is a bubble sort algorithm.
|
|
|
754 |
*/
|
|
|
755 |
bool TPageInterface::sortButtons()
|
|
|
756 |
{
|
|
|
757 |
DECL_TRACER("TPageInterface::sortButtons()");
|
|
|
758 |
|
|
|
759 |
bool turned = true;
|
|
|
760 |
|
|
|
761 |
while (turned)
|
|
|
762 |
{
|
|
|
763 |
Button::BUTTONS_T *button = mButtons;
|
|
|
764 |
turned = false;
|
|
|
765 |
|
|
|
766 |
while (button)
|
|
|
767 |
{
|
|
|
768 |
int zo = button->button->getZOrder();
|
|
|
769 |
|
|
|
770 |
if (button->previous)
|
|
|
771 |
{
|
|
|
772 |
if (zo < button->previous->button->getZOrder())
|
|
|
773 |
{
|
|
|
774 |
Button::BUTTONS_T *pprev = button->previous->previous;
|
|
|
775 |
Button::BUTTONS_T *prev = button->previous;
|
|
|
776 |
Button::BUTTONS_T *next = button->next;
|
|
|
777 |
|
|
|
778 |
if (pprev)
|
|
|
779 |
pprev->next = button;
|
|
|
780 |
|
|
|
781 |
prev->next = next;
|
|
|
782 |
prev->previous = button;
|
|
|
783 |
button->next = prev;
|
|
|
784 |
button->previous = pprev;
|
|
|
785 |
|
|
|
786 |
if (!pprev)
|
|
|
787 |
setButtons(button);
|
|
|
788 |
|
|
|
789 |
button = next;
|
|
|
790 |
|
|
|
791 |
if (next)
|
|
|
792 |
next->previous = prev;
|
|
|
793 |
|
|
|
794 |
turned = true;
|
|
|
795 |
continue;
|
|
|
796 |
}
|
|
|
797 |
}
|
|
|
798 |
|
|
|
799 |
button = button->next;
|
|
|
800 |
}
|
|
|
801 |
}
|
|
|
802 |
|
|
|
803 |
return true;
|
|
|
804 |
}
|
|
|
805 |
|
|
|
806 |
void TPageInterface::setFonts(TFont *font)
|
|
|
807 |
{
|
|
|
808 |
DECL_TRACER("TPageInterface::setFonts(TFont *font)");
|
|
|
809 |
|
|
|
810 |
if (!font)
|
|
|
811 |
return;
|
|
|
812 |
|
|
|
813 |
mFonts = font;
|
|
|
814 |
|
|
|
815 |
Button::BUTTONS_T *button = mButtons;
|
|
|
816 |
|
|
|
817 |
while (button)
|
|
|
818 |
{
|
|
|
819 |
button->button->setFonts(font);
|
|
|
820 |
button = button->next;
|
|
|
821 |
}
|
|
|
822 |
}
|
|
|
823 |
|
|
|
824 |
vector<string> TPageInterface::getListContent(ulong handle, int ap, int ta, int ti, int rows, int columns)
|
|
|
825 |
{
|
|
|
826 |
DECL_TRACER("TPageInterface::getListContent(ulong handle, int ap, int ta, int ti, int rows, int columns)");
|
|
|
827 |
|
|
|
828 |
if (ap == 0 && ta == 0 && ti == 0)
|
|
|
829 |
{
|
|
|
830 |
vector<LIST_t>::iterator iter;
|
|
|
831 |
|
|
|
832 |
for (iter = mLists.begin(); iter != mLists.end(); ++iter)
|
|
|
833 |
{
|
|
|
834 |
if (iter->handle == handle)
|
|
|
835 |
{
|
|
|
836 |
return iter->list;
|
|
|
837 |
}
|
|
|
838 |
}
|
|
|
839 |
|
|
|
840 |
return vector<string>();
|
|
|
841 |
}
|
|
|
842 |
|
|
|
843 |
if (ap == 0 && (ta == SYSTEM_LIST_SYSTEMSOUND || ta == SYSTEM_LIST_SINGLEBEEP)) // System listbox: system sounds and system single beeps
|
|
|
844 |
{
|
|
|
845 |
vector<LIST_t>::iterator iter;
|
|
|
846 |
|
|
|
847 |
for (iter = mLists.begin(); iter != mLists.end(); ++iter)
|
|
|
848 |
{
|
|
|
849 |
if (iter->handle == handle)
|
|
|
850 |
{
|
|
|
851 |
iter->ap = ap;
|
|
|
852 |
iter->ta = ta;
|
|
|
853 |
iter->ti = ti;
|
|
|
854 |
iter->rows = rows;
|
|
|
855 |
iter->columns = columns;
|
|
|
856 |
|
|
|
857 |
if (iter->selected < 0 && !iter->list.empty())
|
|
|
858 |
{
|
|
|
859 |
int row = getSystemSelection(ta, iter->list);
|
|
|
860 |
|
|
|
861 |
if (row > 0)
|
|
|
862 |
iter->selected = row;
|
|
|
863 |
}
|
|
|
864 |
|
|
|
865 |
return iter->list;
|
|
|
866 |
}
|
|
|
867 |
}
|
|
|
868 |
|
|
|
869 |
TSystemSound sysSound(TConfig::getSystemProjectPath() + "/graphics/sounds");
|
|
|
870 |
vector<string> tmpFiles = sysSound.getAllSingleBeep();
|
|
|
871 |
LIST_t list;
|
|
|
872 |
list.handle = handle;
|
|
|
873 |
list.ap = ap;
|
|
|
874 |
list.ta = ta;
|
|
|
875 |
list.ti = ti;
|
|
|
876 |
list.rows = rows;
|
|
|
877 |
list.columns = columns;
|
|
|
878 |
list.list = tmpFiles;
|
|
|
879 |
list.selected = getSystemSelection(ta, tmpFiles);
|
|
|
880 |
mLists.push_back(list);
|
|
|
881 |
return tmpFiles;
|
|
|
882 |
}
|
|
|
883 |
else if (ap == 0 && ta == SYSTEM_LIST_DOUBLEBEEP) // System listbox: double beeps
|
|
|
884 |
{
|
|
|
885 |
vector<LIST_t>::iterator iter;
|
|
|
886 |
|
|
|
887 |
for (iter = mLists.begin(); iter != mLists.end(); ++iter)
|
|
|
888 |
{
|
|
|
889 |
if (iter->handle == handle)
|
|
|
890 |
{
|
|
|
891 |
iter->ap = ap;
|
|
|
892 |
iter->ta = ta;
|
|
|
893 |
iter->ti = ti;
|
|
|
894 |
iter->rows = rows;
|
|
|
895 |
iter->columns = columns;
|
|
|
896 |
|
|
|
897 |
if (iter->selected < 0 && !iter->list.empty())
|
|
|
898 |
{
|
|
|
899 |
int row = getSystemSelection(ta, iter->list);
|
|
|
900 |
|
|
|
901 |
if (row > 0)
|
|
|
902 |
iter->selected = row;
|
|
|
903 |
}
|
|
|
904 |
|
|
|
905 |
return iter->list;
|
|
|
906 |
}
|
|
|
907 |
}
|
|
|
908 |
|
|
|
909 |
TSystemSound sysSound(TConfig::getSystemProjectPath() + "/graphics/sounds");
|
|
|
910 |
vector<string> tmpFiles = sysSound.getAllDoubleBeep();
|
|
|
911 |
LIST_t list;
|
|
|
912 |
list.handle = handle;
|
|
|
913 |
list.ap = ap;
|
|
|
914 |
list.ta = ta;
|
|
|
915 |
list.ti = ti;
|
|
|
916 |
list.rows = rows;
|
|
|
917 |
list.columns = columns;
|
|
|
918 |
list.list = tmpFiles;
|
|
|
919 |
list.selected = getSystemSelection(ta, tmpFiles);
|
|
|
920 |
mLists.push_back(list);
|
|
|
921 |
return tmpFiles;
|
|
|
922 |
}
|
|
|
923 |
else if (ap == 0 && ta == SYSTEM_LIST_SURFACE) // System listbox: TP4 file (surface file)
|
|
|
924 |
{
|
|
|
925 |
vector<LIST_t>::iterator iter;
|
|
|
926 |
|
|
|
927 |
for (iter = mLists.begin(); iter != mLists.end(); ++iter)
|
|
|
928 |
{
|
|
|
929 |
if (iter->handle == handle)
|
|
|
930 |
{
|
|
|
931 |
iter->ap = ap;
|
|
|
932 |
iter->ta = ta;
|
|
|
933 |
iter->ti = ti;
|
|
|
934 |
iter->rows = rows;
|
|
|
935 |
iter->columns = columns;
|
|
|
936 |
|
|
|
937 |
if (iter->selected < 0 && !iter->list.empty())
|
|
|
938 |
{
|
|
|
939 |
int row = getSystemSelection(ta, iter->list);
|
|
|
940 |
|
|
|
941 |
if (row > 0)
|
|
|
942 |
iter->selected = row;
|
|
|
943 |
}
|
|
|
944 |
|
|
|
945 |
return iter->list;
|
|
|
946 |
}
|
|
|
947 |
}
|
|
|
948 |
|
|
|
949 |
// Load surface file names from NetLinx over FTP
|
|
|
950 |
TTPInit tt;
|
|
|
951 |
vector<TTPInit::FILELIST_t> fileList = tt.getFileList(".tp4");
|
|
|
952 |
vector<string> tmpFiles;
|
|
|
953 |
|
|
|
954 |
if (!fileList.empty())
|
|
|
955 |
{
|
|
|
956 |
vector<TTPInit::FILELIST_t>::iterator iter;
|
|
|
957 |
|
|
|
958 |
if (gPageManager)
|
|
|
959 |
gPageManager->clearFtpSurface();
|
|
|
960 |
|
|
|
961 |
for (iter = fileList.begin(); iter != fileList.end(); ++iter)
|
|
|
962 |
{
|
|
|
963 |
tmpFiles.push_back(iter->fname);
|
|
|
964 |
|
|
|
965 |
if (gPageManager)
|
|
|
966 |
gPageManager->addFtpSurface(iter->fname, iter->size);
|
|
|
967 |
}
|
|
|
968 |
}
|
|
|
969 |
|
|
|
970 |
LIST_t list;
|
|
|
971 |
list.handle = handle;
|
|
|
972 |
list.ap = ap;
|
|
|
973 |
list.ta = ta;
|
|
|
974 |
list.ti = ti;
|
|
|
975 |
list.rows = rows;
|
|
|
976 |
list.columns = columns;
|
|
|
977 |
list.list = tmpFiles;
|
|
|
978 |
list.selected = getSystemSelection(ta, tmpFiles);
|
|
|
979 |
mLists.push_back(list);
|
|
|
980 |
return tmpFiles;
|
|
|
981 |
}
|
|
|
982 |
|
|
|
983 |
return vector<string>();
|
|
|
984 |
}
|
|
|
985 |
|
|
|
986 |
int TPageInterface::getSystemSelection(int ta, vector<string>& list)
|
|
|
987 |
{
|
|
|
988 |
DECL_TRACER("TPageInterface::setSystemSelection(int ta, vector<string>* list)");
|
|
|
989 |
|
|
|
990 |
vector<string>::iterator iterSel;
|
|
|
991 |
string sel;
|
|
|
992 |
|
|
|
993 |
if (ta == SYSTEM_LIST_SURFACE)
|
|
|
994 |
sel = TConfig::getFtpSurface();
|
|
|
995 |
if (ta == SYSTEM_LIST_SYSTEMSOUND)
|
|
|
996 |
sel = TConfig::getSystemSound();
|
|
|
997 |
else if (ta == SYSTEM_LIST_SINGLEBEEP)
|
|
|
998 |
sel = TConfig::getSingleBeepSound();
|
|
|
999 |
else if (ta == SYSTEM_LIST_DOUBLEBEEP)
|
|
|
1000 |
sel = TConfig::getDoubleBeepSound();
|
|
|
1001 |
else
|
|
|
1002 |
return -1;
|
|
|
1003 |
|
|
|
1004 |
int row = 1;
|
|
|
1005 |
|
|
|
1006 |
for (iterSel = list.begin(); iterSel != list.end(); ++iterSel)
|
|
|
1007 |
{
|
|
|
1008 |
if (iterSel->compare(sel) == 0)
|
|
|
1009 |
return row;
|
|
|
1010 |
|
|
|
1011 |
row++;
|
|
|
1012 |
}
|
|
|
1013 |
|
|
|
1014 |
return -1;
|
|
|
1015 |
}
|
|
|
1016 |
|
|
|
1017 |
string TPageInterface::getListRow(int ti, int row)
|
|
|
1018 |
{
|
|
|
1019 |
DECL_TRACER("TPageInterface::getListRow(ulong handle, int ti, int row)");
|
|
|
1020 |
|
|
|
1021 |
vector<LIST_t>::iterator iter;
|
|
|
1022 |
|
|
|
1023 |
for (iter = mLists.begin(); iter != mLists.end(); ++iter)
|
|
|
1024 |
{
|
|
|
1025 |
if (iter->ti == ti)
|
|
|
1026 |
{
|
|
|
1027 |
if (row < 1 || (size_t)row > iter->list.size())
|
|
|
1028 |
return string();
|
|
|
1029 |
|
|
|
1030 |
return iter->list[row-1];
|
|
|
1031 |
}
|
|
|
1032 |
}
|
|
|
1033 |
|
|
|
1034 |
return string();
|
|
|
1035 |
}
|
|
|
1036 |
|
|
|
1037 |
void TPageInterface::setGlobalSettings(Button::TButton* button)
|
|
|
1038 |
{
|
|
|
1039 |
DECL_TRACER("TPageInterface::setGlobalSettings(TButton* button)");
|
|
|
1040 |
|
|
|
1041 |
if (!button)
|
|
|
1042 |
return;
|
|
|
1043 |
|
|
|
1044 |
button->setFontOnly(sr[0].fi, 0);
|
|
|
1045 |
button->setTextColorOnly(sr[0].ct, 0);
|
|
|
1046 |
button->setTextEffectColorOnly(sr[0].ec, 0);
|
|
|
1047 |
|
|
|
1048 |
if (button->getListAp() == 0 && button->getListTi() >= SYSTEM_PAGE_START)
|
|
|
1049 |
button->setTextJustificationOnly(4, 0, 0, 0);
|
|
|
1050 |
}
|
|
|
1051 |
|
|
|
1052 |
void TPageInterface::setSelectedRow(ulong handle, int row)
|
|
|
1053 |
{
|
|
|
1054 |
DECL_TRACER("TPageInterface::setSelectedRow(ulong handle, int row)");
|
|
|
1055 |
|
|
|
1056 |
if (row < 1)
|
|
|
1057 |
return;
|
|
|
1058 |
|
|
|
1059 |
vector<LIST_t>::iterator iter;
|
|
|
1060 |
|
|
|
1061 |
for (iter = mLists.begin(); iter != mLists.end(); ++iter)
|
|
|
1062 |
{
|
|
|
1063 |
if (iter->handle == handle)
|
|
|
1064 |
{
|
|
|
1065 |
if ((size_t)row <= iter->list.size())
|
|
|
1066 |
iter->selected = row;
|
|
|
1067 |
|
|
|
1068 |
MSG_DEBUG("Row was set to " << row << " for item " << handleToString(handle));
|
|
|
1069 |
return;
|
|
|
1070 |
}
|
|
|
1071 |
}
|
|
|
1072 |
}
|
|
|
1073 |
|
|
|
1074 |
int TPageInterface::getSelectedRow(ulong handle)
|
|
|
1075 |
{
|
|
|
1076 |
DECL_TRACER("TPageInterface::getSelectedRow(ulong handle)");
|
|
|
1077 |
|
|
|
1078 |
vector<LIST_t>::iterator iter;
|
|
|
1079 |
|
|
|
1080 |
for (iter = mLists.begin(); iter != mLists.end(); ++iter)
|
|
|
1081 |
{
|
|
|
1082 |
if (iter->handle == handle)
|
|
|
1083 |
return iter->selected;
|
|
|
1084 |
}
|
|
|
1085 |
|
|
|
1086 |
return -1;
|
|
|
1087 |
}
|
|
|
1088 |
|
|
|
1089 |
string TPageInterface::getSelectedItem(ulong handle)
|
|
|
1090 |
{
|
|
|
1091 |
DECL_TRACER("TPageInterface::getSelectedItem(ulong handle)");
|
|
|
1092 |
|
|
|
1093 |
vector<LIST_t>::iterator iter;
|
|
|
1094 |
|
|
|
1095 |
for (iter = mLists.begin(); iter != mLists.end(); ++iter)
|
|
|
1096 |
{
|
|
|
1097 |
if (iter->handle == handle)
|
|
|
1098 |
{
|
|
|
1099 |
if (iter->selected > 0 && (size_t)iter->selected <= iter->list.size())
|
|
|
1100 |
return iter->list[iter->selected-1];
|
|
|
1101 |
|
|
|
1102 |
ulong nPage = (handle >> 16) & 0x0000ffff;
|
|
|
1103 |
ulong nButt = handle & 0x0000ffff;
|
|
|
1104 |
string sel;
|
|
|
1105 |
|
|
|
1106 |
if (nPage == SYSTEM_SUBPAGE_SURFACE && nButt == 1)
|
|
|
1107 |
sel = TConfig::getFtpSurface();
|
|
|
1108 |
if (nPage == SYSTEM_SUBPAGE_SYSTEMSOUND && nButt == 1)
|
|
|
1109 |
sel = TConfig::getSystemSound();
|
|
|
1110 |
else if (nPage == SYSTEM_SUBPAGE_SINGLEBEEP && nButt == 1)
|
|
|
1111 |
sel = TConfig::getSingleBeepSound();
|
|
|
1112 |
else if (nPage == SYSTEM_SUBPAGE_DOUBLEBEEP && nButt == 1)
|
|
|
1113 |
sel = TConfig::getDoubleBeepSound();
|
|
|
1114 |
else
|
|
|
1115 |
return string();
|
|
|
1116 |
|
|
|
1117 |
if (iter->list.empty())
|
|
|
1118 |
return string();
|
|
|
1119 |
|
|
|
1120 |
vector<string>::iterator iterSel;
|
|
|
1121 |
int row = 1;
|
|
|
1122 |
|
|
|
1123 |
for (iterSel = iter->list.begin(); iterSel != iter->list.end(); ++iterSel)
|
|
|
1124 |
{
|
|
|
1125 |
if (iterSel->compare(sel) == 0)
|
|
|
1126 |
{
|
|
|
1127 |
iter->selected = row;
|
|
|
1128 |
return sel;
|
|
|
1129 |
}
|
|
|
1130 |
|
|
|
1131 |
row++;
|
|
|
1132 |
}
|
|
|
1133 |
}
|
|
|
1134 |
}
|
|
|
1135 |
|
|
|
1136 |
return string();
|
|
|
1137 |
}
|
|
|
1138 |
|
|
|
1139 |
/**
|
|
|
1140 |
* @brief getBorderFragment - get part of border
|
|
|
1141 |
* The method reads a border image fragment from the disk and converts it to
|
|
|
1142 |
* the border color. If there is a base image and an alpha mask image, the
|
|
|
1143 |
* pixels of the alpha mask are converted to the border color and then the base
|
|
|
1144 |
* image is layed over the mask image.
|
|
|
1145 |
* In case there is no base image, an image with the same size as the mask image
|
|
|
1146 |
* is created and filled transparaent.
|
|
|
1147 |
*
|
|
|
1148 |
* @param path The path and file name of the base image.
|
|
|
1149 |
* @param pathAlpha The path and file name of the alpha mask image.
|
|
|
1150 |
* @param image A pointer to an empty bitmap.
|
|
|
1151 |
* @param color The border color
|
|
|
1152 |
*
|
|
|
1153 |
* @return In case the images exists and were loaded successfully, TRUE is
|
|
|
1154 |
* returned.
|
|
|
1155 |
*/
|
|
|
1156 |
bool TPageInterface::getBorderFragment(const string& path, const string& pathAlpha, SkBitmap* image, SkColor color)
|
|
|
1157 |
{
|
|
|
1158 |
DECL_TRACER("TPageInterface::getBorderFragment(const string& path, const string& pathAlpha, SkBitmap* image, SkColor color)");
|
|
|
1159 |
|
|
|
1160 |
if (!image)
|
|
|
1161 |
{
|
|
|
1162 |
MSG_ERROR("Invalid pointer to image!");
|
|
|
1163 |
return false;
|
|
|
1164 |
}
|
|
|
1165 |
|
|
|
1166 |
sk_sp<SkData> im;
|
|
|
1167 |
SkBitmap bm;
|
|
|
1168 |
bool haveBaseImage = false;
|
|
|
1169 |
|
|
|
1170 |
// If the path ends with "alpha.png" then it is a mask image. This not what
|
|
|
1171 |
// we want first unless this is the only image available.
|
|
|
1172 |
if (!endsWith(path, "alpha.png") || pathAlpha.empty())
|
|
|
1173 |
{
|
|
|
1174 |
if (!path.empty() && retrieveImage(path, image))
|
|
|
1175 |
{
|
|
|
1176 |
haveBaseImage = true;
|
|
|
1177 |
// Underly the pixels with the border color
|
|
|
1178 |
if (pathAlpha.empty() || !fs::exists(pathAlpha) || path == pathAlpha)
|
|
|
1179 |
{
|
|
|
1180 |
SkImageInfo info = image->info();
|
|
|
1181 |
SkBitmap b;
|
|
|
1182 |
allocPixels(info.width(), info.height(), &b);
|
|
|
1183 |
b.eraseColor(SK_ColorTRANSPARENT);
|
|
|
1184 |
|
|
|
1185 |
for (int x = 0; x < info.width(); ++x)
|
|
|
1186 |
{
|
|
|
1187 |
for (int y = 0; y < info.height(); ++y)
|
|
|
1188 |
{
|
|
|
1189 |
SkColor alpha = SkColorGetA(image->getColor(x, y));
|
|
|
1190 |
uint32_t *pix = b.getAddr32(x, y);
|
|
|
1191 |
|
|
|
1192 |
if (alpha > 0)
|
|
|
1193 |
*pix = color;
|
|
|
1194 |
}
|
|
|
1195 |
}
|
|
|
1196 |
|
|
|
1197 |
SkPaint paint;
|
|
|
1198 |
paint.setAntiAlias(true);
|
|
|
1199 |
paint.setBlendMode(SkBlendMode::kDstATop);
|
|
|
1200 |
SkCanvas can(*image);
|
|
|
1201 |
sk_sp<SkImage> _image = SkImages::RasterFromBitmap(b);
|
|
|
1202 |
can.drawImage(_image, 0, 0, SkSamplingOptions(), &paint);
|
|
|
1203 |
}
|
|
|
1204 |
}
|
|
|
1205 |
}
|
|
|
1206 |
|
|
|
1207 |
// If there is no valid path return.
|
|
|
1208 |
if (pathAlpha.empty())
|
|
|
1209 |
return haveBaseImage;
|
|
|
1210 |
|
|
|
1211 |
// On error retrieving the image, return.
|
|
|
1212 |
if (!retrieveImage(pathAlpha, &bm))
|
|
|
1213 |
return haveBaseImage;
|
|
|
1214 |
|
|
|
1215 |
// If there was no base image loaded, allocate the space for an image
|
|
|
1216 |
// filled transparent. Make it the same size as the mask image.
|
|
|
1217 |
if (!haveBaseImage)
|
|
|
1218 |
{
|
|
|
1219 |
allocPixels(bm.info().width(), bm.info().height(), image);
|
|
|
1220 |
image->eraseColor(SK_ColorTRANSPARENT);
|
|
|
1221 |
}
|
|
|
1222 |
|
|
|
1223 |
// Only if the base image and the mask image have the same size, which
|
|
|
1224 |
// should be the case, then the visible pixels of the mask image are
|
|
|
1225 |
// colored by the border color.
|
|
|
1226 |
if (image->info().dimensions() == bm.info().dimensions())
|
|
|
1227 |
{
|
|
|
1228 |
for (int y = 0; y < image->info().height(); ++y)
|
|
|
1229 |
{
|
|
|
1230 |
for (int x = 0; x < image->info().width(); ++x)
|
|
|
1231 |
{
|
|
|
1232 |
SkColor col = bm.getColor(x, y);
|
|
|
1233 |
SkColor alpha = SkColorGetA(col);
|
|
|
1234 |
uint32_t *pix = bm.getAddr32(x, y);
|
|
|
1235 |
|
|
|
1236 |
if (alpha == 0)
|
|
|
1237 |
*pix = SK_ColorTRANSPARENT;
|
|
|
1238 |
else
|
|
|
1239 |
*pix = SkColorSetA(color, alpha);
|
|
|
1240 |
}
|
|
|
1241 |
}
|
|
|
1242 |
}
|
|
|
1243 |
|
|
|
1244 |
// Here we draw the border fragment over the base image.
|
|
|
1245 |
SkPaint paint;
|
|
|
1246 |
paint.setAntiAlias(true);
|
|
|
1247 |
paint.setBlendMode(SkBlendMode::kDstATop);
|
|
|
1248 |
SkCanvas can(*image);
|
|
|
1249 |
sk_sp<SkImage> _image = SkImages::RasterFromBitmap(bm);
|
|
|
1250 |
can.drawImage(_image, 0, 0, SkSamplingOptions(), &paint);
|
|
|
1251 |
|
|
|
1252 |
return true;
|
|
|
1253 |
}
|
|
|
1254 |
|
|
|
1255 |
SkBitmap TPageInterface::retrieveBorderImage(const string& pa, const string& pb, SkColor color, SkColor bgColor)
|
|
|
1256 |
{
|
|
|
1257 |
DECL_TRACER("TPageInterface::retrieveBorderImage(const string& pa, const string& pb, SkColor color, SkColor bgColor)");
|
|
|
1258 |
|
|
|
1259 |
SkBitmap bm, bma;
|
|
|
1260 |
|
|
|
1261 |
if (!pa.empty() && !retrieveImage(pa, &bm))
|
|
|
1262 |
return SkBitmap();
|
|
|
1263 |
|
|
|
1264 |
if (!pb.empty() && !retrieveImage(pb, &bma))
|
|
|
1265 |
return SkBitmap();
|
|
|
1266 |
|
|
|
1267 |
return colorImage(bm, bma, color, bgColor, false);
|
|
|
1268 |
}
|
|
|
1269 |
|
|
|
1270 |
bool TPageInterface::retrieveImage(const string& path, SkBitmap* image)
|
|
|
1271 |
{
|
|
|
1272 |
DECL_TRACER("TPageInterface::retrieveImage(const string& path, SkBitmap* image)");
|
|
|
1273 |
|
|
|
1274 |
if (path.empty() || !image)
|
|
|
1275 |
{
|
|
|
1276 |
MSG_WARNING("One or all of the parameters are invalid!");
|
|
|
1277 |
return false;
|
|
|
1278 |
}
|
|
|
1279 |
|
|
|
1280 |
sk_sp<SkData> im;
|
|
|
1281 |
|
|
|
1282 |
if (!(im = readImage(path)))
|
|
|
1283 |
return false;
|
|
|
1284 |
|
|
|
1285 |
DecodeDataToBitmap(im, image);
|
|
|
1286 |
|
|
|
1287 |
if (image->empty())
|
|
|
1288 |
{
|
|
|
1289 |
MSG_WARNING("Could not create the image " << path);
|
|
|
1290 |
return false;
|
|
|
1291 |
}
|
|
|
1292 |
|
|
|
1293 |
return true;
|
|
|
1294 |
}
|
|
|
1295 |
|
|
|
1296 |
SkBitmap TPageInterface::colorImage(SkBitmap& base, SkBitmap& alpha, SkColor col, SkColor bg, bool useBG)
|
|
|
1297 |
{
|
|
|
1298 |
DECL_TRACER("TPageInterface::colorImage(SkBitmap *img, int width, int height, SkColor col, SkColor bg, bool useBG)");
|
|
|
1299 |
|
|
|
1300 |
int width = base.info().width();
|
|
|
1301 |
int height = base.info().height();
|
|
|
1302 |
|
|
|
1303 |
if (width <= 0 || height <= 0)
|
|
|
1304 |
{
|
|
|
1305 |
MSG_WARNING("Got invalid width or height! (width: " << width << ", height: " << height << ")");
|
|
|
1306 |
return SkBitmap();
|
|
|
1307 |
}
|
|
|
1308 |
|
|
|
1309 |
if (!alpha.empty())
|
|
|
1310 |
{
|
|
|
1311 |
if (width != alpha.info().width() || height != alpha.info().height())
|
|
|
1312 |
{
|
|
|
1313 |
MSG_ERROR("Base and alpha masks have different size!");
|
|
|
1314 |
return SkBitmap();
|
|
|
1315 |
}
|
|
|
1316 |
}
|
|
|
1317 |
|
|
|
1318 |
SkBitmap maskBm;
|
|
|
1319 |
|
|
|
1320 |
if (!allocPixels(width, height, &maskBm))
|
|
|
1321 |
return SkBitmap();
|
|
|
1322 |
|
|
|
1323 |
maskBm.eraseColor(SK_ColorTRANSPARENT);
|
|
|
1324 |
|
|
|
1325 |
for (int ix = 0; ix < width; ix++)
|
|
|
1326 |
{
|
|
|
1327 |
for (int iy = 0; iy < height; iy++)
|
|
|
1328 |
{
|
|
|
1329 |
SkColor pixelAlpha = 0;
|
|
|
1330 |
|
|
|
1331 |
if (!alpha.empty())
|
|
|
1332 |
pixelAlpha = alpha.getColor(ix, iy);
|
|
|
1333 |
else
|
|
|
1334 |
pixelAlpha = base.getColor(ix, iy);
|
|
|
1335 |
|
|
|
1336 |
uint32_t *wpix = maskBm.getAddr32(ix, iy);
|
|
|
1337 |
|
|
|
1338 |
if (!wpix)
|
|
|
1339 |
{
|
|
|
1340 |
MSG_ERROR("No pixel buffer!");
|
|
|
1341 |
break;
|
|
|
1342 |
}
|
|
|
1343 |
|
|
|
1344 |
uint32_t ala = SkColorGetA(pixelAlpha);
|
|
|
1345 |
|
|
|
1346 |
if (ala == 0 && !useBG)
|
|
|
1347 |
pixelAlpha = col;
|
|
|
1348 |
else if (ala == 0)
|
|
|
1349 |
pixelAlpha = bg;
|
|
|
1350 |
else
|
|
|
1351 |
{
|
|
|
1352 |
// We've to change the red and the blue color channel because
|
|
|
1353 |
// of an error in the Skia library.
|
|
|
1354 |
uint32_t red = SkColorGetR(col);
|
|
|
1355 |
uint32_t green = SkColorGetG(col);
|
|
|
1356 |
uint32_t blue = SkColorGetB(col);
|
|
|
1357 |
|
|
|
1358 |
if (alpha.empty())
|
|
|
1359 |
{
|
|
|
1360 |
uint32_t pred = SkColorGetR(pixelAlpha);
|
|
|
1361 |
uint32_t pgreen = SkColorGetG(pixelAlpha);
|
|
|
1362 |
uint32_t pblue = SkColorGetB(pixelAlpha);
|
|
|
1363 |
uint32_t maxChan = SkColorGetG(SK_ColorWHITE);
|
|
|
1364 |
|
|
|
1365 |
red = ((pred == maxChan) ? pred : red);
|
|
|
1366 |
green = ((pgreen == maxChan) ? pgreen : green);
|
|
|
1367 |
blue = ((pblue == maxChan) ? pblue : blue);
|
|
|
1368 |
}
|
|
|
1369 |
else if (ala == 0)
|
|
|
1370 |
red = green = blue = 0;
|
|
|
1371 |
|
|
|
1372 |
pixelAlpha = SkColorSetARGB(ala, red, green, blue);
|
|
|
1373 |
}
|
|
|
1374 |
|
|
|
1375 |
*wpix = pixelAlpha;
|
|
|
1376 |
}
|
|
|
1377 |
}
|
|
|
1378 |
|
|
|
1379 |
if (!alpha.empty())
|
|
|
1380 |
{
|
|
|
1381 |
SkPaint paint;
|
|
|
1382 |
paint.setBlendMode(SkBlendMode::kSrcOver);
|
|
|
1383 |
SkCanvas can(maskBm);
|
|
|
1384 |
sk_sp<SkImage> _image = SkImages::RasterFromBitmap(base);
|
|
|
1385 |
can.drawImage(_image, 0, 0, SkSamplingOptions(), &paint);
|
|
|
1386 |
}
|
|
|
1387 |
|
|
|
1388 |
return maskBm;
|
|
|
1389 |
}
|
|
|
1390 |
|
|
|
1391 |
bool TPageInterface::stretchImageWidth(SkBitmap *bm, int width)
|
|
|
1392 |
{
|
|
|
1393 |
DECL_TRACER("TPageInterface::stretchImageWidth(SkBitmap *bm, int width)");
|
|
|
1394 |
|
|
|
1395 |
if (!bm)
|
|
|
1396 |
return false;
|
|
|
1397 |
|
|
|
1398 |
int rwidth = width;
|
|
|
1399 |
SkPaint paint;
|
|
|
1400 |
paint.setBlendMode(SkBlendMode::kSrc);
|
|
|
1401 |
|
|
|
1402 |
SkImageInfo info = bm->info();
|
|
|
1403 |
sk_sp<SkImage> im = SkImages::RasterFromBitmap(*bm);
|
|
|
1404 |
|
|
|
1405 |
if (width <= 0)
|
|
|
1406 |
rwidth = info.width() + width;
|
|
|
1407 |
|
|
|
1408 |
if (rwidth <= 0)
|
|
|
1409 |
rwidth = 1;
|
|
|
1410 |
|
|
|
1411 |
MSG_DEBUG("Width: " << rwidth << ", Height: " << info.height());
|
|
|
1412 |
|
|
|
1413 |
if (!allocPixels(rwidth, info.height(), bm))
|
|
|
1414 |
return false;
|
|
|
1415 |
|
|
|
1416 |
bm->eraseColor(SK_ColorTRANSPARENT);
|
|
|
1417 |
SkCanvas can(*bm, SkSurfaceProps());
|
|
|
1418 |
SkRect rect = SkRect::MakeXYWH(0, 0, rwidth, info.height());
|
|
|
1419 |
can.drawImageRect(im, rect, SkSamplingOptions(), &paint);
|
|
|
1420 |
return true;
|
|
|
1421 |
}
|
|
|
1422 |
|
|
|
1423 |
bool TPageInterface::stretchImageHeight(SkBitmap *bm, int height)
|
|
|
1424 |
{
|
|
|
1425 |
DECL_TRACER("TPageInterface::stretchImageHeight(SkBitmap *bm, int height)");
|
|
|
1426 |
|
|
|
1427 |
if (!bm)
|
|
|
1428 |
return false;
|
|
|
1429 |
|
|
|
1430 |
int rheight = height;
|
|
|
1431 |
SkPaint paint;
|
|
|
1432 |
paint.setBlendMode(SkBlendMode::kSrc);
|
|
|
1433 |
|
|
|
1434 |
SkImageInfo info = bm->info();
|
|
|
1435 |
|
|
|
1436 |
if (height <= 0)
|
|
|
1437 |
rheight = info.height() + height;
|
|
|
1438 |
|
|
|
1439 |
if (rheight <= 0)
|
|
|
1440 |
rheight = 1;
|
|
|
1441 |
|
|
|
1442 |
sk_sp<SkImage> im = SkImages::RasterFromBitmap(*bm);
|
|
|
1443 |
MSG_DEBUG("Width: " << info.width() << ", Height: " << rheight);
|
|
|
1444 |
|
|
|
1445 |
if (!allocPixels(info.width(), rheight, bm))
|
|
|
1446 |
return false;
|
|
|
1447 |
|
|
|
1448 |
bm->eraseColor(SK_ColorTRANSPARENT);
|
|
|
1449 |
SkCanvas can(*bm, SkSurfaceProps());
|
|
|
1450 |
SkRect rect = SkRect::MakeXYWH(0, 0, info.width(), rheight);
|
|
|
1451 |
can.drawImageRect(im, rect, SkSamplingOptions(), &paint);
|
|
|
1452 |
return true;
|
|
|
1453 |
}
|
|
|
1454 |
|
|
|
1455 |
#ifdef _OPAQUE_SKIA_
|
|
|
1456 |
bool TPageInterface::setOpacity(SkBitmap *bm, int oo)
|
|
|
1457 |
{
|
|
|
1458 |
DECL_TRACER("TPageInterface::setOpacity(SkBitmap *bm, int oo)");
|
|
|
1459 |
|
|
|
1460 |
if (oo < 0 || oo > 255 || !bm)
|
|
|
1461 |
return false;
|
|
|
1462 |
|
|
|
1463 |
SkBitmap ooButton;
|
|
|
1464 |
int w = bm->info().width();
|
|
|
1465 |
int h = bm->info().height();
|
|
|
1466 |
|
|
|
1467 |
if (!allocPixels(w, h, &ooButton))
|
|
|
1468 |
return false;
|
|
|
1469 |
|
|
|
1470 |
SkCanvas canvas(ooButton);
|
|
|
1471 |
SkIRect irect = SkIRect::MakeXYWH(0, 0, w, h);
|
|
|
1472 |
SkRegion region;
|
|
|
1473 |
region.setRect(irect);
|
|
|
1474 |
SkScalar opaque = (SkScalar)oo;
|
|
|
1475 |
|
|
|
1476 |
SkScalar alpha = 1.0 / 255.0 * opaque;
|
|
|
1477 |
MSG_DEBUG("Calculated alpha value: " << alpha << " (oo=" << oo << ")");
|
|
|
1478 |
SkPaint paint;
|
|
|
1479 |
paint.setAlphaf(alpha);
|
|
|
1480 |
sk_sp<SkImage> _image = SkImages::RasterFromBitmap(*bm);
|
|
|
1481 |
canvas.drawImage(_image, 0, 0, SkSamplingOptions(), &paint);
|
|
|
1482 |
bm->erase(SK_ColorTRANSPARENT, {0, 0, w, h});
|
|
|
1483 |
*bm = ooButton;
|
|
|
1484 |
return true;
|
|
|
1485 |
}
|
|
|
1486 |
#endif
|