Slider bar
Slider bar |
//////////////// Slider bar ////////////////////
// // Copyright Simon Donkers 27-1-2005 // www.simondonkers.com - gmmentor@simondonkers.com // // argument0 = x // argument1 = y // argument2 = minimal value // argument3 = maximal value // argument4 = 0 = vertical 1 = horizontal // argument5 = length of bar // place in the draw event // value = the value initialise this variable your self!!! // set 'treat uninitialised variables as value 0' to true // example: 'name_of_script'(5,5,0,255,1,100); // ///////////////////////////////////////////////////// if argument5 = 0 then { argument5 := argument3-argument2; } if argument4 = 0 then { //verical scrollbar //object is selected and mouse button is pressed if global.selected = id and mouse_button = mb_left then { value := (argument5 + argument1-5-mouse_y)/(argument5-10)*(argument3-argument2) + argument2; if value<argument2 then {value := argument2;} if value>argument3 then {value := argument3;} } //object is selected and mouse button is no longer being pressed if global.selected = id and mouse_button!= mb_left then { global.selected := false; } pen_color := c_black; brush_color := c_gray; //x_box = the x coordinate of the plus and minus box x_box := argument0 + 30 + string_width(string(argument3)); //width_box = the width and height off the plus and minus box width_box := 2.5 + string_height('1')/2; //draws the grey box where the scrollbar is in draw_rectangle(argument0,argument1,argument0 + 20,argument5 + argument1); //draws a line in the middle of the scrollbox draw_line(argument0 + 10,argument1 + 5,argument0 + 10,argument5-5 + argument1); //draws the actual scrollblock draw_rectangle(argument0 + 3,argument1 + 5 + (argument3-(value-argument2)-argument2)/(argument3-argument2)*(argument5-10)-2,argument0 + 17,argument1 + 5 + (argument3-(value-argument2)-argument2)/(argument3-argument2)*(argument5-10) + 2); //draws the plus box draw_rectangle(x_box,argument1,x_box + width_box,argument1 + width_box); //draws the minus block draw_rectangle(x_box,argument1 + width_box,x_box + width_box,argument1 + width_box*2); brush_color := c_white; //draws the box with the number in it. draw_rectangle(argument0 + 20,argument1,argument0 + 30 + string_width(string(argument3)),argument1 + string_height('1') + 5); font_color := c_black; //draws the number draw_text(argument0 + 25,argument1 + 2,round(value)); if !(width_box)mod(2) then {pen_size := 2;} //draws the plus draw_line(x_box + width_box/2,argument1 + 2,x_box + width_box/2,argument1 + width_box-2); draw_line(x_box + 2,argument1 + width_box/2,x_box + width_box-2,argument1 + width_box/2); //draws the minus draw_line(x_box + 2,width_box + argument1 + width_box/2,x_box + width_box-2,width_box + argument1 + width_box/2); //if plus pressed if mouse_button = mb_left and mouse_x>x_box and mouse_x<x_box + width_box andmouse_y>argument1 and mouse_y<argument1 + width_box and value<argument3 then { value += 1; } //if minus pressed if mouse_button = mb_left and mouse_x>x_box and mouse_x<x_box + width_box andmouse_y>argument1 + width_box and mouse_y<argument1 + width_box*2 and value>argument2 then { value-= 1; } //if scrollbar pressed if mouse_button = mb_left and mouse_x>argument0 and mouse_x<argument0 + 20 andmouse_y>argument1 and mouse_y<argument1 + + 10 + argument3-argument2 then { global.selected = id; value := (argument5 + argument1-5-mouse_y)/(argument5-10)*(argument3-argument2) + argument2; if value<argument2 then {value := argument2;} if value>argument3 then {value := argument3;} value := round(value); } } else { //horizontal scrollbar pen_color := c_black; brush_color := c_gray; //object is selected and mouse button is pressed if global.selected = id and mouse_button = mb_left then { value := (mouse_x-argument0-5)/(argument5-10)*(argument3-argument2) + argument2; value := round(value); if value<argument2 then {value := argument2;} if value>argument3 then {value := argument3;} } //object is selected and mouse button is no longer being pressed if global.selected = id and mouse_button!= mb_left then { global.selected := false; } //x_box = x coordinate plus and minus x_box := argument0 + 10 + string_width(string(argument3)); //width_box = the width and height off the plus and minus box width_box := 2.5 + string_height('1')/2; //scrollbar background draw_rectangle(argument0,argument1,argument0 + argument5,argument1 + 20); //scrollbar line draw_line(argument0 + 5,argument1 + 10,argument0 + argument5-5,argument1 + 10); //draws the extual scrollbox draw_rectangle(5 + argument0 + (value-argument2)*(argument5-10)/(argument3-argument2)-2,argument1 + 3,5 + argument0 + (value-argument2)*(argument5-10)/(argument3-argument2) + 2,argument1 + 17); //draw plusbox draw_rectangle(x_box,argument1 + 20,x_box + width_box,argument1 + 20 + width_box); //draw minusbox draw_rectangle(x_box,argument1 + 20 + width_box,x_box + width_box,argument1 + 20 + 2*width_box); brush_color := c_white; draw_rectangle(argument0,argument1 + 20,x_box,argument1 + 20 + 2*width_box); font_color := c_black; draw_text(argument0 + 5,argument1 + 22,value); //draw plus draw_line(x_box + width_box/2,argument1 + 22,x_box + width_box/2,argument1 + 20 + width_box-2); draw_line(x_box + 2,argument1 + 20 + width_box/2,x_box + width_box-2,argument1 + 20 + width_box/2); //draw minus draw_line(x_box + 2,argument1 + 20 + width_box*1.5,x_box + width_box-2,argument1 + 20 + width_box*1.5); //if plus pressed if mouse_button = mb_left and value<argument3 and mouse_x>x_box and mouse_x<x_box + width_box and mouse_y>argument1 + 20 and mouse_y<argument1 + 20 + width_box then { value += 1; } //minus pressed if mouse_button = mb_left and value>argument2 and mouse_x>x_box and mouse_x<x_box + width_box and mouse_y>argument1 + 20 + width_box and mouse_y<argument1 + 20 + 2*width_box then { value-= 1; } //scrollbar pressed if mouse_button = mb_left and mouse_x>argument0 and mouse_x<<argument0 + 5 + argument3-argument2 and mouse_y>argument1 and mouse_y<argument1 + 20 { global.selected = id; value := (mouse_x-argument0-5)/(argument5-10)*(argument3-argument2) + argument2; value := round(value); if value<argument2 then {value := argument2;} if value>argument3 then {value := argument3;} } } |