|
allegro gui |
ImLeftFooted
Member #3,935
October 2003
|
Yes, there are many ways. |
CGamesPlay
Member #2,559
July 2002
|
Quote: Is there any way to handle my classes with the Allegro gui or do I HAVE to scrap it and use their ugly buttons? Of course you can do it with Allegro. What's the problem? -- Ryan Patterson - <http://cgamesplay.com/> |
julian_boolean
Member #8,201
January 2007
|
The problem is I don't know how. Well I have a vague idea.. |
CGamesPlay
Member #2,559
July 2002
|
Well try, fail, and post your code when you get stuck! -- Ryan Patterson - <http://cgamesplay.com/> |
ImLeftFooted
Member #3,935
October 2003
|
The trick is to look at the extra parameter the callback gets. In that parameter pass a pointer to your class object. |
julian_boolean
Member #8,201
January 2007
|
I did post code, and when am I not stuck? How is this to work with the switch(msg)? |
ImLeftFooted
Member #3,935
October 2003
|
You skipped the first two steps: Ryan said: Well try, fail, ...
|
julian_boolean
Member #8,201
January 2007
|
Very well thanks for the help everyone and you'll be sure to hear back from me very shortly |
Johan Halmén
Member #1,550
September 2001
|
Quote: or do I HAVE to scrap it and use their ugly buttons? Well, Allegro has some ugly buttons, but you can always use d_icon_proc() which is a button with three bitmaps, one for each state of the button (up, down, inactive). If that is still ugly, you suck with graphics. I once made a class that created these three buttons on the fly. It took a string, a pattern bitmap and a font as parameters. Very simple. Every button looked a bit different. The pattern was seamless and the tiling started at a random point on each button. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest. |
Steve Terry
Member #1,989
March 2002
|
MASkinG and NAS both use themed buttons using 9 bitmaps per button like so: +---+-------------+---+ | | | | +---+-------------+---+ | |I'M A BUTTON!| | +---+-------------+---+ | | | | +---+-------------+---+ You have four corners, a top, bottom, left, right, and middle image. Text goes in the middle, and you can stretch or tile the other bitmaps to make the button any size. This is a much better way than a single bitmap. You can write your own Allegro Button widget by overloading the MSG draw portion of the allegro button with your own widget proc. It's not hard to do and the other messages are left alone so you won't have to recode that. ___________________________________ |
julian_boolean
Member #8,201
January 2007
|
Quote: You can write your own Allegro Button widget by overloading the MSG draw portion of the allegro button with your own widget proc. It's not hard to do and the other messages are left alone so you won't have to recode that. Yes! This is what I want to do but how? (example?) |
Steve Terry
Member #1,989
March 2002
|
int my_button_proc(int msg, DIALOG *d, int c) { if(msg == MSG_DRAW) { // Draw the button } else return d_button_proc(msg, d, c); }
___________________________________ |
julian_boolean
Member #8,201
January 2007
|
I sorta understand that.. But I don't understand how it's suppose to work with the switch statement, or how I'm suppose to use the function in a game state, like is_clicked(). |
BAF
Member #2,981
December 2002
|
What switch statement? |
julian_boolean
Member #8,201
January 2007
|
It was on the previous page:
Something like that anyway. |
BAF
Member #2,981
December 2002
|
Uhm, you don't need that to overload MSG_DRAW because you aren't checking for all those messages. |
julian_boolean
Member #8,201
January 2007
|
I wish I could understand. What's the point of using this MSG_DRAW when I could use this instead? I need to draw different frames of the button if it's down, up, or whatever. Er wait a sec, how about this? case MSG_DRAW { if(MSG_LPRESS) { draw_frame = DRAW_FRAME_DOWN; } }break;
|
Steve Terry
Member #1,989
March 2002
|
The DIALOG object has a flags field. You can get the state of the button through the flags and draw accordingly. Here is code from NAS that does just that:
[edit] ___________________________________ |
BAF
Member #2,981
December 2002
|
Uhm, a switch/case setup is the same as a whole bunch of nested if/else ifs. There is no reason to use a switch, case, or anything else in your case. What Steve posted here will work fine for you. |
julian_boolean
Member #8,201
January 2007
|
Hmm.. I'll try it out, but what is NAS_BUTTON/NAS_TEXT?.. And box and col? |
Steve Terry
Member #1,989
March 2002
|
Those are NAS GUI defines but you can use whatever you want... they are just indexes into an array of button images so that when I pass in buttons.rect into draw_skinned_rect I get the proper image to display. col IIRC is the color index of the text to display since each state of the button can have different text color. ___________________________________ |
julian_boolean
Member #8,201
January 2007
|
Ohh okay, so I could just use my draw_frame instead? (my text is already on the graphics) |
Steve Terry
Member #1,989
March 2002
|
Right-o ___________________________________ |
julian_boolean
Member #8,201
January 2007
|
Awesome Thanks a ton.. One last thing, what is d? |
Steve Terry
Member #1,989
March 2002
|
DIALOG struct said:
int (*proc)(int, DIALOG *, int); - dialog procedure d is a pointer to this structure, you have flags... which you can use to get the state of the widget. Positional and size values are x, y, w, h. dpX are pointers to any kind of data you wish (can include a callback function for your button). ___________________________________ |
|
|