Beispiel #1
0
static VALUE
style_paint_polygon(VALUE self, VALUE gdkwindow, VALUE state_type, VALUE shadow_type, VALUE area, VALUE widget, VALUE detail, VALUE points, VALUE fill)
{
    int i;
    GdkPoint* gpoints = g_new (GdkPoint, RARRAY_LEN(points));

    for (i = 0; i < RARRAY_LEN(points); i++){
        gpoints[i].x = RARRAY_PTR(RARRAY_PTR(points)[i])[0];
        gpoints[i].y = RARRAY_PTR(RARRAY_PTR(points)[i])[1];
    }
    gtk_paint_polygon(_SELF(self), GDK_WINDOW(RVAL2GOBJ(gdkwindow)),
                      RVAL2STATE(state_type), RVAL2SHADOW(shadow_type), RVAL2REC(area),
                      GTK_WIDGET(RVAL2GOBJ(widget)), 
                      NIL_P(detail) ? NULL : RVAL2CSTR(detail), gpoints,
                      RARRAY_LEN(points), RVAL2CBOOL(fill));
    return self;
}
Beispiel #2
0
static gboolean
gtk_dial_expose( GtkWidget      *widget,
		 GdkEventExpose *event )
{
  GtkDial *dial;
  GdkPoint points[6];
  gdouble s,c;
  gdouble theta, last, increment;
  GtkStyle      *blankstyle;
  gint xc, yc;
  gint upper, lower;
  gint tick_length;
  gint i, inc;

  g_return_val_if_fail (widget != NULL, FALSE);
  g_return_val_if_fail (GTK_IS_DIAL (widget), FALSE);
  g_return_val_if_fail (event != NULL, FALSE);

  if (event->count > 0)
    return FALSE;
  
  dial = GTK_DIAL (widget);

/*  gdk_window_clear_area (widget->window,
			 0, 0,
			 widget->allocation.width,
			 widget->allocation.height);
*/
  xc = widget->allocation.width / 2;
  yc = widget->allocation.height / 2;

  upper = (int) dial->adjustment->upper;
  lower = (int) dial->adjustment->lower;

  /* Erase old pointer */

  s = sin (dial->last_angle);
  c = cos (dial->last_angle);
  dial->last_angle = dial->angle;

  points[0].x = (int) ( xc + s*dial->pointer_width/2 );
  points[0].y = (int) ( yc + c*dial->pointer_width/2 );
  points[1].x = (int) ( xc + c*dial->radius );
  points[1].y = (int) ( yc - s*dial->radius );
  points[2].x = (int) ( xc - s*dial->pointer_width/2 );
  points[2].y = (int) ( yc - c*dial->pointer_width/2 );
  points[3].x = (int) ( xc - c*dial->radius/10 );
  points[3].y = (int) ( yc + s*dial->radius/10 );
  points[4].x = (int) ( points[0].x );
  points[4].y = (int) ( points[0].y );

  blankstyle = gtk_style_new ();
  blankstyle->bg_gc[GTK_STATE_NORMAL] =
                widget->style->bg_gc[GTK_STATE_NORMAL];
  blankstyle->dark_gc[GTK_STATE_NORMAL] =
                widget->style->bg_gc[GTK_STATE_NORMAL];
  blankstyle->light_gc[GTK_STATE_NORMAL] =
                widget->style->bg_gc[GTK_STATE_NORMAL];
  blankstyle->black_gc =
                widget->style->bg_gc[GTK_STATE_NORMAL];

  gtk_paint_polygon (blankstyle,
                    widget->window,
                    GTK_STATE_NORMAL,
                    GTK_SHADOW_OUT,
	            NULL,
                    widget,
                    NULL,
                    points, 5,
                    FALSE);

  g_object_unref (blankstyle);


  /* Draw ticks */

  if ((upper - lower) == 0)
    return FALSE;

  increment = ( (100*M_PI) / (dial->radius*dial->radius) );

  inc = (int) ( (upper - lower) );

  while (inc < 100) inc *= 10;
  while (inc >= 1000) inc /= 10;
  last = (int) ( -1 );

  for (i = (int) ( 0 ); i <= inc; i++)
    {
      theta = (int) ( ((gfloat)i*M_PI / (18*inc/24.) - M_PI/6.) );

      if ((theta - last) < (increment))
	continue;     
      last = (int) ( theta );

      s = (int) ( sin (theta) );
      c = (int) ( cos (theta) );

      tick_length = (int) ( (i%(inc/10) == 0) ? dial->pointer_width : dial->pointer_width / 2 );

      gdk_draw_line(
        widget->window,
        widget->style->fg_gc[widget->state],
        (int) (xc + c*(dial->radius - tick_length)),
        (int) (yc - s*(dial->radius - tick_length)),
        (int) (xc + c*dial->radius),
        (int) (yc - s*dial->radius)
      );
    }

  /* Draw pointer */

  s = ( sin (dial->angle) );
  c = ( cos (dial->angle) );
  dial->last_angle = ( dial->angle );

  points[0].x = (int) ( xc + s*dial->pointer_width/2 );
  points[0].y = (int) ( yc + c*dial->pointer_width/2 );
  points[1].x = (int) ( xc + c*dial->radius );
  points[1].y = (int) ( yc - s*dial->radius );
  points[2].x = (int) ( xc - s*dial->pointer_width/2 );
  points[2].y = (int) ( yc - c*dial->pointer_width/2 );
  points[3].x = (int) ( xc - c*dial->radius/10 );
  points[3].y = (int) ( yc + s*dial->radius/10 );
  points[4].x = (int) ( points[0].x );
  points[4].y = (int) ( points[0].y );

  gtk_paint_polygon (
    widget->style,
    widget->window,
    GTK_STATE_NORMAL,
    GTK_SHADOW_OUT,
    NULL,
    widget,
    NULL,
    points, 5,
    TRUE
  );

  return FALSE;
}