[gtk/wip/otte/puzzle] puzzle: Use plain labels



commit ad246d8a28008084bd2f600c53286701b3f6fd12
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jun 7 13:06:07 2018 -0400

    puzzle: Use plain labels
    
    The previous code looked cool in the UI, but was too much
    of a hack in the code.

 demos/gtk-demo/sliding_puzzle.c | 174 +---------------------------------------
 1 file changed, 2 insertions(+), 172 deletions(-)
---
diff --git a/demos/gtk-demo/sliding_puzzle.c b/demos/gtk-demo/sliding_puzzle.c
index 09671024dc..f21a84b8f1 100644
--- a/demos/gtk-demo/sliding_puzzle.c
+++ b/demos/gtk-demo/sliding_puzzle.c
@@ -11,166 +11,6 @@
 #include "puzzlepiece.h"
 #include "paintable.h"
 
-#define ICON_TYPE_PAINTABLE (icon_paintable_get_type ())
-
-G_DECLARE_FINAL_TYPE (IconPaintable, icon_paintable, ICON, PAINTABLE, GObject)
-
-GdkPaintable *  icon_paintable_new                  (GdkPaintable *paintable,
-                                                     double        height);
-
-struct _IconPaintable
-{
-  GObject parent_instance;
-
-  GdkPaintable *paintable;
-  double height;
-  double scale_factor;
-};
-
-struct _IconPaintableClass
-{
-  GObjectClass parent_class;
-};
-
-
-static void
-icon_paintable_paintable_snapshot (GdkPaintable *paintable,
-                                   GdkSnapshot  *snapshot,
-                                   double        width,
-                                   double        height)
-{
-  IconPaintable *self = ICON_PAINTABLE (paintable);
-
-  if (self->scale_factor == 1.0)
-    {
-      gdk_paintable_snapshot (self->paintable, snapshot, width, height);
-    }
-  else
-    {
-      graphene_matrix_t scale_matrix;
-
-      graphene_matrix_init_scale (&scale_matrix, 1.0 / self->scale_factor, 1.0 / self->scale_factor, 1.0);
-      gtk_snapshot_push_transform (snapshot, &scale_matrix);
-      gdk_paintable_snapshot (self->paintable,
-                              snapshot,
-                              width * self->scale_factor,
-                              height * self->scale_factor);
-      gtk_snapshot_pop (snapshot);
-    }
-}
-
-static GdkPaintable *
-icon_paintable_paintable_get_current_image (GdkPaintable *paintable)
-{
-  IconPaintable *self = ICON_PAINTABLE (paintable);
-  GdkPaintable *current_paintable, *current_self;
-
-  current_paintable = gdk_paintable_get_current_image (self->paintable);
-  current_self = icon_paintable_new (current_paintable, self->height);
-  g_object_unref (current_paintable);
-
-  return current_self;
-}
-
-static GdkPaintableFlags
-icon_paintable_paintable_get_flags (GdkPaintable *paintable)
-{
-  IconPaintable *self = ICON_PAINTABLE (paintable);
-
-  return gdk_paintable_get_flags (self->paintable);
-}
-
-static int
-icon_paintable_paintable_get_intrinsic_width (GdkPaintable *paintable)
-{
-  IconPaintable *self = ICON_PAINTABLE (paintable);
-
-  return gdk_paintable_get_intrinsic_width (self->paintable) / self->scale_factor;
-}
-
-static int
-icon_paintable_paintable_get_intrinsic_height (GdkPaintable *paintable)
-{
-  IconPaintable *self = ICON_PAINTABLE (paintable);
-
-  return gdk_paintable_get_intrinsic_height (self->paintable) / self->scale_factor;
-}
-
-static double icon_paintable_paintable_get_intrinsic_aspect_ratio (GdkPaintable *paintable)
-{
-  IconPaintable *self = ICON_PAINTABLE (paintable);
-
-  return gdk_paintable_get_intrinsic_aspect_ratio (self->paintable);
-};
-
-static void
-icon_paintable_paintable_init (GdkPaintableInterface *iface)
-{
-  iface->snapshot = icon_paintable_paintable_snapshot;
-  iface->get_current_image = icon_paintable_paintable_get_current_image;
-  iface->get_flags = icon_paintable_paintable_get_flags;
-  iface->get_intrinsic_width = icon_paintable_paintable_get_intrinsic_width;
-  iface->get_intrinsic_height = icon_paintable_paintable_get_intrinsic_height;
-  iface->get_intrinsic_aspect_ratio = icon_paintable_paintable_get_intrinsic_aspect_ratio;
-}
-
-G_DEFINE_TYPE_EXTENDED (IconPaintable, icon_paintable, G_TYPE_OBJECT, 0,
-                        G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE,
-                                               icon_paintable_paintable_init))
-
-static void
-icon_paintable_dispose (GObject *object)
-{
-  IconPaintable *self = ICON_PAINTABLE (object);
-
-  if (self->paintable)
-    {
-      g_signal_handlers_disconnect_by_func (self->paintable, gdk_paintable_invalidate_contents, self);
-      g_signal_handlers_disconnect_by_func (self->paintable, gdk_paintable_invalidate_size, self);
-      g_clear_object (&self->paintable);
-    }
-
-  G_OBJECT_CLASS (icon_paintable_parent_class)->dispose (object);
-}
-
-static void
-icon_paintable_class_init (IconPaintableClass *klass)
-{
-  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
-  gobject_class->dispose = icon_paintable_dispose;
-}
-
-static void
-icon_paintable_init (IconPaintable *self)
-{
-  self->scale_factor = 1.0;
-}
-
-GdkPaintable *
-icon_paintable_new (GdkPaintable *paintable,
-                    double        height)
-{
-  IconPaintable *self;
-
-  g_return_val_if_fail (GDK_IS_PAINTABLE (paintable), NULL);
-  g_return_val_if_fail (height > 0.0, NULL);
-
-  self = g_object_new (ICON_TYPE_PAINTABLE, NULL);
-
-  self->paintable = g_object_ref (paintable);
-  g_signal_connect_swapped (paintable, "invalidate-contents", G_CALLBACK 
(gdk_paintable_invalidate_contents), self);
-  g_signal_connect_swapped (paintable, "invalidate-size", G_CALLBACK (gdk_paintable_invalidate_size), self);
-  self->height = height;
-  if (gdk_paintable_get_intrinsic_height (paintable) == 0)
-    self->scale_factor = 1.0;
-  else
-    self->scale_factor = gdk_paintable_get_intrinsic_height (paintable) / height;
-
-  return GDK_PAINTABLE (self);
-}
-
-
 static GtkWidget *window = NULL;
 static GtkWidget *frame = NULL;
 static GtkWidget *size_spin = NULL;
