
using Godot;
using Godot.Collections;
using System.Collections.Generic;

namespace Rokojori
{  
  [Tool]
  [GlobalClass]
  public partial class VignetteEffect:OverlayEffect
  {

    public VignetteEffect():base()
    {
      Initialize();
    }

    [ExportGroup("Vignette")]
    [Export( PropertyHint.Range, "0,1")]
    public float amount = 1.0f;

    [Export( PropertyHint.Range, "-1,1")]
    public float fadePosition;

    [Export( PropertyHint.Range, "-2,2")]
    public float fadeInOffset = -0.1f;

    [Export( PropertyHint.Range, "-2,2")]
    public float fadeOutOffset= 0.1f;

    [Export( PropertyHint.Range, "-10,10")]
    public float fadePower= 1f;

    [Export( PropertyHint.Range, "0,1")]
    public float ellipseToCircle= 0.5f;

    [ExportGroup("Colors")]

    [Export]
    public Color colorTop = Colors.Black;

    [Export]
    public Color colorBottom = Colors.Black;
   

    [ExportGroup("Blend Mode")]
    [Export]
    public float replace = 1.0f;

    [Export]
    public float add = 0.0f;

    [Export]
    public float multiply = 0.0f;

    [Export]
    public float colorize = 0.0f;



    RG_ScreenColorTexure _screenTexture;
    RG_Vignette _vignette;


    void Initialize()
    {       
      _screenTexture = new RG_ScreenColorTexure( graph );
      _vignette = new RG_Vignette( graph );


      graph.InitializeNodes();

      _vignette.SetTextureSlotInputs( _screenTexture, _screenTexture );

      graph.SetProcessOrder(
        _screenTexture,
        _vignette
      );
      
    }
    
    
    
    protected override void ForAllViews()
    {
      _vignette.constants.Set(        
        colorTop.SrgbToLinear(),
        colorBottom.SrgbToLinear(),
        (Vector2) context.internalSize,
        amount,
        fadePosition + fadeInOffset,
        fadePosition + fadeOutOffset,        
        ellipseToCircle,
        Mathf.Pow( 10f, fadePower / 10f ),
        replace,
        add,
        multiply,
        colorize
      );


    
    }

  }
}