Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Update Dialog on a specific BITMAP

Credits go to Kitty Cat, Matt Weir, and Timorg for helping out!
This thread is locked; no one can reply to it. rss feed Print
Update Dialog on a specific BITMAP
GullRaDriel
Member #3,861
September 2003
avatar

Hello.

basically I need draw my DIALOG on a specific BITMAP but this is not working.

Here is the code:

1/**\file SprEdit.c
2*
3* SprEdit Main Program
4*
5*\author Castagnier Mickaƫl
6*
7*\version 1.0
8*
9*\date 24/03/07
10*
11*/
12 
13 
14 
15#include <nilorea.h>
16 
17 
18DIALOG MainGui[] =
19{
20 /* (proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
21 { d_radio_proc, 16, 696, 16, 16, 0, 0, 0, 0, 0, 0, "Full", NULL, NULL },
22 { d_radio_proc, 16, 712, 16, 16, 0, 0, 0, 0, 0, 0, "Masked", NULL, NULL },
23 { d_radio_proc, 16, 728, 16, 16, 0, 0, 0, 0, 0, 0, "Transparent", NULL, NULL },
24 { d_button_proc, 216, 704, 120, 16, 0, 0, 0, 0, 0, 0, "Set Hot Point", NULL, NULL },
25 { d_button_proc, 352, 704, 128, 16, 0, 0, 0, 0, 0, 0, "Set frame Delay", NULL, NULL },
26 { d_button_proc, 496, 704, 144, 16, 0, 0, 0, 0, 0, 0, "Next in Batch", NULL, NULL },
27 { d_button_proc, 352, 728, 128, 16, 0, 0, 0, 0, 0, 0, "Apply To All", NULL, NULL },
28 { d_button_proc, 216, 728, 120, 16, 0, 0, 0, 0, 0, 0, "Apply To All", NULL, NULL },
29 { d_button_proc, 496, 728, 144, 16, 0, 0, 0, 0, 0, 0, "Previous in Batch", NULL, NULL },
30 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
31};
32 
33DIALOG_PLAYER *gui;
34 
35int DONE = 0 ;
36 
37 
38 
39BITMAP *buf;
40 
41 
42 
43int main (int argc, char *argv[])
44{
45 
46 allegro_init();
47 install_timer();
48 install_mouse();
49 install_keyboard();
50 
51 gfx_mode( GFX_DIRECTX_WIN , 1024 , 768 , 0 , 0 , 32 , 0 , 0 , 0 , 0 );
52 
53 buf = create_bitmap( SCREEN_W , SCREEN_H );
54 clear( buf );
55 
56 gui_set_screen(buf);
57 
58 gui=init_dialog(MainGui,-1);
59 
60 
61 while( !DONE )
62 {
63 
64 clear_to_color( buf , makecol( 255,255,255 ) );
65 update_dialog(gui);
66 
67 
68 circle( buf , mouse_x , mouse_y , 5 , makecol( 255 , 255 , 0 ) );
69 
70 line( buf , mouse_x - 10 , mouse_y , mouse_x + 10 , mouse_y , makecol( 255 , 255 , 255 ) );
71 line( buf , mouse_x , mouse_y - 10 , mouse_x , mouse_y +10 , makecol( 255 , 255 , 255 ) );
72 
73 
74 blit( buf , screen , 0 , 0 , 0 , 0 , buf -> w , buf -> h );
75 
76 if( key[ KEY_ESC ] )
77 DONE = 1 ;
78 }
79 
80}END_OF_MAIN()

Where do am I wrong ?

_

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

Matt Weir
Member #7,476
July 2006
avatar

I think I tried to do the same thing a while ago and came to the conclusion that it could be broken. I switched my program to OpenLayer (for other reasons) and promptly forgot about it before following it up any further. (I could have been doing something wrong too though...)

Matt Weir.

Kitty Cat
Member #2,815
October 2002
avatar

A dialog uses a dirty rectangles-like system. So when you clear the bitmap, the dialog has no idea it needs to redraw itself, and thus doesn't, leaving your bitmap blank. Either don't clear the bitmap, or tell the dialog to redraw all of itself:
dialog_message(MainGui, MSG_DRAW, NULL);

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Timorg
Member #2,028
March 2002

You needed to set the gui objects colors set_dialog_color() and broadcast_dialog_message() telling it needs to be redrawn

1#include <allegro.h>
2 
3 
4DIALOG MainGui[] =
5{
6 /* (proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7 { d_radio_proc, 16, 696, 16, 16, 0, 0, 0, 0, 0, 0, "Full", NULL, NULL },
8 { d_radio_proc, 16, 712, 16, 16, 0, 0, 0, 0, 0, 0, "Masked", NULL, NULL },
9 { d_radio_proc, 16, 728, 16, 16, 0, 0, 0, 0, 0, 0, "Transparent", NULL, NULL },
10 { d_button_proc, 216, 704, 120, 16, 0, 0, 0, 0, 0, 0, "Set Hot Point", NULL, NULL },
11 { d_button_proc, 352, 704, 128, 16, 0, 0, 0, 0, 0, 0, "Set frame Delay", NULL, NULL },
12 { d_button_proc, 496, 704, 144, 16, 0, 0, 0, 0, 0, 0, "Next in Batch", NULL, NULL },
13 { d_button_proc, 352, 728, 128, 16, 0, 0, 0, 0, 0, 0, "Apply To All", NULL, NULL },
14 { d_button_proc, 216, 728, 120, 16, 0, 0, 0, 0, 0, 0, "Apply To All", NULL, NULL },
15 { d_button_proc, 496, 728, 144, 16, 0, 0, 0, 0, 0, 0, "Previous in Batch", NULL, NULL },
16 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
17};
18 
19DIALOG_PLAYER *gui;
20 
21int DONE = 0 ;
22 
23 
24 
25BITMAP *buf;
26 
27 
28 
29int main (int argc, char *argv[])
30{
31 
32 allegro_init();
33 install_timer();
34 install_mouse();
35 install_keyboard();
36 
37 set_color_depth(32);
38 set_gfx_mode( GFX_DIRECTX_WIN , 1024 , 768 , 0 , 0);
39 
40 buf = create_bitmap( SCREEN_W , SCREEN_H );
41 clear( buf );
42 
43 
44 
45 gui_set_screen(buf);
46 show_mouse(buf);
47 set_dialog_color(MainGui, makecol(0,0,0), makecol(255,255,255));
48 
49 gui=init_dialog(MainGui,-1);
50 
51 while( !DONE )
52 {
53 
54 show_mouse(NULL);
55 
56 clear_to_color( buf , makecol( 255,255,255 ) );
57 
58 broadcast_dialog_message(MSG_DRAW, 0);
59 update_dialog(gui);
60 
61 
62 circle( buf , mouse_x , mouse_y , 5 , makecol( 255 , 255 , 0 ) );
63 
64 line( buf , mouse_x - 10 , mouse_y , mouse_x + 10 , mouse_y , makecol( 255 , 255 , 255 ) );
65 line( buf , mouse_x , mouse_y - 10 , mouse_x , mouse_y +10 , makecol( 255 , 255 , 255 ) );
66 
67 show_mouse(gui_get_screen());
68 
69 
70 blit( buf , screen , 0 , 0 , 0 , 0 , buf -> w , buf -> h );
71 
72 if( key[ KEY_ESC ] )
73 DONE = 1 ;
74 }
75 
76}END_OF_MAIN()

____________________________________________________________________________________________
"c is much better than c++ if you don't need OOP simply because it's smaller and requires less load time." - alethiophile
OMG my sides are hurting from laughing so hard... :D

GullRaDriel
Member #3,861
September 2003
avatar

That solves my problem, thanks.

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

Go to: