static void run(void) { ALLEGRO_EVENT event; bool quit = false; while (!quit) { while (al_get_next_event(queue, &event)) { if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) quit = true; else if (event.type == ALLEGRO_EVENT_KEY_DOWN) { if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) quit = true; else if (event.keyboard.keycode == ALLEGRO_KEY_SPACE) { bool opp = !(al_get_display_flags(display) & ALLEGRO_FULLSCREEN_WINDOW); al_set_display_flag(display, ALLEGRO_FULLSCREEN_WINDOW, opp); redraw(); } else if (event.keyboard.keycode == ALLEGRO_KEY_ENTER) { big = !big; if (big) al_resize_display(display, 800, 600); else al_resize_display(display, 640, 480); redraw(); } } } /* FIXME: Lazy timing */ al_rest(0.02); redraw(); } }
static SCM game_fullscreen (SCM game_smob) { Game *game = check_game (game_smob); return scm_from_bool (al_get_display_flags (game->display) & ALLEGRO_FULLSCREEN); }
static void redraw(void) { ALLEGRO_COLOR color; int w = al_get_display_width(display); int h = al_get_display_height(display); int pw = al_get_bitmap_width(picture); int ph = al_get_bitmap_height(picture); int th = al_get_font_line_height(font); float cx = (w - pw) * 0.5; float cy = (h - ph) * 0.5; ALLEGRO_COLOR white = al_map_rgb_f(1, 1, 1); color = al_map_rgb_f(0.8, 0.7, 0.9); al_clear_to_color(color); color = al_map_rgb(255, 0, 0); al_draw_line(0, 0, w, h, color, 0); al_draw_line(0, h, w, 0, color, 0); al_draw_bitmap(picture, cx, cy, 0); al_draw_textf(font, white, w / 2, cy + ph, ALLEGRO_ALIGN_CENTRE, "Press Space to toggle fullscreen"); al_draw_textf(font, white, w / 2, cy + ph + th, ALLEGRO_ALIGN_CENTRE, "Press Enter to toggle window size"); al_draw_textf(font, white, w / 2, cy + ph + th * 2, ALLEGRO_ALIGN_CENTRE, "Window: %dx%d (%s)", al_get_display_width(display), al_get_display_height(display), (al_get_display_flags(display) & ALLEGRO_FULLSCREEN_WINDOW) ? "fullscreen" : "not fullscreen"); al_flip_display(); }
MBITMAP *m_create_alpha_bitmap(int w, int h, void (*create)(MBITMAP *bitmap, RecreateData *), RecreateData *data, void (*destroy)(MBITMAP *b), bool delayed) // check { int f = al_get_new_bitmap_format(); al_set_new_bitmap_format(ALPHA_FMT); ALLEGRO_BITMAP *bitmap; int flags = al_get_new_bitmap_flags(); int new_flags = flags; if (config.getUseOnlyMemoryBitmaps()) { al_set_new_bitmap_flags(new_flags|ALLEGRO_MEMORY_BITMAP); bitmap = my_al_create_bitmap(w, h); } else { bitmap = my_al_create_bitmap(w, h); } al_set_new_bitmap_flags(flags); al_set_new_bitmap_format(f); MBITMAP *m = new_mbitmap(bitmap); if (create) { create(m, data); } #if defined ALLEGRO_ANDROID || defined ALLEGRO_WINDOWS if ( #ifdef ALLEGRO_WINDOWS (al_get_display_flags(display) & ALLEGRO_DIRECT3D) && #endif (al_get_bitmap_flags(bitmap) & ALLEGRO_NO_PRESERVE_TEXTURE) && !(al_get_bitmap_flags(bitmap) & ALLEGRO_MEMORY_BITMAP) ) { LoadedBitmap *lb = new LoadedBitmap; null_lb(lb); lb->load_type = LOAD_CREATE; lb->flags = al_get_bitmap_flags(bitmap); lb->format = al_get_bitmap_format(bitmap); lb->destroy.func = destroy; lb->recreate.func = create; lb->recreate.data = data; lb->recreate.w = w; lb->recreate.h = h; lb->bitmap = m; lb->delayed = delayed; loaded_bitmaps.push_back(lb); } else { #endif if (data) { delete data; } #if defined ALLEGRO_ANDROID || defined ALLEGRO_WINDOWS } #endif return m; }
/** Returns the fullscreen display mode in ID as string * @param id Id of the display mode. MUST BE in range of 0 to cbeGetGfxModesCount()-1. * @returns Display mode as string. I.e. cbeGetGfxMode(0) returns a string "640,480,60,32" (in most cases). */ void cbeGetGfxMode(CBEnchanted *cb) { // Store the old flags for later restoring int32_t oldFlags = al_get_display_flags(cb->gfxInterface->getWindow()); // Set the display flags for fullscreen al_set_new_display_flags(ALLEGRO_FULLSCREEN); // Get display modes count int32_t displayModesCount = al_get_num_display_modes(); // Pop the ID from input int32_t displayId = cb->popValue().toInt(); // Check if displayId is valid if (displayId < 0 || displayId >= displayModesCount) { string id = std::to_string(displayId); string count = std::to_string(displayModesCount); bool ignore = cb->errors->createError("cbeGetGfxMode() failed!", "Trying to get gfx mode with ID " + id + " out of " + count + " modes\nWhen ignored, the first display mode available in the list is returned."); // If ignored, displayId is 0. Otherwise push empty string and return. if (ignore) { displayId = 0; } else { cb->pushValue(ISString("")); return; } } // Where the display modes data is stored ALLEGRO_DISPLAY_MODE *displayData = new ALLEGRO_DISPLAY_MODE; // Get the display mode with id al_get_display_mode(displayId, displayData); // Restore old flags al_set_new_display_flags(oldFlags); if (displayData != NULL) { // Initialize the string to be returned string displayModeString; // Construct the string displayModeString = std::to_string(displayData->width); displayModeString += "," + std::to_string(displayData->height); displayModeString += "," + std::to_string(displayData->refresh_rate); displayModeString += "," + std::to_string(al_get_pixel_format_bits(displayData->format)); // Return the display mode cb->pushValue(displayModeString.substr(0 , displayModeString.length() )); } else { INFO("Something funny happened in cbeGetGfxMode(), you got an empty display mode...") cb->pushValue(ISString("")); } // Free memory delete displayData; }
void GameMgr::processInput() { ALLEGRO_EVENT evento; while (!al_is_event_queue_empty(fila_eventos)) { al_clear_to_color(al_map_rgb(0, 0, 0)); // Colorindo a janela de preto al_wait_for_event(fila_eventos, &evento); if (evento.type == ALLEGRO_EVENT_KEY_DOWN) { // uma tecla foi pressionada switch (evento.keyboard.keycode) { case ALLEGRO_KEY_UP: player->trocaDirecao(0); break; case ALLEGRO_KEY_DOWN: player->trocaDirecao(2); break; case ALLEGRO_KEY_LEFT: player->trocaDirecao(3); break; case ALLEGRO_KEY_RIGHT: player->trocaDirecao(1); break; case ALLEGRO_KEY_ENTER: if (evento.keyboard.modifiers | ALLEGRO_KEYMOD_ALT) { auto mode = al_get_display_flags(display); if (mode | ALLEGRO_WINDOWED) { al_set_display_flag(display, ALLEGRO_FULLSCREEN_WINDOW, true); } else { al_set_display_flag(display, ALLEGRO_FULLSCREEN_WINDOW, false); } } break; case ALLEGRO_KEY_Q: case ALLEGRO_KEY_ESCAPE: exit(0); } } else if (evento.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) { // click no mouse if (evento.mouse.x > 0 && evento.mouse.x < 20 && evento.mouse.y > 0 && evento.mouse.y < 20) // cordenadas do botao exit(0); } else if (evento.type == ALLEGRO_EVENT_DISPLAY_RESIZE) { al_acknowledge_resize(display); screen_width = al_get_display_width(display); screen_height = al_get_display_height(display); _redraw = true; } else if (evento.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { // click no mouse exit(0); } else if (evento.type == ALLEGRO_EVENT_TIMER) { if (evento.timer.source == draw_timer) _redraw = true; else if (evento.timer.source == logic_timer) _tick = true; } redraw(); } al_destroy_display(display); // Finaliza a janela }
MBITMAP *m_load_alpha_bitmap(const char *name, bool force_memory) { ALLEGRO_BITMAP *bitmap = 0; int old = al_get_new_bitmap_format(); al_set_new_bitmap_format(ALPHA_FMT); if (!force_memory) bitmap = my_load_bitmap(name); if (!bitmap) { ALLEGRO_STATE s; al_store_state(&s, ALLEGRO_STATE_NEW_BITMAP_PARAMETERS); al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); bitmap = my_load_bitmap(name); al_restore_state(&s); } al_set_new_bitmap_format(old); if (!bitmap) { return NULL; } MBITMAP *m = new_mbitmap(bitmap); #if defined ALLEGRO_ANDROID || defined ALLEGRO_WINDOWS if ( #ifdef ALLEGRO_WINDOWS (al_get_display_flags(display) & ALLEGRO_DIRECT3D) && #endif (al_get_bitmap_flags(bitmap) & ALLEGRO_NO_PRESERVE_TEXTURE) && !(al_get_bitmap_flags(bitmap) & ALLEGRO_MEMORY_BITMAP) ) { LoadedBitmap *lb = new LoadedBitmap; null_lb(lb); lb->load_type = LOAD_LOAD; lb->flags = al_get_bitmap_flags(bitmap); lb->format = al_get_bitmap_format(bitmap); lb->load.filename = name; lb->load.redraw = NULL; lb->load.data = NULL; lb->bitmap = m; loaded_bitmaps.push_back(lb); } #endif return m; }
/** Get fullscreen display modes count * @returns List size */ void cbeGetGfxModesCount(CBEnchanted *cb) { // Store the old flags for later restoring int32_t oldFlags = al_get_display_flags(cb->gfxInterface->getWindow()); // Set the display flags for fullscreen al_set_new_display_flags(ALLEGRO_FULLSCREEN); // Get display modes count int32_t displayModesCount = al_get_num_display_modes(); // Restore old flags al_set_new_display_flags(oldFlags); // Return the modes count cb->pushValue(displayModesCount); }
MBITMAP *m_load_bitmap(const char *name, bool force_memory, bool ok_to_fail) { ALLEGRO_BITMAP *bitmap = 0; int flags = al_get_new_bitmap_flags(); if (force_memory || config.getUseOnlyMemoryBitmaps()) { al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); } else { al_set_new_bitmap_flags((flags & ~ALLEGRO_MEMORY_BITMAP)); } bitmap = my_load_bitmap(name, ok_to_fail); al_set_new_bitmap_flags(flags); if (!bitmap) { return NULL; } MBITMAP *m = new_mbitmap(bitmap); #if defined ALLEGRO_ANDROID || defined ALLEGRO_WINDOWS if ( #ifdef ALLEGRO_WINDOWS (al_get_display_flags(display) & ALLEGRO_DIRECT3D) && #endif (al_get_bitmap_flags(bitmap) & ALLEGRO_NO_PRESERVE_TEXTURE) && !(al_get_bitmap_flags(bitmap) & ALLEGRO_MEMORY_BITMAP) ) { LoadedBitmap *lb = new LoadedBitmap; null_lb(lb); lb->load_type = LOAD_LOAD; lb->flags = al_get_bitmap_flags(bitmap); lb->format = al_get_bitmap_format(bitmap); lb->load.filename = name; lb->load.redraw = NULL; lb->load.data = NULL; lb->bitmap = m; loaded_bitmaps.push_back(lb); } #endif return m; }
MBITMAP *m_load_bitmap_redraw(const char *name, void (*redraw)(MBITMAP *bmp, RecreateData *data), RecreateData *data, bool delayed) { ALLEGRO_BITMAP *bitmap = 0; bitmap = my_load_bitmap(name); if (!bitmap) { debug_message("Error loading bitmap %s\n", name); return NULL; } MBITMAP *m = new_mbitmap(bitmap); if (redraw) { redraw(m, data); } #if defined ALLEGRO_ANDROID || defined ALLEGRO_WINDOWS if ( #ifdef ALLEGRO_WINDOWS (al_get_display_flags(display) & ALLEGRO_DIRECT3D) && #endif (al_get_bitmap_flags(bitmap) & ALLEGRO_NO_PRESERVE_TEXTURE) && !(al_get_bitmap_flags(bitmap) & ALLEGRO_MEMORY_BITMAP) ) { LoadedBitmap *lb = new LoadedBitmap; null_lb(lb); lb->load_type = LOAD_LOAD; lb->flags = al_get_bitmap_flags(bitmap); lb->format = al_get_bitmap_format(bitmap); lb->load.filename = name; lb->load.redraw = redraw; lb->load.data = data; lb->bitmap = m; lb->delayed = delayed; loaded_bitmaps.push_back(lb); } #endif return m; }
/* the main game function */ static int play_game() { ALLEGRO_TIMER *inc_counter; int gameover = 0; int cyclenum = 0; /* init */ score = 0; init_view(); init_player(); init_badguys(); init_bullets(); init_explode(); init_message(); #define TIMER_SPEED ALLEGRO_BPS_TO_SECS(30*(cyclenum+2)) inc_counter = al_create_timer(TIMER_SPEED); al_start_timer(inc_counter); while (!gameover) { /* move everyone */ while ((al_get_timer_count(inc_counter) > 0) && (!gameover)) { update_view(); update_bullets(); update_explode(); update_message(); if (update_badguys()) { if (advance_view()) { cyclenum++; al_set_timer_count(inc_counter, 0); lay_attack_wave(TRUE); advance_player(TRUE); } else { lay_attack_wave(FALSE); advance_player(FALSE); } } gameover = update_player(); al_set_timer_count(inc_counter, al_get_timer_count(inc_counter)-1); } /* take a screenshot? */ if (key[ALLEGRO_KEY_PRINTSCREEN]) { static int ss_count = 0; char fname[80]; sprintf(fname, "speed%03d.tga", ++ss_count); al_save_bitmap(fname, al_get_backbuffer(screen)); while (key[ALLEGRO_KEY_PRINTSCREEN]) poll_input_wait(); al_set_timer_count(inc_counter, 0); } /* toggle fullscreen window */ if (key[ALLEGRO_KEY_F]) { int flags = al_get_display_flags(screen); al_set_display_flag(screen, ALLEGRO_FULLSCREEN_WINDOW, !(flags & ALLEGRO_FULLSCREEN_WINDOW)); while (key[ALLEGRO_KEY_F]) poll_input_wait(); } /* draw everyone */ draw_view(); } /* cleanup */ al_destroy_timer(inc_counter); shutdown_view(); shutdown_player(); shutdown_badguys(); shutdown_bullets(); shutdown_explode(); shutdown_message(); if (gameover < 0) { sfx_ping(1); return FALSE; } return TRUE; }
void engine_run(struct State *s) { int redraw = FALSE; if (engine_active) { return; } change_state(s, NULL); // Generate display events al_register_event_source(engine.event_queue, al_get_display_event_source(engine.display)); // Timer events al_register_event_source(engine.event_queue, al_get_timer_event_source(engine.timer)); // Keyboard events al_register_event_source(engine.event_queue, al_get_keyboard_event_source()); // Mouse events al_register_event_source(engine.event_queue, al_get_mouse_event_source()); al_start_timer(engine.timer); engine_active = TRUE; // Main game loop while (engine_active) { ALLEGRO_EVENT event; al_wait_for_event(engine.event_queue, &event); // Event processing engine.states[current_state]->_events(&event, &engine.sm); // If the close button was pressed... if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { engine_active = FALSE; break; } else if (event.type == ALLEGRO_EVENT_KEY_DOWN) { keys[event.keyboard.keycode] = TRUE; // F4 key will toggle full-screen if (event.keyboard.keycode == ALLEGRO_KEY_F4) { al_stop_timer(engine.timer); if (al_get_display_flags(engine.display) & ALLEGRO_FULLSCREEN_WINDOW) { al_toggle_display_flag(engine.display, ALLEGRO_FULLSCREEN_WINDOW, 0); } else { al_toggle_display_flag(engine.display, ALLEGRO_FULLSCREEN_WINDOW, 1); } aspect_ratio_transform(); al_start_timer(engine.timer); } } else if (event.type == ALLEGRO_EVENT_KEY_UP) { keys[event.keyboard.keycode] = FALSE; } else if (event.type == ALLEGRO_EVENT_TIMER) { engine.states[current_state]->_update(&engine.sm); redraw = TRUE; } if (redraw && engine_active && al_is_event_queue_empty(engine.event_queue)) { redraw = FALSE; if (MAINCONF->buffer) { al_set_target_bitmap(engine.buffer); } else { al_set_target_backbuffer(engine.display); } al_clear_to_color(engine.bg_color); engine.states[current_state]->_draw(&engine.sm); if (MAINCONF->buffer) { al_set_target_backbuffer(engine.display); al_clear_to_color(C_BLACK); al_draw_bitmap(engine.buffer, 0, 0, 0); } al_flip_display(); } } while (loaded_count > 0) { engine.loaded_states[--loaded_count]->_free(); } al_destroy_display(engine.display); al_destroy_timer(engine.timer); al_destroy_event_queue(engine.event_queue); al_destroy_font(font); if (MAINCONF->buffer) { al_destroy_bitmap(engine.buffer); } }
void _al_set_d3d_decl(ALLEGRO_VERTEX_DECL* ret) { #ifdef ALLEGRO_CFG_D3D int flags = al_get_display_flags(); if (flags & ALLEGRO_DIRECT3D) { ALLEGRO_DISPLAY *display; LPDIRECT3DDEVICE9 device; D3DVERTEXELEMENT9 d3delements[ALLEGRO_PRIM_ATTR_NUM + 1]; int idx = 0; ALLEGRO_VERTEX_ELEMENT* e; D3DCAPS9 caps; display = al_get_current_display(); device = al_d3d_get_device(display); IDirect3DDevice9_GetDeviceCaps(device, &caps); if(caps.PixelShaderVersion < D3DPS_VERSION(3, 0)) { ret->d3d_decl = 0; } else { e = &ret->elements[ALLEGRO_PRIM_POSITION]; if(e->attribute) { int type = 0; switch(e->storage) { case ALLEGRO_PRIM_FLOAT_2: type = D3DDECLTYPE_FLOAT2; break; case ALLEGRO_PRIM_FLOAT_3: type = D3DDECLTYPE_FLOAT3; break; case ALLEGRO_PRIM_SHORT_2: type = D3DDECLTYPE_SHORT2; break; } d3delements[idx].Stream = 0; d3delements[idx].Offset = e->offset; d3delements[idx].Type = type; d3delements[idx].Method = D3DDECLMETHOD_DEFAULT; d3delements[idx].Usage = D3DDECLUSAGE_POSITION; d3delements[idx].UsageIndex = 0; idx++; } e = &ret->elements[ALLEGRO_PRIM_TEX_COORD]; if(!e->attribute) e = &ret->elements[ALLEGRO_PRIM_TEX_COORD_PIXEL]; if(e->attribute) { int type = 0; switch(e->storage) { case ALLEGRO_PRIM_FLOAT_2: case ALLEGRO_PRIM_FLOAT_3: type = D3DDECLTYPE_FLOAT2; break; case ALLEGRO_PRIM_SHORT_2: type = D3DDECLTYPE_SHORT2; break; } d3delements[idx].Stream = 0; d3delements[idx].Offset = e->offset; d3delements[idx].Type = type; d3delements[idx].Method = D3DDECLMETHOD_DEFAULT; d3delements[idx].Usage = D3DDECLUSAGE_TEXCOORD; d3delements[idx].UsageIndex = 0; idx++; } e = &ret->elements[ALLEGRO_PRIM_COLOR_ATTR]; if(e->attribute) { d3delements[idx].Stream = 0; d3delements[idx].Offset = e->offset; d3delements[idx].Type = D3DDECLTYPE_D3DCOLOR; d3delements[idx].Method = D3DDECLMETHOD_DEFAULT; d3delements[idx].Usage = D3DDECLUSAGE_COLOR; d3delements[idx].UsageIndex = 0; idx++; } d3delements[idx].Stream = 0xFF; d3delements[idx].Offset = 0; d3delements[idx].Type = D3DDECLTYPE_UNUSED; d3delements[idx].Method = 0; d3delements[idx].Usage = 0; d3delements[idx].UsageIndex = 0; IDirect3DDevice9_CreateVertexDeclaration(device, d3delements, (IDirect3DVertexDeclaration9**)&ret->d3d_decl); } } #else ret->d3d_decl = 0; #endif }
void cbeGetBestGfxMode(CBEnchanted *cb) { // Initials int32_t bestHertz = 0; int32_t bestDisplayId = -1; bool no32BitFound = true; // Store the old flags for later restoring int32_t oldFlags = al_get_display_flags(cb->gfxInterface->getWindow()); // Set the display flags for fullscreen al_set_new_display_flags(ALLEGRO_FULLSCREEN); // Get display modes count int32_t displayModesCount = al_get_num_display_modes(); // Pop the input int32_t displayHeight = cb->popValue().getInt(); int32_t displayWidth = cb->popValue().getInt(); // Where the display modes data is stored ALLEGRO_DISPLAY_MODE *displayData = new ALLEGRO_DISPLAY_MODE; // Initialize the string to be returned string displayModeString; for (int currentId = 0; currentId < displayModesCount; currentId++) { // Get the display mode with id al_get_display_mode(currentId, displayData); if (displayData != NULL) { if (displayData->width == displayWidth && displayData->height == displayHeight && displayData->refresh_rate >= bestHertz) { if (al_get_pixel_format_bits(displayData->format) >= 32) { no32BitFound = false; } bestHertz = displayData->refresh_rate; bestDisplayId = currentId; } } } // If we got something, get that display mode and return it if (bestDisplayId > -1) { al_get_display_mode(bestDisplayId, displayData); // Construct the string displayModeString = std::to_string(displayData->width); displayModeString += "," + std::to_string(displayData->height); displayModeString += "," + std::to_string(displayData->refresh_rate); if (no32BitFound) { displayModeString += ",16"; } else { displayModeString += ",32"; } } else { displayModeString = ""; } // Restore old flags al_set_new_display_flags(oldFlags); // Return the display mode cb->pushValue(displayModeString.substr(0 , displayModeString.length() )); }
// Handles button events, may be called once every frame void* buttonhandler(BUTTONPTR button, void* data, int type) { typedef enum button_pressed { NONE, STARTB, HOWTOPLAYB, OPTIONSB, HIGHSCOREB, EXITB } BPRESSED; GDATAPTR game = (GDATAPTR)data; ALLEGRO_DISPLAY *display = game->display; static BPRESSED bpressed = NONE; if(strcmp(button->blabel, "STARTBUTTON") == 0 && type == BPRESSED_CALL) { game_start_init(); execute_on_button_press(); bpressed = STARTB; } if(strcmp(button->blabel, "HOWTOPLAYBUTTON") == 0 && type == BPRESSED_CALL) { execute_on_button_press(); bpressed = HOWTOPLAYB; } if(strcmp(button->blabel, "OPTIONSBUTTON") == 0 && type == BPRESSED_CALL) { execute_on_button_press(); bpressed = OPTIONSB; } if(strcmp(button->blabel, "HIGHSCOREBUTTON") == 0 && type == BPRESSED_CALL) { execute_on_button_press(); bpressed = HIGHSCOREB; } if(strcmp(button->blabel, "EXITBUTTON") == 0 && type == BPRESSED_CALL) { execute_on_button_press(); bpressed = EXITB; } if(strcmp(button->blabel, "FULLSCREEN") == 0 && type == BPRESSED_CALL) { (al_get_display_flags(display) & ALLEGRO_FULLSCREEN_WINDOW) ? al_toggle_display_flag(display, ALLEGRO_FULLSCREEN_WINDOW, false), al_resize_display(display, 800, 600) : al_toggle_display_flag(display, ALLEGRO_FULLSCREEN_WINDOW, true); if(strcmp(button->btext.text, "FULLSCREEN") == 0) button->btext.text = "WINDOWED"; else button->btext.text = "FULLSCREEN"; } if(strcmp(button->blabel, "FPS") == 0 && type == BPRESSED_CALL) { set_fps_status(!get_fps_status()); if(strcmp(button->btext.text, "FPS COUNTER: ON") == 0) button->btext.text = "FPS COUNTER: OFF"; else button->btext.text = "FPS COUNTER: ON"; } if(strcmp(button->blabel, "BACK") == 0 && type == BPRESSED_CALL) { return_to_main_menu(game); } if(strcmp(button->blabel, "RESUME") == 0 && type == BPRESSED_CALL) { exit_pause(game); mpressed = true; } if(strcmp(button->blabel, "EXITGAME") == 0 && type == BPRESSED_CALL) { game->exit = true; } if(strcmp(button->blabel, "QUITTOMENU") == 0 && type == BPRESSED_CALL) { return_to_main_menu(game); } if(strcmp(button->blabel, "QUITTOMENUGO") == 0 && type == BPRESSED_CALL) { return_to_main_menu(game); } if(strcmp(button->blabel, "CLEAR") == 0 && type == BPRESSED_CALL) { set_bflags_on_button(button, BLRELEASED); remove_bflags_on_button(button, BLPRESSED); remove_bflags_on_button(button, BVISIBLE); clear_highscores(); } if(type == CBANIMATION_CALL && (game->options || game->howtoplay || game->highscores || game->paused) && mpressed) { mpressed = false; if(game->paused) { pause_cleanup(); game->gamestarted = true; game->paused = false; } else { execute_on_M_press(); options_cleanup(); howtoplay_cleanup(); highscores_cleanup(); gameover_cleanup(); game->gamestarted = false; game->exit = false; game->options = false; game->highscores = false; game->howtoplay = false; } } if(type == CBANIMATION_CALL && bpressed != NONE) { BUTTONPTR currentptr, firstptr = get_first_element_from_button_list(); currentptr = search_button_list_for_element(&firstptr, "STARTBUTTON"); remove_bflags_on_button(currentptr, BVISIBLE); currentptr = search_button_list_for_element(&firstptr, "HOWTOPLAYBUTTON"); remove_bflags_on_button(currentptr, BVISIBLE); currentptr = search_button_list_for_element(&firstptr, "OPTIONSBUTTON"); remove_bflags_on_button(currentptr, BVISIBLE); currentptr = search_button_list_for_element(&firstptr, "HIGHSCOREBUTTON"); remove_bflags_on_button(currentptr, BVISIBLE); currentptr = search_button_list_for_element(&firstptr, "EXITBUTTON"); remove_bflags_on_button(currentptr, BVISIBLE); switch (bpressed) { case NONE: break; case STARTB: game->gamestarted = true; break; case HOWTOPLAYB: game->howtoplay = true; break; case OPTIONSB: game->options = true; break; case HIGHSCOREB: game->highscores = true; break; case EXITB: game->exit = true; break; default: bpressed = NONE; break; } bpressed = NONE; } return NULL; }
bool is_fullscreen (void) { return (al_get_display_flags (display) & ALLEGRO_FULLSCREEN_WINDOW) || (al_get_display_flags (display) & ALLEGRO_FULLSCREEN); }
int main(int argc, char **argv) { ALLEGRO_DISPLAY *display; ALLEGRO_BITMAP *bitmap; ALLEGRO_EVENT_QUEUE *events; ALLEGRO_EVENT event; bool down = false; int down_x = 0, down_y = 0; ALLEGRO_TIMER *timer; (void)argc; (void)argv; if (!al_init()) { abort_example("Could not init Allegro.\n"); } al_install_mouse(); al_install_keyboard(); al_init_image_addon(); init_platform_specific(); al_set_new_display_flags(ALLEGRO_FRAMELESS); display = al_create_display(300, 200); if (!display) { abort_example("Error creating display\n"); } bitmap = al_load_bitmap("data/fakeamp.bmp"); if (!bitmap) { abort_example("Error loading fakeamp.bmp\n"); } timer = al_create_timer(1.0f/30.0f); events = al_create_event_queue(); al_register_event_source(events, al_get_mouse_event_source()); al_register_event_source(events, al_get_keyboard_event_source()); al_register_event_source(events, al_get_display_event_source(display)); al_register_event_source(events, al_get_timer_event_source(timer)); al_start_timer(timer); for (;;) { al_wait_for_event(events, &event); if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) { if (event.mouse.button == 1 && event.mouse.x) { down = true; down_x = event.mouse.x; down_y = event.mouse.y; } if (event.mouse.button == 2) { al_set_display_flag(display, ALLEGRO_FRAMELESS, !(al_get_display_flags(display) & ALLEGRO_FRAMELESS)); } } else if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } else if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) { if (event.mouse.button == 1) { down = false; } } else if (event.type == ALLEGRO_EVENT_MOUSE_AXES) { if (down) { int cx, cy; if (al_get_mouse_cursor_position(&cx, &cy)) { al_set_window_position(display, cx - down_x, cy - down_y); } } } else if (event.type == ALLEGRO_EVENT_KEY_DOWN && event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { break; } else if (event.type == ALLEGRO_EVENT_TIMER) { al_draw_bitmap(bitmap, 0, 0, 0); al_flip_display(); } } al_destroy_timer(timer); al_destroy_event_queue(events); al_destroy_display(display); return 0; }
static void xdpy_destroy_display(ALLEGRO_DISPLAY *d) { ALLEGRO_SYSTEM_XGLX *s = (void *)al_get_system_driver(); ALLEGRO_DISPLAY_XGLX *glx = (void *)d; ALLEGRO_OGL_EXTRAS *ogl = d->ogl_extras; ALLEGRO_DEBUG("destroy display.\n"); /* If we're the last display, convert all bitmpas to display independent * (memory) bitmaps. */ if (s->system.displays._size == 1) { while (d->bitmaps._size > 0) { ALLEGRO_BITMAP **bptr = _al_vector_ref_back(&d->bitmaps); ALLEGRO_BITMAP *b = *bptr; _al_convert_to_memory_bitmap(b); } } else { /* Pass all bitmaps to any other living display. (We assume all displays * are compatible.) */ size_t i; ALLEGRO_DISPLAY **living = NULL; ASSERT(s->system.displays._size > 1); for (i = 0; i < s->system.displays._size; i++) { living = _al_vector_ref(&s->system.displays, i); if (*living != d) break; } for (i = 0; i < d->bitmaps._size; i++) { ALLEGRO_BITMAP **add = _al_vector_alloc_back(&(*living)->bitmaps); ALLEGRO_BITMAP **ref = _al_vector_ref(&d->bitmaps, i); *add = *ref; (*add)->display = *living; } } _al_xglx_unuse_adapter(s, glx->adapter); _al_ogl_unmanage_extensions(d); ALLEGRO_DEBUG("unmanaged extensions.\n"); _al_mutex_lock(&s->lock); _al_vector_find_and_delete(&s->system.displays, &d); XDestroyWindow(s->x11display, glx->window); if (s->mouse_grab_display == d) { s->mouse_grab_display = NULL; } ALLEGRO_DEBUG("destroy window.\n"); if (d->flags & ALLEGRO_FULLSCREEN) { size_t i; ALLEGRO_DISPLAY **living = NULL; bool last_fullscreen = true; /* If any other fullscreen display is still active on the same adapter, * we must not touch the video mode. */ for (i = 0; i < s->system.displays._size; i++) { living = _al_vector_ref(&s->system.displays, i); ALLEGRO_DISPLAY_XGLX *living_glx = (void*)*living; if (*living == d) continue; /* check for fullscreen displays on the same adapter */ if (living_glx->adapter == glx->adapter && al_get_display_flags(*living) & ALLEGRO_FULLSCREEN) { last_fullscreen = false; } } if (last_fullscreen) { ALLEGRO_DEBUG("restore modes.\n"); _al_xglx_restore_video_mode(s, glx->adapter); } else { ALLEGRO_DEBUG("*not* restoring modes.\n"); } } if (ogl->backbuffer) { _al_ogl_destroy_backbuffer(ogl->backbuffer); ogl->backbuffer = NULL; ALLEGRO_DEBUG("destroy backbuffer.\n"); } if (glx->context) { glXDestroyContext(s->gfxdisplay, glx->context); glx->context = NULL; ALLEGRO_DEBUG("destroy context.\n"); } /* XXX quick pre-release hack */ /* In multi-window programs these result in a double-free bugs. */ #if 0 if (glx->fbc) { al_free(glx->fbc); glx->fbc = NULL; XFree(glx->xvinfo); glx->xvinfo = NULL; } else if (glx->xvinfo) { al_free(glx->xvinfo); glx->xvinfo = NULL; } #endif _al_cond_destroy(&glx->mapped); _al_vector_free(&d->bitmaps); _al_event_source_free(&d->es); al_free(d->ogl_extras); al_free(d->vertex_cache); al_free(d); _al_mutex_unlock(&s->lock); ALLEGRO_DEBUG("destroy display finished.\n"); }