Beispiel #1
0
static gboolean
ekiga_dbus_component_shutdown (G_GNUC_UNUSED EkigaDBusComponent *self,
                               G_GNUC_UNUSED GError **error)
{
  quit_callback (NULL, NULL);

  return TRUE;
}
Beispiel #2
0
void GUI::handle_event(const SDL_Event &event) {
	switch(event.type) {
		case SDL_MOUSEBUTTONDOWN:
		case SDL_MOUSEBUTTONUP:
			for(thing_set::iterator t = things.begin(); t != things.end(); t++) {
				if(event.button.x >= (*t)->x && event.button.x < (*t)->x+(*t)->w && event.button.y >= (*t)->y && event.button.y < (*t)->y+(*t)->h && (*t)->enabled) {
					if(event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) {
						focus = things.find(*t);
						v_focus = true;
					}

					(*t)->HandleEvent(event);
					break;
				}
			}

			break;

		case SDL_KEYDOWN:
			if(event.key.keysym.sym == SDLK_TAB) {
				focus_next();
				break;
			}

		case SDL_MOUSEMOTION:
		case SDL_KEYUP:
			if(v_focus) {
				(*focus)->HandleEvent(event);
			}

			break;

		case SDL_QUIT:
			if(quit_callback) {
				quit_callback(*this, event);
			}

			break;

		default:
			break;
	}
}
Beispiel #3
0
/*
 * GUI warning/error dialog
 * args:
 *   title - dialog title string
 *   message - error message string
 *   fatal - flag a fatal error (display device list combo box)
 *
 * asserts:
 *   none
 *
 * returns: none
 */
void gui_error_gtk3(
	const char *title,
	const char *message,
	int fatal)
{
	if(!gtk_init_called)
	{
		if(!gtk_init_check(NULL, NULL))
		{
			fprintf(stderr, "GUVCVIEW: (GUI) Gtk3 can't open display\n");
			fprintf(stderr, "%s: %s \n", title, message);
			return;
		}

		gtk_init_called = 1;
	}
	/*simple warning message - not fatal and no device selection*/
	if(!fatal)
	{
		GtkWidget *warndialog;
		warndialog = gtk_message_dialog_new (GTK_WINDOW(main_window),
		    GTK_DIALOG_DESTROY_WITH_PARENT,
		    GTK_MESSAGE_WARNING,
		    GTK_BUTTONS_CLOSE,
		    "%s",gettext(title));

		gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(warndialog),
		    "%s",gettext(message));

		gtk_widget_show(warndialog);
		gtk_dialog_run (GTK_DIALOG (warndialog));
		gtk_widget_destroy (warndialog);
		return;
	}

	/*fatal error message*/

	/*add device list (more than one device)*/
	int show_dev_list = (v4l2core_get_num_devices() >= 1) ? 1: 0;

	GtkWidget *errdialog = NULL;
	if(show_dev_list)
		errdialog = gtk_dialog_new_with_buttons (_("Error"),
			GTK_WINDOW(main_window),
			GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
			_("_Ok"), GTK_RESPONSE_ACCEPT,
			_("_Cancel"), GTK_RESPONSE_REJECT,
			NULL);
	else
		errdialog = gtk_dialog_new_with_buttons (_("Error"),
			GTK_WINDOW(main_window),
			GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
			_("_Ok"), GTK_RESPONSE_ACCEPT,
			NULL);

	GtkWidget *table = gtk_grid_new();

	GtkWidget *title_lbl = gtk_label_new (gettext(title));
	
