GtkWidget *create_color_menu (void (*callback) (GtkWidget*, int)) { GtkWidget *menu; GtkWidget *menu_item; GtkWidget *button; int i; menu = gtk_menu_new (); for (i = 0; i < 14; i++) { /* ugly, ugly, ugly... */ button = gtk_button_new_with_label (" "); gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_HALF); gtk_widget_set_sensitive (button, FALSE); gtk_widget_set_usize (button, 40, -1); gtk_widget_show (button); menu_item = gtk_menu_item_new (); gtk_container_add (GTK_CONTAINER (menu_item), button); gtk_menu_append (GTK_MENU (menu), menu_item); g_signal_connect (menu_item, "activate", G_CALLBACK (callback), GINT_TO_POINTER(i)); gtk_widget_show (menu_item); set_bg_color (menu_item, i); set_bg_color (button, i); } return menu; }
int main(void) { if (set_bg_color() == 0) { return EXIT_FAILURE; } else { return EXIT_SUCCESS; } }
int engine_init(struct Engine_Conf *conf) { if (engine.initialized) { puts("WARNING: Calling game_init() more than once"); return 1; } // Initialize Allegro and stuff al_init(); if (!al_install_keyboard()) { puts("ERROR: Could not initialize the keyboard..."); return 0; } if (conf->audio) { if (!al_install_audio()) { puts("ERROR: Could not initialize audio..."); return 0; } if (!al_init_acodec_addon()) { puts("ERROR: Could not initialize acodec addon..."); return 0; } } // Add-ons if (!al_init_image_addon()) { puts("ERROR: Could not initialize image addon..."); return 0; } al_init_font_addon(); al_init_primitives_addon(); // Find how much the game will be scaled when conf->scale <= 0 if (conf->scale <= 0) { ALLEGRO_MONITOR_INFO info; al_get_monitor_info(0, &info); int monitor_w = info.x2 - info.x1; int monitor_h = info.y2 - info.y1; float new_monitor_w = (monitor_w - (monitor_w * SCREEN_RES_OVERRIDE)); float new_monitor_h = (monitor_h - (monitor_h * SCREEN_RES_OVERRIDE)); conf->scale = 2; // Keep scaling until a suitable scale factor is found while (1) { int scale_w = conf->width * conf->scale; int scale_h = conf->height * conf->scale; if (scale_w > new_monitor_w || scale_h > new_monitor_h) { --conf->scale; break; } ++conf->scale; } } else if (conf->scale < 2) { conf->scale = 2; } engine.display = al_create_display(conf->width * conf->scale, conf->height * conf->scale); if (!engine.display) { puts("ERROR: Could not create a display window..."); return 0; } al_set_window_title(engine.display, conf->title); font = al_create_builtin_font(); engine.timer = al_create_timer(1.0 / conf->framerate); engine.event_queue = al_create_event_queue(); mainconf = conf; set_bg_color(BG_COLOR_DEFAULT); ALLEGRO_TRANSFORM trans; al_identity_transform(&trans); al_scale_transform(&trans, conf->scale, conf->scale); al_use_transform(&trans); engine.initialized = TRUE; return 1; }
int engine_init(struct Engine_Conf *conf) { if (engine.initialized) { return 1; } // Initialize Allegro and stuff al_init(); if (!al_install_keyboard()) { puts("engine_init(): Failed to initialize the keyboard..."); return 0; } if (!al_install_mouse()) { puts("engine_init(): Failed to initialize the mouse..."); return 0; } if (al_install_audio()) { if (!al_init_acodec_addon()) { puts("engine_init(): Failed to initialize codecs..."); } al_reserve_samples(1); } else { puts("engine_init(): Failed to initialize audio..."); } // Add-ons if (!al_init_image_addon()) { puts("engine_init(): Failed to initialize image addon..."); return 0; } al_init_font_addon(); al_init_primitives_addon(); if (conf->fullscreen) { al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); } // Initialize variables... engine.display = al_create_display(conf->width, conf->height); if (!engine.display) { puts("engine_init(): Failed to create a display window..."); return 0; } al_set_window_title(engine.display, conf->title); MAINCONF = conf; aspect_ratio_transform(); al_add_new_bitmap_flag(ALLEGRO_MAG_LINEAR); if (conf->buffer) { engine.buffer = al_create_bitmap(conf->width, conf->height); al_set_new_bitmap_flags(0); } font = al_create_builtin_font(); engine.timer = al_create_timer(1.0 / conf->framerate); engine.event_queue = al_create_event_queue(); engine.sm.change_state = change_state; engine.sm.push_state = push_state; engine.sm.pop_state = pop_state; set_bg_color(al_map_rgb(192, 192, 192)); srand(time(NULL)); engine.initialized = TRUE; return 1; }
NPError VlcPluginBase::init(int argc, char* const argn[], char* const argv[]) { /* prepare VLC command line */ const char *ppsz_argv[32]; int ppsz_argc = 0; #ifndef NDEBUG ppsz_argv[ppsz_argc++] = "--no-plugins-cache"; #endif /* locate VLC module path */ #ifdef XP_MACOSX ppsz_argv[ppsz_argc++] = "--vout=vout_macosx"; #elif defined(XP_WIN) HKEY h_key; DWORD i_type, i_data = MAX_PATH + 1; char p_data[MAX_PATH + 1]; if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC", 0, KEY_READ, &h_key ) == ERROR_SUCCESS ) { if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type, (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS ) { if( i_type == REG_SZ ) { strcat( p_data, "\\plugins" ); ppsz_argv[ppsz_argc++] = "--plugin-path"; ppsz_argv[ppsz_argc++] = p_data; } } RegCloseKey( h_key ); } ppsz_argv[ppsz_argc++] = "--no-one-instance"; #endif /* XP_MACOSX */ /* common settings */ ppsz_argv[ppsz_argc++] = "-vv"; ppsz_argv[ppsz_argc++] = "--no-stats"; ppsz_argv[ppsz_argc++] = "--no-media-library"; ppsz_argv[ppsz_argc++] = "--intf=dummy"; ppsz_argv[ppsz_argc++] = "--no-video-title-show"; ppsz_argv[ppsz_argc++] = "--no-xlib"; bool b_autoloop = false; /* parse plugin arguments */ for( int i = 0; (i < argc) && (ppsz_argc < 32); i++ ) { /* fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]); */ if( !strcmp( argn[i], "target" ) || !strcmp( argn[i], "mrl") || !strcmp( argn[i], "filename") || !strcmp( argn[i], "src") ) { psz_target = argv[i]; } else if( !strcmp( argn[i], "text" ) ) { set_bg_text( argv[i] ); } else if( !strcmp( argn[i], "autoplay") || !strcmp( argn[i], "autostart") ) { set_autoplay(boolValue(argv[i])); } else if( !strcmp( argn[i], "fullscreen" ) || !strcmp( argn[i], "allowfullscreen" ) ) { set_enable_fs( boolValue(argv[i]) ); } else if( !strcmp( argn[i], "mute" ) ) { if( boolValue(argv[i]) ) { ppsz_argv[ppsz_argc++] = "--volume=0"; } } else if( !strcmp( argn[i], "loop") || !strcmp( argn[i], "autoloop") ) { b_autoloop = boolValue(argv[i]); } else if( !strcmp( argn[i], "toolbar" ) ) { set_show_toolbar( boolValue(argv[i]) ); } else if( !strcmp( argn[i], "bgcolor" ) ) { set_bg_color( argv[i] ); } } libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv); if( !libvlc_instance ) return NPERR_GENERIC_ERROR; vlc_player::open(libvlc_instance); vlc_player::set_mode(b_autoloop ? libvlc_playback_mode_loop : libvlc_playback_mode_default); /* ** fetch plugin base URL, which is the URL of the page containing the plugin ** this URL is used for making absolute URL from relative URL that may be ** passed as an MRL argument */ NPObject *plugin = NULL; if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) ) { /* ** is there a better way to get that info ? */ static const char docLocHref[] = "document.location.href"; NPString script; NPVariant result; script.UTF8Characters = docLocHref; script.UTF8Length = sizeof(docLocHref)-1; if( NPN_Evaluate(p_browser, plugin, &script, &result) ) { if( NPVARIANT_IS_STRING(result) ) { NPString &location = NPVARIANT_TO_STRING(result); psz_baseURL = (char *) malloc(location.UTF8Length+1); if( psz_baseURL ) { strncpy(psz_baseURL, location.UTF8Characters, location.UTF8Length); psz_baseURL[location.UTF8Length] = '\0'; } } NPN_ReleaseVariantValue(&result); } NPN_ReleaseObject(plugin); } if( psz_target ) { // get absolute URL from src char *psz_absurl = getAbsoluteURL(psz_target); psz_target = psz_absurl ? psz_absurl : strdup(psz_target); } /* assign plugin script root class */ /* new APIs */ p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass(); if( !events.init() ) return NPERR_GENERIC_ERROR; libvlc_media_player_t *p_md = getMD(); if( p_md ) { libvlc_event_manager_t *p_em; p_em = libvlc_media_player_event_manager( getMD() ); events.hook_manager( p_em, this ); } return NPERR_NO_ERROR; }