Ejemplo n.º 1
0
static void
polygon_view_draw (PolygonView *self, cairo_t *cr)
{
    polygon_t *polygon;
    gdouble sf_x, sf_y, sf;
    gdouble mid, dim;
    gdouble x0,  y0;
    box_t extents;

    extents = self->extents;

    mid = (extents.p2.x + extents.p1.x) / 2.;
    dim = (extents.p2.x - extents.p1.x) / 2. * 1.25;
    sf_x = self->widget.allocation.width / dim / 2;

    mid = (extents.p2.y + extents.p1.y) / 2.;
    dim = (extents.p2.y - extents.p1.y) / 2. * 1.25;
    sf_y = self->widget.allocation.height / dim / 2;

    sf = MIN (sf_x, sf_y);

    mid = (extents.p2.x + extents.p1.x) / 2.;
    dim = sf_x / sf * (extents.p2.x - extents.p1.x) / 2. * 1.25;
    x0 = mid - dim;
    mid = (extents.p2.y + extents.p1.y) / 2.;
    dim = sf_y / sf * (extents.p2.y - extents.p1.y) / 2. * 1.25;
    y0 = mid - dim;

    if (self->pixmap_width != self->widget.allocation.width ||
	self->pixmap_height != self->widget.allocation.height)
    {
	cairo_surface_destroy (self->pixmap);
	self->pixmap = pixmap_create (self, cairo_get_target (cr));
	self->pixmap_width = self->widget.allocation.width;
	self->pixmap_height = self->widget.allocation.height;
    }

    cairo_set_source_surface (cr, self->pixmap, 0, 0);
    cairo_paint (cr);

    if (self->polygons == NULL)
	return;

    /* draw a zoom view of the area around the mouse */
    if (1) {
	double zoom = self->mag_zoom;
	int size = self->mag_size;
	int mag_x = self->mag_x;
	int mag_y = self->mag_y;

	if (1) {
	    if (self->px + size < self->widget.allocation.width/2)
		mag_x = self->px + size/4;
	    else
		mag_x = self->px - size/4 - size;
	    mag_y = self->py - size/2;
	    if (mag_y < 0)
		mag_y = 0;
	    if (mag_y + size > self->widget.allocation.height)
		mag_y = self->widget.allocation.height - size;
	}

	cairo_save (cr); {
	    /* bottom right */
	    cairo_rectangle (cr, mag_x, mag_y, size, size);
	    cairo_stroke_preserve (cr);
	    cairo_set_source_rgb (cr, 1, 1, 1);
	    cairo_fill_preserve (cr);
	    cairo_clip (cr);

	    /* compute roi in extents */
	    cairo_translate (cr, mag_x + size/2, mag_y + size/2);

	    cairo_save (cr); {
		cairo_scale (cr, zoom, zoom);
		cairo_translate (cr, -(self->px / sf + x0), -(self->py /sf + y0));
		for (polygon = self->polygons; polygon; polygon = polygon->next) {
		    if (polygon->num_edges == 0)
			continue;

		    draw_polygon (cr, polygon, zoom);
		}

		if (highlight != -1) {
		    cairo_move_to (cr, extents.p1.x, highlight);
		    cairo_line_to (cr, extents.p2.x, highlight);
		    cairo_set_source_rgb (cr, 0, .7, 0);
		    cairo_save (cr);
		    cairo_identity_matrix (cr);
		    cairo_set_line_width (cr, 1.);
		    cairo_stroke (cr);
		    cairo_restore (cr);
		}
	    } cairo_restore (cr);

	    /* grid */
	    cairo_save (cr); {
		int i;

		cairo_translate (cr,
				 -zoom*fmod (self->px/sf + x0, 1.),
				 -zoom*fmod (self->py/sf + y0, 1.));
		zoom /= 2;
		for (i = -size/2/zoom; i <= size/2/zoom + 1; i+=2) {
		    cairo_move_to (cr, zoom*i, -size/2);
		    cairo_line_to (cr, zoom*i, size/2 + zoom);
		    cairo_move_to (cr, -size/2, zoom*i);
		    cairo_line_to (cr, size/2 + zoom, zoom*i);
		}
		zoom *= 2;
		cairo_set_source_rgba (cr, .7, .7, .7, .5);
		cairo_set_line_width (cr, 1.);
		cairo_stroke (cr);

		for (i = -size/2/zoom - 1; i <= size/2/zoom + 1; i++) {
		    cairo_move_to (cr, zoom*i, -size/2);
		    cairo_line_to (cr, zoom*i, size/2 + zoom);
		    cairo_move_to (cr, -size/2, zoom*i);
		    cairo_line_to (cr, size/2 + zoom, zoom*i);
		}
		cairo_set_source_rgba (cr, .1, .1, .1, .5);
		cairo_set_line_width (cr, 2.);
		cairo_stroke (cr);
	    } cairo_restore (cr);

	} cairo_restore (cr);
    }
}
Ejemplo n.º 2
0
bool PageView::paintPage(cairo_t* cr, GdkRectangle* rect)
{
	XOJ_CHECK_TYPE(PageView);

	static const char* txtLoading = _("Loading...");

	double zoom = xournal->getZoom();

	g_mutex_lock(this->drawingMutex);

	int dispWidth = getDisplayWidth();
	int dispHeight = getDisplayHeight();

	if (this->crBuffer == NULL)
	{
		this->crBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, dispWidth,
		                                            dispHeight);
		cairo_t* cr2 = cairo_create(this->crBuffer);
		cairo_set_source_rgb(cr2, 1, 1, 1);
		cairo_rectangle(cr2, 0, 0, dispWidth, dispHeight);
		cairo_fill(cr2);

		cairo_scale(cr2, zoom, zoom);

		cairo_text_extents_t ex;
		cairo_set_source_rgb(cr2, 0.5, 0.5, 0.5);
		cairo_select_font_face(cr2, "Sans", CAIRO_FONT_SLANT_NORMAL,
		                       CAIRO_FONT_WEIGHT_BOLD);
		cairo_set_font_size(cr2, 32.0);
		cairo_text_extents(cr2, txtLoading, &ex);
		cairo_move_to(cr2, (page->getWidth() - ex.width) / 2 - ex.x_bearing,
		              (page->getHeight() - ex.height) / 2 - ex.y_bearing);
		cairo_show_text(cr2, txtLoading);

		cairo_destroy(cr2);
		rerenderPage();
	}

	cairo_save(cr);

	double width = cairo_image_surface_get_width(this->crBuffer);
	if (width != dispWidth)
	{
		double scale = ((double) dispWidth) / ((double) width);

		// Scale current image to fit the zoom level
		cairo_scale(cr, scale, scale);
		cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_FAST);

		cairo_set_source_surface(cr, this->crBuffer, 0, 0);

		rerenderPage();

		rect = NULL;
	}
	else
	{
		cairo_set_source_surface(cr, this->crBuffer, 0, 0);
	}

	if (rect)
	{
		cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height);
		cairo_fill(cr);

#ifdef SHOW_PAINT_BOUNDS
		cairo_set_source_rgb(cr, 1.0, 0.5, 1.0);
		cairo_set_line_width(cr, 1. / zoom);
		cairo_rectangle(cr, rect->x, rect->y, rect->width, rect->height);
		cairo_stroke(cr);
#endif
	}
	else
	{
		cairo_paint(cr);
	}

	cairo_restore(cr);

	// don't paint this with scale, because it needs a 1:1 zoom
	if (this->verticalSpace)
	{
		this->verticalSpace->paint(cr, rect, zoom);
	}

	cairo_scale(cr, zoom, zoom);

	if (this->textEditor)
	{
		this->textEditor->paint(cr, rect, zoom);
	}
	if (this->selection)
	{
		this->selection->paint(cr, rect, zoom);
	}

	if (this->search)
	{
		this->search->paint(cr, rect, zoom, getSelectionColor());
	}
	this->inputHandler->draw(cr, zoom);
	g_mutex_unlock(this->drawingMutex);
	return true;
}
Ejemplo n.º 3
0
/**
 * Function: dataset_draw
 *
 * Draws the dataset's trajectories into a PNG image highlighting different
 * groups with different colors.
 *
 * Parameters:
 *
 *   config  - pointer to a <visualize_config_t> structure containing
 *             information about the size of the image to generate and to what
 *             file it should be saved to
 *
 *   dataset - pointer to a dataset
 *
 *   groups  - pointer to a groups list
 */
void dataset_draw(visualize_config_t* config, dataset_t* dataset, group_list_t* groups)
{
    unsigned char* imgbuf;
    cairo_surface_t* surface;
    cairo_t* cr;
    double scale_x;
    double scale_y;
    int g;
    int t;
    int s;
    int n_groups;
    group_t* gl;
    double* c;
    char filename_buf[256];

    /* allocate memory for image buffer -- the area Cairo will draw in */
    if((imgbuf = malloc(sizeof(unsigned char) * config->width * config->height * 4)) == NULL)
    {
        printf("Cannot allocate memory for image buffer.\n");
        return;
    }

    /* create a drawing surface */
    surface = cairo_image_surface_create_for_data(
                  imgbuf,
                  CAIRO_FORMAT_ARGB32,
                  config->width,
                  config->height,
                  config->width * 4
              );

    /* create a cairo context on the surface */
    cr = cairo_create(surface);

    /* compute the scaling factor based on the size of the dataset grid and the
     * size of the image */
    scale_x = (double)config->width / (double)dataset->grid_size;
    scale_y = (double)config->height / (double)dataset->grid_size;

    /* set the line width */
    cairo_set_line_width(cr, config->line_width);

    /* a dataset can define its own groups, use those as default if there are
     * any */
    n_groups = dataset->n_groups;
    gl = dataset->groups;

    /* if there is an explicitly defined set of groups, use those instead */
    if(groups && (groups->n_groups > 0))
    {
        n_groups = groups->n_groups;
        gl = groups->groups;
    }

    /* if there are no groups defined or we only draw one image, fill the
     * surface with white background */
    if(!config->split || n_groups == 0)
    {
        cairo_rectangle(cr, 0, 0, (double)config->width, (double)config->height);
        cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
        cairo_fill(cr);
    }

    /* FIXME: don't know what happens here, I think this draws the entire
     * dataset */
    dataset_draw_help( config, dataset, groups, cr );

    /* If there are groups defined draw each group individually. */
    if(n_groups > 0)
    {
        /* for each group */
        for(g = 0; g < n_groups; g++)
        {
            /* If we split up the group into individual images, we need to
             * clear the current surface with a white background. */
            if(config->split)
            {
                cairo_rectangle(cr, 0, 0, (double)config->width, (double)config->height);
                cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
                cairo_fill(cr);
                dataset_draw_help( config, dataset, groups, cr );    // inserted ~~ wih fray
            }

            /* for each trajectory in the group */
            for(t = 0; t < gl[g].n_trajectories; t++)
            {
                trajectory_t* tr =
                    &dataset->trajectories[gl[g].trajectories[t]];
                /* move to the beginning of the trajectory */
                cairo_move_to(
                    cr,
                    (double)tr->samples[0].x * scale_x,
                    config->height - ((double)tr->samples[0].y * scale_y)
                );

                /* now draw a polyline by iterating through each of the
                 * trajectory's samples */
                for(s = 1; s < tr->n_samples; s++)
                    cairo_line_to(
                        cr,
                        (double)tr->samples[s].x * scale_x,
                        config->height - ((double)tr->samples[s].y * scale_y)
                    );
            }

            /* If groups should have a different color than the other
             * (non-grouped) trajectories (config->highlight) and the current
             * group is in fact a group of more than one trajectories, then pick a
             * different color. */
            if(config->highlight && gl[g].n_trajectories != 1)
            {
                fprintf(stderr, "Size of colors: %d\n", (g % (sizeof(colors) / 24)) * 3);
                c = &colors[(g % (sizeof(colors) / 24)) * 3];
                cairo_set_source_rgb(cr, c[0], c[1], c[2]);
            }
            else
                /* otherwise draw everything greenish */
                cairo_set_source_rgb(cr, 0.0, 0.7, 0.0);

            /* finally draw all of the group */
            cairo_stroke(cr);

            /* If we split groups in separate images, construct a filename and
             * write the image for the current group. */
            if(config->split)
            {
                snprintf(filename_buf, sizeof(filename_buf), config->output, g);
                cairo_surface_write_to_png(surface, filename_buf);
            }
        }
    }

    /* If the groups were not split into separate images, then write only a
     * single image. */
    if(!config->split || n_groups == 0)
        cairo_surface_write_to_png(surface, config->output);

    /* free up all that memory */
    cairo_destroy(cr);
    cairo_surface_destroy(surface);
    free(imgbuf);
}
Ejemplo n.º 4
0
static void
draw_page (GtkPrintOperation *operation,
           GtkPrintContext   *context,
           gint               page_number,
           gpointer           user_data)
{
  GdictPrintData *data = user_data;
  cairo_t *cr;
  PangoLayout *layout;
  gint text_width, text_height;
  gdouble width;
  gint line, i;
  PangoFontDescription *desc;
  gchar *page_str;

  cr = gtk_print_context_get_cairo_context (context);
  width = gtk_print_context_get_width (context);

  cairo_rectangle (cr, 0, 0, width, HEADER_HEIGHT (10));
  
  cairo_set_source_rgb (cr, 0.8, 0.8, 0.8);
  cairo_fill_preserve (cr);
  
  cairo_set_source_rgb (cr, 0, 0, 0);
  cairo_set_line_width (cr, 1);
  cairo_stroke (cr);

  /* header */
  layout = gtk_print_context_create_pango_layout (context);

  desc = pango_font_description_from_string ("sans 14");
  pango_layout_set_font_description (layout, desc);
  pango_font_description_free (desc);

  pango_layout_set_text (layout, data->word, -1);
  pango_layout_get_pixel_size (layout, &text_width, &text_height);

  if (text_width > width)
    {
      pango_layout_set_width (layout, width);
      pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_START);
      pango_layout_get_pixel_size (layout, &text_width, &text_height);
    }

  cairo_move_to (cr, (width - text_width) / 2,
                     (HEADER_HEIGHT (10) - text_height) / 2);
  pango_cairo_show_layout (cr, layout);

  page_str = g_strdup_printf ("%d/%d", page_number + 1, data->n_pages);
  pango_layout_set_text (layout, page_str, -1);
  g_free (page_str);

  pango_layout_set_width (layout, -1);
  pango_layout_get_pixel_size (layout, &text_width, &text_height);
  cairo_move_to (cr, width - text_width - 4,
                     (HEADER_HEIGHT (10) - text_height) / 2);
  pango_cairo_show_layout (cr, layout);
  
  g_object_unref (layout);

  /* text */
  layout = gtk_print_context_create_pango_layout (context);
  pango_font_description_set_size (data->font_desc,
                                   data->font_size * PANGO_SCALE);
  pango_layout_set_font_description (layout, data->font_desc);
  
  cairo_move_to (cr, 0, HEADER_HEIGHT (10) + HEADER_GAP (3));
  line = page_number * data->lines_per_page;
  for (i = 0; i < data->lines_per_page && line < data->n_lines; i++) 
    {
      pango_layout_set_text (layout, data->lines[line], -1);

      pango_cairo_show_layout (cr, layout);
      cairo_rel_move_to (cr, 0, data->font_size);
      line++;
    }

  g_object_unref (layout);
}
Ejemplo n.º 5
0
/* 
 * function to draw the rectangular selection
 */
