Compare commits
6 Commits
css-variab
...
wip/otte/g
Author | SHA1 | Date | |
---|---|---|---|
|
a089de757b | ||
|
436bda7c34 | ||
|
4865635a08 | ||
|
100be5498d | ||
|
31c3a767ee | ||
|
50496fcedb |
@@ -34,6 +34,9 @@
|
||||
<file>cssview.css</file>
|
||||
<file>reset.css</file>
|
||||
</gresource>
|
||||
<gresource prefix="/guadec2018">
|
||||
<file>gtk4_lightning_talks.ui</file>
|
||||
</gresource>
|
||||
<gresource prefix="/theming_style_classes">
|
||||
<file>theming.ui</file>
|
||||
</gresource>
|
||||
@@ -171,6 +174,7 @@
|
||||
<file>fontplane.c</file>
|
||||
<file>gestures.c</file>
|
||||
<file>glarea.c</file>
|
||||
<file>gtk4_lightning_talks.c</file>
|
||||
<file>headerbar.c</file>
|
||||
<file>hypertext.c</file>
|
||||
<file>iconview.c</file>
|
||||
|
87
demos/gtk-demo/gtk4_lightning_talks.c
Normal file
87
demos/gtk-demo/gtk4_lightning_talks.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/* GUADEC 2018/GTK4 lightning talks
|
||||
*
|
||||
* These are the presentation slides for the GUADEC 2018
|
||||
* presentation "GTK4 lightnoing talks."
|
||||
*/
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "paintable.h"
|
||||
|
||||
GtkWidget *slides;
|
||||
|
||||
static GtkWidget *
|
||||
slide_get_nth_child_widget (GtkStack *stack,
|
||||
guint n)
|
||||
{
|
||||
GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (stack));
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < n && child != NULL; i++)
|
||||
{
|
||||
child = gtk_widget_get_next_sibling (child);
|
||||
}
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
static void
|
||||
switch_to_slide (GtkWidget *spinbutton,
|
||||
GtkWidget *stack)
|
||||
{
|
||||
int slide;
|
||||
GtkWidget *child;
|
||||
|
||||
slide = gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinbutton)) - 1;
|
||||
child = slide_get_nth_child_widget (GTK_STACK (stack), slide);
|
||||
gtk_stack_set_visible_child (GTK_STACK (stack), child);
|
||||
}
|
||||
|
||||
static void
|
||||
start_inspector (GtkWidget *button,
|
||||
gpointer unused)
|
||||
{
|
||||
gtk_window_set_interactive_debugging (TRUE);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
do_gtk4_lightning_talks (GtkWidget *do_widget)
|
||||
{
|
||||
static GtkWidget *window;
|
||||
|
||||
if (!window)
|
||||
{
|
||||
GtkWidget *slides;
|
||||
GtkBuilder *builder;
|
||||
|
||||
/* g_type_ensure() hacks */
|
||||
g_object_unref (gtk_nuclear_icon_new (0.0));
|
||||
g_object_unref (gtk_nuclear_animation_new ());
|
||||
g_object_unref (gtk_nuclear_media_stream_new ());
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/guadec2018/gtk4_lightning_talks.ui");
|
||||
gtk_builder_add_callback_symbols (builder,
|
||||
"switch_to_slide", G_CALLBACK (switch_to_slide),
|
||||
"start_inspector", G_CALLBACK (start_inspector),
|
||||
NULL);
|
||||
gtk_builder_connect_signals (builder, NULL);
|
||||
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
|
||||
gtk_window_set_display (GTK_WINDOW (window),
|
||||
gtk_widget_get_display (do_widget));
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||
|
||||
slides = GTK_WIDGET (gtk_builder_get_object (builder, "slides"));
|
||||
slides = slides;
|
||||
|
||||
g_object_unref (builder);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
gtk_widget_show (window);
|
||||
else
|
||||
gtk_widget_destroy (window);
|
||||
|
||||
return window;
|
||||
}
|
1235
demos/gtk-demo/gtk4_lightning_talks.ui
Normal file
1235
demos/gtk-demo/gtk4_lightning_talks.ui
Normal file
File diff suppressed because it is too large
Load Diff
@@ -29,6 +29,7 @@ demos = files([
|
||||
'foreigndrawing.c',
|
||||
'gestures.c',
|
||||
'glarea.c',
|
||||
'gtk4_lightning_talks.c',
|
||||
'headerbar.c',
|
||||
'hypertext.c',
|
||||
'iconview.c',
|
||||
|
@@ -643,8 +643,8 @@ gdk_paintable_new_empty (int intrinsic_width,
|
||||
{
|
||||
GdkEmptyPaintable *result;
|
||||
|
||||
g_return_val_if_fail (intrinsic_width < 0, NULL);
|
||||
g_return_val_if_fail (intrinsic_height < 0, NULL);
|
||||
g_return_val_if_fail (intrinsic_width >= 0, NULL);
|
||||
g_return_val_if_fail (intrinsic_height >= 0, NULL);
|
||||
|
||||
result = g_object_new (GDK_TYPE_EMPTY_PAINTABLE, NULL);
|
||||
|
||||
|
@@ -239,6 +239,7 @@
|
||||
#include <gtk/gtkwidgetpath.h>
|
||||
#include <gtk/gtkwindow.h>
|
||||
#include <gtk/gtkwindowgroup.h>
|
||||
#include <gtk/gtkzoom.h>
|
||||
|
||||
#include <gtk/gtk-autocleanups.h>
|
||||
|
||||
|
@@ -183,7 +183,7 @@ gtk_media_file_init (GtkMediaFile *self)
|
||||
{
|
||||
}
|
||||
|
||||
static GType
|
||||
GType
|
||||
gtk_media_file_get_impl_type (void)
|
||||
{
|
||||
static GType impl_type = G_TYPE_NONE;
|
||||
|
@@ -49,6 +49,9 @@ struct _GtkMediaFileClass
|
||||
void (*_gtk_reserved4) (void);
|
||||
};
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GType gtk_media_file_get_impl_type (void);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkMediaStream * gtk_media_file_new (void);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
|
@@ -3794,26 +3794,33 @@ gtk_widget_get_surface_allocation (GtkWidget *widget,
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_widget_invalidate_paintable_contents (GtkWidget *widget)
|
||||
gtk_widget_update_paintables (GtkWidget *widget)
|
||||
{
|
||||
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
|
||||
GSList *l;
|
||||
|
||||
if (!_gtk_widget_is_drawable (widget))
|
||||
return;
|
||||
|
||||
for (l = priv->paintables; l; l = l->next)
|
||||
gtk_widget_paintable_invalidate_contents (l->data);
|
||||
gtk_widget_paintable_update_image (l->data);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_widget_invalidate_paintable_size (GtkWidget *widget)
|
||||
gtk_widget_push_paintables (GtkWidget *widget)
|
||||
{
|
||||
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
|
||||
GSList *l;
|
||||
|
||||
for (l = priv->paintables; l; l = l->next)
|
||||
gtk_widget_paintable_invalidate_size (l->data);
|
||||
gtk_widget_paintable_push_snapshot_count (l->data);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_widget_pop_paintables (GtkWidget *widget)
|
||||
{
|
||||
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
|
||||
GSList *l;
|
||||
|
||||
for (l = priv->paintables; l; l = l->next)
|
||||
gtk_widget_paintable_pop_snapshot_count (l->data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3842,7 +3849,6 @@ gtk_widget_queue_draw (GtkWidget *widget)
|
||||
|
||||
priv->draw_needed = TRUE;
|
||||
g_clear_pointer (&priv->render_node, gsk_render_node_unref);
|
||||
gtk_widget_invalidate_paintable_contents (widget);
|
||||
if (_gtk_widget_get_has_surface (widget) &&
|
||||
_gtk_widget_get_realized (widget))
|
||||
gdk_surface_queue_expose (gtk_widget_get_surface (widget));
|
||||
@@ -3911,8 +3917,6 @@ gtk_widget_queue_resize_internal (GtkWidget *widget)
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_invalidate_paintable_size (widget);
|
||||
|
||||
if (_gtk_widget_get_visible (widget))
|
||||
{
|
||||
GtkWidget *parent = _gtk_widget_get_parent (widget);
|
||||
@@ -4298,7 +4302,7 @@ gtk_widget_size_allocate (GtkWidget *widget,
|
||||
priv->alloc_needed = FALSE;
|
||||
priv->alloc_needed_on_child = FALSE;
|
||||
|
||||
gtk_widget_invalidate_paintable_size (widget);
|
||||
gtk_widget_update_paintables (widget);
|
||||
|
||||
check_clip:
|
||||
if (size_changed || baseline_changed)
|
||||
@@ -6330,7 +6334,7 @@ _gtk_widget_set_visible_flag (GtkWidget *widget,
|
||||
priv->allocation.height = 0;
|
||||
memset (&priv->allocated_size, 0, sizeof (priv->allocated_size));
|
||||
priv->allocated_size_baseline = 0;
|
||||
gtk_widget_invalidate_paintable_size (widget);
|
||||
gtk_widget_update_paintables (widget);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8606,7 +8610,7 @@ gtk_widget_real_unmap (GtkWidget *widget)
|
||||
gtk_widget_unmap (child);
|
||||
}
|
||||
|
||||
gtk_widget_invalidate_paintable_contents (widget);
|
||||
gtk_widget_update_paintables (widget);
|
||||
|
||||
gtk_widget_unset_state_flags (widget,
|
||||
GTK_STATE_FLAG_PRELIGHT |
|
||||
@@ -13240,6 +13244,8 @@ gtk_widget_snapshot (GtkWidget *widget,
|
||||
{
|
||||
GskRenderNode *render_node;
|
||||
|
||||
gtk_widget_push_paintables (widget);
|
||||
|
||||
render_node = gtk_widget_create_render_node (widget, snapshot);
|
||||
/* This can happen when nested drawing happens and a widget contains itself
|
||||
* or when we replace a clipped area */
|
||||
@@ -13247,6 +13253,9 @@ gtk_widget_snapshot (GtkWidget *widget,
|
||||
priv->render_node = render_node;
|
||||
|
||||
priv->draw_needed = FALSE;
|
||||
|
||||
gtk_widget_pop_paintables (widget);
|
||||
gtk_widget_update_paintables (widget);
|
||||
}
|
||||
|
||||
if (priv->render_node)
|
||||
|
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "gtkintl.h"
|
||||
#include "gtksnapshot.h"
|
||||
#include "gtkrendernodepaintableprivate.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
|
||||
/**
|
||||
@@ -57,10 +58,11 @@ struct _GtkWidgetPaintable
|
||||
GObject parent_instance;
|
||||
|
||||
GtkWidget *widget;
|
||||
guint loop_tracker;
|
||||
guint snapshot_count;
|
||||
|
||||
guint size_invalid : 1;
|
||||
guint contents_invalid : 1;
|
||||
GdkPaintable *current_image; /* the image that we are presenting */
|
||||
GdkPaintable *pending_image; /* the image that we should be presenting */
|
||||
guint pending_update_cb; /* the idle source that updates the valid image to be the new current image */
|
||||
};
|
||||
|
||||
struct _GtkWidgetPaintableClass
|
||||
@@ -84,56 +86,38 @@ gtk_widget_paintable_paintable_snapshot (GdkPaintable *paintable,
|
||||
double height)
|
||||
{
|
||||
GtkWidgetPaintable *self = GTK_WIDGET_PAINTABLE (paintable);
|
||||
graphene_matrix_t transform;
|
||||
|
||||
self->contents_invalid = FALSE;
|
||||
|
||||
if (self->widget == NULL ||
|
||||
!_gtk_widget_is_drawable (self->widget) ||
|
||||
_gtk_widget_get_alloc_needed (self->widget))
|
||||
if (self->snapshot_count > 2)
|
||||
return;
|
||||
else if (self->snapshot_count > 0)
|
||||
{
|
||||
graphene_matrix_t transform;
|
||||
|
||||
if (self->loop_tracker >= 5)
|
||||
return;
|
||||
self->loop_tracker++;
|
||||
gtk_snapshot_push_clip (snapshot,
|
||||
&GRAPHENE_RECT_INIT(0, 0, width, height));
|
||||
graphene_matrix_init_scale (&transform,
|
||||
width / gtk_widget_get_allocated_width (self->widget),
|
||||
height / gtk_widget_get_allocated_height (self->widget),
|
||||
1.0);
|
||||
gtk_snapshot_push_transform (snapshot, &transform);
|
||||
|
||||
/* need to clip because widgets may draw out of bounds */
|
||||
gtk_snapshot_push_clip (snapshot,
|
||||
&GRAPHENE_RECT_INIT(0, 0, width, height));
|
||||
graphene_matrix_init_scale (&transform,
|
||||
width / gtk_widget_get_allocated_width (self->widget),
|
||||
height / gtk_widget_get_allocated_height (self->widget),
|
||||
1.0);
|
||||
gtk_snapshot_push_transform (snapshot, &transform);
|
||||
gtk_widget_snapshot (self->widget, snapshot);
|
||||
|
||||
gtk_widget_snapshot (self->widget, snapshot);
|
||||
|
||||
gtk_snapshot_pop (snapshot);
|
||||
gtk_snapshot_pop (snapshot);
|
||||
|
||||
self->loop_tracker--;
|
||||
gtk_snapshot_pop (snapshot);
|
||||
gtk_snapshot_pop (snapshot);
|
||||
}
|
||||
else
|
||||
{
|
||||
gdk_paintable_snapshot (self->current_image, snapshot, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
static GdkPaintable *
|
||||
gtk_widget_paintable_paintable_get_current_image (GdkPaintable *paintable)
|
||||
{
|
||||
GtkWidgetPaintable *self = GTK_WIDGET_PAINTABLE (paintable);
|
||||
GtkSnapshot *snapshot;
|
||||
int width, height;
|
||||
|
||||
self->contents_invalid = FALSE;
|
||||
self->size_invalid = FALSE;
|
||||
|
||||
width = gdk_paintable_get_intrinsic_width (paintable);
|
||||
height = gdk_paintable_get_intrinsic_width (paintable);
|
||||
if (width == 0 || height == 0)
|
||||
return gdk_paintable_new_empty (width, height);
|
||||
|
||||
snapshot = gtk_snapshot_new ();
|
||||
gdk_paintable_snapshot (GDK_PAINTABLE (self),
|
||||
snapshot,
|
||||
width, height);
|
||||
return gtk_snapshot_free_to_paintable (snapshot, &(graphene_size_t) { width, height });
|
||||
return g_object_ref (self->current_image);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -141,12 +125,7 @@ gtk_widget_paintable_paintable_get_intrinsic_width (GdkPaintable *paintable)
|
||||
{
|
||||
GtkWidgetPaintable *self = GTK_WIDGET_PAINTABLE (paintable);
|
||||
|
||||
self->size_invalid = FALSE;
|
||||
|
||||
if (self->widget == NULL)
|
||||
return 0;
|
||||
|
||||
return gtk_widget_get_allocated_width (self->widget);
|
||||
return gdk_paintable_get_intrinsic_width (self->current_image);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -154,12 +133,7 @@ gtk_widget_paintable_paintable_get_intrinsic_height (GdkPaintable *paintable)
|
||||
{
|
||||
GtkWidgetPaintable *self = GTK_WIDGET_PAINTABLE (paintable);
|
||||
|
||||
self->size_invalid = FALSE;
|
||||
|
||||
if (self->widget == NULL)
|
||||
return 0;
|
||||
|
||||
return gtk_widget_get_allocated_height (self->widget);
|
||||
return gdk_paintable_get_intrinsic_height (self->current_image);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -226,6 +200,16 @@ gtk_widget_paintable_dispose (GObject *object)
|
||||
G_OBJECT_CLASS (gtk_widget_paintable_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_widget_paintable_finalize (GObject *object)
|
||||
{
|
||||
GtkWidgetPaintable *self = GTK_WIDGET_PAINTABLE (object);
|
||||
|
||||
g_object_unref (self->current_image);
|
||||
|
||||
G_OBJECT_CLASS (gtk_widget_paintable_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_widget_paintable_class_init (GtkWidgetPaintableClass *klass)
|
||||
{
|
||||
@@ -234,6 +218,7 @@ gtk_widget_paintable_class_init (GtkWidgetPaintableClass *klass)
|
||||
gobject_class->get_property = gtk_widget_paintable_get_property;
|
||||
gobject_class->set_property = gtk_widget_paintable_set_property;
|
||||
gobject_class->dispose = gtk_widget_paintable_dispose;
|
||||
gobject_class->finalize = gtk_widget_paintable_finalize;
|
||||
|
||||
/**
|
||||
* GtkWidgetPaintable:widget
|
||||
@@ -253,6 +238,7 @@ gtk_widget_paintable_class_init (GtkWidgetPaintableClass *klass)
|
||||
static void
|
||||
gtk_widget_paintable_init (GtkWidgetPaintable *self)
|
||||
{
|
||||
self->current_image = gdk_paintable_new_empty (0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -273,6 +259,22 @@ gtk_widget_paintable_new (GtkWidget *widget)
|
||||
NULL);
|
||||
}
|
||||
|
||||
static GdkPaintable *
|
||||
gtk_widget_paintable_snapshot_widget (GtkWidgetPaintable *self)
|
||||
{
|
||||
graphene_rect_t bounds;
|
||||
|
||||
if (self->widget == NULL)
|
||||
return gdk_paintable_new_empty (0, 0);
|
||||
|
||||
gtk_widget_compute_bounds (self->widget, self->widget, &bounds);
|
||||
|
||||
if (self->widget->priv->render_node == NULL)
|
||||
return gdk_paintable_new_empty (bounds.size.width, bounds.size.height);
|
||||
|
||||
return gtk_render_node_paintable_new (self->widget->priv->render_node, &bounds);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_widget_paintable_get_widget:
|
||||
* @self: a #GtkWidgetPaintable
|
||||
@@ -325,27 +327,77 @@ gtk_widget_paintable_set_widget (GtkWidgetPaintable *self,
|
||||
self);
|
||||
}
|
||||
|
||||
g_object_unref (self->current_image);
|
||||
self->current_image = gtk_widget_paintable_snapshot_widget (self);
|
||||
g_clear_object (&self->pending_image);
|
||||
if (self->pending_update_cb)
|
||||
{
|
||||
g_source_remove (self->pending_update_cb);
|
||||
self->pending_update_cb = 0;
|
||||
}
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_WIDGET]);
|
||||
gdk_paintable_invalidate_size (GDK_PAINTABLE (self));
|
||||
gdk_paintable_invalidate_contents (GDK_PAINTABLE (self));
|
||||
}
|
||||
|
||||
void
|
||||
gtk_widget_paintable_invalidate_size (GtkWidgetPaintable *self)
|
||||
static gboolean
|
||||
gtk_widget_paintable_update_func (gpointer data)
|
||||
{
|
||||
if (self->size_invalid)
|
||||
return;
|
||||
GtkWidgetPaintable *self = data;
|
||||
GdkPaintable *old_image;
|
||||
|
||||
self->size_invalid = TRUE;
|
||||
gdk_paintable_invalidate_size (GDK_PAINTABLE (self));
|
||||
if (self->current_image != self->pending_image)
|
||||
{
|
||||
old_image = self->current_image;
|
||||
self->current_image = self->pending_image;
|
||||
self->pending_image = NULL;
|
||||
self->pending_update_cb = 0;
|
||||
|
||||
if (gdk_paintable_get_intrinsic_width (self->current_image) != gdk_paintable_get_intrinsic_width (old_image) ||
|
||||
gdk_paintable_get_intrinsic_height (self->current_image) != gdk_paintable_get_intrinsic_height (old_image))
|
||||
gdk_paintable_invalidate_size (GDK_PAINTABLE (self));
|
||||
|
||||
g_object_unref (old_image);
|
||||
|
||||
gdk_paintable_invalidate_contents (GDK_PAINTABLE (self));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_clear_object (&self->pending_image);
|
||||
self->pending_update_cb = 0;
|
||||
}
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_widget_paintable_invalidate_contents (GtkWidgetPaintable *self)
|
||||
gtk_widget_paintable_update_image (GtkWidgetPaintable *self)
|
||||
{
|
||||
if (self->contents_invalid)
|
||||
return;
|
||||
GdkPaintable *pending_image;
|
||||
|
||||
self->contents_invalid = TRUE;
|
||||
gdk_paintable_invalidate_contents (GDK_PAINTABLE (self));
|
||||
if (self->pending_update_cb == 0)
|
||||
{
|
||||
self->pending_update_cb = g_idle_add_full (G_PRIORITY_HIGH,
|
||||
gtk_widget_paintable_update_func,
|
||||
self,
|
||||
NULL);
|
||||
}
|
||||
|
||||
pending_image = gtk_widget_paintable_snapshot_widget (self);
|
||||
g_set_object (&self->pending_image, pending_image);
|
||||
g_object_unref (pending_image);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_widget_paintable_push_snapshot_count (GtkWidgetPaintable *self)
|
||||
{
|
||||
self->snapshot_count++;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_widget_paintable_pop_snapshot_count (GtkWidgetPaintable *self)
|
||||
{
|
||||
self->snapshot_count--;
|
||||
}
|
||||
|
||||
|
@@ -23,8 +23,9 @@
|
||||
#include "gtkwidgetpaintable.h"
|
||||
|
||||
|
||||
void gtk_widget_paintable_invalidate_size (GtkWidgetPaintable *self);
|
||||
void gtk_widget_paintable_invalidate_contents (GtkWidgetPaintable *self);
|
||||
void gtk_widget_paintable_update_image (GtkWidgetPaintable *self);
|
||||
|
||||
void gtk_widget_paintable_push_snapshot_count (GtkWidgetPaintable *self);
|
||||
void gtk_widget_paintable_pop_snapshot_count (GtkWidgetPaintable *self);
|
||||
|
||||
#endif /* __GTK_WIDGET_PAINTABLE_PRIVATE_H__ */
|
||||
|
333
gtk/gtkzoom.c
Normal file
333
gtk/gtkzoom.c
Normal file
@@ -0,0 +1,333 @@
|
||||
/*
|
||||
* Copyright © 2018 Benjamin Otte
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkzoom.h"
|
||||
|
||||
#include "gtkintl.h"
|
||||
#include "gtksnapshot.h"
|
||||
|
||||
/**
|
||||
* SECTION:gtkzoom
|
||||
* @title: GtkZoom
|
||||
* @short_description: A widget for zooming
|
||||
* @see_also: #GtkAspectFrame, #GtkMagnifier
|
||||
*
|
||||
* GtkZoom is a widget that zooms its contents to the available size
|
||||
* user a way to control the playback.
|
||||
*/
|
||||
|
||||
struct _GtkZoom
|
||||
{
|
||||
GtkWidget parent_instance;
|
||||
|
||||
GtkWidget *child;
|
||||
double zoom;
|
||||
graphene_point3d_t offset;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_CHILD,
|
||||
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (GtkZoom, gtk_zoom, GTK_TYPE_CONTAINER)
|
||||
|
||||
static GParamSpec *properties[N_PROPS] = { NULL, };
|
||||
|
||||
static GType
|
||||
gtk_zoom_child_type (GtkContainer *container)
|
||||
{
|
||||
GtkZoom *zoom = GTK_ZOOM (container);
|
||||
|
||||
if (!zoom->child)
|
||||
return GTK_TYPE_WIDGET;
|
||||
else
|
||||
return G_TYPE_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_zoom_add (GtkContainer *container,
|
||||
GtkWidget *child)
|
||||
{
|
||||
GtkZoom *zoom = GTK_ZOOM (container);
|
||||
|
||||
if (zoom->child != NULL)
|
||||
{
|
||||
g_warning ("Attempting to add a widget with type %s to a %s, "
|
||||
"but as a GtkZoom subclass a %s can only contain one widget at a time; "
|
||||
"it already contains a widget of type %s",
|
||||
g_type_name (G_OBJECT_TYPE (child)),
|
||||
g_type_name (G_OBJECT_TYPE (zoom)),
|
||||
g_type_name (G_OBJECT_TYPE (zoom)),
|
||||
g_type_name (G_OBJECT_TYPE (zoom->child)));
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_zoom_set_child (zoom, child);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_zoom_remove (GtkContainer *container,
|
||||
GtkWidget *child)
|
||||
{
|
||||
GtkZoom *zoom = GTK_ZOOM (container);
|
||||
|
||||
g_return_if_fail (zoom->child == child);
|
||||
|
||||
gtk_zoom_set_child (zoom, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_zoom_forall (GtkContainer *container,
|
||||
GtkCallback callback,
|
||||
gpointer callback_data)
|
||||
{
|
||||
GtkZoom *zoom = GTK_ZOOM (container);
|
||||
|
||||
if (zoom->child)
|
||||
(* callback) (zoom->child, callback_data);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_zoom_measure (GtkWidget *widget,
|
||||
GtkOrientation orientation,
|
||||
int for_size,
|
||||
int *minimum,
|
||||
int *natural,
|
||||
int *minimum_baseline,
|
||||
int *natural_baseline)
|
||||
{
|
||||
GtkZoom *self = GTK_ZOOM (widget);
|
||||
|
||||
if (self->child)
|
||||
{
|
||||
gtk_widget_measure (self->child,
|
||||
orientation,
|
||||
for_size,
|
||||
minimum, natural,
|
||||
minimum_baseline, natural_baseline);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_zoom_size_allocate (GtkWidget *widget,
|
||||
const GtkAllocation *allocation,
|
||||
int baseline)
|
||||
{
|
||||
GtkZoom *self = GTK_ZOOM (widget);
|
||||
GtkAllocation child_allocation;
|
||||
|
||||
if (self->child == NULL)
|
||||
{
|
||||
self->zoom = 1.0;
|
||||
graphene_point3d_init (&self->offset, 0.0, 0.0, 0.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_measure (self->child, GTK_ORIENTATION_HORIZONTAL, -1, &child_allocation.width, NULL, NULL, NULL);
|
||||
gtk_widget_measure (self->child, GTK_ORIENTATION_VERTICAL, child_allocation.width, &child_allocation.height, NULL, NULL, NULL);
|
||||
self->zoom = MIN ((double) allocation->width / child_allocation.width,
|
||||
(double) allocation->height / child_allocation.height);
|
||||
child_allocation.x = 0;
|
||||
child_allocation.y = 0;
|
||||
gtk_widget_size_allocate (self->child, &child_allocation, -1);
|
||||
graphene_point3d_init (&self->offset,
|
||||
/* use int math here, so we get a pixel offset */
|
||||
(allocation->width - child_allocation.width * self->zoom) / 2,
|
||||
(allocation->height - child_allocation.height * self->zoom) / 2,
|
||||
0.0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_zoom_snapshot (GtkWidget *widget,
|
||||
GtkSnapshot *snapshot)
|
||||
{
|
||||
GtkZoom *self = GTK_ZOOM (widget);
|
||||
|
||||
if (self->child)
|
||||
{
|
||||
graphene_matrix_t transform;
|
||||
|
||||
graphene_matrix_init_scale (&transform, self->zoom, self->zoom, 1.0);
|
||||
graphene_matrix_translate (&transform, &self->offset);
|
||||
|
||||
gtk_snapshot_push_transform (snapshot, &transform);
|
||||
|
||||
gtk_widget_snapshot_child (widget, self->child, snapshot);
|
||||
|
||||
gtk_snapshot_pop (snapshot);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_zoom_dispose (GObject *object)
|
||||
{
|
||||
GtkZoom *self = GTK_ZOOM (object);
|
||||
|
||||
g_clear_pointer (&self->child, gtk_widget_unparent);
|
||||
|
||||
G_OBJECT_CLASS (gtk_zoom_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_zoom_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkZoom *self = GTK_ZOOM (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_CHILD:
|
||||
g_value_set_object (value, self->child);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_zoom_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkZoom *self = GTK_ZOOM (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_CHILD:
|
||||
gtk_zoom_set_child (self, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_zoom_class_init (GtkZoomClass *klass)
|
||||
{
|
||||
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
container_class->add = gtk_zoom_add;
|
||||
container_class->remove = gtk_zoom_remove;
|
||||
container_class->forall = gtk_zoom_forall;
|
||||
container_class->child_type = gtk_zoom_child_type;
|
||||
|
||||
widget_class->measure = gtk_zoom_measure;
|
||||
widget_class->size_allocate = gtk_zoom_size_allocate;
|
||||
widget_class->snapshot = gtk_zoom_snapshot;
|
||||
|
||||
gobject_class->dispose = gtk_zoom_dispose;
|
||||
gobject_class->get_property = gtk_zoom_get_property;
|
||||
gobject_class->set_property = gtk_zoom_set_property;
|
||||
|
||||
/**
|
||||
* GtkZoom:child:
|
||||
*
|
||||
* The displayed widget
|
||||
*/
|
||||
properties[PROP_CHILD] =
|
||||
g_param_spec_object ("child",
|
||||
P_("Child"),
|
||||
P_("The displayed widget"),
|
||||
GTK_TYPE_WIDGET,
|
||||
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (gobject_class, N_PROPS, properties);
|
||||
|
||||
gtk_widget_class_set_css_name (widget_class, I_("zoom"));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_zoom_init (GtkZoom *self)
|
||||
{
|
||||
gtk_widget_set_has_surface (GTK_WIDGET (self), FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_zoom_new:
|
||||
*
|
||||
* Creates a new empty #GtkZoom.
|
||||
*
|
||||
* Returns: a new #GtkZoom
|
||||
**/
|
||||
GtkWidget *
|
||||
gtk_zoom_new (void)
|
||||
{
|
||||
return g_object_new (GTK_TYPE_ZOOM, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_zoom_get_child:
|
||||
* @self: a #GtkZoom
|
||||
*
|
||||
* Gets the child #GtkWidget displayed by @self or %NULL if no child was set.
|
||||
*
|
||||
* Returns: (nullable) (transfer none): The displayed widget
|
||||
**/
|
||||
GtkWidget *
|
||||
gtk_zoom_get_child (GtkZoom *self)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_ZOOM (self), NULL);
|
||||
|
||||
return self->child;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_zoom_set_child:
|
||||
* @self: a #GtkZoom
|
||||
* @child: (allow-none): the #GtkWidget to display
|
||||
*
|
||||
* Makes @self display the given @child.
|
||||
**/
|
||||
void
|
||||
gtk_zoom_set_child (GtkZoom *self,
|
||||
GtkWidget *child)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_ZOOM (self));
|
||||
g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
|
||||
|
||||
if (self->child == child)
|
||||
return;
|
||||
|
||||
g_clear_pointer (&self->child, gtk_widget_unparent);
|
||||
|
||||
if (child)
|
||||
{
|
||||
self->child = child;
|
||||
gtk_widget_set_parent (child, GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CHILD]);
|
||||
}
|
||||
|
54
gtk/gtkzoom.h
Normal file
54
gtk/gtkzoom.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GTK+ Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_ZOOM_H__
|
||||
#define __GTK_ZOOM_H__
|
||||
|
||||
|
||||
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <gtk/gtkcontainer.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_ZOOM (gtk_zoom_get_type ())
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
G_DECLARE_FINAL_TYPE (GtkZoom, gtk_zoom, GTK, ZOOM, GtkContainer)
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidget * gtk_zoom_new (void);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidget * gtk_zoom_get_child (GtkZoom *zoom);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_zoom_set_child (GtkZoom *zoom,
|
||||
GtkWidget *widget);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_ZOOM_H__ */
|
@@ -381,6 +381,7 @@ gtk_public_sources = files([
|
||||
'gtkwidgetpath.c',
|
||||
'gtkwindow.c',
|
||||
'gtkwindowgroup.c',
|
||||
'gtkzoom.c',
|
||||
])
|
||||
|
||||
gtk_private_type_headers = files([
|
||||
@@ -600,6 +601,7 @@ gtk_public_headers = files([
|
||||
'gtkwidgetpath.h',
|
||||
'gtkwindow.h',
|
||||
'gtkwindowgroup.h',
|
||||
'gtkzoom.h',
|
||||
'gtk-a11y.h',
|
||||
'gtk-autocleanups.h',
|
||||
'gtk.h',
|
||||
|
Reference in New Issue
Block a user