CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/UI/OnScreenDisplay.cpp
Views: 1401
1
#include <algorithm>
2
#include <sstream>
3
4
#include "UI/OnScreenDisplay.h"
5
6
#include "Common/Data/Color/RGBAUtil.h"
7
#include "Common/Data/Encoding/Utf8.h"
8
#include "Common/Render/TextureAtlas.h"
9
#include "Common/Render/DrawBuffer.h"
10
#include "Common/Math/math_util.h"
11
#include "Common/UI/IconCache.h"
12
#include "UI/RetroAchievementScreens.h"
13
#include "UI/DebugOverlay.h"
14
#include "UI/Root.h"
15
16
#include "Common/UI/Context.h"
17
#include "Common/System/OSD.h"
18
19
#include "Common/TimeUtil.h"
20
#include "Common/Net/HTTPClient.h"
21
#include "Core/Config.h"
22
23
static inline const char *DeNull(const char *ptr) {
24
return ptr ? ptr : "";
25
}
26
27
extern bool g_TakeScreenshot;
28
29
static const float g_atlasIconSize = 36.0f;
30
static const float extraTextScale = 0.7f;
31
32
static uint32_t GetNoticeBackgroundColor(NoticeLevel type) {
33
// Colors from Infima
34
switch (type) {
35
case NoticeLevel::ERROR: return 0x3530d5; // danger-darker
36
case NoticeLevel::WARN: return 0x009ed9; // warning-darker
37
case NoticeLevel::INFO: return 0x706760; // gray-700
38
case NoticeLevel::SUCCESS: return 0x008b00; // nice green
39
default: return 0x606770;
40
}
41
}
42
43
static ImageID GetOSDIcon(NoticeLevel level) {
44
switch (level) {
45
case NoticeLevel::INFO: return ImageID("I_INFO");
46
case NoticeLevel::ERROR: return ImageID("I_CROSS");
47
case NoticeLevel::WARN: return ImageID("I_WARNING");
48
case NoticeLevel::SUCCESS: return ImageID("I_CHECKMARK");
49
default: return ImageID::invalid();
50
}
51
}
52
53
static NoticeLevel GetNoticeLevel(OSDType type) {
54
switch (type) {
55
case OSDType::MESSAGE_INFO:
56
return NoticeLevel::INFO;
57
case OSDType::MESSAGE_ERROR:
58
case OSDType::MESSAGE_ERROR_DUMP:
59
case OSDType::MESSAGE_CENTERED_ERROR:
60
return NoticeLevel::ERROR;
61
case OSDType::MESSAGE_WARNING:
62
case OSDType::MESSAGE_CENTERED_WARNING:
63
return NoticeLevel::WARN;
64
case OSDType::MESSAGE_SUCCESS:
65
return NoticeLevel::SUCCESS;
66
default:
67
return NoticeLevel::SUCCESS;
68
}
69
}
70
71
// Align only matters here for the ASCII-only flag.
72
static void MeasureNotice(const UIContext &dc, NoticeLevel level, const std::string &text, const std::string &details, const std::string &iconName, int align, float *width, float *height, float *height1) {
73
dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, text.c_str(), width, height, align);
74
75
*height1 = *height;
76
77
float width2 = 0.0f, height2 = 0.0f;
78
if (!details.empty()) {
79
dc.MeasureText(dc.theme->uiFont, extraTextScale, extraTextScale, details.c_str(), &width2, &height2, align);
80
*width = std::max(*width, width2);
81
*height += 5.0f + height2;
82
}
83
84
float iconW = 0.0f;
85
float iconH = 0.0f;
86
if (!iconName.empty() && !startsWith(iconName, "I_")) { // Check for atlas image. Bit hacky, but we choose prefixes for icon IDs anyway in a way that this is safe.
87
// Normal entry but with a cached icon.
88
int iconWidth, iconHeight;
89
if (g_iconCache.GetDimensions(iconName, &iconWidth, &iconHeight)) {
90
*width += 5.0f + iconWidth;
91
iconW = iconWidth;
92
iconH = iconHeight;
93
}
94
} else {
95
ImageID iconID = iconName.empty() ? GetOSDIcon(level) : ImageID(iconName.c_str());
96
if (iconID.isValid()) {
97
dc.Draw()->GetAtlas()->measureImage(iconID, &iconW, &iconH);
98
}
99
}
100
101
iconW += 5.0f;
102
103
*width += iconW + 12.0f;
104
*height = std::max(*height, iconH + 5.0f);
105
}
106
107
// Align only matters here for the ASCII-only flag.
108
static void MeasureOSDEntry(const UIContext &dc, const OnScreenDisplay::Entry &entry, int align, float *width, float *height, float *height1) {
109
if (entry.type == OSDType::ACHIEVEMENT_UNLOCKED) {
110
const rc_client_achievement_t *achievement = rc_client_get_achievement_info(Achievements::GetClient(), entry.numericID);
111
MeasureAchievement(dc, achievement, AchievementRenderStyle::UNLOCKED, width, height);
112
*width = 550.0f;
113
*height1 = *height;
114
} else {
115
MeasureNotice(dc, GetNoticeLevel(entry.type), entry.text, entry.text2, entry.iconName, align, width, height, height1);
116
}
117
}
118
119
static void RenderNotice(UIContext &dc, Bounds bounds, float height1, NoticeLevel level, const std::string &text, const std::string &details, const std::string &iconName, int align, float alpha) {
120
UI::Drawable background = UI::Drawable(colorAlpha(GetNoticeBackgroundColor(level), alpha));
121
122
uint32_t foreGround = whiteAlpha(alpha);
123
124
dc.DrawRectDropShadow(bounds, 12.0f, 0.7f * alpha);
125
dc.FillRect(background, bounds);
126
127
float iconW = 0.0f;
128
float iconH = 0.0f;
129
if (!iconName.empty() && !startsWith(iconName, "I_")) {
130
dc.Flush();
131
// Normal entry but with a cached icon.
132
Draw::Texture *texture = g_iconCache.BindIconTexture(&dc, iconName);
133
if (texture) {
134
iconW = texture->Width();
135
iconH = texture->Height();
136
dc.Draw()->DrawTexRect(Bounds(bounds.x + 2.5f, bounds.y + 2.5f, iconW, iconH), 0.0f, 0.0f, 1.0f, 1.0f, foreGround);
137
dc.Flush();
138
dc.RebindTexture();
139
}
140
dc.Begin();
141
} else {
142
ImageID iconID = iconName.empty() ? GetOSDIcon(level) : ImageID(iconName.c_str());
143
if (iconID.isValid()) {
144
// Atlas icon.
145
dc.Draw()->GetAtlas()->measureImage(iconID, &iconW, &iconH);
146
if (!iconName.empty()) {
147
Bounds iconBounds = Bounds(bounds.x + 2.5f, bounds.y + 2.5f, iconW, iconH);
148
// If it's not a preset OSD icon, give it some background to blend in. The RA icon for example
149
// easily melts into the orange of warnings otherwise.
150
dc.FillRect(UI::Drawable(0x50000000), iconBounds.Expand(2.0f));
151
}
152
dc.DrawImageVGradient(iconID, foreGround, foreGround, Bounds(bounds.x + 2.5f, bounds.y + 2.5f, iconW, iconH));
153
}
154
}
155
156
// Make room
157
bounds.x += iconW + 5.0f;
158
bounds.w -= iconW + 5.0f;
159
160
dc.DrawTextShadowRect(text.c_str(), bounds.Inset(0.0f, 1.0f, 0.0f, 0.0f), foreGround, (align & FLAG_DYNAMIC_ASCII));
161
162
if (!details.empty()) {
163
Bounds bottomTextBounds = bounds.Inset(3.0f, height1 + 5.0f, 3.0f, 3.0f);
164
UI::Drawable backgroundDark = UI::Drawable(colorAlpha(darkenColor(GetNoticeBackgroundColor(level)), alpha));
165
dc.FillRect(backgroundDark, bottomTextBounds);
166
dc.SetFontScale(extraTextScale, extraTextScale);
167
dc.DrawTextRect(details, bottomTextBounds, foreGround, (align & FLAG_DYNAMIC_ASCII) | ALIGN_LEFT);
168
}
169
dc.SetFontScale(1.0f, 1.0f);
170
}
171
172
static void RenderOSDEntry(UIContext &dc, const OnScreenDisplay::Entry &entry, Bounds bounds, float height1, int align, float alpha) {
173
if (entry.type == OSDType::ACHIEVEMENT_UNLOCKED) {
174
const rc_client_achievement_t * achievement = rc_client_get_achievement_info(Achievements::GetClient(), entry.numericID);
175
if (achievement) {
176
RenderAchievement(dc, achievement, AchievementRenderStyle::UNLOCKED, bounds, alpha, entry.startTime, time_now_d(), false);
177
}
178
return;
179
} else {
180
RenderNotice(dc, bounds, height1, GetNoticeLevel(entry.type), entry.text, entry.text2, entry.iconName, align, alpha);
181
}
182
}
183
184
static void MeasureOSDProgressBar(const UIContext &dc, const OnScreenDisplay::Entry &bar, float *width, float *height) {
185
*height = 36;
186
*width = 450.0f;
187
}
188
189
static void RenderOSDProgressBar(UIContext &dc, const OnScreenDisplay::Entry &entry, Bounds bounds, int align, float alpha) {
190
uint32_t foreGround = whiteAlpha(alpha);
191
192
dc.DrawRectDropShadow(bounds, 12.0f, 0.7f * alpha);
193
194
uint32_t backgroundColor = colorAlpha(0x806050, alpha);
195
uint32_t progressBackgroundColor = colorAlpha(0xa08070, alpha);
196
197
if (entry.maxValue > entry.minValue) {
198
// Normal progress bar
199
200
UI::Drawable background = UI::Drawable(backgroundColor);
201
UI::Drawable progressBackground = UI::Drawable(progressBackgroundColor);
202
203
float ratio = (float)(entry.progress - entry.minValue) / (float)entry.maxValue;
204
205
Bounds boundLeft = bounds;
206
Bounds boundRight = bounds;
207
208
boundLeft.w *= ratio;
209
boundRight.x += ratio * boundRight.w;
210
boundRight.w *= (1.0f - ratio);
211
212
dc.FillRect(progressBackground, boundLeft);
213
dc.FillRect(background, boundRight);
214
} else {
215
// Indeterminate spinner
216
float alpha = cos(time_now_d() * 5.0) * 0.5f + 0.5f;
217
uint32_t pulse = colorBlend(backgroundColor, progressBackgroundColor, alpha);
218
UI::Drawable background = UI::Drawable(pulse);
219
dc.FillRect(background, bounds);
220
}
221
222
dc.SetFontStyle(dc.theme->uiFont);
223
dc.SetFontScale(1.0f, 1.0f);
224
225
dc.DrawTextShadowRect(entry.text.c_str(), bounds, colorAlpha(0xFFFFFFFF, alpha), (align & FLAG_DYNAMIC_ASCII) | ALIGN_CENTER);
226
}
227
228
static void MeasureLeaderboardTracker(UIContext &dc, const std::string &text, float *width, float *height) {
229
dc.MeasureText(dc.GetFontStyle(), 1.0f, 1.0f, text.c_str(), width, height);
230
*width += 16.0f;
231
*height += 10.0f;
232
}
233
234
static void RenderLeaderboardTracker(UIContext &dc, const Bounds &bounds, const std::string &text, float alpha) {
235
// TODO: Awful color.
236
uint32_t backgroundColor = colorAlpha(0x806050, alpha);
237
UI::Drawable background = UI::Drawable(backgroundColor);
238
dc.DrawRectDropShadow(bounds, 12.0f, 0.7f * alpha);
239
dc.FillRect(background, bounds);
240
dc.SetFontStyle(dc.theme->uiFont);
241
dc.SetFontScale(1.0f, 1.0f);
242
dc.DrawTextShadowRect(text.c_str(), bounds.Inset(5.0f, 5.0f), colorAlpha(0xFFFFFFFF, alpha), ALIGN_VCENTER | ALIGN_HCENTER);
243
}
244
245
void OnScreenMessagesView::Draw(UIContext &dc) {
246
if (!g_Config.bShowOnScreenMessages || g_TakeScreenshot) {
247
return;
248
}
249
250
dc.Flush();
251
252
double now = time_now_d();
253
254
const float padding = 5.0f;
255
256
const float fadeinCoef = 1.0f / OnScreenDisplay::FadeinTime();
257
const float fadeoutCoef = 1.0f / OnScreenDisplay::FadeoutTime();
258
259
float sidebarAlpha = g_OSD.SidebarAlpha();
260
261
struct LayoutEdge {
262
float height;
263
float maxWidth;
264
float alpha;
265
};
266
267
struct MeasuredEntry {
268
float w;
269
float h;
270
float h1;
271
float alpha;
272
int align;
273
int align2;
274
AchievementRenderStyle style;
275
};
276
277
// Grab all the entries. Makes a copy so we can release the lock ASAP.
278
const std::vector<OnScreenDisplay::Entry> entries = g_OSD.Entries();
279
280
std::vector<MeasuredEntry> measuredEntries;
281
measuredEntries.resize(entries.size());
282
283
// Indexed by the enum ScreenEdgePosition.
284
LayoutEdge edges[(size_t)ScreenEdgePosition::VALUE_COUNT]{};
285
for (size_t i = 0; i < (size_t)ScreenEdgePosition::VALUE_COUNT; i++) {
286
edges[i].alpha = sidebarAlpha;
287
}
288
edges[(size_t)ScreenEdgePosition::TOP_CENTER].alpha = 1.0f;
289
290
ScreenEdgePosition typeEdges[(size_t)OSDType::VALUE_COUNT]{};
291
// Default to top.
292
for (int i = 0; i < (size_t)OSDType::VALUE_COUNT; i++) {
293
typeEdges[i] = ScreenEdgePosition::TOP_CENTER;
294
}
295
296
typeEdges[(size_t)OSDType::ACHIEVEMENT_CHALLENGE_INDICATOR] = (ScreenEdgePosition)g_Config.iAchievementsChallengePos;
297
typeEdges[(size_t)OSDType::ACHIEVEMENT_PROGRESS] = (ScreenEdgePosition)g_Config.iAchievementsProgressPos;
298
typeEdges[(size_t)OSDType::LEADERBOARD_TRACKER] = (ScreenEdgePosition)g_Config.iAchievementsLeaderboardTrackerPos;
299
typeEdges[(size_t)OSDType::LEADERBOARD_STARTED_FAILED] = (ScreenEdgePosition)g_Config.iAchievementsLeaderboardStartedOrFailedPos;
300
typeEdges[(size_t)OSDType::LEADERBOARD_SUBMITTED] = (ScreenEdgePosition)g_Config.iAchievementsLeaderboardSubmittedPos;
301
typeEdges[(size_t)OSDType::ACHIEVEMENT_UNLOCKED] = (ScreenEdgePosition)g_Config.iAchievementsUnlockedPos;
302
typeEdges[(size_t)OSDType::MESSAGE_CENTERED_WARNING] = ScreenEdgePosition::CENTER;
303
typeEdges[(size_t)OSDType::MESSAGE_CENTERED_ERROR] = ScreenEdgePosition::CENTER;
304
305
dc.SetFontScale(1.0f, 1.0f);
306
307
// First pass: Measure all the sides.
308
for (size_t i = 0; i < entries.size(); i++) {
309
const auto &entry = entries[i];
310
auto &measuredEntry = measuredEntries[i];
311
312
ScreenEdgePosition pos = typeEdges[(size_t)entry.type];
313
if (pos == ScreenEdgePosition::VALUE_COUNT || pos == (ScreenEdgePosition)-1) {
314
// NONE.
315
continue;
316
}
317
318
measuredEntry.align = 0;
319
measuredEntry.align2 = 0;
320
// If we have newlines, we may be looking at ASCII debug output. But let's verify.
321
if (entry.text.find('\n') != std::string::npos) {
322
if (!UTF8StringHasNonASCII(entry.text.c_str()))
323
measuredEntry.align |= FLAG_DYNAMIC_ASCII;
324
}
325
if (entry.text2.find('\n') != std::string::npos) {
326
if (!UTF8StringHasNonASCII(entry.text2.c_str()))
327
measuredEntry.align2 |= FLAG_DYNAMIC_ASCII;
328
}
329
330
switch (entry.type) {
331
case OSDType::ACHIEVEMENT_PROGRESS:
332
{
333
const rc_client_achievement_t *achievement = rc_client_get_achievement_info(Achievements::GetClient(), entry.numericID);
334
if (!achievement)
335
continue;
336
measuredEntry.style = AchievementRenderStyle::PROGRESS_INDICATOR;
337
MeasureAchievement(dc, achievement, measuredEntry.style, &measuredEntry.w, &measuredEntry.h);
338
break;
339
}
340
case OSDType::ACHIEVEMENT_CHALLENGE_INDICATOR:
341
{
342
const rc_client_achievement_t *achievement = rc_client_get_achievement_info(Achievements::GetClient(), entry.numericID);
343
if (!achievement)
344
continue;
345
measuredEntry.style = AchievementRenderStyle::CHALLENGE_INDICATOR;
346
MeasureAchievement(dc, achievement, measuredEntry.style, &measuredEntry.w, &measuredEntry.h);
347
break;
348
}
349
case OSDType::LEADERBOARD_TRACKER:
350
{
351
MeasureLeaderboardTracker(dc, entry.text, &measuredEntry.w, &measuredEntry.h);
352
break;
353
}
354
case OSDType::ACHIEVEMENT_UNLOCKED:
355
{
356
const rc_client_achievement_t *achievement = rc_client_get_achievement_info(Achievements::GetClient(), entry.numericID);
357
if (!achievement)
358
continue;
359
measuredEntry.style = AchievementRenderStyle::UNLOCKED;
360
MeasureAchievement(dc, achievement, AchievementRenderStyle::UNLOCKED, &measuredEntry.w, &measuredEntry.h);
361
measuredEntry.h1 = measuredEntry.h;
362
measuredEntry.w = 550.0f;
363
break;
364
}
365
case OSDType::PROGRESS_BAR:
366
MeasureOSDProgressBar(dc, entry, &measuredEntry.w, &measuredEntry.h);
367
break;
368
default:
369
MeasureOSDEntry(dc, entry, measuredEntry.align, &measuredEntry.w, &measuredEntry.h, &measuredEntry.h1);
370
break;
371
}
372
373
float enterAlpha = saturatef((float)(now - entry.startTime) * fadeoutCoef);
374
float leaveAlpha = saturatef((float)(entry.endTime - now) * fadeoutCoef);
375
float alpha = std::min(enterAlpha, leaveAlpha);
376
measuredEntry.alpha = alpha;
377
378
edges[(size_t)pos].height += (measuredEntry.h + 4.0f) * alpha;
379
edges[(size_t)pos].maxWidth = std::max(edges[(size_t)pos].maxWidth, measuredEntry.w);
380
}
381
382
std::vector<ClickZone> clickZones;
383
384
// Now, perform layout for all 8 edges.
385
for (size_t i = 0; i < (size_t)ScreenEdgePosition::VALUE_COUNT; i++) {
386
if (edges[i].height == 0.0f) {
387
// Nothing on this side, ignore it entirely.
388
continue;
389
}
390
391
// First, compute the start position.
392
float y = padding;
393
int horizAdj = 0;
394
int vertAdj = 0;
395
switch ((ScreenEdgePosition)i) {
396
case ScreenEdgePosition::TOP_LEFT: horizAdj = -1; vertAdj = -1; break;
397
case ScreenEdgePosition::CENTER_LEFT: horizAdj = -1; break;
398
case ScreenEdgePosition::BOTTOM_LEFT: horizAdj = -1; vertAdj = 1; break;
399
case ScreenEdgePosition::TOP_RIGHT: horizAdj = 1; vertAdj = -1; break;
400
case ScreenEdgePosition::CENTER_RIGHT: horizAdj = 1; break;
401
case ScreenEdgePosition::BOTTOM_RIGHT: horizAdj = 1; vertAdj = 1; break;
402
case ScreenEdgePosition::TOP_CENTER: vertAdj = -1; break;
403
case ScreenEdgePosition::BOTTOM_CENTER: vertAdj = 1; break;
404
case ScreenEdgePosition::CENTER: break;
405
default: break;
406
}
407
408
if (vertAdj == 0) {
409
// Center vertically
410
y = (bounds_.h - edges[i].height) * 0.5f;
411
} else if (vertAdj == 1) {
412
y = (bounds_.h - edges[i].height);
413
}
414
415
// Then, loop through the entries and those belonging here, get rendered here.
416
for (size_t j = 0; j < (size_t)entries.size(); j++) {
417
auto &entry = entries[j];
418
if (typeEdges[(size_t)entry.type] != (ScreenEdgePosition)i) { // yes, i
419
continue;
420
}
421
auto &measuredEntry = measuredEntries[j];
422
float alpha = measuredEntry.alpha * edges[i].alpha;
423
424
Bounds b(padding, y, measuredEntry.w, measuredEntry.h);
425
426
if (horizAdj == 0) {
427
// Centered
428
b.x = (bounds_.w - b.w) * 0.5f;
429
} else if (horizAdj == 1) {
430
// Right-aligned
431
b.x = bounds_.w - (b.w + padding);
432
}
433
434
switch (entry.type) {
435
case OSDType::ACHIEVEMENT_PROGRESS:
436
case OSDType::ACHIEVEMENT_CHALLENGE_INDICATOR:
437
{
438
const rc_client_achievement_t *achievement = rc_client_get_achievement_info(Achievements::GetClient(), entry.numericID);
439
RenderAchievement(dc, achievement, measuredEntry.style, b, alpha, entry.startTime, now, false);
440
break;
441
}
442
case OSDType::LEADERBOARD_TRACKER:
443
RenderLeaderboardTracker(dc, b, entry.text, alpha);
444
break;
445
case OSDType::PROGRESS_BAR:
446
RenderOSDProgressBar(dc, entry, b, 0, alpha);
447
break;
448
default:
449
{
450
// Scale down if height doesn't fit.
451
float scale = 1.0f;
452
if (measuredEntry.h > bounds_.h - y) {
453
// Scale down!
454
scale = std::max(0.15f, (bounds_.h - y) / measuredEntry.h);
455
dc.SetFontScale(scale, scale);
456
b.w *= scale;
457
b.h *= scale;
458
}
459
460
float alpha = Clamp((float)(entry.endTime - now) * 4.0f, 0.0f, 1.0f);
461
RenderOSDEntry(dc, entry, b, measuredEntry.h1, measuredEntry.align, alpha);
462
463
switch (entry.type) {
464
case OSDType::MESSAGE_INFO:
465
case OSDType::MESSAGE_SUCCESS:
466
case OSDType::MESSAGE_WARNING:
467
case OSDType::MESSAGE_ERROR:
468
case OSDType::MESSAGE_CENTERED_ERROR:
469
case OSDType::MESSAGE_CENTERED_WARNING:
470
case OSDType::MESSAGE_ERROR_DUMP:
471
case OSDType::MESSAGE_FILE_LINK:
472
case OSDType::ACHIEVEMENT_UNLOCKED:
473
// Save the location of the popup, for easy dismissal.
474
clickZones.push_back(ClickZone{ (int)j, b });
475
break;
476
default:
477
break;
478
}
479
break;
480
}
481
}
482
483
484
y += (measuredEntry.h + 4.0f) * measuredEntry.alpha;
485
}
486
}
487
488
std::lock_guard<std::mutex> lock(clickMutex_);
489
clickZones_ = clickZones;
490
}
491
492
std::string OnScreenMessagesView::DescribeText() const {
493
std::stringstream ss;
494
const auto &entries = g_OSD.Entries();
495
for (auto iter = entries.begin(); iter != entries.end(); ++iter) {
496
if (iter != entries.begin()) {
497
ss << "\n";
498
}
499
ss << iter->text;
500
}
501
return ss.str();
502
}
503
504
// Asynchronous!
505
bool OnScreenMessagesView::Dismiss(float x, float y) {
506
bool dismissed = false;
507
std::lock_guard<std::mutex> lock(clickMutex_);
508
double now = time_now_d();
509
for (auto &zone : clickZones_) {
510
if (zone.bounds.Contains(x, y)) {
511
g_OSD.ClickEntry(zone.index, now);
512
dismissed = true;
513
}
514
}
515
return dismissed;
516
}
517
518
bool OSDOverlayScreen::UnsyncTouch(const TouchInput &touch) {
519
// Don't really need to forward.
520
// UIScreen::UnsyncTouch(touch);
521
if ((touch.flags & TOUCH_DOWN) && osmView_) {
522
return osmView_->Dismiss(touch.x, touch.y);
523
} else {
524
return false;
525
}
526
}
527
528
void OSDOverlayScreen::CreateViews() {
529
root_ = new UI::AnchorLayout();
530
root_->SetTag("OSDOverlayScreen");
531
osmView_ = root_->Add(new OnScreenMessagesView(new UI::AnchorLayoutParams(0.0f, 0.0f, 0.0f, 0.0f)));
532
}
533
534
void OSDOverlayScreen::DrawForeground(UIContext &ui) {
535
DebugOverlay debugOverlay = (DebugOverlay)g_Config.iDebugOverlay;
536
537
// Special case control for now, since it uses the control mapper that's owned by EmuScreen.
538
if (debugOverlay != DebugOverlay::OFF && debugOverlay != DebugOverlay::CONTROL) {
539
UIContext *uiContext = screenManager()->getUIContext();
540
DrawDebugOverlay(uiContext, uiContext->GetLayoutBounds(), debugOverlay);
541
}
542
}
543
544
void OSDOverlayScreen::update() {
545
// Partial version of UIScreen::update() but doesn't do event processing to avoid duplicate event processing.
546
bool vertical = UseVerticalLayout();
547
if (vertical != lastVertical_) {
548
RecreateViews();
549
lastVertical_ = vertical;
550
}
551
552
DoRecreateViews();
553
}
554
555
void NoticeView::GetContentDimensionsBySpec(const UIContext &dc, UI::MeasureSpec horiz, UI::MeasureSpec vert, float &w, float &h) const {
556
Bounds bounds(0, 0, layoutParams_->width, layoutParams_->height);
557
if (bounds.w < 0) {
558
// If there's no size, let's grow as big as we want.
559
bounds.w = horiz.size;
560
}
561
if (bounds.h < 0) {
562
bounds.h = vert.size;
563
}
564
ApplyBoundsBySpec(bounds, horiz, vert);
565
MeasureNotice(dc, level_, text_, detailsText_, iconName_, 0, &w, &h, &height1_);
566
// Layout hack! Some weird problems with the layout that I can't figure out right now..
567
if (squishy_) {
568
w = 50.0;
569
}
570
}
571
572
void NoticeView::Draw(UIContext &dc) {
573
dc.PushScissor(bounds_);
574
RenderNotice(dc, bounds_, height1_, level_, text_, detailsText_, iconName_, 0, 1.0f);
575
dc.PopScissor();
576
}
577
578