static void
paint_selection (cairo_t *ci, Detect * d)
{

	double t =  microtime();

	int w = cairo_image_surface_get_width (surface);
	int h = cairo_image_surface_get_height (surface);

	/** draw brush */ /*
	cairo_surface_t* test;
	cairo_t *cb;
	double brush_w = 70, brush_h = 70;
	int w = cairo_image_surface_get_width (image);
	int h = cairo_image_surface_get_height (image);

	test = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, w, h );
	cb = cairo_create(test);
	cairo_scale (cb, brush_w/w, brush_h/h);
	cairo_set_source_surface (cb, image, 0, 0);
	cairo_mask_surface(cb, test, 0, 0);

	cairo_paint(cb);

	cairo_destroy (cb);

//    cairo_set_source_rgb (ci, 0.5,0.5,0.5);
	cairo_paint(ci);

	cairo_set_source_surface (ci, test, mouse->x-(brush_w/2),mouse->y-(brush_h/2));
	cairo_paint(ci);
	*/	

   d_events * events;
   d_events::iterator it_events;
   events = d->GetEvents();
   MousePosition mouse;

	/*	mouse->x = 100;
	mouse->y = 100;
	mouse->prev_x = 250;
	mouse->prev_y = 100;*/

   //cairo_save (ci);

   //printf("size %d \n",events->size());

   for(it_events = events->begin(); it_events!= events->end(); it_events++){ 
      if(it_events->second.live ){

          mouse.x = (gint) (w*(1-it_events->second.x));
          mouse.y = (gint) (h*it_events->second.y);
          mouse.prev_x = (gint) (w*(1-it_events->second.last[1].x));
          mouse.prev_y = (gint) (h*(it_events->second.last[1].y));
          mouse.bold = it_events->second.size; 

         // printf("mouse: %d %d %d | ", mouse.x, mouse.y, mouse.bold);
          //printf("mouse: %d %d %d | ", mouse.prev_x, mouse.prev_y, mouse.bold);
          //printf("mouse: %f %f | %f %f \n", it_events->second.x, it_events->second.y, it_events->second.last[1].x, it_events->second.last[1].y);

        /*cairo_set_source_rgba (ci, 255,0,0, 1.);
        cairo_arc (ci, mouse.x,mouse.y, 20, 0, 2 * M_PI);
        cairo_fill_preserve (ci);
        cairo_stroke (ci);*/

        //printf("%f %f\n",mouse->f_x,mouse->f_y);
        //if(!(mouse->f_x>0 && mouse->f_y > 0)) return;

        //mouse->x = (int) (w-mouse->f_x*w);
        //mouse->y = (int) (mouse->f_y*h);
        //printf("(%d %d) %d %d < %f %f\n",w,h,mouse->x,mouse->y,mouse->f_x,mouse->f_y);

        /* proložení vykreslování */
        float test_t = sqrt(pow(mouse.x-mouse.prev_x,2) + pow(mouse.y-mouse.prev_y,2));

        int size_brush;
        //omezení pokud jsou velké skoky
        if(test_t==0 || test_t > 100) break;

        if(brush_type == 0 || brush_type==3){
            size_brush = (mouse.bold / 2) - 5;
            if(size_brush < 5) size_brush = 5;
            if(size_brush > 20) size_brush = 20;
            cairo_set_line_width (ci, 0.);
         } else {
            size_brush = mouse.bold / 10;
            if(size_brush > 5) size_brush = 5;
            if(size_brush < 1) size_brush = 1;
         }

        // printf("brush %d \n", size_brush); 

         int step = int (test_t/size_brush);
         int rate_rand = 10;
         //printf("%d %d\n",size_brush, mouse->bold);
         //délka jednoho tahu
         double step_x = (mouse.x - mouse.prev_x)/(double) step;
         double step_y = (mouse.y - mouse.prev_y)/(double) step;

         float aplha = 1.;

         if (brush_type == 3) aplha = 0.3;
      
         if(brush_type == 2) {
            aplha = 0.2;
//            size_brush = 5;
         }
        // printf("color: %f %f %f\n",color.r, color.g, color.b);
      
        /* proložení ploch */
       if(brush_type == 0){
        for(int i=0; i < step+1; i++){
            if(brush_type == 0){
                cairo_set_source_rgba (ci, color.r, color.g, color.b, 1.);
                cairo_arc (ci, mouse.prev_x+step_x*i,mouse.prev_y+step_y*i,  size_brush, 0, 2 * M_PI);
                cairo_fill_preserve (ci);
                cairo_stroke (ci);
            } else {
                cairo_set_source_rgba (ci, color.r, color.g, color.b, aplha);
                for(int j=0; j < 5; j++){
               //		printf("%f ",10*(drand48()*2.-1.));
                  cairo_arc (ci, (mouse.prev_x+step_x*i)+rate_rand*(drand48()*2.-1.), (mouse.prev_y+step_y*i)+rate_rand*(drand48()*2.-1.),  size_brush, 0, 2 * M_PI);
                  cairo_fill_preserve (ci);
                  cairo_stroke (ci);
               }
            }
        }
}
        //vykreslení plochy
       if(brush_type == 0){
          cairo_set_source_rgba (ci, color.r, color.g, color.b, 1.);
          cairo_arc (ci, mouse.x, mouse.y,  size_brush, 0, 2 * M_PI);
          cairo_fill_preserve (ci);
          cairo_stroke (ci);
       } else {
          cairo_set_source_rgba (ci, color.r, color.g, color.b, aplha);
          for(int j=0; j < 8; j++){
      //		printf("%f ",10*(drand48()*2.-1.));
            cairo_arc (ci, mouse.x+rate_rand*(drand48()*2.5-1.), mouse.y+rate_rand*(drand48()*2.5-1.),  ((int) size_brush), 0, 2 * M_PI);
            cairo_fill_preserve (ci);
            cairo_stroke (ci);
          }
       }
   }
}

   //	cairo_restore (ci);
   if(image!=NULL){
      int _w = cairo_image_surface_get_width (image);
      int _h = cairo_image_surface_get_height (image);
      //cairo_surface_t* test;
      //cairo_t *cb;
      //test = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, _w, _h );
       //printf("%d %d\n",_w,_h);
      //cb = cairo_create(test);
       cairo_scale  (ci, w/(double)_w, h/(double)_h);
       cairo_set_source_surface (ci, image, 0, 0);
       cairo_paint(ci);
   }
      cairo_restore (ci);


        timer[1] =  microtime() - t;
}
Ejemplo n.º 6
0
static void _draw_mode_toggle(cairo_t *cr, float x, float y, float width, float height, int type)
{
  cairo_save(cr);
  cairo_translate(cr, x, y);

  // border
  float border = MIN(width * .1, height * .1);
  cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.4);
  cairo_rectangle(cr, border, border, width - 2.0 * border, height - 2.0 * border);
  cairo_fill_preserve(cr);
  cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.5);
  cairo_set_line_width(cr, border);
  cairo_stroke(cr);

  // icon
  cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5);
  cairo_move_to(cr, 2.0 * border, height - 2.0 * border);
  switch(type)
  {
    case DT_DEV_HISTOGRAM_LINEAR:
      cairo_line_to(cr, width - 2.0 * border, 2.0 * border);
      cairo_stroke(cr);
      break;
    case DT_DEV_HISTOGRAM_LOGARITHMIC:
      cairo_curve_to(cr, 2.0 * border, 0.33 * height, 0.66 * width, 2.0 * border, width - 2.0 * border,
                     2.0 * border);
      cairo_stroke(cr);
      break;
    case DT_DEV_HISTOGRAM_WAVEFORM:
    {
      cairo_pattern_t *pattern;
      pattern = cairo_pattern_create_linear(0.0, 1.5 * border, 0.0, height - 3.0 * border);

      cairo_pattern_add_color_stop_rgba(pattern, 0.0, 0.0, 0.0, 0.0, 0.5);
      cairo_pattern_add_color_stop_rgba(pattern, 0.2, 0.2, 0.2, 0.2, 0.5);
      cairo_pattern_add_color_stop_rgba(pattern, 0.5, 1.0, 1.0, 1.0, 0.5);
      cairo_pattern_add_color_stop_rgba(pattern, 0.6, 1.0, 1.0, 1.0, 0.5);
      cairo_pattern_add_color_stop_rgba(pattern, 1.0, 0.2, 0.2, 0.2, 0.5);

      cairo_rectangle(cr, 1.5 * border, 1.5 * border, (width - 3.0 * border) * 0.3, height - 3.0 * border);
      cairo_set_source(cr, pattern);
      cairo_fill(cr);

      cairo_save(cr);
      cairo_scale(cr, 1, -1);
      cairo_translate(cr, 0, -height);
      cairo_rectangle(cr, 1.5 * border + (width - 3.0 * border) * 0.2, 1.5 * border,
                      (width - 3.0 * border) * 0.6, height - 3.0 * border);
      cairo_set_source(cr, pattern);
      cairo_fill(cr);
      cairo_restore(cr);

      cairo_rectangle(cr, 1.5 * border + (width - 3.0 * border) * 0.7, 1.5 * border,
                      (width - 3.0 * border) * 0.3, height - 3.0 * border);
      cairo_set_source(cr, pattern);
      cairo_fill(cr);

      cairo_pattern_destroy(pattern);
      break;
    }
  }
  cairo_restore(cr);
}
Ejemplo n.º 7
0
void Viewport::prepareContext(const Object* obj){
    const GdkRGBA color = obj->getColor();
    cairo_set_source_rgb(m_cairo, color.red, color.green, color.blue);
    cairo_set_line_width(m_cairo, ((obj==m_border) ? 3 : 1) );//Pequena gambiarra...
}
static void
clearlooks_inverted_draw_list_view_header (cairo_t *cr,
                                  const ClearlooksColors          *colors,
                                  const WidgetParameters          *params,
                                  const ListViewHeaderParameters  *header,
                                  int x, int y, int width, int height)
{
	const CairoColor *fill = &colors->bg[params->state_type];
	const CairoColor *border = &colors->shade[4];
	cairo_pattern_t *pattern;
	CairoColor hilight_header;
	CairoColor hilight;
	CairoColor shadow;

	ge_shade_color (border, 1.5, &hilight);
	ge_shade_color (fill, 1.05, &hilight_header);	
	ge_shade_color (fill, 0.95, &shadow);	

	cairo_translate (cr, x, y);
	cairo_set_line_width (cr, 1.0);
	
	/* Draw highlight */
	if (header->order & CL_ORDER_FIRST)
	{
		cairo_move_to (cr, 0.5, height-1);
		cairo_line_to (cr, 0.5, 0.5);
	}
	else
		cairo_move_to (cr, 0.0, 0.5);
	
	cairo_line_to (cr, width, 0.5);
	
	ge_cairo_set_color (cr, &hilight);
	cairo_stroke (cr);
	
	/* Draw bottom border */
	cairo_move_to (cr, 0.0, height-0.5);
	cairo_line_to (cr, width, height-0.5);
	ge_cairo_set_color (cr, border);
	cairo_stroke (cr);

	/* Draw bottom shade */	
	pattern = cairo_pattern_create_linear (0.0, 0, 0.0, height-1.0);
	cairo_pattern_add_color_stop_rgb     (pattern, 0.0, shadow.r, shadow.g, shadow.b);
	cairo_pattern_add_color_stop_rgb     (pattern, 1.0, hilight_header.r, hilight_header.g, hilight_header.b);

	cairo_rectangle       (cr, 0, 1, width, height-2);
	cairo_set_source      (cr, pattern);
	cairo_fill            (cr);
	cairo_pattern_destroy (pattern);
	
	/* Draw resize grip */
	if ((params->ltr && !(header->order & CL_ORDER_LAST)) ||
	    (!params->ltr && !(header->order & CL_ORDER_FIRST)) || header->resizable)
	{
		SeparatorParameters separator;
		separator.horizontal = FALSE;
		
		if (params->ltr)
			params->style_functions->draw_separator (cr, colors, params, &separator,
			                                         width-1.5, 4.0, 2, height-8.0);
		else
			params->style_functions->draw_separator (cr, colors, params, &separator,
			                                         1.5, 4.0, 2, height-8.0);
	}
}
static void
clearlooks_inverted_draw_scrollbar_stepper (cairo_t *cr,
                                   const ClearlooksColors           *colors,
                                   const WidgetParameters           *widget,
                                   const ScrollBarParameters        *scrollbar,
                                   const ScrollBarStepperParameters *stepper,
                                   int x, int y, int width, int height)
{
	CairoCorners corners = CR_CORNER_NONE;
	CairoColor border;
	CairoColor s1, s2, s3;
	cairo_pattern_t *pattern;
	double radius = MIN (widget->radius, MIN ((width - 2.0) / 2.0, (height - 2.0) / 2.0));
	
	ge_shade_color(&colors->shade[6], 1.05, &border);

	if (scrollbar->horizontal)
	{
		if (stepper->stepper == CL_STEPPER_A)
			corners = CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT;
		else if (stepper->stepper == CL_STEPPER_D)
			corners = CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT;

		if (stepper->stepper == CL_STEPPER_B)
		{
			x -= 1;
			width += 1;
		}
		else if (stepper->stepper == CL_STEPPER_C)
		{
			width += 1;
		}
	}
	else
	{
		if (stepper->stepper == CL_STEPPER_A)
			corners = CR_CORNER_TOPLEFT | CR_CORNER_TOPRIGHT;
		else if (stepper->stepper == CL_STEPPER_D)
			corners = CR_CORNER_BOTTOMLEFT | CR_CORNER_BOTTOMRIGHT;

		if (stepper->stepper == CL_STEPPER_B)
		{
			y -= 1;
			height += 1;
		}
		else if (stepper->stepper == CL_STEPPER_C)
		{
			height += 1;
		}
	}
	
	cairo_translate (cr, x, y);
	cairo_set_line_width (cr, 1);
	
	ge_cairo_rounded_rectangle (cr, 1, 1, width-2, height-2, radius, corners);
	
	if (scrollbar->horizontal)
		pattern = cairo_pattern_create_linear (0, 0, 0, height);
	else
		pattern = cairo_pattern_create_linear (0, 0, width, 0);
				
	s1 = colors->bg[widget->state_type];
	ge_shade_color(&s1, 0.95, &s2); 
	ge_shade_color(&s1, 1.05, &s3); 
	
	cairo_pattern_add_color_stop_rgb(pattern, 0,    s2.r, s2.g, s2.b);
	cairo_pattern_add_color_stop_rgb(pattern, 1.0,  s3.r, s3.g, s3.b);
	cairo_set_source (cr, pattern);
	cairo_fill (cr);
	cairo_pattern_destroy (pattern);

	widget->style_functions->draw_top_left_highlight (cr, &s1, widget, 1, 1, width-2, height-2, radius, corners);

	ge_cairo_rounded_rectangle (cr, 0.5, 0.5, width-1, height-1, radius, corners);	
	clearlooks_set_border_gradient (cr, &border, 1.2, (scrollbar->horizontal ? 0 : width), (scrollbar->horizontal ? height: 0)); 
	cairo_stroke (cr);
}
static void
clearlooks_inverted_draw_button (cairo_t *cr,
                        const ClearlooksColors *colors,
                        const WidgetParameters *params,
                        int x, int y, int width, int height)
{
	double xoffset = 0, yoffset = 0;
	double radius = params->radius;
	const CairoColor *fill = &colors->bg[params->state_type];	
	const CairoColor *border_disabled = &colors->shade[4];
	CairoColor border_normal;
	CairoColor shadow;

	ge_shade_color(&colors->shade[6], 1.05, &border_normal);
	ge_shade_color (&border_normal, 0.925, &shadow);
	
	cairo_save (cr);
	
	cairo_translate (cr, x, y);
	cairo_set_line_width (cr, 1.0);

	if (params->xthickness == 3 || params->ythickness == 3)
	{
		if (params->xthickness == 3)
			xoffset = 1;
		if (params->ythickness == 3)
			yoffset = 1;
	}

	radius = MIN (radius, MIN ((width - 2.0 - xoffset * 2.0) / 2.0, (height - 2.0 - yoffset * 2) / 2.0));

	if (params->xthickness == 3 || params->ythickness == 3)
	{
		params->style_functions->draw_inset (cr, &params->parentbg, 0, 0, width, height, radius+1, params->corners);
	}		
	
	ge_cairo_rounded_rectangle (cr, xoffset+1, yoffset+1,
	                                     width-(xoffset*2)-2,
	                                     height-(yoffset*2)-2,
	                                     radius, params->corners);
	
	if (!params->active)
	{
		cairo_pattern_t *pattern;

		CairoColor top_shade, bottom_shade;
		ge_shade_color (fill, 0.95, &top_shade);		
		ge_shade_color (fill, 1.05, &bottom_shade);
		
		pattern	= cairo_pattern_create_linear (0, 0, 0, height);
		cairo_pattern_add_color_stop_rgb (pattern, 0.0, top_shade.r, top_shade.g, top_shade.b);
		cairo_pattern_add_color_stop_rgb (pattern, 1.0, bottom_shade.r, bottom_shade.g, bottom_shade.b);
		cairo_set_source (cr, pattern);
		cairo_fill (cr);
		cairo_pattern_destroy (pattern);
	}
	else
	{
		cairo_pattern_t *pattern;
		
		ge_cairo_set_color (cr, fill);
		cairo_fill_preserve (cr);

		pattern	= cairo_pattern_create_linear (0, 0, 0, height);
		cairo_pattern_add_color_stop_rgba (pattern, 0.0, shadow.r, shadow.g, shadow.b, 0.0);
		cairo_pattern_add_color_stop_rgba (pattern, 0.4, shadow.r, shadow.g, shadow.b, 0.0);
		cairo_pattern_add_color_stop_rgba (pattern, 1.0, shadow.r, shadow.g, shadow.b, 0.2);
		cairo_set_source (cr, pattern);
		cairo_fill_preserve (cr);
		cairo_pattern_destroy (pattern);

		pattern	= cairo_pattern_create_linear (0, yoffset+1, 0, 3+yoffset);
		cairo_pattern_add_color_stop_rgba (pattern, 0.0, shadow.r, shadow.g, shadow.b, params->disabled ? 0.125 : 0.3);
		cairo_pattern_add_color_stop_rgba (pattern, 1.0, shadow.r, shadow.g, shadow.b, 0.0);
		cairo_set_source (cr, pattern);
		cairo_fill_preserve (cr);
		cairo_pattern_destroy (pattern);

		pattern	= cairo_pattern_create_linear (xoffset+1, 0, 3+xoffset, 0);
		cairo_pattern_add_color_stop_rgba (pattern, 0.0, shadow.r, shadow.g, shadow.b, params->disabled ? 0.125 : 0.3);
		cairo_pattern_add_color_stop_rgba (pattern, 1.0, shadow.r, shadow.g, shadow.b, 0.0);
		cairo_set_source (cr, pattern);
		cairo_fill (cr);
		cairo_pattern_destroy (pattern);
	}

	/* Drawing the border */

	if (!params->active && params->is_default)
	{
		const CairoColor *l = &colors->shade[4];
		const CairoColor *d = &colors->shade[4];
		ge_cairo_set_color (cr, l);
		ge_cairo_stroke_rectangle (cr, 2.5, 2.5, width-5, height-5);

		ge_cairo_set_color (cr, d);
		ge_cairo_stroke_rectangle (cr, 3.5, 3.5, width-7, height-7);
	}
	
	if (params->disabled)
			ge_cairo_set_color (cr, border_disabled);
	else
		if (!params->active)
			clearlooks_set_border_gradient (cr, &border_normal, 1.32, 0, height); 
		else
			ge_cairo_set_color (cr, &border_normal);
	
	ge_cairo_rounded_rectangle (cr, xoffset + 0.5, yoffset + 0.5,
                                  width-(xoffset*2)-1, height-(yoffset*2)-1,
                                  radius, params->corners);
	cairo_stroke (cr);
	
	/* Draw the "shadow" */
	if (!params->active)
	{
		/* Draw right shadow */
		cairo_move_to (cr, width-xoffset-1.5, yoffset + radius);
		cairo_line_to (cr, width-xoffset-1.5, height - yoffset - radius);
		cairo_set_source_rgba (cr, shadow.r, shadow.g, shadow.b, 0.1);
		cairo_stroke (cr);
		
		/* Draw topleft shadow */
		params->style_functions->draw_top_left_highlight (cr, fill, params,
		                                                  xoffset+1, yoffset+1,
		                                                  width-2*(xoffset+1), height-2*(yoffset+1),
		                                                  radius, params->corners);
	}
	cairo_restore (cr);
}
static void
clearlooks_inverted_draw_slider (cairo_t *cr,
                        const ClearlooksColors *colors,
                        const WidgetParameters *params,
                        int x, int y, int width, int height)
{
	const CairoColor *border = &colors->shade[params->disabled ? 4 : 6];
	const CairoColor *spot   = &colors->spot[1];
	const CairoColor *fill   = &colors->shade[2];
	double radius = MIN (params->radius, MIN ((width - 1.0) / 2.0, (height - 1.0) / 2.0));

	cairo_pattern_t *pattern;

	cairo_set_line_width (cr, 1.0);	
	cairo_translate      (cr, x, y);

	if (params->disabled)
		border = &colors->shade[4];
	else if (params->prelight)
		border = &colors->spot[2];
	else
		border = &colors->shade[6];

	/* fill the widget */
	cairo_rectangle (cr, 1.0, 1.0, width-2, height-2);

	/* Fake light */
	if (!params->disabled)
	{
		const CairoColor *top = &colors->shade[2];
		const CairoColor *bot = &colors->shade[0];

		pattern	= cairo_pattern_create_linear (0, 0, 0, height);
		cairo_pattern_add_color_stop_rgb (pattern, 0.0,  top->r, top->g, top->b);
		cairo_pattern_add_color_stop_rgb (pattern, 1.0,  bot->r, bot->g, bot->b);
		cairo_set_source (cr, pattern);
		cairo_fill (cr);
		cairo_pattern_destroy (pattern);
	}
	else
	{
		ge_cairo_set_color (cr, fill);
		cairo_rectangle    (cr, 1.0, 1.0, width-2, height-2);
		cairo_fill         (cr);
	}

	/* Set the clip */
	cairo_save (cr);
	cairo_rectangle (cr, 1.0, 1.0, 6, height-2);
	cairo_rectangle (cr, width-7.0, 1.0, 6, height-2);
	cairo_clip_preserve (cr);

	cairo_new_path (cr);

	/* Draw the handles */
	ge_cairo_rounded_rectangle (cr, 1.0, 1.0, width-1, height-1, radius, params->corners);
	pattern = cairo_pattern_create_linear (0.5, 0.5, 0.5, 0.5+height);

	if (params->prelight)
	{
		CairoColor highlight;
		ge_shade_color (spot, 1.5, &highlight);
		cairo_pattern_add_color_stop_rgb (pattern, 0.0, spot->r, spot->g, spot->b);
		cairo_pattern_add_color_stop_rgb (pattern, 1.0, highlight.r, highlight.g, highlight.b);
		cairo_set_source (cr, pattern);
	}
	else {
		CairoColor hilight; 
		ge_shade_color (fill, 1.5, &hilight);
		cairo_set_source_rgba (cr, hilight.r, hilight.g, hilight.b, 0.5);
	}

	cairo_fill (cr);
	cairo_pattern_destroy (pattern);

	cairo_restore (cr);

	/* Draw the border */
	ge_cairo_inner_rounded_rectangle (cr, 0, 0, width, height, radius, params->corners);
	if (params->prelight || params->disabled)
		ge_cairo_set_color (cr, border);
	else
		clearlooks_set_border_gradient (cr, border, 1.2, 0, height);
	cairo_stroke (cr);

	/* Draw handle lines */
	if (width > 14)
	{
		cairo_move_to (cr, 6.5, 1.0);
		cairo_line_to (cr, 6.5, height-1);
	
		cairo_move_to (cr, width-6.5, 1.0);
		cairo_line_to (cr, width-6.5, height-1);
	
		cairo_set_line_width (cr, 1.0);
		cairo_set_source_rgba (cr, border->r,
		                           border->g,
		                           border->b,
	                                   0.3);
		cairo_stroke (cr);
	}
}
static void
clearlooks_inverted_draw_tab (cairo_t *cr,
                     const ClearlooksColors *colors,
                     const WidgetParameters *params,
                     const TabParameters    *tab,
                     int x, int y, int width, int height)
{
	const CairoColor    *border1       = &colors->shade[6];
	const CairoColor    *border2       = &colors->shade[5];
	const CairoColor    *stripe_fill   = &colors->spot[1];
	const CairoColor    *stripe_border = &colors->spot[2];
	const CairoColor    *fill;
	CairoColor           hilight;
	CairoColor           shadow;

	cairo_pattern_t     *pattern;
	
	double               radius;
	double               strip_size;
	double               length;

	radius = MIN (params->radius, MIN ((width - 2.0) / 2.0, (height - 2.0) / 2.0));

	/* Set clip */
	cairo_rectangle      (cr, x, y, width, height);
	cairo_clip           (cr);
	cairo_new_path       (cr);

	/* Translate and set line width */	
	cairo_set_line_width (cr, 1.0);
	cairo_translate      (cr, x+0.5, y+0.5);


	/* Make the tabs slightly bigger than they should be, to create a gap */
	/* And calculate the strip size too, while you're at it */
	if (tab->gap_side == CL_GAP_TOP || tab->gap_side == CL_GAP_BOTTOM)
	{
		height += 3.0;
	 	length = height;
	 	strip_size = 2.0/height; /* 2 pixel high strip */
		
		if (tab->gap_side == CL_GAP_TOP)
			cairo_translate (cr, 0.0, -3.0); /* gap at the other side */
	}
	else
	{
		width += 3.0;
	 	length = width;
	 	strip_size = 2.0/width;
		
		if (tab->gap_side == CL_GAP_LEFT) 
			cairo_translate (cr, -3.0, 0.0); /* gap at the other side */
	}
	
	/* Set the fill color */
	fill = &colors->bg[params->state_type];

	/* Set tab shape */
	ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1,
	                            radius, params->corners);
	
	/* Draw fill */
	ge_cairo_set_color (cr, fill);
	cairo_fill   (cr);

	ge_shade_color (fill, 1.3, &hilight);

	/* Draw highlight */
	if (!params->active)
	{
		ShadowParameters shadow;
		
		shadow.shadow  = CL_SHADOW_OUT;
		shadow.corners = params->corners;
		/*
		clearlooks_draw_highlight_and_shade (cr, colors, &shadow,
		                                     width,
		                                     height, radius);*/
	}
	
	if (params->active)
	{
		switch (tab->gap_side)
		{
			case CL_GAP_TOP:
				pattern = cairo_pattern_create_linear (0, height-2, 0, 0);
				break;
			case CL_GAP_BOTTOM:
				pattern = cairo_pattern_create_linear (0, 1, 0, height);
				break;
			case CL_GAP_LEFT:
				pattern = cairo_pattern_create_linear (width-2, 0, 1, 0);
				break;
			case CL_GAP_RIGHT:
				pattern = cairo_pattern_create_linear (1, 0, width-2, 0);
				break;
			default:
				pattern = NULL;
		}

		ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1, radius, params->corners);
		
		ge_shade_color (fill, 0.92, &shadow);

		cairo_pattern_add_color_stop_rgba  (pattern, 0.0,  				hilight.r, hilight.g, hilight.b, 0.4);     
		cairo_pattern_add_color_stop_rgba  (pattern, 1.0/height,  hilight.r, hilight.g, hilight.b, 0.4); 
		cairo_pattern_add_color_stop_rgb	(pattern, 1.0/height, 	fill->r,fill->g,fill->b);
		cairo_pattern_add_color_stop_rgb 	(pattern, 1.0, 					shadow.r,shadow.g,shadow.b);
		cairo_set_source (cr, pattern);
		cairo_fill (cr);
		cairo_pattern_destroy (pattern);
	}
	else
	{
		/* Draw shade */
		switch (tab->gap_side)
		{
			case CL_GAP_TOP:
				pattern = cairo_pattern_create_linear (0, height-2, 0, 0);
				break;
			case CL_GAP_BOTTOM:
				pattern = cairo_pattern_create_linear (0, 0, 0, height);
				break;
			case CL_GAP_LEFT:
				pattern = cairo_pattern_create_linear (width-2, 0, 0, 0);
				break;
			case CL_GAP_RIGHT:
				pattern = cairo_pattern_create_linear (0, 0, width, 0);
				break;
			default:
				pattern = NULL;
		}
	
		ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1, radius, params->corners);
		

		cairo_pattern_add_color_stop_rgb  (pattern, 0.0,        stripe_fill->r, stripe_fill->g, stripe_fill->b);
		cairo_pattern_add_color_stop_rgb  (pattern, strip_size, stripe_fill->r, stripe_fill->g, stripe_fill->b);
		cairo_pattern_add_color_stop_rgba (pattern, strip_size, hilight.r, hilight.g, hilight.b, 0.0);
		cairo_pattern_add_color_stop_rgba (pattern, 0.8,        hilight.r, hilight.g, hilight.b, 0.0);
		cairo_set_source (cr, pattern);
		cairo_fill (cr);
		cairo_pattern_destroy (pattern);
	}

	ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1, radius, params->corners);
	
	if (params->active)
	{
		ge_cairo_set_color (cr, border2);	
		cairo_stroke (cr);
	}
	else
	{
		switch (tab->gap_side)
		{
			case CL_GAP_TOP:
				pattern = cairo_pattern_create_linear (2, height-2, 2, 2);
				break;
			case CL_GAP_BOTTOM:
				pattern = cairo_pattern_create_linear (2, 2, 2, height);
				break;
			case CL_GAP_LEFT:
				pattern = cairo_pattern_create_linear (width-2, 2, 2, 2);
				break;
			case CL_GAP_RIGHT:
				pattern = cairo_pattern_create_linear (2, 2, width, 2);
				break;
			default:
				pattern = NULL;
		}
		
		cairo_pattern_add_color_stop_rgb (pattern, 0.0,        stripe_border->r, stripe_border->g, stripe_border->b);
		cairo_pattern_add_color_stop_rgb (pattern, strip_size, stripe_border->r, stripe_border->g, stripe_border->b);
		cairo_pattern_add_color_stop_rgb (pattern, strip_size, border1->r,       border1->g,       border1->b);
		cairo_pattern_add_color_stop_rgb (pattern, 1.0,        border2->r,       border2->g,       border2->b);
		cairo_set_source (cr, pattern);
		cairo_stroke (cr);
		cairo_pattern_destroy (pattern);
	}
}
Ejemplo n.º 13
0
static gboolean
ppg_header_expose_event (GtkWidget      *widget,
                         GdkEventExpose *expose)
{
	PpgHeader *header = (PpgHeader *)widget;
	PpgHeaderPrivate *priv;
	GtkStateType state = GTK_STATE_NORMAL;
	GtkAllocation alloc;
	GtkStyle *style;
	GdkColor begin;
	GdkColor end;
	GdkColor line;
	GdkColor v_begin;
	GdkColor v_end;
	cairo_pattern_t *p;
	cairo_t *cr;

	g_return_val_if_fail(PPG_IS_HEADER(header), FALSE);

	priv = header->priv;

	gtk_widget_get_allocation(widget, &alloc);
	style = gtk_widget_get_style(widget);
	begin = style->light[state];
	end = style->mid[state];
	line = style->dark[state];
	v_begin = style->mid[state];
	v_end = style->dark[state];

	cr = gdk_cairo_create(expose->window);
	p = cairo_pattern_create_linear(0, 0, 0, alloc.height);

	cairo_pattern_add_color_stop_rgb(p, 0.0, TO_CAIRO_RGB(begin));
	cairo_pattern_add_color_stop_rgb(p, 1.0, TO_CAIRO_RGB(end));
	cairo_set_source(cr, p);
	cairo_rectangle(cr, 0, 0, alloc.width, alloc.height);
	cairo_fill(cr);
	cairo_pattern_destroy(p);


	if (priv->bottom_separator) {
		cairo_set_source_rgb(cr, TO_CAIRO_RGB(line));
		cairo_set_line_width(cr, 1.0);
		cairo_move_to(cr, 0, alloc.height - 0.5);
		cairo_line_to(cr, alloc.width, alloc.height - 0.5);
		cairo_stroke(cr);
	}

	if (priv->right_separator) {
		p = cairo_pattern_create_linear(0, 0, 0, alloc.height);
		cairo_pattern_add_color_stop_rgb(p, 0.0, TO_CAIRO_RGB(v_begin));
		cairo_pattern_add_color_stop_rgb(p, 1.0, TO_CAIRO_RGB(v_end));
		cairo_set_source(cr, p);
		cairo_set_line_width(cr, 1.0);
		cairo_move_to(cr, alloc.width - 0.5, 0);
		cairo_line_to(cr, alloc.width - 0.5, alloc.height);
		cairo_stroke(cr);
		cairo_pattern_destroy(p);
	}

	cairo_destroy(cr);

	return FALSE;
}
Ejemplo n.º 14
0
static void draw_edges (cairo_t *cr, polygon_t *p, gdouble sf, int dir)
{
    int n;

    if (dir < 0)
	cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
    else
	cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);

    for (n = 0; n < p->num_edges; n++) {
	const edge_t *e = &p->edges[n];
	double dx, dy;
	double x1, x2;

	if (e->dir != dir)
	    continue;

	dx = e->p2.x - e->p1.x;
	dy = e->p2.y - e->p1.y;

	x1 = e->p1.x + (e->top - e->p1.y) / dy * dx;
	x2 = e->p1.x + (e->bot - e->p1.y) / dy * dx;

	cairo_arc (cr, x1, e->top, 2/sf, 0, 2*M_PI);
	cairo_arc (cr, x2, e->bot, 2/sf, 0, 2*M_PI);
	cairo_fill (cr);
    }

    if (dir < 0)
	cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.5);
    else
	cairo_set_source_rgba (cr, 1.0, 0.0, 0.0, 0.5);

    for (n = 0; n < p->num_edges; n++) {
	const edge_t *e = &p->edges[n];

	if (e->dir != dir)
	    continue;

	cairo_move_to (cr, e->p1.x, e->p1.y);
	cairo_line_to (cr, e->p2.x, e->p2.y);
    }
    cairo_save (cr); {
	cairo_identity_matrix (cr);
	cairo_set_line_width (cr, 1.);
	cairo_stroke (cr);
    } cairo_restore (cr);

    if (dir < 0)
	cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
    else
	cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);

    for (n = 0; n < p->num_edges; n++) {
	const edge_t *e = &p->edges[n];
	double dx, dy;
	double x1, x2;

	if (e->dir != dir)
	    continue;

	dx = e->p2.x - e->p1.x;
	dy = e->p2.y - e->p1.y;

	x1 = e->p1.x + (e->top - e->p1.y) / dy * dx;
	x2 = e->p1.x + (e->bot - e->p1.y) / dy * dx;

	cairo_move_to (cr, x1, e->top);
	cairo_line_to (cr, x2, e->bot);
    }
    cairo_save (cr); {
	cairo_identity_matrix (cr);
	cairo_set_line_width (cr, 1.);
	cairo_stroke (cr);
    } cairo_restore (cr);
}
Ejemplo n.º 15
0
static VALUE
cr_set_line_width (VALUE self, VALUE width)
{
  cairo_set_line_width (_SELF, NUM2DBL (width));
  return self;
}
static void
clearlooks_inverted_draw_scrollbar_slider (cairo_t *cr,
                                   const ClearlooksColors          *colors,
                                   const WidgetParameters          *widget,
                                   const ScrollBarParameters       *scrollbar,
                                   int x, int y, int width, int height)
{
	if (scrollbar->junction & CL_JUNCTION_BEGIN)
	{
		if (scrollbar->horizontal)
		{
			x -= 1;
			width += 1;
		}
		else
		{
			y -= 1;
			height += 1;
		}
	}
	if (scrollbar->junction & CL_JUNCTION_END)
	{
		if (scrollbar->horizontal)
			width += 1;
		else
			height += 1;
	}
	
	if (!scrollbar->horizontal)
		ge_cairo_exchange_axis (cr, &x, &y, &width, &height);

	cairo_translate (cr, x, y);	

	if (scrollbar->has_color)
	{
		const CairoColor *border = &colors->shade[8];
		CairoColor  fill    = scrollbar->color;
		CairoColor  hilight;
		CairoColor  shade1, shade2, shade3;
		cairo_pattern_t *pattern;
				
		if (widget->prelight)
			ge_shade_color (&fill, 1.1, &fill);
			
		cairo_set_line_width (cr, 1);
		
		ge_shade_color (&fill, 1.3, &hilight);
		ge_shade_color (&fill, 1.1, &shade1);
		ge_shade_color (&fill, 1.05, &shade2);
		ge_shade_color (&fill, 0.98, &shade3);
		
		pattern = cairo_pattern_create_linear (1, 1, 1, height-2);
		cairo_pattern_add_color_stop_rgb (pattern, 0,    fill.r,  fill.g,  fill.b);
		cairo_pattern_add_color_stop_rgb (pattern, 0.5,  shade3.r, shade3.g, shade3.b);
		cairo_pattern_add_color_stop_rgb (pattern, 0.5,  shade2.r, shade2.g, shade2.b);	
		cairo_pattern_add_color_stop_rgb (pattern, 1.0,  shade1.r, shade1.g, shade1.b);
		cairo_rectangle (cr, 1, 1, width-2, height-2);
		cairo_set_source (cr, pattern);
		cairo_fill (cr);
		cairo_pattern_destroy (pattern);
		
		cairo_set_source_rgba (cr, hilight.r, hilight.g, hilight.b, 0.5);
		ge_cairo_stroke_rectangle (cr, 1.5, 1.5, width-3, height-3);
	
		ge_cairo_set_color (cr, border);
		ge_cairo_stroke_rectangle (cr, 0.5, 0.5, width-1, height-1);
	}
	else
	{
		CairoColor border;
		CairoColor s1, s2, s3;
		cairo_pattern_t *pattern;
		int bar_x, i;
		
		const CairoColor *dark  = &colors->shade[4];
		const CairoColor *light = &colors->shade[0];		

		ge_shade_color(&colors->shade[6], 1.05, &border);

		pattern = cairo_pattern_create_linear(1, 1, 1, height-1);

		s1 = colors->bg[widget->state_type];
		ge_shade_color(&s1, 0.95, &s2); 
		ge_shade_color(&s1, 1.05, &s3); 

		cairo_pattern_add_color_stop_rgb(pattern, 0,    s2.r, s2.g, s2.b);
		cairo_pattern_add_color_stop_rgb(pattern, 1.0,  s3.r, s3.g, s3.b);

		cairo_rectangle (cr, 1, 1, width-2, height-2);
		cairo_set_source(cr, pattern);
		cairo_fill(cr);
		cairo_pattern_destroy(pattern);
		
		widget->style_functions->draw_top_left_highlight (cr, &s2, widget, 1, 1, width-2, height-2, 0, widget->corners);

		clearlooks_set_border_gradient (cr, &border, 1.2, 0, height);
		ge_cairo_stroke_rectangle (cr, 0.5, 0.5, width-1, height-1);
		
		/* draw handles */
		cairo_set_line_width (cr, 1);
		
		bar_x = width/2 - 4;
		cairo_translate(cr, 0.5, 0.5);
		for (i=0; i<3; i++)
		{
			cairo_move_to (cr, bar_x, 4);
			cairo_line_to (cr, bar_x, height-5);
			ge_cairo_set_color (cr, dark);
			cairo_stroke (cr);
			
			cairo_move_to (cr, bar_x+1, 4);
			cairo_line_to (cr, bar_x+1, height-5);
			ge_cairo_set_color (cr, light);
			cairo_stroke (cr);
			
			bar_x += 3;
		}
	}
}
Ejemplo n.º 17
0
void gfxContext::SetLineWidth(gfxFloat width)
{
    cairo_set_line_width(mCairo, width);
}
Ejemplo n.º 18
0
void menuwin_paint_keyboard(cairo_t *cr) {

	int x,y;
	int counter=4*KEYS_PER_ROW*keyboard_current_block;
	cairo_text_extents_t te;
	for(y=4;y>0;y--) {
		for(x=0;x<KEYS_PER_ROW;x++) {
			if (keyboard_lowercase[counter].type!=KEY_BLANK) {
				menuwin_paint_button(cr,x,y,keyboard_lowercase[counter].w,keyboard_lowercase[counter].h,0.9,0.9,0.9);
				cairo_set_line_width(cr,0.12);
				cairo_set_source_rgb(cr,0.0,0.0,0.0);
				switch(keyboard_lowercase[counter].type) {
				case KEY_TAB:
					cairo_move_to(cr,-0.8,-0.8);
					cairo_line_to(cr,-0.8,0.0);
					cairo_stroke(cr);
					cairo_move_to(cr,0.8,0.8);
					cairo_line_to(cr,0.8,0.0);
					cairo_stroke(cr);
					cairo_move_to(cr,-0.7,-0.4);
					cairo_line_to(cr,0.8,-0.4);
					cairo_stroke(cr);
					cairo_move_to(cr,-0.7,0.4);
					cairo_line_to(cr,0.8,0.4);
					cairo_stroke(cr);
					cairo_move_to(cr,-0.3,-0.8);
					cairo_line_to(cr,-0.7,-0.4);
					cairo_line_to(cr,-0.3,0.0);
					cairo_stroke(cr);
					cairo_move_to(cr,0.3,0.8);
					cairo_line_to(cr,0.7,0.4);
					cairo_line_to(cr,0.3,0.0);
					cairo_stroke(cr);
				break;
				case KEY_RETURN:
					cairo_move_to(cr,0.8,-1.6);
					cairo_line_to(cr,0.8,1.2);
					cairo_line_to(cr,-0.8,1.2);
					cairo_stroke(cr);
					cairo_move_to(cr,-0.4,0.8);
					cairo_line_to(cr,-0.8,1.2);
					cairo_line_to(cr,-0.4,1.6);
					cairo_stroke(cr);
				break;
				case KEY_DELETE:
					cairo_move_to(cr,0.8,0.0);
					cairo_line_to(cr,-0.8,0.0);
					cairo_stroke(cr);
					cairo_move_to(cr,-0.4,-0.4);
					cairo_line_to(cr,-0.8,0.0);
					cairo_line_to(cr,-0.4,0.4);
					cairo_stroke(cr);
				break;
				case KEY_JUMPTO:
					if (keyboard_lowercase[counter].modifier==1) { // Shift symbol
						cairo_move_to(cr,0.0,-0.6);
						cairo_line_to(cr,0.0,0.6);
						cairo_stroke(cr);
						cairo_move_to(cr,-0.4,-0.2);
						cairo_line_to(cr,0.0,-0.6);
						cairo_line_to(cr,0.4,-0.2);
						cairo_stroke(cr);
					} else if (keyboard_lowercase[counter].modifier==2) { // Jump to numbers/symbols
						cairo_set_font_size(cr,KEYS_JUMP_FONT_SIZE);
						cairo_text_extents(cr,"123", &te);
						cairo_move_to(cr,-te.x_bearing-(te.width/2.0),0.35);
						cairo_show_text(cr,"123");
						cairo_set_font_size(cr,KEYS_FONT_SIZE);
					} else if (keyboard_lowercase[counter].modifier==3) { // Jump to letters
						cairo_set_font_size(cr,KEYS_JUMP_FONT_SIZE);
						cairo_text_extents(cr,"abc", &te);
						cairo_move_to(cr,-te.x_bearing-(te.width/2.0),0.35);
						cairo_show_text(cr,"abc");
						cairo_set_font_size(cr,KEYS_FONT_SIZE);
					} else { // Generic symbol
						cairo_set_font_size(cr,KEYS_JUMP_FONT_SIZE);
						cairo_text_extents(cr,"...", &te);
						cairo_move_to(cr,-te.x_bearing-(te.width/2.0),0.35);
						cairo_show_text(cr,"...");
						cairo_set_font_size(cr,KEYS_FONT_SIZE);
					}
				break;
				case KEY_UP:
					cairo_move_to(cr,-0.6,0.3);
					cairo_line_to(cr,0.0,-0.3);
					cairo_line_to(cr,0.6,0.3);
					cairo_line_to(cr,-0.6,0.3);
					cairo_fill(cr);
				break;
				case KEY_DOWN:
					cairo_move_to(cr,-0.6,-0.3);
					cairo_line_to(cr,0.0,0.3);
					cairo_line_to(cr,0.6,-0.3);
					cairo_line_to(cr,-0.6,-0.3);
					cairo_fill(cr);
				break;
				case KEY_LEFT:
					cairo_move_to(cr,0.3,-0.6);
					cairo_line_to(cr,-0.3,0.0);
					cairo_line_to(cr,0.3,0.6);
					cairo_line_to(cr,0.3,-0.6);
					cairo_fill(cr);
				break;
				case KEY_RIGHT:
					cairo_move_to(cr,-0.3,-0.6);
					cairo_line_to(cr,0.3,0.0);
					cairo_line_to(cr,-0.3,0.6);
					cairo_line_to(cr,-0.3,-0.6);
					cairo_fill(cr);
				break;
				case KEY_PH:
					if (keyboard_lowercase[counter].keycode==0) { // this letter has no keycode assigned. Paint it red
						cairo_set_source_rgb(cr,1.0,0.0,0.0);
					}
					if (keyboard_lowercase[counter].size!=KEYS_FONT_SIZE) {
						cairo_set_font_size(cr,keyboard_lowercase[counter].size);
					}
					cairo_text_extents(cr,keyboard_lowercase[counter].g_element, &te);
					cairo_move_to(cr,-te.x_bearing-(te.width/2.0),0.35);
					cairo_show_text(cr,keyboard_lowercase[counter].g_element);
					if (keyboard_lowercase[counter].size!=KEYS_FONT_SIZE) {
						cairo_set_font_size(cr,KEYS_FONT_SIZE);
					}
					if (keyboard_lowercase[counter].keycode==0) { // this letter has no keycode assigned. Paint it red
						cairo_set_source_rgb(cr,0.0,0.0,0.0);
					}
				break;

				// KEY_SYMBOL

				}
				cairo_restore(cr);
			}
			counter++;
		}
	}
}
Ejemplo n.º 19
0
static gboolean _lib_histogram_draw_callback(GtkWidget *widget, cairo_t *crf, gpointer user_data)
{
  dt_lib_module_t *self = (dt_lib_module_t *)user_data;
  dt_lib_histogram_t *d = (dt_lib_histogram_t *)self->data;

  dt_develop_t *dev = darktable.develop;
  uint32_t *hist = dev->histogram;
  float hist_max = dev->histogram_type == DT_DEV_HISTOGRAM_LINEAR ? dev->histogram_max
                                                                  : logf(1.0 + dev->histogram_max);
  const int inset = DT_HIST_INSET;
  GtkAllocation allocation;
  gtk_widget_get_allocation(widget, &allocation);
  int width = allocation.width, height = allocation.height;
  cairo_surface_t *cst = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
  cairo_t *cr = cairo_create(cst);

  gtk_render_background(gtk_widget_get_style_context(widget), cr, 0, 0, allocation.width, allocation.height);

  cairo_translate(cr, 4 * inset, inset);
  width -= 2 * 4 * inset;
  height -= 2 * inset;

  if(d->mode_x == 0)
  {
    d->color_w = 0.06 * width;
    d->button_spacing = 0.01 * width;
    d->button_h = 0.06 * width;
    d->button_y = d->button_spacing;
    d->mode_w = d->color_w;
    d->mode_x = width - 3 * (d->color_w + d->button_spacing) - (d->mode_w + d->button_spacing);
    d->red_x = width - 3 * (d->color_w + d->button_spacing);
    d->green_x = width - 2 * (d->color_w + d->button_spacing);
    d->blue_x = width - (d->color_w + d->button_spacing);
  }

  // TODO: probably this should move to the configure-event callback! That would be future proof if we ever
  // (again) allow to resize the side panels.
  const gint stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);

  // this code assumes that the first expose comes before the first (preview) pipe is processed and that the
  // size of the widget doesn't change!
  if(dev->histogram_waveform_width == 0)
  {
    dev->histogram_waveform = (uint32_t *)calloc(height * stride / 4, sizeof(uint32_t));
    dev->histogram_waveform_stride = stride;
    dev->histogram_waveform_height = height;
    dev->histogram_waveform_width = width;
    //     return TRUE; // there are enough expose events following ...
  }

