Skip to content

Commit

Permalink
Merge pull request #9773 from unknownbrackets/ui-minor
Browse files Browse the repository at this point in the history
Tweak some minor UI glitches
  • Loading branch information
hrydgard committed Jun 3, 2017
2 parents d0aca65 + 9a14de5 commit 0f5c59d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 35 deletions.
6 changes: 4 additions & 2 deletions UI/EmuScreen.cpp
Expand Up @@ -88,6 +88,8 @@ static bool startDumping;

static void __EmuScreenVblank()
{
I18NCategory *sy = GetI18NCategory("System");

if (frameStep_ && lastNumFlips != gpuStats.numFlips)
{
frameStep_ = false;
Expand All @@ -98,7 +100,7 @@ static void __EmuScreenVblank()
if (g_Config.bDumpFrames && !startDumping)
{
avi.Start(PSP_CoreParameter().renderWidth, PSP_CoreParameter().renderHeight);
osm.Show("AVI Dump started.", 3.0f);
osm.Show(sy->T("AVI Dump started."), 3.0f);
startDumping = true;
}
if (g_Config.bDumpFrames && startDumping)
Expand All @@ -108,7 +110,7 @@ static void __EmuScreenVblank()
else if (!g_Config.bDumpFrames && startDumping)
{
avi.Stop();
osm.Show("AVI Dump stopped.", 3.0f);
osm.Show(sy->T("AVI Dump stopped."), 3.0f);
startDumping = false;
}
#endif
Expand Down
44 changes: 25 additions & 19 deletions UI/GameSettingsScreen.cpp
Expand Up @@ -218,7 +218,8 @@ void GameSettingsScreen::CreateViews() {
renderingModeChoice->SetDisabledPtr(&g_Config.bSoftwareRendering);
CheckBox *blockTransfer = graphicsSettings->Add(new CheckBox(&g_Config.bBlockTransferGPU, gr->T("Simulate Block Transfer", "Simulate Block Transfer")));
blockTransfer->OnClick.Add([=](EventParams &e) {
settingInfo_->Show(gr->T("BlockTransfer Tip", "Some games require this to be On for correct graphics"), e.v);
if (!g_Config.bBlockTransferGPU)
settingInfo_->Show(gr->T("BlockTransfer Tip", "Some games require this to be On for correct graphics"), e.v);
return UI::EVENT_CONTINUE;
});
blockTransfer->SetDisabledPtr(&g_Config.bSoftwareRendering);
Expand Down Expand Up @@ -305,7 +306,7 @@ void GameSettingsScreen::CreateViews() {

CheckBox *swSkin = graphicsSettings->Add(new CheckBox(&g_Config.bSoftwareSkinning, gr->T("Software Skinning")));
swSkin->OnClick.Add([=](EventParams &e) {
settingInfo_->Show(gr->T("SoftwareSkinning Tip", "Reduce drawcalls and faster in games that use the advanced skinning technique, but some games slower"), e.v);
settingInfo_->Show(gr->T("SoftwareSkinning Tip", "Combine skinned model draws on the CPU, faster in most games"), e.v);
return UI::EVENT_CONTINUE;
});
swSkin->SetDisabledPtr(&g_Config.bSoftwareRendering);
Expand Down Expand Up @@ -590,9 +591,9 @@ void GameSettingsScreen::CreateViews() {
settingInfo_->Show(co->T("MouseControl Tip", "You can now map mouse in control mapping screen by pressing the 'M' icon."), e.v);
return UI::EVENT_CONTINUE;
});
controlsSettings->Add(new CheckBox(&g_Config.bMouseConfine, co->T("Confine Mouse", "Trap mouse within window/display area")));
controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fMouseSensitivity, 0.01f, 1.0f, co->T("Mouse sensitivity"), 0.01f, screenManager(), "x"));
controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fMouseSmoothing, 0.0f, 0.95f, co->T("Mouse smoothing"), 0.05f, screenManager(), "x"));
controlsSettings->Add(new CheckBox(&g_Config.bMouseConfine, co->T("Confine Mouse", "Trap mouse within window/display area")))->SetEnabledPtr(&g_Config.bMouseControl);
controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fMouseSensitivity, 0.01f, 1.0f, co->T("Mouse sensitivity"), 0.01f, screenManager(), "x"))->SetEnabledPtr(&g_Config.bMouseControl);
controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fMouseSmoothing, 0.0f, 0.95f, co->T("Mouse smoothing"), 0.05f, screenManager(), "x"))->SetEnabledPtr(&g_Config.bMouseControl);
#endif

