Пример #1
0
static gint
motion_notify_event (GtkWidget *widget, GdkEventMotion *event)
{
  GdkTimeCoord **events;
  int n_events;
  int i;

  current_device = event->device;
  cursor_proximity = TRUE;

  if (event->state & GDK_BUTTON1_MASK && pixmap != NULL)
    {
      if (gdk_device_get_history (event->device, event->window, 
				  motion_time, event->time,
				  &events, &n_events))
	{
	  for (i=0; i<n_events; i++)
	    {
	      double x = 0, y = 0, pressure = 0.5;

	      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);

	      print_axes (event->device, events[i]->axes);
	    }
	  gdk_device_free_history (events, n_events);
	}
      else
	{
	  double pressure = 0.5;

	  gdk_event_get_axis ((GdkEvent *)event, GDK_AXIS_PRESSURE, &pressure);

	  draw_brush (widget,  event->device->source, event->x, event->y, pressure);
	}
      motion_time = event->time;
    }

  if (event->is_hint)
    gdk_device_get_state (event->device, event->window, NULL, NULL);

  print_axes (event->device, event->axes);
  update_cursor (widget, event->x, event->y);

  return TRUE;
}
Пример #2
0
JNIEXPORT jboolean JNICALL
Java_org_gnome_gdk_GdkDevice_gdk_1device_1get_1axis
(
	JNIEnv* env,
	jclass cls,
	jlong _self,
	jdoubleArray _axes,
	jint _use,
	jdoubleArray _value
)
{
	gboolean result;
	jboolean _result;
	GdkDevice* self;
	gdouble* axes;
	GdkAxisUse use;
	gdouble* value;

	// convert parameter self
	self = (GdkDevice*) _self;

	// convert parameter axes
	axes = (gdouble*) (*env)->GetDoubleArrayElements(env, _axes, NULL);
	if (axes == NULL) {
		return  JNI_FALSE; // Java Exception already thrown
	}

	// convert parameter use
	use = (GdkAxisUse) _use;

	// convert parameter value
	value = (gdouble*) (*env)->GetDoubleArrayElements(env, _value, NULL);
	if (value == NULL) {
		return  JNI_FALSE; // Java Exception already thrown
	}

	// call function
	result = gdk_device_get_axis(self, axes, use, value);

	// cleanup parameter self

	// cleanup parameter axes
	(*env)->ReleaseDoubleArrayElements(env, _axes, (jdouble*)axes, 0);

	// cleanup parameter use

	// cleanup parameter value
	(*env)->ReleaseDoubleArrayElements(env, _value, (jdouble*)value, 0);

	// translate return value to JNI type
	_result = (jboolean) result;

	// and finally
	return _result;
}
void
gimp_device_info_get_time_coords (GimpDeviceInfo *info,
                                  GdkTimeCoord   *event,
                                  GimpCoords     *coords)
{
  *coords = default_coords;

  gdk_device_get_axis (info->device, event->axes, GDK_AXIS_X, &coords->x);
  gdk_device_get_axis (info->device, event->axes, GDK_AXIS_Y, &coords->y);

  /*  CLAMP() the return value of each *_get_axis() call to be safe
   *  against buggy XInput drivers.
   */

  if (gdk_device_get_axis (info->device,
                           event->axes, GDK_AXIS_PRESSURE, &coords->pressure))
    {
      coords->pressure = gimp_device_info_map_axis (info,
                                                    GDK_AXIS_PRESSURE,
                                                    coords->pressure);
    }

  if (gdk_device_get_axis (info->device,
                           event->axes, GDK_AXIS_XTILT, &coords->xtilt))
    {
      coords->xtilt = gimp_device_info_map_axis (info,
                                                 GDK_AXIS_XTILT,
                                                 coords->xtilt);
    }

  if (gdk_device_get_axis (info->device,
                           event->axes, GDK_AXIS_YTILT, &coords->ytilt))
    {
      coords->ytilt = gimp_device_info_map_axis (info,
                                                 GDK_AXIS_YTILT,
                                                 coords->ytilt);
    }

  if (gdk_device_get_axis (info->device,
                           event->axes, GDK_AXIS_WHEEL, &coords->wheel))
    {
      coords->wheel = gimp_device_info_map_axis (info,
                                                 GDK_AXIS_WHEEL,
                                                 coords->wheel);
    }

  if (gimp_device_info_get_mode (info)     != GDK_MODE_DISABLED &&
      gdk_device_get_source (info->device) != GDK_SOURCE_MOUSE)
    {
      /* The event was generated by an enabled extended non-mouse device */
      coords->extended = TRUE;
    }
  else
    {
      /* The event was generated by a not extended enabled device */
      coords->extended = FALSE;
    }
}
void
gimp_device_info_get_device_coords (GimpDeviceInfo *info,
                                    GdkWindow      *window,
                                    GimpCoords     *coords)
{
  gdouble axes[GDK_AXIS_LAST] = { 0, };

  *coords = default_coords;

  gdk_device_get_state (info->device, window, axes, NULL);

  gdk_device_get_axis (info->device, axes, GDK_AXIS_X, &coords->x);
  gdk_device_get_axis (info->device, axes, GDK_AXIS_Y, &coords->y);

  if (gdk_device_get_axis (info->device,
                           axes, GDK_AXIS_PRESSURE, &coords->pressure))
    {
      coords->pressure = gimp_device_info_map_axis (info,
                                                    GDK_AXIS_PRESSURE,
                                                    coords->pressure);
    }

  if (gdk_device_get_axis (info->device,
                           axes, GDK_AXIS_XTILT, &coords->xtilt))
    {
      coords->xtilt = gimp_device_info_map_axis (info,
                                                 GDK_AXIS_XTILT,
                                                 coords->xtilt);
    }

  if (gdk_device_get_axis (info->device,
                           axes, GDK_AXIS_YTILT, &coords->ytilt))
    {
      coords->ytilt = gimp_device_info_map_axis (info,
                                                 GDK_AXIS_YTILT,
                                                 coords->ytilt);
    }

  if (gdk_device_get_axis (info->device,
                           axes, GDK_AXIS_WHEEL, &coords->wheel))
    {
      coords->wheel = gimp_device_info_map_axis (info,
                                                 GDK_AXIS_WHEEL,
                                                 coords->wheel);
    }

  if (gimp_device_info_get_mode (info)     != GDK_MODE_DISABLED &&
      gdk_device_get_source (info->device) != GDK_SOURCE_MOUSE)
    {
      /* The event was generated by an enabled extended non-mouse device */
      coords->extended = TRUE;
    }
  else
    {
      /* The event was generated by a not extended enabled device */
      coords->extended = FALSE;
    }
}
Пример #5
0
/**
 * Get input data relative to current input page
 */
