[Goodies-commits] r2208 - in ristretto/trunk: . src
Stephan Arts
stephan at xfce.org
Sun Dec 10 10:09:13 CET 2006
Author: stephan
Date: 2006-12-10 09:09:13 +0000 (Sun, 10 Dec 2006)
New Revision: 2208
Modified:
ristretto/trunk/AUTHORS
ristretto/trunk/configure.in.in
ristretto/trunk/src/main.c
ristretto/trunk/src/picture_viewer.c
ristretto/trunk/src/picture_viewer.h
Log:
Changed stuff
Modified: ristretto/trunk/AUTHORS
===================================================================
--- ristretto/trunk/AUTHORS 2006-12-09 04:22:12 UTC (rev 2207)
+++ ristretto/trunk/AUTHORS 2006-12-10 09:09:13 UTC (rev 2208)
@@ -1 +1 @@
-Stephan Arts - psyBSD - <psybsd at gmail.com>
+Stephan Arts - <stephan at xfce.org>
Modified: ristretto/trunk/configure.in.in
===================================================================
--- ristretto/trunk/configure.in.in 2006-12-09 04:22:12 UTC (rev 2207)
+++ ristretto/trunk/configure.in.in 2006-12-10 09:09:13 UTC (rev 2208)
@@ -3,7 +3,7 @@
dnl The Xfce development team. All rights reserved.
dnl
dnl Originally written for Xfce by Benedikt Meurer <benny at xfce.org>
-dnl Modified by Stephan Arts <psybsd at gmail.com>
+dnl Modified by Stephan Arts <stephan at xfce.org>
dnl
dnl ***************************
@@ -24,7 +24,7 @@
AC_COPYRIGHT([Copyright (c) 2006
The Xfce development team. All rights reserved.
-Written for Xfce by Stephan Arts <psybsd at gmail.com>.])
+Written for Xfce by Stephan Arts <stephan at xfce.org>.])
AC_INIT([ristretto], [ristretto_version], [])
AC_PREREQ([2.50])
@@ -111,6 +111,7 @@
XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.2.0])
XDT_CHECK_PACKAGE([GOBJECT], [gobject-2.0], [2.2.0])
+
dnl check for debugging support
XDT_FEATURE_DEBUG
Modified: ristretto/trunk/src/main.c
===================================================================
--- ristretto/trunk/src/main.c 2006-12-09 04:22:12 UTC (rev 2207)
+++ ristretto/trunk/src/main.c 2006-12-10 09:09:13 UTC (rev 2208)
@@ -29,21 +29,13 @@
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
- GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file("test.png", NULL);
-
- GtkWidget *scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
-
GtkWidget *viewer = rstto_picture_viewer_new();
- gtk_container_add(GTK_CONTAINER(scrolledwindow), viewer);
- gtk_container_add(GTK_CONTAINER(window), scrolledwindow);
+ gtk_container_add(GTK_CONTAINER(window), viewer);
- gtk_widget_show_all(window);
- gtk_widget_show_all(viewer);
gtk_widget_set_size_request(window, 400,300);
+ gtk_widget_show_all(window);
- rstto_picture_viewer_set_pixbuf(RSTTO_PICTURE_VIEWER(viewer), pixbuf);
-
gtk_main();
return 0;
}
Modified: ristretto/trunk/src/picture_viewer.c
===================================================================
--- ristretto/trunk/src/picture_viewer.c 2006-12-09 04:22:12 UTC (rev 2207)
+++ ristretto/trunk/src/picture_viewer.c 2006-12-10 09:09:13 UTC (rev 2208)
@@ -16,11 +16,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-/**TODO:
- *
- * Fix viewport-dimension > picture-dimension ratio
- */
-
#include <config.h>
#include <gtk/gtk.h>
@@ -32,10 +27,23 @@
rstto_picture_viewer_class_init(RsttoPictureViewerClass *);
static void
-rstto_picture_viewer_size_alloc(GtkWidget *widget, GtkAllocation*);
+rstto_picture_viewer_size_request(GtkWidget *, GtkRequisition *);
+static void
+rstto_picture_viewer_size_allocate(GtkWidget *, GtkAllocation *);
+static void
+rstto_picture_viewer_realize(GtkWidget *);
+static gboolean
+rstto_picture_viewer_expose(GtkWidget *, GdkEventExpose *);
-static GtkViewportClass *rstto_picture_viewer_parent_class = NULL;
+static void
+rstto_picture_viewer_forall(GtkContainer *, gboolean, GtkCallback, gpointer);
+static void
+rstto_picture_viewer_add(GtkContainer *, GtkWidget *);
+static void
+rstto_picture_viewer_remove(GtkContainer *, GtkWidget *);
+static GtkContainerClass *rstto_parent_class = NULL;
+
GType
rstto_picture_viewer_get_type ()
{
@@ -57,7 +65,7 @@
NULL
};
- rstto_picture_viewer_type = g_type_register_static (GTK_TYPE_VIEWPORT, "RsttoPictureViewer", &rstto_picture_viewer_info, 0);
+ rstto_picture_viewer_type = g_type_register_static (GTK_TYPE_CONTAINER, "RsttoPictureViewer", &rstto_picture_viewer_info, 0);
}
return rstto_picture_viewer_type;
}
@@ -65,75 +73,171 @@
static void
rstto_picture_viewer_init(RsttoPictureViewer *viewer)
{
+ GTK_WIDGET_SET_FLAGS(viewer, GTK_NO_WINDOW);
+ gtk_widget_set_redraw_on_allocate(GTK_WIDGET(viewer), TRUE);
+
viewer->scale = 100;
- viewer->image = gtk_image_new();
+ viewer->src_pixbuf = gdk_pixbuf_new_from_file("test.png", NULL);
+ gint width = gdk_pixbuf_get_width(viewer->src_pixbuf);
+ gint height = gdk_pixbuf_get_height(viewer->src_pixbuf);
- gtk_container_add(GTK_CONTAINER(viewer), viewer->image);
+ GtkAdjustment *h_adjustment = (GtkAdjustment *)gtk_adjustment_new(0, 0, width, width*0.1, width*0.9, 0);
+ GtkAdjustment *v_adjustment = (GtkAdjustment *)gtk_adjustment_new(0, 0, height, height*0.1, height*0.9, 0);
- gtk_widget_show(viewer->image);
+ viewer->h_scrollbar = (GtkHScrollbar *)gtk_hscrollbar_new(h_adjustment);
+ viewer->v_scrollbar = (GtkVScrollbar *)gtk_vscrollbar_new(v_adjustment);
+
+ viewer->dst_pixbuf = NULL;
+
+ gtk_container_add((GtkContainer *)viewer, (GtkWidget *)viewer->h_scrollbar);
+ gtk_container_add((GtkContainer *)viewer, (GtkWidget *)viewer->v_scrollbar);
+
+ gtk_widget_show((GtkWidget *)viewer->h_scrollbar);
+ gtk_widget_show((GtkWidget *)viewer->v_scrollbar);
}
static void
rstto_picture_viewer_class_init(RsttoPictureViewerClass *viewer_class)
{
- GtkWidgetClass *object_class = GTK_WIDGET_CLASS(viewer_class);
+ GtkWidgetClass *widget_class;
+ GtkContainerClass *container_class;
- rstto_picture_viewer_parent_class = &viewer_class->parent_class;
+ widget_class = (GtkWidgetClass*)viewer_class;
+ container_class = (GtkContainerClass*)viewer_class;
- object_class->size_allocate = rstto_picture_viewer_size_alloc;
+ widget_class->realize = rstto_picture_viewer_realize;
+ widget_class->expose_event = rstto_picture_viewer_expose;
+ widget_class->size_request = rstto_picture_viewer_size_request;
+ widget_class->size_allocate = rstto_picture_viewer_size_allocate;
+
+ container_class->add = rstto_picture_viewer_add;
+ container_class->remove = rstto_picture_viewer_remove;
+ container_class->forall = rstto_picture_viewer_forall;
+
+ rstto_parent_class = container_class;
}
static void
-rstto_picture_viewer_size_alloc(GtkWidget *widget, GtkAllocation *alloc)
+rstto_picture_viewer_size_request(GtkWidget *widget, GtkRequisition *requisition)
{
- if(RSTTO_PICTURE_VIEWER(widget)->src_pixbuf)
- {
- RsttoPictureViewer *viewer = RSTTO_PICTURE_VIEWER(widget);
- GtkViewport *viewport = GTK_VIEWPORT(widget);
+ g_debug("size request");
+}
- viewport->hadjustment->page_size = alloc->width;
- viewport->vadjustment->page_size = alloc->height;
- viewport->hadjustment->upper = gdk_pixbuf_get_width(viewer->src_pixbuf)*viewer->scale/100;
- viewport->vadjustment->upper = gdk_pixbuf_get_height(viewer->src_pixbuf)*viewer->scale/100;
- viewport->hadjustment->lower = 0;
- viewport->vadjustment->lower = 0;
+static void
+rstto_picture_viewer_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
+{
+ GtkAllocation child_allocation;
+ g_debug("size allocate: x:%d y:%d w:%d h:%d", allocation->x, allocation->y, allocation->width, allocation->height);
+ RsttoPictureViewer *viewer = RSTTO_PICTURE_VIEWER(widget);
+ gtk_widget_set_child_visible(GTK_WIDGET(viewer->h_scrollbar), TRUE);
+ gtk_widget_set_child_visible(GTK_WIDGET(viewer->v_scrollbar), TRUE);
- if((viewport->vadjustment->value + viewport->vadjustment->page_size) > viewport->vadjustment->upper)
- {
- viewport->vadjustment->value = viewport->vadjustment->upper - viewport->vadjustment->page_size;
- gtk_adjustment_value_changed(viewport->vadjustment);
- }
+ GtkAdjustment *h_adjustment = gtk_range_get_adjustment(GTK_RANGE(viewer->h_scrollbar));
+ h_adjustment->page_size = allocation->width-20;
+ if((h_adjustment->value + h_adjustment->page_size) > h_adjustment->upper)
+ h_adjustment->value = MAX(h_adjustment->upper - h_adjustment->page_size, 0);
+ gtk_range_set_adjustment(GTK_RANGE(viewer->h_scrollbar), h_adjustment);
- if((viewport->hadjustment->value + viewport->hadjustment->page_size) > viewport->hadjustment->upper)
- {
- viewport->hadjustment->value = viewport->hadjustment->upper - viewport->hadjustment->page_size;
- gtk_adjustment_value_changed(viewport->hadjustment);
- }
- gtk_adjustment_changed(viewport->hadjustment);
- gtk_adjustment_changed(viewport->vadjustment);
- }
- gtk_widget_size_allocate(GTK_BIN(widget)->child, alloc);
+ GtkAdjustment *v_adjustment = gtk_range_get_adjustment(GTK_RANGE(viewer->v_scrollbar));
+ v_adjustment->page_size = allocation->height-20;
+ if((v_adjustment->value + v_adjustment->page_size) > v_adjustment->upper)
+ v_adjustment->value = MAX(v_adjustment->upper - v_adjustment->page_size, 0);
+ gtk_range_set_adjustment(GTK_RANGE(viewer->v_scrollbar), v_adjustment);
+
+ GdkPixbuf *tmp = gdk_pixbuf_new_subpixbuf(viewer->src_pixbuf,
+ h_adjustment->value*100/viewer->scale,
+ v_adjustment->value*100/viewer->scale,
+ MIN(h_adjustment->page_size*100/viewer->scale, gdk_pixbuf_get_width(viewer->src_pixbuf)*100/viewer->scale),
+ MIN(v_adjustment->page_size*100/viewer->scale, gdk_pixbuf_get_height(viewer->src_pixbuf)*100/viewer->scale));
+
+ viewer->dst_pixbuf = gdk_pixbuf_scale_simple(tmp, h_adjustment->page_size, v_adjustment->page_size, GDK_INTERP_BILINEAR);
+
+ child_allocation.x = allocation->width-20;
+ child_allocation.y = allocation->y;
+ child_allocation.width=20;
+ child_allocation.height = allocation->height-20;
+ gtk_widget_size_allocate(GTK_WIDGET(viewer->v_scrollbar), &child_allocation);
+
+ child_allocation.x = allocation->x;
+ child_allocation.y = allocation->height-20;
+ child_allocation.width= allocation->width-20;
+ child_allocation.height=20;
+ gtk_widget_size_allocate(GTK_WIDGET(viewer->h_scrollbar), &child_allocation);
}
+static void
+rstto_picture_viewer_realize(GtkWidget *widget)
+{
+ g_debug("realize");
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (RSTTO_IS_PICTURE_VIEWER(widget));
-void
-rstto_picture_viewer_set_pixbuf(RsttoPictureViewer *viewer, GdkPixbuf *pixbuf)
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+
+ GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+
+ attributes.x = widget->allocation.x;
+ attributes.y = widget->allocation.y;
+ attributes.width = widget->allocation.width-20;
+ attributes.height = widget->allocation.height-20;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.event_mask = gtk_widget_get_events (widget) |
+ GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK |
+ GDK_POINTER_MOTION_HINT_MASK;
+ attributes.visual = gtk_widget_get_visual (widget);
+ attributes.colormap = gtk_widget_get_colormap (widget);
+
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+ widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask);
+
+ widget->style = gtk_style_attach (widget->style, widget->window);
+}
+
+static gboolean
+rstto_picture_viewer_expose(GtkWidget *widget, GdkEventExpose *event)
{
- viewer->src_pixbuf = pixbuf;
+ g_debug("expose");
+ gdk_window_clear_area (widget->window, 0, 0, widget->allocation.width-20, widget->allocation.height-20);
+ (* GTK_WIDGET_CLASS (rstto_parent_class)->expose_event) (widget, event);
- gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->image), pixbuf);
+ return FALSE;
+}
- gtk_widget_queue_resize(GTK_WIDGET(viewer));
+static void
+rstto_picture_viewer_forall(GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data)
+{
+ RsttoPictureViewer *viewer = RSTTO_PICTURE_VIEWER(container);
+
+ (*callback)(GTK_WIDGET(viewer->v_scrollbar), callback_data);
+ (*callback)(GTK_WIDGET(viewer->h_scrollbar), callback_data);
}
+static void
+rstto_picture_viewer_add(GtkContainer *container, GtkWidget *child)
+{
+ g_return_if_fail(GTK_IS_WIDGET(child));
+ RsttoPictureViewer *viewer = RSTTO_PICTURE_VIEWER(container);
+
+ gtk_widget_set_parent(child, GTK_WIDGET(viewer));
+}
+
+static void
+rstto_picture_viewer_remove(GtkContainer *container, GtkWidget *child)
+{
+
+}
+
GtkWidget *
rstto_picture_viewer_new()
{
GtkWidget *widget;
- widget = g_object_new(RSTTO_TYPE_PICTURE_VIEWER, "hadjustment", NULL, "vadjustment", NULL, NULL);
+ widget = g_object_new(RSTTO_TYPE_PICTURE_VIEWER, NULL);
return widget;
}
Modified: ristretto/trunk/src/picture_viewer.h
===================================================================
--- ristretto/trunk/src/picture_viewer.h 2006-12-09 04:22:12 UTC (rev 2207)
+++ ristretto/trunk/src/picture_viewer.h 2006-12-10 09:09:13 UTC (rev 2208)
@@ -45,8 +45,9 @@
struct _RsttoPictureViewer
{
- GtkViewport parent;
- GtkWidget *image;
+ GtkContainer parent;
+ GtkHScrollbar *h_scrollbar;
+ GtkVScrollbar *v_scrollbar;
GdkPixbuf *src_pixbuf;
GdkPixbuf *dst_pixbuf; /* The pixbuf which ends up on screen */
gint scale;
@@ -56,7 +57,7 @@
struct _RsttoPictureViewerClass
{
- GtkViewportClass parent_class;
+ GtkContainerClass parent_class;
};
GType rstto_picture_viewer_get_type();
More information about the Goodies-commits
mailing list