draw_get_button
This function is designed to be called during the Draw Event. It draws a simple, semi-transparent text button on the screen that can be clicked with the mouse. It is primarily intended for debugging and testing purposes.
// Example
if (draw_get_button(250,50,"PRESS THIS BUTTON",200,20,c_black,c_white,c_red)) {
perform_an_action();
}
if (draw_get_button(250,50,"PRESS THIS BUTTON",200,20,c_black,c_white,c_red)) {
perform_an_action();
}
/*
** Usage:
** draw_get_button(x,y,str,width,height,color1,color2,color3)
**
** Arguments:
** x,y position to draw the center of the button
** str string to display inside the button
** width width of the button
** height height of the button
** color1 color of the text when the mouse is not over the button
** color2 color of the text when the mouse is over the button
** color3 color of the background when the mouse is over the button
**
** Returns:
** TRUE if the button is clicked on by the mouse, FALSE otherwise
**
** Notes:
** This function is designed to be called during the Draw Event.
** It draws a simple, semi-transparent button on the screen that
** can be clicked with the mouse. It is primarily intended for
** debugging and testing purposes. It changes the text alignment
** settings to horizontal and vertical centering.
**
** GMLscripts.com
*/
{
var xx,yy,str,w,h,col1,col2,col3,prev_color,prev_alpha,bl,br,bt,bb,in;
xx = argument0;
yy = argument1;
str = argument2;
w = argument3 / 2;
h = argument4 / 2;
col1 = argument5;
col2 = argument6;
col3 = argument7;
prev_color = draw_get_color();
prev_alpha = draw_get_alpha();
bl = xx - w;
br = xx + w;
bt = yy - h;
bb = yy + h;
in = (mouse_x>bl && mouse_x<br && mouse_y>bt && mouse_y<bb);
if (in) {
draw_set_color(col3);
draw_set_alpha(0.2);
draw_rectangle(bl,bt,br,bb,0);
draw_set_color(col2);
draw_set_alpha(1);
}else{
draw_set_color(col1);
draw_set_alpha(0.3);
}
draw_rectangle(bl,bt,br,bb,1);
draw_set_halign(fa_center);
draw_set_valign(fa_middle);
draw_text(xx,yy,str);
draw_set_color(prev_color);
draw_set_alpha(prev_alpha);
if (in && mouse_check_button_pressed(mb_left)) return true;
return false;
}
** Usage:
** draw_get_button(x,y,str,width,height,color1,color2,color3)
**
** Arguments:
** x,y position to draw the center of the button
** str string to display inside the button
** width width of the button
** height height of the button
** color1 color of the text when the mouse is not over the button
** color2 color of the text when the mouse is over the button
** color3 color of the background when the mouse is over the button
**
** Returns:
** TRUE if the button is clicked on by the mouse, FALSE otherwise
**
** Notes:
** This function is designed to be called during the Draw Event.
** It draws a simple, semi-transparent button on the screen that
** can be clicked with the mouse. It is primarily intended for
** debugging and testing purposes. It changes the text alignment
** settings to horizontal and vertical centering.
**
** GMLscripts.com
*/
{
var xx,yy,str,w,h,col1,col2,col3,prev_color,prev_alpha,bl,br,bt,bb,in;
xx = argument0;
yy = argument1;
str = argument2;
w = argument3 / 2;
h = argument4 / 2;
col1 = argument5;
col2 = argument6;
col3 = argument7;
prev_color = draw_get_color();
prev_alpha = draw_get_alpha();
bl = xx - w;
br = xx + w;
bt = yy - h;
bb = yy + h;
in = (mouse_x>bl && mouse_x<br && mouse_y>bt && mouse_y<bb);
if (in) {
draw_set_color(col3);
draw_set_alpha(0.2);
draw_rectangle(bl,bt,br,bb,0);
draw_set_color(col2);
draw_set_alpha(1);
}else{
draw_set_color(col1);
draw_set_alpha(0.3);
}
draw_rectangle(bl,bt,br,bb,1);
draw_set_halign(fa_center);
draw_set_valign(fa_middle);
draw_text(xx,yy,str);
draw_set_color(prev_color);
draw_set_alpha(prev_alpha);
if (in && mouse_check_button_pressed(mb_left)) return true;
return false;
}
[Please Login]
Projects: 2
Contributor: Mordi
comments powered by Disqus

Related: draw_get_button