[gtk+/wip/baedert/gtkimageview: 3/73] gtk3-demo: Add GtkImageView demo
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/baedert/gtkimageview: 3/73] gtk3-demo: Add GtkImageView demo
- Date: Sun, 24 Jan 2016 20:06:42 +0000 (UTC)
commit cddc9acbae870d5e594cc2b0f56efc5830bccb21
Author: Timm Bäder <mail baedert org>
Date: Sun Jul 5 20:18:45 2015 +0200
gtk3-demo: Add GtkImageView demo
demos/gtk-demo/Makefile.am | 3 +-
demos/gtk-demo/demo.gresource.xml | 4 +
demos/gtk-demo/image_view.c | 174 +++++++++++++++++++++++++++
demos/gtk-demo/image_view.ui | 237 +++++++++++++++++++++++++++++++++++++
4 files changed, 417 insertions(+), 1 deletions(-)
---
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am
index bbe91ea..40730f5 100644
--- a/demos/gtk-demo/Makefile.am
+++ b/demos/gtk-demo/Makefile.am
@@ -69,7 +69,8 @@ demos_base = \
theming_style_classes.c \
toolpalette.c \
transparent.c \
- tree_store.c
+ tree_store.c \
+ image_view.c
if OS_UNIX
demos = $(demos_base) pagesetup.c
diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml
index 9ca8dad..8f724f3 100644
--- a/demos/gtk-demo/demo.gresource.xml
+++ b/demos/gtk-demo/demo.gresource.xml
@@ -149,6 +149,7 @@
<file>iconview.c</file>
<file>iconview_edit.c</file>
<file>images.c</file>
+ <file>image_view.c</file>
<file>infobar.c</file>
<file>links.c</file>
<file>listbox.c</file>
@@ -185,6 +186,9 @@
<file>tree_store.c</file>
<file>textmask.c</file>
</gresource>
+ <gresource prefix="/imageview">
+ <file>image_view.ui</file>
+ </gresource>
<gresource prefix="/textview">
<file>floppybuddy.gif</file>
</gresource>
diff --git a/demos/gtk-demo/image_view.c b/demos/gtk-demo/image_view.c
new file mode 100644
index 0000000..0d6f95c
--- /dev/null
+++ b/demos/gtk-demo/image_view.c
@@ -0,0 +1,174 @@
+/* Image View
+ */
+#include <gtk/gtk.h>
+
+GtkWidget *image_view;
+GtkWidget *uri_entry;
+
+void
+generic_cb ()
+{
+ g_message ("Generic");
+}
+
+void
+file_set_cb (GtkFileChooserButton *widget,
+ gpointer user_data)
+{
+ char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
+ GFile *file = g_file_new_for_path (filename);
+ gtk_image_view_load_from_file_async (GTK_IMAGE_VIEW (image_view),
+ file,
+ NULL,
+ generic_cb,
+ NULL);
+}
+
+void
+load_button_cb ()
+{
+ const char *uri = gtk_entry_get_text (GTK_ENTRY (uri_entry));
+ GFile *file = g_file_new_for_uri (uri);
+ gtk_image_view_load_from_file_async (GTK_IMAGE_VIEW (image_view),
+ file,
+ NULL,
+ generic_cb,
+ NULL);
+}
+
+void
+zoom_mode_changed_cb (GtkComboBox *widget,
+ gpointer user_data)
+{
+ const gchar *new_id = gtk_combo_box_get_active_id (widget);
+
+ if (g_strcmp0 (new_id, "fit") == 0)
+ gtk_image_view_set_zoom_mode (GTK_IMAGE_VIEW (image_view),
+ GTK_IMAGE_VIEW_ZOOM_MODE_FIT);
+ else if (g_strcmp0 (new_id, "original") == 0)
+ gtk_image_view_set_zoom_mode (GTK_IMAGE_VIEW (image_view),
+ GTK_IMAGE_VIEW_ZOOM_MODE_ORIGINAL);
+ else
+ g_error (new_id);
+
+}
+
+void
+angle_changed_cb (GtkRange *range,
+ gpointer user_data)
+{
+ double value = gtk_range_get_value (range);
+
+ gtk_image_view_set_angle (GTK_IMAGE_VIEW (image_view), value);
+}
+
+void
+scale_changed_cb (GtkRange *range,
+ gpointer user_data)
+{
+ double value = gtk_range_get_value (range);
+
+ gtk_image_view_set_scale (GTK_IMAGE_VIEW (image_view), value);
+}
+
+void
+rotate_left_clicked_cb ()
+{
+ double current_angle = gtk_image_view_get_angle (GTK_IMAGE_VIEW (image_view));
+
+ gtk_image_view_set_angle (GTK_IMAGE_VIEW (image_view), current_angle - 90);
+}
+
+
+void
+rotate_right_clicked_cb ()
+{
+ double current_angle = gtk_image_view_get_angle (GTK_IMAGE_VIEW (image_view));
+
+ gtk_image_view_set_angle (GTK_IMAGE_VIEW (image_view), current_angle + 90);
+}
+
+void
+scrolled_check_button_active_cb (GObject *source)
+{
+ GtkWidget *parent = gtk_widget_get_parent (image_view);
+
+ if (GTK_IS_SCROLLED_WINDOW (parent))
+ {
+ GtkWidget *grandparent = gtk_widget_get_parent (parent);
+ g_assert (grandparent != NULL);
+ gtk_container_remove (GTK_CONTAINER (grandparent), parent);
+ gtk_container_add (GTK_CONTAINER (grandparent), image_view);
+ gtk_widget_show (image_view);
+ }
+ else
+ {
+ GtkWidget *scroller = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroller),
+ GTK_POLICY_ALWAYS,
+ GTK_POLICY_ALWAYS);
+ gtk_widget_show (scroller);
+ gtk_container_remove (GTK_CONTAINER (parent), image_view);
+ gtk_container_add (GTK_CONTAINER (scroller), image_view);
+ gtk_container_add (GTK_CONTAINER (parent), scroller);
+ }
+}
+
+gchar *
+angle_scale_format_value_cb (GtkScale *scale,
+ double value,
+ gpointer user_data)
+{
+ return g_strdup_printf ("%f°", value);
+}
+
+
+gchar *
+scale_scale_format_value_cb (GtkScale *scale,
+ double value,
+ gpointer user_data)
+{
+ return g_strdup_printf ("%f", value);
+}
+
+
+
+
+GtkWidget *
+do_image_view (GtkWidget *do_widget)
+{
+ GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ GtkBuilder *builder = gtk_builder_new_from_resource ("/imageview/image_view.ui");
+ image_view = GTK_WIDGET (gtk_builder_get_object (builder, "image_view"));
+ uri_entry = GTK_WIDGET (gtk_builder_get_object (builder, "uri_entry"));
+ GtkWidget *box = GTK_WIDGET (gtk_builder_get_object (builder, "box"));
+ GtkWidget *zoom_mode_combo = GTK_WIDGET (gtk_builder_get_object (builder, "zoom_mode_combo"));
+ GtkWidget *snap_angle_button = GTK_WIDGET (gtk_builder_get_object (builder, "snap_angle_check_button"));
+ GtkWidget *header_bar = gtk_header_bar_new ();
+ gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (header_bar), TRUE);
+ gtk_window_set_titlebar (GTK_WINDOW (window), header_bar);
+
+ GtkAdjustment *scale_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "scale_adjustment"));
+ GtkAdjustment *angle_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "angle_adjustment"));
+
+ g_object_bind_property (scale_adjustment, "value", image_view, "scale",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+ g_object_bind_property (image_view, "angle", angle_adjustment, "value",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+ g_object_bind_property (image_view, "snap-angle", snap_angle_button, "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+
+
+ if (gtk_image_view_get_zoom_mode (GTK_IMAGE_VIEW (image_view)) == GTK_IMAGE_VIEW_ZOOM_MODE_FIT)
+ gtk_combo_box_set_active_id (GTK_COMBO_BOX (zoom_mode_combo), "fit");
+ else if (gtk_image_view_get_zoom_mode (GTK_IMAGE_VIEW (image_view)) == GTK_IMAGE_VIEW_ZOOM_MODE_ORIGINAL)
+ gtk_combo_box_set_active_id (GTK_COMBO_BOX (zoom_mode_combo), "original");
+
+ gtk_container_add (GTK_CONTAINER (window), box);
+ gtk_builder_connect_signals (builder, NULL);
+
+ gtk_window_resize (GTK_WINDOW (window), 800, 600);
+ gtk_widget_show_all (window);
+ return window;
+}
diff --git a/demos/gtk-demo/image_view.ui b/demos/gtk-demo/image_view.ui
new file mode 100644
index 0000000..99233c7
--- /dev/null
+++ b/demos/gtk-demo/image_view.ui
@@ -0,0 +1,237 @@
+<?xml version="1.0"?>
+<interface>
+ <object class="GtkAdjustment" id="scale_adjustment">
+ <property name="upper">5</property>
+ <property name="value">1.0</property>
+ <property name="step_increment">0.001</property>
+ </object>
+
+ <object class="GtkAdjustment" id="angle_adjustment">
+ <property name="upper">360</property>
+ <property name="value">0</property>
+ <property name="step_increment">0.1</property>
+ </object>
+
+
+ <object class="GtkBox" id="box">
+ <property name="visible">true</property>
+ <property name="orientation">horizontal</property>
+
+
+ <child>
+ <object class="GtkGrid" id="grid">
+ <property name="visible">true</property>
+ <property name="row_spacing">6</property>
+ <property name="column_spacing">12</property>
+ <property name="margin">6</property>
+
+
+ <child>
+ <object class="GtkEntry" id="uri_entry">
+ <property name="visible">true</property>
+ <property name="placeholder_text">URI</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+
+ <child>
+ <object class="GtkButton" id="load_button">
+ <property name="visible">true</property>
+ <property name="label" translatable="yes">Load</property>
+ <signal name="clicked" handler="load_button_cb" />
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+
+
+ <child>
+ <object class="GtkFileChooserButton">
+ <property name="visible">true</property>
+ <property name="valign">baseline</property>
+ <signal name="file-set" handler="file_set_cb" />
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+
+
+
+
+ <child>
+ <object class="GtkComboBoxText" id="zoom_mode_combo">
+ <property name="visible">true</property>
+ <signal name="changed" handler="zoom_mode_changed_cb" />
+
+ <items>
+ <item id="fit">ZOOM_MODE_FIT</item>
+ <item id="original">ZOOM_MODE_ORIGINAL</item>
+ </items>
+
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+
+
+ <child>
+ <object class="GtkCheckButton" id="scrolled_check_button">
+ <property name="visible">true</property>
+ <property name="label">In ScrolledWindow</property>
+ <signal name="toggled" handler="scrolled_check_button_active_cb" />
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+
+
+
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">true</property>
+ <property name="label" translatable="yes">Angle</property>
+ <property name="margin_top">12</property>
+ <property name="halign">start</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+
+
+ <child>
+ <object class="GtkCheckButton" id="snap_angle_check_button">
+ <property name="visible">true</property>
+ <property name="label" translatable="yes">Snap angle</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">5</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+
+
+ <child>
+ <object class="GtkScale" id="angle_scale">
+ <property name="visible">true</property>
+ <property name="draw_value">true</property>
+ <property name="adjustment">angle_adjustment</property>
+ <signal name="format-value" handler="angle_scale_format_value_cb" />
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">6</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+
+ <child>
+ <object class="GtkBox">
+ <property name="visible">true</property>
+ <property name="orientation">horizontal</property>
+ <property name="halign">center</property>
+ <style>
+ <class name="linked" />
+ </style>
+
+ <child>
+ <object class="GtkButton">
+ <property name="visible">true</property>
+ <signal name="clicked" handler="rotate_left_clicked_cb" />
+ <child>
+ <object class="GtkImage">
+ <property name="visible">true</property>
+ <property name="icon-name">object-rotate-left-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkButton">
+ <property name="visible">true</property>
+ <signal name="clicked" handler="rotate_right_clicked_cb" />
+ <child>
+ <object class="GtkImage">
+ <property name="visible">true</property>
+ <property name="icon-name">object-rotate-right-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
+
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">7</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+
+
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">true</property>
+ <property name="label" translatable="yes">Scale</property>
+ <property name="margin_top">12</property>
+ <property name="halign">start</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">8</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+
+ <child>
+ <object class="GtkScale" id="scale_scale">
+ <property name="visible">true</property>
+ <property name="draw_value">true</property>
+ <property name="adjustment">scale_adjustment</property>
+ <signal name="format-value" handler="scale_scale_format_value_cb" />
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">9</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+
+
+ </object>
+
+ </child>
+
+
+
+
+ <child>
+ <object class="GtkImageView" id="image_view">
+ <property name="visible">true</property>
+ <property name="hexpand">true</property>
+ <property name="vexpand">true</property>
+ </object>
+ </child>
+
+ </object>
+
+
+
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]