PositionInputData InputSequence::getInputDataRelativeToCurrentPage(XojPageView* page)
{
	XOJ_CHECK_TYPE(InputSequence);

	GtkXournal* xournal = inputHandler->getXournal();

	PositionInputData pos;
	pos.x = x - page->getX() - xournal->x;
	pos.y = y - page->getY() - xournal->y;
	pos.pressure = Point::NO_PRESSURE;
	pos.timestamp = this->eventTime;

	if (presureSensitivity)
	{
		gdk_device_get_axis(device, axes, GDK_AXIS_PRESSURE, &pos.pressure);
	}

	pos.state = this->state;

	return pos;
}
Пример #6
0
static VALUE
device_get_axis(VALUE self, VALUE rbaxes, VALUE rbuse)
{
    GdkDevice *device = _SELF(self);
    GdkAxisUse use = RVAL2GENUM(rbuse, GDK_TYPE_AXIS_USE);
    long n;
    gdouble *axes = RVAL2GDOUBLES(rbaxes, &n);
    gint device_n_axes = gdk_device_get_n_axes(device);
    gdouble value;
    gboolean found;

    if (n != device_n_axes)
        rb_raise(rb_eArgError,
                 "unexpected number of axes: %ld != %d",
                 n, device_n_axes);

    found = gdk_device_get_axis(device, axes, use, &value);

    g_free(axes);

    return found ? DBL2NUM(value) : Qnil;
}
Пример #7
0
void
gimp_device_info_get_time_coords (GimpDeviceInfo *info,
                                  GdkTimeCoord   *event,
                                  GimpCoords     *coords)
{
  *coords = default_coords;

  gdk_device_get_axis (info->device, event->axes, GDK_AXIS_X, &coords->x);
  gdk_device_get_axis (info->device, event->axes, GDK_AXIS_Y, &coords->y);

  /*  CLAMP() the return value of each *_get_axis() call to be safe
   *  against buggy XInput drivers.
   */

  if (gdk_device_get_axis (info->device,
                           event->axes, GDK_AXIS_PRESSURE, &coords->pressure))
    {
      coords->pressure = gimp_device_info_map_axis (info,
                                                    GDK_AXIS_PRESSURE,
                                                    coords->pressure);
    }

  if (gdk_device_get_axis (info->device,
                           event->axes, GDK_AXIS_XTILT, &coords->xtilt))
    {
      coords->xtilt = gimp_device_info_map_axis (info,
                                                 GDK_AXIS_XTILT,
                                                 coords->xtilt);
    }

  if (gdk_device_get_axis (info->device,
                           event->axes, GDK_AXIS_YTILT, &coords->ytilt))
    {
      coords->ytilt = gimp_device_info_map_axis (info,
                                                 GDK_AXIS_YTILT,
                                                 coords->ytilt);
    }

  if (gdk_device_get_axis (info->device,
                           event->axes, GDK_AXIS_WHEEL, &coords->wheel))
    {
      coords->wheel = gimp_device_info_map_axis (info,
                                                 GDK_AXIS_WHEEL,
                                                 coords->wheel);
    }
}
Пример #8
0
void
gimp_device_info_get_device_coords (GimpDeviceInfo *info,
                                    GdkWindow      *window,
                                    GimpCoords     *coords)
{
  gdouble axes[GDK_AXIS_LAST];

  *coords = default_coords;

  gdk_device_get_state (info->device, window, axes, NULL);

  gdk_device_get_axis (info->device, axes, GDK_AXIS_X, &coords->x);
  gdk_device_get_axis (info->device, axes, GDK_AXIS_Y, &coords->y);

  if (gdk_device_get_axis (info->device,
                           axes, GDK_AXIS_PRESSURE, &coords->pressure))
    {
      coords->pressure = gimp_device_info_map_axis (info,
                                                    GDK_AXIS_PRESSURE,
                                                    coords->pressure);
    }

  if (gdk_device_get_axis (info->device,
                           axes, GDK_AXIS_XTILT, &coords->xtilt))
    {
      coords->xtilt = gimp_device_info_map_axis (info,
                                                 GDK_AXIS_XTILT,
                                                 coords->xtilt);
    }

  if (gdk_device_get_axis (info->device,
                           axes, GDK_AXIS_YTILT, &coords->ytilt))
    {
      coords->ytilt = gimp_device_info_map_axis (info,
                                                 GDK_AXIS_YTILT,
                                                 coords->ytilt);
    }

  if (gdk_device_get_axis (info->device,
                           axes, GDK_AXIS_WHEEL, &coords->wheel))
    {
      coords->wheel = gimp_device_info_map_axis (info,
                                                 GDK_AXIS_WHEEL,
                                                 coords->wheel);
    }
}
Пример #9
0
static gboolean
motion_notify_event (GtkWidget      *widget,
                     GdkEventMotion *event,
                     ColorselWater  *water)
{
  GtkAllocation  allocation;
  GdkTimeCoord **coords;
  gint           nevents;
  gint           i;
  gboolean       erase;

  gtk_widget_get_allocation (widget, &allocation);

  if (event->state & (GDK_BUTTON1_MASK |
                      GDK_BUTTON2_MASK |
                      GDK_BUTTON3_MASK |
                      GDK_BUTTON4_MASK))
    {
      guint32 last_motion_time = event->time;

      erase = ((event->state &
                (GDK_BUTTON2_MASK | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK)) ||
               FALSE);
      /* FIXME: (event->source == GDK_SOURCE_ERASER) */

      if (event->state & GDK_SHIFT_MASK)
        erase = !erase;

      water->motion_time = event->time;

      if (gdk_device_get_history (event->device,
                                  event->window,
                                  last_motion_time,
                                  event->time,
                                  &coords,
                                  &nevents))
        {
          for (i = 0; i < nevents; i++)
            {
              gdouble x        = 0.0;
              gdouble y        = 0.0;
              gdouble pressure = 0.5;

              gdk_device_get_axis (event->device, coords[i]->axes,
                                   GDK_AXIS_X, &x);
              gdk_device_get_axis (event->device, coords[i]->axes,
                                   GDK_AXIS_Y, &y);
              gdk_device_get_axis (event->device, coords[i]->axes,
                                   GDK_AXIS_PRESSURE, &pressure);

              draw_brush (water, widget, erase,
                          x / allocation.width,
                          y / allocation.height, pressure);
            }

          g_free (coords);
        }
      else
        {
          gdouble pressure = 0.5;

          gdk_event_get_axis ((GdkEvent *) event, GDK_AXIS_PRESSURE, &pressure);

          draw_brush (water, widget, erase,
                      event->x / allocation.width,
                      event->y / allocation.height, pressure);
        }
    }

  /* Ask for more motion events in case the event was a hint */
  gdk_event_request_motions (event);

  return TRUE;
}
Пример #10
0
/**
 * gdk_event_get_axis:
 * @event: a #GdkEvent
 * @axis_use: the axis use to look for
 * @value: location to store the value found
 * 
 * Extract the axis value for a particular axis use from
 * an event structure.
 * 
 * Return value: %TRUE if the specified axis was found, otherwise %FALSE
 **/
