Compare commits
2 Commits
matthiasc/
...
wip/carlos
Author | SHA1 | Date | |
---|---|---|---|
|
721e325802 | ||
|
1e52541c22 |
@@ -180,6 +180,7 @@
|
|||||||
<file>modelbutton.c</file>
|
<file>modelbutton.c</file>
|
||||||
<file>overlay.c</file>
|
<file>overlay.c</file>
|
||||||
<file>overlay2.c</file>
|
<file>overlay2.c</file>
|
||||||
|
<file>paint.c</file>
|
||||||
<file>pagesetup.c</file>
|
<file>pagesetup.c</file>
|
||||||
<file>panes.c</file>
|
<file>panes.c</file>
|
||||||
<file>pickers.c</file>
|
<file>pickers.c</file>
|
||||||
|
@@ -45,6 +45,7 @@ demos = files([
|
|||||||
'modelbutton.c',
|
'modelbutton.c',
|
||||||
'overlay.c',
|
'overlay.c',
|
||||||
'overlay2.c',
|
'overlay2.c',
|
||||||
|
'paint.c',
|
||||||
'panes.c',
|
'panes.c',
|
||||||
'pickers.c',
|
'pickers.c',
|
||||||
'pixbufs.c',
|
'pixbufs.c',
|
||||||
|
273
demos/gtk-demo/paint.c
Normal file
273
demos/gtk-demo/paint.c
Normal file
@@ -0,0 +1,273 @@
|
|||||||
|
/* Paint
|
||||||
|
*
|
||||||
|
* Demonstrates practical handling of drawing tablets in a real world
|
||||||
|
* usecase.
|
||||||
|
*/
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
GtkWidget parent_instance;
|
||||||
|
cairo_surface_t *surface;
|
||||||
|
cairo_t *cr;
|
||||||
|
GdkRGBA draw_color;
|
||||||
|
|
||||||
|
GtkGesture *stylus_gesture;
|
||||||
|
} DrawingArea;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
GtkWidgetClass parent_class;
|
||||||
|
} DrawingAreaClass;
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (DrawingArea, drawing_area, GTK_TYPE_WIDGET)
|
||||||
|
|
||||||
|
static void
|
||||||
|
drawing_area_ensure_surface (DrawingArea *area,
|
||||||
|
gint width,
|
||||||
|
gint height)
|
||||||
|
{
|
||||||
|
if (!area->surface ||
|
||||||
|
cairo_image_surface_get_width (area->surface) != width ||
|
||||||
|
cairo_image_surface_get_height (area->surface) != height)
|
||||||
|
{
|
||||||
|
cairo_surface_t *surface;
|
||||||
|
|
||||||
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
||||||
|
width, height);
|
||||||
|
if (area->surface)
|
||||||
|
{
|
||||||
|
cairo_t *cr;
|
||||||
|
|
||||||
|
cr = cairo_create (surface);
|
||||||
|
cairo_set_source_surface (cr, area->surface, 0, 0);
|
||||||
|
cairo_paint (cr);
|
||||||
|
|
||||||
|
cairo_surface_destroy (area->surface);
|
||||||
|
cairo_destroy (area->cr);
|
||||||
|
cairo_destroy (cr);
|
||||||
|
}
|
||||||
|
|
||||||
|
area->surface = surface;
|
||||||
|
area->cr = cairo_create (surface);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
drawing_area_size_allocate (GtkWidget *widget,
|
||||||
|
const GtkAllocation *allocation,
|
||||||
|
int baseline,
|
||||||
|
GtkAllocation *out_clip)
|
||||||
|
{
|
||||||
|
DrawingArea *area = (DrawingArea *) widget;
|
||||||
|
|
||||||
|
drawing_area_ensure_surface (area, allocation->width, allocation->height);
|
||||||
|
|
||||||
|
GTK_WIDGET_CLASS (drawing_area_parent_class)->size_allocate (widget, allocation, baseline, out_clip);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
drawing_area_map (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
GtkAllocation allocation;
|
||||||
|
|
||||||
|
GTK_WIDGET_CLASS (drawing_area_parent_class)->map (widget);
|
||||||
|
|
||||||
|
gtk_widget_get_allocation (widget, &allocation);
|
||||||
|
drawing_area_ensure_surface ((DrawingArea *) widget,
|
||||||
|
allocation.width, allocation.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
drawing_area_unmap (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
DrawingArea *area = (DrawingArea *) widget;
|
||||||
|
|
||||||
|
g_clear_pointer (&area->cr, cairo_destroy);
|
||||||
|
g_clear_pointer (&area->surface, cairo_surface_destroy);
|
||||||
|
|
||||||
|
GTK_WIDGET_CLASS (drawing_area_parent_class)->unmap (widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
drawing_area_draw (GtkWidget *widget,
|
||||||
|
cairo_t *cr)
|
||||||
|
{
|
||||||
|
DrawingArea *area = (DrawingArea *) widget;
|
||||||
|
GtkAllocation allocation;
|
||||||
|
|
||||||
|
gtk_widget_get_allocation (widget, &allocation);
|
||||||
|
cairo_set_source_rgb (cr, 1, 1, 1);
|
||||||
|
cairo_paint (cr);
|
||||||
|
|
||||||
|
cairo_set_source_surface (cr, area->surface, 0, 0);
|
||||||
|
cairo_paint (cr);
|
||||||
|
|
||||||
|
cairo_set_source_rgb (cr, 0.6, 0.6, 0.6);
|
||||||
|
cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
|
||||||
|
cairo_stroke (cr);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
drawing_area_class_init (DrawingAreaClass *klass)
|
||||||
|
{
|
||||||
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||||
|
|
||||||
|
widget_class->size_allocate = drawing_area_size_allocate;
|
||||||
|
widget_class->draw = drawing_area_draw;
|
||||||
|
widget_class->map = drawing_area_map;
|
||||||
|
widget_class->unmap = drawing_area_unmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
drawing_area_apply_stroke (DrawingArea *area,
|
||||||
|
GdkDeviceTool *tool,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y,
|
||||||
|
gdouble pressure)
|
||||||
|
{
|
||||||
|
if (gdk_device_tool_get_tool_type (tool) == GDK_DEVICE_TOOL_TYPE_ERASER)
|
||||||
|
{
|
||||||
|
cairo_set_line_width (area->cr, 10 * pressure);
|
||||||
|
cairo_set_operator (area->cr, CAIRO_OPERATOR_DEST_OUT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cairo_set_line_width (area->cr, 4 * pressure);
|
||||||
|
cairo_set_operator (area->cr, CAIRO_OPERATOR_SATURATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
cairo_set_source_rgba (area->cr, area->draw_color.red,
|
||||||
|
area->draw_color.green, area->draw_color.blue,
|
||||||
|
area->draw_color.alpha * pressure);
|
||||||
|
|
||||||
|
//cairo_set_source_rgba (area->cr, 0, 0, 0, pressure);
|
||||||
|
|
||||||
|
cairo_line_to (area->cr, x, y);
|
||||||
|
cairo_stroke (area->cr);
|
||||||
|
cairo_move_to (area->cr, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
stylus_gesture_down (GtkGestureStylus *gesture,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y,
|
||||||
|
DrawingArea *area)
|
||||||
|
{
|
||||||
|
cairo_new_path (area->cr);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
stylus_gesture_motion (GtkGestureStylus *gesture,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y,
|
||||||
|
DrawingArea *area)
|
||||||
|
{
|
||||||
|
GdkTimeCoord *backlog;
|
||||||
|
GdkDeviceTool *tool;
|
||||||
|
gdouble pressure;
|
||||||
|
guint n_items;
|
||||||
|
|
||||||
|
tool = gtk_gesture_stylus_get_device_tool (gesture);
|
||||||
|
|
||||||
|
if (gtk_gesture_stylus_get_backlog (gesture, &backlog, &n_items))
|
||||||
|
{
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
for (i = 0; i < n_items; i++)
|
||||||
|
{
|
||||||
|
drawing_area_apply_stroke (area, tool,
|
||||||
|
backlog[i].axes[GDK_AXIS_X],
|
||||||
|
backlog[i].axes[GDK_AXIS_Y],
|
||||||
|
backlog[i].axes[GDK_AXIS_PRESSURE]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!gtk_gesture_stylus_get_axis (gesture, GDK_AXIS_PRESSURE, &pressure))
|
||||||
|
pressure = 1;
|
||||||
|
|
||||||
|
drawing_area_apply_stroke (area, tool, x, y, pressure);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_widget_queue_draw (GTK_WIDGET (area));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
drawing_area_init (DrawingArea *area)
|
||||||
|
{
|
||||||
|
gtk_widget_set_has_window (GTK_WIDGET (area), FALSE);
|
||||||
|
|
||||||
|
area->stylus_gesture = gtk_gesture_stylus_new (GTK_WIDGET (area));
|
||||||
|
g_signal_connect (area->stylus_gesture, "down",
|
||||||
|
G_CALLBACK (stylus_gesture_down), area);
|
||||||
|
g_signal_connect (area->stylus_gesture, "motion",
|
||||||
|
G_CALLBACK (stylus_gesture_motion), area);
|
||||||
|
|
||||||
|
area->draw_color = (GdkRGBA) { 0, 0, 0, 1 };
|
||||||
|
}
|
||||||
|
|
||||||
|
GtkWidget *
|
||||||
|
drawing_area_new (void)
|
||||||
|
{
|
||||||
|
return g_object_new (drawing_area_get_type (), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
drawing_area_set_color (DrawingArea *area,
|
||||||
|
GdkRGBA *color)
|
||||||
|
{
|
||||||
|
area->draw_color = *color;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
color_button_color_set (GtkColorButton *button,
|
||||||
|
DrawingArea *draw_area)
|
||||||
|
{
|
||||||
|
GdkRGBA color;
|
||||||
|
|
||||||
|
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), &color);
|
||||||
|
drawing_area_set_color (draw_area, &color);
|
||||||
|
}
|
||||||
|
|
||||||
|
GtkWidget *
|
||||||
|
do_paint (GtkWidget *toplevel)
|
||||||
|
{
|
||||||
|
static GtkWidget *window = NULL;
|
||||||
|
|
||||||
|
if (!window)
|
||||||
|
{
|
||||||
|
GtkWidget *draw_area, *headerbar, *colorbutton;
|
||||||
|
|
||||||
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
|
|
||||||
|
draw_area = drawing_area_new ();
|
||||||
|
gtk_container_add (GTK_CONTAINER (window), draw_area);
|
||||||
|
|
||||||
|
headerbar = gtk_header_bar_new ();
|
||||||
|
gtk_header_bar_set_title (GTK_HEADER_BAR (headerbar), "Paint");
|
||||||
|
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (headerbar), TRUE);
|
||||||
|
|
||||||
|
colorbutton = gtk_color_button_new ();
|
||||||
|
g_signal_connect (colorbutton, "color-set",
|
||||||
|
G_CALLBACK (color_button_color_set), draw_area);
|
||||||
|
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (colorbutton),
|
||||||
|
&(GdkRGBA) { 0, 0, 0, 1 });
|
||||||
|
|
||||||
|
gtk_header_bar_pack_end (GTK_HEADER_BAR (headerbar), colorbutton);
|
||||||
|
gtk_window_set_titlebar (GTK_WINDOW (window), headerbar);
|
||||||
|
|
||||||
|
g_signal_connect (window, "destroy",
|
||||||
|
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gtk_widget_get_visible (window))
|
||||||
|
gtk_widget_show (window);
|
||||||
|
else
|
||||||
|
gtk_widget_destroy (window);
|
||||||
|
|
||||||
|
return window;
|
||||||
|
}
|
@@ -116,6 +116,7 @@
|
|||||||
#include <gtk/gtkgesturepan.h>
|
#include <gtk/gtkgesturepan.h>
|
||||||
#include <gtk/gtkgesturerotate.h>
|
#include <gtk/gtkgesturerotate.h>
|
||||||
#include <gtk/gtkgesturesingle.h>
|
#include <gtk/gtkgesturesingle.h>
|
||||||
|
#include <gtk/gtkgesturestylus.h>
|
||||||
#include <gtk/gtkgestureswipe.h>
|
#include <gtk/gtkgestureswipe.h>
|
||||||
#include <gtk/gtkgesturezoom.h>
|
#include <gtk/gtkgesturezoom.h>
|
||||||
#include <gtk/gtkglarea.h>
|
#include <gtk/gtkglarea.h>
|
||||||
|
330
gtk/gtkgesturestylus.c
Normal file
330
gtk/gtkgesturestylus.c
Normal file
@@ -0,0 +1,330 @@
|
|||||||
|
/* GTK - The GIMP Toolkit
|
||||||
|
* Copyright (C) 2017-2018, Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*
|
||||||
|
* Author(s): Carlos Garnacho <carlosg@gnome.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SECTION:gtkgesturestylus
|
||||||
|
* @Short_description: Gesture for stylus input
|
||||||
|
* @Title: GtkGestureStylus
|
||||||
|
* @See_also: #GtkGesture, #GtkGestureSingle
|
||||||
|
*
|
||||||
|
* #GtkGestureStylus is a #GtkGesture implementation specific to stylus
|
||||||
|
* input. The provided signals just provide the basic information
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "gtkgesturestylus.h"
|
||||||
|
#include "gtkgesturestylusprivate.h"
|
||||||
|
#include "gtkprivate.h"
|
||||||
|
#include "gtkintl.h"
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (GtkGestureStylus, gtk_gesture_stylus, GTK_TYPE_GESTURE_SINGLE)
|
||||||
|
|
||||||
|
enum {
|
||||||
|
PROXIMITY,
|
||||||
|
DOWN,
|
||||||
|
MOTION,
|
||||||
|
UP,
|
||||||
|
N_SIGNALS
|
||||||
|
};
|
||||||
|
|
||||||
|
static guint signals[N_SIGNALS] = { 0, };
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gtk_gesture_stylus_handle_event (GtkEventController *controller,
|
||||||
|
const GdkEvent *event)
|
||||||
|
{
|
||||||
|
GdkModifierType modifiers;
|
||||||
|
guint n_signal;
|
||||||
|
gdouble x, y;
|
||||||
|
|
||||||
|
GTK_EVENT_CONTROLLER_CLASS (gtk_gesture_stylus_parent_class)->handle_event (controller, event);
|
||||||
|
|
||||||
|
if (!gdk_event_get_device_tool (event))
|
||||||
|
return FALSE;
|
||||||
|
if (!gdk_event_get_coords (event, &x, &y))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
switch ((guint) gdk_event_get_event_type (event))
|
||||||
|
{
|
||||||
|
case GDK_BUTTON_PRESS:
|
||||||
|
n_signal = DOWN;
|
||||||
|
break;
|
||||||
|
case GDK_BUTTON_RELEASE:
|
||||||
|
n_signal = UP;
|
||||||
|
break;
|
||||||
|
case GDK_MOTION_NOTIFY:
|
||||||
|
gdk_event_get_state (event, &modifiers);
|
||||||
|
|
||||||
|
if (modifiers & GDK_BUTTON1_MASK)
|
||||||
|
n_signal = MOTION;
|
||||||
|
else
|
||||||
|
n_signal = PROXIMITY;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_signal_emit (controller, signals[n_signal], 0, x, y);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_gesture_stylus_class_init (GtkGestureStylusClass *klass)
|
||||||
|
{
|
||||||
|
GObjectClass *object_class;
|
||||||
|
GtkEventControllerClass *event_controller_class;
|
||||||
|
|
||||||
|
object_class = G_OBJECT_CLASS (klass);
|
||||||
|
event_controller_class = GTK_EVENT_CONTROLLER_CLASS (klass);
|
||||||
|
|
||||||
|
event_controller_class->handle_event = gtk_gesture_stylus_handle_event;
|
||||||
|
|
||||||
|
signals[PROXIMITY] =
|
||||||
|
g_signal_new (I_("proximity"),
|
||||||
|
G_TYPE_FROM_CLASS (klass),
|
||||||
|
G_SIGNAL_RUN_LAST,
|
||||||
|
G_STRUCT_OFFSET (GtkGestureStylusClass, proximity),
|
||||||
|
NULL, NULL, NULL,
|
||||||
|
G_TYPE_NONE, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
||||||
|
signals[DOWN] =
|
||||||
|
g_signal_new (I_("down"),
|
||||||
|
G_TYPE_FROM_CLASS (klass),
|
||||||
|
G_SIGNAL_RUN_LAST,
|
||||||
|
G_STRUCT_OFFSET (GtkGestureStylusClass, down),
|
||||||
|
NULL, NULL, NULL,
|
||||||
|
G_TYPE_NONE, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
||||||
|
signals[MOTION] =
|
||||||
|
g_signal_new (I_("motion"),
|
||||||
|
G_TYPE_FROM_CLASS (klass),
|
||||||
|
G_SIGNAL_RUN_LAST,
|
||||||
|
G_STRUCT_OFFSET (GtkGestureStylusClass, motion),
|
||||||
|
NULL, NULL, NULL,
|
||||||
|
G_TYPE_NONE, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
||||||
|
signals[UP] =
|
||||||
|
g_signal_new (I_("up"),
|
||||||
|
G_TYPE_FROM_CLASS (klass),
|
||||||
|
G_SIGNAL_RUN_LAST,
|
||||||
|
G_STRUCT_OFFSET (GtkGestureStylusClass, up),
|
||||||
|
NULL, NULL, NULL,
|
||||||
|
G_TYPE_NONE, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_gesture_stylus_init (GtkGestureStylus *gesture)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_gesture_stylus_new:
|
||||||
|
* @widget: a #GtkWidget
|
||||||
|
*
|
||||||
|
* Creates a new #GtkGestureStylus.
|
||||||
|
*
|
||||||
|
* Returns: a newly created stylus gesture
|
||||||
|
*
|
||||||
|
* Since: 3.94
|
||||||
|
**/
|
||||||
|
GtkGesture *
|
||||||
|
gtk_gesture_stylus_new (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
return g_object_new (GTK_TYPE_GESTURE_STYLUS,
|
||||||
|
"widget", widget,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const GdkEvent *
|
||||||
|
gesture_get_current_event (GtkGestureStylus *gesture)
|
||||||
|
{
|
||||||
|
GdkEventSequence *sequence;
|
||||||
|
|
||||||
|
sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
|
||||||
|
|
||||||
|
return gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_gesture_stylus_get_axis:
|
||||||
|
* @gesture: a #GtkGestureStylus
|
||||||
|
* @axis: requested device axis
|
||||||
|
* @value: (out): return location for the axis value
|
||||||
|
*
|
||||||
|
* Returns the current value for the requested @axis. This function
|
||||||
|
* must be called from either the #GtkGestureStylus:down,
|
||||||
|
* #GtkGestureStylus:motion, #GtkGestureStylus:up or #GtkGestureStylus:proximity
|
||||||
|
* signals.
|
||||||
|
*
|
||||||
|
* Returns: #TRUE if there is a current value for the axis
|
||||||
|
*
|
||||||
|
* Since: 3.94
|
||||||
|
**/
|
||||||
|
gboolean
|
||||||
|
gtk_gesture_stylus_get_axis (GtkGestureStylus *gesture,
|
||||||
|
GdkAxisUse axis,
|
||||||
|
gdouble *value)
|
||||||
|
{
|
||||||
|
const GdkEvent *event;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GTK_IS_GESTURE_STYLUS (gesture), FALSE);
|
||||||
|
g_return_val_if_fail (axis < GDK_AXIS_LAST, FALSE);
|
||||||
|
g_return_val_if_fail (value != NULL, FALSE);
|
||||||
|
|
||||||
|
event = gesture_get_current_event (gesture);
|
||||||
|
if (!event)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
return gdk_event_get_axis (event, axis, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_gesture_stylus_get_axes:
|
||||||
|
* @gesture: a GtkGestureStylus
|
||||||
|
* @axes: array of requested axes, terminated with #GDK_AXIS_IGNORE
|
||||||
|
* @values: (out): return location for the axis values
|
||||||
|
*
|
||||||
|
* Returns the current values for the requested @axes. This function
|
||||||
|
* must be called from either the #GtkGestureStylus:down,
|
||||||
|
* #GtkGestureStylus:motion, #GtkGestureStylus:up or #GtkGestureStylus:proximity
|
||||||
|
* signals.
|
||||||
|
*
|
||||||
|
* Returns: #TRUE if there is a current value for the axes
|
||||||
|
**/
|
||||||
|
gboolean
|
||||||
|
gtk_gesture_stylus_get_axes (GtkGestureStylus *gesture,
|
||||||
|
GdkAxisUse axes[],
|
||||||
|
gdouble **values)
|
||||||
|
{
|
||||||
|
const GdkEvent *event;
|
||||||
|
GArray *array;
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GTK_IS_GESTURE_STYLUS (gesture), FALSE);
|
||||||
|
g_return_val_if_fail (values != NULL, FALSE);
|
||||||
|
|
||||||
|
event = gesture_get_current_event (gesture);
|
||||||
|
if (!event)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
while (axes[i] != GDK_AXIS_IGNORE)
|
||||||
|
{
|
||||||
|
gdouble value;
|
||||||
|
|
||||||
|
if (axes[i] >= GDK_AXIS_LAST)
|
||||||
|
{
|
||||||
|
g_warning ("Requesting unknown axis %d, did you "
|
||||||
|
"forget to add a last GDK_AXIS_IGNORE axis?",
|
||||||
|
axes[i]);
|
||||||
|
g_array_free (array, TRUE);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gdk_event_get_axis (event, axes[i], &value);
|
||||||
|
g_array_append_val (array, value);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*values = g_array_free (array, FALSE);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_gesture_stylus_get_backlog:
|
||||||
|
* @gesture: a #GtkGestureStylus
|
||||||
|
* @backlog: (out): coordinates and times for the backlog events
|
||||||
|
* @n_elems: (out): return location for the number of elements
|
||||||
|
*
|
||||||
|
* By default, GTK+ will limit rate of input events. On stylus input where
|
||||||
|
* accuracy of strokes is paramount, this function returns the accumulated
|
||||||
|
* coordinate/timing state before the emission of the current
|
||||||
|
* #GtkGestureStylus:motion signal.
|
||||||
|
*
|
||||||
|
* This function may only be called within a #GtkGestureStylus::motion
|
||||||
|
* signal handler, the state given in this signal and obtainable through
|
||||||
|
* gtk_gesture_stylus_get_axis() call express the latest (most up-to-date)
|
||||||
|
* state in motion history.
|
||||||
|
*
|
||||||
|
* @backlog is provided in chronological order.
|
||||||
|
*
|
||||||
|
* Returns: #TRUE if there is a backlog to unfold in the current state.
|
||||||
|
**/
|
||||||
|
gboolean
|
||||||
|
gtk_gesture_stylus_get_backlog (GtkGestureStylus *gesture,
|
||||||
|
GdkTimeCoord **backlog,
|
||||||
|
guint *n_elems)
|
||||||
|
{
|
||||||
|
GdkEvent *event;
|
||||||
|
GArray *backlog_array;
|
||||||
|
GList *history, *l;
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GTK_IS_GESTURE_STYLUS (gesture), FALSE);
|
||||||
|
g_return_val_if_fail (backlog != NULL && n_elems != NULL, FALSE);
|
||||||
|
|
||||||
|
event = gesture_get_current_event (gesture);
|
||||||
|
|
||||||
|
if (event)
|
||||||
|
history = gdk_event_get_history (event);
|
||||||
|
if (!history)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
backlog_array = g_array_new (FALSE, FALSE, sizeof (GdkTimeCoord));
|
||||||
|
for (l = history; l; l = l->next)
|
||||||
|
{
|
||||||
|
GdkTimeCoord time_coord;
|
||||||
|
GdkEvent *ev = l->data;
|
||||||
|
|
||||||
|
time_coord.time = gdk_event_get_time (ev);
|
||||||
|
|
||||||
|
for (i = 0; i < GDK_AXIS_LAST; i++)
|
||||||
|
gdk_event_get_axis (event, i, &time_coord.axes[i]);
|
||||||
|
|
||||||
|
g_array_append_val (backlog_array, time_coord);
|
||||||
|
}
|
||||||
|
|
||||||
|
*n_elems = backlog_array->len;
|
||||||
|
*backlog = g_array_free (backlog_array, FALSE);
|
||||||
|
g_list_free (history);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gdk_gesture_stylus_get_device_tool:
|
||||||
|
* @gesture: a #GtkGestureStylus
|
||||||
|
*
|
||||||
|
* Returns the #GdkDeviceTool currently driving input through this gesture.
|
||||||
|
* This function must be called from either the #GtkGestureStylus:down,
|
||||||
|
* #GtkGestureStylus:motion, #GtkGestureStylus:up or #GtkGestureStylus:proximity
|
||||||
|
* signals.
|
||||||
|
*
|
||||||
|
* Returns: (transfer none): The current stylus tool
|
||||||
|
**/
|
||||||
|
GdkDeviceTool *
|
||||||
|
gtk_gesture_stylus_get_device_tool (GtkGestureStylus *gesture)
|
||||||
|
{
|
||||||
|
const GdkEvent *event;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GTK_IS_GESTURE_STYLUS (gesture), FALSE);
|
||||||
|
|
||||||
|
event = gesture_get_current_event (gesture);
|
||||||
|
if (!event)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return gdk_event_get_device_tool (event);
|
||||||
|
}
|
63
gtk/gtkgesturestylus.h
Normal file
63
gtk/gtkgesturestylus.h
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/* GTK - The GIMP Toolkit
|
||||||
|
* Copyright (C) 2017-2018, Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*
|
||||||
|
* Author(s): Carlos Garnacho <carlosg@gnome.org>
|
||||||
|
*/
|
||||||
|
#ifndef __GTK_GESTURE_STYLUS_H__
|
||||||
|
#define __GTK_GESTURE_STYLUS_H__
|
||||||
|
|
||||||
|
#include <gtk/gtkgesture.h>
|
||||||
|
|
||||||
|
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||||
|
#error "Only <gtk/gtk.h> can be included directly."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define GTK_TYPE_GESTURE_STYLUS (gtk_gesture_stylus_get_type ())
|
||||||
|
#define GTK_GESTURE_STYLUS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_GESTURE_STYLUS, GtkGestureStylus))
|
||||||
|
#define GTK_GESTURE_STYLUS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_GESTURE_STYLUS, GtkGestureStylusClass))
|
||||||
|
#define GTK_IS_GESTURE_STYLUS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_GESTURE_STYLUS))
|
||||||
|
#define GTK_IS_GESTURE_STYLUS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_GESTURE_STYLUS))
|
||||||
|
#define GTK_GESTURE_STYLUS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_GESTURE_STYLUS, GtkGestureStylusClass))
|
||||||
|
|
||||||
|
typedef struct _GtkGestureStylus GtkGestureStylus;
|
||||||
|
typedef struct _GtkGestureStylusClass GtkGestureStylusClass;
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_3_94
|
||||||
|
GType gtk_gesture_stylus_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_3_94
|
||||||
|
GtkGesture * gtk_gesture_stylus_new (GtkWidget *widget);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_3_94
|
||||||
|
gboolean gtk_gesture_stylus_get_axis (GtkGestureStylus *gesture,
|
||||||
|
GdkAxisUse axis,
|
||||||
|
gdouble *value);
|
||||||
|
GDK_AVAILABLE_IN_3_94
|
||||||
|
gboolean gtk_gesture_stylus_get_axes (GtkGestureStylus *gesture,
|
||||||
|
GdkAxisUse axis[],
|
||||||
|
gdouble **axes);
|
||||||
|
GDK_AVAILABLE_IN_3_94
|
||||||
|
gboolean gtk_gesture_stylus_get_backlog (GtkGestureStylus *gesture,
|
||||||
|
GdkTimeCoord **backlog,
|
||||||
|
guint *n_elems);
|
||||||
|
GDK_AVAILABLE_IN_3_94
|
||||||
|
GdkDeviceTool * gtk_gesture_stylus_get_device_tool (GtkGestureStylus *gesture);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* __GTK_GESTURE_STYLUS_H__ */
|
51
gtk/gtkgesturestylusprivate.h
Normal file
51
gtk/gtkgesturestylusprivate.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/* GTK - The GIMP Toolkit
|
||||||
|
* Copyright (C) 2017-2018, Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*
|
||||||
|
* Author(s): Carlos Garnacho <carlosg@gnome.org>
|
||||||
|
*/
|
||||||
|
#ifndef __GTK_GESTURE_STYLUS_PRIVATE_H__
|
||||||
|
#define __GTK_GESTURE_STYLUS_PRIVATE_H__
|
||||||
|
|
||||||
|
#include "gtkgesturesingleprivate.h"
|
||||||
|
#include "gtkgesturestylus.h"
|
||||||
|
|
||||||
|
struct _GtkGestureStylus
|
||||||
|
{
|
||||||
|
GtkGestureSingle parent_instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _GtkGestureStylusClass
|
||||||
|
{
|
||||||
|
GtkGestureSingleClass parent_class;
|
||||||
|
|
||||||
|
void (*proximity) (GtkGestureStylus *gesture,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y);
|
||||||
|
void (*down) (GtkGestureStylus *gesture,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y);
|
||||||
|
void (*motion) (GtkGestureStylus *gesture,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y);
|
||||||
|
void (*up) (GtkGestureStylus *gesture,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y);
|
||||||
|
|
||||||
|
/*< private >*/
|
||||||
|
gpointer padding[10];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* __GTK_GESTURE_STYLUS_PRIVATE_H__ */
|
@@ -181,6 +181,7 @@ gtk_public_sources = files([
|
|||||||
'gtkgesturepan.c',
|
'gtkgesturepan.c',
|
||||||
'gtkgesturerotate.c',
|
'gtkgesturerotate.c',
|
||||||
'gtkgesturesingle.c',
|
'gtkgesturesingle.c',
|
||||||
|
'gtkgesturestylus.c',
|
||||||
'gtkgestureswipe.c',
|
'gtkgestureswipe.c',
|
||||||
'gtkgesturezoom.c',
|
'gtkgesturezoom.c',
|
||||||
'gtkgizmo.c',
|
'gtkgizmo.c',
|
||||||
@@ -463,6 +464,7 @@ gtk_public_headers = files([
|
|||||||
'gtkgesturepan.h',
|
'gtkgesturepan.h',
|
||||||
'gtkgesturerotate.h',
|
'gtkgesturerotate.h',
|
||||||
'gtkgesturesingle.h',
|
'gtkgesturesingle.h',
|
||||||
|
'gtkgesturestylus.h',
|
||||||
'gtkgestureswipe.h',
|
'gtkgestureswipe.h',
|
||||||
'gtkgesturezoom.h',
|
'gtkgesturezoom.h',
|
||||||
'gtkglarea.h',
|
'gtkglarea.h',
|
||||||
|
Reference in New Issue
Block a user