Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » allegro gui

This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
allegro gui
Dustin Dettmer
Member #3,935
October 2003
avatar

Yes, there are many ways.

CGamesPlay
Member #2,559
July 2002
avatar

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?

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

julian_boolean
Member #8,201
January 2007

The problem is I don't know how. :P Well I have a vague idea..

CGamesPlay
Member #2,559
July 2002
avatar

Well try, fail, and post your code when you get stuck! :)

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Dustin Dettmer
Member #3,935
October 2003
avatar

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? :P

How is this to work with the switch(msg)?

Dustin Dettmer
Member #3,935
October 2003
avatar

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 :P

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 the red "x" that closes a window, really isn't red, but white on red background.

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
avatar

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.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

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
avatar

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);
}

:P

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

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
avatar

What switch statement?

julian_boolean
Member #8,201
January 2007

It was on the previous page:

1int button::logic(int msg)
2{
3 switch(msg)
4 {
5 case MSG_LPRESS:
6 draw_frame = DRAW_FRAME_DOWN;
7 play_sound = PLAY_SOUND_DOWN;
8 break;
9
10 case MSG_LRELEASE:
11 draw_frame = DRAW_FRAME_ON;
12 play_sound = PLAY_SOUND_ON;
13 break;
14
15 case MSG_IDLE:
16 draw_frame = DRAW_FRAME_OFF;
17 break;
18 }
19}

Something like that anyway.

BAF
Member #2,981
December 2002
avatar

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
avatar

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:

1if(d->flags & D_DISABLED)
2{
3 box = NAS_BUTTON_DISABLED;
4 col = NAS_TEXT_DISABLED;
5}
6else if(d->flags & D_SELECTED)
7{
8 box = NAS_BUTTON_PRESSED;
9 col = NAS_TEXT_PRESSED;
10}
11else if(d->flags & D_GOTMOUSE)
12{
13 box = NAS_BUTTON_HIGHLIGHTED;
14 col = NAS_TEXT_HIGHLIGHTED;
15}
16else if(d->flags & D_GOTFOCUS)
17{
18 box = NAS_BUTTON_FOCUSED;
19 col = NAS_TEXT_FOCUSED;
20}
21else
22{
23 box = NAS_BUTTON_UNSELECTED;
24 col = NAS_TEXT_UNSELECTED;
25}
26drawskinnedrect(wnd, &buttons.rect[box], d->x, d->y, d->x + d->w, d->y + d->h);

[edit]
DON'T mix MSG_DRAW with other messages ...
[/edit]

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

BAF
Member #2,981
December 2002
avatar

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. :P

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
avatar

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.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

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
avatar

Right-o

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

julian_boolean
Member #8,201
January 2007

Awesome :D Thanks a ton.. One last thing, what is d?

Steve Terry
Member #1,989
March 2002
avatar

DIALOG struct said:

int (*proc)(int, DIALOG *, int); - dialog procedure
(message handler)
int x, y, w, h; - position and size of the object
int fg, bg; - foreground and background colors
int key; - ASCII keyboard shortcut
int flags; - flags about the status of the object
int d1, d2; - whatever you want to use them for
void *dp, *dp2, *dp3; - pointers to more object-specific data

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).

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

 1   2   3 


Go to: