Page 1 of 2

Making a Button

Posted: Sat Mar 20, 2010 11:21 pm
by XianForce
So, I was recently considering adding some simple GUI things to my SDL Framework. At the moment I'm simply planning some things out, but I was thinking about how I would go about making a button class.

The way I think about it, When the user clicks, I'll let some 'GUI Manager' object know, and it will, in turn, send the click to every object it is controlling.

But with buttons, every button does something different. So if I had an 'OnClick()' method, how would I make it perform different tasks?

I thought of making the button as a virtual base class, but that seems like a pain to me...

So is there a more intelligent way to do this?

Re: Making a Button

Posted: Sun Mar 21, 2010 1:01 am
by Live-Dimension
There are lots of GUI systems around, there's bound to be one compatible with SDL.

Re: Making a Button

Posted: Sun Mar 21, 2010 1:59 am
by XianForce
Live-Dimension wrote:There are lots of GUI systems around, there's bound to be one compatible with SDL.
Err I know that, but I'm interested in making my own >.>

Re: Making a Button

Posted: Sun Mar 21, 2010 3:21 am
by LeonBlade
Assign a listener to the button's OnClick, essentially, you just pass in what Event you want to listen for and then the name of the function.

Re: Making a Button

Posted: Sun Mar 21, 2010 9:19 pm
by eatcomics
LeonBlade wrote:Assign a listener to the button's OnClick, essentially, you just pass in what Event you want to listen for and then the name of the function.
This is exactly what I was thinking.

Re: Making a Button

Posted: Sun Mar 21, 2010 9:24 pm
by Bakkon
You may want to look into function pointers.

Re: Making a Button

Posted: Sun Mar 21, 2010 9:25 pm
by eatcomics
Bakkon wrote:You may want to look into function pointers.
Yes indeed. I haven't actually used these but that could be pretty darn handy.

Re: Making a Button

Posted: Sun Mar 21, 2010 9:42 pm
by XianForce
Bakkon wrote:You may want to look into function pointers.
Yeah that's another thing I thought of, but I'm not too familiar with them, so I guess it's something to familiarize myself with them.

Re: Making a Button

Posted: Mon Mar 22, 2010 10:01 am
by Falco Girgis
If you're using C++, you might NOT want to look into function pointers, and you might want to look into functoids. They're way more versatile, useful, and powerful.

Re: Making a Button

Posted: Mon Mar 22, 2010 2:40 pm
by Bakkon
GyroVorbis wrote:If you're using C++, you might NOT want to look into function pointers, and you might want to look into functoids. They're way more versatile, useful, and powerful.
I've been working with delegates in C# for too long. :(

Re: Making a Button

Posted: Mon Mar 22, 2010 2:42 pm
by Falco Girgis
Bakkon wrote:
GyroVorbis wrote:If you're using C++, you might NOT want to look into function pointers, and you might want to look into functoids. They're way more versatile, useful, and powerful.
I've been working with delegates in C# for too long. :(
I hear that. We use C# at work, and I remember going "what in the FUCK is a delegate!?!"

Re: Making a Button

Posted: Mon Mar 22, 2010 3:05 pm
by K-Bal
GyroVorbis wrote:"what in the FUCK is a delegate!?!"
Well, what is it? (Resident evil quotation :lol:)

Re: Making a Button

Posted: Mon Mar 22, 2010 3:59 pm
by hurstshifter
K-Bal wrote:
GyroVorbis wrote:"what in the FUCK is a delegate!?!"
Well, what is it? (Resident evil quotation :lol:)
What a mansion!

Re: Making a Button

Posted: Mon Mar 22, 2010 7:53 pm
by XianForce
Errr... What's a functoid haha? I've never heard that term to be honest. I did a quick google search, but I keep finding functoid libraries, nothing that actually explains what it is and/or how to implement/use it.

Re: Making a Button

Posted: Mon Mar 22, 2010 9:56 pm
by eatcomics
I'm pretty sure there is a thread on the forums about them somewhere, right?

Edit: Does this help? http://accu.org/index.php/journals/561

I didn't really read it through, but it looks like it has some info... IDK though I'd say use the search bar on this forum to find the functoid thread

Edit:Edit: There is not a thread on functoids....