gtk-demo: Work without stylus
authorMatthias Clasen <mclasen@redhat.com>
Sun, 9 Apr 2023 12:28:26 +0000 (08:28 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 21 Apr 2023 07:14:12 +0000 (09:14 +0200)
In the paint demo, don't assume that the event
backlog contains pressure. It won't, if we are
working with a plain old mouse.

demos/gtk-demo/paint.c

index 59561ed7b4fe9e7957dea62e43c49799574af41a..b9fb3502155eb270da219942c0abde550f04d913 100644 (file)
@@ -263,7 +263,7 @@ drawing_area_apply_stroke (DrawingArea   *area,
                            double         y,
                            double         pressure)
 {
-  if (gdk_device_tool_get_tool_type (tool) == GDK_DEVICE_TOOL_TYPE_ERASER)
+  if (tool && gdk_device_tool_get_tool_type (tool) == GDK_DEVICE_TOOL_TYPE_ERASER)
     {
       cairo_set_line_width (area->cr, 10 * pressure * area->brush_size);
       cairo_set_operator (area->cr, CAIRO_OPERATOR_DEST_OUT);
@@ -314,7 +314,9 @@ stylus_gesture_motion (GtkGestureStylus *gesture,
           drawing_area_apply_stroke (area, tool,
                                      backlog[i].axes[GDK_AXIS_X],
                                      backlog[i].axes[GDK_AXIS_Y],
-                                     backlog[i].axes[GDK_AXIS_PRESSURE]);
+                                     backlog[i].flags & GDK_AXIS_FLAG_PRESSURE
+                                        ? backlog[i].axes[GDK_AXIS_PRESSURE]
+                                        : 1);
         }
 
       g_free (backlog);