Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [Module] DetectButton
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Aange10




PostPosted: Sat Dec 31, 2011 9:46 pm   Post subject: [Module] DetectButton

Features

This quick little module contains a function I use in almost every program now 'adays. I love it because it is simple to set up (as simple as copy and pasting coordinates if you hard coding, or inserting variables if you're not) and extremely easy to debug!

One of the most annoying things for me when I'm developing a program is setting up buttons. This tool makes it extremely easy, and has an appropriate 'debug' parameter to make your life easier.

How it Works

Basically it will take in the coordinates you give it, and check to see if your mouse is in there. If you have drawing ("debug") mode on, it will also outline where your code is detecting. (It's also useful for being lazy and still making things look good).

The function outputs true or false. True if you're mouse is there, and false if not.

Syntax

The syntax is super simple. [See The Turing Walkthrough for importing modules]

After importing the module you can call it by these parameters:
Turing:

    MPos (x1, y1, x2, y2, mouseX, mouseY : int, drawBox : boolean)


The syntax is very self explanatory

Instructions


1) Import the "ButtonDetect.tu"
2) Call it by saying DetectButton.MPos (x1, y1, x2, y2, mx, my, drawbox)
3) DONE!

Working Example



ButtonDetect.zip
 Description:

Download
 Filename:  ButtonDetect.zip
 Filesize:  974 Bytes
 Downloaded:  390 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Wed Jan 18, 2012 8:19 pm   Post subject: RE:[Module] DetectButton

The test is more impressive than the actual module itself. You're also combining logic with rendering. What if I wanted to execute some code that would affect other parts of the rendering that frame?

One function, while it can be a module, isn't really something people will download a dependency for.

Possibly consider including a Button data type so the user doesn't need to do that every program.

The module itself has no documentation (comments) and you used shorthand variables (mx, my) which can mean anything (unless you've experience someone using them in that context before). You even used mouseX here.
Aange10




PostPosted: Wed Jan 18, 2012 9:03 pm   Post subject: RE:[Module] DetectButton

Quote:

You're also combining logic with rendering. What if I wanted to execute some code that would affect other parts of the rendering that frame?


It's just a debug mode. It has a boolean to disable it. Making it completely used to tell you if your mouse is in a certain area. The function has helped me several times in wondering why my clicking was off.

Quote:
One function, while it can be a module, isn't really something people will download a dependency for.


I'm not really sure what you mean, so I'm going to assume you're criticizing it being one function. If that is the case, then that is fine. If somebody doesn't want to take two seconds to download a 6kb file, that's on them.

Quote:
The module itself has no documentation (comments) and you used shorthand variables (mx, my) which can mean anything (unless you've experience someone using them in that context before).


I should fix that if I plan to do anything else with the module.


Quote:
You even used mouseX here.


That's explicitly so people can use it correctly. The code may be short hand, but that's easily fixed. However giving this syntax here, is the same as saying "it is" in a formal essay, as to saying "its" or "it's" in a chat room.
Zren




PostPosted: Wed Jan 18, 2012 9:26 pm   Post subject: Re: RE:[Module] DetectButton

Quote:
It's just a debug mode. It has a boolean to disable it. Making it completely used to tell you if your mouse is in a certain area. The function has helped me several times in wondering why my clicking was off.


Still, to be any use for debugging, you would have needed to use this function after you've started drawing the frame (and after you've drawn the button).

[quote="Aange10 @ Wed Jan 18, 2012 9:03 pm"]
Quote:

Quote:
One function, while it can be a module, isn't really something people will download a dependency for.


I'm not really sure what you mean, so I'm going to assume you're criticizing it being one function. If that is the case, then that is fine. If somebody doesn't want to take two seconds to download a 6kb file, that's on them.


It's more so it's easier to copy/paste the function. Being only one function, it wouldn't bulk up whatever program you insert it into.
Aange10




PostPosted: Wed Jan 18, 2012 9:29 pm   Post subject: RE:[Module] DetectButton

Quote:

It's more so it's easier to copy/paste the function. Being only one function, it wouldn't bulk up whatever program you insert it into.


Ahh, I see. Makes sense.

Quote:

Still, to be any use for debugging, you would have needed to use this function after you've started drawing the frame (and after you've drawn the button).


Do you have a suggestion? I also implement this (personally) for its drawing the box. It is a good way to indicate if somebody is 'hovering' over a button.

But, more to the point, do you have a suggestion for a better way of going about it?
Zren




PostPosted: Wed Jan 18, 2012 9:46 pm   Post subject: Re: RE:[Module] DetectButton

Aange10 @ Wed Jan 18, 2012 9:29 pm wrote:

Do you have a suggestion? I also implement this (personally) for its drawing the box. It is a good way to indicate if somebody is 'hovering' over a button.

But, more to the point, do you have a suggestion for a better way of going about it?


Yea, it's fine as a feature, it's just that you described it as a debugging method which threw alarm bells that you included debugging code in a release. As for suggestions, nothing that not entirely insanely complicated for the use you were after. Essentially anything I'd suggest is writing a GUI module for just buttons. A button data type that would include it's bounding box, it's state (normal, hover, pressed), and whatever data you wanted within (label of text, images, etc) (optional). Creation function (constructor) along with functions to update an instance of the data type from input (mouse), and a seperate function to render the button itself.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: