From: <tj...@us...> - 2008-09-26 22:24:03
|
Revision: 10984 http://alleg.svn.sourceforge.net/alleg/?rev=10984&view=rev Author: tjaden Date: 2008-09-26 22:24:00 +0000 (Fri, 26 Sep 2008) Log Message: ----------- Rename ex_flip.c to ex_bitmap_flip.c. Reindent and remove incomplete attempts to avoid global variables. Add to scons build. Modified Paths: -------------- allegro/branches/4.9/examples/CMakeLists.txt allegro/branches/4.9/scons/all.scons Added Paths: ----------- allegro/branches/4.9/examples/ex_bitmap_flip.c Removed Paths: ------------- allegro/branches/4.9/examples/ex_flip.c Modified: allegro/branches/4.9/examples/CMakeLists.txt =================================================================== --- allegro/branches/4.9/examples/CMakeLists.txt 2008-09-26 22:04:11 UTC (rev 10983) +++ allegro/branches/4.9/examples/CMakeLists.txt 2008-09-26 22:24:00 UTC (rev 10984) @@ -15,6 +15,7 @@ if(SUPPORT_IIO) example(ex_bitmap ${IIO_LINK_WITH}) + example(ex_bitmap_flip ${IIO_LINK_WITH}) example(ex_convert ${IIO_LINK_WITH}) example(ex_dualies ${IIO_LINK_WITH}) example(ex_expose ${IIO_LINK_WITH}) @@ -28,7 +29,6 @@ example(ex_resize2 ${IIO_LINK_WITH}) example(ex_scale ${IIO_LINK_WITH}) example(ex_winfull ${IIO_LINK_WITH}) - example(ex_flip ${IIO_LINK_WITH}) endif(SUPPORT_IIO) if(SUPPORT_KCM_AUDIO) Added: allegro/branches/4.9/examples/ex_bitmap_flip.c =================================================================== --- allegro/branches/4.9/examples/ex_bitmap_flip.c (rev 0) +++ allegro/branches/4.9/examples/ex_bitmap_flip.c 2008-09-26 22:24:00 UTC (rev 10984) @@ -0,0 +1,126 @@ +/* An example showing bitmap flipping flags, by Steven Wallace. */ + +#include <allegro5/allegro5.h> +#include <allegro5/a5_iio.h> + +#define INTERVAL 0.01 + + +float bmp_x = 0; +float bmp_y = 0; +float bmp_dx = 96; +float bmp_dy = 96; +int bmp_flag = 0; + + +void update(ALLEGRO_BITMAP *bmp) +{ + int display_w = al_get_display_width(); + int display_h = al_get_display_height(); + int bitmap_w = al_get_bitmap_width(bmp); + int bitmap_h = al_get_bitmap_height(bmp); + + bmp_x += bmp_dx * INTERVAL; + bmp_y += bmp_dy * INTERVAL; + + /* Make sure bitmap is still on the screen. */ + if (bmp_y < 0) { + bmp_y = 0; + bmp_dy *= -1; + bmp_flag &= ~ALLEGRO_FLIP_VERTICAL; + } + + if (bmp_x < 0) { + bmp_x = 0; + bmp_dx *= -1; + bmp_flag &= ~ALLEGRO_FLIP_HORIZONTAL; + } + + if (bmp_y > display_h - bitmap_h) { + bmp_y = display_h - bitmap_h; + bmp_dy *= -1; + bmp_flag |= ALLEGRO_FLIP_VERTICAL; + } + + if (bmp_x > display_w - bitmap_w) { + bmp_x = display_w - bitmap_w; + bmp_dx *= -1; + bmp_flag |= ALLEGRO_FLIP_HORIZONTAL; + } +} + + +int main(int argc, char *argv[]) +{ + ALLEGRO_DISPLAY *display; + ALLEGRO_TIMER *timer; + ALLEGRO_EVENT_QUEUE *queue; + ALLEGRO_BITMAP *bmp; + bool done = false; + + if (!al_init()) { + TRACE("Failed to init Allegro.\n"); + return 1; + } + + if (!al_iio_init()) { + TRACE("Failed to init IIO addon.\n"); + return 1; + } + + display = al_create_display(640, 480); + if (!display) { + TRACE("Error creating display.\n"); + return 1; + } + + if (!al_install_keyboard()) { + TRACE("Error installing keyboard.\n"); + return 1; + } + + bmp = al_iio_load("data/mysha.pcx"); + if (!bmp) { + TRACE("Error loading data/mysha.pcx\n"); + return 1; + } + + timer = al_install_timer(INTERVAL); + + queue = al_create_event_queue(); + al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE *) al_get_keyboard()); + al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE *) timer); + al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE *) display); + + al_start_timer(timer); + + while (!done) { + ALLEGRO_EVENT event; + + al_wait_for_event(queue, &event); + switch (event.type) { + case ALLEGRO_EVENT_KEY_DOWN: + if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) + done = true; + break; + + case ALLEGRO_EVENT_DISPLAY_CLOSE: + done = true; + break; + + case ALLEGRO_EVENT_TIMER: + update(bmp); + al_clear(al_map_rgb(0, 0, 0)); + al_draw_bitmap(bmp, bmp_x, bmp_y, bmp_flag); + al_flip_display(); + break; + } + } + + al_destroy_bitmap(bmp); + + return 0; +} +END_OF_MAIN() + +/* vim: set sts=3 sw=3 et: */ Deleted: allegro/branches/4.9/examples/ex_flip.c =================================================================== --- allegro/branches/4.9/examples/ex_flip.c 2008-09-26 22:04:11 UTC (rev 10983) +++ allegro/branches/4.9/examples/ex_flip.c 2008-09-26 22:24:00 UTC (rev 10984) @@ -1,110 +0,0 @@ -/* An example showing bitmap flipping flags, by Steven Wallace. */ - -#include <allegro5/allegro5.h> -#include <allegro5/a5_iio.h> - -#define INTERVAL 0.01 - - -void update(float *bmp_x, float *bmp_y, int *bmp_flag, ALLEGRO_BITMAP *bmp) { - static float bmp_dx = 96, bmp_dy = 96; - *bmp_x += bmp_dx * INTERVAL; - *bmp_y += bmp_dy * INTERVAL; - - // Make sure bitmap is still on the screen - if(*bmp_y < 0) { - *bmp_y = 0; - bmp_dy *= -1; - *bmp_flag &= ~ALLEGRO_FLIP_VERTICAL; - } - - if(*bmp_x < 0) { - *bmp_x = 0; - bmp_dx *= -1; - *bmp_flag &= ~ALLEGRO_FLIP_HORIZONTAL; - } - - if(*bmp_y > al_get_display_height() - al_get_bitmap_height(bmp)) { - *bmp_y = al_get_display_height() - al_get_bitmap_height(bmp); - bmp_dy *= -1; - *bmp_flag |= ALLEGRO_FLIP_VERTICAL; - } - - if(*bmp_x > al_get_display_width() - al_get_bitmap_width(bmp)) { - *bmp_x = al_get_display_width() - al_get_bitmap_width(bmp); - bmp_dx *= -1; - *bmp_flag |= ALLEGRO_FLIP_HORIZONTAL; - } -} - - -int main(int argc, char *argv[]) { - ALLEGRO_DISPLAY *display; - ALLEGRO_TIMER *timer; - ALLEGRO_EVENT_QUEUE *queue; - ALLEGRO_BITMAP *bmp; - float bmp_x = 0, bmp_y = 0; - int bmp_flag = 0; - volatile bool done = false; - - if (!al_init()) { - TRACE("Failed to init Allegro.\n"); - return 1; - } - - if (!al_iio_init()) { - TRACE("Failed to init IIO addon.\n"); - return 1; - } - - display = al_create_display(640, 480); - if(!display) { - TRACE("Error creating display.\n"); - return 1; - } - - if(!al_install_keyboard()) { - TRACE("Error installing keyboard.\n"); - return 1; - } - - timer = al_install_timer(INTERVAL); - al_start_timer(timer); - - queue = al_create_event_queue(); - al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE *)al_get_keyboard()); - al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE *)timer); - al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE *)display); - - bmp = al_iio_load("data/mysha.pcx"); - if(!bmp) { - TRACE("Error loading data/mysha.pcx\n"); - return 1; - } - - while (!done) { - ALLEGRO_EVENT event; - - al_wait_for_event(queue, &event); - switch(event.type) { - case ALLEGRO_EVENT_KEY_DOWN: - if(event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) - done = true; - break; - - case ALLEGRO_EVENT_DISPLAY_CLOSE: - done = true; - break; - - case ALLEGRO_EVENT_TIMER: - update(&bmp_x, &bmp_y, &bmp_flag, bmp); - al_clear(al_map_rgb(0, 0, 0)); - al_draw_bitmap(bmp, bmp_x, bmp_y, bmp_flag); - al_flip_display(); - break; - } - } - - return 0; -} -END_OF_MAIN() Modified: allegro/branches/4.9/scons/all.scons =================================================================== --- allegro/branches/4.9/scons/all.scons 2008-09-26 22:04:11 UTC (rev 10983) +++ allegro/branches/4.9/scons/all.scons 2008-09-26 22:24:00 UTC (rev 10984) @@ -93,6 +93,7 @@ example("ex_acodec_multi") example("ex_stream_file") example("ex_bitmap") + example("ex_bitmap_flip") example("ex_bitmap_target") example("ex_blend") example("ex_drawpixels") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |