desc:new effect

import inc\Mouse3Full.jsfx-inc

slider1:0<0,1,1>ChangeObject(rect1-rect2)
slider2:0<0,100,1>-parameter2
slider3:0<0,100,1>-parameter3
slider4:0<0,100,1>-parameter4
slider5:0<0,100,1>-parameter5

@init
R = G = B = 20; // color for test 
gfx_clear = R+G*256+B*65536;

ext_noinit = 1;

//*******************************************
TestRect1.r = TestRect1.g = TestRect1.b = TestRect1.a = 0.5;
TestRect2.r = TestRect2.g = TestRect2.b = TestRect2.a = 0.3;


//-- Draw spinBox -------------
function spinBox_Draw(x,y,w,h, lbl, val)
  instance(cap_val, cap_y)
  local(cx,cy, str, str_w, str_h)
(
  gfx_set(0.3,0.3,0.3,0.4);
  gfx_rect(x,y,w,h,0); // bg
  
    //--- Get mouse, set val --
    mouse_up ? this.isCaptd = 0;
    
    mouse_down && mouseINrect(x,y,w,h) ? (
        mouse_down_x > x+w-h+2 ? (
          mouse_down_y < y+h/2 ? val+=1/255 : val-=1/255;
          val = min( max(val, 0), 1);
        ) : (
          this.isCaptd = 1; 
          this.cap_val = val; 
          this.cap_y = mouse_y;
        );
    );
  
    this.isCaptd ? (
      val = cap_val + 1/512 * (cap_y-mouse_y);
      val = min( max(val, 0), 1);
    );
  
  gfx_set(0.6,0.6,0.6,0.9); // clr
  //-- Draw() ---------
  cx = x+w-8; cy = y+h/2;   // center()
  gfx_x = cx-2; gfx_y = cy-2;
  gfx_lineto(cx, cy-4); gfx_lineto(cx+2, cy-2); //up
  gfx_x = cx-2; gfx_y = cy+2;
  gfx_lineto(cx, cy+4); gfx_lineto(cx+2, cy+2); //down
   
  //-- label -----------------
  gfx_measurestr(lbl, str_w, str_h);
  gfx_x = x- str_w-4; gfx_y = y+(h-str_h)/2;
  gfx_drawstr(lbl); 
  
  //-- value -----------------
  str = sprintf(#, "%g", floor(val*255)); // value(0...255 form)
  gfx_measurestr(str, str_w, str_h);
  gfx_x = x+5;
  gfx_y = y+(h-str_h)/2;
  gfx_drawstr(str); 

  val; // return value
);
//----------------------------
function ColorMenu(x,y, obj*)
( 
  //-- Draw menu, change obj color ---  
  obj.r = R.spinBox_Draw(x,y,   40,18, "R: ", obj.r);
  obj.g = G.spinBox_Draw(x,y+20,40,18, "G: ", obj.g);
  obj.b = B.spinBox_Draw(x,y+40,40,18, "B: ", obj.b);
  obj.a = A.spinBox_Draw(x,y+60,40,18, "A: ", obj.a);
 
);

//***************************************************************
@serialize
//-- Test Serialize
file_var(0,TestRect1.r); 
file_var(0,TestRect1.g); 
file_var(0,TestRect1.b); 
file_var(0,TestRect1.a);

file_var(0,TestRect2.r); 
file_var(0,TestRect2.g); 
file_var(0,TestRect2.b); 
file_var(0,TestRect2.a);


@slider

@block

@sample
spl0=spl0;
spl1=spl1;


@gfx 100 100
//------------------------------
function Draw_Controls()
(
  gfx_setfont(1,"Calibri", 15);
  //----Test -----
  slider1 == 0 ? ColorMenu(40,10, TestRect1);
  slider1 == 1 ? ColorMenu(40,10, TestRect2);

);

GetMouseState();
//***************************************************************
Draw_Controls();

gfx_set(TestRect1.r , TestRect1.g , TestRect1.b , TestRect1.a);
gfx_rect(100, 10, 40,80, 1);
gfx_set(TestRect2.r , TestRect2.g , TestRect2.b , TestRect2.a);
gfx_rect(150, 10, 40,80, 1);
//***************************************************************
SetMouseLastState();