Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » help customizing GUI

This thread is locked; no one can reply to it. rss feed Print
help customizing GUI
raja peter
Member #7,835
October 2006

hi,
I want to customize GUI elements. I want to incorporate button and other GUI elements' functionalities.

I just want to display a bgimg(bg), a button(but) and a cursor(cur) all bmp images.

I just want to create alert when the button is clicked.

I tried like this.

1#include "allegro.h"
2#include "algif.h"
3 
4BITMAP *bg,*b;
5BITMAP *buffer;
6BITMAP *cur;
7 
8 
9int change_font_proc(int msg, DIALOG *d, int c)
10{
11 int ret;
12 
13 /* call the parent object */
14 ret = d_button_proc(msg, d, c);
15 
16 /* trap the close return value and change the font */
17 if (ret == D_CLOSE) {
18
19 alert("An alert",NULL,NULL,"OK",NULL,0,0);
20 return D_O_K;
21 }
22 
23 /* otherwise just return */
24 return ret;
25}
26 
27DIALOG the_dialog[] =
28{
29 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
30 { d_clear_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
31 { change_font_proc, 300, 300, 140, 37, 0, 0, 0, D_EXIT, 0, 0, "", NULL, NULL },
32 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
33};
34 
35int main()
36{
37
38 if (allegro_init() != 0)
39 return 1;
40
41 install_keyboard();
42 install_timer();
43 install_mouse();
44 if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0)
45 {
46 allegro_message("Error initialising sound\n%s\n", allegro_error);
47 install_sound(DIGI_NONE, MIDI_NONE, NULL);
48 }
49 set_color_depth(32);
50 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
51
52 bg=load_bitmap("bg.bmp",NULL);
53 b=load_bitmap("but.bmp",NULL);
54 cur=load_bitmap("cur.bmp",NULL);
55 buffer=create_bitmap(800,600);
56
57 do_dialog(the_dialog, -1);
58
59 int mx,my;
60 while(!key[KEY_ESC])
61 {
62 mx=mouse_x;
63 my=mouse_y;
64 draw_sprite(buffer,bg,0,0);
65 draw_sprite(buffer,b,300,300);
66 draw_sprite(buffer,cur,mx,my);
67 draw_sprite(screen,buffer,0,0);
68
69 rest(16);
70 }
71 allegro_exit();
72 
73 return 0;
74}
75 
76END_OF_MAIN()

It compiles and runs. But It gives only a black screen and If i click on positions around (300,300) and (440,340), alerts are popping up.

Help me to find What is wrong with the code. Am i in a wrong path. Is there any other way to do it.

Thanks.

luv,

raja

GullRaDriel
Member #3,861
September 2003
avatar

You need to:

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

raja peter
Member #7,835
October 2006

I want to display the bmp images on my screen and do the gui functionality.

I set the dialog color. It doesn't display my bmp images.

luv,

raja

spellcaster
Member #1,493
September 2001
avatar

Well, I'll tell you what you code does. You can then tell me if this is what you want ;)

First the dialog is called. No bitmaps will be shown here. Once you finish the dialog, you will enter the while loop displaying your bitmaps.

If you quit the dialog using ESC you'll never run into the while loop and the program will just exit.

Is this what you want? or do you want to display the bitmaps inside the dialog? If so, there is a bitmap proc to do this.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

raja peter
Member #7,835
October 2006

i need to dig more .

Thanks spellcaster.

luv,

raja

GullRaDriel
Member #3,861
September 2003
avatar

raja: first check that your bitmap are loaded.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

raja peter
Member #7,835
October 2006

yes they've been loaded. I tested by commenting do_dialog. They are displayed. I've to try what spellcaster has mentioned.

luv,

raja

Go to: