Skip to content

Commit

Permalink
Merge pull request #18729 from hrydgard/even-more-beta-fixes
Browse files Browse the repository at this point in the history
More UI fixes
  • Loading branch information
hrydgard committed Jan 19, 2024
2 parents 52b526e + b71ccfd commit 98e0d30
Show file tree
Hide file tree
Showing 63 changed files with 155 additions and 103 deletions.
2 changes: 1 addition & 1 deletion Common/Data/Encoding/Utf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ std::wstring ConvertUTF8ToWString(const std::string_view source) {
std::wstring str;
str.resize(size);
if (size > 0) {
MultiByteToWideChar(CP_UTF8, 0, source.data(), source.size(), &str[0], size);
MultiByteToWideChar(CP_UTF8, 0, source.data(), (int)source.size(), &str[0], size);
}
return str;
}
Expand Down
3 changes: 1 addition & 2 deletions Common/File/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,13 @@ std::string Path::GetDirectory() const {
return path_;
}

bool Path::FilePathContainsNoCase(const std::string &needle) const {
bool Path::FilePathContainsNoCase(std::string_view needle) const {
std::string haystack;
if (type_ == PathType::CONTENT_URI) {
haystack = AndroidContentURI(path_).FilePath();
} else {
haystack = path_;
}

auto pred = [](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); };
auto found = std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end(), pred);
return found != haystack.end();
Expand Down
2 changes: 1 addition & 1 deletion Common/File/Path.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Path {
return path_ != other.path_ || type_ != other.type_;
}

bool FilePathContainsNoCase(const std::string &needle) const;
bool FilePathContainsNoCase(std::string_view needle) const;

bool StartsWith(const Path &other) const;

Expand Down
6 changes: 3 additions & 3 deletions Common/Render/ManagedTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TextureLoadTask : public Task {
return;
}

if (!tempImage_->LoadTextureLevels(buffer, fileSize, type_)) {
if (!tempImage_->LoadTextureLevelsFromFileData(buffer, fileSize, type_)) {
*state_ = ManagedTexture::LoadState::FAILED;
waitable_->Notify();
return;
Expand Down Expand Up @@ -85,7 +85,7 @@ static ImageFileType DetectImageFileType(const uint8_t *data, size_t size) {
}
}

bool TempImage::LoadTextureLevels(const uint8_t *data, size_t size, ImageFileType typeSuggestion) {
bool TempImage::LoadTextureLevelsFromFileData(const uint8_t *data, size_t size, ImageFileType typeSuggestion) {
if (typeSuggestion == ImageFileType::DETECT) {
typeSuggestion = DetectImageFileType(data, size);
}
Expand Down Expand Up @@ -166,7 +166,7 @@ Draw::Texture *CreateTextureFromTempImage(Draw::DrawContext *draw, const TempIma

Draw::Texture *CreateTextureFromFileData(Draw::DrawContext *draw, const uint8_t *data, size_t dataSize, ImageFileType type, bool generateMips, const char *name) {
TempImage image;
if (!image.LoadTextureLevels(data, dataSize, type)) {
if (!image.LoadTextureLevelsFromFileData(data, dataSize, type)) {
return nullptr;
}
Draw::Texture *texture = CreateTextureFromTempImage(draw, image, generateMips, name);
Expand Down
3 changes: 2 additions & 1 deletion Common/Render/ManagedTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct TempImage {
int height[16]{};
int numLevels = 0;

bool LoadTextureLevels(const uint8_t *data, size_t size, ImageFileType typeSuggestion = ImageFileType::DETECT);
bool LoadTextureLevelsFromFileData(const uint8_t *data, size_t size, ImageFileType typeSuggestion = ImageFileType::DETECT);
void Free() {
if (levels[0]) {
free(levels[0]);
Expand Down Expand Up @@ -79,3 +79,4 @@ class ManagedTexture {

Draw::Texture *CreateTextureFromFileData(Draw::DrawContext *draw, const uint8_t *data, size_t dataSize, ImageFileType type, bool generateMips, const char *name);
Draw::Texture *CreateTextureFromFile(Draw::DrawContext *draw, const char *filename, ImageFileType type, bool generateMips);
Draw::Texture *CreateTextureFromTempImage(Draw::DrawContext *draw, const TempImage &image, bool generateMips, const char *name);
18 changes: 18 additions & 0 deletions Common/UI/PopupScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ PopupSliderChoice::PopupSliderChoice(int *value, int minValue, int maxValue, int
OnClick.Handle(this, &PopupSliderChoice::HandleClick);
}

void PopupSliderChoice::SetFormat(std::string_view fmt) {
fmt_ = fmt;
if (units_.empty()) {
if (startsWith(fmt_, "%d ")) {
units_ = fmt_.substr(3);
}
}
}

PopupSliderChoiceFloat::PopupSliderChoiceFloat(float *value, float minValue, float maxValue, float defaultValue, const std::string &text, ScreenManager *screenManager, const std::string &units, LayoutParams *layoutParams)
: AbstractChoiceWithValueDisplay(text, layoutParams), value_(value), minValue_(minValue), maxValue_(maxValue), defaultValue_(defaultValue), step_(1.0f), units_(units), screenManager_(screenManager) {
_dbg_assert_(maxValue > minValue);
Expand All @@ -181,6 +190,15 @@ PopupSliderChoiceFloat::PopupSliderChoiceFloat(float *value, float minValue, flo
OnClick.Handle(this, &PopupSliderChoiceFloat::HandleClick);
}

void PopupSliderChoiceFloat::SetFormat(std::string_view fmt) {
fmt_ = fmt;
if (units_.empty()) {
if (startsWith(fmt_, "%f ")) {
units_ = fmt_.substr(3);
}
}
}

EventReturn PopupSliderChoice::HandleClick(EventParams &e) {
restoreFocus_ = HasFocus();

Expand Down
8 changes: 2 additions & 6 deletions Common/UI/PopupScreens.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,7 @@ class PopupSliderChoice : public AbstractChoiceWithValueDisplay {
PopupSliderChoice(int *value, int minValue, int maxValue, int defaultValue, const std::string &text, ScreenManager *screenManager, const std::string &units = "", LayoutParams *layoutParams = 0);
PopupSliderChoice(int *value, int minValue, int maxValue, int defaultValue, const std::string &text, int step, ScreenManager *screenManager, const std::string &units = "", LayoutParams *layoutParams = 0);

void SetFormat(const char *fmt) {
fmt_ = fmt;
}
void SetFormat(std::string_view fmt);
void SetZeroLabel(const std::string &str) {
zeroLabel_ = str;
}
Expand Down Expand Up @@ -322,9 +320,7 @@ class PopupSliderChoiceFloat : public AbstractChoiceWithValueDisplay {
PopupSliderChoiceFloat(float *value, float minValue, float maxValue, float defaultValue, const std::string &text, ScreenManager *screenManager, const std::string &units = "", LayoutParams *layoutParams = 0);
PopupSliderChoiceFloat(float *value, float minValue, float maxValue, float defaultValue, const std::string &text, float step, ScreenManager *screenManager, const std::string &units = "", LayoutParams *layoutParams = 0);

void SetFormat(const char *fmt) {
fmt_ = fmt;
}
void SetFormat(std::string_view fmt);
void SetZeroLabel(const std::string &str) {
zeroLabel_ = str;
}
Expand Down
7 changes: 7 additions & 0 deletions Common/UI/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1657,4 +1657,11 @@ void SliderFloat::GetContentDimensions(const UIContext &dc, float &w, float &h)
h = 50;
}

void Spacer::Draw(UIContext &dc) {
View::Draw(dc);
if (drawAsSeparator_) {
dc.FillRect(UI::Drawable(dc.theme->itemDownStyle.background.color), bounds_);
}
}

} // namespace
4 changes: 3 additions & 1 deletion Common/UI/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -950,11 +950,13 @@ class Spacer : public InertView {
h = size_;
}

void Draw(UIContext &dc) override {}
void Draw(UIContext &dc) override;
std::string DescribeText() const override { return ""; }
void SetSeparator() { drawAsSeparator_ = true; }

private:
float size_ = 0.0f;
bool drawAsSeparator_ = false;
};

class BorderView : public InertView {
Expand Down
28 changes: 16 additions & 12 deletions Common/UI/ViewGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Common/UI/Tween.h"
#include "Common/UI/Root.h"
#include "Common/UI/View.h"
#include "Common/UI/UIScreen.h"
#include "Common/UI/ViewGroup.h"
#include "Common/Render/DrawBuffer.h"

Expand Down Expand Up @@ -949,16 +950,29 @@ TabHolder::TabHolder(Orientation orientation, float stripSize, LayoutParams *lay
tabScroll_->Add(tabStrip_);
Add(tabScroll_);
} else {
tabStrip_ = new ChoiceStrip(orientation, new LayoutParams(stripSize, WRAP_CONTENT));
tabContainer_ = new LinearLayout(ORIENT_VERTICAL, new LayoutParams(stripSize, FILL_PARENT));
tabStrip_ = new ChoiceStrip(orientation, new LayoutParams(FILL_PARENT, FILL_PARENT));
tabStrip_->SetTopTabs(true);
Add(tabStrip_);
tabScroll_ = new ScrollView(orientation, new LinearLayoutParams(1.0f));
tabScroll_->Add(tabStrip_);
tabContainer_->Add(tabScroll_);
Add(tabContainer_);
}
tabStrip_->OnChoice.Handle(this, &TabHolder::OnTabClick);

Add(new Spacer(4.0f))->SetSeparator();

contents_ = new AnchorLayout(new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0f));
Add(contents_)->SetClip(true);
}

void TabHolder::AddBack(UIScreen *parent) {
if (tabContainer_) {
auto di = GetI18NCategory(I18NCat::DIALOG);
tabContainer_->Add(new Choice(di->T("Back"), "", false, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 0.0f, Margins(0, 0, 10, 10))))->OnClick.Handle<UIScreen>(parent, &UIScreen::OnBack);
}
}

void TabHolder::AddTabContents(const std::string &title, View *tabContents) {
tabContents->ReplaceLayoutParams(new AnchorLayoutParams(FILL_PARENT, FILL_PARENT));
tabs_.push_back(tabContents);
Expand Down Expand Up @@ -1149,16 +1163,6 @@ bool ChoiceStrip::Key(const KeyInput &input) {
return ret || ViewGroup::Key(input);
}

void ChoiceStrip::Draw(UIContext &dc) {
ViewGroup::Draw(dc);
if (topTabs_) {
if (orientation_ == ORIENT_HORIZONTAL)
dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y2() - 4, bounds_.x2(), bounds_.y2(), dc.theme->itemDownStyle.background.color );
else if (orientation_ == ORIENT_VERTICAL)
dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x2() - 4, bounds_.y, bounds_.x2(), bounds_.y2(), dc.theme->itemDownStyle.background.color );
}
}

std::string ChoiceStrip::DescribeText() const {
auto u = GetI18NCategory(I18NCat::UI_ELEMENTS);
return DescribeListUnordered(u->T("Choices:"));
Expand Down
6 changes: 5 additions & 1 deletion Common/UI/ViewGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "Common/Input/GestureDetector.h"
#include "Common/UI/View.h"

class UIScreen;

namespace UI {

class AnchorTranslateTween;
Expand Down Expand Up @@ -270,7 +272,6 @@ class ChoiceStrip : public LinearLayout {
bool Key(const KeyInput &input) override;

void SetTopTabs(bool tabs) { topTabs_ = tabs; }
void Draw(UIContext &dc) override;

std::string DescribeLog() const override { return "ChoiceStrip: " + View::DescribeLog(); }
std::string DescribeText() const override;
Expand Down Expand Up @@ -298,6 +299,8 @@ class TabHolder : public LinearLayout {
tabStrip_->EnableChoice(tab, enabled);
}

void AddBack(UIScreen *parent);

void SetCurrentTab(int tab, bool skipTween = false);

int GetCurrentTab() const { return currentTab_; }
Expand All @@ -309,6 +312,7 @@ class TabHolder : public LinearLayout {
void AddTabContents(const std::string &title, View *tabContents);
EventReturn OnTabClick(EventParams &e);

LinearLayout *tabContainer_ = nullptr;
ChoiceStrip *tabStrip_ = nullptr;
ScrollView *tabScroll_ = nullptr;
AnchorLayout *contents_ = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static const ConfigSetting generalSettings[] = {
ConfigSetting("DisableHTTPS", &g_Config.bDisableHTTPS, false, CfgFlag::DONT_SAVE),
ConfigSetting("AutoLoadSaveState", &g_Config.iAutoLoadSaveState, 0, CfgFlag::PER_GAME),
ConfigSetting("EnableCheats", &g_Config.bEnableCheats, false, CfgFlag::PER_GAME | CfgFlag::REPORT),
ConfigSetting("CwCheatRefreshRate", &g_Config.iCwCheatRefreshRate, 77, CfgFlag::PER_GAME),
ConfigSetting("CwCheatRefreshRate", &g_Config.iCwCheatRefreshIntervalMs, 77, CfgFlag::PER_GAME),
ConfigSetting("CwCheatScrollPosition", &g_Config.fCwCheatScrollPosition, 0.0f, CfgFlag::PER_GAME),
ConfigSetting("GameListScrollPosition", &g_Config.fGameListScrollPosition, 0.0f, CfgFlag::DEFAULT),
ConfigSetting("DebugOverlay", &g_Config.iDebugOverlay, 0, CfgFlag::DONT_SAVE),
Expand Down
2 changes: 1 addition & 1 deletion Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ struct Config {
int iAutoLoadSaveState; // 0 = off, 1 = oldest, 2 = newest, >2 = slot number + 3
bool bEnableCheats;
bool bReloadCheats;
int iCwCheatRefreshRate;
int iCwCheatRefreshIntervalMs;
float fCwCheatScrollPosition;
float fGameListScrollPosition;
int iBloomHack; //0 = off, 1 = safe, 2 = balanced, 3 = aggressive
Expand Down
2 changes: 1 addition & 1 deletion Core/CwCheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ static void __CheatStart() {
}

static int GetRefreshMs() {
int refresh = g_Config.iCwCheatRefreshRate;
int refresh = g_Config.iCwCheatRefreshIntervalMs;

if (!cheatsEnabled)
refresh = 1000;
Expand Down
4 changes: 2 additions & 2 deletions Core/MIPS/MIPSDebugInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ class MipsExpressionFunctions: public IExpressionFunctions
if (referenceIndex == REF_INDEX_MODULE)
return __KernelGetCurThreadModuleId();
if (referenceIndex == REF_INDEX_USEC)
return CoreTiming::GetGlobalTimeUs();
return (uint32_t)CoreTiming::GetGlobalTimeUs(); // Loses information
if (referenceIndex == REF_INDEX_USEC)
return CoreTiming::GetTicks();
return (uint32_t)CoreTiming::GetTicks();
if ((referenceIndex & ~(REF_INDEX_FPU | REF_INDEX_FPU_INT)) < 32)
return cpu->GetRegValue(1, referenceIndex & ~(REF_INDEX_FPU | REF_INDEX_FPU_INT));
if ((referenceIndex & ~(REF_INDEX_VFPU | REF_INDEX_VFPU_INT)) < 128)
Expand Down
2 changes: 2 additions & 0 deletions Core/MemFault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ bool HandleFault(uintptr_t hostAddress, void *ctx) {
bool inJitSpace = MIPSComp::jit && MIPSComp::jit->CodeInRange(codePtr);
if (!inJitSpace) {
// This is a crash in non-jitted code. Not something we want to handle here, ignore.
// Actually, we could handle crashes from the IR interpreter here, although recovering the call stack
// might be tricky...
inCrashHandler = false;
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion UI/CwCheatScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ void CwCheatScreen::CreateViews() {
leftColumn->Add(new Choice(cw->T("Edit Cheat File")))->OnClick.Handle(this, &CwCheatScreen::OnEditCheatFile);
#endif
leftColumn->Add(new Choice(di->T("Disable All")))->OnClick.Handle(this, &CwCheatScreen::OnDisableAll);
leftColumn->Add(new PopupSliderChoice(&g_Config.iCwCheatRefreshRate, 1, 1000, 77, cw->T("Refresh Rate"), 1, screenManager()));
leftColumn->Add(new PopupSliderChoice(&g_Config.iCwCheatRefreshIntervalMs, 1, 1000, 77, cw->T("Refresh Interval"), 1, screenManager()))->SetFormat(di->T("%d ms"));


rightScroll_ = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 0.5f));
rightScroll_->SetTag("CwCheats");
Expand Down
Loading

0 comments on commit 98e0d30

Please sign in to comment.