Skip to content

Commit

Permalink
Smooth out touch moving and resize and other small changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaMoo committed Jan 17, 2016
1 parent 80fa269 commit 6751617
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
34 changes: 20 additions & 14 deletions UI/DisplayLayoutScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,47 +74,52 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) {
if (g_Config.iSmallDisplayZoomType == 2) { mode = -1; }

const Bounds &screen_bounds = screenManager()->getUIContext()->GetBounds();

if ((touch.flags & TOUCH_MOVE) && picked_ != 0) {
int touchX = touch.x - offsetTouchX;
int touchY = touch.y - offsetTouchY;
if (mode == 0) {
const Bounds &bounds = picked_->GetBounds();

int mintouchX = screen_bounds.w / 4;
int maxTouchX = screen_bounds.w - screen_bounds.w / 4;
int maxTouchX = screen_bounds.w - mintouchX;

int minTouchY = screen_bounds.h / 4;
int maxTouchY = screen_bounds.h - screen_bounds.h / 4;
int maxTouchY = screen_bounds.h - minTouchY;

int newX = bounds.centerX(), newY = bounds.centerY();
// we have to handle x and y separately since even if x is blocked, y may not be.
if (touch.x > mintouchX && touch.x < maxTouchX) {
if (touchX > mintouchX && touchX < maxTouchX) {
// if the leftmost point of the control is ahead of the margin,
// move it. Otherwise, don't.
newX = touch.x;
newX = touchX;
}
if (touch.y > minTouchY && touch.y < maxTouchY) {
newY = touch.y;
if (touchY > minTouchY && touchY < maxTouchY) {
newY = touchY;
}
picked_->ReplaceLayoutParams(new UI::AnchorLayoutParams(newX, newY, NONE, NONE, true));
}
else if (mode == 1) {
} else if (mode == 1) {
// Resize. Vertical = scaling, horizontal = spacing;
// Up should be bigger so let's negate in that direction
float diffX = (touch.x - startX_);
float diffY = -(touch.y - startY_);
float diffX = (touchX - startX_);
float diffY = -(touchY - startY_);

float movementScale = 0.5f;
float newScale = startScale_ + diffY * movementScale;
if (newScale > 100.0f) newScale = 100.0f;
if (newScale < 1.0f) newScale = 1.0f;
picked_->SetScale(newScale);
scaleUpdate_ = picked_->GetScale();
g_Config.fSmallDisplayZoomLevel = scaleUpdate_ / 8.0f;
}
}
if ((touch.flags & TOUCH_DOWN) && picked_ == 0) {
picked_ = displayRepresentation_;
if (picked_) {
startX_ = touch.x;
startY_ = touch.y;
const Bounds &bounds = picked_->GetBounds();
startX_ = bounds.centerX();
startY_ = bounds.centerY();
offsetTouchX = touch.x - startX_;
offsetTouchY = touch.y - startY_;
startScale_ = picked_->GetScale();
}
}
Expand All @@ -126,7 +131,6 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) {
picked_->SaveDisplayPosition();
picked_ = 0;
}
g_Config.fSmallDisplayZoomLevel = startScale_ / 8.0f;
return true;
};

Expand Down Expand Up @@ -250,6 +254,7 @@ void DisplayLayoutScreen::CreateViews() {
float height = local_dp_yres / 2.0f;
if (g_Config.iSmallDisplayZoomType == 0) { // Stretched
Choice *stretched = new Choice("", "", false, new AnchorLayoutParams(width, height, width - width / 2.0f, NONE, NONE, height - height / 2.0f));
stretched->SetEnabled(false);
root_->Add(stretched);
} else { // Partially stretched
float origRatio = !bRotated ? 480.0f / 272.0f : 272.0f / 480.0f;
Expand All @@ -262,6 +267,7 @@ void DisplayLayoutScreen::CreateViews() {
if (bRotated && g_Config.iSmallDisplayZoomType == 1) { width = (272.0f + height) / 2.0f; }
}
Choice *stretched = new Choice("", "", false, new AnchorLayoutParams(width, height, local_dp_xres / 2.0f - width / 2.0f, NONE, NONE, local_dp_yres / 2.0f - height / 2.0f));
stretched->SetEnabled(false);
root_->Add(stretched);
}
}
Expand Down
3 changes: 2 additions & 1 deletion UI/DisplayLayoutScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class DisplayLayoutScreen : public UIDialogScreenWithBackground {
// Touch down state for drag to resize etc
float startX_;
float startY_;
float startScale_;
float startScale_, scaleUpdate_;
float displayRepresentationScale_;
int offsetTouchX, offsetTouchY;

};

0 comments on commit 6751617

Please sign in to comment.