Windows menu script
A script that generates a simple looking completely GML menu box.
Windows menu script |
//////////////// Windows menu script ////////////////////
// // Copyright Simon Donkers 27-1-2005 // www.simondonkers.com - gmmentor@simondonkers.com // // place in the draw event // argument0 = x coordinate // argument1 = y coordinate // argument2 = button discription // argument3 = menu options seperate by | // variable clicked containes the last clicked. item // If clicked = 0 then no option has been clicked yet // first option is 1, second 2... // set 'treat unitialised variables as 0' on // near the end stands a command named: // "what to do when clicked" // you can place an alarm event or so in there // the alarm will be set when the button is clicked // or you can use user defined events // ///////////////////////////////////////////////////// //if mouse over button if mouse_x>argument0 and mouse_x<argument0 + 5 + string_width(argument2) andmouse_y>argument1 and mouse_y<argument1 + 5 + string_height(argument2) then { past:= true; } else { past:= false; } //draw button background if past = false and global.open!= id then { //unselected brush_color:= c_gray; } else { //selected brush_color:= make_color(50,50,200); } //open or close menu if past = true and mouse_button = mb_left and !pressed then { mouse_clear(mb_left); if global.open = id then { global.open:= false; } else { global.open:= id; } } //draw top button pen_color:= c_gray; draw_rectangle(argument0,argument1,argument0 + 5 + string_width(argument2),argument1 + 5 + string_height(argument2)); font_color:= c_black; draw_text(argument0 + 2,argument1 + 2,argument2); position:= 0; number:= 0; selected:= 0; //if menu is open if global.open = id then { //since last option is not read at dummy option argument3:= string_insert('|dummy',argument3,string_length(argument3) + 1); //add every menu option to the array text for(i = 0; i<string_length(argument3); i += 1) { if string_copy(argument3,i,1) = '|' then { text[number]:= string_copy(argument3,position + 1,i-position-1); position:= i; number += 1; } } length:= 0; //check which is the length of the longest menu option for(i = 0; i<number; i += 1;) { if string_width(text[i])>length then { length:= string_width(text[i]); } } //draw menu background brush_color:= c_gray; draw_rectangle(argument0,argument1 + 5 + string_height(argument2),argument0 + 5 + length,argument1 + 10 + string_height(argument2)*(number + 1)); for(i = 0; i<number; i += 1;) { //if mouse over button if mouse_x>argument0 and mouse_x<argument0 + length and mouse_y>argument1+ string_height(argument2) + 7 + string_height(argument2)*i and mouse_y<argument1 + string_height(argument2) + 7 + string_height(argument2)*(i + 1) then { selected:= i + 1; brush_color:= make_color(50,50,200); draw_rectangle(argument0,argument1 + string_height(argument2) + 7 + string_height(argument2)*i,3 + argument0 + length,argument1 + string_height(argument2) + 7 + string_height(argument2)*(i + 1) + 2); } //draw button text draw_text(argument0 + 2,argument1 + string_height(argument2) + 7 + string_height(argument2)*i,text[i]); } } //if option is selected if mouse_button = mb_left and !pressed and selected!= 0 then { clicked = selected; global.open:= 0; /////////////////////////////////// //what to do when clicked. Perhaps set an alarm or execute a script /////////////////////////////////// } //if clicked somewhere else in the screen then close if !(past | (mouse_x>argument0 and mouse_x<argument0 + 5 + length and mouse_y>argument1 + 5 + string_height(argument2) and mouse_y<argument1 + 10 + string_height(argument2)*(number + 1)))and mouse_button = mb_left and !pressed and global.open = id then { global.open:= 0 } //checks whether mouse is pressed at the end so in the next step it is know //whether the mouse is pressed or is still pressed pressed:= (mouse_button = mb_left); |