ViewGroup *networkingSettingsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT));
Expand Down Expand Up @@ -1275,7 +1276,11 @@ void DeveloperToolsScreen::CreateViews() {
list->Add(new CheckBox(&g_Config.bSaveNewTextures, dev->T("Save new textures")));
list->Add(new CheckBox(&g_Config.bReplaceTextures, dev->T("Replace textures")));
#if !defined(MOBILE_DEVICE)
list->Add(new Choice(dev->T("Create/Open textures.ini file for current game")))->OnClick.Handle(this, &DeveloperToolsScreen::OnOpenTexturesIniFile);
Choice *createTextureIni = list->Add(new Choice(dev->T("Create/Open textures.ini file for current game")));
createTextureIni->OnClick.Handle(this, &DeveloperToolsScreen::OnOpenTexturesIniFile);
if (!PSP_IsInited()) {
createTextureIni->SetEnabled(false);
}
#endif
}

Expand Down Expand Up @@ -1507,6 +1512,16 @@ UI::EventReturn ProAdhocServerScreen::OnCancelClick(UI::EventParams &e) {
return UI::EVENT_DONE;
}

SettingInfoMessage::SettingInfoMessage(int align, UI::AnchorLayoutParams *lp)
: UI::LinearLayout(UI::ORIENT_HORIZONTAL, lp) {
using namespace UI;
SetSpacing(0.0f);
Add(new UI::Spacer(10.0f));
text_ = Add(new UI::TextView("", align, false, new LinearLayoutParams(1.0, Margins(0, 10))));
text_->SetTag("TEST?");
Add(new UI::Spacer(10.0f));
}

void SettingInfoMessage::Show(const std::string &text, UI::View *refView) {
if (refView) {
Bounds b = refView->GetBounds();
Expand All @@ -1517,23 +1532,17 @@ void SettingInfoMessage::Show(const std::string &text, UI::View *refView) {
ReplaceLayoutParams(new UI::AnchorLayoutParams(lp->width, lp->height, lp->left, dp_yres - 80.0f - 40.0f, lp->right, lp->bottom, lp->center));
}
}
SetText(text);
text_->SetText(text);
timeShown_ = time_now_d();
}

void SettingInfoMessage::GetContentDimensionsBySpec(const UIContext &dc, UI::MeasureSpec horiz, UI::MeasureSpec vert, float &w, float &h) const {
TextView::GetContentDimensionsBySpec(dc, horiz, vert, w, h);
w += 20.0f;
h += 20.0f;
}

void SettingInfoMessage::Draw(UIContext &dc) {
static const double FADE_TIME = 1.0;
static const float MAX_ALPHA = 0.9f;

// Let's show longer messages for more time (guesstimate at reading speed.)
// Note: this will give multibyte characters more time, but they often have shorter words anyway.
double timeToShow = std::max(1.5, GetText().size() * 0.05);
double timeToShow = std::max(1.5, text_->GetText().size() * 0.05);

double sinceShow = time_now_d() - timeShown_;
float alpha = MAX_ALPHA;
Expand All @@ -1549,9 +1558,6 @@ void SettingInfoMessage::Draw(UIContext &dc) {
dc.FillRect(style.background, bounds_);
}

SetTextColor(whiteAlpha(alpha));
// Fake padding by adjusting bounds.
SetBounds(bounds_.Expand(-10.0f));
TextView::Draw(dc);
SetBounds(bounds_.Expand(10.0f));
text_->SetTextColor(whiteAlpha(alpha));
ViewGroup::Draw(dc);
}
10 changes: 4 additions & 6 deletions UI/GameSettingsScreen.h
Expand Up @@ -122,22 +122,20 @@ class GameSettingsScreen : public UIDialogScreenWithGameBackground {
bool tessHWEnable_;
};

