Loodwin Temat założony przez niniejszego użytkownika |
[Allegro, C++] Jak stworzyć prosty przycisk (button)? » 2011-08-01 11:15:19 Chciałbym się dowiedzieć jak zrobić pole aktywne. Aktualnie mam taki kod: #include <allegro.h>
BITMAP * ludek = NULL; void laduj_ludek() { ludek = load_bmp( "ludek.bmp", default_palette ); if( !ludek ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "nie mogę załadować obrazka Ludek !" ); allegro_exit(); } }
BITMAP * kliknij;
void laduj_kliknij() { kliknij = load_bitmap( "kliknij.bmp", NULL ); if( !kliknij ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "Nie moge zaladowac grafiki ( kliknij )" ); allegro_exit(); } };
BITMAP * kursor;
void laduj_kursor() { kursor = load_bitmap( "kursor.bmp", NULL ); if( !kursor ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( "Nie moge zaladowac grafiki ( kursor )" ); allegro_exit(); } };
int mx = 0, my = 0, mb = 0; void myszka() { if( mx != mouse_x || my != mouse_y || mb != mouse_b ) { mx = mouse_x; my = mouse_y; mb = mouse_b; } };
int main() { allegro_init(); install_keyboard(); set_color_depth( 16 ); set_gfx_mode( GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0 ); clear_to_color( screen, makecol( 128, 128, 128 ) ); BITMAP * bufor = NULL; bufor = create_bitmap( 800, 600 ); laduj_kursor(); laduj_kliknij(); laduj_ludek(); install_mouse(); show_mouse( screen ); set_mouse_sprite( kursor ); unscare_mouse(); masked_blit( kliknij, bufor, 0, 0, 250, 250, kliknij->w, kliknij->h ); while( !key[ KEY_ESC ] ) { clear_to_color( bufor, makecol( 100, 100, 100 ) ); myszka(); textprintf_ex( bufor, font, 20, 20, makecol( 200, 200, 200 ), - 1, "Myszka x = %d, y = %d, klawisz = %d !", mx, my, mb ); blit( bufor, screen, 0, 0, 0, 0, 800, 600 ); clear_keybuf(); } if( mx = 250, my = 250, mb = 1 ) { masked_blit( ludek, bufor, 0, 0, 100, 100, ludek->w, ludek->h ); }; readkey(); destroy_bitmap( ludek ); destroy_bitmap( kursor ); destroy_bitmap( kliknij ); destroy_bitmap( bufor ); allegro_exit(); return 0; } END_OF_MAIN(); Nie wyświetla mi się wogóle bitmapa "kliknij". |