Skip to content

Commit

Permalink
Support for extra text in OSD messages (drawn smaller, on darker back…
Browse files Browse the repository at this point in the history
…ground)
  • Loading branch information
hrydgard committed Jun 20, 2023
1 parent c76b6a4 commit 266b85d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Common/Math/geom2d.h
Expand Up @@ -72,6 +72,9 @@ struct Bounds {
Bounds Offset(float xAmount, float yAmount) const {
return Bounds(x + xAmount, y + yAmount, w, h);
}
Bounds Inset(float left, float top, float right, float bottom) {
return Bounds(x + left, y + top, w - left - right, h - bottom - top);
}

float x;
float y;
Expand Down
8 changes: 4 additions & 4 deletions Core/FileSystems/BlockDevices.cpp
Expand Up @@ -73,13 +73,13 @@ u32 BlockDevice::CalculateCRC(volatile bool *cancel) {
void BlockDevice::NotifyReadError() {
auto err = GetI18NCategory(I18NCat::ERRORS);
if (!reportedError_) {
g_OSD.Show(OSDType::MESSAGE_ERROR, err->T("Game disc read error - ISO corrupt"), 6.0f);
g_OSD.Show(OSDType::MESSAGE_WARNING, err->T("Game disc read error - ISO corrupt"), fileLoader_->GetPath().ToVisualString(), 6.0f);
reportedError_ = true;
}
}

FileBlockDevice::FileBlockDevice(FileLoader *fileLoader)
: fileLoader_(fileLoader) {
: BlockDevice(fileLoader) {
filesize_ = fileLoader->FileSize();
}

Expand Down Expand Up @@ -137,7 +137,7 @@ typedef struct ciso_header
static const u32 CSO_READ_BUFFER_SIZE = 256 * 1024;

CISOFileBlockDevice::CISOFileBlockDevice(FileLoader *fileLoader)
: fileLoader_(fileLoader)
: BlockDevice(fileLoader)
{
// CISO format is fairly simple, but most tools do not write the header_size.

Expand Down Expand Up @@ -382,7 +382,7 @@ bool CISOFileBlockDevice::ReadBlocks(u32 minBlock, int count, u8 *outPtr) {
}

NPDRMDemoBlockDevice::NPDRMDemoBlockDevice(FileLoader *fileLoader)
: fileLoader_(fileLoader)
: BlockDevice(fileLoader)
{
std::lock_guard<std::mutex> guard(mutex_);
MAC_KEY mkey;
Expand Down
5 changes: 2 additions & 3 deletions Core/FileSystems/BlockDevices.h
Expand Up @@ -32,6 +32,7 @@ class FileLoader;

class BlockDevice {
public:
BlockDevice(FileLoader *fileLoader) : fileLoader_(fileLoader) {}
virtual ~BlockDevice() {}
virtual bool ReadBlock(int blockNumber, u8 *outPtr, bool uncached = false) = 0;
virtual bool ReadBlocks(u32 minBlock, int count, u8 *outPtr) {
Expand All @@ -51,6 +52,7 @@ class BlockDevice {
void NotifyReadError();

protected:
FileLoader *fileLoader_;
bool reportedError_ = false;
};

Expand All @@ -64,7 +66,6 @@ class CISOFileBlockDevice : public BlockDevice {
bool IsDisc() override { return true; }

private:
FileLoader *fileLoader_;
u32 *index;
u8 *readBuffer;
u8 *zlibBuffer;
Expand All @@ -88,7 +89,6 @@ class FileBlockDevice : public BlockDevice {
bool IsDisc() override { return true; }

private:
FileLoader *fileLoader_;
u64 filesize_;
};

Expand All @@ -113,7 +113,6 @@ class NPDRMDemoBlockDevice : public BlockDevice {
bool IsDisc() override { return false; }

private:
FileLoader *fileLoader_;
static std::mutex mutex_;
u32 lbaSize;

Expand Down
2 changes: 1 addition & 1 deletion UI/DevScreens.cpp
Expand Up @@ -804,7 +804,7 @@ void SystemInfoScreen::CreateTabs() {
return UI::EVENT_DONE;
});
internals->Add(new Choice(si->T("Warning")))->OnClick.Add([&](UI::EventParams &) {
g_OSD.Show(OSDType::MESSAGE_WARNING, si->T("Warning"));
g_OSD.Show(OSDType::MESSAGE_WARNING, si->T("Warning"), "Some\nAdditional\nDetail");
return UI::EVENT_DONE;
});
internals->Add(new Choice(si->T("Info")))->OnClick.Add([&](UI::EventParams &) {
Expand Down
31 changes: 25 additions & 6 deletions UI/OnScreenDisplay.cpp
Expand Up @@ -40,9 +40,19 @@ ImageID GetOSDIcon(OSDType type) {

static const float iconSize = 36.0f;

static const float extraTextScale = 0.7f;

// Align only matters here for the ASCII-only flag.
static void MeasureOSDEntry(UIContext &dc, const OnScreenDisplay::Entry &entry, int align, float *width, float *height) {
static void MeasureOSDEntry(UIContext &dc, const OnScreenDisplay::Entry &entry, int align, float *width, float *height, float *height1) {
dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, entry.text.c_str(), width, height, align);
*height1 = *height;

float width2 = 0.0f, height2 = 0.0f;
if (!entry.text2.empty()) {
dc.MeasureText(dc.theme->uiFont, extraTextScale, extraTextScale, entry.text2.c_str(), &width2, &height2, align);
*width = std::max(*width, width2);
*height += 5.0f + height2;
}

if (!GetOSDIcon(entry.type).isInvalid()) {
*width += iconSize + 5.0f;
Expand All @@ -52,7 +62,7 @@ static void MeasureOSDEntry(UIContext &dc, const OnScreenDisplay::Entry &entry,
*height = std::max(*height, iconSize + 5.0f);
}

static void RenderOSDEntry(UIContext &dc, const OnScreenDisplay::Entry &entry, Bounds bounds, int align, float alpha) {
static void RenderOSDEntry(UIContext &dc, const OnScreenDisplay::Entry &entry, Bounds bounds, float height1, int align, float alpha) {
UI::Drawable background = UI::Drawable(colorAlpha(GetOSDBackgroundColor(entry.type), alpha));

uint32_t foreGround = whiteAlpha(alpha);
Expand All @@ -74,7 +84,16 @@ static void RenderOSDEntry(UIContext &dc, const OnScreenDisplay::Entry &entry, B
bounds.w -= iconSize + 5.0f;
}

dc.DrawTextShadowRect(entry.text.c_str(), bounds, colorAlpha(0xFFFFFFFF, alpha), (align & FLAG_DYNAMIC_ASCII) | ALIGN_CENTER);
dc.DrawTextShadowRect(entry.text.c_str(), bounds.Inset(0.0f, 1.0f, 0.0f, 0.0f), colorAlpha(0xFFFFFFFF, alpha), (align & FLAG_DYNAMIC_ASCII));

if (!entry.text2.empty()) {
Bounds bottomTextBounds = bounds.Inset(3.0f, height1 + 5.0f, 3.0f, 3.0f);
UI::Drawable backgroundDark = UI::Drawable(colorAlpha(darkenColor(GetOSDBackgroundColor(entry.type)), alpha));
dc.FillRect(backgroundDark, bottomTextBounds);
dc.SetFontScale(extraTextScale, extraTextScale);
dc.DrawTextRect(entry.text2.c_str(), bottomTextBounds, colorAlpha(0xFFFFFFFF, alpha), (align & FLAG_DYNAMIC_ASCII) | ALIGN_LEFT);
dc.SetFontScale(1.0f, 1.0f);
}
}

static void MeasureOSDProgressBar(UIContext &dc, const OnScreenDisplay::ProgressBar &bar, float *width, float *height) {
Expand Down Expand Up @@ -159,8 +178,8 @@ void OnScreenMessagesView::Draw(UIContext &dc) {
align |= FLAG_DYNAMIC_ASCII;
}

float tw, th;
MeasureOSDEntry(dc, *iter, align, &tw, &th);
float tw, th, h1;
MeasureOSDEntry(dc, *iter, align, &tw, &th, &h1);

Bounds b(0.0f, y, tw, th);

Expand All @@ -183,7 +202,7 @@ void OnScreenMessagesView::Draw(UIContext &dc) {
}

float alpha = Clamp((float)(iter->endTime - now) * 4.0f, 0.0f, 1.0f);
RenderOSDEntry(dc, *iter, b, align, alpha);
RenderOSDEntry(dc, *iter, b, h1, align, alpha);
y += (b.h * scale + 4.0f) * alpha; // including alpha here gets us smooth animations.
}

Expand Down

0 comments on commit 266b85d

Please sign in to comment.