colorplane: Drop the Private struct and padding

This commit is contained in:
Matthias Clasen 2020-07-24 22:56:24 -04:00
parent f2bdb1fb87
commit 0e70ddcab3
2 changed files with 53 additions and 73 deletions

View File

@ -33,8 +33,10 @@
#include "gtkshortcutaction.h"
#include "gtkshortcut.h"
struct _GtkColorPlanePrivate
struct _GtkColorPlane
{
GtkWidget parent_instance;
GtkAdjustment *h_adj;
GtkAdjustment *s_adj;
GtkAdjustment *v_adj;
@ -42,6 +44,11 @@ struct _GtkColorPlanePrivate
GdkTexture *texture;
};
typedef struct
{
GtkWidgetClass parent_class;
} GtkColorPlaneClass;
enum {
PROP_0,
PROP_H_ADJUSTMENT,
@ -49,7 +56,7 @@ enum {
PROP_V_ADJUSTMENT
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkColorPlane, gtk_color_plane, GTK_TYPE_WIDGET)
G_DEFINE_TYPE (GtkColorPlane, gtk_color_plane, GTK_TYPE_WIDGET)
static void
sv_to_xy (GtkColorPlane *plane,
@ -62,8 +69,8 @@ sv_to_xy (GtkColorPlane *plane,
width = gtk_widget_get_width (GTK_WIDGET (plane));
height = gtk_widget_get_height (GTK_WIDGET (plane));
s = gtk_adjustment_get_value (plane->priv->s_adj);
v = gtk_adjustment_get_value (plane->priv->v_adj);
s = gtk_adjustment_get_value (plane->s_adj);
v = gtk_adjustment_get_value (plane->v_adj);
*x = CLAMP (width * v, 0, width - 1);
*y = CLAMP (height * (1 - s), 0, height - 1);
@ -82,7 +89,7 @@ plane_snapshot (GtkWidget *widget,
height = gtk_widget_get_height (widget);
gtk_snapshot_append_texture (snapshot,
plane->priv->texture,
plane->texture,
&GRAPHENE_RECT_INIT (0, 0, width, height));
if (gtk_widget_has_visible_focus (widget))
{
@ -136,7 +143,7 @@ create_texture (GtkColorPlane *plane)
if (width == 0 || height == 0)
return;
g_clear_object (&plane->priv->texture);
g_clear_object (&plane->texture);
stride = width * 4;
@ -144,7 +151,7 @@ create_texture (GtkColorPlane *plane)
if (width > 1 && height > 1)
{
h = gtk_adjustment_get_value (plane->priv->h_adj);
h = gtk_adjustment_get_value (plane->h_adj);
sf = 1.0 / (height - 1);
vf = 1.0 / (width - 1);
for (y = 0; y < height; y++)
@ -168,7 +175,7 @@ create_texture (GtkColorPlane *plane)
}
bytes = g_bytes_new_take (data, height * stride);
plane->priv->texture = gdk_memory_texture_new (width, height,
plane->texture = gdk_memory_texture_new (width, height,
GDK_MEMORY_DEFAULT,
bytes,
stride);
@ -198,9 +205,8 @@ static void
plane_unrealize (GtkWidget *widget)
{
GtkColorPlane *plane = GTK_COLOR_PLANE (widget);
GtkColorPlanePrivate *priv = gtk_color_plane_get_instance_private (plane);
g_clear_object (&priv->texture);
g_clear_object (&plane->texture);
GTK_WIDGET_CLASS (gtk_color_plane_parent_class)->unrealize (widget);
}
@ -238,8 +244,8 @@ update_color (GtkColorPlane *plane,
s = CLAMP (1 - y * (1.0 / gtk_widget_get_height (widget)), 0, 1);
v = CLAMP (x * (1.0 / gtk_widget_get_width (widget)), 0, 1);
gtk_adjustment_set_value (plane->priv->s_adj, s);
gtk_adjustment_set_value (plane->priv->v_adj, v);
gtk_adjustment_set_value (plane->s_adj, s);
gtk_adjustment_set_value (plane->v_adj, v);
gtk_widget_queue_draw (widget);
}
@ -262,8 +268,8 @@ sv_move (GtkColorPlane *plane,
{
double s, v;
s = gtk_adjustment_get_value (plane->priv->s_adj);
v = gtk_adjustment_get_value (plane->priv->v_adj);
s = gtk_adjustment_get_value (plane->s_adj);
v = gtk_adjustment_get_value (plane->v_adj);
if (s + ds > 1)
{
@ -303,8 +309,8 @@ sv_move (GtkColorPlane *plane,
v += dv;
}
gtk_adjustment_set_value (plane->priv->s_adj, s);
gtk_adjustment_set_value (plane->priv->v_adj, v);
gtk_adjustment_set_value (plane->s_adj, s);
gtk_adjustment_set_value (plane->v_adj, v);
return;
error:
@ -405,8 +411,6 @@ gtk_color_plane_init (GtkColorPlane *plane)
GtkShortcutAction *action;
GtkShortcut *shortcut;
plane->priv = gtk_color_plane_get_instance_private (plane);
gtk_widget_set_focusable (GTK_WIDGET (plane), TRUE);
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (plane));
@ -452,11 +456,11 @@ plane_finalize (GObject *object)
{
GtkColorPlane *plane = GTK_COLOR_PLANE (object);
g_clear_object (&plane->priv->texture);
g_clear_object (&plane->texture);
g_clear_object (&plane->priv->h_adj);
g_clear_object (&plane->priv->s_adj);
g_clear_object (&plane->priv->v_adj);
g_clear_object (&plane->h_adj);
g_clear_object (&plane->s_adj);
g_clear_object (&plane->v_adj);
G_OBJECT_CLASS (gtk_color_plane_parent_class)->finalize (object);
}
@ -479,7 +483,7 @@ plane_set_property (GObject *object,
adjustment = g_value_get_object (value);
if (adjustment)
{
plane->priv->h_adj = g_object_ref_sink (adjustment);
plane->h_adj = g_object_ref_sink (adjustment);
g_signal_connect_swapped (adjustment, "value-changed", G_CALLBACK (h_changed), plane);
}
break;
@ -487,7 +491,7 @@ plane_set_property (GObject *object,
adjustment = g_value_get_object (value);
if (adjustment)
{
plane->priv->s_adj = g_object_ref_sink (adjustment);
plane->s_adj = g_object_ref_sink (adjustment);
g_signal_connect_swapped (adjustment, "value-changed", G_CALLBACK (sv_changed), plane);
}
break;
@ -495,7 +499,7 @@ plane_set_property (GObject *object,
adjustment = g_value_get_object (value);
if (adjustment)
{
plane->priv->v_adj = g_object_ref_sink (adjustment);
plane->v_adj = g_object_ref_sink (adjustment);
g_signal_connect_swapped (adjustment, "value-changed", G_CALLBACK (sv_changed), plane);
}
break;

View File

@ -18,40 +18,16 @@
#ifndef __GTK_COLOR_PLANE_H__
#define __GTK_COLOR_PLANE_H__
#include <gtk/gtkdrawingarea.h>
#include <gtk/gtktypes.h>
G_BEGIN_DECLS
#define GTK_TYPE_COLOR_PLANE (gtk_color_plane_get_type ())
#define GTK_COLOR_PLANE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_PLANE, GtkColorPlane))
#define GTK_COLOR_PLANE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COLOR_PLANE, GtkColorPlaneClass))
#define GTK_IS_COLOR_PLANE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_PLANE))
#define GTK_IS_COLOR_PLANE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COLOR_PLANE))
#define GTK_COLOR_PLANE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR_PLANE, GtkColorPlaneClass))
typedef struct _GtkColorPlane GtkColorPlane;
typedef struct _GtkColorPlaneClass GtkColorPlaneClass;
typedef struct _GtkColorPlanePrivate GtkColorPlanePrivate;
struct _GtkColorPlane
{
GtkWidget parent_instance;
GtkColorPlanePrivate *priv;
};
struct _GtkColorPlaneClass
{
GtkWidgetClass parent_class;
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
void (*_gtk_reserved4) (void);
};
GType gtk_color_plane_get_type (void) G_GNUC_CONST;