#if 1
  // draw shadow around
  float alpha = 1.0f;
  cairo_set_line_width(cr, 0.2);
  for(int k = 0; k < inset; k++)
  {
    cairo_rectangle(cr, -k, -k, width + 2 * k, height + 2 * k);
    cairo_set_source_rgba(cr, 0, 0, 0, alpha);
    alpha *= 0.5f;
    cairo_fill(cr);
  }
  cairo_set_line_width(cr, 1.0);
#else
  cairo_set_line_width(cr, 1.0);
  cairo_set_source_rgb(cr, .1, .1, .1);
  cairo_rectangle(cr, 0, 0, width, height);
  cairo_stroke(cr);
#endif

  cairo_rectangle(cr, 0, 0, width, height);
  cairo_clip(cr);

  cairo_set_source_rgb(cr, .3, .3, .3);
  cairo_rectangle(cr, 0, 0, width, height);
  cairo_fill(cr);
  if(d->highlight == 1)
  {
    cairo_set_source_rgb(cr, .5, .5, .5);
    cairo_rectangle(cr, 0, 0, .2 * width, height);
    cairo_fill(cr);
  }
  else if(d->highlight == 2)
  {
    cairo_set_source_rgb(cr, .5, .5, .5);
    cairo_rectangle(cr, 0.2 * width, 0, width, height);
    cairo_fill(cr);
  }

  // draw grid
  cairo_set_line_width(cr, .4);
  cairo_set_source_rgb(cr, .1, .1, .1);
  if(dev->histogram_type == DT_DEV_HISTOGRAM_WAVEFORM)
    dt_draw_waveform_lines(cr, 0, 0, width, height);
  else
    dt_draw_grid(cr, 4, 0, 0, width, height);

  if(hist_max > 0.0f)
  {
    cairo_save(cr);
    if(dev->histogram_type == DT_DEV_HISTOGRAM_WAVEFORM)
    {
      // make the color channel selector work:
      uint8_t *buf = (uint8_t *)malloc(sizeof(uint8_t) * height * stride);
      uint8_t mask[3] = { d->blue, d->green, d->red };
      memcpy(buf, dev->histogram_waveform, sizeof(uint8_t) * height * stride);
      for(int y = 0; y < height; y++)
        for(int x = 0; x < width; x++)
          for(int k = 0; k < 3; k++)
          {
            buf[y * stride + x * 4 + k] *= mask[k];
          }

      cairo_surface_t *source
          = cairo_image_surface_create_for_data(buf, CAIRO_FORMAT_ARGB32, width, height, stride);

      cairo_set_source_surface(cr, source, 0.0, 0.0);
      cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
      cairo_paint(cr);
      cairo_surface_destroy(source);
      free(buf);
    }
    else
    {
      // cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
      cairo_translate(cr, 0, height);
      cairo_scale(cr, width / 63.0, -(height - 10) / hist_max);
      cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
      // cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
      cairo_set_line_width(cr, 1.);
      if(d->red)
      {
        cairo_set_source_rgba(cr, 1., 0., 0., 0.2);
        dt_draw_histogram_8(cr, hist, 0, dev->histogram_type == DT_DEV_HISTOGRAM_LINEAR);
      }
      if(d->green)
      {
        cairo_set_source_rgba(cr, 0., 1., 0., 0.2);
        dt_draw_histogram_8(cr, hist, 1, dev->histogram_type == DT_DEV_HISTOGRAM_LINEAR);
      }
      if(d->blue)
      {
        cairo_set_source_rgba(cr, 0., 0., 1., 0.2);
        dt_draw_histogram_8(cr, hist, 2, dev->histogram_type == DT_DEV_HISTOGRAM_LINEAR);
      }
      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
      // cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT);
    }
    cairo_restore(cr);
  }

  cairo_set_source_rgb(cr, .25, .25, .25);
  cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
  PangoLayout *layout;
  PangoRectangle ink;
  PangoFontDescription *desc = pango_font_description_copy_static(darktable.bauhaus->pango_font_desc);
  pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
  layout = pango_cairo_create_layout(cr);
  pango_font_description_set_absolute_size(desc, .1 * height * PANGO_SCALE);
  pango_layout_set_font_description(layout, desc);

  char exifline[50];
  dt_image_print_exif(&dev->image_storage, exifline, 50);
  pango_layout_set_text(layout, exifline, -1);
  pango_layout_get_pixel_extents(layout, &ink, NULL);
  cairo_move_to(cr, .02 * width, .98 * height - ink.height - ink.y);
  cairo_save(cr);
  cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(2.0));
  cairo_set_source_rgba(cr, 1, 1, 1, 0.3);
  pango_cairo_layout_path(cr, layout);
  cairo_stroke_preserve(cr);
  cairo_set_source_rgb(cr, .25, .25, .25);
  cairo_fill(cr);
  cairo_restore(cr);

  // buttons to control the display of the histogram: linear/log, r, g, b
  if(d->highlight != 0)
  {
    _draw_mode_toggle(cr, d->mode_x, d->button_y, d->mode_w, d->button_h, dev->histogram_type);
    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.4);
    _draw_color_toggle(cr, d->red_x, d->button_y, d->color_w, d->button_h, d->red);
    cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 0.4);
    _draw_color_toggle(cr, d->green_x, d->button_y, d->color_w, d->button_h, d->green);
    cairo_set_source_rgba(cr, 0.0, 0.0, 1.0, 0.4);
    _draw_color_toggle(cr, d->blue_x, d->button_y, d->color_w, d->button_h, d->blue);
  }

  cairo_destroy(cr);
  cairo_set_source_surface(crf, cst, 0, 0);
  cairo_paint(crf);
  cairo_surface_destroy(cst);
  pango_font_description_free(desc);
  g_object_unref(layout);
  return TRUE;
}
Ejemplo n.º 20
0
void menuwin_paint_batery(cairo_t *cr) {

	float tmp,bat;
	char string[100];
	int charge,tmp2,retval;
	int memtotal,memfree,memcached,swaptotal,swapfree;

	menuwin_paint_button(cr,3,0,1,1,1.0,1.0,1.0);

	cairo_set_line_width(cr,0.12);
	cairo_set_source_rgb(cr,0.0,0.0,0.0);
	cairo_move_to(cr,-0.9,0.7);
	cairo_line_to(cr,-0.2,0.7);
	cairo_line_to(cr,-0.2,-0.5);
	cairo_line_to(cr,-0.4,-0.5);
	cairo_line_to(cr,-0.4,-0.7);
	cairo_line_to(cr,-0.7,-0.7);
	cairo_line_to(cr,-0.7,-0.5);
	cairo_line_to(cr,-0.9,-0.5);
	cairo_close_path(cr);
	cairo_fill(cr);

	cairo_move_to(cr,0.8,0.5);
	cairo_line_to(cr,0.3,0.5);
	cairo_line_to(cr,0.3,-0.5);
	cairo_line_to(cr,0.8,-0.5);
	cairo_close_path(cr);
	cairo_fill(cr);
	cairo_move_to(cr,0.8,0.4);
	cairo_line_to(cr,0.9,0.4);
	cairo_stroke(cr);
	cairo_move_to(cr,0.3,0.4);
	cairo_line_to(cr,0.2,0.4);
	cairo_stroke(cr);
	cairo_move_to(cr,0.8,0.2);
	cairo_line_to(cr,0.9,0.2);
	cairo_stroke(cr);
	cairo_move_to(cr,0.3,0.2);
	cairo_line_to(cr,0.2,0.2);
	cairo_stroke(cr);
	cairo_move_to(cr,0.8,-0.4);
	cairo_line_to(cr,0.9,-0.4);
	cairo_stroke(cr);
	cairo_move_to(cr,0.3,-0.4);
	cairo_line_to(cr,0.2,-0.4);
	cairo_stroke(cr);
	cairo_move_to(cr,0.8,-0.2);
	cairo_line_to(cr,0.9,-0.2);
	cairo_stroke(cr);
	cairo_move_to(cr,0.3,-0.2);
	cairo_line_to(cr,0.2,-0.2);
	cairo_stroke(cr);

	cairo_move_to(cr,0.8,0.0);
	cairo_line_to(cr,0.9,0.0);
	cairo_stroke(cr);
	cairo_move_to(cr,0.3,0.0);
	cairo_line_to(cr,0.2,0.0);
	cairo_stroke(cr);


	FILE *apm=fopen("/proc/apm","r");
	if (apm==NULL) {
		cairo_set_source_rgb(cr,1.0,1.0,1.0);
		bat=100.0;
		charge=1;
	} else {
		retval=fscanf(apm,"%s %s %x %x %x %x %f%% %d %s",string,string,&tmp2,&charge,&tmp2,&tmp2,&bat,&tmp2,string);
		menuwin_set_color_scale(cr,bat/100.0);
		fclose(apm);
	}
	cairo_rectangle(cr,-0.8,0.6,0.5,-(bat/100.0));
	cairo_fill(cr);
	if((charge&0x01)!=0) {

		// socket when charging

		cairo_set_source_rgb(cr,0.5,0.5,1.0);
		cairo_move_to(cr,-0.55,0.5);
		cairo_line_to(cr,-0.55,0.0);
		cairo_stroke(cr);
		cairo_arc(cr,-0.55,-0.20,0.20,0,3.141592);
		cairo_fill(cr);
		cairo_set_line_width(cr,0.09);
		cairo_move_to(cr,-0.63,-0.15);
		cairo_line_to(cr,-0.63,-0.35);
		cairo_stroke(cr);
		cairo_move_to(cr,-0.47,-0.15);
		cairo_line_to(cr,-0.47,-0.35);
		cairo_stroke(cr);
	}

	float v;
	FILE *meminfo=fopen("/proc/meminfo","r");
	memtotal=100;
	memfree=100;
	memcached=0;
	swaptotal=0;
	swapfree=0;
	charge=1;
	if (meminfo==NULL) {
		cairo_set_source_rgb(cr,1.0,1.0,1.0);
	} else {
		while(!feof(meminfo)) {
			retval=fscanf(meminfo,"%s",string);
			if (retval<1) {
				continue;
			}
			retval=fscanf(meminfo,"%d",&tmp2);
			if (retval<1) {
				continue;
			}
			if(!strcmp(string,"MemTotal:")) {
				memtotal=tmp2;
			} else if(!strcmp(string,"MemFree:")) {
				memfree=tmp2;
			} else if(!strcmp(string,"Cached:")) {
				memcached=tmp2;
			} else if(!strcmp(string,"SwapTotal:")) {
				swaptotal=tmp2;
			} else if(!strcmp(string,"SwapFree:")) {
				swapfree=tmp2;
			}
		}
		fclose(meminfo);
	}
	v=((float)(memfree+memcached+swapfree))/((float)(memtotal+swaptotal));
	if (v>1.0) {
		v=1.0;
	}
	menuwin_set_color_scale(cr,v);
	cairo_rectangle(cr,0.4,0.4,0.3,-(v*0.8));
	cairo_fill(cr);

	cairo_restore(cr);

}
Ejemplo n.º 21
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    const cairo_test_context_t *ctx = cairo_test_get_context (cr);
    cairo_surface_t *surface;
    cairo_t         *cr2;
    const char      *phase;
    const char	     string[] = "The quick brown fox jumps over the lazy dog.";
    cairo_text_extents_t extents, scaled_font_extents;
    int              errors = 0;

    surface = cairo_surface_create_similar (cairo_get_group_target (cr),
                                            CAIRO_CONTENT_COLOR, 100, 100);
    /* don't use cr accidentally */
    cr = NULL;
    cr2 = cairo_create (surface);
    cairo_surface_destroy (surface);

    cairo_set_line_width (cr2, 10);
    cairo_set_line_join (cr2, CAIRO_LINE_JOIN_MITER);
    cairo_set_miter_limit (cr2, 100);

    phase = "No path";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 0, 0, 0, 0);

    cairo_save (cr2);

    cairo_new_path (cr2);
    cairo_move_to (cr2, 200, 400);
    cairo_rel_line_to (cr2, 0., 0.);
    phase = "Degenerate line";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 200, 400, 0, 0);

    cairo_new_path (cr2);
    cairo_move_to (cr2, 200, 400);
    cairo_rel_curve_to (cr2, 0., 0., 0., 0., 0., 0.);
    phase = "Degenerate curve";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 200, 400, 0, 0);

    cairo_new_path (cr2);
    cairo_arc (cr2, 200, 400, 0., 0, 2 * M_PI);
    phase = "Degenerate arc (R=0)";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 200, 400, 0, 0);

    cairo_new_path (cr2);
    cairo_arc (cr2, 200, 400, 10., 0, 0);
    phase = "Degenerate arc (Θ=0)";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 200, 400, 0, 0);

    cairo_new_path (cr2);
    cairo_restore (cr2);

    /* Test that with CAIRO_LINE_CAP_ROUND, we get "dots" from
     * cairo_move_to; cairo_rel_line_to(0,0) */
    cairo_save (cr2);

    cairo_set_line_cap (cr2, CAIRO_LINE_CAP_ROUND);
    cairo_set_line_width (cr2, 20);

    cairo_move_to (cr2, 200, 400);
    cairo_rel_line_to (cr2, 0, 0);
    phase = "Single 'dot'";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 190, 390, 20, 20);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 200, 400, 0, 0);

    /* Add another dot without starting a new path */
    cairo_move_to (cr2, 100, 500);
    cairo_rel_line_to (cr2, 0, 0);
    phase = "Multiple 'dots'";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 90, 390, 120, 120);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 100, 400, 100, 100);

    cairo_new_path (cr2);

    cairo_restore (cr2);

    /* http://bugs.freedesktop.org/show_bug.cgi?id=7965 */
    phase = "A vertical, open path";
    cairo_save (cr2);
    cairo_set_line_cap (cr2, CAIRO_LINE_CAP_ROUND);
    cairo_set_line_join (cr2, CAIRO_LINE_JOIN_ROUND);
    cairo_move_to (cr2, 0, 180);
    cairo_line_to (cr2, 750, 180);
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 0, 0, 0, 0);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, -5, 175, 760, 10);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 0, 180, 755, 0);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    phase = "Simple rect";
    cairo_save (cr2);
    cairo_rectangle (cr2, 10, 10, 80, 80);
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 80, 80);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 5, 5, 90, 90);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 80, 80);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    phase = "Two rects";
    cairo_save (cr2);
    cairo_rectangle (cr2, 10, 10, 10, 10);
    cairo_rectangle (cr2, 20, 20, 10, 10);
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 20, 20);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 5, 5, 30, 30);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 20, 20);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    phase = "Triangle";
    cairo_save (cr2);
    cairo_move_to (cr2, 10, 10);
    cairo_line_to (cr2, 90, 90);
    cairo_line_to (cr2, 90, 10);
    cairo_close_path (cr2);
    /* miter joins protrude 5*(1+sqrt(2)) above the top-left corner and to
       the right of the bottom-right corner */
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 80, 80);
    errors += !check_extents (ctx, phase, cr2, STROKE, CONTAINS, 0, 5, 95, 95);
    errors += !check_extents (ctx, phase, cr2, PATH, CONTAINS, 10, 10, 80, 80);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    cairo_save (cr2);

    cairo_set_line_width (cr2, 4);

    cairo_rectangle (cr2, 10, 10, 30, 30);
    cairo_rectangle (cr2, 25, 10, 15, 30);

    cairo_set_fill_rule (cr2, CAIRO_FILL_RULE_EVEN_ODD);
    phase = "EVEN_ODD overlapping rectangles";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 15, 30);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 30, 30);

    /* Test other fill rule with the same path. */

    cairo_set_fill_rule (cr2, CAIRO_FILL_RULE_WINDING);
    phase = "WINDING overlapping rectangles";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 30, 30);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 30, 30);

    /* Now, change the direction of the second rectangle and test both
     * fill rules again. */
    cairo_new_path (cr2);
    cairo_rectangle (cr2, 10, 10, 30, 30);
    cairo_rectangle (cr2, 25, 40, 15, -30);

    cairo_set_fill_rule (cr2, CAIRO_FILL_RULE_EVEN_ODD);
    phase = "EVEN_ODD overlapping rectangles";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 15, 30);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 30, 30);

    /* Test other fill rule with the same path. */

    cairo_set_fill_rule (cr2, CAIRO_FILL_RULE_WINDING);
    phase = "WINDING overlapping rectangles";
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 15, 30);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 8, 8, 34, 34);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 30, 30);

    cairo_new_path (cr2);

    cairo_restore (cr2);

    /* http://bugs.freedesktop.org/show_bug.cgi?id=7245 */
    phase = "Arc";
    cairo_save (cr2);
    cairo_arc (cr2, 250.0, 250.0, 157.0, 5.147, 3.432);
    cairo_set_line_width (cr2, 154.0);
    errors += !check_extents (ctx, phase, cr2, STROKE, APPROX_EQUALS, 16, 38, 468, 446);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    phase = "Text";
    cairo_save (cr2);
    cairo_select_font_face (cr2, "Bitstream Vera Sans",
			    CAIRO_FONT_SLANT_NORMAL,
			    CAIRO_FONT_WEIGHT_NORMAL);
    cairo_set_font_size (cr2, 12);
    cairo_text_extents (cr2, string, &extents);
    /* double check that the two methods of measuring the text agree... */
    cairo_scaled_font_text_extents (cairo_get_scaled_font (cr2),
				    string,
				    &scaled_font_extents);
    if (memcmp (&extents, &scaled_font_extents, sizeof (extents))) {
	cairo_test_log (ctx, "Error: cairo_text_extents() does not match cairo_scaled_font_text_extents() - font extents (%f, %f) x (%f, %f) should be (%f, %f) x (%f, %f)\n",
		        scaled_font_extents.x_bearing,
			scaled_font_extents.y_bearing,
			scaled_font_extents.width,
			scaled_font_extents.height,
			extents.x_bearing,
			extents.y_bearing,
			extents.width,
			extents.height);
	errors++;
    }

    cairo_move_to (cr2, -extents.x_bearing, -extents.y_bearing);
    cairo_text_path (cr2, string);
    cairo_set_line_width (cr2, 2.0);
    /* XXX: We'd like to be able to use EQUALS here, but currently
     * when hinting is enabled freetype returns integer extents. See
     * http://cairographics.org/todo */
    errors += !check_extents (ctx, phase, cr2, FILL, APPROX_EQUALS,
			      0, 0, extents.width, extents.height);
    errors += !check_extents (ctx, phase, cr2, STROKE, APPROX_EQUALS,
			      -1, -1, extents.width+2, extents.height+2);
    errors += !check_extents (ctx, phase, cr2, PATH, APPROX_EQUALS,
			      0, 0, extents.width, extents.height);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    phase = "User space, simple scale, getting extents with same transform";
    cairo_save (cr2);
    cairo_scale (cr2, 2, 2);
    cairo_rectangle (cr2, 5, 5, 40, 40);
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 5, 5, 40, 40);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 0, 0, 50, 50);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 5, 5, 40, 40);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    phase = "User space, simple scale, getting extents with no transform";
    cairo_save (cr2);
    cairo_save (cr2);
    cairo_scale (cr2, 2, 2);
    cairo_rectangle (cr2, 5, 5, 40, 40);
    cairo_restore (cr2);
    errors += !check_extents (ctx, phase, cr2, FILL, EQUALS, 10, 10, 80, 80);
    errors += !check_extents (ctx, phase, cr2, STROKE, EQUALS, 5, 5, 90, 90);
    errors += !check_extents (ctx, phase, cr2, PATH, EQUALS, 10, 10, 80, 80);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    phase = "User space, rotation, getting extents with transform";
    cairo_save (cr2);
    cairo_rectangle (cr2, -50, -50, 50, 50);
    cairo_rotate (cr2, -M_PI/4);
    /* the path in user space is now (nearly) the square rotated by
       45 degrees about the origin. Thus its x1 and x2 are both nearly 0.
       This should show any bugs where we just transform device-space
       x1,y1 and x2,y2 to get the extents. */
    /* The largest axis-aligned square inside the rotated path has
       side lengths 50*sqrt(2), so a bit over 35 on either side of
       the axes. With the stroke width added to the rotated path,
       the largest axis-aligned square is a bit over 38 on either side of
       the axes. */
    errors += !check_extents (ctx, phase, cr2, FILL, CONTAINS, -35, -35, 35, 35);
    errors += !check_extents (ctx, phase, cr2, STROKE, CONTAINS, -38, -38, 38, 38);
    errors += !check_extents (ctx, phase, cr2, PATH, CONTAINS, -35, -35, 35, 35);
    cairo_new_path (cr2);
    cairo_restore (cr2);

    cairo_destroy (cr2);

    return errors == 0 ? CAIRO_TEST_SUCCESS : CAIRO_TEST_FAILURE;
}
static void
locate_pointer_paint (CsdLocatePointerData *data,
                      cairo_t              *cr,
                      gboolean              composite)
{
  GdkRGBA color;
  gdouble progress, circle_progress;
  gint width, height, i;
  GtkStyleContext *context;

  progress = data->progress;

  width = gdk_window_get_width (data->window);
  height = gdk_window_get_height (data->window);
  context = gtk_widget_get_style_context (data->widget);
  gtk_style_context_get_background_color (context, GTK_STATE_FLAG_SELECTED, &color);

  cairo_set_source_rgba (cr, 1., 1., 1., 0.);
  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
  cairo_paint (cr);

  for (i = 0; i <= N_CIRCLES; i++)
    {
      if (progress < 0.)
        break;

      circle_progress = MIN (1., (progress * 2));
      progress -= CIRCLES_PROGRESS_INTERVAL;

      if (circle_progress >= 1.)
        continue;

      if (composite)
        {
          cairo_set_source_rgba (cr,
                                 color.red,
                                 color.green,
                                 color.blue,
                                 1 - circle_progress);
          cairo_arc (cr,
                     width / 2,
                     height / 2,
                     circle_progress * width / 2,
                     0, 2 * G_PI);

          cairo_fill (cr);
        }
      else
        {
          cairo_set_source_rgb (cr, 0., 0., 0.);
          cairo_set_line_width (cr, 3.);
          cairo_arc (cr,
                     width / 2,
                     height / 2,
                     circle_progress * width / 2,
                     0, 2 * G_PI);
          cairo_stroke (cr);

          cairo_set_source_rgb (cr, 1., 1., 1.);
          cairo_set_line_width (cr, 1.);
          cairo_arc (cr,
                     width / 2,
                     height / 2,
                     circle_progress * width / 2,
                     0, 2 * G_PI);
          cairo_stroke (cr);
        }
    }
}
Ejemplo n.º 23
0
void
draw_graph(cairo_t *cr, struct layout *L, gboolean is_screen)
{
  int i, j, k;

  cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
  cairo_paint(cr);

  if (! state->dataset_used)
    goto draw_message;

  /* minor grid lines */
  cairo_set_line_width(cr, 1);
  cairo_set_source_rgb(cr, 0.85, 0.85, 0.85);
  for (i=ceil(-L->bx/L->ax/L->dx); ; ++i) {
    double wx = L->ax*i*L->dx + L->bx;
    if (wx > L->width) break;
    if (i%L->xmult == 0) continue;
    if (is_screen) wx = floor(wx) + .5;
    cairo_move_to(cr, wx, 0);
    cairo_line_to(cr, wx, L->height);
  }
  for (i=ceil((L->height-L->by)/L->ay/L->dy); ; ++i) {
    double wy = L->ay*i*L->dy + L->by;
    if (wy < 0) break;
    if (i%L->ymult == 0) continue;
    if (is_screen) wy = floor(wy) + .5;
    cairo_move_to(cr, 0, wy);
    cairo_line_to(cr, L->width, wy);
  }
  cairo_stroke(cr);

  /* major grid lines */
  cairo_set_line_width(cr, 2);
  cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
  for (i=ceil(-L->bx/L->ax/L->dx); ; ++i) {
    double wx = L->ax*i*L->dx + L->bx;
    if (wx > L->width) break;
    if (i%L->xmult) continue;
    if (is_screen) wx = floor(wx) + .5;
    cairo_move_to(cr, wx, 0);
    cairo_line_to(cr, wx, L->height);
  }
  for (i=ceil((L->height-L->by)/L->ay/L->dy); ; ++i) {
    double wy = L->ay*i*L->dy + L->by;
    if (wy < 0) break;
    if (i%L->ymult) continue;
    if (is_screen) wy = floor(wy) + .5;
    cairo_move_to(cr, 0, wy);
    cairo_line_to(cr, L->width, wy);
  }
  cairo_stroke(cr);

  /* grid labels */
  cairo_select_font_face(cr, "sans-serif",
                         CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
  cairo_set_font_size(cr, 12.0);
  for (i=ceil(-L->bx/L->ax/L->dx); ; ++i) {
    double wx = L->ax*i*L->dx + L->bx;
    if (wx > L->width) break;
    if (i%L->xmult) continue;
    if (is_screen) wx = floor(wx) + .5;

    char buffer[32];
    snprintf(buffer, 32, "%g", i*L->dx);

    cairo_text_extents_t te;
    cairo_text_extents(cr, buffer, &te);

    double xpos = wx - te.x_bearing - .5*te.width;
    if (xpos+te.x_bearing+te.width+2 > L->width) {
      /* make sure the right-most label is visible */
      xpos = L->width-te.x_bearing-te.width-2;
    }
    cairo_rectangle(cr, xpos+te.x_bearing-2, L->height-8+te.y_bearing-2,
                    te.width+4, te.height+4);
    cairo_set_source_rgba(cr, 1, 1, 1, .8);
    cairo_fill(cr);

    cairo_set_source_rgb(cr, 0, 0, 0);
    cairo_move_to(cr, xpos, L->height-8);
    cairo_show_text(cr, buffer);
  }
  for (i=ceil((L->height-L->by)/L->ay/L->dy); ; ++i) {
    double wy = L->ay*i*L->dy + L->by;
    if (wy < 0) break;
    if (i%L->ymult) continue;
    if (is_screen) wy = floor(wy) + .5;

    char buffer[32];
    snprintf(buffer, 32, "%g", i*L->dy);

    cairo_text_extents_t te;
    cairo_text_extents(cr, buffer, &te);

    cairo_rectangle(cr, 8+te.x_bearing-2, wy+4+te.y_bearing-2,
                    te.width+4, te.height+4);
    cairo_set_source_rgba(cr, 1, 1, 1, .8);
    cairo_fill(cr);

    cairo_set_source_rgb(cr, 0, 0, 0);
    cairo_move_to(cr, 8, wy+4);
    cairo_show_text(cr, buffer);
  }

  /* graphs for the data */
  for (k=0; k<state->dataset_used; ++k) {
    int cols = state->dataset[k].cols;
    int rows = state->dataset[k].rows;
    double *data = state->dataset[k].data;
    for (j=1; j<cols; ++j) {
      cairo_set_source_rgba(cr, 1, 1, 1, .5);
      if (rows == 1) {
        double x = data[0];
        double y = data[j];
        cairo_arc(cr, L->ax*x + L->bx, L->ay*y + L->by, 6, 0, 2*M_PI);
        cairo_close_path(cr);
        cairo_fill(cr);
      } else {
        cairo_set_line_width(cr, 6);
        cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
        cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
        for (i=0; i<rows; ++i) {
          double x = data[i*cols];
          double y = data[i*cols+j];
          double wx = L->ax*x + L->bx;
          double wy = L->ay*y + L->by;
          if (i == 0) {
            cairo_move_to(cr, wx, wy);
          } else {
            cairo_line_to(cr, wx, wy);
          };
        }
        cairo_stroke(cr);
      }

      int ci = (j-1)%100;
      cairo_set_source_rgb(cr, colors[ci].r, colors[ci].g, colors[ci].b);
      if (rows == 1) {
        double x = data[0];
        double y = data[j];
        cairo_arc(cr, L->ax*x + L->bx, L->ay*y + L->by, 4, 0, 2*M_PI);
        cairo_close_path(cr);
        cairo_fill(cr);
      } else {
        cairo_set_line_width(cr, 2);
        for (i=0; i<rows; ++i) {
          double x = data[i*cols];
          double y = data[i*cols+j];
          double wx = L->ax*x + L->bx;
          double wy = L->ay*y + L->by;
          if (i == 0) {
            cairo_move_to(cr, wx, wy);
          } else {
            cairo_line_to(cr, wx, wy);
          };
        }
        cairo_stroke(cr);
      }
    }
  }

 draw_message:
  /* state messages */
  if (state->message && is_screen) {
    cairo_select_font_face(cr, "sans-serif",
                           CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
    cairo_set_font_size(cr, 24.0);

    cairo_text_extents_t te;
    cairo_text_extents(cr, state->message, &te);
    double xpos = xres/2.54 - te.x_bearing;
    double ypos = yres/2.54 - te.y_bearing;
    cairo_rectangle(cr, xpos+te.x_bearing-2, ypos+te.y_bearing-2,
                    te.width+4, te.height+4);
    cairo_set_source_rgba(cr, 1, 1, 1, .8);
    cairo_fill(cr);

    cairo_set_source_rgb(cr, .8, 0, 0);
    cairo_move_to(cr, xpos, ypos);
    cairo_show_text(cr, state->message);
  }
}
Ejemplo n.º 24
0
void JoinedUp::drawCell (cairo_t *cr, gint x, gint y)
{
	int i, m, n;
	int segments[4];
	double xofs;
	double yofs;
	int c;
	int neighbours[8];
	static const int formtable[4][8] = {{0, 7, 0, 7, 4, 9, 4, 8},
					    {1, 4, 1, 4, 5, 10, 5, 8},
					    {2, 6, 2, 6, 7, 11, 7, 8},
					    {3, 5, 3, 5, 6, 12, 6, 8}};
	static const gdouble colours[7][3] = {{1.0, 0.0, 0.0},
					      {0.1, 0.8, 0.1},
					      {0.1, 0.1, 0.8},
					      {1.0, 1.0, 1.0},
					      {1.0, 1.0, 0.0},
					      {0.8, 0.1, 0.8},
					      {0.0, 1.0, 1.0}};
	static const int neighbourmap[8][2] = {{-1, -1}, {0, -1}, {+1, -1},
					       {-1, 0}, {+1, 0},
					       {-1, +1}, {0, +1}, {+1, +1}};

	if (data[x][y].what == EMPTY)
		return;

	i = data[x][y].color;
	i = CLAMP (i, 0, 6);

	cairo_save (cr);
	cairo_translate (cr, x, y);

	cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
	cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
	cairo_set_line_width (cr, 0.05);

	if (data[x][y].what == TARGET) {
		cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0);
	} else {
		cairo_set_source_rgb (cr, colours[i][0],
				      colours[i][1],
				      colours[i][2]);
	}
	cairo_rectangle (cr, -0.025, -0.025, 1.025, 1.025);
	cairo_fill (cr);
	cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);

	// Enumerate the neighbours.
	c = data[x][y].color;
	for (i=0; i<8; i++) {
		m = x + neighbourmap[i][0];
		n = y + neighbourmap[i][1];
		if ((m < 0) || (n < 0) || (m >= width) || (n >= height))
			neighbours[i] = 0;
		else
			neighbours[i] = ((data[m][n].what != EMPTY) &&
					 (data[m][n].color == c)) ? 1 : 0;
	}

	// Sort out which quadrant of the square is drawn in what way.
	segments[0] = formtable [0][neighbours[3]*4 +
				    neighbours[0]*2 +
				    neighbours[1]];
	segments[1] = formtable [1][neighbours[1]*4 +
				    neighbours[2]*2 +
				    neighbours[4]];
	segments[2] = formtable [2][neighbours[6]*4 +
				    neighbours[5]*2 +
				    neighbours[3]];
	segments[3] = formtable [3][neighbours[4]*4 +
				    neighbours[7]*2 +
				    neighbours[6]];

	// Finally: do the actual drawing.
	for (i=0; i<4; i++) {
		cairo_save (cr);
		xofs = 0.5*(i % 2);
		yofs = 0.5*(i / 2);
		cairo_translate (cr, xofs, yofs);
		switch (segments[i]) {
		case 0:
			drawOuterCorner (cr);
			break;
		case 1:
			cairo_scale (cr, -1.0, 1.0);
			cairo_translate (cr, -0.5, 0);
			drawOuterCorner (cr);
			break;
		case 2:
			cairo_scale (cr, 1.0, -1.0);
			cairo_translate (cr, 0, -0.5);
			drawOuterCorner (cr);
			break;
		case 3:
			cairo_scale (cr, -1.0, -1.0);
			cairo_translate (cr, -0.5, -0.5);
			drawOuterCorner (cr);
			break;
		case 4:
			drawHEdge (cr);
			break;
		case 5:
			cairo_scale (cr, -1.0, 1.0);
			cairo_translate (cr, -0.5, 0);
			drawVEdge (cr);
			break;
		case 6:
			cairo_scale (cr, 1.0, -1.0);
			cairo_translate (cr, 0, -0.5);
			drawHEdge (cr);
			break;
		case 7:
			drawVEdge (cr);
			break;

		case 8:
			break;
		case 9:
			drawInnerCorner (cr);
			break;
		case 10:
			cairo_scale (cr, -1.0, 1.0);
			cairo_translate (cr, -0.5, 0);
			drawInnerCorner (cr);
			break;
		case 11:
			cairo_scale (cr, 1.0, -1.0);
			cairo_translate (cr, 0, -0.5);
			drawInnerCorner (cr);
			break;
		case 12:
			cairo_scale (cr, -1.0, -1.0);
			cairo_translate (cr, -0.5, -0.5);
			drawInnerCorner (cr);
			break;
		}
		cairo_restore (cr);
	}

	cairo_restore (cr);
}
Ejemplo n.º 25
0
static cairo_status_t
twin_scaled_font_render_glyph (cairo_scaled_font_t  *scaled_font,
			       unsigned long         glyph,
			       cairo_t              *cr,
			       cairo_text_extents_t *metrics)
{
    double x1, y1, x2, y2, x3, y3;
    double marginl;
    twin_scaled_properties_t *props;
    twin_snap_info_t info;
    const int8_t *b;
    const int8_t *g;
    int8_t w;
    double gw;

    props = cairo_scaled_font_get_user_data (scaled_font, &twin_properties_key);

    /* Save glyph space, we need it when stroking */
    cairo_save (cr);

    /* center the pen */
    cairo_translate (cr, props->penx * .5, -props->peny * .5);

    /* small-caps */
    if (props->face_props->smallcaps && glyph >= 'a' && glyph <= 'z') {
	glyph += 'A' - 'a';
	/* 28 and 42 are small and capital letter heights of the glyph data */
	cairo_scale (cr, 1, 28. / 42);
    }

    /* slant */
    if (props->face_props->slant != CAIRO_FONT_SLANT_NORMAL) {
	cairo_matrix_t shear = { 1, 0, -.2, 1, 0, 0};
	cairo_transform (cr, &shear);
    }

    b = _cairo_twin_outlines +
	_cairo_twin_charmap[unlikely (glyph >= ARRAY_LENGTH (_cairo_twin_charmap)) ? 0 : glyph];
    g = twin_glyph_draw(b);
    w = twin_glyph_right(b);
    gw = F(w);

    marginl = props->marginl;

    /* monospace */
    if (props->face_props->monospace) {
	double monow = F(24);
	double extra =  props->penx + props->marginl + props->marginr;
	cairo_scale (cr, (monow + extra) / (gw + extra), 1);
	gw = monow;

	/* resnap margin for new transform */
	{
	    double x, y, x_scale, x_scale_inv;
	    x = 1; y = 0;
	    compute_hinting_scale (cr, x, y, &x_scale, &x_scale_inv);
	    marginl = SNAPXI (marginl);
	}
    }

    cairo_translate (cr, marginl, 0);

    /* stretch */
    cairo_scale (cr, props->stretch, 1);

    if (props->snap)
	twin_compute_snap (cr, &info, b);
    else
	info.n_snap_x = info.n_snap_y = 0;

    /* advance width */
    metrics->x_advance = gw * props->stretch + props->penx + props->marginl + props->marginr;

    /* glyph shape */
    for (;;) {
	switch (*g++) {
	case 'M':
	    cairo_close_path (cr);
	    /* fall through */
	case 'm':
	    x1 = SNAPX(*g++);
	    y1 = SNAPY(*g++);
	    cairo_move_to (cr, x1, y1);
	    continue;
	case 'L':
	    cairo_close_path (cr);
	    /* fall through */
	case 'l':
	    x1 = SNAPX(*g++);
	    y1 = SNAPY(*g++);
	    cairo_line_to (cr, x1, y1);
	    continue;
	case 'C':
	    cairo_close_path (cr);
	    /* fall through */
	case 'c':
	    x1 = SNAPX(*g++);
	    y1 = SNAPY(*g++);
	    x2 = SNAPX(*g++);
	    y2 = SNAPY(*g++);
	    x3 = SNAPX(*g++);
	    y3 = SNAPY(*g++);
	    cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
	    continue;
	case 'E':
	    cairo_close_path (cr);
	    /* fall through */
	case 'e':
	    cairo_restore (cr); /* restore glyph space */
	    cairo_set_tolerance (cr, 0.01);
	    cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
	    cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
	    cairo_set_line_width (cr, 1);
	    cairo_scale (cr, props->penx, props->peny);
	    cairo_stroke (cr);
	    break;
	case 'X':
	    /* filler */
	    continue;
	}
	break;
    }

    return CAIRO_STATUS_SUCCESS;
}
Ejemplo n.º 26
0
void TangoBlock::drawCell (cairo_t *cr, gint x, gint y)
{

	int i;
	cairo_pattern_t *pat = NULL;
	/* the following garbage is derived from the official tango style guide */
	const gdouble colours[8][3][3] = {
					  {{0.93725490196078431, 0.16078431372549021, 0.16078431372549021},
					   {0.8, 0.0, 0.0},
					   {0.64313725490196083, 0.0, 0.0}}, /* red */

					  {{0.54117647058823526, 0.88627450980392153, 0.20392156862745098},
					   {0.45098039215686275, 0.82352941176470584, 0.086274509803921567},
					   {0.30588235294117649, 0.60392156862745094, 0.023529411764705882}}, /* green */

					  {{0.44705882352941179, 0.62352941176470589, 0.81176470588235294},
					   {0.20392156862745098, 0.396078431372549, 0.64313725490196083},
					   {0.12549019607843137, 0.29019607843137257, 0.52941176470588236}}, /* blue */

					  {{0.93333333333333335, 0.93333333333333335, 0.92549019607843142},
					   {0.82745098039215681, 0.84313725490196079, 0.81176470588235294},
					   {0.72941176470588232, 0.74117647058823533, 0.71372549019607845}}, /* white */

					  {{0.9882352941176471, 0.9137254901960784, 0.30980392156862746},
					   {0.92941176470588238, 0.83137254901960789, 0.0},
					   {0.7686274509803922, 0.62745098039215685, 0.0}}, /* yellow */

					  {{0.67843137254901964, 0.49803921568627452, 0.6588235294117647},
					   {0.45882352941176469, 0.31372549019607843, 0.4823529411764706},
					   {0.36078431372549019, 0.20784313725490197, 0.4}}, /* purple */

					  {{0.9882352941176471, 0.68627450980392157, 0.24313725490196078},
					   {0.96078431372549022, 0.47450980392156861, 0.0},
					   {0.80784313725490198, 0.36078431372549019, 0.0}}, /* orange (replacing cyan) */

					  {{0.33, 0.34, 0.32},
					   {0.18, 0.2, 0.21},
					   {0.10, 0.12, 0.13}} /* grey */
					 };

	if (data[x][y].what == EMPTY)
		return;

	if (data[x][y].what == TARGET) {
		i = 7;
	} else {
		i = data[x][y].color;
		i = CLAMP (i, 0, 6);
	}

	if (usegrads) {
		 pat = cairo_pattern_create_linear (x+0.35, y, x+0.55, y+0.9);
		 cairo_pattern_add_color_stop_rgb (pat, 0.0, colours[i][0][0],
						   colours[i][0][1],
						   colours[i][0][2]);
		 cairo_pattern_add_color_stop_rgb (pat, 1.0, colours[i][1][0],
						   colours[i][1][1],
						   colours[i][1][2]);
		 cairo_set_source (cr, pat);
	} else {
		 cairo_set_source_rgb (cr, colours[i][0][0],
				       colours[i][0][1],
				       colours[i][0][2]);
	}

	drawRoundedRectangle (cr, x+0.05, y+0.05, 0.9, 0.9, 0.2);
	cairo_fill_preserve (cr);  /* fill with shaded gradient */


	if (usegrads)
		cairo_pattern_destroy(pat);
	cairo_set_source_rgb(cr, colours[i][2][0],
			     colours[i][2][1],
			     colours[i][2][2]);

	cairo_set_line_width (cr, 0.1);
	cairo_stroke (cr);  /* add darker outline */

	drawRoundedRectangle (cr, x+0.15, y+0.15, 0.7, 0.7, 0.08);
	if (data[x][y].what != TARGET) {
		if (usegrads) {
			pat = cairo_pattern_create_linear (x-0.3, y-0.3, x+0.8, y+0.8);
			switch (i) { /* yellow and white blocks need a brighter highlight */
			case 3:
			case 4:
				cairo_pattern_add_color_stop_rgba (pat, 0.0, 1.0,
								   1.0,
								   1.0,
								   1.0);
				cairo_pattern_add_color_stop_rgba (pat, 1.0, 1.0,
								   1.0,
								   1.0,
								   0.0);
				break;
			default:
				cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.9295,
								   0.9295,
								   0.9295,
								   1.0);
				cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.9295,
								   0.9295,
								   0.9295,
								   0.0);
				break;
			}
			cairo_set_source (cr, pat);
		} else {
			cairo_set_source_rgba (cr, 1.0,
					       1.0,
					       1.0,
					       0.35);
		}
	} else {  /* black preview block, use a much weaker highlight */
		cairo_set_source_rgba (cr, 1.0,
				       1.0,
				       1.0,
				       0.15);
	}
	cairo_stroke (cr);  /* add inner edge highlight */

	if (usegrads && (data[x][y].what != TARGET))
		cairo_pattern_destroy (pat);
}
Ejemplo n.º 27
0
static gboolean _lib_navigation_expose_callback(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
{
  dt_lib_module_t *self = (dt_lib_module_t *)user_data;
  dt_lib_navigation_t *d = (dt_lib_navigation_t *)self->data;

  const int inset = DT_NAVIGATION_INSET;
  GtkAllocation allocation;
  gtk_widget_get_allocation(widget, &allocation);
  int width = allocation.width, height = allocation.height;

  dt_develop_t *dev = darktable.develop;

  if(dev->preview_status != DT_DEV_PIXELPIPE_VALID) return FALSE;

  /* get the current style */
  GtkStyle *style = gtk_rc_get_style_by_paths(gtk_settings_get_default(), NULL, "GtkWidget", GTK_TYPE_WIDGET);
  if(!style) style = gtk_rc_get_style(widget);
  cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
  cairo_t *cr = cairo_create(cst);

  /* fill background */
  cairo_set_source_rgb(cr, style->bg[0].red / 65535.0, style->bg[0].green / 65535.0,
                       style->bg[0].blue / 65535.0);
  cairo_paint(cr);

  width -= 2 * inset;
  height -= 2 * inset;
  cairo_translate(cr, inset, inset);

  /* draw navigation image if available */
  if(dev->preview_pipe->backbuf && (dev->preview_status == DT_DEV_PIXELPIPE_VALID))
  {
    dt_pthread_mutex_t *mutex = &dev->preview_pipe->backbuf_mutex;
    dt_pthread_mutex_lock(mutex);
    const int wd = dev->preview_pipe->backbuf_width;
    const int ht = dev->preview_pipe->backbuf_height;
    const float scale = fminf(width / (float)wd, height / (float)ht);

    const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, wd);
    cairo_surface_t *surface
        = cairo_image_surface_create_for_data(dev->preview_pipe->backbuf, CAIRO_FORMAT_RGB24, wd, ht, stride);
    cairo_translate(cr, width / 2.0, height / 2.0f);
    cairo_scale(cr, scale, scale);
    cairo_translate(cr, -.5f * wd, -.5f * ht);

    // draw shadow around
    float alpha = 1.0f;
    for(int k = 0; k < 4; k++)
    {
      cairo_rectangle(cr, -k / scale, -k / scale, wd + 2 * k / scale, ht + 2 * k / scale);
      cairo_set_source_rgba(cr, 0, 0, 0, alpha);
      alpha *= 0.6f;
      cairo_fill(cr);
    }

    cairo_rectangle(cr, 0, 0, wd - 2, ht - 1);
    cairo_set_source_surface(cr, surface, 0, 0);
    cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_FAST);
    cairo_fill(cr);
    cairo_surface_destroy(surface);

    dt_pthread_mutex_unlock(mutex);

    // draw box where we are
    dt_dev_zoom_t zoom = dt_control_get_dev_zoom();
    int closeup = dt_control_get_dev_closeup();
    float zoom_x = dt_control_get_dev_zoom_x();
    float zoom_y = dt_control_get_dev_zoom_y();
    const float min_scale = dt_dev_get_zoom_scale(dev, DT_ZOOM_FIT, closeup ? 2.0 : 1.0, 0);
    const float cur_scale = dt_dev_get_zoom_scale(dev, zoom, closeup ? 2.0 : 1.0, 0);
    // avoid numerical instability for small resolutions:
    double h, w;
    if(cur_scale > min_scale)
    {
      float boxw = 1, boxh = 1;
      dt_dev_check_zoom_bounds(darktable.develop, &zoom_x, &zoom_y, zoom, closeup, &boxw, &boxh);

      cairo_translate(cr, wd * (.5f + zoom_x), ht * (.5f + zoom_y));
      cairo_set_source_rgb(cr, 0., 0., 0.);
      cairo_set_line_width(cr, 1.f / scale);
      boxw *= wd;
      boxh *= ht;
      cairo_rectangle(cr, -boxw / 2 - 1, -boxh / 2 - 1, boxw + 2, boxh + 2);
      cairo_stroke(cr);
      cairo_set_source_rgb(cr, 1., 1., 1.);
      cairo_rectangle(cr, -boxw / 2, -boxh / 2, boxw, boxh);
      cairo_stroke(cr);
    }
    if(fabsf(cur_scale - min_scale) > 0.001f)
    {
      /* Zoom % */
      cairo_identity_matrix(cr);
      cairo_translate(cr, 0, height);
      cairo_set_source_rgba(cr, 1., 1., 1., 0.5);
      cairo_select_font_face(cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
      cairo_set_font_size(cr, DT_PIXEL_APPLY_DPI(11));

      char zoomline[5];
      snprintf(zoomline, sizeof(zoomline), "%.0f%%", cur_scale * 100);

      cairo_text_extents_t ext;
      cairo_text_extents(cr, zoomline, &ext);
      h = d->zoom_h = ext.height;
      w = d->zoom_w = ext.width;

      cairo_move_to(cr, width - w - h * 1.1, 0);

      cairo_save(cr);
      cairo_set_line_width(cr, 2.0);
      cairo_set_source_rgb(cr, style->bg[0].red / 65535.0, style->bg[0].green / 65535.0,
                           style->bg[0].blue / 65535.0);
      cairo_text_path(cr, zoomline);
      cairo_stroke_preserve(cr);
      cairo_set_source_rgb(cr, 0.6, 0.6, 0.6);
      cairo_fill(cr);
      cairo_restore(cr);
    }
    else
    {
      // draw the zoom-to-fit icon
      cairo_identity_matrix(cr);
      cairo_translate(cr, 0, height);
      cairo_set_source_rgb(cr, 0.6, 0.6, 0.6);
      cairo_text_extents_t ext;
      cairo_select_font_face(cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
      cairo_set_font_size(cr, DT_PIXEL_APPLY_DPI(11));
      cairo_text_extents(cr, "100%", &ext); // dummy text, just to get the height
      h = d->zoom_h = ext.height;
      w = h * 1.5;
      float sp = h * 0.6;
      d->zoom_w = w + sp;

      cairo_move_to(cr, width - w - h - sp, -1.0 * h);
      cairo_rectangle(cr, width - w - h - sp, -1.0 * h, w, h);
      cairo_set_source_rgb(cr, 0.2, 0.2, 0.2);
      cairo_fill(cr);

      cairo_set_source_rgb(cr, 0.6, 0.6, 0.6);
      cairo_move_to(cr, width - w * 0.8 - h - sp, -1.0 * h);
      cairo_line_to(cr, width - w - h - sp, -1.0 * h);
      cairo_line_to(cr, width - w - h - sp, -0.7 * h);
      cairo_stroke(cr);
      cairo_move_to(cr, width - w - h - sp, -0.3 * h);
      cairo_line_to(cr, width - w - h - sp, 0);
      cairo_line_to(cr, width - w * 0.8 - h - sp, 0);
      cairo_stroke(cr);
      cairo_move_to(cr, width - w * 0.2 - h - sp, 0);
      cairo_line_to(cr, width - h - sp, 0);
      cairo_line_to(cr, width - h - sp, -0.3 * h);
      cairo_stroke(cr);
      cairo_move_to(cr, width - h - sp, -0.7 * h);
      cairo_line_to(cr, width - h - sp, -1.0 * h);
      cairo_line_to(cr, width - w * 0.2 - h - sp, -1.0 * h);
      cairo_stroke(cr);
    }

    cairo_move_to(cr, width - 0.95 * h, -0.9 * h);
    cairo_line_to(cr, width - 0.05 * h, -0.9 * h);
    cairo_line_to(cr, width - 0.5 * h, -0.1 * h);
    cairo_fill(cr);
  }

  /* blit memsurface into widget */
  cairo_destroy(cr);
  cairo_t *cr_pixmap = gdk_cairo_create(gtk_widget_get_window(widget));
  cairo_set_source_surface(cr_pixmap, cst, 0, 0);
  cairo_paint(cr_pixmap);
  cairo_destroy(cr_pixmap);
  cairo_surface_destroy(cst);

  return TRUE;
}
static gboolean
awn_throbber_expose_event (GtkWidget *widget, GdkEventExpose *event)
{
    AwnThrobberPrivate *priv = AWN_THROBBER (widget)->priv;
    cairo_t *cr;
    gint w, h;
    GtkPositionType pos_type;

    /* clip the drawing region, nvidia likes it */
    AwnEffects *fx = awn_overlayable_get_effects (AWN_OVERLAYABLE (widget));
    cr = awn_effects_cairo_create_clipped (fx, event);

    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);

    // we'll paint to [0,0] - [1,1], so scale's needed
    g_object_get (G_OBJECT (widget), "icon-width", &w, "icon-height", &h, NULL);
    cairo_scale (cr, w, h);

    switch (priv->type)
    {
    case AWN_THROBBER_TYPE_NORMAL:
    {
        const gdouble RADIUS = 0.0625;
        const gdouble DIST = 0.3;
        const gdouble OTHER = DIST * 0.707106781; /* sqrt(2)/2 */
        const gint COUNT = 8;
        const gint counter = priv->counter;

        cairo_set_line_width (cr, 1. / priv->size);
        cairo_translate (cr, 0.5, 0.5);
        cairo_scale (cr, 1, -1);

#define PAINT_CIRCLE(cr, x, y, cnt) \
    awn_cairo_set_source_color_with_alpha_multiplier (cr, \
        priv->fill_color, ((counter+cnt) % COUNT) / (float)COUNT); \
    cairo_arc (cr, x, y, RADIUS, 0, 2*M_PI); \
    cairo_fill_preserve (cr); \
    awn_cairo_set_source_color_with_alpha_multiplier (cr, \
        priv->outline_color, ((counter+cnt) % COUNT) / (float)COUNT); \
    cairo_stroke (cr);

        PAINT_CIRCLE (cr, 0, DIST, 0);
        PAINT_CIRCLE (cr, OTHER, OTHER, 1);
        PAINT_CIRCLE (cr, DIST, 0, 2);
        PAINT_CIRCLE (cr, OTHER, -OTHER, 3);
        PAINT_CIRCLE (cr, 0, -DIST, 4);
        PAINT_CIRCLE (cr, -OTHER, -OTHER, 5);
        PAINT_CIRCLE (cr, -DIST, 0, 6);
        PAINT_CIRCLE (cr, -OTHER, OTHER, 7);

#undef PAINT_CIRCLE

        break;
    }
    case AWN_THROBBER_TYPE_SAD_FACE:
    {
        cairo_set_line_width (cr, 0.03);

        if (priv->fill_color == NULL)
        {
            GdkColor c;
            double r, g, b;

            c = gtk_widget_get_style (widget)->fg[GTK_STATE_NORMAL];
            r = c.red / 65535.0;
            g = c.green / 65535.0;
            b = c.blue / 65535.0;

            cairo_set_source_rgb (cr, r, g, b);
        }
        else
        {
            awn_cairo_set_source_color_with_alpha_multiplier (cr,
                    priv->fill_color,
                    0.75);
        }

        paint_sad_face (cr);

        break;
    }
    case AWN_THROBBER_TYPE_ARROW_1:
        cairo_rotate (cr, M_PI);
        cairo_translate (cr, -1.0, -1.0);
    // no break
    case AWN_THROBBER_TYPE_ARROW_2:
    {
        pos_type = awn_icon_get_pos_type (AWN_ICON (widget));

        if (pos_type == GTK_POS_LEFT || pos_type == GTK_POS_RIGHT)
        {
            cairo_rotate (cr, 0.5 * M_PI);
            cairo_translate (cr, 0.0, -1.0);
        }

        if (priv->outline_color)
        {
            cairo_set_line_width (cr, 3.5 / priv->size);
            awn_cairo_set_source_color (cr, priv->outline_color);

            cairo_move_to (cr, 0.125, 0.375);
            cairo_line_to (cr, 0.875, 0.5);
            cairo_line_to (cr, 0.125, 0.625);
            cairo_stroke (cr);
        }

        cairo_set_line_width (cr, 1.75 / priv->size);

        if (priv->fill_color == NULL)
        {
            GdkColor c = gtk_widget_get_style (widget)->fg[GTK_STATE_NORMAL];
            double r = c.red / 65535.0;
            double g = c.green / 65535.0;
            double b = c.blue / 65535.0;

            cairo_set_source_rgb (cr, r, g, b);
        }
        else
        {
            awn_cairo_set_source_color (cr, priv->fill_color);
        }

        cairo_move_to (cr, 0.125, 0.375);
        cairo_line_to (cr, 0.875, 0.5);
        cairo_line_to (cr, 0.125, 0.625);
        cairo_stroke (cr);

        break;
    }
    case AWN_THROBBER_TYPE_CLOSE_BUTTON:
    {
        cairo_set_line_width (cr, 1. / priv->size);

        cairo_pattern_t *pat = cairo_pattern_create_linear (0.0, 0.0, 0.5, 1.0);
        cairo_pattern_add_color_stop_rgb (pat, 0.0, 0.97254, 0.643137, 0.403921);
        //cairo_pattern_add_color_stop_rgb (pat, 0.0, 0.0, 0.0, 0.0); // test
        cairo_pattern_add_color_stop_rgb (pat, 0.7, 0.98823, 0.4, 0.0);
        cairo_pattern_add_color_stop_rgb (pat, 1.0, 0.98823, 0.4, 0.0);

        cairo_set_source (cr, pat);
        //cairo_arc (cr, 0.5, 0.5, 0.4, 0.0, 2 * M_PI);
        awn_cairo_rounded_rect (cr, 0.1, 0.1, 0.8, 0.8, 0.15, ROUND_ALL);
        cairo_fill_preserve (cr);

        cairo_pattern_destroy (pat);

        cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
        cairo_stroke (cr);

        cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
        cairo_set_line_width (cr, 2./priv->size);

        /*  \  starting with the upper point  */
        cairo_move_to (cr, 0.3, 0.25);
        cairo_line_to (cr, 0.7, 0.75);
        cairo_stroke (cr);
        /*  /  starting with the upper point  */
        cairo_move_to (cr, 0.7, 0.25);
        cairo_line_to (cr, 0.3, 0.75);
        cairo_stroke (cr);
        break;
    }
    default:
        break;
    }

    /* let effects know we're finished */
    awn_effects_cairo_destroy (fx);

    return TRUE;
}
Ejemplo n.º 29
0
void Drawer::DrawArc(const Point& aPoint, double aRadius, double aRadian, double aWidth/*=10*/)
{
    cairo_arc (mCairoDC, aPoint.X, aPoint.Y, aRadius, 0, aRadian);
    cairo_set_line_width(mCairoDC, aWidth);
    cairo_stroke(mCairoDC);
}
Ejemplo n.º 30
0
static cairo_surface_t *
pixmap_create (PolygonView *self, cairo_surface_t *target)
{
    cairo_surface_t *surface =
	cairo_surface_create_similar (target, CAIRO_CONTENT_COLOR,
				      self->widget.allocation.width,
				      self->widget.allocation.height);
    cairo_t *cr = cairo_create (surface);
    polygon_t *polygon;
    gdouble sf_x, sf_y, sf;
    gdouble mid, dim;
    gdouble x0,  y0;
    box_t extents;

    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);

    if (self->polygons == NULL) {
	cairo_destroy(cr);
	return surface;
    }

    extents = self->extents;

    mid = (extents.p2.x + extents.p1.x) / 2.;
    dim = (extents.p2.x - extents.p1.x) / 2. * 1.25;
    sf_x = self->widget.allocation.width / dim / 2;

    mid = (extents.p2.y + extents.p1.y) / 2.;
    dim = (extents.p2.y - extents.p1.y) / 2. * 1.25;
    sf_y = self->widget.allocation.height / dim / 2;

    sf = MIN (sf_x, sf_y);

    mid = (extents.p2.x + extents.p1.x) / 2.;
    dim = sf_x / sf * (extents.p2.x - extents.p1.x) / 2. * 1.25;
    x0 = mid - dim;
    mid = (extents.p2.y + extents.p1.y) / 2.;
    dim = sf_y / sf * (extents.p2.y - extents.p1.y) / 2. * 1.25;
    y0 = mid - dim;

    cairo_save (cr); {
	cairo_scale (cr, sf, sf);
	cairo_translate (cr, -x0, -y0);

	for (polygon = self->polygons; polygon; polygon = polygon->next) {
	    if (polygon->num_edges == 0)
		continue;

	    draw_polygon (cr, polygon, sf);
	}

	if (highlight != -1) {
	    cairo_move_to (cr, extents.p1.x, highlight);
	    cairo_line_to (cr, extents.p2.x, highlight);
	    cairo_set_source_rgb (cr, 0, .7, 0);
	    cairo_save (cr);
	    cairo_identity_matrix (cr);
	    cairo_set_line_width (cr, 1.);
	    cairo_stroke (cr);
	    cairo_restore (cr);
	}
    } cairo_restore (cr);

    cairo_destroy (cr);
    return surface;
}