package com.xixun.xixunplayer;

import android.content.Context;
import android.graphics.Canvas;
import android.view.View;

import androidx.annotation.NonNull;

public class SrcCopy extends View {

    View view;
    float scaleX = 1, scaleY = 1;

    public SrcCopy(Context context, View view) {
        super(context);
        this.view = view;
    }

    @Override
    protected void onDraw(@NonNull Canvas canvas) {
        super.onDraw(canvas);
        if(view==null) return;
        if(scaleX==0) {
            if(view.getWidth()!=0&&getWidth()!=0) {
                scaleX = getWidth() / (float) view.getWidth();
                scaleY = getHeight() / (float) view.getHeight();
            } else {
                invalidate();
                return;
            }
        }
        if(scaleX!=1 || scaleY!=1) canvas.scale(scaleX, scaleY);
        view.draw(canvas);
        invalidate();
    }
}