gboolean
gdk_event_get_axis (const GdkEvent *event,
		    GdkAxisUse      axis_use,
		    gdouble        *value)
{
  gdouble *axes;
  GdkDevice *device;
  
  g_return_val_if_fail (event != NULL, FALSE);
  
  if (axis_use == GDK_AXIS_X || axis_use == GDK_AXIS_Y)
    {
      gdouble x, y;
      
      switch (event->type)
	{
	case GDK_MOTION_NOTIFY:
	  x = event->motion.x;
	  y = event->motion.y;
	  break;
	case GDK_SCROLL:
	  x = event->scroll.x;
	  y = event->scroll.y;
	  break;
	case GDK_BUTTON_PRESS:
	case GDK_BUTTON_RELEASE:
	  x = event->button.x;
	  y = event->button.y;
	  break;
	case GDK_ENTER_NOTIFY:
	case GDK_LEAVE_NOTIFY:
	  x = event->crossing.x;
	  y = event->crossing.y;
	  break;
	  
	default:
	  return FALSE;
	}

      if (axis_use == GDK_AXIS_X && value)
	*value = x;
      if (axis_use == GDK_AXIS_Y && value)
	*value = y;

      return TRUE;
    }
  else if (event->type == GDK_BUTTON_PRESS ||
	   event->type == GDK_BUTTON_RELEASE)
    {
      device = event->button.device;
      axes = event->button.axes;
    }
  else if (event->type == GDK_MOTION_NOTIFY)
    {
      device = event->motion.device;
      axes = event->motion.axes;
    }
  else
    return FALSE;

  return gdk_device_get_axis (device, axes, axis_use, value);
}
Пример #11
0
gboolean on_motion (GtkWidget *win,
		    GdkEventMotion *ev,
		    gpointer user_data)
{
  GromitData *data = (GromitData *) user_data;
  GdkTimeCoord **coords = NULL;
  gint nevents;
  int i;
  gdouble pressure = 0.5;

  /* get the data for this device */
  GdkDevice *master = ev->device;
  GromitDeviceData *masterdata =
    g_hash_table_lookup(data->devdatatable, master);

  if (!masterdata->is_grabbed)
    return FALSE;

  GdkDevice *slave =
    gdk_event_get_source_device ((GdkEvent *) ev);
  GromitDeviceData *slavedata =
    g_hash_table_lookup(data->devdatatable, slave);

  if (ev->state != masterdata->state ||
      ev->state != slavedata->state ||
      masterdata->lastslave != slave)
    select_tool (data, master, slave, ev->state);

  if(!(ev->state & (GDK_BUTTON1_MASK|
                    GDK_BUTTON2_MASK|
                    GDK_BUTTON3_MASK|
                    GDK_BUTTON4_MASK|
                    GDK_BUTTON5_MASK)))
    return TRUE;

  gdk_device_get_history (slave, ev->window,
                          slavedata->motion_time, ev->time,
                          &coords, &nevents);

  if(!data->xinerama && nevents > 0)
    {
      for (i=0; i < nevents; i++)
        {
          gdouble x, y;

          gdk_device_get_axis (slave, coords[i]->axes,
                               GDK_AXIS_PRESSURE, &pressure);
          if (pressure > 0)
            {
              if (gdk_device_get_source(slave) == GDK_SOURCE_MOUSE)
                data->maxwidth = slavedata->cur_context->width;
              else
		data->maxwidth = (CLAMP (pressure + line_thickener, 0, 1) *
				  (double) (slavedata->cur_context->width -
					    slavedata->cur_context->minwidth) +
				  slavedata->cur_context->minwidth);

              gdk_device_get_axis(slave, coords[i]->axes,
                                  GDK_AXIS_X, &x);
              gdk_device_get_axis(slave, coords[i]->axes,
                                  GDK_AXIS_Y, &y);

	      draw_line (data, slave, slavedata->lastx, slavedata->lasty, x, y);

              coord_list_prepend (data, slave, x, y, data->maxwidth);
              slavedata->lastx = x;
              slavedata->lasty = y;
            }
        }

      slavedata->motion_time = coords[nevents-1]->time;
      g_free (coords);
    }

  /* always paint to the current event coordinate. */
  gdk_event_get_axis ((GdkEvent *) ev, GDK_AXIS_PRESSURE, &pressure);

  if (pressure > 0)
    {
      if (gdk_device_get_source(slave) == GDK_SOURCE_MOUSE)
	data->maxwidth = slavedata->cur_context->width;
      else
	data->maxwidth = (CLAMP (pressure + line_thickener, 0, 1) *
			  (double) (slavedata->cur_context->width -
				    slavedata->cur_context->minwidth) +
			  slavedata->cur_context->minwidth);

      if(slavedata->motion_time > 0)
	{
	  draw_line (data, slave, slavedata->lastx, slavedata->lasty, ev->x, ev->y);
	  coord_list_prepend (data, slave, ev->x, ev->y, data->maxwidth);
	}
    }

  slavedata->lastx = ev->x;
  slavedata->lasty = ev->y;
  slavedata->motion_time = ev->time;

  return TRUE;
}