@@ -497,21 +337,11 @@ do_sliding_puzzle (GtkWidget *do_widget)
       gtk_grid_set_column_spacing (GTK_GRID (tweaks), 10);
       g_object_set (tweaks, "margin", 10, NULL);
 
-      rose_button = button = gtk_radio_button_new (NULL);
-      image = gtk_image_new_from_paintable (icon_paintable_new (rose, 40));
-      gtk_image_set_can_shrink (GTK_IMAGE (image), TRUE);
-      gtk_widget_set_size_request (image, 40, 40);
-      gtk_container_add (GTK_CONTAINER (button), image);
+      rose_button = button = gtk_radio_button_new_with_label (NULL, "Rose");
       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
       gtk_grid_attach (GTK_GRID (tweaks), button, 0, 0, 1, 1);
 
-      button = gtk_radio_button_new_from_widget (button);
-      image = gtk_image_new_from_paintable (icon_paintable_new (atom, 40));
-      gtk_image_set_can_shrink (GTK_IMAGE (image), TRUE);
-      gtk_widget_set_size_request (image, 40, 40);
-      gtk_container_add (GTK_CONTAINER (button), image);
-      gtk_widget_set_halign (button, GTK_ALIGN_CENTER);
-      gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
+      button = gtk_radio_button_new_with_label_from_widget (button, "Danger");
       gtk_grid_attach (GTK_GRID (tweaks), button, 1, 0, 1, 1);
 
       label = gtk_label_new ("Size");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]