gtk: Add GtkTransform

This is a new object (well, boxed type, but I'm calling it object) for
dealing with transform in a more constructive way than graphene_matrix_t
by keeping track of how the transform was created.

This way, reasoning about the transform becomes easier, and we can create
better ways to print it or transition from one transform to another one.

An example of this is that while a 0 degree and a 360degree rotation are
both the identity matrix, doing a transition between the two would cause
a rotation.
This commit is contained in:
Benjamin Otte 2019-02-17 12:54:04 +01:00
parent 70a1233a28
commit 49d83820a2
8 changed files with 1301 additions and 1 deletions

View File

@ -279,8 +279,8 @@
<xi:include href="xml/gtkimcontextsimple.xml" />
<xi:include href="xml/gtkimmulticontext.xml" />
<xi:include href="xml/gtksizegroup.xml" />
<xi:include href="xml/gtktooltip.xml" />
<xi:include href="xml/gtksnapshot.xml" />
<xi:include href="xml/gtktooltip.xml" />
<xi:include href="xml/gtkwidgetpaintable.xml" />
</chapter>
@ -344,6 +344,7 @@
<xi:include href="xml/gtkselection.xml" />
<xi:include href="xml/gtktesting.xml" />
<xi:include href="xml/filesystem.xml" />
<xi:include href="xml/gtktransform.xml" />
</part>
<part id="theming">

View File

@ -5885,6 +5885,38 @@ gtk_mount_operation_get_type
GtkMountOperationPrivate
</SECTION>
<SECTION>
<FILE>tranform</FILE>
<TITLE>3D transformations</TITLE>
GtkTransformType;
GtkTransform;
gtk_transform_ref
gtk_transform_unref
<SUBSECTION>
gtk_transform_print
gtk_transform_to_string
gtk_transform_to_matrix
<SUBSECTION>
gtk_transform_identity
gtk_transform_transform
gtk_transform_matrix
gtk_transform_translate
gtk_transform_translate_3d
gtk_transform_rotate
gtk_transform_rotate_3d
gtk_transform_scale
gtk_transform_scale_3d
<SUBSECTION>
gtk_transform_equal
<SUBSECTION>
gtk_transform_get_transform_type
gtk_transform_get_next
<SUBSECTION Private>
GTK_TYPE_TRANSFORM
gdk_transform_get_type
gtk_transform_new
</SECTION>
<SECTION>
<FILE>gtkorientable</FILE>
<TITLE>Orientable</TITLE>

View File

@ -228,6 +228,7 @@
#include <gtk/gtktoolshell.h>
#include <gtk/gtktooltip.h>
#include <gtk/gtktestutils.h>
#include <gtk/gtktransform.h>
#include <gtk/gtktreednd.h>
#include <gtk/gtktreelistmodel.h>
#include <gtk/gtktreemodel.h>

1113
gtk/gtktransform.c Normal file

File diff suppressed because it is too large Load Diff

104
gtk/gtktransform.h Normal file
View File

@ -0,0 +1,104 @@
/*
* Copyright © 2019 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>
*/
#ifndef __GTK_TRANSFORM_H__
#define __GTK_TRANSFORM_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <graphene.h>
#include <gtk/gtktypes.h>
G_BEGIN_DECLS
#define GTK_TYPE_MATRIX (gtk_transform_get_type ())
typedef enum
{
GTK_TRANSFORM_TYPE_IDENTITY,
GTK_TRANSFORM_TYPE_TRANSFORM,
GTK_TRANSFORM_TYPE_TRANSLATE,
GTK_TRANSFORM_TYPE_ROTATE,
GTK_TRANSFORM_TYPE_SCALE
} GtkTransformType;
GDK_AVAILABLE_IN_ALL
GType gtk_transform_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkTransform * gtk_transform_ref (GtkTransform *self);
GDK_AVAILABLE_IN_ALL
void gtk_transform_unref (GtkTransform *self);
GDK_AVAILABLE_IN_ALL
void gtk_transform_print (GtkTransform *self,
GString *string);
GDK_AVAILABLE_IN_ALL
char * gtk_transform_to_string (GtkTransform *self);
GDK_AVAILABLE_IN_ALL
void gtk_transform_to_matrix (GtkTransform *self,
graphene_matrix_t *out_matrix);
GDK_AVAILABLE_IN_ALL
gboolean gtk_transform_equal (GtkTransform *first,
GtkTransform *second) G_GNUC_PURE;
GDK_AVAILABLE_IN_ALL
GtkTransform * gtk_transform_new (void);
GDK_AVAILABLE_IN_ALL
GtkTransform * gtk_transform_identity (GtkTransform *next);
GDK_AVAILABLE_IN_ALL
GtkTransform * gtk_transform_transform (GtkTransform *next,
GtkTransform *other);
GDK_AVAILABLE_IN_ALL
GtkTransform * gtk_transform_matrix (GtkTransform *next,
const graphene_matrix_t *matrix);
GDK_AVAILABLE_IN_ALL
GtkTransform * gtk_transform_translate (GtkTransform *next,
const graphene_point_t *point);
GDK_AVAILABLE_IN_ALL
GtkTransform * gtk_transform_translate_3d (GtkTransform *next,
const graphene_point3d_t *point);
GDK_AVAILABLE_IN_ALL
GtkTransform * gtk_transform_rotate (GtkTransform *next,
float angle);
GDK_AVAILABLE_IN_ALL
GtkTransform * gtk_transform_rotate_3d (GtkTransform *next,
float angle,
const graphene_vec3_t *axis);
GDK_AVAILABLE_IN_ALL
GtkTransform * gtk_transform_scale (GtkTransform *next,
float factor_x,
float factor_y);
GDK_AVAILABLE_IN_ALL
GtkTransform * gtk_transform_scale_3d (GtkTransform *next,
float factor_x,
float factor_y,
float factor_z);
GDK_AVAILABLE_IN_ALL
GtkTransformType gtk_transform_get_transform_type (GtkTransform *self) G_GNUC_PURE;
GDK_AVAILABLE_IN_ALL
GtkTransform * gtk_transform_get_next (GtkTransform *self) G_GNUC_PURE;
G_END_DECLS
#endif /* __GTK_TRANSFORM_H__ */

46
gtk/gtktransformprivate.h Normal file
View File

@ -0,0 +1,46 @@
/*
* Copyright © 2019 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>
*/
#ifndef __GTK_TRANSFORM_PRIVATE_H__
#define __GTK_TRANSFORM_PRIVATE_H__
#include "gtktransform.h"
#include <gsk/gsk.h>
#include "gsk/gskrendernodeprivate.h"
G_BEGIN_DECLS
GskMatrixCategory gtk_transform_categorize (GtkTransform *self);
gboolean gtk_transform_to_affine (GtkTransform *self,
float *scale_x,
float *scale_y,
float *dx,
float *dy) G_GNUC_WARN_UNUSED_RESULT;
GtkTransform * gtk_transform_matrix_with_category (GtkTransform *next,
const graphene_matrix_t*matrix,
GskMatrixCategory category);
G_END_DECLS
#endif /* __GTK_TRANSFORM_PRIVATE_H__ */

View File

@ -45,6 +45,7 @@ typedef struct _GtkSettings GtkSettings;
typedef GdkSnapshot GtkSnapshot;
typedef struct _GtkStyleContext GtkStyleContext;
typedef struct _GtkTooltip GtkTooltip;
typedef struct _GtkTransform GtkTransform;
typedef struct _GtkWidget GtkWidget;
typedef struct _GtkWidgetPath GtkWidgetPath;
typedef struct _GtkWindow GtkWindow;

View File

@ -376,6 +376,7 @@ gtk_public_sources = files([
'gtktoolshell.c',
'gtktooltip.c',
'gtktooltipwindow.c',
'gtktransform.c',
'gtktreednd.c',
'gtktreelistmodel.c',
'gtktreemenu.c',
@ -606,6 +607,7 @@ gtk_public_headers = files([
'gtktoolitem.h',
'gtktoolshell.h',
'gtktooltip.h',
'gtktransform.h',
'gtktreednd.h',
'gtktreelistmodel.h',
'gtktreemodel.h',