Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Phase-Press Button

Author
Message
Four Dimensional
15
Years of Service
User Offline
Joined: 11th Jun 2008
Location: lost in thought
Posted: 12th Aug 2009 02:41
I notice many button functions that people create have small flaws, for example, if I hold the mouse button and move the mouse around randomly, I may accidentally press the button.
It's not the programmer's fault, but the limitation of a single function, taken out of context, and no global varibles.
I have created a very forgiving button that works in phases and requires global variables or, preferably a global array of data. It allows you to, when holding down the mouse on the button, change your mind by simply moving the mouse out of the button.
This is the source code for an example:



Note: I believe the best way to use the function it to first create a variable (or constant) that matches the amount of buttons in use, then create an array called "ButtonData" and give it dimensions of the said variable by 2, ex. ButtonData(buttons,2). The array returns data, so ButtonData(button,1)= phase in progress and ButtonData(button,2)= press(1 or 0).

Good luck everyone!
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 12th Aug 2009 14:30
I have some code which although isn't perfect, only activates the button on mouseup, not mousedown.

It's in the codebase and here too!



Your signature has been erased by a mod because it is way too awesome!
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Aug 2009 20:34 Edited at: 12th Aug 2009 20:35
What I do for buttons that require a click is if the user is within the button area it stops all action except for updating the screen (for mouse animation) until the user lets go of the mouse button. Then it simply checks if the mouse is still within the button area to register a click.

That way no other buttons are hit during the process because it only focuses on the initial button hit while any mouse button is down. Once the mouse button is let go it does whatever the button does and/or frees the mouse to click on another button.

Four Dimensional
15
Years of Service
User Offline
Joined: 11th Jun 2008
Location: lost in thought
Posted: 12th Aug 2009 22:03
Mobiius,
like the buttons, also i actually learned from your programming, i didn't know you can create an array of types, for example. Thank you, and i hope our programs help many others programmers.

Grog Grueslayer,
sounds good in theory, but i would like to see a working example.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 12th Aug 2009 22:12
Quote: "like the buttons, also i actually learned from your programming"

Well I'm glad I helped!

Your signature has been erased by a mod because it is way too awesome!
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 13th Aug 2009 10:02 Edited at: 13th Aug 2009 10:03
Quote: "sounds good in theory, but i would like to see a working example. "


Np. This doesn't have an animated mouse in it but I can add that later in the ShowScreen function if you want to see that too.

This checks for 4 different mouse types mouseover, mouse hold, mouse hold with timer, and mouse click.



Four Dimensional
15
Years of Service
User Offline
Joined: 11th Jun 2008
Location: lost in thought
Posted: 13th Aug 2009 23:47
I like the selection of buttons, also the so-called "mouseclick" button is a masterpiece. I never would have thought to create a loop with an exit (mouseclick()=0) for a button. Thank you as well.

I was hoping to create a thread that revisited buttons and button functions in hopes of improvements, and i think we've done a great job! If anyone has any more good demos/functions, feel free to post them.

Also, anyone can use my "MouseInside(left, top, right, bottom)" function if he/she wants; i think it might save some typing.
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 14th Aug 2009 00:06
Np and thanks for the compliment.

feiting shadow
17
Years of Service
User Offline
Joined: 12th Sep 2006
Location:
Posted: 14th Sep 2009 10:49
4D, I enjoy your post and hope my button code doesn't do that, I thought I programmed that out of it. Either way, I'm gonna check it out now to make sure (btw, now = soon, heh).

Please add your button code to the codebase if you haven't. And thank Grog for pointing me to your thread. Gonna try drawing and editing my GUI codes in my spare time. May post here for C&C, in the appropriate threads of course. Also, 4D, why'd you choose that name? I'm quite a fan of nonlinear time and such viewpoints

Signed
------
Four Dimensional
15
Years of Service
User Offline
Joined: 11th Jun 2008
Location: lost in thought
Posted: 15th Oct 2009 02:54
Hey, sorry i haven't replied. I'll try posting in the codebase; i have never posted anything there, so it might be a while (sorry).

The reason i chose my name is because i was interested in spacial studies of the fourth dimension, which usually range from 4D primitives, like the tesseract, or even the theory of many 'parallel' universes only accessible by means of traveling in a yet-to-be-discovered direction. i'm not very certain about nonlinear time, but it sounds interesting.

Login to post a reply

Server time is: 2024-05-01 20:00:12
Your offset time is: 2024-05-01 20:00:12