![]() |
|
allegro gui |
julian_boolean
Member #8,201
January 2007
|
How's this! And will I be able to use the same function for any kinda widget, like radio buttons or text fields?
|
Steve Terry
Member #1,989
March 2002
![]() |
... is that valid code??? ___________________________________ |
julian_boolean
Member #8,201
January 2007
|
/bawl.. What am I doing wrong? |
Steve Terry
Member #1,989
March 2002
![]() |
Ok what the hell is your button class? It keeps changing but it still makes no sense. You basically copied my code I gave you and pasted it into your is_clicked method but the code I gave you was for my GUI as a demonstration on how you should handle things. It was not to be taken literally. Your button has an is_clicked method but the code you have inside it has nothing to do with it being clicked.. it's more of a draw method and yet you still use play_sound inside of it which also makes no sense. You keep hanging onto your class, we're just trying to show you how you can make pretty buttons using the Allegro built in GUI. You can pretty much take the Allegro GUI and extend the procs to make pretty nice looking GUI elements. NAS does pretty much that and it extends all the procs to have more functionality. It's up to you how you want to your buttons but the thread is labeled Allegro GUI so I assumed you wanted to use the Allegro GUI in which case your class is irrelevant and your code will need to be rewritten. ___________________________________ |
julian_boolean
Member #8,201
January 2007
|
This is just getting depressing.. All I wanted was something to handle the different states for my widgets so I wouldn't have to keep rewriting the (near) same logic in each widget class, while keeping my own graphics and not using libraries other then Allegro to do it. I thought the Allegro GUI could do that, well it seems like it could. My class hasn't changed yet, I just copied the code given to me and rewrote it to the way I thought it works, then reposted it to see if I was even on the right track. This is what I'm using now:
|
Steve Terry
Member #1,989
March 2002
![]() |
Ok you can use your button class but it's not that flexible, I mean you can't use your button for anything else than playing a sound because that's the variable it's setting. You couldn't, for example, use your button to change the color of a box or something. You could also use the Allegro GUI which has the functionality you need but it's a bit ugly but I showed you ways to make it less ugly. Unfortunately to use the Allegro GUI you would have to rewrite your code. That said I would stick with what you have at the moment, you just need to break out your methods a bit and possibly use callbacks or overloaded methods to drive your play_sound variable. ___________________________________ |
julian_boolean
Member #8,201
January 2007
|
That's all I want it to do, just draw and play a sound, or return TRUE if I want to use the function outside the class for other things. Before, everyone kept saying that I needed some kinda event handler for all my widgets and since then I've been trying to do that without much luck. I suppose I could just try to write things like WIDGET_FOCUSED, WIDGET_PRESSED, etc myself. |
ImLeftFooted
Member #3,935
October 2003
![]() |
A GUI is a pretty advanced and complicated project. Maybe make your user interface a bit simpler this time around and improve with your next game? |
julian_boolean
Member #8,201
January 2007
|
Because I'd just rather start learning it now while I'm at it since I already know how the code I'm using works throughout. And yeah it can be complicated, depending on how versatile you want it to be. I want it to be pretty specific though, for the most part. |
Steve Terry
Member #1,989
March 2002
![]() |
Hang on I'll whip up a simple widget and button class... I was doing so but accidentally hit the wrong keyboard button and lost my friggin post >:E ___________________________________ |
julian_boolean
Member #8,201
January 2007
|
|
Steve Terry
Member #1,989
March 2002
![]() |
I made three classes, one is the base widget class. The widget class is what every other GUI object is derived from. The next class is a base button class, all it is concerned about is doing a few methods essential to a button. The third class is a class derived from button which overloads a few methods and utilizes the callback to play a sound when the button is pressed. Please use this code only as a template, I have not compiled it and it probably won't work correctly but it should give you a direction. If you notice all methods do what their names imply and nothing more. They each do a small part. This code is not optimized either but as I said it's just to give a general idea. [edit] ___________________________________ |
julian_boolean
Member #8,201
January 2007
|
Looks very promising to me, going to look it over before bed (stupid work in the morning) Thanks a million for all your help, and everyone elses help (again) hehe tomorrow whenever I get home I'll try to fool around with it for awhile and will certainly give a heads up if I run into any problems, but I understand this a lot more then the Allergo gui stuff. |
Steve Terry
Member #1,989
March 2002
![]() |
Why would you do that? You are making confusing methods again. set_enabled sets a variable wheras enable acts on that variable? Why not just have a method called set_enable(bool enable) that takes true or false and enables or disables the widget there. No need for an extra method that is seemingly pointless. [edit] ___________________________________ |
julian_boolean
Member #8,201
January 2007
|
Sorry hehe erased it after looking it over for a couple seconds. Thanks again though. |
Steve Terry
Member #1,989
March 2002
![]() |
Sorry I made some minor tweaks to the widget and button classes because I could ___________________________________ |
julian_boolean
Member #8,201
January 2007
|
Hmm.. The button is being displayed properly, but it doesn't seem to be doing the "clicked" logic. Also, what does |= and &= mean? |
Johan Halmén
Member #1,550
September 2001
|
I've tried to read this thread some times, but can't figure out what you want to do. Do you want to create your own gui system? Or do you just want to have a button in your game? If the former, I guess it's a bit hard, if you still learn about &= and |=. If the latter, Allegro gui should do the job. a = a & b; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
julian_boolean
Member #8,201
January 2007
|
I just wanted an event/message handler using only Allegro. What is the difference between & and && anyway? |
Steve Terry
Member #1,989
March 2002
![]() |
&& is an AND comparison operator whereas & is a binary AND operator. For instance you would say if(someval == 2 && someotherval > 0) to only trigger the if statement only if both statements are true. Binary operations are completely different:
I'm using the operations to toggle bits in the flags variable. Which by posting this I realize a flaw in my W_* enumeration. You need each state to be a power of two. The changes would be: #define W_DISABLED 1 #define W_GOTMOUSE 2 #define W_SELECTED 4
___________________________________ |
julian_boolean
Member #8,201
January 2007
|
Still no luck. :/ No idea why it's not working for me, doesn't seem to like those W_'s. |
Steve Terry
Member #1,989
March 2002
![]() |
Allegro's defines are the same to mine, no reason it wouldn't work. Again I never said the code would work right off the bat, it's just there as an example so you can understand how things work. How are you using the class? Just stating it doesn't work doesn't tell me you are doing something wrong elsewhere. ___________________________________ |
julian_boolean
Member #8,201
January 2007
|
I just took functions from the code you did and stuck it in my own classes, modifying them slightly.
|
Steve Terry
Member #1,989
March 2002
![]() |
I don't know... you just aren't getting the picture here. I'm not sure if I can even help you. Take a closer look at my code instead of copying and pasting and get a good grasp of the concepts first. I give up. ___________________________________ |
julian_boolean
Member #8,201
January 2007
|
Will do.. I'm sorry for bugging so much, going to just work with what you did until it works for me! Thank you. |
|
|