Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by M_D. 04/26/24 20:22
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (PeroPero), 788 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
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 Offline OP
Expert
Kartoffel  Offline 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 smirk
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
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
A simple func I wrote some time ago:
Code:
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 laugh

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 Offline OP
Expert
Kartoffel  Offline 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] #411508
11/17/12 14:48
11/17/12 14:48
Joined: Nov 2011
Posts: 139
India
Yashas Offline
Member
Yashas  Offline
Member

Joined: Nov 2011
Posts: 139
India
Epic Coding , but isn't engine_getscript slow??
Function pointers are faster if I am correct.


Keep smiling laugh
http://translation.babylon.com/ - Translate many languages
Re: Make a button act like a 'normal' windows button [Re: Yashas] #411514
11/17/12 14:53
11/17/12 14:53
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
...I thought the same, but the main idea of the function is more important smile


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 Offline
User
Carlos3DGS  Offline
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.


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: Make a button act like a 'normal' windows button [Re: Carlos3DGS] #412453
11/27/12 15:51
11/27/12 15:51
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Bro, lbgui uses for every element as example a button a new while-loop. Ever made a main-menu and drawed a serverlist? 20 fps on 1920x1080 reolution. My way is much better. Btw the millisecond it takes to get a functionpointer is not captchable by human eyes wink its only called 1 time when you click the button!

Re: Make a button act like a 'normal' windows button [Re: Ch40zzC0d3r] #412474
11/27/12 19:05
11/27/12 19:05
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline
User
Carlos3DGS  Offline
User

Joined: Oct 2008
Posts: 513
I never used it for anything very complex so I never noticed that. If I ever make a very complex gui I will be sure to use this approach all I can and only use the more complex lbgui objects for stuff like re-formatting text for resizable panels.

Thanks for the info! You have probably helped me out alot to avoid headaches further down the line when my UI gets more complex and it would have been a pain to re-do everything later whith more UI elements. By the time I would have started to notice the fps drop in the future I would have tons of stuff to re-make. Thanks for the warning!
Cheers mate!

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 Offline OP
Expert
Kartoffel  Offline 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 frown


POTATO-MAN saves the day! - Random
Re: Make a button act like a 'normal' windows button [Re: Kartoffel] #412478
11/27/12 19:50
11/27/12 19:50
Joined: Jul 2008
Posts: 894
T
TechMuc Offline
User
TechMuc  Offline
User
T

Joined: Jul 2008
Posts: 894
use cegui and do not use draw_quad / draw_text if you want to have performance.

http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=409292

Last edited by TechMuc; 11/27/12 19:50.
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1