Fix arrow rotation
This commit is contained in:
parent
fe3d6278ce
commit
02e2628260
1 changed files with 17 additions and 7 deletions
|
@ -33,12 +33,14 @@ public class DirectionDrawable extends Drawable {
|
||||||
IconsCache iconsCache = ((OsmandApplication) ctx.getApplicationContext()).getIconsCache();
|
IconsCache iconsCache = ((OsmandApplication) ctx.getApplicationContext()).getIconsCache();
|
||||||
arrowImage = iconsCache.getIcon(resourceId, clrId);
|
arrowImage = iconsCache.getIcon(resourceId, clrId);
|
||||||
this.resourceId = resourceId;
|
this.resourceId = resourceId;
|
||||||
|
onBoundsChange(getBounds());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setImage(int resourceId) {
|
public void setImage(int resourceId) {
|
||||||
IconsCache iconsCache = ((OsmandApplication) ctx.getApplicationContext()).getIconsCache();
|
IconsCache iconsCache = ((OsmandApplication) ctx.getApplicationContext()).getIconsCache();
|
||||||
arrowImage = iconsCache.getIcon(resourceId, 0);
|
arrowImage = iconsCache.getIcon(resourceId, 0);
|
||||||
this.resourceId = resourceId;
|
this.resourceId = resourceId;
|
||||||
|
onBoundsChange(getBounds());
|
||||||
}
|
}
|
||||||
|
|
||||||
public DirectionDrawable(Context ctx, float width, float height) {
|
public DirectionDrawable(Context ctx, float width, float height) {
|
||||||
|
@ -91,17 +93,25 @@ public class DirectionDrawable extends Drawable {
|
||||||
return super.getIntrinsicHeight();
|
return super.getIntrinsicHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onBoundsChange(Rect bounds) {
|
||||||
|
super.onBoundsChange(bounds);
|
||||||
|
if (arrowImage != null) {
|
||||||
|
Rect r = getBounds();
|
||||||
|
int w = arrowImage.getIntrinsicWidth();
|
||||||
|
int h = arrowImage.getIntrinsicHeight();
|
||||||
|
int dx = r.width() - w;
|
||||||
|
int dy = r.height() - h;
|
||||||
|
arrowImage.setBounds(r.left + dx / 2, r.top + dy / 2, r.right - dx / 2, r.bottom - dy / 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas) {
|
public void draw(Canvas canvas) {
|
||||||
canvas.save();
|
canvas.save();
|
||||||
if (arrowImage != null) {
|
if (arrowImage != null) {
|
||||||
int w = arrowImage.getIntrinsicWidth();
|
Rect r = getBounds();
|
||||||
int h = arrowImage.getIntrinsicHeight();
|
canvas.rotate(angle, r.centerX(), r.centerY());
|
||||||
int dx = canvas.getWidth() - w;
|
|
||||||
int dy = canvas.getHeight() - h;
|
|
||||||
arrowImage.setBounds(0, 0, w, h);
|
|
||||||
canvas.rotate(angle, w / 2, h / 2);
|
|
||||||
canvas.translate(dx / 3, dy / 3);
|
|
||||||
arrowImage.draw(canvas);
|
arrowImage.draw(canvas);
|
||||||
} else {
|
} else {
|
||||||
canvas.rotate(angle, canvas.getWidth() / 2, canvas.getHeight() / 2);
|
canvas.rotate(angle, canvas.getWidth() / 2, canvas.getHeight() / 2);
|
||||||
|
|
Loading…
Reference in a new issue