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

namespace Rokojori
{  
  [Tool]
  [GlobalClass]
  public partial class HSLAdjustmentEffect:ColorEffect
  {
    public HSLAdjustmentEffect():base()
    {
      Initialize();
    } 

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

    [Export( PropertyHint.Range, "-360,360") ]
    public float hueShift = 0;

    [Export( PropertyHint.Range, "-360,360") ]
    public float temparatureShift = 0;

    [Export( PropertyHint.Range, "0,120") ]
    public float temparatureBlendRadius = 15f;

    [Export( PropertyHint.Range, "-100,100") ]
    public float saturationOffset = 0;

    [Export( PropertyHint.Range, "-100,100") ]
    public float saturationGamma = 0;

    [Export( PropertyHint.Range, "-100,100") ]
    public float lightnessOffset = 0;

    [Export( PropertyHint.Range, "-100,100") ]
    public float lightnessGamma = 0;


    public enum HSLConversionMode
    {
      Raw,
      Scaled,
      Clamped
    }

    [Export]
    public HSLConversionMode hslConversionMode = HSLConversionMode.Scaled;



    RG_ScreenColorTexure screenColorTexture;
    RG_HSLAdjustment hslAdjustment;    

    void Initialize()
    { 
      screenColorTexture = new RG_ScreenColorTexure( graph );
      hslAdjustment = new RG_HSLAdjustment( graph );


      graph.InitializeNodes();      

      
      hslAdjustment.SetTextureSlotInputs( screenColorTexture, screenColorTexture ); 


      graph.SetProcessOrder( 
        screenColorTexture, 
        hslAdjustment 
      );
    }
   

    protected override void ForAllViews()
    {
      hslAdjustment.constants.Set(        
        amount,
        MathX.Repeat( hueShift, 360 ) / 360f,  temparatureShift,

        ( saturationOffset ) / 100f, Mathf.Pow( 5f, saturationGamma / 100f ),
        ( lightnessOffset) / 100f, Mathf.Pow( 5f, lightnessGamma / 100f ),

        (float)(int)hslConversionMode,

        temparatureBlendRadius, 
        0f,
        0f,
        0f
      );
    }

   
  }
}