package com.codigoparallevar.minicards; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; import android.support.annotation.NonNull; import com.codigoparallevar.minicards.types.Tuple2; public class ScrolledCanvas { private final Canvas canvas; private final int xOrig; private final int yOrig; public ScrolledCanvas(Canvas canvas, Tuple2 viewOrigin) { this.canvas = canvas; this.xOrig = viewOrigin.item1; this.yOrig = viewOrigin.item2; } public void drawLine(float startX, float startY, float stopX, float stopY, @NonNull Paint paint) { canvas.drawLine(startX - xOrig, startY - yOrig, stopX - xOrig, stopY - yOrig, paint); } public void drawRect(@NonNull Rect r, @NonNull Paint paint) { canvas.drawRect(r.left - xOrig, r.top - yOrig, r.right - xOrig, r.bottom - yOrig, paint); } public void drawCircle(float cx, float cy, float radius, @NonNull Paint paint) { canvas.drawCircle(cx - xOrig, cy - yOrig, radius, paint); } public void drawPath(@NonNull Path path, @NonNull Paint paint) { Path offsetPath = new Path(path); offsetPath.offset(-xOrig, -yOrig); canvas.drawPath(offsetPath, paint); } }