]> Pileus Git - ~andy/gtk/blobdiff - tests/testinput.c
tests: Add test for latest bugfix
[~andy/gtk] / tests / testinput.c
index a7e51af581216e0031b34309c213a158dcc54bfa..2a2e4cc8eeda570280ce3ccaeeb1e2e7911b7f7d 100644 (file)
@@ -12,9 +12,7 @@
  * 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, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
@@ -27,6 +25,7 @@
 #include "config.h"
 #include <stdio.h>
 #include "gtk/gtk.h"
+#include <math.h>
 
 /* Backing surface for drawing area */
 
@@ -46,7 +45,10 @@ static void
 update_cursor (GtkWidget *widget,  gdouble x, gdouble y)
 {
   static gint cursor_present = 0;
-  gint state = !current_device->has_cursor && cursor_proximity;
+  gint state = !gdk_device_get_has_cursor (current_device) && cursor_proximity;
+
+  x = floor (x);
+  y = floor (y);
 
   if (surface != NULL)
     {
@@ -119,26 +121,27 @@ static void
 draw_brush (GtkWidget *widget, GdkInputSource source,
            gdouble x, gdouble y, gdouble pressure)
 {
-  GtkStyle *style;
-  GdkColor color;
+  GdkRGBA color;
   GdkRectangle update_rect;
   cairo_t *cr;
 
-  style = gtk_widget_get_style (widget);
+  color.alpha = 1.0;
 
   switch (source)
     {
     case GDK_SOURCE_MOUSE:
-      color = style->dark[gtk_widget_get_state (widget)];
+      color.red = color.green = 0.0;
+      color.blue = 1.0;
       break;
     case GDK_SOURCE_PEN:
-      color.red = color.green = color.blue = 0;
+      color.red = color.green = color.blue = 0.0;
       break;
     case GDK_SOURCE_ERASER:
-      color.red = color.green = color.blue = 65535;
+      color.red = color.green = color.blue = 1.0;
       break;
     default:
-      color = style->light[gtk_widget_get_state (widget)];
+      color.red = color.blue = 0.0;
+      color.green = 1.0;
     }
 
   update_rect.x = x - 10 * pressure;
@@ -147,7 +150,7 @@ draw_brush (GtkWidget *widget, GdkInputSource source,
   update_rect.height = 20 * pressure;
 
   cr = cairo_create (surface);
-  gdk_cairo_set_source_color (cr, &color);
+  gdk_cairo_set_source_rgba (cr, &color);
   gdk_cairo_rectangle (cr, &update_rect);
   cairo_fill (cr);
   cairo_destroy (cr);
@@ -167,9 +170,9 @@ print_axes (GdkDevice *device, gdouble *axes)
   
   if (axes)
     {
-      g_print ("%s ", device->name);
-      
-      for (i=0; i<device->num_axes; i++)
+      g_print ("%s ", gdk_device_get_name (device));
+
+      for (i = 0; i < gdk_device_get_n_axes (device); i++)
        g_print ("%g ", axes[i]);
 
       g_print ("\n");
@@ -182,14 +185,16 @@ button_press_event (GtkWidget *widget, GdkEventButton *event)
   current_device = event->device;
   cursor_proximity = TRUE;
 
-  if (event->button == 1 && surface != NULL)
+  if (event->button == GDK_BUTTON_PRIMARY &&
+      surface != NULL)
     {
       gdouble pressure = 0.5;
 
       print_axes (event->device, event->axes);
       gdk_event_get_axis ((GdkEvent *)event, GDK_AXIS_PRESSURE, &pressure);
-      draw_brush (widget, event->device->source, event->x, event->y, pressure);
-      
+      draw_brush (widget, gdk_device_get_source (event->device),
+                  event->x, event->y, pressure);
+
       motion_time = event->time;
     }
 
@@ -232,7 +237,8 @@ motion_notify_event (GtkWidget *widget, GdkEventMotion *event)
              gdk_device_get_axis (event->device, events[i]->axes, GDK_AXIS_X, &x);
              gdk_device_get_axis (event->device, events[i]->axes, GDK_AXIS_Y, &y);
              gdk_device_get_axis (event->device, events[i]->axes, GDK_AXIS_PRESSURE, &pressure);
-             draw_brush (widget,  event->device->source, x, y, pressure);
+             draw_brush (widget, gdk_device_get_source (event->device),
+                          x, y, pressure);
 
              print_axes (event->device, events[i]->axes);
            }
@@ -244,7 +250,8 @@ motion_notify_event (GtkWidget *widget, GdkEventMotion *event)
 
          gdk_event_get_axis ((GdkEvent *)event, GDK_AXIS_PRESSURE, &pressure);
 
-         draw_brush (widget,  event->device->source, event->x, event->y, pressure);
+         draw_brush (widget, gdk_device_get_source (event->device),
+                      event->x, event->y, pressure);
        }
       motion_time = event->time;
     }
@@ -303,7 +310,7 @@ main (int argc, char *argv[])
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_widget_set_name (window, "Test Input");
 
-  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 0);
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
   gtk_container_add (GTK_CONTAINER (window), vbox);
   gtk_widget_show (vbox);