package com.xixun.xixunplayer;

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

import androidx.annotation.NonNull;

@SuppressLint("ViewConstructor")
public class SrcCopy extends View {

    Prog.Source source;
    float scaleX = 1, scaleY = 1;

    public SrcCopy(Context context, Prog.Source source) {
        super(context);
        this.source = source;
    }

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