#if GTK_VER_AT_LEAST(3,16)
	/* Style provider for this label. */
	GtkCssProvider *providerTitle = gtk_css_provider_new();

	gtk_style_context_add_provider(gtk_widget_get_style_context(title_lbl),
	        GTK_STYLE_PROVIDER(providerTitle),
	        GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
	gtk_css_provider_load_from_data(providerTitle,
	                                "GtkLabel { font: \"Sans bold 10\"; }",
	                                -1, NULL);
	g_object_unref(providerTitle);
#else
	gtk_widget_override_font(title_lbl, pango_font_description_from_string ("Sans bold 10"));
	gtk_misc_set_alignment (GTK_MISC (title_lbl), 0, 0);
#endif
	gtk_grid_attach (GTK_GRID (table), title_lbl, 0, 0, 2, 1);
	gtk_widget_show (title_lbl);

	GtkWidget *text = gtk_label_new (gettext(message));

#if GTK_VER_AT_LEAST(3,16)
	/* Style provider for this label. */
	GtkCssProvider *providerText = gtk_css_provider_new();

	gtk_style_context_add_provider(gtk_widget_get_style_context(text),
	        GTK_STYLE_PROVIDER(providerText),
	        GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
	gtk_css_provider_load_from_data(providerText,
	                                "GtkLabel { font: \"Sans italic 8\"; }",
	                                -1, NULL);
	g_object_unref(providerText);
#else
	gtk_widget_override_font(text, pango_font_description_from_string ("Sans italic 8"));
	gtk_misc_set_alignment (GTK_MISC (text), 0, 0);
#endif
	
	gtk_grid_attach (GTK_GRID (table), text, 0, 1, 2, 1);
	gtk_widget_show (text);

	GtkWidget *wgtDevices = NULL;

	if(show_dev_list)
	{
		GtkWidget *text2 = gtk_label_new (_("\nYou seem to have video devices installed.\n"
							                "Do you want to try one ?\n"));

#if GTK_VER_AT_LEAST(3,16)
	/* Style provider for this label. */
	GtkCssProvider *providerText2 = gtk_css_provider_new();

	gtk_style_context_add_provider(gtk_widget_get_style_context(text2),
	        GTK_STYLE_PROVIDER(providerText2),
	        GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
	gtk_css_provider_load_from_data(providerText2,
	                                "GtkLabel { font: \"Sans 10\"; }",
	                                -1, NULL);
	g_object_unref(providerText2);
#else
		gtk_widget_override_font(text2, pango_font_description_from_string ("Sans 10"));
		gtk_misc_set_alignment (GTK_MISC (text2), 0, 0);
#endif
		gtk_grid_attach (GTK_GRID (table), text2, 0, 2, 2, 1);
		gtk_widget_show (text2);

		GtkWidget *dev_lbl = gtk_label_new(_("Device:"));

#if GTK_VER_AT_LEAST(3,15)
		gtk_label_set_xalign(GTK_LABEL(dev_lbl), 0.5);
		gtk_label_set_yalign(GTK_LABEL(dev_lbl), 0.5);
#else
		gtk_misc_set_alignment (GTK_MISC (dev_lbl), 0.5, 0.5);
#endif
		gtk_grid_attach (GTK_GRID(table), dev_lbl, 0, 3, 1, 1);
		gtk_widget_show (dev_lbl);

		wgtDevices = gtk_combo_box_text_new ();
		gtk_widget_set_halign (wgtDevices, GTK_ALIGN_FILL);
		gtk_widget_set_hexpand (wgtDevices, TRUE);

		int i = 0;
		for(i = 0; i < v4l2core_get_num_devices(); i++)
		{
			gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(wgtDevices),
				v4l2core_get_device_sys_data(i)->name);
		}
		/*select the last listed device by default*/
		gtk_combo_box_set_active(GTK_COMBO_BOX(wgtDevices), v4l2core_get_num_devices() - 1);

		gtk_grid_attach(GTK_GRID(table), wgtDevices, 1, 3, 1, 1);
		gtk_widget_show (wgtDevices);
	}

	GtkWidget *content_area = gtk_dialog_get_content_area (GTK_DIALOG (errdialog));
	gtk_container_add (GTK_CONTAINER (content_area), table);
	gtk_widget_show (table);

	int result = gtk_dialog_run (GTK_DIALOG (errdialog));

	if(show_dev_list)
	{
		switch (result)
		{
			case GTK_RESPONSE_ACCEPT:
			{
				/*launch another guvcview instance for the selected device*/
				int index = gtk_combo_box_get_active(GTK_COMBO_BOX(wgtDevices));

				char videodevice[30];
				strncpy(videodevice, v4l2core_get_device_sys_data(index)->device, 29);

				gchar *command = g_strjoin("",
					g_get_prgname(),
					" --device=",
					videodevice,
					NULL);

				/*spawn new process*/
				GError *error = NULL;
				if(!(g_spawn_command_line_async(command, &error)))
				{
					fprintf(stderr, "GUVCVIEW: spawn failed: %s\n", error->message);
					g_error_free( error );
				}
				g_free(command);
			}
			break;

			default:
				/* do nothing since dialog was cancelled or closed */
				break;

		}
	}

	gtk_widget_destroy (errdialog);

	quit_callback(NULL); /*terminate the program*/
}
Beispiel #4
0
// Show and loop main menu
void show_menu_loop() {
    char *ip = "";
    FILE *han;
    SDL_Event event;
    int createserver = 0;
    SDL_Thread *ReadThread;
    //GConfClient *gcc = NULL;

    // Init GConf
    //g_type_init();
    //gcc = gconf_client_get_default();
    //createserver = gconf_client_get_bool(gcc, BATTLEGWELED_CREATESERVER, NULL);
    //ip = gconf_client_get_string(gcc, BATTLEGWELED_SERVERIP, NULL);

    // Single player
    if (!createserver && !strcmp(ip, "")) {
	han = fopen("/tmp/.battlegweled-save", "rb");
	if (han) {
		fread(&total_score, sizeof(int), 1, han);
		fread(&single_timer, sizeof(int), 1, han);
		fread(&timer_delay, sizeof(int), 1, han);
		fread(&score, sizeof(int), 1, han);
       		fread(nb_of_tiles, sizeof(nb_of_tiles), 1, han);
       		fread(matrix, BOARD_WIDTH * BOARD_HEIGHT, sizeof(int), han);
       		fclose(han);
       		new_game(true, GM_SINGLE, true);
    	} else new_game(true, GM_SINGLE, false); 
       	if (game_loop()) {
		flush_callback(0);
		quit_callback(0);
	} else exit_callback(0);
    } else {
	    int joined;
	    if (createserver) create_game();
	    else joined = join_game(ip);

            while (1) {

	        // If connected then start the game
	        if (ss == SS_CONNECTED) {
	            new_game(true, GM_MULTIPLAYER, false);
	            ReadThread = SDL_CreateThread(multi_player_loop, "ReadThread", NULL);
	            game_loop();
	            //SDL_KillThread(ReadThread);
                    SDL_WaitThread(ReadThread, NULL);
		    break;
                }

		if (ss == SS_ERROR || (SDL_PollEvent(&event) && ((event.key.state == SDL_PRESSED && (event.key.keysym.sym == SDLK_ESCAPE
			|| event.key.keysym.sym == SDLK_F4 || event.key.keysym.sym == SDLK_F5 || event.key.keysym.sym == SDLK_F6))
			|| event.type == SDL_QUIT || (event.type == SDL_MOUSEBUTTONDOWN && event.button.x >= BACK_OFFSETX
			&& event.button.y >= BACK_OFFSETY && event.button.x < BACK_OFFSETX2 && event.button.y < BACK_OFFSETY2)))) {
                        SDL_WaitThread(ThreadConnect, NULL);
                        SDL_WaitThread(ThreadAccept, NULL);
			//if (ThreadConnect) SDL_KillThread(ThreadConnect);
                        //if (ThreadAccept) SDL_KillThread(ThreadAccept);
			break;
                }

		// Update screen
        	draw_waiting_screen();
        }
	quit_callback(0);
    }
}