Making a Button
Moderator: Coders of Rage
Making a Button
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?
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?
-
- Chaos Rift Junior
- Posts: 345
- Joined: Tue Jan 12, 2010 7:23 pm
- Favorite Gaming Platforms: PC - Windows 7
- Programming Language of Choice: c++;haxe
- Contact:
Re: Making a Button
There are lots of GUI systems around, there's bound to be one compatible with SDL.
Re: Making a Button
Err I know that, but I'm interested in making my own >.>Live-Dimension wrote:There are lots of GUI systems around, there's bound to be one compatible with SDL.
- LeonBlade
- Chaos Rift Demigod
- Posts: 1314
- Joined: Thu Jan 22, 2009 12:22 am
- Current Project: Trying to make my first engine in C++ using OGL
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: Blossvale, NY
Re: Making a Button
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.
There's no place like ~/
Re: Making a Button
This is exactly what I was thinking.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.
- Bakkon
- Chaos Rift Junior
- Posts: 384
- Joined: Wed May 20, 2009 2:38 pm
- Programming Language of Choice: C++
- Location: Indiana
Re: Making a Button
You may want to look into function pointers.
Re: Making a Button
Yes indeed. I haven't actually used these but that could be pretty darn handy.Bakkon wrote:You may want to look into function pointers.
Re: Making a Button
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.Bakkon wrote:You may want to look into function pointers.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Making a Button
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.
- Bakkon
- Chaos Rift Junior
- Posts: 384
- Joined: Wed May 20, 2009 2:38 pm
- Programming Language of Choice: C++
- Location: Indiana
Re: Making a Button
I've been working with delegates in C# for too long.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.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Making a Button
I hear that. We use C# at work, and I remember going "what in the FUCK is a delegate!?!"Bakkon wrote:I've been working with delegates in C# for too long.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.
Re: Making a Button
Well, what is it? (Resident evil quotation )GyroVorbis wrote:"what in the FUCK is a delegate!?!"
- hurstshifter
- ES Beta Backer
- Posts: 713
- Joined: Mon Jun 08, 2009 8:33 pm
- Favorite Gaming Platforms: SNES
- Programming Language of Choice: C/++
- Location: Boston, MA
- Contact:
Re: Making a Button
What a mansion!K-Bal wrote:Well, what is it? (Resident evil quotation )GyroVorbis wrote:"what in the FUCK is a delegate!?!"
"Time is an illusion. Lunchtime, doubly so."
http://www.thenerdnight.com
http://www.thenerdnight.com
Re: Making a Button
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
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....
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....