Skip to content

Commit

Permalink
Merge pull request #8954 from unknownbrackets/ui-tweaks
Browse files Browse the repository at this point in the history
UI: Consistently set bgaudio on game start
  • Loading branch information
hrydgard authored Sep 4, 2016
2 parents f39c603 + cfbfbc1 commit 98db638
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 38 deletions.
36 changes: 27 additions & 9 deletions UI/DisplayLayoutScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class DragDropDisplay : public MultiTouchDisplay {

DisplayLayoutScreen::DisplayLayoutScreen() {
picked_ = 0;
mode_ = nullptr;
};


Expand All @@ -70,7 +71,7 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) {

using namespace UI;

int mode = mode_->GetSelection();
int mode = mode_ ? mode_->GetSelection() : 0;
if (g_Config.iSmallDisplayZoomType == 2) { mode = -1; }

const Bounds &screen_bounds = screenManager()->getUIContext()->GetBounds();
Expand Down Expand Up @@ -172,6 +173,17 @@ class Boundary : public UI::View {
}
};

// Stealing StickyChoice's layout and text rendering.
class HighlightLabel : public UI::StickyChoice {
public:
HighlightLabel(const std::string &text, UI::LayoutParams *layoutParams)
: UI::StickyChoice(text, "", layoutParams) {
Press();
}

bool CanBeFocused() const override { return false; }
};

void DisplayLayoutScreen::CreateViews() {
const Bounds &bounds = screenManager()->getUIContext()->GetBounds();

Expand Down Expand Up @@ -202,7 +214,6 @@ void DisplayLayoutScreen::CreateViews() {
root_->Add(new Boundary(new AnchorLayoutParams(previewWidth, vertBoundariesHeight, horizPreviewPadding, vertPreviewPadding - vertBoundariesHeight, NONE, NONE)));
root_->Add(new Boundary(new AnchorLayoutParams(previewWidth, vertBoundariesHeight, horizPreviewPadding, NONE, NONE, vertPreviewPadding - vertBoundariesHeight)));

Choice *back = new Choice(di->T("Back"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 10));
static const char *zoomLevels[] = { "Stretching", "Partial Stretch", "Auto Scaling", "Manual Scaling" };
zoom_ = new PopupMultiChoice(&g_Config.iSmallDisplayZoomType, di->T("Options"), zoomLevels, 0, ARRAY_SIZE(zoomLevels), gr->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, previewWidth - 200.0f, NONE, NONE, 10));
zoom_->OnChoice.Handle(this, &DisplayLayoutScreen::OnZoomTypeChange);
Expand All @@ -215,12 +226,13 @@ void DisplayLayoutScreen::CreateViews() {
if (displayRotEnable_ && (g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL || g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL180)) {
bRotated = true;
}
mode_ = new ChoiceStrip(ORIENT_VERTICAL, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 158 + 64 + 10));
displayRepresentationScale_ = g_Config.fSmallDisplayZoomLevel * 8.0f; // Visual representation image is just icon size and have to be scaled 8 times to match PSP native resolution which is used as 1.0 for zoom

HighlightLabel *label = nullptr;
mode_ = nullptr;
if (g_Config.iSmallDisplayZoomType > 1) { // Scaling
if (g_Config.iSmallDisplayZoomType == 2) { // Auto Scaling
mode_->AddChoice(gr->T("Auto Scaling"));
mode_->ReplaceLayoutParams(new AnchorLayoutParams(160.0f, 0, local_dp_xres / 2.0f - 80.0f, local_dp_yres / 2.0f - 32.0f, NONE, NONE));
label = new HighlightLabel(gr->T("Auto Scaling"), new AnchorLayoutParams(WRAP_CONTENT, 64.0f, local_dp_xres / 2.0f, local_dp_yres / 2.0f, NONE, NONE, true));
float autoBound = local_dp_yres / 270.0f;
// Case of screen rotated ~ only works with buffered rendering
if (bRotated) {
Expand All @@ -246,17 +258,17 @@ void DisplayLayoutScreen::CreateViews() {
Choice *center = new Choice(di->T("Center"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 74));
center->OnClick.Handle(this, &DisplayLayoutScreen::OnCenter);
root_->Add(center);
PopupSliderChoiceFloat *zoomlvl = new PopupSliderChoiceFloat(&g_Config.fSmallDisplayZoomLevel, 1.0f, 10.0f, di->T("Zoom"), 1.0f, screenManager(), di->T("* PSP res"), new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 134));
PopupSliderChoiceFloat *zoomlvl = new PopupSliderChoiceFloat(&g_Config.fSmallDisplayZoomLevel, 1.0f, 10.0f, di->T("Zoom"), 1.0f, screenManager(), di->T("* PSP res"), new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 10 + 64 + 64));
root_->Add(zoomlvl);
mode_ = new ChoiceStrip(ORIENT_VERTICAL, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 158 + 64 + 10));
mode_->AddChoice(di->T("Move"));
mode_->AddChoice(di->T("Resize"));
mode_->SetSelection(0);
}
displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, I_PSP_DISPLAY, displayRepresentationScale_);
displayRepresentation_->SetVisibility(V_VISIBLE);
} else { // Stretching
mode_->AddChoice(gr->T("Stretching"));
mode_->ReplaceLayoutParams(new AnchorLayoutParams(140.0f, 0, local_dp_xres / 2.0f - 70.0f, local_dp_yres / 2.0f - 32.0f, NONE, NONE));
label = new HighlightLabel(gr->T("Stretching"), new AnchorLayoutParams(WRAP_CONTENT, 64.0f, local_dp_xres / 2.0f, local_dp_yres / 2.0f, NONE, NONE, true));
displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, I_PSP_DISPLAY, displayRepresentationScale_);
displayRepresentation_->SetVisibility(V_INVISIBLE);
float width = previewWidth;
Expand Down Expand Up @@ -288,9 +300,15 @@ void DisplayLayoutScreen::CreateViews() {
displayRepresentation_->SetAngle(90.0f);
}

Choice *back = new Choice(di->T("Back"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 10));
back->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
root_->Add(displayRepresentation_);
root_->Add(mode_);
if (mode_) {
root_->Add(mode_);
}
if (label) {
root_->Add(label);
}
root_->Add(zoom_);
root_->Add(rotation_);
root_->Add(back);
Expand Down
3 changes: 3 additions & 0 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "Core/HLE/__sceAudio.h"

#include "UI/ui_atlas.h"
#include "UI/BackgroundAudio.h"
#include "UI/OnScreenDisplay.h"
#include "UI/GamepadEmu.h"
#include "UI/PauseScreen.h"
Expand Down Expand Up @@ -109,6 +110,8 @@ void EmuScreen::bootGame(const std::string &filename) {
return;
}

SetBackgroundAudioGame("");

//pre-emptive loading of game specific config if possible, to get all the settings
GameInfo *info = g_gameInfoCache->GetInfo(NULL, filename, 0);
if (info && !info->id.empty()) {
Expand Down
1 change: 0 additions & 1 deletion UI/MainScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,6 @@ void MainScreen::sendMessage(const char *message, const char *value) {

if (!strcmp(message, "boot")) {
screenManager()->switchScreen(new EmuScreen(value));
SetBackgroundAudioGame(value);
}
if (!strcmp(message, "control mapping")) {
UpdateUIState(UISTATE_MENU);
Expand Down
21 changes: 14 additions & 7 deletions ext/native/base/stringutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,20 @@ bool TryParse(const std::string &str, bool *const output)

void SplitString(const std::string& str, const char delim, std::vector<std::string>& output)
{
std::istringstream iss(str);
output.resize(1);

while (std::getline(iss, *output.rbegin(), delim))
output.push_back("");
size_t next = 0;
for (size_t pos = 0, len = str.length(); pos < len; ++pos) {
if (str[pos] == delim) {
output.push_back(str.substr(next, pos - next));
// Skip the delimiter itself.
next = pos + 1;
}
}

output.pop_back();
if (next == 0) {
output.push_back(str);
} else if (next < str.length()) {
output.push_back(str.substr(next));
}
}

std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest)
Expand All @@ -281,4 +288,4 @@ int strcmpIgnore(std::string str1, std::string str2, std::string ignorestr1, std
str1 = ReplaceAll(str1, ignorestr1, ignorestr2);
str2 = ReplaceAll(str2, ignorestr1, ignorestr2);
return strcmp(str1.c_str(),str2.c_str());
}
}
94 changes: 73 additions & 21 deletions ext/native/gfx_es2/draw_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,18 @@ TextDrawer::TextDrawer(Thin3DContext *thin3d) : thin3d_(thin3d), ctx_(NULL) {
}

TextDrawer::~TextDrawer() {
for (auto iter = cache_.begin(); iter != cache_.end(); ++iter) {
if (iter->second->texture)
iter->second->texture->Release();
delete iter->second;
for (auto iter : cache_) {
if (iter.second->texture)
iter.second->texture->Release();
delete iter.second;
}
cache_.clear();

for (auto iter : sizeCache_) {
delete iter.second;
}
sizeCache_.clear();

for (auto iter = fontMap_.begin(); iter != fontMap_.end(); ++iter) {
DeleteObject(iter->second->hFont);
delete iter->second;
Expand Down Expand Up @@ -136,16 +141,32 @@ void TextDrawer::MeasureString(const char *str, float *w, float *h) {
}

void TextDrawer::MeasureString(const char *str, size_t len, float *w, float *h) {
auto iter = fontMap_.find(fontHash_);
if (iter != fontMap_.end()) {
SelectObject(ctx_->hDC, iter->second->hFont);
uint32_t stringHash = hash::Fletcher((const uint8_t *)str, len);
uint32_t entryHash = stringHash ^ fontHash_;

TextMeasureEntry *entry;
auto iter = sizeCache_.find(entryHash);
if (iter != sizeCache_.end()) {
entry = iter->second;
} else {
auto iter = fontMap_.find(fontHash_);
if (iter != fontMap_.end()) {
SelectObject(ctx_->hDC, iter->second->hFont);
}

SIZE size;
std::wstring wstr = ConvertUTF8ToWString(ReplaceAll(std::string(str, len), "\n", "\r\n"));
GetTextExtentPoint32(ctx_->hDC, wstr.c_str(), (int)wstr.size(), &size);

entry = new TextMeasureEntry();
entry->width = size.cx;
entry->height = size.cy;
sizeCache_[entryHash] = entry;
}

SIZE size;
std::wstring wstr = ConvertUTF8ToWString(ReplaceAll(std::string(str, len), "\n", "\r\n"));
GetTextExtentPoint32(ctx_->hDC, wstr.c_str(), (int)wstr.size(), &size);
*w = size.cx * fontScaleX_;
*h = size.cy * fontScaleY_;
entry->lastUsedFrame = frameCount_;
*w = entry->width * fontScaleX_;
*h = entry->height * fontScaleY_;
}

void TextDrawer::MeasureStringRect(const char *str, size_t len, const Bounds &bounds, float *w, float *h, int align) {
Expand All @@ -165,13 +186,29 @@ void TextDrawer::MeasureStringRect(const char *str, size_t len, const Bounds &bo
float total_w = 0.0f;
float total_h = 0.0f;
for (size_t i = 0; i < lines.size(); i++) {
SIZE size;
std::wstring wstr = ConvertUTF8ToWString(lines[i].length() == 0 ? " " : lines[i]);
GetTextExtentPoint32(ctx_->hDC, wstr.c_str(), (int)wstr.size(), &size);
if (total_w < size.cx * fontScaleX_) {
total_w = size.cx * fontScaleX_;
uint32_t stringHash = hash::Fletcher((const uint8_t *)&lines[i][0], lines[i].length());
uint32_t entryHash = stringHash ^ fontHash_;

TextMeasureEntry *entry;
auto iter = sizeCache_.find(entryHash);
if (iter != sizeCache_.end()) {
entry = iter->second;
} else {
SIZE size;
std::wstring wstr = ConvertUTF8ToWString(lines[i].length() == 0 ? " " : lines[i]);
GetTextExtentPoint32(ctx_->hDC, wstr.c_str(), (int)wstr.size(), &size);

entry = new TextMeasureEntry();
entry->width = size.cx;
entry->height = size.cy;
sizeCache_[entryHash] = entry;
}
total_h += size.cy * fontScaleY_;
entry->lastUsedFrame = frameCount_;

if (total_w < entry->width * fontScaleX_) {
total_w = entry->width * fontScaleX_;
}
total_h += entry->height * fontScaleY_;
}
*w = total_w;
*h = total_h;
Expand Down Expand Up @@ -268,11 +305,17 @@ TextDrawer::TextDrawer(Thin3DContext *thin3d) : thin3d_(thin3d), ctx_(NULL) {
}

TextDrawer::~TextDrawer() {
for (auto iter = cache_.begin(); iter != cache_.end(); ++iter) {
iter->second->texture->Release();
delete iter->second;
for (auto iter : cache_) {
if (iter.second->texture)
iter.second->texture->Release();
delete iter.second;
}
cache_.clear();

for (auto iter : sizeCache_) {
delete iter.second;
}
sizeCache_.clear();
}

uint32_t TextDrawer::SetFont(const char *fontName, int size, int flags) {
Expand Down Expand Up @@ -450,5 +493,14 @@ void TextDrawer::OncePerFrame() {
iter++;
}
}

for (auto iter = sizeCache_.begin(); iter != sizeCache_.end(); ) {
if (frameCount_ - iter->second->lastUsedFrame > 100) {
delete iter->second;
sizeCache_.erase(iter++);
} else {
iter++;
}
}
}
}
7 changes: 7 additions & 0 deletions ext/native/gfx_es2/draw_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ struct TextStringEntry {
int lastUsedFrame;
};

struct TextMeasureEntry {
int width;
int height;
int lastUsedFrame;
};

// Not yet functional
enum {
FONTSTYLE_BOLD = 1,
Expand Down Expand Up @@ -75,4 +81,5 @@ class TextDrawer {
uint32_t fontHash_;
// The key is the CityHash of the string xor the fontHash_.
std::map<uint32_t, TextStringEntry *> cache_;
std::map<uint32_t, TextMeasureEntry *> sizeCache_;
};

0 comments on commit 98db638

Please sign in to comment.