Making a Button

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Making a Button

Post 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?
Live-Dimension
Chaos Rift Junior
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

Post by Live-Dimension »

There are lots of GUI systems around, there's bound to be one compatible with SDL.
Image
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: Making a Button

Post 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 >.>
User avatar
LeonBlade
Chaos Rift Demigod
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

Post 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.
There's no place like ~/
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Making a Button

Post 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.
Image
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: Making a Button

Post by Bakkon »

You may want to look into function pointers.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Making a Button

Post 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.
Image
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: Making a Button

Post 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.
User avatar
Falco Girgis
Elysian Shadows Team
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

Post 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.
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: Making a Button

Post 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. :(
User avatar
Falco Girgis
Elysian Shadows Team
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

Post 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!?!"
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Making a Button

Post by K-Bal »

GyroVorbis wrote:"what in the FUCK is a delegate!?!"
Well, what is it? (Resident evil quotation :lol:)
User avatar
hurstshifter
ES Beta Backer
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

Post 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!
"Time is an illusion. Lunchtime, doubly so."
http://www.thenerdnight.com
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: Making a Button

Post 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.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Making a Button

Post 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....
Image
Post Reply