MADRIX Forum • need scripting help
Page 1 of 1

need scripting help

Posted: Thu Nov 17, 2011 10:43 pm
by dieter
Hi,

I will build a effect script with an min and max slider for build a range. What I must do? Value for min are never higher then max value and max value never lower then min value automatic.
How program that?

Here my not perfect script test.

Code: Select all

@scriptname="SliderMinMaxRange";
@author="Dieter";
@version="1.0";
@description="11/14/2011";

int	maxX=GetMatrixWidth();
int maxY=GetMatrixHeight();

ctrlslider sliderMin={"Min",1,maxX*1/4,maxX};
ctrlslider sliderMax={"Max",1,maxX*3/4,maxX};


void InitEffect(){
	// get size
	maxX=GetMatrixWidth();
	maxY=GetMatrixHeight();
}

void RenderEffect(){
	Clear(); // clear screen
    // get value of slider
	int maxValue=sliderMax.value;
	int minValue=sliderMin.value;
    // check range
	if(maxValue<minValue)maxValue=minValue;
	if(minValue>maxValue)minValue=maxValue;
    // set value of slider
	sliderMax.value=maxValue;
	sliderMin.value=minValue;
    // draw rectangle
	FillPixelRect(WHITE,0,minValue-1,maxX,maxValue-minValue+1);
	DrawPixelRect(RED,  0,minValue-1,maxX,maxValue-minValue+1);
}

void MatrixSizeChanged(){
	InitEffect();
}
Can anyone help me?

Re: need scripting help

Posted: Fri Nov 18, 2011 9:56 am
by Wissmann
try this

Code: Select all

@scriptname="SliderMinMaxRange";
@author="Dieter";
@version="1.0";
@description="11/14/2011";

int maxX,maxY;
ctrlslider sliderMin={"Min",1,100,100,"Min"};
ctrlslider sliderMax={"Max",1,100,100,"Max"};

void InitEffect()
{
	// get size
	maxX=GetMatrixWidth();
	maxY=GetMatrixHeight();

	//Init Slider ranges
	int sMin = (int)((float)maxY*0.25);
	sliderMin.rangeMax = sMin;
	sliderMin.value = sMin;      		
	
	int sMax = (int)((float)maxY*0.75);
	sliderMax.rangeMax = sMax;
	sliderMax.value = sMax;    	
}

void RenderEffect()
{
	Clear(); // clear screen
    
	//check range
	if(sliderMax.value < sliderMin.value) sliderMax.value = sliderMin.value;   	
	if(sliderMin.value > sliderMax.value) sliderMin.value = sliderMax.value;

	// draw rectangle
	FillPixelRect(WHITE,0,sliderMin.value-1,maxX,sliderMax.value-sliderMin.value+1);
	DrawPixelRect(RED,  0,sliderMin.value-1,maxX,sliderMax.value-sliderMin.value+1);   	
}

void MatrixSizeChanged()
{
   InitEffect();
}




Re: need scripting help

Posted: Fri Nov 18, 2011 9:57 pm
by dieter
Hi wissmann,
sorry but you don't understand my problem.
I don't will limit the range of slider or output.

I want:
If I slide the max slider lower the min slider then also move the min slider lower.
If I slider the min slider higher the max slider then also move the max slider higher.

If you test my script you see one direction running fine but the inverse way running not really good.

Re: need scripting help

Posted: Mon Nov 21, 2011 1:52 pm
by Pinzer
Hi dieter,

maybe this is what you are looking for.

Code: Select all

@scriptname="SliderMinMaxRange";
@author="Dieter";
@version="1.0";
@description="11/14/2011";

int maxX=GetMatrixWidth();
int maxY=GetMatrixHeight();

ctrlslider sliderMin={"Min",1,maxX*1/4,maxX};
ctrlslider sliderMax={"Max",1,maxX*3/4,maxX};


void InitEffect(){
   // get size
   maxX=GetMatrixWidth();
   maxY=GetMatrixHeight();
}

void RenderEffect(){
   Clear(); // clear screen
    // get value of slider
   int maxValue=sliderMax.value;
   int minValue=sliderMin.value;
   int newmaxValue=maxValue;
   int newminValue=minValue;
    // check range
   if(minValue>maxValue)newmaxValue=minValue;
   if(maxValue<minValue)newminValue=maxValue;
    // set value of slider
   sliderMax.value=newmaxValue;
   sliderMin.value=newminValue;
    // draw rectangle
   FillPixelRect(WHITE,0,minValue-1,maxX,newmaxValue-newminValue+1);
   DrawPixelRect(RED,  0,minValue-1,maxX,newmaxValue-newminValue+1);
}

void MatrixSizeChanged(){
   InitEffect();
}