2 registered members (AndrewAMD, ChrstphFr),
941
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Make a button act like a 'normal' windows button
#411487
11/17/12 10:41
11/17/12 10:41
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
OP
Expert
|
OP
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
Hi there, the title says it all, I want a button which acts like this: clicked? -> wait for mouse left release -> mouse is over the button ? -> call button event -> else -> do nothing I could do a kind of workaround for this but that'll be a lot of work to modify this workaround for every single button Isn't there an easy way to do this?
POTATO-MAN saves the day! - Random
|
|
|
Re: Make a button act like a 'normal' windows button
[Re: Kartoffel]
#411494
11/17/12 13:31
11/17/12 13:31
|
Joined: Oct 2011
Posts: 1,082 Germany
Ch40zzC0d3r
Serious User
|
Serious User
Joined: Oct 2011
Posts: 1,082
Germany
|
A simple func I wrote some time ago:
function DrawButton(var x, var y, var alpha, STRING *caption, STRING *functionName)
{
var w = 187;
var h = 40;
static int wasPressed = 0;
draw_textmode("Arial", 1, 18, alpha);
if(mouse_pos.x >= x && mouse_pos.x <= x+w && mouse_pos.y >= y && mouse_pos.y <= y+h)
{
if(mouse_left)
{
draw_quad(button_bmap, vector(x, y, 0), nullvector, vector(w, h, 0), NULL, COLOR_YELLOW_DARK, alpha, 0);
draw_text(caption, x + (w / 2) - (str_width(caption, arialMenu_font) / 2) + 2, y + (h / 2) - 6, COLOR_YELLOW_DARK);
if(wasPressed == 0)
{
pButtonCallback = engine_getscript(_chr(functionName));
if(ValidPointer(pButtonCallback))
{
pButtonCallback();
}
}
wasPressed = 1;
}
else
{
wasPressed = 0;
draw_quad(button_bmap, vector(x, y, 0), nullvector, vector(w, h, 0), NULL, COLOR_YELLOW, alpha, 0);
draw_text(caption, x + (w / 2) - (str_width(caption, arialMenu_font) / 2), y + (h / 2) - 8, COLOR_YELLOW);
}
}
else
{
draw_quad(button_bmap, vector(x, y, 0), nullvector, vector(w, h, 0), NULL, COLOR_WHITE, alpha, 0);
draw_text(caption, x + (w / 2) - (str_width(caption, arialMenu_font) / 2), y + (h / 2) - 8, COLOR_WHITE);
}
draw_textmode("Arial", 0, 16, 100);
}
void ExitFunc()
{
error("LOL");
}
DrawButton(50, 50, 100, "Quit the Game", "ExitFunc"); //HowTo
You just need to make a new variable and store mouse_left, and wait till its not pressed anymore, then execute the event
Last edited by Ch40zzC0d3r; 11/17/12 13:32.
|
|
|
Re: Make a button act like a 'normal' windows button
[Re: Ch40zzC0d3r]
#411496
11/17/12 13:50
11/17/12 13:50
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
OP
Expert
|
OP
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
well, thanks a lot! I haven't got the time right now to test it, but I'll let you know if it works for me.
POTATO-MAN saves the day! - Random
|
|
|
Re: Make a button act like a 'normal' windows button
[Re: Kartoffel]
#412440
11/27/12 14:11
11/27/12 14:11
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
User
|
User
Joined: Oct 2008
Posts: 513
|
alternatively, you can search the forum for "lbgui", a great solution someone posted some time ago that does all that and much more. Basically he made everything work more "windows-like".
The thing I can remember I used in the past were windows buttons, sliders, combobox, checkbox, dropdown menu lists, textbox, progress bars, window-like panels, scrollbars, maximize/minimize buttons for window-panels, resizing panels, auto ajusting text objects to fit variable window size, and a loooong list of many similar things.
LBGUI is a great tool for 3dgs I recommend for anyone working on user interface elements that want a more windows-like or visual studio feel, behaviour, and functionality.
|
|
|
Re: Make a button act like a 'normal' windows button
[Re: Carlos3DGS]
#412477
11/27/12 19:30
11/27/12 19:30
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
OP
Expert
|
OP
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
well I know lbgui but I don't use it because of the complexity (really hard to create a solid interface with it) and for performace reasons. I wanted this for my own interface system. Maybe - if some other people are interested in this - I'll post it in the "The Future"-Forum together with some other small GUI-improvements which would be really helpful, like textboxes for easier text-input with auto scroll if the text is longer than the editbox. At the moment I'm using pan_setstring(); and checkboxes together with a work-around as editboxes. They work but they're far from perfect and this workaround is really annoying, inelegant and uncomfortable to use
POTATO-MAN saves the day! - Random
|
|
|
|