static void read_allegro_cfg(void) { /* We assume that the stdio file interface is in effect. */ ALLEGRO_PATH *path; ALLEGRO_CONFIG *temp; if (!sys_config) sys_config = al_create_config(); #if defined(ALLEGRO_UNIX) && !defined(ALLEGRO_IPHONE) temp = al_load_config_file("/etc/allegro5rc"); if (temp) { al_merge_config_into(sys_config, temp); al_destroy_config(temp); } path = _al_unix_get_path(ALLEGRO_USER_HOME_PATH); if (path) { al_set_path_filename(path, "allegro5rc"); temp = al_load_config_file(al_path_cstr(path, '/')); if (temp) { al_merge_config_into(sys_config, temp); al_destroy_config(temp); } al_set_path_filename(path, ".allegro5rc"); temp = al_load_config_file(al_path_cstr(path, '/')); if (temp) { al_merge_config_into(sys_config, temp); al_destroy_config(temp); } al_destroy_path(path); } #endif path = early_get_exename_path(); if (path) { al_set_path_filename(path, "allegro5.cfg"); temp = al_load_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP)); if (temp) { al_merge_config_into(sys_config, temp); al_destroy_config(temp); } al_destroy_path(path); } /* Reconfigure logging in case something changed. */ _al_configure_logging(); }
SolarSystem *solsys_load(const char *filename) { SolarSystem *ret; ALLEGRO_FILE *file; ALLEGRO_CONFIG *cfg; file = al_fopen(filename, "rb"); if (file == NULL) { log_err("Error opening file %s\n", filename); return NULL; } cfg = al_load_config_file_f(file); if (cfg == NULL) { al_fclose(file); log_err("Not a valid config file\n"); return NULL; } ret = load_from_config(cfg); if (ret == NULL) log_err("Couldn't load solarsystem from file: %s\n", filename); else log_dbg("Loaded a solarsystem with %d bodies\n", ret->num_bodies); al_destroy_config(cfg); al_fclose(file); return ret; }
void unload_resources(al_defs *al){ al_destroy_font(al->menu_font); al_destroy_font(al->logo_font); al_destroy_font(al->hint_font); al_save_config_file("res/config.ini", al->conf); al_destroy_config(al->conf); }
EngineConfig::~EngineConfig() { if (m_Config != NULL) { al_destroy_config(m_Config); } }
static void config_free(mrb_state *mrb, void *p) { if (p) { al_destroy_config(p); } }
static void read_scores(void) { ALLEGRO_PATH *fn = userResourcePath(); if (al_make_directory(al_path_cstr(fn, ALLEGRO_NATIVE_PATH_SEP))) { al_set_path_filename(fn, "scores.cfg"); ALLEGRO_CONFIG *cfg = al_load_config_file(al_path_cstr(fn, ALLEGRO_NATIVE_PATH_SEP)); if (cfg) { for (int i = 0; i < NUM_SCORES; i++) { char name[] = {'n', (char)('0'+i), '\0'}; char score[] = {'s', (char)('0'+i), '\0'}; const char *v; v = al_get_config_value(cfg, "scores", name); if (v && strlen(v) <= 3) { strcpy(highScores[i].name, v); } v = al_get_config_value(cfg, "scores", score); if (v) { highScores[i].score = atoi(v); } } al_destroy_config(cfg); } } al_destroy_path(fn); }
/* read_config: * Load settings from the configuration file, providing default values */ void read_global_config(const char *config) { ALLEGRO_CONFIG *c = al_load_config_file(config); if (!c) c = al_create_config(); fullscreen = get_config_int(c, "GFX", "fullscreen", fullscreen); bit_depth = get_config_int(c, "GFX", "bit_depth", bit_depth); screen_width = get_config_int(c, "GFX", "screen_width", screen_width); screen_height = get_config_int(c, "GFX", "screen_height", screen_height); window_width = get_config_int(c, "GFX", "window_width", window_height); window_height = get_config_int(c, "GFX", "window_height", screen_height); screen_samples = get_config_int(c, "GFX", "samples", screen_samples); use_vsync = get_config_int(c, "GFX", "vsync", use_vsync); logic_framerate = get_config_int(c, "TIMING", "logic_framerate", logic_framerate); limit_framerate = get_config_int(c, "TIMING", "limit_framerate", limit_framerate); max_frame_skip = get_config_int(c, "TIMING", "max_frame_skip", max_frame_skip); display_framerate = get_config_int(c, "TIMING", "display_framerate", display_framerate); reduce_cpu_usage = get_config_int(c, "TIMING", "reduce_cpu_usage", reduce_cpu_usage); sound_volume = get_config_int(c, "SOUND", "sound_volume", sound_volume); music_volume = get_config_int(c, "SOUND", "music_volume", music_volume); set_sound_volume(sound_volume / 10.0); set_music_volume(music_volume / 10.0); controller_id = get_config_int(c, "CONTROLS", "controller_id", controller_id); al_destroy_config(c); }
/** cleans up a skin structure. Destroys the allegro config. @param skin skin structure to cleanup. */ void algui_cleanup_skin(ALGUI_SKIN *skin) { assert(skin); al_ustr_free(skin->filename); al_destroy_config(skin->config); skin->filename = NULL; skin->config = NULL; }
int main(int argc, char * argv[]) { ALLEGRO_CONFIG *config; ALLEGRO_EVENT event; unsigned buffer_count; unsigned samples; const char *s; initialize(); if (argc < 2) { log_printf("This example needs to be run from the command line.\nUsage: %s {audio_files}\n", argv[0]); goto done; } buffer_count = 0; samples = 0; config = al_load_config_file("ex_stream_seek.cfg"); if (config) { if ((s = al_get_config_value(config, "", "buffer_count"))) { buffer_count = atoi(s); } if ((s = al_get_config_value(config, "", "samples"))) { samples = atoi(s); } al_destroy_config(config); } if (buffer_count == 0) { buffer_count = 4; } if (samples == 0) { samples = 1024; } stream_filename = argv[1]; music_stream = al_load_audio_stream(stream_filename, buffer_count, samples); if (!music_stream) { abort_example("Stream error!\n"); } loop_start = 0.0; loop_end = al_get_audio_stream_length_secs(music_stream); al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end); al_set_audio_stream_playmode(music_stream, ALLEGRO_PLAYMODE_LOOP); al_attach_audio_stream_to_mixer(music_stream, al_get_default_mixer()); al_start_timer(timer); while (!exiting) { al_wait_for_event(queue, &event); event_handler(&event); } done: myexit(); al_destroy_display(display); close_log(true); return 0; }
void GameGui::LoadGui(BuildingManager& manager) { // more gross allegro config file stuff // it might be fine to just hardcode this stuff auto buildingMenu = new Gwen::Controls::TabControl(m_canvas.get(), "Buildings"); buildingMenu->SetBounds(SCREEN_WIDTH - 262 - 150,SCREEN_HEIGHT - 135,262,135); auto mapBox = new Gwen::Controls::ImagePanel(m_canvas.get(), "Map"); mapBox->SetBounds(SCREEN_WIDTH - 150, SCREEN_HEIGHT - 150, 150, 150); ALLEGRO_CONFIG *uiConfig = al_load_config_file("ui/building_ui.cfg"); ALLEGRO_CONFIG_SECTION *iter; // this first section is the 'global' section, we ignore it const char * cfgSection = al_get_first_config_section(uiConfig, &iter); const char * cfgEntry; ALLEGRO_CONFIG_ENTRY *eIter; // load tab pages from building_ui.cfg while(true) { cfgSection = al_get_next_config_section(&iter); // did we pass by the last section in the file? if(!cfgSection) break; auto section = std::string(cfgSection); Gwen::Controls::TabButton* resExtractors = buildingMenu->AddPage(section); cfgEntry = al_get_first_config_entry(uiConfig, cfgSection, &eIter); for(int i = 0; cfgEntry; i++) { auto entry = std::string(cfgEntry); CommandButton* but; if (section == "Terraform") but = CommandButton::CreateTerraformButton(resExtractors->GetPage()); else if (section == "Transportation") but = CommandButton::CreatePathwayButton(resExtractors->GetPage()); else but = CommandButton::CreateBuildingButton(resExtractors->GetPage(), manager.GetTemplateByName(entry)); but->SetImage(al_get_config_value(uiConfig, cfgSection, cfgEntry)); but->SetToolTip(cfgEntry); but->SetShouldDrawBackground(false); but->SetBounds((i/2) * 50, 0, 50, 50); but->onPress.Add(&m_iHandler, &InputHandler::OnBuildingButton); if(i%2) but->SetPos((i/2) * 50, 52); cfgEntry = al_get_next_config_entry(&eIter); } } al_destroy_config(uiConfig); }
int main(int argc, char * argv[]) { ALLEGRO_CONFIG *config; ALLEGRO_EVENT event; unsigned buffer_count; unsigned samples; const char *s; if (argc < 2) { printf("Usage: ex_stream_seek <filename>\n"); return -1; } if (!initialize()) return 1; buffer_count = 0; samples = 0; config = al_load_config_file("ex_stream_seek.cfg"); if (config) { if ((s = al_get_config_value(config, "", "buffer_count"))) { buffer_count = atoi(s); } if ((s = al_get_config_value(config, "", "samples"))) { samples = atoi(s); } al_destroy_config(config); } if (buffer_count == 0) { buffer_count = 4; } if (samples == 0) { samples = 1024; } stream_filename = argv[1]; music_stream = al_load_audio_stream(stream_filename, buffer_count, samples); if (!music_stream) { printf("Stream error!\n"); return 1; } loop_start = 0.0; loop_end = al_get_audio_stream_length_secs(music_stream); al_set_audio_stream_loop_secs(music_stream, loop_start, loop_end); al_set_audio_stream_playmode(music_stream, ALLEGRO_PLAYMODE_LOOP); al_attach_audio_stream_to_mixer(music_stream, al_get_default_mixer()); al_start_timer(timer); while (!exiting) { al_wait_for_event(queue, &event); event_handler(&event); } myexit(); return 0; }
void ConfigfileCreateConfig(void) { if (Configfile.config != NULL) { al_destroy_config(Configfile.config); Configfile.config = NULL; } Configfile.config = al_create_config(); }
void ConfigfileLoadConfig(char *filename) { if (Configfile.config != NULL) { al_destroy_config(Configfile.config); Configfile.config = NULL; } Configfile.config = al_load_config_file((const char *)filename); }
void DeinitConfig(void) { ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH); ALLEGRO_PATH *data = al_create_path("SuperDerpy.ini"); al_make_directory(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP)); al_join_paths(path, data); al_save_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP), config); al_destroy_path(path); al_destroy_path(data); al_destroy_config(config); }
static mrb_value config_destroy(mrb_state *mrb, mrb_value self) { ALLEGRO_CONFIG *cfg; cfg = DATA_PTR(self); if (cfg) { al_destroy_config(cfg); DATA_PTR(self) = NULL; } return mrb_nil_value(); }
SYMBOL_EXPORT void DeinitConfig(struct Game* game) { const ALLEGRO_FILE_INTERFACE* iface = al_get_new_file_interface(); al_set_standard_file_interface(); ALLEGRO_PATH* path = al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH); ALLEGRO_PATH* data = al_create_path("SuperDerpy.ini"); al_make_directory(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP)); al_join_paths(path, data); al_save_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP), game->_priv.config); al_destroy_path(path); al_destroy_path(data); al_destroy_config(game->_priv.config); al_set_new_file_interface(iface); }
list* load_all_generator_data() { list *names = list_new(); ALLEGRO_CONFIG *cfg = al_load_config_file(DATA_PATH); // open config file ALLEGRO_CONFIG_SECTION *section = NULL; al_get_first_config_section(cfg, §ion); char const *name = al_get_next_config_section(§ion); while (name != NULL) { load_generator_data(name, cfg); list_push(names, strdup(name)); name = al_get_next_config_section(§ion); } al_destroy_config(cfg); return names; }
//////////////////////////////////////////////////////////////////////////////// // A helper function for loading an Allegro dat file where cursors are // supposed to be stored. MAS::Error MAS::Skin::LoadCursors(ALLEGRO_PATH *dir, ALLEGRO_CONFIG *config) { if (!dir || !al_is_path_present(dir)) { return Error(Error::NO_FILE); } MAS::Cursor::ReadSkinData(config); al_set_path_filename(dir, al_get_path_component(dir, -1)); al_set_path_extension(dir, ".ini"); const char *config_path_t = al_path_cstr(dir, ALLEGRO_NATIVE_PATH_SEP); ALLEGRO_CONFIG *mouse_config = al_load_config_file(config_path_t); int i; char tmp[256]; char *config_path = strdup(config_path_t); int x, y, frames, interval; const char *str; // Look for each bitmap inside the dat file and load it if it exists for (i=0; i<nCursors; i++) { al_set_path_filename(dir, cursorName[i]); al_set_path_extension(dir, ".png"); const char *fullPath = al_path_cstr(dir, ALLEGRO_NATIVE_PATH_SEP); Bitmap bmp; if (bmp.Load(fullPath, Bitmap::MEMORY) == Error::NONE) { snprintf(tmp, 256, "%s_FCSX", cursorName[i]); x = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 0; snprintf(tmp, 256, "%s_FCSY", cursorName[i]); y = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 0; snprintf(tmp, 256, "%s_FRMS", cursorName[i]); frames = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 1; snprintf(tmp, 256, "%s_FDUR", cursorName[i]); interval = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 20; curList[i]->Create(bmp, frames); curList[i]->SetFocus(x, y); curList[i]->SetAnimationInterval(interval); } } al_set_path_filename(dir, ""); free(config_path); al_destroy_config(mouse_config); return Error(Error::NONE); }
ship *ship_init(const point start) { ALLEGRO_CONFIG *config = al_load_config_file(CONFIG_FILE_PATH); if (config != NULL) { ship *s = (ship *) malloc(sizeof(ship)); s->center.x = start.x; s->center.y = start.y; s->v.dx = 0; s->v.dy = 0; s->a.ax = SHIP_FORCE; s->a.ay = SHIP_FORCE; s->direction = velocity_compute_direction(s->v); s->speed = velocity_compute_speed(s->v); s->bullets = NULL; s->bullet_count = 0; s->m.movement[UP] = false; s->m.movement[DOWN] = false; s->m.movement[LEFT] = false; s->m.movement[RIGHT] = false; const char *bitmap_path = al_get_config_value(config, CONFIG_SHIP_SECTION, CONFIG_SHIP_BITMAP_KEY); s->bitmap = al_load_bitmap(bitmap_path); if (!s->bitmap) { error_message("fail to load ship bitmap"); return NULL; } // ship attributes s->attr.lives = SHIP_STARTING_LIVES; s->attr.mana = SHIP_MAX_MANA; s->attr.level = atoi(al_get_config_value(config, CONFIG_SHIP_SECTION, CONFIG_SHIP_LEVEL_KEY)); s->attr.damage = SHIP_STARTING_DAMAGE; s->attr.is_buffed = false; s->attr.is_immune = false; s->attr.time_stamp = 0; al_destroy_config(config); return s; } else { error_message("fail to load ship config file"); return NULL; } }
static void shutdown_system_driver(void) { if (active_sysdrv) { if (active_sysdrv->user_exe_path) al_destroy_path(active_sysdrv->user_exe_path); if (active_sysdrv->vt && active_sysdrv->vt->shutdown_system) active_sysdrv->vt->shutdown_system(); active_sysdrv = NULL; while (!_al_vector_is_empty(&_al_system_interfaces)) _al_vector_delete_at(&_al_system_interfaces, _al_vector_size(&_al_system_interfaces)-1); _al_vector_free(&_al_system_interfaces); _al_vector_init(&_al_system_interfaces, sizeof(ALLEGRO_SYSTEM_INTERFACE *)); } al_destroy_config(sys_config); sys_config = NULL; }
particle_generator get_particle_generator(char *name) { list_node *p = data_list->head; generator_data *dat = NULL; while (p != NULL && strcmp(((generator_data*)p->value)->name, name) != 0) { p = p->next; // search for data matching the given name } if (p == NULL) { // did not find data ALLEGRO_CONFIG *cfg = al_load_config_file(DATA_PATH); // open config file dat = load_generator_data(name, cfg); // load data from file list_push(data_list, dat); // cache data in list al_destroy_config(cfg); } else { // found data dat = (generator_data*)p->value; } return (particle_generator) { .data = dat, .position = {0,0}, .angle = 0, ._spawn_counter = 0 }; }
void EngineConfig::load(std::string filename) { if (m_Config != NULL) { al_destroy_config(m_Config); } m_Config = al_load_config_file(filename.c_str()); if (m_Config == NULL) { THROW_GAME_EXCEPTION(EXCEP_CONFIG_FILE_MISSING); } loadResolutionWidth(); loadResolutionHeight(); loadFullscreen(); loadFrameSpeed(); }
static void write_scores(void) { ALLEGRO_CONFIG *cfg = al_create_config(); for (int i = 0; i < NUM_SCORES; i++) { char name[] = {'n', (char)('0'+i), '\0'}; char score[] = {'s', (char)('0'+i), '\0'}; char sc[32]; al_set_config_value(cfg, "scores", name, highScores[i].name); snprintf(sc, sizeof(sc), "%d", highScores[i].score); al_set_config_value(cfg, "scores", score, sc); } ALLEGRO_PATH *fn = userResourcePath(); al_set_path_filename(fn, "scores.cfg"); al_save_config_file(al_path_cstr(fn, ALLEGRO_NATIVE_PATH_SEP), cfg); al_destroy_path(fn); al_destroy_config(cfg); }
void reset_billiard_balls(billiard_ball *balls) { int i; const int key_size = 256; char key[key_size]; ALLEGRO_CONFIG *config = al_load_config_file(BCONFIG_FPATH); /* DEBUG */ #ifdef DEBUG if(balls == NULL) { perror("billiard_ball null pointer"); return; } #endif if(!config) { perror("fail to load billiard_ball.config"); return; } for(i = 0 ; i < BALL_COUNT ; i ++) { balls[i].number = i; balls[i].is_on_table = 1; balls[i].dx = 0; balls[i].dy = 0; // prepare the key for reading config file memset(key, '\0', key_size); sprintf(key, "ball%d", i); // read the initial position balls[i].cx = atof(al_get_config_value(config, key, "start_x")); balls[i].cy = atof(al_get_config_value(config, key, "start_y")); } al_destroy_config(config); }
void ship_reset(ship *s, const size window_size) { if (s != NULL) { ALLEGRO_CONFIG *config = al_load_config_file(CONFIG_FILE_PATH); if (config != NULL) { // reset ship attributes s->attr.lives = SHIP_STARTING_LIVES; s->attr.mana = SHIP_MAX_MANA; s->attr.level = atoi(al_get_config_value(config, CONFIG_SHIP_SECTION, CONFIG_SHIP_LEVEL_KEY)); s->attr.damage = SHIP_STARTING_DAMAGE; s->attr.is_buffed = false; s->attr.is_immune = false; s->attr.time_stamp = 0; al_destroy_config(config); } s->center.x = window_size.w / 2; s->center.y = window_size.h / 2; s->v.dx = 0; s->v.dy = 0; s->direction = velocity_compute_direction(s->v); s->speed = velocity_compute_speed(s->v); // destroy bullets bullet_destroy(s->bullets); s->bullets = NULL; s->bullet_count = 0; // reset movement s->m.movement[UP] = false; s->m.movement[DOWN] = false; s->m.movement[LEFT] = false; s->m.movement[RIGHT] = false; } else { error_message("ship object null pointer"); } }
int main(int argc, char* argv []) { al_init(); al_init_primitives_addon(); al_install_keyboard(); al_init_image_addon(); ALLEGRO_CONFIG *configFile = al_load_config_file("data/config/config.ini"); if (configFile == NULL) { al_show_native_message_box(NULL, "A fatal error has ocurred!", "The configuration file has not been found!", "Be sure to always have a valid conf.ini in /data/config/ for the program to work...", "Understood", ALLEGRO_MESSAGEBOX_ERROR); return 0; } std::string dispW = al_get_config_value(configFile, "DISPLAY", "RESX"); std::string dispH = al_get_config_value(configFile, "DISPLAY", "RESY"); std::string fullscreenMode = al_get_config_value(configFile, "DISPLAY", "FULLSCREEN"); int iDispW = stoi(dispW); int iDispH = stoi(dispH); bool bfullscreenMode = stoi(fullscreenMode); assert(iDispW < 5000 && iDispW > 0); assert(iDispH < 5000 && iDispH > 0); if (bfullscreenMode == true) al_set_new_display_flags(ALLEGRO_FULLSCREEN); ALLEGRO_DISPLAY *display = al_create_display(iDispW, iDispH); if (display == NULL) { al_show_native_message_box(NULL, "A fatal error has ocurred!", "Display creation failed!", "The resolution selected is not supported by your screen/video card...", "Understood", ALLEGRO_MESSAGEBOX_ERROR); return 0; } al_clear_to_color(al_map_rgb(255, 0, 0)); al_flip_display(); bool done = false; bool redraw = false; ALLEGRO_TIMER *timer = al_create_timer(1.0 / 60.0); ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_display_event_source(display)); al_register_event_source(queue, al_get_timer_event_source(timer)); //********************** ALLEGRO_BITMAP *test = al_load_bitmap("data/background.png"); int x = 320, y = 240; Vec2D size(40.0f, 40.0f); TestObject gameObject(Vec2D(10.0f, 10.0f)); gameObject.AddComponent(new RenderComponent()); gameObject.AddComponent(new PhysicsComponent(size, size, size, true)); //********************* al_start_timer(timer); //newManager.AddComponent(new PhysicsComponent(Vec2D(), Vec2D(), Vec2D(5.0f, 10.0f), false)); while (!done) { ALLEGRO_EVENT ev; al_wait_for_event(queue, &ev); switch (ev.type) { case ALLEGRO_EVENT_TIMER: redraw = true; gameObject.Update(); break; case ALLEGRO_EVENT_DISPLAY_CLOSE: done = true; break; case ALLEGRO_EVENT_KEY_DOWN: if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { done = true; } //************ else { // NOTHING } //************ break; default: break; } if (redraw && al_is_event_queue_empty(queue)) { redraw = false; al_clear_to_color(al_map_rgb(0, 0, 0)); al_draw_bitmap(test, 0, 0, NULL); //PhysicsComponent *test = (PhysicsComponent*) newManager.GetComponentByType(COMP_PHYSICS); //Vec2D pos = test->GetPosition(); al_draw_filled_circle(x, y, 89, al_map_rgb(255, 0, 255)); al_flip_display(); } } al_destroy_config(configFile); al_destroy_display(display); al_destroy_event_queue(queue); al_destroy_timer(timer); }
int main(int argc, char **argv) { ALLEGRO_DISPLAY *display; ALLEGRO_TIMER *timer; ALLEGRO_CONFIG *config; char const *value; char str[256]; (void)argc; (void)argv; if (!al_init()) { abort_example("Could not init Allegro.\n"); } al_init_primitives_addon(); al_install_keyboard(); al_install_mouse(); al_init_image_addon(); al_init_font_addon(); init_platform_specific(); /* Read supersampling info from ex_draw.ini. */ ex.samples = 0; config = al_load_config_file("ex_draw.ini"); if (!config) config = al_create_config(); value = al_get_config_value(config, "settings", "samples"); if (value) ex.samples = strtol(value, NULL, 0); sprintf(str, "%d", ex.samples); al_set_config_value(config, "settings", "samples", str); al_save_config_file("ex_draw.ini", config); al_destroy_config(config); if (ex.samples) { al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_REQUIRE); al_set_new_display_option(ALLEGRO_SAMPLES, ex.samples, ALLEGRO_SUGGEST); } display = al_create_display(640, 640); if (!display) { abort_example("Unable to create display.\n"); } init(); timer = al_create_timer(1.0 / ex.FPS); ex.queue = al_create_event_queue(); al_register_event_source(ex.queue, al_get_keyboard_event_source()); al_register_event_source(ex.queue, al_get_mouse_event_source()); al_register_event_source(ex.queue, al_get_display_event_source(display)); al_register_event_source(ex.queue, al_get_timer_event_source(timer)); al_start_timer(timer); run(); al_destroy_event_queue(ex.queue); return 0; }
int main(int argc, char **argv) { ALLEGRO_DISPLAY *display; ALLEGRO_TIMER *timer; ALLEGRO_EVENT_QUEUE *queue; int redraw = 0; double t = 0; if (!al_init()) { abort_example("Could not init Allegro.\n"); } open_log_monospace(); al_init_primitives_addon(); al_install_mouse(); al_init_font_addon(); al_init_ttf_addon(); al_init_image_addon(); init_platform_specific(); #ifdef ALLEGRO_IPHONE al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); #endif display = al_create_display(640, 480); if (!display) { abort_example("Could not create display.\n"); } al_install_keyboard(); if (argc >= 2) { font_file = argv[1]; } ex.f1 = al_load_font(font_file, 48, 0); ex.f2 = al_load_font(font_file, 48, ALLEGRO_TTF_NO_KERNING); ex.f3 = al_load_font(font_file, 12, 0); /* Specifying negative values means we specify the glyph height * in pixels, not the usual font size. */ ex.f4 = al_load_font(font_file, -140, 0); ex.f5 = al_load_font(font_file, 12, ALLEGRO_TTF_MONOCHROME); { int ranges[] = {0x1F40A, 0x1F40A}; ALLEGRO_BITMAP *icon = al_load_bitmap("data/icon.png"); if (!icon) { abort_example("Couldn't load data/icon.png.\n"); } ALLEGRO_BITMAP *glyph = al_create_bitmap(50, 50); al_set_target_bitmap(glyph); al_clear_to_color(al_map_rgba_f(0, 0, 0, 0)); al_draw_rectangle(0.5, 0.5, 49.5, 49.5, al_map_rgb_f(1, 1, 0), 1); al_draw_bitmap(icon, 1, 1, 0); al_set_target_backbuffer(display); ex.f_alex = al_grab_font_from_bitmap(glyph, 1, ranges); } if (!ex.f1 || !ex.f2 || !ex.f3 || !ex.f4 || !ex.f_alex) { abort_example("Could not load font: %s\n", font_file); } al_set_fallback_font(ex.f3, ex.f_alex); ex.ranges_count = al_get_font_ranges(ex.f1, 0, NULL); print_ranges(ex.f1); ex.config = al_load_config_file("data/ex_ttf.ini"); if (!ex.config) { abort_example("Could not data/ex_ttf.ini\n"); } timer = al_create_timer(1.0 / 60); queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_display_event_source(display)); al_register_event_source(queue, al_get_timer_event_source(timer)); al_start_timer(timer); while (true) { ALLEGRO_EVENT event; al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) break; if (event.type == ALLEGRO_EVENT_KEY_DOWN && event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { break; } if (event.type == ALLEGRO_EVENT_TIMER) redraw++; while (redraw > 0 && al_is_event_queue_empty(queue)) { double dt; redraw--; dt = al_get_time(); render(); dt = al_get_time() - dt; t = 0.99 * t + 0.01 * dt; ex.fps = 1.0 / t; al_flip_display(); } } al_destroy_font(ex.f1); al_destroy_font(ex.f2); al_destroy_font(ex.f3); al_destroy_font(ex.f4); al_destroy_font(ex.f5); al_destroy_config(ex.config); close_log(false); return 0; }
int main(void) { ALLEGRO_DISPLAY *display; ALLEGRO_TIMER *timer; ALLEGRO_EVENT_QUEUE *queue; int redraw = 0, i; bool quit = false; if (!al_init()) { abort_example("Could not initialise Allegro\n"); return 1; } al_init_primitives_addon(); al_install_mouse(); al_init_image_addon(); al_init_font_addon(); al_init_ttf_addon(); srand(time(NULL)); white = al_map_rgba_f(1, 1, 1, 1); display = al_create_display(640, 480); if (!display) { abort_example("Could not create display\n"); return 1; } al_set_window_title(display, "Allegro Logo Generator"); al_install_keyboard(); /* Read logo parameters from logo.ini (if it exists). */ config = al_load_config_file("logo.ini"); if (!config) config = al_create_config(); for (i = 0; param_names[i]; i++) { char const *value = al_get_config_value(config, "logo", param_names[i]); if (value) strncpy(param_values[i], value, sizeof(param_values[i])); } font = al_load_font("data/DejaVuSans.ttf", 12, 0); if (!font) { abort_example("Could not load font\n"); return 1; } timer = al_create_timer(1.0 / 60); queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_mouse_event_source()); al_register_event_source(queue, al_get_display_event_source(display)); al_register_event_source(queue, al_get_timer_event_source(timer)); al_start_timer(timer); while (!quit) { ALLEGRO_EVENT event; al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) break; if (event.type == ALLEGRO_EVENT_KEY_CHAR) { if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { quit = true; } else if (event.keyboard.keycode == ALLEGRO_KEY_ENTER) { if (editing) { regenerate = true; editing = false; } else { cursor = 0; editing = true; } } else if (event.keyboard.keycode == ALLEGRO_KEY_UP) { if (selection > 0) { selection--; cursor = 0; editing = false; } } else if (event.keyboard.keycode == ALLEGRO_KEY_DOWN) { if (param_names[selection + 1]) { selection++; cursor = 0; editing = false; } } else { int c = event.keyboard.unichar; if (editing) { if (c >= 32) { ALLEGRO_USTR *u = al_ustr_new(param_values[selection]); al_ustr_set_chr(u, cursor, c); cursor++; al_ustr_set_chr(u, cursor, 0); strncpy(param_values[selection], al_cstr(u), sizeof param_values[selection]); al_ustr_free(u); } } else { if (c == 'r') randomize(); if (c == 's') save(); } } } if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) { if (event.mouse.button == 1) { mouse_click(event.mouse.x, event.mouse.y); } } if (event.type == ALLEGRO_EVENT_TIMER) redraw++; if (redraw && al_is_event_queue_empty(queue)) { redraw = 0; render(); al_flip_display(); } } /* Write modified parameters back to logo.ini. */ for (i = 0; param_names[i]; i++) { al_set_config_value(config, "logo", param_names[i], param_values[i]); } al_save_config_file("logo.ini", config); al_destroy_config(config); return 0; }
//////////////////////////////////////////////////////////////////////////////// // Loads and processes the skin description file which is in fact a regular // Allegro configuration file MAS::Error MAS::Skin::Load(const char *file) { int i = 0; lastError = MAS::Error(MAS::Error::NONE); ALLEGRO_CONFIG *config; const char *str; ALLEGRO_PATH *sdp; if (!file) { lastError = MAS::Error(MAS::Error::SKIN_INI); return lastError; } // Try to open the skin description file sdp = al_create_path(file); if (!al_is_path_present(sdp)) { al_destroy_path(sdp); lastError = MAS::Error(MAS::Error::SKIN_INI); return lastError; } config = al_load_config_file(file); if (skinFilePath != file) { delete [] skinFilePath; skinFilePath = new char[1+strlen(file)]; strcpy(skinFilePath, file); } Reset(); // Get the path to the skin configuration file (drop the filename) al_set_path_filename(sdp, ""); //////////////////////////////////////////////////////////////////////////////// // Read the name of the dir and load the bitmap data bool default_bitmaps = false; str = al_get_config_value(config, "Skin", "main_data"); if (str) { al_append_path_component(sdp, str); lastError = LoadData(sdp, config); al_drop_path_tail(sdp); if (lastError) { al_destroy_config(config); al_destroy_path(sdp); delete [] skinFilePath; skinFilePath = NULL; return lastError; } } else { default_bitmaps = true; } //////////////////////////////////////////////////////////////////////////////// // Read the default colors #define GET_COLOR_STR(val, def) ((str = al_get_config_value(config, "COLORS", val)) ? str : def) c_face = MAS::Color(GET_COLOR_STR("face", "210,210,210")); c_font = MAS::Color(GET_COLOR_STR("fontface", " 16, 16, 16")); c_shad1 = MAS::Color(GET_COLOR_STR("shad1", "255,255,255")); c_shad2 = MAS::Color(GET_COLOR_STR("shad2", " 80, 80, 80")); c_disable = MAS::Color(GET_COLOR_STR("disable", "128,128,128")); c_select = MAS::Color(GET_COLOR_STR("select", "128,192,128")); c_deselect = MAS::Color(GET_COLOR_STR("deselect", "224,224,224")); c_focus = MAS::Color(GET_COLOR_STR("focus", "128,192,128")); c_sunken = MAS::Color(GET_COLOR_STR("sunken", "232,232,232")); c_back = MAS::Color(GET_COLOR_STR("back", "180,180,180")); #undef GET_COLOR_STR if (default_bitmaps) { GenerateDefaultBitmaps(); } //////////////////////////////////////////////////////////////////////////////// // Read the cursors from another datafile str = al_get_config_value(config, "Skin", "cursors"); if (str) { al_append_path_component(sdp, str); lastError = LoadCursors(sdp, config); al_drop_path_tail(sdp); if (lastError) { al_destroy_config(config); al_destroy_path(sdp); delete [] skinFilePath; skinFilePath = NULL; return lastError; } } //////////////////////////////////////////////////////////////////////////////// // Read the samples from another datafile str = al_get_config_value(config, "Skin", "sounds"); if (str) { al_append_path_component(sdp, str); lastError = LoadSamples(sdp); al_drop_path_tail(sdp); if (lastError) { al_destroy_config(config); al_destroy_path(sdp); delete [] skinFilePath; skinFilePath = NULL; return lastError; } } #define GET_CONFIG_STR(section, key, def) \ (str = al_get_config_value(config, section, key)) ? strtol(str, NULL, 10) : def //////////////////////////////////////////////////////////////////////////////// // Now load the fonts const char *fonts[] = { "FONT0", "FONT1", "FONT2", "FONT3", "FONT4", "FONT5", "FONT6", "FONT7" }; const char *ttfont; int size; for (i=0; i<nFonts; i++) { size = GET_CONFIG_STR(fonts[i], "size", 10); ttfont = al_get_config_value(config, fonts[i], "file"); // the filename of the font al_set_path_filename(sdp, ttfont); const char *filename = al_path_cstr(sdp, ALLEGRO_NATIVE_PATH_SEP); fntList[i]->Load(filename, size, false); } //////////////////////////////////////////////////////////////////////////////// // Read the object specific data: //---------------------------------------------- const char *fnames[] = { "font1", "font2", "font3", "font4" }; const char *cnames[] = { "f_col1", "f_col2", "f_col3", "f_col4" }; const char *snames[] = { "s_col1", "s_col2", "s_col3", "s_col4" }; const char *def_col[] = { "0,0,0", "0,0,0", "128,128,128", "0,0,0" }; const char *def_shd[] = { "-1", "-1", "-1", "-1" }; // button, checkbox, radio button, etc. const char *info_name[] = { "BOX", "BUTTON", "CHECKBOX", "RADIO", "LIST", "WINDOW", "MENU", "TEXT", "EDITBOX", "PROGRESS", "HYPER", "TAB", "TOOLTIP" }; for (int j=0; j<nInfoItems; j++) { for (i=0; i<4; i++) { fnt[j][i] = GET_CONFIG_STR(info_name[i], fnames[i], 10); fcol[j][i] = Color((str = al_get_config_value(config, info_name[j], cnames[i])) ? str : def_col[i]); scol[j][i] = Color((str = al_get_config_value(config, info_name[j], snames[i])) ? str : def_shd[i]); } } // wallpaper style wallpaperStyle = GET_CONFIG_STR("WALLPAPER", "style", 3); // buttons animation buttonDisplacement = GET_CONFIG_STR("BUTTON", "displacement", 1); buttonAnimationType = GET_CONFIG_STR("BUTTON", "animationType", 0); buttonAnimationLength = GET_CONFIG_STR("BUTTON", "animationLength", 0); // group box info boxX = GET_CONFIG_STR("BOX", "offX", 6); boxY = GET_CONFIG_STR("BOX", "offY", 1); boxAlign = GET_CONFIG_STR("BOX", "alignment", 0); boxBack = (str = al_get_config_value(config, "BOX", "backColor")) ? str : "222,222,222"; // window winTextPos.x( GET_CONFIG_STR("WINDOW", "textX", 10)); winTextPos.y( GET_CONFIG_STR("WINDOW", "textY", 18)); winTextAlign = GET_CONFIG_STR("WINDOW", "alignment", 0); winTextBack = GET_CONFIG_STR("WINDOW", "textBack", 0); winExitPos.x( GET_CONFIG_STR("WINDOW", "exitX", -22)); winExitPos.y( GET_CONFIG_STR("WINDOW", "exitY", 6)); winMaxPos.x( GET_CONFIG_STR("WINDOW", "manX", -40)); winMaxPos.y( GET_CONFIG_STR("WINDOW", "manY", 6)); winMinPos.x( GET_CONFIG_STR("WINDOW", "minX", -56)); winMinPos.y( GET_CONFIG_STR("WINDOW", "minY", 6)); winAnimationType = GET_CONFIG_STR("WINDOW", "animationType", 0); winAnimationLength = GET_CONFIG_STR("WINDOW", "animationLength", 0); // combo box comboAnimationType = GET_CONFIG_STR("COMBOBOX", "animationType", 0); comboAnimationLength = GET_CONFIG_STR("COMBOBOX", "animationLength", 0); // menu menuHeight = GET_CONFIG_STR("MENU", "height", 16); menuDelay = GET_CONFIG_STR("MENU", "delay", 300); menuAnimationType = GET_CONFIG_STR("MENU", "animationType", 0); menuAnimationLength = GET_CONFIG_STR("MENU", "animationLength", 0); // tooltip info tooltipAnimationType = GET_CONFIG_STR("TOOLTIP", "animationType", 0); tooltipAnimationLength = GET_CONFIG_STR("TOOLTIP", "animationLength", 0); tooltipBack = Color((str = al_get_config_value(config, "TOOLTIP", "backColor")) ? str : "255,255,192"); tooltipBorder = Color((str = al_get_config_value(config, "TOOLTIP", "backColor")) ? str : "0,0,0"); // dialog popup animation // ... // should the GUI draw dotted rectangles? drawDots = (str = al_get_config_value(config, "Skin", "dottedRect")) ? *str != '0' : false; // how the focus follows the mouse focus = GET_CONFIG_STR("Skin", "focus", 1); #undef GET_CONFIG_STR al_destroy_path(sdp); return MAS::Error(MAS::Error::NONE); }