class SettingInfoMessage : public UI::TextView {
class SettingInfoMessage : public UI::LinearLayout {
public:
SettingInfoMessage(int align, UI::AnchorLayoutParams *lp)
: UI::TextView("", align, false, lp), timeShown_(0.0) {
}
SettingInfoMessage(int align, UI::AnchorLayoutParams *lp);

void SetBottomCutoff(float y) {
cutOffY_ = y;
}
void Show(const std::string &text, UI::View *refView = nullptr);

void GetContentDimensionsBySpec(const UIContext &dc, UI::MeasureSpec horiz, UI::MeasureSpec vert, float &w, float &h) const;
void Draw(UIContext &dc);

private:
double timeShown_;
UI::TextView *text_ = nullptr;
double timeShown_ = 0.0;
float cutOffY_;
};

Expand Down
2 changes: 1 addition & 1 deletion UI/GamepadEmu.h
Expand Up @@ -34,7 +34,7 @@ class GamepadView : public UI::View {
void Update() override;

protected:
float GetButtonOpacity();
virtual float GetButtonOpacity();

float lastFrameTime_;
float secondsWithoutTouch_;
Expand Down
7 changes: 7 additions & 0 deletions UI/TouchControlLayoutScreen.cpp
Expand Up @@ -15,6 +15,7 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#include <algorithm>
#include <vector>

#include "base/colorutil.h"
Expand Down Expand Up @@ -65,6 +66,12 @@ class DragDropButton : public MultiTouchButton {
virtual float GetSpacing() const { return 1.0f; }
virtual void SetSpacing(float s) { }

protected:
float GetButtonOpacity() override {
float opacity = g_Config.iTouchButtonOpacity / 100.0f;
return std::max(0.5f, opacity);
}

private:
// convert from screen coordinates (leftColumnWidth to dp_xres) to actual fullscreen coordinates (0 to 1.0)
inline float toFullscreenCoord(int screenx) {
Expand Down
13 changes: 10 additions & 3 deletions ext/native/util/text/wrap_text.cpp
Expand Up @@ -82,6 +82,7 @@ void WordWrapper::WrapBeforeWord() {
out_[out_.size() - 1] = '-';
}
out_ += "\n";
lastLineStart_ = (int)out_.size();
x_ = 0.0f;
forceEarlyWrap_ = false;
}
Expand All @@ -93,6 +94,13 @@ void WordWrapper::AppendWord(int endIndex, bool addNewline) {
out_ += std::string(str_ + lastIndex_, endIndex - lastIndex_);
if (addNewline) {
out_ += "\n";
lastLineStart_ = (int)out_.size();
} else {
// We may have appended a newline - check.
size_t pos = out_.find_last_of("\n", lastLineStart_);
if (pos != out_.npos) {
lastLineStart_ = (int)pos;
}
}
lastIndex_ = endIndex;
}
Expand Down Expand Up @@ -135,9 +143,8 @@ void WordWrapper::Wrap() {
// Is this the end of a word (space)?
if (wordWidth_ > 0.0f && IsSpace(c)) {
AppendWord(afterIndex, false);
// We include the space in the x increase.
// If the space takes it over, we'll wrap on the next word.
x_ += newWordWidth;
// To account for kerning around spaces, we recalculate the entire line width.
x_ = MeasureWidth(out_.c_str() + lastLineStart_, out_.size() - lastLineStart_);
wordWidth_ = 0.0f;
continue;
}
Expand Down
10 changes: 6 additions & 4 deletions ext/native/util/text/wrap_text.h
Expand Up @@ -5,7 +5,7 @@
class WordWrapper {
public:
WordWrapper(const char *str, float maxW)
: str_(str), maxW_(maxW), lastIndex_(0), x_(0.0f), forceEarlyWrap_(false) {
: str_(str), maxW_(maxW) {
}

std::string Wrapped();
Expand All @@ -25,11 +25,13 @@ class WordWrapper {
const float maxW_;
std::string out_;
// Index of last output / start of current word.
int lastIndex_;
int lastIndex_ = 0;
// Index of last line start.
int lastLineStart_ = 0;
// Position the current word starts at.
float x_;
float x_ = 0.0f;
// Most recent width of word since last index.
float wordWidth_;
// Force the next word to cut partially and wrap.
bool forceEarlyWrap_;
bool forceEarlyWrap_ = false;
};

0 comments on commit 0f5c59d

Please sign in to comment.