mirror of
https://github.com/etlegacy/JoyStick.git
synced 2024-11-10 06:42:15 +00:00
small changes, removed the alpha variable for bitmaps, alpha can just be added to the bitmaps themselves
This commit is contained in:
parent
30b3cefca3
commit
80e0dca5f8
3 changed files with 1 additions and 26 deletions
|
@ -22,7 +22,6 @@ public class MainActivity extends AppCompatActivity implements JoyStick.JoyStick
|
||||||
((JoyStick)findViewById(R.id.joy2)).enableStayPut(true);
|
((JoyStick)findViewById(R.id.joy2)).enableStayPut(true);
|
||||||
((JoyStick)findViewById(R.id.joy2)).setButtonSize(50);
|
((JoyStick)findViewById(R.id.joy2)).setButtonSize(50);
|
||||||
((JoyStick)findViewById(R.id.joy2)).setButtonDrawable(R.drawable.droid);
|
((JoyStick)findViewById(R.id.joy2)).setButtonDrawable(R.drawable.droid);
|
||||||
((JoyStick)findViewById(R.id.joy2)).setButtonAlpha(100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -66,12 +66,6 @@ public class JoyStick extends View {
|
||||||
//Button Bitmap
|
//Button Bitmap
|
||||||
Bitmap buttonBitmap = null;
|
Bitmap buttonBitmap = null;
|
||||||
|
|
||||||
//Background Alpha
|
|
||||||
int padAlpha = 255;
|
|
||||||
|
|
||||||
//Button Alpha
|
|
||||||
int buttonAlpha = 255;
|
|
||||||
|
|
||||||
public interface JoyStickListener {
|
public interface JoyStickListener {
|
||||||
void onMove(JoyStick joyStick, double angle, double power);
|
void onMove(JoyStick joyStick, double angle, double power);
|
||||||
}
|
}
|
||||||
|
@ -116,8 +110,6 @@ public class JoyStick extends View {
|
||||||
buttonBitmap = BitmapFactory.decodeResource(getResources(), buttonResId);
|
buttonBitmap = BitmapFactory.decodeResource(getResources(), buttonResId);
|
||||||
}
|
}
|
||||||
|
|
||||||
padAlpha = typedArray.getInt(R.styleable.JoyStick_backgroundAlpha, 255);
|
|
||||||
buttonAlpha = typedArray.getInt(R.styleable.JoyStick_buttonAlpha, 255);
|
|
||||||
typedArray.recycle();
|
typedArray.recycle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +126,7 @@ public class JoyStick extends View {
|
||||||
posX = centerX;
|
posX = centerX;
|
||||||
posY = centerY;
|
posY = centerY;
|
||||||
buttonRadius = (min / 2f * (percentage/100f));
|
buttonRadius = (min / 2f * (percentage/100f));
|
||||||
radius = (min / 2 * 0.75f);
|
radius = (min / 2f * ((100f-percentage)/100f));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -145,7 +137,6 @@ public class JoyStick extends View {
|
||||||
paint.setColor(padColor);
|
paint.setColor(padColor);
|
||||||
canvas.drawCircle(centerX, centerY, radius, paint);
|
canvas.drawCircle(centerX, centerY, radius, paint);
|
||||||
} else {
|
} else {
|
||||||
paint.setAlpha(padAlpha);
|
|
||||||
temp.set(posX - radius, posY - radius, posX + radius, posY + radius);
|
temp.set(posX - radius, posY - radius, posX + radius, posY + radius);
|
||||||
canvas.drawBitmap(padBGBitmap, null, temp, paint);
|
canvas.drawBitmap(padBGBitmap, null, temp, paint);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +144,6 @@ public class JoyStick extends View {
|
||||||
paint.setColor(buttonColor);
|
paint.setColor(buttonColor);
|
||||||
canvas.drawCircle(posX, posY, buttonRadius, paint);
|
canvas.drawCircle(posX, posY, buttonRadius, paint);
|
||||||
} else {
|
} else {
|
||||||
paint.setAlpha(buttonAlpha);
|
|
||||||
temp.set(posX - buttonRadius, posY - buttonRadius, posX + buttonRadius, posY + buttonRadius);
|
temp.set(posX - buttonRadius, posY - buttonRadius, posX + buttonRadius, posY + buttonRadius);
|
||||||
canvas.drawBitmap(buttonBitmap, null, temp, paint);
|
canvas.drawBitmap(buttonBitmap, null, temp, paint);
|
||||||
}
|
}
|
||||||
|
@ -242,16 +232,4 @@ public class JoyStick extends View {
|
||||||
public void setButtonDrawable(int resId) {
|
public void setButtonDrawable(int resId) {
|
||||||
this.buttonBitmap = BitmapFactory.decodeResource(getResources(), resId);
|
this.buttonBitmap = BitmapFactory.decodeResource(getResources(), resId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBackgroundAlpha(int alpha) {
|
|
||||||
padAlpha = alpha;
|
|
||||||
if (padAlpha > 255) padAlpha = 255;
|
|
||||||
if (padAlpha < 0) padAlpha = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setButtonAlpha(int alpha) {
|
|
||||||
buttonAlpha = alpha;
|
|
||||||
if (buttonAlpha > 255) buttonAlpha = 255;
|
|
||||||
if (buttonAlpha < 0) buttonAlpha = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -7,7 +7,5 @@
|
||||||
<attr name="percentage" format="integer" />
|
<attr name="percentage" format="integer" />
|
||||||
<attr name="backgroundDrawable" format="reference" />
|
<attr name="backgroundDrawable" format="reference" />
|
||||||
<attr name="buttonDrawable" format="reference" />
|
<attr name="buttonDrawable" format="reference" />
|
||||||
<attr name="backgroundAlpha" format="integer" />
|
|
||||||
<attr name="buttonAlpha" format="integer" />
|
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in a new issue