/* test GTK_ALIGN_FILL handling */ static GtkWidget * test_fullwidth (void) { GtkWidget *win; GtkWidget *overlay; GtkWidget *text; GtkWidget *child; win = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (win), "Full-width"); overlay = gtk_overlay_new (); gtk_container_add (GTK_CONTAINER (win), overlay); text = gtk_text_view_new (); gtk_widget_set_size_request (text, 200, 200); gtk_widget_set_hexpand (text, TRUE); gtk_widget_set_vexpand (text, TRUE); gtk_container_add (GTK_CONTAINER (overlay), text); child = gtk_label_new ("Fullwidth top overlay"); gtk_widget_set_halign (child, GTK_ALIGN_FILL); gtk_widget_set_valign (child, GTK_ALIGN_START); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_object_set (child, "margin", 4, NULL); return win; }
static void gth_window_set_n_pages (GthWindow *self, int n_pages) { int i; if (self->priv->n_pages != 0) { g_critical ("The number of pages of a GthWindow can be set only once."); return; } self->priv->n_pages = n_pages; self->priv->overlay = gtk_overlay_new (); gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->overlay), "window-overlay"); gtk_widget_show (self->priv->overlay); gtk_container_add (GTK_CONTAINER (self), self->priv->overlay); g_signal_connect (self->priv->overlay, "get-child-position", G_CALLBACK (overlay_get_child_position_cb), self); self->priv->grid = gtk_grid_new (); gtk_widget_show (self->priv->grid); gtk_container_add (GTK_CONTAINER (self->priv->overlay), self->priv->grid); self->priv->stack = gtk_stack_new (); gtk_stack_set_transition_type (GTK_STACK (self->priv->stack), GTK_STACK_TRANSITION_TYPE_CROSSFADE); gtk_widget_show (self->priv->stack); gtk_grid_attach (GTK_GRID (self->priv->grid), self->priv->stack, 0, 2, 1, 1); self->priv->toolbars = g_new0 (GtkWidget *, n_pages); self->priv->contents = g_new0 (GtkWidget *, n_pages); self->priv->pages = g_new0 (GtkWidget *, n_pages); for (i = 0; i < n_pages; i++) { GtkWidget *page; self->priv->pages[i] = page = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_widget_show (page); gtk_container_add (GTK_CONTAINER (self->priv->stack), page); self->priv->toolbars[i] = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_widget_show (self->priv->toolbars[i]); gtk_box_pack_start (GTK_BOX (page), self->priv->toolbars[i], FALSE, FALSE, 0); self->priv->contents[i] = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_widget_hide (self->priv->contents[i]); gtk_box_pack_start (GTK_BOX (page), self->priv->contents[i], TRUE, TRUE, 0); } self->priv->window_size = g_new0 (GthWindowSize, n_pages); for (i = 0; i < n_pages; i++) self->priv->window_size[i].saved = FALSE; }
static void photos_tool_filter_button_init (PhotosToolFilterButton *self) { self->overlay = gtk_overlay_new (); self->selected_image = gtk_image_new_from_icon_name ("object-select-symbolic", GTK_ICON_SIZE_INVALID); gtk_widget_set_halign (self->selected_image, GTK_ALIGN_CENTER); gtk_widget_set_valign (self->selected_image, GTK_ALIGN_CENTER); gtk_widget_set_no_show_all (self->selected_image, TRUE); gtk_image_set_pixel_size (GTK_IMAGE (self->selected_image), 48); gtk_overlay_add_overlay (GTK_OVERLAY (self->overlay), self->selected_image); }
int main (int argc, char *argv[]) { GtkWidget *window, *vbox, *label; GtkWidget *combo, *scale, *overlay, *da; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 400, 300); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_container_add (GTK_CONTAINER (window), vbox); combo = gtk_combo_box_text_new (); scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0, 360, 1); label = gtk_label_new ("This label may be ellipsized\nto make it fit."); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "NONE"); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "START"); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "MIDDLE"); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "END"); gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0); gtk_widget_set_halign (label, GTK_ALIGN_CENTER); gtk_widget_set_valign (label, GTK_ALIGN_CENTER); da = gtk_drawing_area_new (); gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), overlay_draw, label, NULL); overlay = gtk_overlay_new (); gtk_container_add (GTK_CONTAINER (overlay), da); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), label); gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, TRUE); gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, TRUE); gtk_box_pack_start (GTK_BOX (vbox), overlay, TRUE, TRUE); g_object_set_data (G_OBJECT (label), "combo", combo); g_signal_connect (combo, "changed", G_CALLBACK (combo_changed_cb), label); g_signal_connect (scale, "value-changed", G_CALLBACK (scale_changed_cb), label); gtk_widget_show_all (window); gtk_main (); return 0; }
/* test custom positioning */ static GtkWidget * test_relative (void) { GtkWidget *win; GtkWidget *grid; GtkWidget *overlay; GtkWidget *text; GtkWidget *child; GdkRGBA color; win = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (win), "Custom positioning"); overlay = gtk_overlay_new (); gdk_rgba_parse (&color, "yellow"); G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_widget_override_background_color (overlay, 0, &color); G_GNUC_END_IGNORE_DEPRECATIONS gtk_container_add (GTK_CONTAINER (win), overlay); grid = gtk_grid_new (); gtk_container_add (GTK_CONTAINER (overlay), grid); gtk_grid_attach (GTK_GRID (grid), gtk_label_new ("Above"), 1, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), gtk_label_new ("Below"), 1, 2, 1, 1); gtk_grid_attach (GTK_GRID (grid), gtk_label_new ("Left"), 0, 1, 1, 1); gtk_grid_attach (GTK_GRID (grid), gtk_label_new ("Right"), 2, 1, 1, 1); text = gtk_text_view_new (); gtk_widget_set_size_request (text, 200, 200); g_object_set (text, "margin", 5, NULL); gtk_widget_set_hexpand (text, TRUE); gtk_widget_set_vexpand (text, TRUE); gtk_grid_attach (GTK_GRID (grid), text, 1, 1, 1, 1); g_signal_connect (overlay, "get-child-position", G_CALLBACK (get_child_position), text); child = gtk_label_new ("Top left overlay"); gtk_widget_set_halign (child, GTK_ALIGN_START); gtk_widget_set_valign (child, GTK_ALIGN_START); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_object_set (child, "margin", 1, NULL); child = gtk_label_new ("Bottom right overlay"); gtk_widget_set_halign (child, GTK_ALIGN_END); gtk_widget_set_valign (child, GTK_ALIGN_END); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_object_set (child, "margin", 1, NULL); return win; }
static GtkWidget * test_stacking (void) { GtkWidget *win; GtkWidget *overlay; GtkWidget *main_child; GtkWidget *label; GtkWidget *child; GtkWidget *grid; GtkWidget *check1; GtkWidget *check2; GdkRGBA color; win = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (win), "Stacking"); grid = gtk_grid_new (); overlay = gtk_overlay_new (); main_child = gtk_event_box_new (); gdk_rgba_parse (&color, "green"); G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_widget_override_background_color (main_child, 0, &color); G_GNUC_END_IGNORE_DEPRECATIONS gtk_widget_set_hexpand (main_child, TRUE); gtk_widget_set_vexpand (main_child, TRUE); label = gtk_label_new ("Main child"); child = gtk_label_new ("Overlay"); gtk_widget_set_halign (child, GTK_ALIGN_END); gtk_widget_set_valign (child, GTK_ALIGN_END); check1 = gtk_check_button_new_with_label ("Show main"); g_object_bind_property (main_child, "visible", check1, "active", G_BINDING_BIDIRECTIONAL); check2 = gtk_check_button_new_with_label ("Show overlay"); g_object_bind_property (child, "visible", check2, "active", G_BINDING_BIDIRECTIONAL); gtk_container_add (GTK_CONTAINER (main_child), label); gtk_container_add (GTK_CONTAINER (overlay), main_child); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); gtk_grid_attach (GTK_GRID (grid), overlay, 1, 0, 1, 3); gtk_container_add (GTK_CONTAINER (win), grid); gtk_grid_attach (GTK_GRID (grid), check1, 0, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), check2, 0, 1, 1, 1); child = gtk_label_new (""); gtk_widget_set_vexpand (child, TRUE); gtk_grid_attach (GTK_GRID (grid), child, 0, 2, 1, 1); return win; }
static GtkWidget * test_chase (void) { GtkWidget *win; GtkWidget *overlay; GtkWidget *sw; GtkWidget *text; GtkWidget *child; GtkTextBuffer *buffer; gchar *contents; gsize len; win = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (win), "Chase"); overlay = gtk_overlay_new (); gtk_widget_set_events (overlay, GDK_ENTER_NOTIFY_MASK|GDK_LEAVE_NOTIFY_MASK); gtk_container_add (GTK_CONTAINER (win), overlay); sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_min_content_width (GTK_SCROLLED_WINDOW (sw), 200); gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (sw), 200); gtk_container_add (GTK_CONTAINER (overlay), sw); text = gtk_text_view_new (); buffer = gtk_text_buffer_new (NULL); if (!g_file_get_contents ("testoverlay.c", &contents, &len, NULL)) { contents = g_strdup ("Text should go here..."); len = strlen (contents); } gtk_text_buffer_set_text (buffer, contents, len); g_free (contents); gtk_text_view_set_buffer (GTK_TEXT_VIEW (text), buffer); gtk_widget_set_hexpand (text, TRUE); gtk_widget_set_vexpand (text, TRUE); gtk_container_add (GTK_CONTAINER (sw), text); child = gtk_label_new ("Try to enter"); gtk_widget_set_halign (child, GTK_ALIGN_START); gtk_widget_set_valign (child, GTK_ALIGN_END); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_object_set (child, "margin", 4, NULL); g_signal_connect (overlay, "enter-notify-event", G_CALLBACK (on_enter), child); return win; }
/* test that margins and non-zero allocation x/y * of the main widget are handled correctly */ static GtkWidget * test_nonzerox (void) { GtkWidget *win; GtkWidget *grid; GtkWidget *overlay; GtkWidget *text; GtkWidget *child; GdkRGBA color; win = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (win), "Non-zero X"); grid = gtk_grid_new (); g_object_set (grid, "margin", 5, NULL); gtk_container_add (GTK_CONTAINER (win), grid); gtk_grid_attach (GTK_GRID (grid), gtk_label_new ("Above"), 1, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), gtk_label_new ("Below"), 1, 2, 1, 1); gtk_grid_attach (GTK_GRID (grid), gtk_label_new ("Left"), 0, 1, 1, 1); gtk_grid_attach (GTK_GRID (grid), gtk_label_new ("Right"), 2, 1, 1, 1); overlay = gtk_overlay_new (); gdk_rgba_parse (&color, "red"); G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_widget_override_background_color (overlay, 0, &color); G_GNUC_END_IGNORE_DEPRECATIONS gtk_grid_attach (GTK_GRID (grid), overlay, 1, 1, 1, 1); text = gtk_text_view_new (); gtk_widget_set_size_request (text, 200, 200); gtk_widget_set_hexpand (text, TRUE); gtk_widget_set_vexpand (text, TRUE); gtk_container_add (GTK_CONTAINER (overlay), text); child = gtk_label_new ("I'm the overlay"); gtk_widget_set_halign (child, GTK_ALIGN_START); gtk_widget_set_valign (child, GTK_ALIGN_START); g_object_set (child, "margin", 3, NULL); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); child = gtk_label_new ("No, I'm the overlay"); gtk_widget_set_halign (child, GTK_ALIGN_END); gtk_widget_set_valign (child, GTK_ALIGN_END); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_object_set (child, "margin", 3, NULL); return win; }
/* test that scrolling works as expected */ static GtkWidget * test_scrolling (void) { GtkWidget *win; GtkWidget *overlay; GtkWidget *sw; GtkWidget *text; GtkWidget *child; GtkTextBuffer *buffer; gchar *contents; gsize len; win = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (win), "Scrolling"); overlay = gtk_overlay_new (); gtk_container_add (GTK_CONTAINER (win), overlay); sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_min_content_width (GTK_SCROLLED_WINDOW (sw), 200); gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (sw), 200); gtk_container_add (GTK_CONTAINER (overlay), sw); text = gtk_text_view_new (); buffer = gtk_text_buffer_new (NULL); if (!g_file_get_contents ("testoverlay.c", &contents, &len, NULL)) { contents = g_strdup ("Text should go here..."); len = strlen (contents); } gtk_text_buffer_set_text (buffer, contents, len); g_free (contents); gtk_text_view_set_buffer (GTK_TEXT_VIEW (text), buffer); gtk_widget_set_hexpand (text, TRUE); gtk_widget_set_vexpand (text, TRUE); gtk_container_add (GTK_CONTAINER (sw), text); child = gtk_label_new ("This should be visible"); gtk_widget_set_halign (child, GTK_ALIGN_CENTER); gtk_widget_set_valign (child, GTK_ALIGN_END); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_object_set (child, "margin", 4, NULL); return win; }
static gboolean activate_link (GtkLabel *label, const gchar *uri, GisPrivacyPage *page) { GtkWidget *dialog; GtkWidget *overlay; GtkWidget *view; GtkWidget *progress_bar; dialog = gtk_dialog_new_with_buttons (_("Privacy Policy"), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (page))), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR, NULL); overlay = gtk_overlay_new (); gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), overlay); progress_bar = gtk_progress_bar_new (); gtk_style_context_add_class (gtk_widget_get_style_context (progress_bar), GTK_STYLE_CLASS_OSD); gtk_widget_set_halign (progress_bar, GTK_ALIGN_FILL); gtk_widget_set_valign (progress_bar, GTK_ALIGN_START); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), progress_bar); view = webkit_web_view_new (); gtk_widget_set_size_request (view, 600, 500); gtk_widget_set_hexpand (view, TRUE); gtk_widget_set_vexpand (view, TRUE); g_signal_connect (view, "notify::estimated-load-progress", G_CALLBACK (notify_progress_cb), progress_bar); gtk_container_add (GTK_CONTAINER (overlay), view); gtk_widget_show_all (overlay); gtk_window_present (GTK_WINDOW (dialog)); webkit_web_view_load_uri (WEBKIT_WEB_VIEW (view), uri); return TRUE; }
static void nautilus_window_slot_constructed (GObject *object) { NautilusWindowSlot *slot = NAUTILUS_WINDOW_SLOT (object); GtkWidget *extras_vbox; G_OBJECT_CLASS (nautilus_window_slot_parent_class)->constructed (object); gtk_orientable_set_orientation (GTK_ORIENTABLE (slot), GTK_ORIENTATION_VERTICAL); gtk_widget_show (GTK_WIDGET (slot)); extras_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); slot->extra_location_widgets = extras_vbox; gtk_box_pack_start (GTK_BOX (slot), extras_vbox, FALSE, FALSE, 0); gtk_widget_show (extras_vbox); slot->query_editor = NAUTILUS_QUERY_EDITOR (nautilus_query_editor_new ()); nautilus_window_slot_add_extra_location_widget (slot, GTK_WIDGET (slot->query_editor)); g_object_add_weak_pointer (G_OBJECT (slot->query_editor), (gpointer *) &slot->query_editor); slot->view_overlay = gtk_overlay_new (); gtk_widget_add_events (slot->view_overlay, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK); gtk_box_pack_start (GTK_BOX (slot), slot->view_overlay, TRUE, TRUE, 0); gtk_widget_show (slot->view_overlay); slot->floating_bar = nautilus_floating_bar_new (NULL, NULL, FALSE); gtk_widget_set_halign (slot->floating_bar, GTK_ALIGN_END); gtk_widget_set_valign (slot->floating_bar, GTK_ALIGN_END); gtk_overlay_add_overlay (GTK_OVERLAY (slot->view_overlay), slot->floating_bar); g_signal_connect (slot->floating_bar, "action", G_CALLBACK (floating_bar_action_cb), slot); slot->title = g_strdup (_("Loading...")); }
static void nemo_window_slot_init (NemoWindowSlot *slot) { GtkWidget *extras_vbox; gtk_orientable_set_orientation (GTK_ORIENTABLE (slot), GTK_ORIENTATION_VERTICAL); gtk_widget_show (GTK_WIDGET (slot)); extras_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); slot->extra_location_widgets = extras_vbox; gtk_box_pack_start (GTK_BOX (slot), extras_vbox, FALSE, FALSE, 0); gtk_widget_show (extras_vbox); slot->query_editor = NEMO_QUERY_EDITOR (nemo_query_editor_new ()); slot->query_editor_revealer = gtk_revealer_new (); gtk_container_add (GTK_CONTAINER (slot->query_editor_revealer), GTK_WIDGET (slot->query_editor)); gtk_widget_show_all (slot->query_editor_revealer); nemo_window_slot_add_extra_location_widget (slot, slot->query_editor_revealer); slot->view_overlay = gtk_overlay_new (); gtk_widget_add_events (slot->view_overlay, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK); gtk_box_pack_start (GTK_BOX (slot), slot->view_overlay, TRUE, TRUE, 0); gtk_widget_show (slot->view_overlay); slot->floating_bar = nemo_floating_bar_new ("", FALSE); gtk_widget_set_halign (slot->floating_bar, GTK_ALIGN_END); gtk_widget_set_valign (slot->floating_bar, GTK_ALIGN_END); gtk_overlay_add_overlay (GTK_OVERLAY (slot->view_overlay), slot->floating_bar); g_signal_connect (slot->floating_bar, "action", G_CALLBACK (floating_bar_action_cb), slot); slot->title = g_strdup (_("Loading...")); }
int main (int argc, char *argv[]) { GtkWidget *window, *box, *hbox, *button, *spinner, *check, *fps_label, *gears, *extra_hbox, *bbox, *overlay, *revealer, *frame, *label, *scrolled; int i; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "GdkGears"); gtk_window_set_default_size (GTK_WINDOW (window), 640, 640); gtk_container_set_border_width (GTK_CONTAINER (window), 12); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); overlay = gtk_overlay_new (); gtk_container_add (GTK_CONTAINER (window), overlay); gtk_widget_show (overlay); revealer = gtk_revealer_new (); gtk_widget_set_halign (revealer, GTK_ALIGN_END); gtk_widget_set_valign (revealer, GTK_ALIGN_START); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), revealer); gtk_widget_show (revealer); frame = gtk_frame_new (NULL); gtk_style_context_add_class (gtk_widget_get_style_context (frame), "app-notification"); gtk_container_add (GTK_CONTAINER (revealer), frame); gtk_widget_show (frame); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE); gtk_box_set_spacing (GTK_BOX (hbox), 6); gtk_container_add (GTK_CONTAINER (frame), hbox); gtk_widget_show (hbox); label = gtk_label_new ("This is a transparent overlay widget!!!!\nAmazing, eh?"); gtk_container_add (GTK_CONTAINER (hbox), label); gtk_widget_show (label); box = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE); gtk_box_set_spacing (GTK_BOX (box), 6); gtk_container_add (GTK_CONTAINER (overlay), box); gtk_widget_show (box); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE); gtk_box_set_spacing (GTK_BOX (box), 6); gtk_container_add (GTK_CONTAINER (box), hbox); gtk_widget_show (hbox); gears = gtk_gears_new (); gtk_widget_set_hexpand (gears, TRUE); gtk_widget_set_vexpand (gears, TRUE); gtk_container_add (GTK_CONTAINER (hbox), gears); gtk_widget_show (gears); for (i = 0; i < GTK_GEARS_N_AXIS; i++) gtk_container_add (GTK_CONTAINER (hbox), create_axis_slider (GTK_GEARS (gears), i)); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE); gtk_box_set_spacing (GTK_BOX (hbox), 6); gtk_container_add (GTK_CONTAINER (box), hbox); gtk_widget_show (hbox); fps_label = gtk_label_new (""); gtk_container_add (GTK_CONTAINER (hbox), fps_label); gtk_widget_show (fps_label); gtk_gears_set_fps_label (GTK_GEARS (gears), GTK_LABEL (fps_label)); spinner = gtk_spinner_new (); gtk_box_pack_end (GTK_BOX (hbox), spinner, FALSE, FALSE, 0); gtk_widget_show (spinner); gtk_spinner_start (GTK_SPINNER (spinner)); check = gtk_check_button_new_with_label ("Animate spinner"); gtk_box_pack_end (GTK_BOX (hbox), check, FALSE, FALSE, 0); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE); gtk_widget_show (check); g_signal_connect (check, "toggled", G_CALLBACK (toggle_spin), spinner); check = gtk_check_button_new_with_label ("Alpha"); gtk_box_pack_end (GTK_BOX (hbox), check, FALSE, FALSE, 0); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), FALSE); gtk_widget_show (check); g_signal_connect (check, "toggled", G_CALLBACK (toggle_alpha), gears); check = gtk_check_button_new_with_label ("Overlay"); gtk_box_pack_end (GTK_BOX (hbox), check, FALSE, FALSE, 0); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), FALSE); gtk_widget_show (check); g_signal_connect (check, "toggled", G_CALLBACK (toggle_overlay), revealer); scrolled = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER); gtk_container_add (GTK_CONTAINER (box), scrolled); gtk_widget_show (scrolled); extra_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE); gtk_box_set_spacing (GTK_BOX (extra_hbox), 6); gtk_container_add (GTK_CONTAINER (scrolled), extra_hbox); gtk_widget_show (extra_hbox); bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL); gtk_box_set_spacing (GTK_BOX (bbox), 6); gtk_container_add (GTK_CONTAINER (box), bbox); gtk_widget_show (bbox); button = gtk_button_new_with_label ("Moar gears!"); gtk_widget_set_hexpand (button, TRUE); gtk_container_add (GTK_CONTAINER (bbox), button); g_signal_connect (button, "clicked", G_CALLBACK (moar_gears), extra_hbox); gtk_widget_show (button); button = gtk_button_new_with_label ("Quit"); gtk_widget_set_hexpand (button, TRUE); gtk_container_add (GTK_CONTAINER (bbox), button); g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window); gtk_widget_show (button); gtk_widget_show (window); gtk_main (); return EXIT_SUCCESS; }
static void browserWindowConstructed(GObject *gObject) { BrowserWindow *window = BROWSER_WINDOW(gObject); WebKitSettings *settings = webkit_web_view_get_settings(window->webView); /*init minimumZoomLevel, maximumZoomLevel sunhaiming add.*/ minimumZoomLevel = zoom_factor[0]; maximumZoomLevel = zoom_factor[settings->pageZoomNum - 1]; // browserWindowUpdateZoomActions(window); g_signal_connect(window->webView, "notify::uri", G_CALLBACK(webViewURIChanged), window); g_signal_connect(window->webView, "notify::estimated-load-progress", G_CALLBACK(webViewLoadProgressChanged), window); g_signal_connect(window->webView, "notify::title", G_CALLBACK(webViewTitleChanged), window); g_signal_connect(window->webView, "create", G_CALLBACK(webViewCreate), window); g_signal_connect(window->webView, "load-failed", G_CALLBACK(webViewLoadFailed), window); g_signal_connect(window->webView, "decide-policy", G_CALLBACK(webViewDecidePolicy), window); g_signal_connect(window->webView, "permission-request", G_CALLBACK(webViewDecidePermissionRequest), window); g_signal_connect(window->webView, "mouse-target-changed", G_CALLBACK(webViewMouseTargetChanged), window); // g_signal_connect(window->webView, "notify::zoom-level", G_CALLBACK(webViewZoomLevelChanged), window); g_signal_connect(window->webView, "notify::favicon", G_CALLBACK(faviconChanged), window); g_signal_connect(window->webView, "enter-fullscreen", G_CALLBACK(webViewEnterFullScreen), window); g_signal_connect(window->webView, "leave-fullscreen", G_CALLBACK(webViewLeaveFullScreen), window); g_signal_connect(window->webView, "notify::is-loading", G_CALLBACK(webViewIsLoadingChanged), window); g_signal_connect(webkit_web_view_get_context(window->webView), "download-started", G_CALLBACK(downloadStarted), window); window->searchBar = BROWSER_SEARCH_BAR(browser_search_bar_new(window->webView)); browser_search_bar_add_accelerators(window->searchBar, window->accelGroup); gtk_box_pack_start(GTK_BOX(window->mainBox), GTK_WIDGET(window->searchBar), FALSE, FALSE, 0); WebKitBackForwardList *backForwadlist = webkit_web_view_get_back_forward_list(window->webView); g_signal_connect(backForwadlist, "changed", G_CALLBACK(backForwadlistChanged), window); WebKitWebInspector *inspectorWindow = webkit_web_view_get_inspector(WEBKIT_WEB_VIEW(window->webView)); g_signal_connect(inspectorWindow, "open-window", G_CALLBACK(inspectorWasOpenedInAnotherWindow), window); g_signal_connect(inspectorWindow, "closed", G_CALLBACK(inspectorWasClosed), window); GtkWidget *overlay = gtk_overlay_new(); gtk_box_pack_start(GTK_BOX(window->mainBox), overlay, TRUE, TRUE, 0); gtk_widget_show(overlay); window->statusLabel = gtk_label_new(NULL); gtk_widget_set_halign(window->statusLabel, GTK_ALIGN_START); gtk_widget_set_valign(window->statusLabel, GTK_ALIGN_END); gtk_widget_set_margin_left(window->statusLabel, 1); gtk_widget_set_margin_right(window->statusLabel, 1); gtk_widget_set_margin_top(window->statusLabel, 1); gtk_widget_set_margin_bottom(window->statusLabel, 1); gtk_overlay_add_overlay(GTK_OVERLAY(overlay), window->statusLabel); gtk_container_add(GTK_CONTAINER(overlay), GTK_WIDGET(window->webView)); window->fullScreenMessageLabel = gtk_label_new(NULL); gtk_widget_set_halign(window->fullScreenMessageLabel, GTK_ALIGN_CENTER); gtk_widget_set_valign(window->fullScreenMessageLabel, GTK_ALIGN_CENTER); gtk_widget_set_no_show_all(window->fullScreenMessageLabel, TRUE); gtk_overlay_add_overlay(GTK_OVERLAY(overlay), window->fullScreenMessageLabel); gtk_widget_show(GTK_WIDGET(window->webView)); //<wangc attach webview to tab window->overlay=overlay; GtkWidget *btab = gtk_button_new_with_label ("Tab"); gtk_box_pack_start (GTK_BOX(window->boxtab), btab, FALSE, FALSE, 0); int tabid=window->tabmng->generateTabId(window->tabmng); TabInfo* ti=(TabInfo*)malloc(sizeof(TabInfo)); ti->window=window; ti->tabid=tabid; g_signal_connect (G_OBJECT (btab), "clicked", G_CALLBACK (cbShowTab), ti); gtk_widget_show (btab); window->tabmng->addTab(window->tabmng,tabid,window->overlay,window->webView); //> }
int main (int argc, char *argv[]) { GtkWidget *win; GtkWidget *box; GtkWidget *button; GtkWidget *button2; GtkBuilder *builder; GMenuModel *model; GSimpleActionGroup *actions; GtkWidget *overlay; GtkWidget *grid; GtkWidget *popover; GtkWidget *popover2; GtkWidget *label; GtkWidget *check; GtkWidget *combo; gtk_init (&argc, &argv); win = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (win), 400, 600); actions = g_simple_action_group_new (); g_action_map_add_action_entries (G_ACTION_MAP (actions), entries, G_N_ELEMENTS (entries), NULL); gtk_widget_insert_action_group (win, "top", G_ACTION_GROUP (actions)); overlay = gtk_overlay_new (); gtk_container_add (GTK_CONTAINER (win), overlay); grid = gtk_grid_new (); gtk_widget_set_halign (grid, GTK_ALIGN_FILL); gtk_widget_set_valign (grid, GTK_ALIGN_FILL); gtk_grid_set_row_spacing (GTK_GRID (grid), 10); gtk_grid_set_column_spacing (GTK_GRID (grid), 10); gtk_container_add (GTK_CONTAINER (overlay), grid); label = gtk_label_new (""); gtk_widget_set_hexpand (label, TRUE); gtk_widget_set_vexpand (label, TRUE); gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1); label = gtk_label_new (""); gtk_widget_set_hexpand (label, TRUE); gtk_widget_set_vexpand (label, TRUE); gtk_grid_attach (GTK_GRID (grid), label, 3, 6, 1, 1); builder = gtk_builder_new_from_file ("popover.ui"); model = (GMenuModel *)gtk_builder_get_object (builder, "menu"); box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); button = gtk_menu_button_new (); gtk_container_add (GTK_CONTAINER (box), button); button2 = gtk_menu_button_new (); gtk_container_add (GTK_CONTAINER (box), button2); gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), model); gtk_menu_button_set_use_popover (GTK_MENU_BUTTON (button), TRUE); popover = GTK_WIDGET (gtk_menu_button_get_popover (GTK_MENU_BUTTON (button))); builder = gtk_builder_new_from_file ("popover2.ui"); popover2 = (GtkWidget *)gtk_builder_get_object (builder, "popover"); gtk_menu_button_set_popover (GTK_MENU_BUTTON (button2), popover2); g_object_set (box, "margin", 10, NULL); gtk_widget_set_halign (box, GTK_ALIGN_END); gtk_widget_set_valign (box, GTK_ALIGN_START); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), box); label = gtk_label_new ("Popover hexpand"); check = gtk_check_button_new (); g_object_bind_property (check, "active", popover, "hexpand", G_BINDING_DEFAULT); g_object_bind_property (check, "active", popover2, "hexpand", G_BINDING_DEFAULT); gtk_grid_attach (GTK_GRID (grid), label , 1, 1, 1, 1); gtk_grid_attach (GTK_GRID (grid), check, 2, 1, 1, 1); label = gtk_label_new ("Popover vexpand"); check = gtk_check_button_new (); g_object_bind_property (check, "active", popover, "vexpand", G_BINDING_DEFAULT); g_object_bind_property (check, "active", popover2, "vexpand", G_BINDING_DEFAULT); gtk_grid_attach (GTK_GRID (grid), label , 1, 2, 1, 1); gtk_grid_attach (GTK_GRID (grid), check, 2, 2, 1, 1); label = gtk_label_new ("Button direction"); combo = gtk_combo_box_text_new (); gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "up", "Up"); gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "down", "Down"); gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "left", "Left"); gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "right", "Right"); g_object_bind_property (combo, "active", button, "direction", G_BINDING_DEFAULT); g_object_bind_property (combo, "active", button2, "direction", G_BINDING_DEFAULT); gtk_grid_attach (GTK_GRID (grid), label , 1, 3, 1, 1); gtk_grid_attach (GTK_GRID (grid), combo, 2, 3, 1, 1); label = gtk_label_new ("Button halign"); combo = gtk_combo_box_text_new (); gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "fill", "Fill"); gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "start", "Start"); gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "end", "End"); gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "center", "Center"); g_object_bind_property (combo, "active", box, "halign", G_BINDING_DEFAULT); gtk_grid_attach (GTK_GRID (grid), label , 1, 4, 1, 1); gtk_grid_attach (GTK_GRID (grid), combo, 2, 4, 1, 1); label = gtk_label_new ("Button valign"); combo = gtk_combo_box_text_new (); gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "fill", "Fill"); gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "start", "Start"); gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "end", "End"); gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "center", "Center"); g_object_bind_property (combo, "active", box, "valign", G_BINDING_DEFAULT); gtk_grid_attach (GTK_GRID (grid), label , 1, 5, 1, 1); gtk_grid_attach (GTK_GRID (grid), combo, 2, 5, 1, 1); gtk_widget_show_all (win); gtk_main (); return 0; }
int main (int argc, char *argv[]) { //const std::string creatureDB[]={"pidgeot","gardevoir"}; - For creature catalog~~ //std::cout<<creatureDB[0]; /* Initialize GTK+ */ g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL); gtk_init (&argc, &argv); g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL); /* Main window configuration */ win = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_resizable (GTK_WINDOW (win), false); gtk_widget_set_size_request(win,windowWidth,windowHeight); gtk_container_set_border_width (GTK_CONTAINER (win), 0); gtk_window_set_title (GTK_WINDOW (win), "Pokemon"); gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER); gtk_widget_realize (win); g_signal_connect (win, "destroy", gtk_main_quit, NULL); gtk_window_set_icon_from_file(GTK_WINDOW(win),"images/winIcon.png",NULL); //gtk_window_set_decorated (GTK_WINDOW(win),FALSE); //Óáèðàåò ñòàíäàðòíîå îôîðìëåíèå îêíà windows /* Initializing objects */ zeBigContainer = gtk_box_new (GTK_ORIENTATION_VERTICAL,0); zeBigContainerOverlay = gtk_overlay_new(); topPart = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,0); topPartCenter = gtk_alignment_new (0.5,0.5,1,1); topPartLeft = gtk_box_new (GTK_ORIENTATION_VERTICAL,0); topPartCenter = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,0); topPartRight = gtk_box_new (GTK_ORIENTATION_VERTICAL,0); bottomPart = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,0); buttons = gtk_grid_new (); dialogScrollFrame = gtk_scrolled_window_new(NULL,NULL); dialogText = gtk_text_view_new (); dialogBuffer = gtk_text_buffer_new (NULL); button1 = gtk_button_new (); button2 = gtk_button_new (); button3 = gtk_button_new (); button4 = gtk_button_new_with_label ("Restart"); button5 = gtk_button_new_with_label ("Back to choosing screen"); topMidPart = gtk_image_new_from_file ("images/topPic.jpg"); IMGBackground = gtk_image_new_from_file ("images/pokeBackground.jpg"); leftImage = gtk_image_new_from_file ("images/filler.PNG"); rightImage = gtk_image_new_from_file ("images/filler.PNG"); leftBar = gtk_progress_bar_new (); rightBar = gtk_progress_bar_new (); /* Setting dialogText */ gtk_text_view_set_border_window_size(GTK_TEXT_VIEW(dialogText), GTK_TEXT_WINDOW_LEFT, 5); gtk_text_view_set_border_window_size(GTK_TEXT_VIEW(dialogText), GTK_TEXT_WINDOW_BOTTOM, 20); gtk_text_view_set_border_window_size(GTK_TEXT_VIEW(dialogText), GTK_TEXT_WINDOW_TOP, 5); gtk_text_view_set_editable(GTK_TEXT_VIEW(dialogText), FALSE); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(dialogText), FALSE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(dialogText),GTK_WRAP_WORD); /* Setting progress bars */ gtk_progress_bar_set_inverted(GTK_PROGRESS_BAR(rightBar),TRUE); gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(leftBar),TRUE); gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(rightBar),TRUE); /* Various initializations */ gtk_box_set_homogeneous((GtkBox*)topPartCenter,TRUE); gtk_box_set_homogeneous((GtkBox*)topPart,TRUE); gtk_box_set_homogeneous((GtkBox*)bottomPart,TRUE); gtk_box_set_homogeneous((GtkBox*)zeBigContainer,TRUE); gtk_grid_set_row_homogeneous((GtkGrid*)buttons,TRUE); gtk_grid_set_column_homogeneous((GtkGrid*)buttons,TRUE); gtk_grid_set_row_spacing((GtkGrid*)buttons,12); gtk_grid_set_column_spacing((GtkGrid*)buttons,12); g_object_set (buttons,"margin",12,NULL); g_object_set (topPart,"margin",12,NULL); gtk_container_set_border_width(GTK_CONTAINER(dialogScrollFrame),5); //gtk_box_set_child_packing((GtkBox*)zeBigContainer,bottomPart,gTRUE,gTRUE,100,GTK_PACK_START); gtk_text_view_set_buffer (GTK_TEXT_VIEW(dialogText), dialogBuffer); gtk_text_buffer_set_text(dialogBuffer, "", -1); //gtk_text_buffer_get_iter_at_offset (dialogBuffer, &lastCharIter, -1); gtk_text_buffer_get_end_iter(dialogBuffer, &endIter); fontDesc = pango_font_description_from_string("Consolas"); gtk_widget_override_font(dialogText,fontDesc); endMark = gtk_text_mark_new ("endMark",FALSE); endMark = gtk_text_buffer_get_mark(dialogBuffer,"insert"); gtk_button_set_always_show_image(GTK_BUTTON(button1),TRUE); gtk_button_set_always_show_image(GTK_BUTTON(button2),TRUE); gtk_button_set_always_show_image(GTK_BUTTON(button3),TRUE); /* Building objects */ gtk_container_add (GTK_CONTAINER(win),zeBigContainerOverlay); gtk_overlay_add_overlay(GTK_OVERLAY(zeBigContainerOverlay),zeBigContainer); gtk_container_add (GTK_CONTAINER(zeBigContainerOverlay),IMGBackground); gtk_container_add (GTK_CONTAINER(zeBigContainer),topPart); gtk_container_add (GTK_CONTAINER(zeBigContainer),bottomPart); gtk_container_add (GTK_CONTAINER(topPart),topPartLeft); // Â topPartLeft âñòàâëÿòü ëåâûé áàð gtk_container_add (GTK_CONTAINER(topPartLeft),leftBar); gtk_container_add (GTK_CONTAINER(topPartLeft),leftImage); gtk_container_add (GTK_CONTAINER(topPart),topPartCenter); gtk_container_add (GTK_CONTAINER(topPart),topPartRight); // â topPartRight - ïðàâûé... gtk_container_add (GTK_CONTAINER(topPartRight),rightBar); gtk_container_add (GTK_CONTAINER(topPartRight),rightImage); gtk_container_add (GTK_CONTAINER(topPartCenter),topMidPart); gtk_container_add (GTK_CONTAINER(bottomPart),dialogScrollFrame); gtk_container_add (GTK_CONTAINER(dialogScrollFrame),dialogText); gtk_container_add (GTK_CONTAINER(bottomPart),buttons); gtk_grid_attach (GTK_GRID(buttons),button1, 1,1,1,1); gtk_grid_attach (GTK_GRID(buttons),button2, 1,2,1,1); gtk_grid_attach (GTK_GRID(buttons),button3, 1,3,1,1); gtk_grid_attach (GTK_GRID(buttons),button4, 1,4,1,1); gtk_grid_attach (GTK_GRID(buttons),button5, 1,5,1,1); /* Signal connects and some shiatd */ g_signal_connect(G_OBJECT(button1), "clicked", Cast1, NULL); g_signal_connect(G_OBJECT(button2), "clicked", Cast2, NULL); g_signal_connect(G_OBJECT(button3), "clicked", Cast3, NULL); g_signal_connect(G_OBJECT(button4), "clicked", combatStart, NULL); g_signal_connect(G_OBJECT(button5), "clicked", backToChoosingScreen,NULL); /* Creature chooser window configuration */ // TO BE CONTINUED.......................................................................... /* Window creation/configuration (win2) */ win2win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_resizable (GTK_WINDOW (win2win), false); gtk_widget_set_size_request(win2win,windowWidth,windowHeight); gtk_window_set_title (GTK_WINDOW (win2win), "Pokemon creature chooser"); gtk_window_set_position (GTK_WINDOW (win2win), GTK_WIN_POS_CENTER); gtk_widget_realize (win2win); g_signal_connect (win2win, "destroy", gtk_main_quit, NULL); gtk_window_set_icon_from_file(GTK_WINDOW(win2win),"images/winIcon.png",NULL); /* Initializing objects (win2) */ win2topLabel = gtk_image_new_from_file("images/logo.png"); //win2topLabel = gtk_label_new(""); //gtk_label_set_markup(GTK_LABEL(win2topLabel),"<small>Small</small><big>Bold</big>"); win2BigContainer = gtk_grid_new(); win2BigContainerOverlay = gtk_overlay_new (); win2TopPart = gtk_grid_new (); win2MiddlePart = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,0); win2BottomPart = gtk_grid_new(); win2BackgroundIMG = gtk_image_new_from_file ("images/pokeBackground.jpg"); win2button1 = gtk_button_new_with_label(">>Switch Screens<<"); win2button2 = gtk_button_new_with_label("Exit"); win2buttonReset = gtk_button_new_with_label("Reset"); win2creatureIcon1 = gtk_button_new(); win2creatureIcon2 = gtk_button_new(); win2creatureIcon3 = gtk_button_new(); win2creatureIcon4 = gtk_button_new(); win2creatureIcon5 = gtk_button_new(); win2creatureIcon1IMG = gtk_image_new_from_file("images/ImagePidgeotSmall.png"); win2creatureIcon2IMG = gtk_image_new_from_file("images/ImageGardevoirSmall.png"); win2creatureIcon3IMG = gtk_image_new_from_file("images/ImageArcanineSmall.png"); win2creatureIcon4IMG = gtk_image_new_from_file("images/ImagePikachuSmall.png"); win2creatureIcon5IMG = gtk_image_new_from_file("images/ImageFishSmall.png"); win2ImageVersus = gtk_image_new_from_file ("images/versus.png"); win2MiddleFirst = gtk_image_new_from_file ("images/facelessVoid.png"); win2MiddleSecond = gtk_image_new_from_file ("images/facelessVoid.png"); /* Various initializations (win2) */ gtk_grid_set_row_homogeneous((GtkGrid*)win2BigContainer,TRUE); gtk_grid_set_column_homogeneous((GtkGrid*)win2BigContainer,TRUE); gtk_grid_set_row_spacing((GtkGrid*)win2BigContainer,12); gtk_grid_set_column_spacing((GtkGrid*)win2BigContainer,12); //g_object_set (win2BigContainer,"margin",12,NULL); gtk_grid_set_row_homogeneous((GtkGrid*)win2BottomPart,TRUE); gtk_grid_set_column_homogeneous((GtkGrid*)win2BottomPart,TRUE); gtk_grid_set_row_spacing((GtkGrid*)win2BottomPart,12); gtk_grid_set_column_spacing((GtkGrid*)win2BottomPart,12); g_object_set (win2BottomPart,"margin",12,NULL); gtk_grid_set_row_homogeneous((GtkGrid*)win2TopPart,TRUE); gtk_grid_set_column_homogeneous((GtkGrid*)win2TopPart,TRUE); gtk_grid_set_row_spacing((GtkGrid*)win2TopPart,12); gtk_grid_set_column_spacing((GtkGrid*)win2TopPart,12); g_object_set (win2TopPart,"margin",12,NULL); gtk_box_set_homogeneous(GTK_BOX(win2MiddlePart),TRUE); gtk_button_set_always_show_image(GTK_BUTTON(win2creatureIcon1),TRUE); gtk_button_set_always_show_image(GTK_BUTTON(win2creatureIcon2),TRUE); gtk_button_set_always_show_image(GTK_BUTTON(win2creatureIcon3),TRUE); gtk_button_set_always_show_image(GTK_BUTTON(win2creatureIcon4),TRUE); gtk_button_set_always_show_image(GTK_BUTTON(win2creatureIcon5),TRUE); gtk_button_set_image(GTK_BUTTON(win2creatureIcon1),win2creatureIcon1IMG); gtk_button_set_image(GTK_BUTTON(win2creatureIcon2),win2creatureIcon2IMG); gtk_button_set_image(GTK_BUTTON(win2creatureIcon3),win2creatureIcon3IMG); gtk_button_set_image(GTK_BUTTON(win2creatureIcon4),win2creatureIcon4IMG); gtk_button_set_image(GTK_BUTTON(win2creatureIcon5),win2creatureIcon5IMG); /* Building objects (win2) */ gtk_container_add (GTK_CONTAINER(win2win),win2BigContainerOverlay); gtk_overlay_add_overlay(GTK_OVERLAY(win2BigContainerOverlay),win2BigContainer); gtk_container_add (GTK_CONTAINER(win2BigContainerOverlay),win2BackgroundIMG); gtk_grid_attach(GTK_GRID(win2BigContainer),win2topLabel,1,1,1,2);//1 gtk_grid_attach(GTK_GRID(win2BigContainer),win2TopPart,1,2,1,3);//3 gtk_grid_attach(GTK_GRID(win2TopPart),win2creatureIcon1,1,1,1,1); gtk_grid_attach(GTK_GRID(win2TopPart),win2creatureIcon2,2,1,1,1); gtk_grid_attach(GTK_GRID(win2TopPart),win2creatureIcon3,3,1,1,1); gtk_grid_attach(GTK_GRID(win2TopPart),win2creatureIcon4,4,1,1,1); gtk_grid_attach(GTK_GRID(win2TopPart),win2creatureIcon5,5,1,1,1); gtk_grid_attach(GTK_GRID(win2BigContainer),win2MiddlePart,1,5,1,3);//3 gtk_grid_attach(GTK_GRID(win2BigContainer),win2BottomPart,1,8,1,3);//3 gtk_container_add (GTK_CONTAINER(win2MiddlePart),win2MiddleFirst); gtk_container_add (GTK_CONTAINER(win2MiddlePart),win2ImageVersus); gtk_container_add (GTK_CONTAINER(win2MiddlePart),win2MiddleSecond); gtk_grid_attach (GTK_GRID(win2BottomPart),win2button1, 1,1,3,1); gtk_grid_attach (GTK_GRID(win2BottomPart),win2buttonReset,4,1,1,1); gtk_grid_attach (GTK_GRID(win2BottomPart),win2button2, 5,1,1,1); /* Signal connects (win2) */ g_signal_connect (G_OBJECT(win2button1),"clicked",win2StartGame,NULL); g_signal_connect (G_OBJECT(win2button2),"clicked",gtk_main_quit,NULL); g_signal_connect (G_OBJECT(win2creatureIcon1),"clicked",win2pidgeotSelect,NULL); g_signal_connect (G_OBJECT(win2creatureIcon2),"clicked",win2gardevoirSelect,NULL); g_signal_connect (G_OBJECT(win2creatureIcon3),"clicked",win2arcanineSelect,NULL); g_signal_connect (G_OBJECT(win2creatureIcon4),"clicked",win2pikachuSelect,NULL); g_signal_connect (G_OBJECT(win2creatureIcon5),"clicked",win2mightyfishSelect,NULL); g_signal_connect (G_OBJECT(win2buttonReset),"clicked",win2CharReset,NULL); /* Other stuff */ srand(time(NULL)); write ("___________________________________________________\n"); /* Enter the main loop */ gtk_widget_show_all (win2win); gtk_main (); return 0; };
static void gtk_color_editor_init (GtkColorEditor *editor) { GtkWidget *grid; GtkWidget *slider; GtkWidget *entry; GtkWidget *swatch; GtkAdjustment *h_adj, *s_adj, *v_adj, *a_adj; AtkObject *atk_obj; GdkRGBA transparent = { 0, 0, 0, 0 }; editor->priv = G_TYPE_INSTANCE_GET_PRIVATE (editor, GTK_TYPE_COLOR_EDITOR, GtkColorEditorPrivate); editor->priv->use_alpha = TRUE; editor->priv->h_adj = h_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0); editor->priv->s_adj = s_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0); editor->priv->v_adj = v_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0); editor->priv->a_adj = a_adj = gtk_adjustment_new (0, 0, 1, 0.01, 0.1, 0); g_object_ref_sink (h_adj); g_object_ref_sink (s_adj); g_object_ref_sink (v_adj); g_object_ref_sink (a_adj); g_signal_connect_swapped (h_adj, "value-changed", G_CALLBACK (hsv_changed), editor); g_signal_connect_swapped (s_adj, "value-changed", G_CALLBACK (hsv_changed), editor); g_signal_connect_swapped (v_adj, "value-changed", G_CALLBACK (hsv_changed), editor); g_signal_connect_swapped (a_adj, "value-changed", G_CALLBACK (hsv_changed), editor); gtk_widget_push_composite_child (); /* Construct the main UI */ editor->priv->swatch = swatch = gtk_color_swatch_new (); gtk_color_swatch_set_selectable (GTK_COLOR_SWATCH (editor->priv->swatch), FALSE); gtk_widget_set_events (swatch, gtk_widget_get_events (swatch) & ~(GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK)); gtk_widget_set_can_focus (swatch, FALSE); editor->priv->entry = entry = gtk_entry_new (); atk_obj = gtk_widget_get_accessible (entry); atk_object_set_role (atk_obj, ATK_ROLE_ENTRY); atk_object_set_name (atk_obj, _("Color Name")); g_signal_connect (entry, "activate", G_CALLBACK (entry_apply), editor); g_signal_connect (entry, "notify::text", G_CALLBACK (entry_text_changed), editor); g_signal_connect (entry, "focus-out-event", G_CALLBACK (entry_focus_out), editor); editor->priv->h_slider = slider = gtk_color_scale_new (h_adj, GTK_COLOR_SCALE_HUE); gtk_orientable_set_orientation (GTK_ORIENTABLE (slider), GTK_ORIENTATION_VERTICAL); if (gtk_widget_get_direction (slider) == GTK_TEXT_DIR_RTL) gtk_style_context_add_class (gtk_widget_get_style_context (slider), GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE); else gtk_style_context_add_class (gtk_widget_get_style_context (slider), GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW); editor->priv->sv_plane = gtk_color_plane_new (h_adj, s_adj, v_adj); gtk_widget_set_size_request (editor->priv->sv_plane, 300, 300); editor->priv->a_slider = slider = gtk_color_scale_new (a_adj, GTK_COLOR_SCALE_ALPHA); gtk_orientable_set_orientation (GTK_ORIENTABLE (slider), GTK_ORIENTATION_HORIZONTAL); gtk_style_context_add_class (gtk_widget_get_style_context (slider), GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE); editor->priv->grid = grid = gtk_grid_new (); gtk_grid_set_row_spacing (GTK_GRID (grid), 12); gtk_grid_set_column_spacing (GTK_GRID (grid), 12); gtk_grid_attach (GTK_GRID (grid), editor->priv->swatch, 1, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), editor->priv->entry, 2, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), editor->priv->h_slider, 0, 1, 1, 1); gtk_grid_attach (GTK_GRID (grid), editor->priv->sv_plane, 1, 1, 2, 1); gtk_grid_attach (GTK_GRID (grid), editor->priv->a_slider, 1, 2, 2, 1); /* This extra margin is necessary so we have room to the sides * to place the popups as desired */ gtk_widget_set_margin_left (grid, 30); gtk_widget_set_margin_right (grid, 30); editor->priv->overlay = gtk_overlay_new (); gtk_widget_override_background_color (editor->priv->overlay, 0, &transparent); gtk_container_add (GTK_CONTAINER (editor->priv->overlay), grid); /* Construct the sv popup */ editor->priv->s_entry = entry = gtk_spin_button_new (scaled_adjustment (s_adj, 100), 1, 0); atk_obj = gtk_widget_get_accessible (entry); atk_object_set_name (atk_obj, C_("Color channel", "Saturation")); atk_object_set_role (atk_obj, ATK_ROLE_ENTRY); g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor); editor->priv->v_entry = entry = gtk_spin_button_new (scaled_adjustment (v_adj, 100), 1, 0); atk_obj = gtk_widget_get_accessible (entry); atk_object_set_name (atk_obj, C_("Color channel", "Value")); atk_object_set_role (atk_obj, ATK_ROLE_ENTRY); g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor); grid = gtk_grid_new (); gtk_grid_set_row_spacing (GTK_GRID (grid), 6); gtk_grid_set_column_spacing (GTK_GRID (grid), 6); gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "S")), 0, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), editor->priv->s_entry, 1, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "V")), 0, 1, 1, 1); gtk_grid_attach (GTK_GRID (grid), editor->priv->v_entry, 1, 1, 1, 1); editor->priv->sv_popup = create_popup (editor, editor->priv->sv_plane, grid); /* Construct the h popup */ editor->priv->h_entry = entry = gtk_spin_button_new (scaled_adjustment (h_adj, 100), 1, 0); atk_obj = gtk_widget_get_accessible (entry); atk_object_set_name (atk_obj, C_("Color channel", "Hue")); atk_object_set_role (atk_obj, ATK_ROLE_ENTRY); g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor); grid = gtk_grid_new (); gtk_grid_set_column_spacing (GTK_GRID (grid), 6); gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "H")), 0, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), editor->priv->h_entry, 1, 0, 1, 1); editor->priv->h_popup = create_popup (editor, editor->priv->h_slider, grid); /* Construct the a popup */ editor->priv->a_entry = entry = gtk_spin_button_new (scaled_adjustment (a_adj, 100), 1, 0); atk_obj = gtk_widget_get_accessible (entry); atk_object_set_name (atk_obj, C_("Color channel", "Alpha")); atk_object_set_role (atk_obj, ATK_ROLE_ENTRY); g_signal_connect (entry, "key-press-event", G_CALLBACK (popup_key_press), editor); grid = gtk_grid_new (); gtk_grid_set_column_spacing (GTK_GRID (grid), 6); gtk_grid_attach (GTK_GRID (grid), gtk_label_new (C_("Color channel", "A")), 0, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), editor->priv->a_entry, 1, 0, 1, 1); editor->priv->a_popup = create_popup (editor, editor->priv->a_slider, grid); /* Hook up popup positioning */ g_signal_connect (editor->priv->overlay, "get-child-position", G_CALLBACK (get_child_position), editor); g_signal_connect (editor, "notify::visible", G_CALLBACK (dismiss_current_popup), NULL); gtk_widget_show_all (editor->priv->overlay); gtk_container_add (GTK_CONTAINER (editor), editor->priv->overlay); gtk_widget_pop_composite_child (); }
int main (int argc, char *argv[]) { GtkWidget *win, *overlay, *grid, *main_child, *child, *label, *sw; GtkCssProvider *provider; gchar *str; gtk_init (&argc, &argv); provider = gtk_css_provider_new (); gtk_css_provider_load_from_data (provider, "GtkLabel { border: 3px solid black; border-radius: 5px; padding: 2px; }" ".top { border-top-style: none; right-radius: 0px; border-top-left-radius: 0px; }" ".bottom { border-bottom-style: none; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; }" ".left { border-left-style: none; border-top-left-radius: 0px; border-bottom-left-radius: 0px; }" ".right { border-right-style: none; border-top-right-radius: 0px; border-bottom-right-radius: 0px; }", -1, NULL); gtk_style_context_add_provider_for_screen (gdk_screen_get_default (), GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); win = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (win), 600, 600); grid = gtk_grid_new (); child = gtk_event_box_new (); gtk_widget_set_hexpand (child, TRUE); gtk_widget_set_vexpand (child, TRUE); gtk_container_add (GTK_CONTAINER (grid), child); label = gtk_label_new ("Out of overlay"); gtk_container_add (GTK_CONTAINER (child), label); overlay = gtk_overlay_new (); sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS); gtk_container_add (GTK_CONTAINER (overlay), sw); main_child = gtk_event_box_new (); gtk_container_add (GTK_CONTAINER (sw), main_child); gtk_widget_set_hexpand (main_child, TRUE); gtk_widget_set_vexpand (main_child, TRUE); label = gtk_label_new ("Main child"); gtk_widget_set_halign (label, GTK_ALIGN_CENTER); gtk_widget_set_valign (label, GTK_ALIGN_CENTER); gtk_container_add (GTK_CONTAINER (main_child), label); child = gtk_label_new (NULL); str = g_strdup_printf ("%p", child); gtk_label_set_text (GTK_LABEL (child), str); g_free (str); g_print ("Bottom/Right child: %p\n", child); gtk_widget_set_halign (child, GTK_ALIGN_END); gtk_widget_set_valign (child, GTK_ALIGN_END); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_signal_connect (child, "size-allocate", G_CALLBACK (child_size_allocate), overlay); child = gtk_label_new (NULL); str = g_strdup_printf ("%p", child); gtk_label_set_text (GTK_LABEL (child), str); g_free (str); g_print ("Left/Top child: %p\n", child); gtk_widget_set_halign (child, GTK_ALIGN_START); gtk_widget_set_valign (child, GTK_ALIGN_START); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_signal_connect (child, "size-allocate", G_CALLBACK (child_size_allocate), overlay); child = gtk_label_new (NULL); str = g_strdup_printf ("%p", child); gtk_label_set_text (GTK_LABEL (child), str); g_free (str); g_print ("Right/Center child: %p\n", child); gtk_widget_set_halign (child, GTK_ALIGN_END); gtk_widget_set_valign (child, GTK_ALIGN_CENTER); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_signal_connect (child, "size-allocate", G_CALLBACK (child_size_allocate), overlay); child = gtk_label_new (NULL); str = g_strdup_printf ("%p", child); gtk_label_set_text (GTK_LABEL (child), str); g_free (str); gtk_widget_set_margin_start (child, 55); gtk_widget_set_margin_top (child, 4); g_print ("Left/Top margined child: %p\n", child); gtk_widget_set_halign (child, GTK_ALIGN_START); gtk_widget_set_valign (child, GTK_ALIGN_START); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_signal_connect (child, "size-allocate", G_CALLBACK (child_size_allocate), overlay); child = gtk_label_new (NULL); str = g_strdup_printf ("%p", child); gtk_label_set_text (GTK_LABEL (child), str); g_free (str); g_print ("Custom get-child-position child: %p\n", child); gtk_widget_set_halign (child, GTK_ALIGN_START); gtk_widget_set_valign (child, GTK_ALIGN_START); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_signal_connect (child, "size-allocate", G_CALLBACK (child_size_allocate), overlay); g_signal_connect (overlay, "get-child-position", G_CALLBACK (overlay_get_child_position), child); gtk_grid_attach (GTK_GRID (grid), overlay, 1, 0, 1, 3); gtk_container_add (GTK_CONTAINER (win), grid); g_print ("\n"); gtk_widget_show_all (win); gtk_main (); return 0; }
int main (int argc, char *argv[]) { GtkWidget *win, *overlay, *grid, *main_child, *child, *label, *sw; GdkRGBA color; gchar *str; gtk_init (&argc, &argv); win = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (win), 600, 600); grid = gtk_grid_new (); child = gtk_event_box_new (); gdk_rgba_parse (&color, "red"); gtk_widget_override_background_color (child, 0, &color); gtk_widget_set_hexpand (child, TRUE); gtk_widget_set_vexpand (child, TRUE); gtk_container_add (GTK_CONTAINER (grid), child); label = gtk_label_new ("Out of overlay"); gtk_container_add (GTK_CONTAINER (child), label); overlay = gtk_overlay_new (); sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS); gtk_container_add (GTK_CONTAINER (overlay), sw); main_child = gtk_event_box_new (); gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), main_child); gdk_rgba_parse (&color, "green"); gtk_widget_override_background_color (main_child, 0, &color); gtk_widget_set_hexpand (main_child, TRUE); gtk_widget_set_vexpand (main_child, TRUE); label = gtk_label_new ("Main child"); gtk_container_add (GTK_CONTAINER (main_child), label); child = gtk_label_new (NULL); str = g_strdup_printf ("%p", child); gtk_label_set_text (GTK_LABEL (child), str); g_free (str); g_print ("Bottom/Right child: %p\n", child); gtk_widget_set_halign (child, GTK_ALIGN_END); gtk_widget_set_valign (child, GTK_ALIGN_END); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_signal_connect (child, "size-allocate", G_CALLBACK (child_size_allocate), overlay); child = gtk_label_new (NULL); str = g_strdup_printf ("%p", child); gtk_label_set_text (GTK_LABEL (child), str); g_free (str); g_print ("Left/Top child: %p\n", child); gtk_widget_set_halign (child, GTK_ALIGN_START); gtk_widget_set_valign (child, GTK_ALIGN_START); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_signal_connect (child, "size-allocate", G_CALLBACK (child_size_allocate), overlay); child = gtk_label_new (NULL); str = g_strdup_printf ("%p", child); gtk_label_set_text (GTK_LABEL (child), str); g_free (str); g_print ("Right/Center child: %p\n", child); gtk_widget_set_halign (child, GTK_ALIGN_END); gtk_widget_set_valign (child, GTK_ALIGN_CENTER); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_signal_connect (child, "size-allocate", G_CALLBACK (child_size_allocate), overlay); child = gtk_label_new (NULL); str = g_strdup_printf ("%p", child); gtk_label_set_text (GTK_LABEL (child), str); g_free (str); gtk_widget_set_margin_left (child, 55); gtk_widget_set_margin_top (child, 4); g_print ("Left/Top margined child: %p\n", child); gtk_widget_set_halign (child, GTK_ALIGN_START); gtk_widget_set_valign (child, GTK_ALIGN_START); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_signal_connect (child, "size-allocate", G_CALLBACK (child_size_allocate), overlay); child = gtk_label_new (NULL); str = g_strdup_printf ("%p", child); gtk_label_set_text (GTK_LABEL (child), str); g_free (str); g_print ("Custom get-child-position child: %p\n", child); gtk_widget_set_halign (child, GTK_ALIGN_START); gtk_widget_set_valign (child, GTK_ALIGN_START); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child); g_signal_connect (child, "size-allocate", G_CALLBACK (child_size_allocate), overlay); g_signal_connect (overlay, "get-child-position", G_CALLBACK (overlay_get_child_position), child); gtk_grid_attach (GTK_GRID (grid), overlay, 1, 0, 1, 3); gtk_container_add (GTK_CONTAINER (win), grid); g_print ("\n"); gtk_widget_show_all (win); gtk_main (); return 0; }
GtkWidget * do_transparent (GtkWidget *do_widget) { static GtkWidget *window = NULL; if (!window) { GtkWidget *view; GtkWidget *sw; GtkWidget *overlay; GtkWidget *entry; GtkCssProvider *provider; gchar *css; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_screen (GTK_WINDOW (window), gtk_widget_get_screen (do_widget)); gtk_window_set_default_size (GTK_WINDOW (window), 450, 450); g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window); gtk_window_set_title (GTK_WINDOW (window), "Transparent"); gtk_container_set_border_width (GTK_CONTAINER (window), 0); view = gtk_text_view_new (); sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (sw), view); overlay = gtk_overlay_new (); gtk_container_add (GTK_CONTAINER (overlay), sw); gtk_container_add (GTK_CONTAINER (window), overlay); entry = gtk_entry_new (); provider = gtk_css_provider_new (); css = g_strdup_printf ("* { border-width: 0px %dpx %dpx 0px; }", SHADOW_OFFSET_X, SHADOW_OFFSET_Y); gtk_css_provider_load_from_data (provider, css, -1, NULL); g_free (css); gtk_style_context_add_provider (gtk_widget_get_style_context (entry), GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); g_signal_connect (entry, "draw", G_CALLBACK (draw_callback), NULL); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), entry); gtk_widget_set_halign (entry, GTK_ALIGN_CENTER); gtk_widget_set_valign (entry, GTK_ALIGN_START); gtk_widget_show_all (overlay); } if (!gtk_widget_get_visible (window)) { gtk_widget_show (window); } else { gtk_widget_destroy (window); window = NULL; } return window; }
GtkWidget * do_css_multiplebgs (GtkWidget *do_widget) { if (!window) { GtkWidget *paned, *container, *child; GtkStyleProvider *provider; GtkTextBuffer *text; GBytes *bytes; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget)); gtk_window_set_default_size (GTK_WINDOW (window), 400, 300); g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window); container = gtk_overlay_new (); gtk_widget_add_events (container, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK); gtk_container_add (GTK_CONTAINER (window), container); child = gtk_drawing_area_new (); gtk_widget_set_name (child, "canvas"); g_signal_connect (child, "draw", G_CALLBACK (drawing_area_draw), NULL); gtk_container_add (GTK_CONTAINER (container), child); child = gtk_button_new (); gtk_widget_add_events (child, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK); gtk_overlay_add_overlay (GTK_OVERLAY (container), child); gtk_widget_set_name (child, "bricks-button"); gtk_widget_set_halign (child, GTK_ALIGN_CENTER); gtk_widget_set_valign (child, GTK_ALIGN_CENTER); gtk_widget_set_size_request (child, 200, 80); paned = gtk_paned_new (GTK_ORIENTATION_VERTICAL); gtk_overlay_add_overlay (GTK_OVERLAY (container), paned); /* Need a filler so we get a handle */ child = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_container_add (GTK_CONTAINER (paned), child); text = gtk_text_buffer_new (NULL); gtk_text_buffer_create_tag (text, "warning", "underline", PANGO_UNDERLINE_SINGLE, NULL); gtk_text_buffer_create_tag (text, "error", "underline", PANGO_UNDERLINE_ERROR, NULL); provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ()); container = gtk_scrolled_window_new (NULL, NULL); gtk_container_add (GTK_CONTAINER (paned), container); child = gtk_text_view_new_with_buffer (text); gtk_container_add (GTK_CONTAINER (container), child); g_signal_connect (text, "changed", G_CALLBACK (css_text_changed), provider); bytes = g_resources_lookup_data ("/css_multiplebgs/gtk.css", 0, NULL); gtk_text_buffer_set_text (text, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes)); g_signal_connect (provider, "parsing-error", G_CALLBACK (show_parsing_error), gtk_text_view_get_buffer (GTK_TEXT_VIEW (child))); apply_css (window, provider); } if (!gtk_widget_get_visible (window)) gtk_widget_show_all (window); else { gtk_widget_destroy (window); window = NULL; } return window; }
int main(int argc, char *argv[]) { signal_user_data_t *ud; GValue *preset; GError *error = NULL; GOptionContext *context; #ifdef ENABLE_NLS bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #endif context = g_option_context_new("- Transcode media formats"); g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); g_option_context_add_group(context, gtk_get_option_group(TRUE)); #if defined(_ENABLE_GST) g_option_context_add_group(context, gst_init_get_option_group()); #endif g_option_context_parse(context, &argc, &argv, &error); if (error != NULL) { g_warning("%s: %s", G_STRFUNC, error->message); g_clear_error(&error); } g_option_context_free(context); if (argc > 1 && dvd_device == NULL && argv[1][0] != '-') { dvd_device = argv[1]; } gtk_init(&argc, &argv); #if GTK_CHECK_VERSION(3, 0, 0) GtkCssProvider *css = gtk_css_provider_new(); error = NULL; gtk_css_provider_load_from_data(css, MyCSS, -1, &error); if (error == NULL) { GdkScreen *ss = gdk_screen_get_default(); gtk_style_context_add_provider_for_screen(ss, GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } else { g_warning("%s: %s", G_STRFUNC, error->message); g_clear_error(&error); } #else gtk_rc_parse_string(hud_rcstyle); #endif g_type_class_unref(g_type_class_ref(GTK_TYPE_BUTTON)); g_object_set(gtk_settings_get_default(), "gtk-button-images", TRUE, NULL); #if !defined(_WIN32) notify_init("HandBrake"); #endif ghb_register_transforms(); ghb_resource_init(); ghb_load_icons(); #if !defined(_WIN32) dbus_g_thread_init(); #endif ghb_udev_init(); ghb_write_pid_file(); ud = g_malloc0(sizeof(signal_user_data_t)); ud->debug = ghb_debug; g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, debug_log_handler, ud); g_log_set_handler("Gtk", G_LOG_LEVEL_WARNING, warn_log_handler, ud); //g_log_set_handler("Gtk", G_LOG_LEVEL_CRITICAL, warn_log_handler, ud); ud->settings = ghb_settings_new(); ud->builder = create_builder_or_die(BUILDER_NAME); // Enable events that alert us to media change events watch_volumes(ud); //GtkWidget *widget = GHB_WIDGET(ud->builder, "PictureDetelecineCustom"); //gtk_entry_set_inner_border(widget, 2); // Since GtkBuilder no longer assigns object ids to widget names // Assign a few that are necessary for style overrides to work GtkWidget *widget; #if defined(_NO_UPDATE_CHECK) widget = GHB_WIDGET(ud->builder, "check_updates_box"); gtk_widget_hide(widget); #endif // Must set the names of the widgets that I want to modify // style for. gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_event_box"), "preview_event_box"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_frame"), "preview_frame"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_preview_play"), "live_preview_play"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_preview_progress"), "live_preview_progress"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_encode_progress"), "live_encode_progress"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_duration"), "live_duration"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_show_crop"), "preview_show_crop"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_fullscreen"), "preview_fullscreen"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "hide_settings"), "hide_settings"); widget = GHB_WIDGET(ud->builder, "preview_hud"); gtk_widget_set_name(widget, "preview_hud"); widget = GHB_WIDGET(ud->builder, "preview_window"); gtk_widget_set_name(widget, "preview_window"); // Set up the "hud" control overlay for the preview window GtkWidget *align, *draw, *hud, *blender; align = GHB_WIDGET(ud->builder, "preview_window_alignment"); draw = GHB_WIDGET(ud->builder, "preview_image_align"); hud = GHB_WIDGET(ud->builder, "preview_hud"); #if 0 // wGTK_CHECK_VERSION(3, 0, 0) // This uses the new GtkOverlay widget. // // Unfortunately, GtkOverlay is broken in a couple of ways. // // First, it doesn't respect gtk_widget_shape_combine_region() // on it's child overlays. It appears to just ignore the clip // mask of the child. // // Second, it doesn't respect window opacity. // // So for now, I'll just continue using my home-grown overlay // widget (GhbCompositor). blender = gtk_overlay_new(); gtk_container_add(GTK_CONTAINER(align), blender); gtk_container_add(GTK_CONTAINER(blender), draw); gtk_widget_set_valign (hud, GTK_ALIGN_END); gtk_widget_set_halign (hud, GTK_ALIGN_CENTER); gtk_overlay_add_overlay(GTK_OVERLAY(blender), hud); g_signal_connect(G_OBJECT(blender), "get-child-position", G_CALLBACK(position_overlay_cb), ud); gtk_widget_show(blender); #else // Set up compositing for hud blender = ghb_compositor_new(); gtk_container_add(GTK_CONTAINER(align), blender); ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), draw, 1, 1); ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), hud, 2, .85); gtk_widget_show(blender); #endif // Redirect stderr to the activity window ghb_preview_init(ud); IoRedirect(ud); ghb_log( "%s - %s - %s", HB_PROJECT_TITLE, HB_PROJECT_BUILD_TITLE, HB_PROJECT_URL_WEBSITE ); ghb_init_dep_map(); // Need to connect x264_options textview buffer to the changed signal // since it can't be done automatically GtkTextView *textview; GtkTextBuffer *buffer; textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "x264Option")); buffer = gtk_text_view_get_buffer(textview); g_signal_connect(buffer, "changed", (GCallback)x264_entry_changed_cb, ud); textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "x264OptionExtra")); buffer = gtk_text_view_get_buffer(textview); g_signal_connect(buffer, "changed", (GCallback)x264_option_changed_cb, ud); ghb_combo_init(ud); g_debug("ud %p\n", ud); g_debug("ud->builder %p\n", ud->builder); bind_audio_tree_model(ud); bind_subtitle_tree_model(ud); bind_presets_tree_model(ud); bind_queue_tree_model(ud); bind_chapter_tree_model(ud); // Connect up the signals to their callbacks // I wrote my own connector so that I could pass user data // to the callbacks. Builder's standard autoconnect doesn't all this. gtk_builder_connect_signals_full(ud->builder, MyConnect, ud); GtkWidget *presetSlider = GHB_WIDGET(ud->builder, "x264PresetSlider"); const char * const *x264_presets; int count = 0; x264_presets = hb_x264_presets(); while (x264_presets && x264_presets[count]) count++; gtk_range_set_range(GTK_RANGE(presetSlider), 0, count-1); // Load all internal settings ghb_settings_init(ud); // Load the presets files ghb_presets_load(ud); ghb_prefs_load(ud); ghb_prefs_to_ui(ud); gint logLevel; logLevel = ghb_settings_get_int(ud->settings, "LoggingLevel"); ghb_backend_init(logLevel); if (ghb_settings_get_boolean(ud->settings, "hbfd")) { ghb_hbfd(ud, TRUE); } gchar *source = ghb_settings_get_string(ud->settings, "default_source"); ghb_dvd_set_current(source, ud); g_free(source); // Parsing x264 options "" initializes x264 widgets to proper defaults ghb_x264_parse_options(ud, ""); // Populate the presets tree view ghb_presets_list_init(ud, NULL, 0); // Get the first preset name if (arg_preset != NULL) { preset = ghb_parse_preset_path(arg_preset); if (preset) { ghb_select_preset(ud->builder, preset); ghb_value_free(preset); } } else { ghb_select_default_preset(ud->builder); } // Grey out widgets that are dependent on a disabled feature ghb_check_all_depencencies(ud); if (dvd_device != NULL) { // Source overridden from command line option ghb_settings_set_string(ud->settings, "scan_source", dvd_device); g_idle_add((GSourceFunc)ghb_idle_scan, ud); } // Reload and check status of the last saved queue g_idle_add((GSourceFunc)ghb_reload_queue, ud); // Start timer for monitoring libhb status, 500ms g_timeout_add(500, ghb_timer_cb, (gpointer)ud); // Add dvd devices to File menu ghb_volname_cache_init(); GHB_THREAD_NEW("Cache Volume Names", (GThreadFunc)ghb_cache_volnames, ud); #if defined(_USE_APP_IND) GtkUIManager * uim = GTK_UI_MANAGER(GHB_OBJECT(ud->builder, "uimanager1")); GtkMenu *ai_menu = GTK_MENU(gtk_ui_manager_get_widget(uim, "/ui/tray_menu")); ud->ai = app_indicator_new("HandBrake", "hb-icon", APP_INDICATOR_CATEGORY_APPLICATION_STATUS); app_indicator_set_menu( ud->ai, ai_menu ); app_indicator_set_label( ud->ai, "", "99.99%"); if (ghb_settings_get_boolean(ud->settings, "show_status")) { app_indicator_set_status( ud->ai, APP_INDICATOR_STATUS_ACTIVE ); } else { app_indicator_set_status( ud->ai, APP_INDICATOR_STATUS_PASSIVE ); } GtkStatusIcon *si; si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status")); gtk_status_icon_set_visible(si, FALSE ); #else GtkStatusIcon *si; si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status")); gtk_status_icon_set_visible(si, ghb_settings_get_boolean(ud->settings, "show_status")); #if GTK_CHECK_VERSION(2, 16, 0) gtk_status_icon_set_has_tooltip(si, TRUE); g_signal_connect(si, "query-tooltip", status_icon_query_tooltip_cb, ud); #else gtk_status_icon_set_tooltip(si, "HandBrake"); #endif #endif // Ugly hack to keep subtitle table from bouncing around as I change // which set of controls are visible gint width, height; #if GTK_CHECK_VERSION(3, 0, 0) GtkRequisition min_size, size; widget = GHB_WIDGET(ud->builder, "SrtCodeset"); gtk_widget_get_preferred_size( widget, &min_size, &size ); height = MAX(min_size.height, size.height); widget = GHB_WIDGET(ud->builder, "srt_code_label"); gtk_widget_get_preferred_size( widget, &min_size, &size ); height += MAX(min_size.height, size.height); widget = GHB_WIDGET(ud->builder, "subtitle_table"); gtk_widget_set_size_request(widget, -1, height); #else GtkRequisition size; widget = GHB_WIDGET(ud->builder, "SrtCodeset"); gtk_widget_size_request( widget, &size ); height = size.height; widget = GHB_WIDGET(ud->builder, "srt_code_label"); gtk_widget_size_request( widget, &size ); height += size.height; widget = GHB_WIDGET(ud->builder, "subtitle_table"); gtk_widget_set_size_request(widget, -1, height); #endif widget = GHB_WIDGET(ud->builder, "hb_window"); GdkGeometry geo = { -1, -1, 1024, 768, -1, -1, 10, 10, 0, 0, GDK_GRAVITY_NORTH_WEST }; GdkWindowHints geo_mask; geo_mask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_BASE_SIZE; gtk_window_set_geometry_hints( GTK_WINDOW(widget), widget, &geo, geo_mask); width = ghb_settings_get_int(ud->settings, "window_width"); height = ghb_settings_get_int(ud->settings, "window_height"); gtk_window_resize(GTK_WINDOW(widget), width, height); gtk_widget_show(widget); /* * Filter objects in GtkBuilder xml * Unfortunately, GtkFilter is poorly supported by GtkBuilder, * so a lot of the setup must happen in code. SourceFilterAll SourceFilterVideo SourceFilterTS SourceFilterMPG SourceFilterEVO SourceFilterVOB SourceFilterMKV SourceFilterMP4 SourceFilterAVI SourceFilterMOV SourceFilterOGG SourceFilterFLV SourceFilterWMV */ // Add filters to source chooser GtkFileFilter *filter; GtkFileChooser *chooser; chooser = GTK_FILE_CHOOSER(GHB_WIDGET(ud->builder, "source_dialog")); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAll")); gtk_file_filter_set_name(filter, "All"); gtk_file_filter_add_pattern(filter, "*"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterVideo")); gtk_file_filter_set_name(filter, "Video"); gtk_file_filter_add_mime_type(filter, "video/*"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterTS")); gtk_file_filter_set_name(filter, "TS"); gtk_file_filter_add_pattern(filter, "*.ts"); gtk_file_filter_add_pattern(filter, "*.TS"); gtk_file_filter_add_pattern(filter, "*.m2ts"); gtk_file_filter_add_pattern(filter, "*.M2TS"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMPG")); gtk_file_filter_set_name(filter, "MPG"); gtk_file_filter_add_pattern(filter, "*.mpg"); gtk_file_filter_add_pattern(filter, "*.MPG"); gtk_file_filter_add_pattern(filter, "*.mepg"); gtk_file_filter_add_pattern(filter, "*.MEPG"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterEVO")); gtk_file_filter_set_name(filter, "EVO"); gtk_file_filter_add_pattern(filter, "*.evo"); gtk_file_filter_add_pattern(filter, "*.EVO"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterVOB")); gtk_file_filter_set_name(filter, "VOB"); gtk_file_filter_add_pattern(filter, "*.vob"); gtk_file_filter_add_pattern(filter, "*.VOB"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMKV")); gtk_file_filter_set_name(filter, "MKV"); gtk_file_filter_add_pattern(filter, "*.mkv"); gtk_file_filter_add_pattern(filter, "*.MKV"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMP4")); gtk_file_filter_set_name(filter, "MP4"); gtk_file_filter_add_pattern(filter, "*.mp4"); gtk_file_filter_add_pattern(filter, "*.MP4"); gtk_file_filter_add_pattern(filter, "*.m4v"); gtk_file_filter_add_pattern(filter, "*.M4V"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMOV")); gtk_file_filter_set_name(filter, "MOV"); gtk_file_filter_add_pattern(filter, "*.mov"); gtk_file_filter_add_pattern(filter, "*.MOV"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAVI")); gtk_file_filter_set_name(filter, "AVI"); gtk_file_filter_add_pattern(filter, "*.avi"); gtk_file_filter_add_pattern(filter, "*.AVI"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterOGG")); gtk_file_filter_set_name(filter, "OGG"); gtk_file_filter_add_pattern(filter, "*.ogg"); gtk_file_filter_add_pattern(filter, "*.OGG"); gtk_file_filter_add_pattern(filter, "*.ogv"); gtk_file_filter_add_pattern(filter, "*.OGV"); gtk_file_filter_add_pattern(filter, "*.ogm"); gtk_file_filter_add_pattern(filter, "*.OGM"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterFLV")); gtk_file_filter_set_name(filter, "FLV"); gtk_file_filter_add_pattern(filter, "*.flv"); gtk_file_filter_add_pattern(filter, "*.FLV"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterWMV")); gtk_file_filter_set_name(filter, "WMV"); gtk_file_filter_add_pattern(filter, "*.wmv"); gtk_file_filter_add_pattern(filter, "*.WMV"); gtk_file_chooser_add_filter(chooser, filter); // Gtk has a really stupid bug. If the file chooser is showing // hidden files AND there is no filter set, it will not select // the filename when gtk_file_chooser_set_filename is called. // So add a completely unnessary filter to prevent this behavior. filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAll")); gtk_file_chooser_set_filter(chooser, filter); PangoFontDescription *font_desc; font_desc = pango_font_description_from_string("monospace 10"); textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "activity_view")); gtk_widget_modify_font(GTK_WIDGET(textview), font_desc); pango_font_description_free(font_desc); // Everything should be go-to-go. Lets rock! gtk_main(); gtk_status_icon_set_visible(si, FALSE); ghb_backend_close(); if (ud->queue) ghb_value_free(ud->queue); ghb_value_free(ud->settings); g_io_channel_unref(ud->activity_log); ghb_settings_close(); #if !defined(_WIN32) notify_uninit(); #endif g_free(ud); return 0; }
static void setup_button (GpMenuButtonApplet *menu_button) { GpMenuButtonAppletPrivate *priv; GtkWidget *overlay; gboolean show_arrow; GtkStyleContext *style; guint icon_size; guint arrow_size; gchar *tooltip; priv = gp_menu_button_applet_get_instance_private (menu_button); priv->button = gp_menu_button_new (); gtk_container_add (GTK_CONTAINER (menu_button), priv->button); gtk_widget_show (priv->button); g_signal_connect (priv->button, "button-press-event", G_CALLBACK (button_press_event_cb), menu_button); g_signal_connect (priv->button, "clicked", G_CALLBACK (clicked_cb), menu_button); overlay = gtk_overlay_new (); gtk_container_add (GTK_CONTAINER (priv->button), overlay); gtk_widget_set_halign (overlay, GTK_ALIGN_FILL); gtk_widget_set_valign (overlay, GTK_ALIGN_FILL); gtk_widget_show (overlay); priv->image = gtk_image_new (); gtk_container_add (GTK_CONTAINER (overlay), priv->image); gtk_widget_show (priv->image); style = gtk_widget_get_style_context (priv->image); gtk_style_context_add_class (style, "icon"); show_arrow = g_settings_get_boolean (priv->settings, "show-arrow"); priv->arrow = gtk_image_new_from_icon_name ("go-down-symbolic", GTK_ICON_SIZE_MENU); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), priv->arrow); gtk_overlay_set_overlay_pass_through (GTK_OVERLAY (overlay), priv->arrow, TRUE); gtk_widget_set_visible (priv->arrow, show_arrow); style = gtk_widget_get_style_context (priv->arrow); gtk_style_context_add_class (style, "arrow"); icon_size = gp_applet_get_panel_icon_size (GP_APPLET (menu_button)); gtk_image_set_pixel_size (GTK_IMAGE (priv->image), icon_size); arrow_size = arrow_size_from_icon_size (icon_size); gtk_image_set_pixel_size (GTK_IMAGE (priv->arrow), arrow_size); tooltip = g_settings_get_string (priv->settings, "tooltip"); gtk_widget_set_tooltip_text (priv->button, *tooltip != '\0' ? tooltip : NULL); g_free (tooltip); g_object_bind_property (menu_button, "enable-tooltips", priv->button, "has-tooltip", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE); update_menu (menu_button); update_icon (menu_button); }
int main(int argc, char *argv[]) { signal_user_data_t *ud; GError *error = NULL; GOptionContext *context; hb_global_init(); #ifdef ENABLE_NLS bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #endif context = g_option_context_new(_("- Transcode media formats")); g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); g_option_context_add_group(context, gtk_get_option_group(TRUE)); #if defined(_ENABLE_GST) g_option_context_add_group(context, gst_init_get_option_group()); #endif g_option_context_parse(context, &argc, &argv, &error); if (error != NULL) { g_warning("%s: %s", G_STRFUNC, error->message); g_clear_error(&error); } g_option_context_free(context); #if defined(_WIN32) if (win32_console) { // Enable console logging if(AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole()){ close(STDOUT_FILENO); freopen("CONOUT$", "w", stdout); close(STDERR_FILENO); freopen("CONOUT$", "w", stderr); } } else { // Non-console windows apps do not have a stderr->_file // assigned properly stderr->_file = STDERR_FILENO; stdout->_file = STDOUT_FILENO; } #endif if (argc > 1 && dvd_device == NULL && argv[1][0] != '-') { dvd_device = argv[1]; } gtk_init(&argc, &argv); GtkCssProvider *css = gtk_css_provider_new(); error = NULL; gtk_css_provider_load_from_data(css, MyCSS, -1, &error); if (error == NULL) { GdkScreen *ss = gdk_screen_get_default(); gtk_style_context_add_provider_for_screen(ss, GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } else { g_warning("%s: %s", G_STRFUNC, error->message); g_clear_error(&error); } #if !defined(_WIN32) notify_init("HandBrake"); #endif ghb_resource_init(); ghb_load_icons(); #if !defined(_WIN32) dbus_g_thread_init(); #endif ghb_udev_init(); ghb_write_pid_file(); ud = g_malloc0(sizeof(signal_user_data_t)); ud->debug = ghb_debug; g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, debug_log_handler, ud); g_log_set_handler("Gtk", G_LOG_LEVEL_WARNING, warn_log_handler, ud); //g_log_set_handler("Gtk", G_LOG_LEVEL_CRITICAL, warn_log_handler, ud); ud->globals = ghb_dict_new(); ud->prefs = ghb_dict_new(); ud->settings_array = ghb_array_new(); ud->settings = ghb_dict_new(); ghb_array_append(ud->settings_array, ud->settings); ud->builder = create_builder_or_die(BUILDER_NAME); // Enable events that alert us to media change events watch_volumes(ud); //GtkWidget *widget = GHB_WIDGET(ud->builder, "PictureDetelecineCustom"); //gtk_entry_set_inner_border(widget, 2); // Since GtkBuilder no longer assigns object ids to widget names // Assign a few that are necessary for style overrides to work GtkWidget *widget; #if defined(_NO_UPDATE_CHECK) widget = GHB_WIDGET(ud->builder, "check_updates_box"); gtk_widget_hide(widget); #endif // Must set the names of the widgets that I want to modify // style for. gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_hud"), "preview_hud"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_frame"), "preview_frame"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_preview_play"), "live_preview_play"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_preview_progress"), "live_preview_progress"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_encode_progress"), "live_encode_progress"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_duration"), "live_duration"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_show_crop"), "preview_show_crop"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_fullscreen"), "preview_fullscreen"); widget = GHB_WIDGET(ud->builder, "preview_hud"); gtk_widget_set_name(widget, "preview_hud"); widget = GHB_WIDGET(ud->builder, "preview_window"); gtk_widget_set_name(widget, "preview_window"); // Set up the "hud" control overlay for the preview window GtkWidget *preview_box, *draw, *hud, *blender; preview_box = GHB_WIDGET(ud->builder, "preview_window_box"); draw = GHB_WIDGET(ud->builder, "preview_image"); hud = GHB_WIDGET(ud->builder, "preview_hud"); #if 0 // GTK_CHECK_VERSION(3, 0, 0) // This uses the new GtkOverlay widget. // // Unfortunately, GtkOverlay is broken in a couple of ways. // // First, it doesn't respect gtk_widget_shape_combine_region() // on it's child overlays. It appears to just ignore the clip // mask of the child. // // Second, it doesn't respect window opacity. // // So for now, I'll just continue using my home-grown overlay // widget (GhbCompositor). blender = gtk_overlay_new(); gtk_container_add(GTK_CONTAINER(preview_box), blender); gtk_container_add(GTK_CONTAINER(blender), draw); gtk_widget_set_valign (hud, GTK_ALIGN_END); gtk_widget_set_halign (hud, GTK_ALIGN_CENTER); gtk_overlay_add_overlay(GTK_OVERLAY(blender), hud); g_signal_connect(G_OBJECT(blender), "get-child-position", G_CALLBACK(position_overlay_cb), ud); gtk_widget_show(blender); #else // Set up compositing for hud blender = ghb_compositor_new(); gtk_container_add(GTK_CONTAINER(preview_box), blender); ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), draw, 1, 1); ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), hud, 2, .85); gtk_widget_show(blender); #endif // Redirect stderr to the activity window ghb_preview_init(ud); IoRedirect(ud); ghb_log( "%s - %s - %s", HB_PROJECT_TITLE, HB_PROJECT_BUILD_TITLE, HB_PROJECT_URL_WEBSITE ); ghb_init_dep_map(); // Need to connect x264_options textview buffer to the changed signal // since it can't be done automatically GtkTextView *textview; GtkTextBuffer *buffer; textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "x264Option")); buffer = gtk_text_view_get_buffer(textview); g_signal_connect(buffer, "changed", (GCallback)x264_entry_changed_cb, ud); textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "VideoOptionExtra")); buffer = gtk_text_view_get_buffer(textview); g_signal_connect(buffer, "changed", (GCallback)video_option_changed_cb, ud); textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "MetaLongDescription")); buffer = gtk_text_view_get_buffer(textview); g_signal_connect(buffer, "changed", (GCallback)plot_changed_cb, ud); ghb_combo_init(ud); g_debug("ud %p\n", ud); g_debug("ud->builder %p\n", ud->builder); bind_audio_tree_model(ud); bind_subtitle_tree_model(ud); bind_presets_tree_model(ud); bind_queue_tree_model(ud); bind_chapter_tree_model(ud); // Connect up the signals to their callbacks // I wrote my own connector so that I could pass user data // to the callbacks. Builder's standard autoconnect doesn't all this. gtk_builder_connect_signals_full(ud->builder, MyConnect, ud); ghb_init_audio_defaults_ui(ud); ghb_init_subtitle_defaults_ui(ud); // Parsing x264 options "" initializes x264 widgets to proper defaults ghb_x264_init(ud); // Load prefs before presets. Some preset defaults may depend // on preference settings. // First load default values ghb_settings_init(ud->prefs, "Preferences"); ghb_settings_init(ud->globals, "Globals"); ghb_settings_init(ud->settings, "Initialization"); ghb_settings_init(ud->settings, "OneTimeInitialization"); // Load user preferences file ghb_prefs_load(ud); // Store user preferences into ud->prefs ghb_prefs_to_settings(ud->prefs); int logLevel = ghb_dict_get_int(ud->prefs, "LoggingLevel"); ghb_backend_init(logLevel); // Load the presets files ghb_presets_load(ud); // Note that ghb_preset_to_settings(ud->settings) is called when // the default preset is selected. ghb_settings_to_ui(ud, ud->globals); ghb_settings_to_ui(ud, ud->prefs); // Note that ghb_settings_to_ui(ud->settings) happens when initial // empty title is initialized. if (ghb_dict_get_bool(ud->prefs, "hbfd")) { ghb_hbfd(ud, TRUE); } const gchar *source = ghb_dict_get_string(ud->prefs, "default_source"); ghb_dvd_set_current(source, ud); // Populate the presets tree view ghb_presets_list_init(ud, NULL); // Get the first preset name if (arg_preset != NULL) { ghb_select_preset(ud->builder, arg_preset); } else { ghb_select_default_preset(ud->builder); } // Grey out widgets that are dependent on a disabled feature ghb_check_all_depencencies(ud); if (dvd_device != NULL) { // Source overridden from command line option ghb_dict_set_string(ud->globals, "scan_source", dvd_device); g_idle_add((GSourceFunc)ghb_idle_scan, ud); } else { GhbValue *gval = ghb_dict_get_value(ud->prefs, "default_source"); ghb_dict_set(ud->globals, "scan_source", ghb_value_dup(gval)); } // Reload and check status of the last saved queue g_idle_add((GSourceFunc)ghb_reload_queue, ud); // Start timer for monitoring libhb status, 500ms g_timeout_add(200, ghb_timer_cb, (gpointer)ud); // Add dvd devices to File menu ghb_volname_cache_init(); GHB_THREAD_NEW("Cache Volume Names", (GThreadFunc)ghb_cache_volnames, ud); GtkWidget *ghb_window = GHB_WIDGET(ud->builder, "hb_window"); gint window_width, window_height; GdkGeometry geo = { -1, -1, 1920, 768, -1, -1, 10, 10, 0, 0, GDK_GRAVITY_NORTH_WEST }; GdkWindowHints geo_mask; geo_mask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_BASE_SIZE; gtk_window_set_geometry_hints(GTK_WINDOW(ghb_window), ghb_window, &geo, geo_mask); window_width = ghb_dict_get_int(ud->prefs, "window_width"); window_height = ghb_dict_get_int(ud->prefs, "window_height"); /* * Filter objects in GtkBuilder xml * Unfortunately, GtkFilter is poorly supported by GtkBuilder, * so a lot of the setup must happen in code. SourceFilterAll SourceFilterVideo SourceFilterTS SourceFilterMPG SourceFilterEVO SourceFilterVOB SourceFilterMKV SourceFilterMP4 SourceFilterAVI SourceFilterMOV SourceFilterOGG SourceFilterFLV SourceFilterWMV */ // Add filters to source chooser GtkFileFilter *filter; GtkFileChooser *chooser; chooser = GTK_FILE_CHOOSER(GHB_WIDGET(ud->builder, "source_dialog")); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAll")); gtk_file_filter_set_name(filter, _("All")); gtk_file_filter_add_pattern(filter, "*"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterVideo")); gtk_file_filter_set_name(filter, _("Video")); gtk_file_filter_add_mime_type(filter, "video/*"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterTS")); gtk_file_filter_set_name(filter, "TS"); gtk_file_filter_add_pattern(filter, "*.ts"); gtk_file_filter_add_pattern(filter, "*.TS"); gtk_file_filter_add_pattern(filter, "*.m2ts"); gtk_file_filter_add_pattern(filter, "*.M2TS"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMPG")); gtk_file_filter_set_name(filter, "MPG"); gtk_file_filter_add_pattern(filter, "*.mpg"); gtk_file_filter_add_pattern(filter, "*.MPG"); gtk_file_filter_add_pattern(filter, "*.mepg"); gtk_file_filter_add_pattern(filter, "*.MEPG"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterEVO")); gtk_file_filter_set_name(filter, "EVO"); gtk_file_filter_add_pattern(filter, "*.evo"); gtk_file_filter_add_pattern(filter, "*.EVO"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterVOB")); gtk_file_filter_set_name(filter, "VOB"); gtk_file_filter_add_pattern(filter, "*.vob"); gtk_file_filter_add_pattern(filter, "*.VOB"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMKV")); gtk_file_filter_set_name(filter, "MKV"); gtk_file_filter_add_pattern(filter, "*.mkv"); gtk_file_filter_add_pattern(filter, "*.MKV"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMP4")); gtk_file_filter_set_name(filter, "MP4"); gtk_file_filter_add_pattern(filter, "*.mp4"); gtk_file_filter_add_pattern(filter, "*.MP4"); gtk_file_filter_add_pattern(filter, "*.m4v"); gtk_file_filter_add_pattern(filter, "*.M4V"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMOV")); gtk_file_filter_set_name(filter, "MOV"); gtk_file_filter_add_pattern(filter, "*.mov"); gtk_file_filter_add_pattern(filter, "*.MOV"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAVI")); gtk_file_filter_set_name(filter, "AVI"); gtk_file_filter_add_pattern(filter, "*.avi"); gtk_file_filter_add_pattern(filter, "*.AVI"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterOGG")); gtk_file_filter_set_name(filter, "OGG"); gtk_file_filter_add_pattern(filter, "*.ogg"); gtk_file_filter_add_pattern(filter, "*.OGG"); gtk_file_filter_add_pattern(filter, "*.ogv"); gtk_file_filter_add_pattern(filter, "*.OGV"); gtk_file_filter_add_pattern(filter, "*.ogm"); gtk_file_filter_add_pattern(filter, "*.OGM"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterFLV")); gtk_file_filter_set_name(filter, "FLV"); gtk_file_filter_add_pattern(filter, "*.flv"); gtk_file_filter_add_pattern(filter, "*.FLV"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterWMV")); gtk_file_filter_set_name(filter, "WMV"); gtk_file_filter_add_pattern(filter, "*.wmv"); gtk_file_filter_add_pattern(filter, "*.WMV"); gtk_file_chooser_add_filter(chooser, filter); // Gtk has a really stupid bug. If the file chooser is showing // hidden files AND there is no filter set, it will not select // the filename when gtk_file_chooser_set_filename is called. // So add a completely unnessary filter to prevent this behavior. filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAll")); gtk_file_chooser_set_filter(chooser, filter); PangoFontDescription *font_desc; font_desc = pango_font_description_from_string("monospace 10"); textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "activity_view")); gtk_widget_override_font(GTK_WIDGET(textview), font_desc); pango_font_description_free(font_desc); // Grrrr! Gtk developers !!!hard coded!!! the width of the // radio buttons in GtkStackSwitcher to 100!!! // // Thankfully, GtkStackSwitcher is a regular container object // and we can access the buttons to change their width. GList *stack_switcher_children, *link; GtkContainer * stack_switcher = GTK_CONTAINER( GHB_WIDGET(ud->builder, "SettingsStackSwitcher")); link = stack_switcher_children = gtk_container_get_children(stack_switcher); while (link != NULL) { GtkWidget *widget = link->data; gtk_widget_set_size_request(widget, -1, -1); gtk_widget_set_hexpand(widget, TRUE); gtk_widget_set_halign(widget, GTK_ALIGN_FILL); link = link->next; } g_list_free(stack_switcher_children); gtk_window_resize(GTK_WINDOW(ghb_window), window_width, window_height); gtk_widget_show(ghb_window); // Everything should be go-to-go. Lets rock! gtk_main(); ghb_backend_close(); ghb_value_free(&ud->queue); ghb_value_free(&ud->settings_array); ghb_value_free(&ud->prefs); ghb_value_free(&ud->globals); ghb_value_free(&ud->x264_priv); g_io_channel_unref(ud->activity_log); ghb_settings_close(); ghb_resource_free(); #if !defined(_WIN32) notify_uninit(); #endif g_object_unref(ud->builder); g_free(ud->current_dvd_device); g_free(ud); return 0; }
static void gth_media_viewer_page_real_activate (GthViewerPage *base, GthBrowser *browser) { GthMediaViewerPage *self; gboolean rtl; if (! gstreamer_init ()) return; self = (GthMediaViewerPage*) base; self->priv->browser = browser; g_action_map_add_action_entries (G_ACTION_MAP (browser), actions, G_N_ELEMENTS (actions), browser); self->priv->screenshot_button = gth_browser_add_header_bar_button (browser, GTH_BROWSER_HEADER_SECTION_VIEWER_VIEW, "camera-photo-symbolic", _("Take a screenshot"), "win.video-screenshot", NULL); rtl = gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL; /* video area */ self->priv->area = gtk_drawing_area_new (); /* do not use the rgba visual on the drawing area */ { GdkVisual *visual; visual = gdk_screen_get_system_visual (gtk_widget_get_screen (GTK_WIDGET (self->priv->area))); if (visual != NULL) gtk_widget_set_visual (GTK_WIDGET (self->priv->area), visual); } gtk_widget_set_double_buffered (self->priv->area, FALSE); gtk_widget_add_events (self->priv->area, (gtk_widget_get_events (self->priv->area) | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_SCROLL_MASK)); gtk_widget_set_can_focus (self->priv->area, TRUE); gtk_widget_show (self->priv->area); g_signal_connect (G_OBJECT (self->priv->area), "realize", G_CALLBACK (video_area_realize_cb), self); g_signal_connect (G_OBJECT (self->priv->area), "unrealize", G_CALLBACK (video_area_unrealize_cb), self); g_signal_connect (G_OBJECT (self->priv->area), "draw", G_CALLBACK (video_area_draw_cb), self); g_signal_connect (G_OBJECT (self->priv->area), "button_press_event", G_CALLBACK (video_area_button_press_cb), self); g_signal_connect (G_OBJECT (self->priv->area), "popup-menu", G_CALLBACK (video_area_popup_menu_cb), self); g_signal_connect (G_OBJECT (self->priv->area), "scroll_event", G_CALLBACK (video_area_scroll_event_cb), self); g_signal_connect (G_OBJECT (self->priv->area), "key_press_event", G_CALLBACK (video_area_key_press_cb), self); /* mediabar */ self->priv->builder = _gtk_builder_new_from_file ("mediabar.ui", "gstreamer_tools"); self->priv->mediabar = GET_WIDGET ("mediabar"); gtk_widget_set_halign (self->priv->mediabar, GTK_ALIGN_FILL); gtk_widget_set_valign (self->priv->mediabar, GTK_ALIGN_END); gtk_image_set_from_icon_name (GTK_IMAGE (GET_WIDGET ("play_slower_image")), rtl ? "media-seek-backward-rtl-symbolic" : "media-seek-backward-symbolic", GTK_ICON_SIZE_MENU); gtk_image_set_from_icon_name (GTK_IMAGE (GET_WIDGET ("play_faster_image")), rtl ? "media-seek-forward-rtl-symbolic" : "media-seek-forward-symbolic", GTK_ICON_SIZE_MENU); g_signal_connect (GET_WIDGET ("volume_adjustment"), "value-changed", G_CALLBACK (volume_value_changed_cb), self); g_signal_connect (GET_WIDGET ("position_adjustment"), "value-changed", G_CALLBACK (position_value_changed_cb), self); g_signal_connect (GET_WIDGET ("play_button"), "clicked", G_CALLBACK (play_button_clicked_cb), self); g_signal_connect (GET_WIDGET ("play_slower_button"), "clicked", G_CALLBACK (play_slower_button_clicked_cb), self); g_signal_connect (GET_WIDGET ("play_faster_button"), "clicked", G_CALLBACK (play_faster_button_clicked_cb), self); self->priv->mediabar_revealer = gtk_revealer_new (); gtk_revealer_set_transition_type (GTK_REVEALER (self->priv->mediabar_revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP); gtk_widget_set_halign (self->priv->mediabar_revealer, GTK_ALIGN_FILL); gtk_widget_set_valign (self->priv->mediabar_revealer, GTK_ALIGN_END); gtk_widget_show (self->priv->mediabar_revealer); gtk_container_add (GTK_CONTAINER (self->priv->mediabar_revealer), self->priv->mediabar); self->priv->area_box = gtk_overlay_new (); gtk_container_add (GTK_CONTAINER (self->priv->area_box), self->priv->area); gtk_overlay_add_overlay (GTK_OVERLAY (self->priv->area_box), self->priv->mediabar_revealer); gtk_widget_show (self->priv->area_box); gth_browser_set_viewer_widget (browser, self->priv->area_box); gtk_widget_realize (self->priv->area); gth_browser_register_viewer_control (self->priv->browser, self->priv->mediabar); gth_viewer_page_focus (GTH_VIEWER_PAGE (self)); }
GtkWidget * create_videobox(entry * argEntry) { GtkWidget * top; GtkWidget * box; GtkWidget * title; GtkWidget * author; GtkWidget * duration; GtkWidget * thumboverlay; /*GTKoverlay to overlay author and duration over the image thumb.*/ GtkWidget * thumb; GdkRGBA * bgcolor = NULL; uint8_t colorret =0; if(argEntry == (entry *) NULL) return (GtkWidget *) NULL; //construction top = gtk_event_box_new(); box = gtk_box_new(GTK_ORIENTATION_VERTICAL,0); get_thumb_filename(argEntry); thumb = gtk_image_new_from_file(argEntry->fields[THUMBLOC]); title = gtk_label_new(argEntry->fields[TITLE]); author = gtk_label_new(argEntry->fields[AUTHOR]); duration = gtk_label_new(argEntry->fields[DURATION]); thumboverlay = gtk_overlay_new(); gtk_label_set_ellipsize(GTK_LABEL(title),PANGO_ELLIPSIZE_END); gtk_label_set_ellipsize(GTK_LABEL(author),PANGO_ELLIPSIZE_END); gtk_label_set_line_wrap(GTK_LABEL(title),gtk_true()); gtk_widget_set_tooltip_text(title,argEntry->fields[TITLE]); gtk_widget_set_size_request(thumboverlay,120,20); gtk_widget_set_size_request(top,ENTRYWIDTH,ENTRYHEIGHT); gtk_widget_set_valign(author,GTK_ALIGN_START); gtk_widget_set_halign(author,GTK_ALIGN_START); gtk_widget_set_valign(duration,GTK_ALIGN_END); gtk_widget_set_halign(duration,GTK_ALIGN_END); //Adding widgets gtk_container_add(GTK_CONTAINER(thumboverlay), thumb); gtk_container_add(GTK_CONTAINER(top), box); gtk_overlay_add_overlay(GTK_OVERLAY(thumboverlay),author); gtk_overlay_add_overlay(GTK_OVERLAY(thumboverlay),duration); gtk_box_set_homogeneous(GTK_BOX(box),FALSE); gtk_box_pack_start(GTK_BOX(box),title,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(box),thumboverlay,FALSE,FALSE,0); //Color bgcolor = get_bgcolor(argEntry->fields[AUTHOR]); colorret = adjust_titlecolor(bgcolor); gtk_widget_override_color(title,GTK_STATE_FLAG_NORMAL,RGBARRAY[colorret]); gtk_widget_override_background_color(top,GTK_STATE_FLAG_NORMAL,bgcolor); free(bgcolor); // gtk_widget_add_events(thumb, GDK_BUTTON_MOTION_MASK); g_signal_connect(top,"button-press-event",G_CALLBACK(get_ytstream),argEntry->fields[ID]); gtk_widget_override_background_color(thumboverlay,GTK_STATE_FLAG_NORMAL,&BLACK); gtk_widget_override_color(author,GTK_STATE_FLAG_NORMAL,&WHITE); gtk_widget_override_color(duration,GTK_STATE_FLAG_NORMAL,&WHITE); gtk_widget_show_all(top); return top; }
/** * @brief * @param ui The GstSwitchUI instance. * @memberof GstSwitchUI */ static void gst_switch_ui_init (GstSwitchUI * ui) { GtkWidget *main_box, *right_box; GtkWidget *scrollwin; GtkWidget *overlay; GtkStyleContext *style; GdkDisplay *display; GdkScreen *screen; GError *error = NULL; g_mutex_init (&ui->audio_lock); g_mutex_init (&ui->compose_lock); g_mutex_init (&ui->select_lock); g_mutex_init (&ui->faces_lock); g_mutex_init (&ui->tracking_lock); display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); ui->css = gtk_css_provider_new (); gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (ui->css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); ui->window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (ui->window), 640, 480); gtk_window_set_title (GTK_WINDOW (ui->window), "GstSwitch"); g_signal_connect (G_OBJECT (ui->window), "key-press-event", G_CALLBACK (gst_switch_ui_key_event), ui); main_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5); right_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); //gtk_widget_set_hexpand (right_box, TRUE); //gtk_widget_set_vexpand (right_box, TRUE); ui->preview_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); gtk_widget_set_name (ui->preview_box, "previews"); gtk_widget_set_size_request (ui->preview_box, 120, -1); gtk_widget_set_vexpand (ui->preview_box, TRUE); overlay = gtk_overlay_new (); gtk_widget_set_hexpand (overlay, TRUE); gtk_widget_set_vexpand (overlay, TRUE); ui->compose_view = gtk_drawing_area_new (); gtk_widget_set_name (ui->compose_view, "compose"); gtk_widget_set_double_buffered (ui->compose_view, FALSE); gtk_widget_set_hexpand (ui->compose_view, TRUE); gtk_widget_set_vexpand (ui->compose_view, TRUE); gtk_widget_set_events (ui->compose_view, GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); /* g_signal_connect (ui->compose_view, "draw", G_CALLBACK (gst_switch_ui_compose_draw), ui); */ g_signal_connect (ui->compose_view, "key-press-event", G_CALLBACK (gst_switch_ui_compose_key_event), ui); g_signal_connect (ui->compose_view, "motion-notify-event", G_CALLBACK (gst_switch_ui_compose_view_motion), ui); g_signal_connect (ui->compose_view, "button-press-event", G_CALLBACK (gst_switch_ui_compose_view_press), ui); ui->compose_overlay = gtk_fixed_new (); style = gtk_widget_get_style_context (ui->compose_overlay); gtk_style_context_add_class (style, "compose"); gtk_widget_set_halign (ui->compose_overlay, GTK_ALIGN_START); gtk_widget_set_valign (ui->compose_overlay, GTK_ALIGN_START); //gtk_fixed_put (GTK_FIXED (ui->compose_overlay), w, 5, 5); ui->status = gtk_label_new (NULL); gtk_widget_set_hexpand (ui->status, TRUE); gtk_misc_set_alignment (GTK_MISC (ui->status), 1.0, 0); scrollwin = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_widget_set_size_request (scrollwin, 130, -1); gtk_widget_set_vexpand (scrollwin, TRUE); gtk_container_add (GTK_CONTAINER (scrollwin), ui->preview_box); gtk_container_add (GTK_CONTAINER (overlay), ui->compose_view); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), ui->compose_overlay); gtk_box_pack_start (GTK_BOX (right_box), overlay, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (right_box), ui->status, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (main_box), scrollwin, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (main_box), right_box, TRUE, TRUE, 0); gtk_container_add (GTK_CONTAINER (ui->window), main_box); gtk_container_set_border_width (GTK_CONTAINER (ui->window), 5); g_signal_connect (G_OBJECT (ui->window), "delete-event", G_CALLBACK (gst_switch_ui_window_closed), ui); gtk_css_provider_load_from_data (ui->css, gst_switch_ui_css, -1, &error); g_assert_no_error (error); /* gtk_widget_show_all (ui->window); gtk_widget_realize (ui->window); */ }
GtkWidget * do_overlay (GtkWidget *do_widget) { static GtkWidget *window = NULL; if (!window) { GtkWidget *overlay; GtkWidget *grid; GtkWidget *button; GtkWidget *vbox; GtkWidget *label; GtkWidget *entry; int i, j; char *text; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 500, 510); gtk_window_set_title (GTK_WINDOW (window), "Interactive Overlay"); overlay = gtk_overlay_new (); grid = gtk_grid_new (); gtk_container_add (GTK_CONTAINER (overlay), grid); entry = gtk_entry_new (); for (j = 0; j < 5; j++) { for (i = 0; i < 5; i++) { text = g_strdup_printf ("%d", 5*j + i); button = gtk_button_new_with_label (text); g_free (text); gtk_widget_set_hexpand (button, TRUE); gtk_widget_set_vexpand (button, TRUE); g_signal_connect (button, "clicked", G_CALLBACK (do_number), entry); gtk_grid_attach (GTK_GRID (grid), button, i, j, 1, 1); } } vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), vbox); gtk_overlay_set_overlay_pass_through (GTK_OVERLAY (overlay), vbox, TRUE); gtk_widget_set_halign (vbox, GTK_ALIGN_CENTER); gtk_widget_set_valign (vbox, GTK_ALIGN_CENTER); label = gtk_label_new ("<span foreground='blue' weight='ultrabold' font='40'>Numbers</span>"); gtk_label_set_use_markup (GTK_LABEL (label), TRUE); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 8); gtk_entry_set_placeholder_text (GTK_ENTRY (entry), "Your Lucky Number"); gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 8); gtk_container_add (GTK_CONTAINER (window), overlay); g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window); gtk_widget_show_all (overlay); } if (!gtk_widget_get_visible (window)) gtk_widget_show (window); else gtk_widget_destroy (window); return window; }