Skip to content

Commit

Permalink
u8_clamp clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
iota97 committed Mar 5, 2020
1 parent 7836776 commit f460151
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
19 changes: 8 additions & 11 deletions UI/GamepadEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "gfx/texture_atlas.h"
#include "math/math_util.h"
#include "ui/ui_context.h"
#include "Core/Util/AudioFormat.h" // for clamp_u8

static u32 GetButtonColor() {
return g_Config.iTouchButtonStyle != 0 ? 0xFFFFFF : 0xc0b080;
Expand Down Expand Up @@ -464,8 +463,6 @@ void PSPStick::ProcessTouch(float x, float y, bool down) {

PSPCustomStick::PSPCustomStick(ImageID bgImg, ImageID stickImg, ImageID stickDownImg, float scale, UI::LayoutParams *layoutParams)
: PSPStick(bgImg, stickImg, stickDownImg, -1, scale, layoutParams) {
posX_ = clamp_u8((int)ceilf(127.5f));
posY_ = clamp_u8((int)ceilf(127.5f));
}

void PSPCustomStick::Draw(UIContext &dc) {
Expand All @@ -490,8 +487,8 @@ void PSPCustomStick::Draw(UIContext &dc) {
float stickY = centerY_;

float dx, dy;
dx = (posX_ - 127.5f) / 127.5f;
dy = -(posY_ - 127.5f) / 127.5f;
dx = posX_;
dy = -posY_;

dc.Draw()->DrawImage(bgImg_, stickX, stickY, 1.0f * scale_, colorBg, ALIGN_CENTER);
if (dragPointerId_ != -1 && g_Config.iTouchButtonStyle == 2 && stickDownImg_ != stickImageIndex_)
Expand All @@ -505,8 +502,8 @@ void PSPCustomStick::Touch(const TouchInput &input) {
dragPointerId_ = -1;
centerX_ = bounds_.centerX();
centerY_ = bounds_.centerY();
posX_ = clamp_u8((int)ceilf(127.5f));
posY_ = clamp_u8((int)ceilf(127.5f));
posX_ = 0.0f;
posY_ = 0.0f;
return;
}
if (input.flags & TOUCH_DOWN) {
Expand Down Expand Up @@ -576,8 +573,8 @@ void PSPCustomStick::ProcessTouch(float x, float y, bool down) {
if (g_Config.iRightAnalogPress != 0)
__CtrlButtonDown(button[g_Config.iRightAnalogPress-1]);

posX_ = clamp_u8((int)ceilf(dx * 127.5f + 127.5f));
posY_ = clamp_u8((int)ceilf(dy * 127.5f + 127.5f));
posX_ = dx;
posY_ = dy;

} else {
if (g_Config.iRightAnalogUp != 0)
Expand All @@ -591,8 +588,8 @@ void PSPCustomStick::ProcessTouch(float x, float y, bool down) {
if (g_Config.iRightAnalogPress != 0)
__CtrlButtonUp(button[g_Config.iRightAnalogPress-1]);

posX_ = clamp_u8((int)ceilf(127.5f));
posY_ = clamp_u8((int)ceilf(127.5f));
posX_ = 0.0f;
posY_ = 0.0f;
}
}

Expand Down
4 changes: 2 additions & 2 deletions UI/GamepadEmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ class PSPCustomStick : public PSPStick {
private:
void ProcessTouch(float x, float y, bool down);

u8 posX_;
u8 posY_;
float posX_ = 0.0f;
float posY_ = 0.0f;
};

//initializes the layout from Config. if a default layout does not exist,
Expand Down

0 comments on commit f460151

Please sign in to comment.