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); }
static cairo_surface_t * snapshot_widget (GtkWidget *widget, SnapshotMode mode) { cairo_surface_t *surface; cairo_pattern_t *bg; GMainLoop *loop; cairo_t *cr; g_assert (gtk_widget_get_realized (widget)); surface = gdk_window_create_similar_surface (gtk_widget_get_window (widget), CAIRO_CONTENT_COLOR, gtk_widget_get_allocated_width (widget), gtk_widget_get_allocated_height (widget)); loop = g_main_loop_new (NULL, FALSE); /* We wait until the widget is drawn for the first time. * We can not wait for a GtkWidget::draw event, because that might not * happen if the window is fully obscured by windowed child widgets. * Alternatively, we could wait for an expose event on widget's window. * Both of these are rather hairy, not sure what's best. */ gdk_event_handler_set (check_for_draw, loop, NULL); g_main_loop_run (loop); cr = cairo_create (surface); switch (mode) { case SNAPSHOT_WINDOW: { GdkWindow *window = gtk_widget_get_window (widget); if (gdk_window_get_window_type (window) == GDK_WINDOW_TOPLEVEL || gdk_window_get_window_type (window) == GDK_WINDOW_FOREIGN) { /* give the WM/server some time to sync. They need it. * Also, do use popups instead of toplevls in your tests * whenever you can. */ gdk_display_sync (gdk_window_get_display (window)); g_timeout_add (500, quit_when_idle, loop); g_main_loop_run (loop); } gdk_cairo_set_source_window (cr, window, 0, 0); cairo_paint (cr); } break; case SNAPSHOT_DRAW: bg = gdk_window_get_background_pattern (gtk_widget_get_window (widget)); if (bg) { cairo_set_source (cr, bg); cairo_paint (cr); } gtk_widget_draw (widget, cr); break; default: g_assert_not_reached(); break; } cairo_destroy (cr); g_main_loop_unref (loop); gtk_widget_destroy (widget); return surface; }
static gboolean gtk_clock_draw (GtkWidget *clock, cairo_t *cr) { gint width = gtk_widget_get_allocated_width (clock); gint height = gtk_widget_get_allocated_height (clock); gdouble cx = width / 2.0; gdouble cy = height / 2.0; gdouble radius = MIN (width/2, height/2) - 5; gint inset; gint i; GtkClockPrivate *priv = GTK_CLOCK_GET_PRIVATE (clock); struct tm *time = &priv->time; cairo_pattern_t *pat; cairo_arc (cr, cx, cy, radius, 0, 2 * M_PI); cairo_set_source_rgba (cr, 1, 1, 1, 0.5); cairo_fill_preserve (cr); cairo_set_source_rgb (cr, 0, 0, 0); cairo_stroke (cr); for (i = 0; i < 12; i++) { cairo_save (cr); if (i % 3 == 0) inset = 0.2 * radius; else { inset = 0.1 * radius; cairo_set_line_width (cr, 0.5 * cairo_get_line_width (cr)); } cairo_move_to (cr, cx + (radius - inset) * cos (i * M_PI / 6), cy + (radius - inset) * sin (i * M_PI / 6)); cairo_line_to (cr, cx + radius * cos (i * M_PI / 6), cy + radius * sin (i * M_PI / 6)); cairo_stroke (cr); cairo_restore (cr); } cairo_set_line_width (cr, 2.0 * cairo_get_line_width (cr)); cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); cairo_move_to (cr, cx, cy); cairo_line_to (cr, cx + radius / 2 * sin (M_PI / 6 * time->tm_hour + M_PI / 360 * time->tm_min), cy + radius / 2 * -cos (M_PI / 6 * time->tm_hour + M_PI / 360 * time->tm_min)); cairo_stroke (cr); cairo_move_to (cr, cx, cy); cairo_line_to (cr, cx + radius * 0.75 * sin (M_PI / 30 * time->tm_min), cy + radius * 0.75 * -cos (M_PI / 30 * time->tm_min)); cairo_stroke (cr); cairo_set_line_width (cr, 0.2 * cairo_get_line_width (cr)); cairo_set_source_rgb (cr, 1, 0, 0); cairo_move_to (cr, cx, cy); cairo_line_to (cr, cx + radius * 0.75 * sin (M_PI / 30 * time->tm_sec), cy + radius * 0.75 * -cos (M_PI / 30 * time->tm_sec)); cairo_stroke (cr); cairo_arc (cr, cx, cy, radius, 0.0, 2.0 * M_PI); pat = cairo_pattern_create_radial (cx, cy, radius, cx, 0, radius); cairo_pattern_add_color_stop_rgba (pat, 0, 0, 0, 0, 0.4); cairo_pattern_add_color_stop_rgba (pat, 1, 1, 1, 1, 0.0); cairo_set_source (cr, pat); cairo_fill (cr); cairo_pattern_destroy (pat); return TRUE; }
static gboolean draw (ClutterCanvas *canvas, cairo_t *cr, int width_raw, int height_raw) { /* rounded rectangle taken from: * * http://cairographics.org/samples/rounded_rectangle/ * * we leave 1 pixel around the edges to avoid jagged edges * when rotating the actor */ double x = 1.0, /* parameters like cairo_rectangle */ y = 1.0, width = width_raw - 2.0, height = height_raw - 2.0, corner_radius = 5.0, tab_radius = 20.0; double radius = corner_radius ; double degrees = M_PI / 180.0; cairo_pattern_t *gradient; cairo_surface_t *image; cairo_pattern_t *imagelol; cairo_surface_t *image2; cairo_pattern_t *imagelol2; cairo_save (cr); cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint (cr); cairo_restore (cr); cairo_new_sub_path (cr); cairo_arc (cr, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees); cairo_arc (cr, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees); /*bottom-left*/cairo_arc (cr, x + radius + 30, y + height - radius, radius, 90 * degrees, 180 * degrees); cairo_arc_negative (cr, x + 30 - tab_radius, 225, tab_radius, 0 * degrees, -45 * degrees); cairo_arc (cr, x + tab_radius, 255 - 75, tab_radius, 135 * degrees, 180 * degrees); cairo_arc (cr, x + tab_radius, 255 - 75 - 85, tab_radius, 180 * degrees, 225 * degrees); cairo_arc_negative (cr, x + 30 - tab_radius, 255 - 75 - 85 - 45, tab_radius, 45 * degrees, 0 * degrees); /*top-left*/cairo_arc (cr, x + radius + 30, y + radius, radius, 180 * degrees, 270 * degrees); cairo_close_path (cr); cairo_set_source_rgba (cr, 0.145098*1.7, 0.317647*1.6, 0.380392*1.5, 0.6); cairo_fill_preserve (cr); gradient = cairo_pattern_create_linear(0.0, 0.0, 0.0, 60); cairo_pattern_add_color_stop_rgba(gradient, 1, 0, 0, 0, 0); cairo_pattern_add_color_stop_rgba(gradient, 0, 1*.7, 1*.9, 1, .15); cairo_set_source(cr, gradient); cairo_fill_preserve(cr); gradient = cairo_pattern_create_linear(0.0, 0.0, 50.0, 0.0); cairo_pattern_add_color_stop_rgba(gradient, 1, 0, 0, 0, 0); cairo_pattern_add_color_stop_rgba(gradient, 0, 1*.7, 1*.9, 1, .08); cairo_set_source(cr, gradient); cairo_fill_preserve(cr); /*image = cairo_image_surface_create_from_png("/home/jason/workspace/lol/src/noise.png"); imagelol = cairo_pattern_create_for_surface(image); cairo_set_source(cr, imagelol); cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); cairo_set_operator(cr, CAIRO_OPERATOR_ADD); cairo_clip(cr); cairo_paint_with_alpha(cr, .1);*/ /* image2 = cairo_image_surface_create_from_png("/home/jason/Desktop/lol.png"); imagelol2 = cairo_pattern_create_for_surface(image2); cairo_set_source(cr, imagelol2); cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_paint_with_alpha(cr, .25); *//* we're done drawing */ return TRUE; }
static void render (GtkCellRenderer *cell, GdkDrawable *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, GtkCellRendererState flags) { GtkCellRendererBubblePrivate *priv; cairo_t *cr; cairo_pattern_t *pattern; GdkColor *start; GdkColor *stop; g_return_if_fail (GTK_IS_CELL_RENDERER_BUBBLE (cell)); priv = GTK_CELL_RENDERER_BUBBLE (cell)->priv; if (priv->show_bubble) { cr = gdk_cairo_create (GDK_DRAWABLE (window)); g_assert (cr); start = &widget->style->light [GTK_STATE_SELECTED]; stop = &widget->style->mid [GTK_STATE_SELECTED]; pattern = cairo_pattern_create_linear (cell_area->x, cell_area->y, cell_area->x, cell_area->y + cell_area->height); cairo_pattern_add_color_stop_rgb (pattern, 0.3, start->red / (gdouble)G_MAXUINT16, start->green / (gdouble)G_MAXUINT16, start->blue / (gdouble)G_MAXUINT16); cairo_pattern_add_color_stop_rgb (pattern, 0.9, stop->red / (gdouble)G_MAXUINT16, stop->green / (gdouble)G_MAXUINT16, stop->blue / (gdouble)G_MAXUINT16); rounded_rectangle (cr, cell_area->x, cell_area->y + 1, cell_area->width, cell_area->height - 2, cell_area->height / 2.5, cell_area->height / 2.5); cairo_set_source (cr, pattern); cairo_fill_preserve (cr); gdk_cairo_set_source_color (cr, &widget->style->dark [GTK_STATE_SELECTED]); cairo_set_line_width (cr, 1.0); cairo_stroke (cr); rounded_rectangle (cr, cell_area->x + 1.0, cell_area->y + 2.0, cell_area->width - 2.0, cell_area->height - 4.0, cell_area->height / 2.5, cell_area->height / 2.5); gdk_cairo_set_source_color (cr, &widget->style->light [GTK_STATE_SELECTED]); cairo_stroke (cr); cairo_destroy (cr); } GTK_CELL_RENDERER_CLASS (gtk_cell_renderer_bubble_parent_class)-> render (cell, window, widget, background_area, cell_area, expose_area, flags); }
static void gtk_css_image_radial_draw (GtkCssImage *image, cairo_t *cr, double width, double height) { GtkCssImageRadial *radial = GTK_CSS_IMAGE_RADIAL (image); cairo_pattern_t *pattern; cairo_matrix_t matrix; double x, y; double radius, yscale; double start, end; double r1, r2, r3, r4, r; double offset; int i, last; x = _gtk_css_position_value_get_x (radial->position, width); y = _gtk_css_position_value_get_y (radial->position, height); if (radial->circle) { switch (radial->size) { case GTK_CSS_EXPLICIT_SIZE: radius = _gtk_css_number_value_get (radial->sizes[0], width); break; case GTK_CSS_CLOSEST_SIDE: radius = MIN (MIN (x, width - x), MIN (y, height - y)); break; case GTK_CSS_FARTHEST_SIDE: radius = MAX (MAX (x, width - x), MAX (y, height - y)); break; case GTK_CSS_CLOSEST_CORNER: case GTK_CSS_FARTHEST_CORNER: r1 = x*x + y*y; r2 = x*x + (height - y)*(height - y); r3 = (width - x)*(width - x) + y*y; r4 = (width - x)*(width - x) + (height - y)*(height - y); if (radial->size == GTK_CSS_CLOSEST_CORNER) r = MIN ( MIN (r1, r2), MIN (r3, r4)); else r = MAX ( MAX (r1, r2), MAX (r3, r4)); radius = sqrt (r); break; default: g_assert_not_reached (); } radius = MAX (1.0, radius); yscale = 1.0; } else { double hradius, vradius; switch (radial->size) { case GTK_CSS_EXPLICIT_SIZE: hradius = _gtk_css_number_value_get (radial->sizes[0], width); vradius = _gtk_css_number_value_get (radial->sizes[1], height); break; case GTK_CSS_CLOSEST_SIDE: hradius = MIN (x, width - x); vradius = MIN (y, height - y); break; case GTK_CSS_FARTHEST_SIDE: hradius = MAX (x, width - x); vradius = MAX (y, height - y); break; case GTK_CSS_CLOSEST_CORNER: hradius = M_SQRT2 * MIN (x, width - x); vradius = M_SQRT2 * MIN (y, height - y); break; case GTK_CSS_FARTHEST_CORNER: hradius = M_SQRT2 * MAX (x, width - x); vradius = M_SQRT2 * MAX (y, height - y); break; default: g_assert_not_reached (); } hradius = MAX (1.0, hradius); vradius = MAX (1.0, vradius); radius = hradius; yscale = vradius / hradius; } gtk_css_image_radial_get_start_end (radial, radius, &start, &end); pattern = cairo_pattern_create_radial (0, 0, 0, 0, 0, radius); if (yscale != 1.0) { cairo_matrix_init_scale (&matrix, 1.0, 1.0 / yscale); cairo_pattern_set_matrix (pattern, &matrix); } if (radial->repeating) cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); else cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD); offset = start; last = -1; for (i = 0; i < radial->stops->len; i++) { GtkCssImageRadialColorStop *stop; double pos, step; stop = &g_array_index (radial->stops, GtkCssImageRadialColorStop, i); if (stop->offset == NULL) { if (i == 0) pos = 0.0; else if (i + 1 == radial->stops->len) pos = 1.0; else continue; } else pos = _gtk_css_number_value_get (stop->offset, radius) / radius; pos = MAX (pos, 0); step = pos / (i - last); for (last = last + 1; last <= i; last++) { const GdkRGBA *rgba; stop = &g_array_index (radial->stops, GtkCssImageRadialColorStop, last); rgba = _gtk_css_rgba_value_get_rgba (stop->color); offset += step; cairo_pattern_add_color_stop_rgba (pattern, (offset - start) / (end - start), rgba->red, rgba->green, rgba->blue, rgba->alpha); } offset = pos; last = i; } cairo_rectangle (cr, 0, 0, width, height); cairo_translate (cr, x, y); cairo_set_source (cr, pattern); cairo_fill (cr); cairo_pattern_destroy (pattern); }
int main(int argc, char **argv){ float width=8.5*72.0; float height=11.0*72.0; float xoff=0; float yoff=0; float fontsize=-1; int havey=0; float dpp=300.0/72.0; char *text=NULL; int c,long_option_index; cairo_surface_t *cs; cairo_t *ct; cairo_text_extents_t extents; while((c=getopt_long(argc,argv,optstring,options,&long_option_index))!=EOF){ switch(c){ case 'W': case 'H': case 'x': case 'y': { float temp; if(strstr(optarg,"cm")){ temp=atof(optarg)*28.3464566929; }else if (strstr(optarg,"mm")){ temp=atof(optarg)*2.83464566929; }else if (strstr(optarg,"pt")){ temp=atof(optarg); }else{ temp=atof(optarg)*72.0; } switch(c){ case 'W': width=temp; break; case 'H': height=temp; break; case 'x': xoff=temp; break; case 'y': yoff=temp; havey=1; break; } } break; case 'r': if(strstr(optarg,"dpcm")){ dpp=atof(optarg)*.03527777777778; }else if (strstr(optarg,"dpmm")){ dpp=atof(optarg)*.35277777777778; }else if (strstr(optarg,"dpp")){ dpp=atof(optarg); }else{ dpp=atof(optarg)*.01388888888889; } break; case 'f': fontsize=atof(optarg); break; case 't': text=strdup(optarg); break; case 'h': usage(stdout); exit(0); case 'v': fprintf(stderr,"pngxpdf "VERSION"\n"); default: usage(stderr); } } /* set up our surface */ cs = cairo_pdf_surface_create_for_stream (pdf_write, NULL, width, height); if(!cs || cairo_surface_status(cs)!=CAIRO_STATUS_SUCCESS){ fprintf(stderr,"CAIRO ERROR: Unable to create PDF surface.\n\n"); exit(1); } ct = cairo_create(cs); if(fontsize<=0){ fontsize=height*15./792.; if(fontsize<5)fontsize=5; } cairo_set_font_size(ct, fontsize); if(text){ cairo_text_extents(ct, text, &extents); if(!havey) yoff = -extents.height-fontsize*4; } /* Iterate through PNG files inline */ while(optind<argc){ int ww, hh; char *filename = argv[optind]; cairo_pattern_t *pattern; cairo_surface_t *ps=cairo_image_surface_create_from_png(filename); cairo_status_t status = cairo_surface_status(ps); if(!ps || status!=CAIRO_STATUS_SUCCESS){ fprintf(stderr,"CAIRO ERROR: Unable to load PNG file %s: %s\n\n",filename,cairo_status_to_string(status)); exit(1); } ww = cairo_image_surface_get_width(ps); hh = cairo_image_surface_get_height(ps); cairo_save(ct); cairo_scale(ct, 1./dpp, 1./dpp); pattern = cairo_pattern_create_for_surface(ps); cairo_translate(ct,(width*dpp - (ww-1))*.5,((height+yoff)*dpp - (hh-1))*.5); cairo_pattern_set_filter(pattern, CAIRO_FILTER_BEST); cairo_set_source(ct,pattern); cairo_paint(ct); cairo_restore(ct); /* draw comment text */ if(text){ cairo_set_source_rgba(ct, 1,1,1,.75); cairo_move_to(ct, width-extents.width-fontsize*1.5, height-fontsize*1.5); cairo_text_path (ct, text); cairo_set_line_width(ct,3.); cairo_set_line_join(ct,CAIRO_LINE_JOIN_ROUND); cairo_stroke(ct); cairo_set_source_rgb(ct, 0,0,0); cairo_move_to(ct, width-extents.width-fontsize*1.5, height-fontsize*1.5); cairo_show_text(ct, text); } cairo_surface_show_page(cs); cairo_surface_destroy(ps); optind++; } cairo_destroy(ct); cairo_surface_destroy(cs); }
void render_image(struct window *window, cairo_surface_t *image, enum scaling_mode scaling_mode) { double width = cairo_image_surface_get_width(image); double height = cairo_image_surface_get_height(image); switch (scaling_mode) { case SCALING_MODE_STRETCH: cairo_scale(window->cairo, (double) window->width / width, (double) window->height / height); cairo_set_source_surface(window->cairo, image, 0, 0); break; case SCALING_MODE_FILL: { double window_ratio = (double) window->width / window->height; double bg_ratio = width / height; if (window_ratio > bg_ratio) { double scale = (double) window->width / width; cairo_scale(window->cairo, scale, scale); cairo_set_source_surface(window->cairo, image, 0, (double) window->height/2 / scale - height/2); } else { double scale = (double) window->height / height; cairo_scale(window->cairo, scale, scale); cairo_set_source_surface(window->cairo, image, (double) window->width/2 / scale - width/2, 0); } break; } case SCALING_MODE_FIT: { double window_ratio = (double) window->width / window->height; double bg_ratio = width / height; if (window_ratio > bg_ratio) { double scale = (double) window->height / height; cairo_scale(window->cairo, scale, scale); cairo_set_source_surface(window->cairo, image, (double) window->width/2 / scale - width/2, 0); } else { double scale = (double) window->width / width; cairo_scale(window->cairo, scale, scale); cairo_set_source_surface(window->cairo, image, 0, (double) window->height/2 / scale - height/2); } break; } case SCALING_MODE_CENTER: cairo_set_source_surface(window->cairo, image, (double) window->width/2 - width/2, (double) window->height/2 - height/2); break; case SCALING_MODE_TILE: { cairo_pattern_t *pattern = cairo_pattern_create_for_surface(image); cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); cairo_set_source(window->cairo, pattern); break; } } cairo_paint(window->cairo); }
void WallScreen::drawSwitcherBackground () { cairo_t *cr; cairo_pattern_t *pattern; float outline = 2.0f; int width, height, radius; float r, g, b, a; destroyCairoContext (switcherContext); setupCairoContext (switcherContext); cr = switcherContext.cr; clearCairoLayer (cr); width = switcherContext.width - outline; height = switcherContext.height - outline; cairo_save (cr); cairo_translate (cr, outline / 2.0f, outline / 2.0f); /* set the pattern for the switcher's background */ pattern = cairo_pattern_create_linear (0, 0, width, height); getColorRGBA (BackgroundGradientBaseColor); cairo_pattern_add_color_stop_rgba (pattern, 0.00f, r, g, b, a); getColorRGBA (BackgroundGradientHighlightColor); cairo_pattern_add_color_stop_rgba (pattern, 0.65f, r, g, b, a); getColorRGBA (BackgroundGradientShadowColor); cairo_pattern_add_color_stop_rgba (pattern, 0.85f, r, g, b, a); cairo_set_source (cr, pattern); /* draw the border's shape */ radius = optionGetEdgeRadius (); if (radius) { cairo_arc (cr, radius, radius, radius, PI, 1.5f * PI); cairo_arc (cr, radius + width - 2 * radius, radius, radius, 1.5f * PI, 2.0 * PI); cairo_arc (cr, width - radius, height - radius, radius, 0, PI / 2.0f); cairo_arc (cr, radius, height - radius, radius, PI / 2.0f, PI); } else { cairo_rectangle (cr, 0, 0, width, height); } cairo_close_path (cr); /* apply pattern to background... */ cairo_fill_preserve (cr); /* ... and draw an outline */ cairo_set_line_width (cr, outline); getColorRGBA (OutlineColor); cairo_set_source_rgba (cr, r, g, b, a); cairo_stroke (cr); cairo_pattern_destroy (pattern); cairo_restore (cr); cairo_save (cr); for (unsigned int i = 0; i < (unsigned int) screen->vpSize ().height (); i++) { cairo_translate (cr, 0.0, viewportBorder); cairo_save (cr); for (unsigned int j = 0; j < (unsigned int) screen->vpSize ().width (); j++) { cairo_translate (cr, viewportBorder, 0.0); /* this cuts a hole into our background */ cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0); cairo_rectangle (cr, 0, 0, viewportWidth, viewportHeight); cairo_fill_preserve (cr); cairo_set_operator (cr, CAIRO_OPERATOR_XOR); cairo_fill (cr); cairo_translate (cr, viewportWidth, 0.0); } cairo_restore(cr); cairo_translate (cr, 0.0, viewportHeight); } cairo_restore (cr); }
void cairo_context::set_pattern(cairo_pattern const& pattern) { cairo_set_source(cairo_.get(), pattern.pattern()); check_object_status_and_throw_exception(*this); }
void Font::drawGlyphs(GraphicsContext* context, const SimpleFontData* font, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const { cairo_t* cr = context->platformContext(); cairo_save(cr); cairo_set_scaled_font(cr, font->platformData().scaledFont()); GlyphBufferGlyph* glyphs = (GlyphBufferGlyph*)glyphBuffer.glyphs(from); float offset = 0.0f; for (int i = 0; i < numGlyphs; i++) { glyphs[i].x = offset; glyphs[i].y = 0.0f; offset += glyphBuffer.advanceAt(from + i); } Color fillColor = context->fillColor(); // Synthetic Oblique if(font->platformData().syntheticOblique()) { cairo_matrix_t mat = {1, 0, -tanf(SYNTHETIC_OBLIQUE_ANGLE * acosf(0) / 90), 1, point.x(), point.y()}; cairo_transform(cr, &mat); } else { cairo_translate(cr, point.x(), point.y()); } // Text shadow, inspired by FontMac FloatSize shadowOffset; float shadowBlur = 0; Color shadowColor; bool hasShadow = context->textDrawingMode() & cTextFill && context->getShadow(shadowOffset, shadowBlur, shadowColor); // TODO: Blur support if (hasShadow) { // Disable graphics context shadows (not yet implemented) and paint them manually context->clearShadow(); Color shadowFillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(), shadowColor.alpha() * fillColor.alpha() / 255); cairo_save(cr); float red, green, blue, alpha; shadowFillColor.getRGBA(red, green, blue, alpha); cairo_set_source_rgba(cr, red, green, blue, alpha); #if ENABLE(FILTERS) cairo_text_extents_t extents; cairo_scaled_font_glyph_extents(font->platformData().scaledFont(), glyphs, numGlyphs, &extents); FloatRect rect(FloatPoint(), FloatSize(extents.width, extents.height)); IntSize shadowBufferSize; FloatRect shadowRect; float radius = 0; context->calculateShadowBufferDimensions(shadowBufferSize, shadowRect, radius, rect, shadowOffset, shadowBlur); // Draw shadow into a new ImageBuffer OwnPtr<ImageBuffer> shadowBuffer = ImageBuffer::create(shadowBufferSize); GraphicsContext* shadowContext = shadowBuffer->context(); cairo_t* shadowCr = shadowContext->platformContext(); cairo_translate(shadowCr, radius, extents.height + radius); cairo_set_scaled_font(shadowCr, font->platformData().scaledFont()); cairo_show_glyphs(shadowCr, glyphs, numGlyphs); if (font->syntheticBoldOffset()) { cairo_save(shadowCr); cairo_translate(shadowCr, font->syntheticBoldOffset(), 0); cairo_show_glyphs(shadowCr, glyphs, numGlyphs); cairo_restore(shadowCr); } cairo_translate(cr, 0.0, -extents.height); context->applyPlatformShadow(shadowBuffer.release(), shadowColor, shadowRect, radius); #else cairo_translate(cr, shadowOffset.width(), shadowOffset.height()); cairo_show_glyphs(cr, glyphs, numGlyphs); if (font->syntheticBoldOffset()) { cairo_save(cr); cairo_translate(cr, font->syntheticBoldOffset(), 0); cairo_show_glyphs(cr, glyphs, numGlyphs); cairo_restore(cr); } #endif cairo_restore(cr); } if (context->textDrawingMode() & cTextFill) { if (context->fillGradient()) { cairo_set_source(cr, context->fillGradient()->platformGradient()); if (context->getAlpha() < 1.0f) { cairo_push_group(cr); cairo_paint_with_alpha(cr, context->getAlpha()); cairo_pop_group_to_source(cr); } } else if (context->fillPattern()) { AffineTransform affine; cairo_pattern_t* pattern = context->fillPattern()->createPlatformPattern(affine); cairo_set_source(cr, pattern); if (context->getAlpha() < 1.0f) { cairo_push_group(cr); cairo_paint_with_alpha(cr, context->getAlpha()); cairo_pop_group_to_source(cr); } cairo_pattern_destroy(pattern); } else { float red, green, blue, alpha; fillColor.getRGBA(red, green, blue, alpha); cairo_set_source_rgba(cr, red, green, blue, alpha * context->getAlpha()); } cairo_show_glyphs(cr, glyphs, numGlyphs); if (font->syntheticBoldOffset()) { cairo_save(cr); cairo_translate(cr, font->syntheticBoldOffset(), 0); cairo_show_glyphs(cr, glyphs, numGlyphs); cairo_restore(cr); } } // Prevent running into a long computation within cairo. If the stroke width is // twice the size of the width of the text we will not ask cairo to stroke // the text as even one single stroke would cover the full wdth of the text. // See https://bugs.webkit.org/show_bug.cgi?id=33759. if (context->textDrawingMode() & cTextStroke && context->strokeThickness() < 2 * offset) { if (context->strokeGradient()) { cairo_set_source(cr, context->strokeGradient()->platformGradient()); if (context->getAlpha() < 1.0f) { cairo_push_group(cr); cairo_paint_with_alpha(cr, context->getAlpha()); cairo_pop_group_to_source(cr); } } else if (context->strokePattern()) { AffineTransform affine; cairo_pattern_t* pattern = context->strokePattern()->createPlatformPattern(affine); cairo_set_source(cr, pattern); if (context->getAlpha() < 1.0f) { cairo_push_group(cr); cairo_paint_with_alpha(cr, context->getAlpha()); cairo_pop_group_to_source(cr); } cairo_pattern_destroy(pattern); } else { Color strokeColor = context->strokeColor(); float red, green, blue, alpha; strokeColor.getRGBA(red, green, blue, alpha); cairo_set_source_rgba(cr, red, green, blue, alpha * context->getAlpha()); } cairo_glyph_path(cr, glyphs, numGlyphs); cairo_set_line_width(cr, context->strokeThickness()); cairo_stroke(cr); } // Re-enable the platform shadow we disabled earlier if (hasShadow) context->setShadow(shadowOffset, shadowBlur, shadowColor, DeviceColorSpace); cairo_restore(cr); }
/*********************************************** * ge_cairo_pattern_fill - * * Fill an area with some pattern * Scaling or tiling if needed ***********************************************/ void ge_cairo_pattern_fill(cairo_t *canvas, CairoPattern *pattern, gint x, gint y, gint width, gint height) { cairo_matrix_t original_matrix, current_matrix; if (pattern->operator == CAIRO_OPERATOR_DEST) { return; } cairo_pattern_get_matrix(pattern->handle, &original_matrix); current_matrix = original_matrix; if (pattern->scale != GE_DIRECTION_NONE) { gdouble scale_x = 1.0; gdouble scale_y = 1.0; if ((pattern->scale == GE_DIRECTION_VERTICAL) || (pattern->scale == GE_DIRECTION_BOTH)) { scale_x = 1.0/width; } if ((pattern->scale == GE_DIRECTION_HORIZONTAL) || (pattern->scale == GE_DIRECTION_BOTH)) { scale_y = 1.0/height; } cairo_matrix_scale(¤t_matrix, scale_x, scale_y); } if (pattern->translate != GE_DIRECTION_NONE) { gdouble translate_x = 0; gdouble translate_y = 0; if ((pattern->translate == GE_DIRECTION_VERTICAL) || (pattern->translate == GE_DIRECTION_BOTH)) { translate_x = 0.0-x; } if ((pattern->translate == GE_DIRECTION_HORIZONTAL) || (pattern->translate == GE_DIRECTION_BOTH)) { translate_y = 0.0-y; } cairo_matrix_translate(¤t_matrix, translate_x, translate_y); } cairo_pattern_set_matrix(pattern->handle, ¤t_matrix); cairo_save(canvas); cairo_set_source(canvas, pattern->handle); cairo_set_operator(canvas, pattern->operator); cairo_rectangle(canvas, x, y, width, height); cairo_fill (canvas); cairo_restore(canvas); cairo_pattern_set_matrix(pattern->handle, &original_matrix); }
gboolean ly_3lrc_widget_on_expose_cb(GtkWidget * widget, cairo_t *cr, gpointer data) { gint width; gint height; width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); gchar title_font[1024]="Sans Regular 18"; ly_reg_get("3lrc_title_font", "%1024[^\n]", title_font); gchar normal_font[1024]="Sans Regular 10"; ly_reg_get("3lrc_normal_font", "%1024[^\n]", normal_font); /* * draw bg */ if(ly_3lrc_pixbuf_bg) { if(ly_3lrc_pixbuf_bg_copy) { int h=gdk_pixbuf_get_height(ly_3lrc_pixbuf_bg_copy); int w=gdk_pixbuf_get_width(ly_3lrc_pixbuf_bg_copy); if(h<height||h-height>2||w<width||w-width>2) { g_object_unref(ly_3lrc_pixbuf_bg_copy); ly_3lrc_pixbuf_bg_copy=gdk_pixbuf_scale_simple(ly_3lrc_pixbuf_bg, width, height, GDK_INTERP_BILINEAR); } } else { ly_3lrc_pixbuf_bg_copy=gdk_pixbuf_scale_simple(ly_3lrc_pixbuf_bg, width, height, GDK_INTERP_BILINEAR); } gdk_cairo_set_source_pixbuf(cr, ly_3lrc_pixbuf_bg_copy, 0, 0); cairo_paint(cr); } cairo_rectangle (cr, 0, 0, width, height); cairo_set_source_rgba (cr, 0, 0, 0, 0.5); cairo_fill(cr); //画标题 cairo_pattern_t *pat; pat = cairo_pattern_create_linear (0, 0, 0, 45); cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 0.5); cairo_pattern_add_color_stop_rgba (pat, 0.18, 1, 1, 1, 0.3); cairo_pattern_add_color_stop_rgba (pat, 0.25, 1, 1, 1, 0.1); cairo_pattern_add_color_stop_rgba (pat, 1, 1, 1, 1, 0.1); cairo_rectangle (cr, 0, 0, width, 45); cairo_set_source (cr, pat); cairo_fill(cr); cairo_pattern_destroy (pat); cairo_set_line_width(cr, 0.5); cairo_set_source_rgba (cr, 0.9, 0.9, 0.9, 0.6); cairo_move_to(cr, 0, 44); cairo_line_to(cr, width, 44); cairo_stroke(cr); cairo_set_source_rgba (cr, 0, 0, 0, 0.9); cairo_move_to(cr, 0, 44.5); cairo_line_to(cr, width, 44.5); cairo_stroke(cr); LyMdhMetadata *md=ly_pqm_get_current_md(); int length=ly_lrc_get_length(); if(md) { gchar title[1024]=""; g_snprintf(title, sizeof(title), "%s - %s", md->title,md->artist); cairo_set_source_rgb ( cr, 0.1, 0.1, 0.1); ly_3lrc_widget_draw_text_midx(cr, title, title_font, width ,6); cairo_set_source_rgb ( cr, 0.9, 0.9, 0.9); ly_3lrc_widget_draw_text_midx(cr, title, title_font, width ,7); } //没有找到歌词 if(length<=0||!md) { //画边框 cairo_set_source_rgba ( cr, 0.3 , 0.3 , 0.3 ,0.8) ; cairo_set_line_width ( cr,1); cairo_translate ( cr, width/2 , height/2); cairo_move_to(cr, -70, -30); cairo_line_to(cr, 70, -30); cairo_arc(cr, 70, 0.0, 30.0 ,-M_PI/2 ,-M_PI*3/2); cairo_line_to(cr, 70, 30); cairo_arc(cr, -70, 0.0, 30.0 ,M_PI/2 ,M_PI*3/2); cairo_fill (cr); //画闪烁的原点 cairo_translate ( cr, -60 , 0 ); static gdouble const trs[ 8 ] [ 8 ] = { { 0.0 , 0.15 , 0.30 , 0.5 , 0.65 , 0.80 , 0.9 , 1.0 } , { 1.0 , 0.0 , 0.15 , 0.30 , 0.5 , 0.65 , 0.8 , 0.9 } , { 0.9 , 1.0 , 0.0 , 0.15 , 0.3 , 0.5 , 0.65 , 0.8 } , { 0.8 , 0.9 , 1.0 , 0.0 , 0.15 , 0.3 , 0.5 , 0.65 } , { 0.65 , 0.8 , 0.9 , 1.0 , 0.0 , 0.15 , 0.3 , 0.5 } , { 0.5 , 0.65 , 0.8 , 0.9 , 1.0 , 0.0 , 0.15 , 0.3 } , { 0.3 , 0.5 , 0.65 , 0.8 , 0.9 , 1.0 , 0.0 , 0.15 } , { 0.15 , 0.3 , 0.5 , 0.65 , 0.8 , 0.9 , 1.0 , 0.0 ,} }; gint i = 0 ; for ( i = 0 ; i < 8 ; i++) { cairo_set_line_width ( cr, 8 ) ; cairo_set_line_cap ( cr, CAIRO_LINE_CAP_ROUND) ; cairo_set_source_rgba ( cr, 1.0 , 1.0 , 1.0 , trs[count%8][i]) ; cairo_move_to ( cr, 0.0 , -15.0 ); cairo_line_to (cr, 0.0, -15.0); cairo_rotate ( cr, M_PI / 4 ) ; cairo_stroke ( cr) ; } //写字“Serching Lyrics...” cairo_set_source_rgba ( cr, 1.0 , 1.0 , 1.0 , 1.0) ; cairo_move_to (cr, 30.0 , -6.0); ly_3lrc_widget_draw_text(cr,"Missing Lyrics...", "Sans Regular 10"); count=(count+1)%8; } //有歌词 else { gint lrc_gap=20; if(!ly_reg_get("lrc_gap","%d",&lrc_gap)) { ly_reg_set("lrc_gap","%d",lrc_gap); } int y=height/2; LyLrcLyric **array=ly_lrc_get_array(); int index=ly_lrc_get_index(); if(flag_seek&&flag_seeked) { cairo_set_source_rgba ( cr, 0.8, 0.8, 0.8, 0.8); cairo_set_line_width ( cr,20); cairo_set_line_cap ( cr, CAIRO_LINE_CAP_ROUND) ; cairo_move_to(cr, 10.0, height/2.0+8); cairo_line_to(cr, width-10.0, height/2.0+8); cairo_stroke (cr); y=height/2.0; } else { gint64 t1=0; gint64 t2=0; if(index+1<length) { t1=array[index+1]->time-array[index]->time; } else t1=ly_mdh_time_str2int(md->duration)-array[index]->time; t2=ly_aud_get_position_abs()-array[index]->time; if(t1!=0) { y=y-(int)((t2/(gdouble)t1)*lrc_gap); } } //正式画歌词区域 //画当前歌词 cairo_set_source_rgb(cr,1, 1, 1); if(y>height/5.0&&y<height*4/5.0) ly_3lrc_widget_draw_text_midx(cr,array[index]->text, normal_font,width,y); //画普通歌词 cairo_set_source_rgb(cr,0.5,0.5,0.5); int i=1; for(i=1;i<=10;i++) { if(index-i>=0 &&(y-i*(lrc_gap)>height/5.0)) { ly_3lrc_widget_draw_text_midx(cr,array[index-i]->text, normal_font,width,y-i*(lrc_gap)); } else break; } for(i=1;i<=10;i++) { if(index+i<length &&(y+i*(lrc_gap)<(height/5.0*4))) { ly_3lrc_widget_draw_text_midx(cr,array[index+i]->text,normal_font,width,y+i*(lrc_gap)); } else break; } } return FALSE; }
gboolean cd_drop_indicator_render (gpointer pUserData, CairoDock *pDock, cairo_t *pCairoContext) { CDDropIndicatorData *pData = CD_APPLET_GET_MY_DOCK_DATA (pDock); if (pData == NULL) return GLDI_NOTIFICATION_LET_PASS; if (pCairoContext != NULL) { if (pData->fAlpha > 0) { cairo_save (pCairoContext); double fX = pDock->container.iMouseX - myData.dropIndicator.iWidth / 2; if (pDock->container.bIsHorizontal) cairo_rectangle (pCairoContext, (int) pDock->container.iMouseX - myData.dropIndicator.iWidth/2, (int) (pDock->container.bDirectionUp ? 0 : pDock->iActiveHeight - 2*myData.dropIndicator.iHeight), (int) myData.dropIndicator.iWidth, (int) (pDock->container.bDirectionUp ? 2*myData.dropIndicator.iHeight : pDock->iActiveHeight)); else cairo_rectangle (pCairoContext, (int) (pDock->container.bDirectionUp ? pDock->container.iHeight - pDock->iActiveHeight : pDock->iActiveHeight - 2*myData.dropIndicator.iHeight), (int) pDock->container.iMouseX - myData.dropIndicator.iWidth/2, (int) (pDock->container.bDirectionUp ? 2*myData.dropIndicator.iHeight : pDock->iActiveHeight), (int) myData.dropIndicator.iWidth); cairo_clip (pCairoContext); if (pDock->container.bIsHorizontal) cairo_translate (pCairoContext, fX, (pDock->container.bDirectionUp ? 0 : pDock->iActiveHeight)); else cairo_translate (pCairoContext, (pDock->container.bDirectionUp ? 0 : pDock->iActiveHeight), fX); double fRotationAngle = (pDock->container.bIsHorizontal ? (pDock->container.bDirectionUp ? 0 : G_PI) : (pDock->container.bDirectionUp ? -G_PI/2 : G_PI/2)); cairo_rotate (pCairoContext, fRotationAngle); cairo_translate (pCairoContext, 0, pData->iDropIndicatorOffset); cairo_pattern_t* pPattern = cairo_pattern_create_for_surface (myData.dropIndicator.pSurface); g_return_val_if_fail (cairo_pattern_status (pPattern) == CAIRO_STATUS_SUCCESS, GLDI_NOTIFICATION_LET_PASS); cairo_pattern_set_extend (pPattern, CAIRO_EXTEND_REPEAT); cairo_set_source (pCairoContext, pPattern); cairo_translate (pCairoContext, 0, - pData->iDropIndicatorOffset); cairo_pattern_t *pGradationPattern = cairo_pattern_create_linear (0., 0., 0., 2*myData.dropIndicator.iHeight); // de haut en bas. g_return_val_if_fail (cairo_pattern_status (pGradationPattern) == CAIRO_STATUS_SUCCESS, GLDI_NOTIFICATION_LET_PASS); cairo_pattern_set_extend (pGradationPattern, CAIRO_EXTEND_NONE); cairo_pattern_add_color_stop_rgba (pGradationPattern, 0., 0., 0., 0., 0.); cairo_pattern_add_color_stop_rgba (pGradationPattern, 0.4, 0., 0., 0., pData->fAlpha); cairo_pattern_add_color_stop_rgba (pGradationPattern, 0.5, 0., 0., 0., pData->fAlpha); cairo_pattern_add_color_stop_rgba (pGradationPattern, 1., 0., 0., 0., 0.); cairo_mask (pCairoContext, pGradationPattern); cairo_pattern_destroy (pPattern); cairo_pattern_destroy (pGradationPattern); cairo_restore (pCairoContext); } if (pData->fAlphaHover > 0 && myData.hoverIndicator.pSurface != NULL) { Icon *pIcon = cairo_dock_get_pointed_icon (pDock->icons); if (pIcon != NULL && ! CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon)) { cairo_save (pCairoContext); if (pDock->container.bIsHorizontal) { cairo_translate (pCairoContext, pIcon->fDrawX + 2./3*pIcon->fWidth*pIcon->fScale, pIcon->fDrawY); // top right corner cairo_scale (pCairoContext, pIcon->fWidth*pIcon->fScale/3 / myData.hoverIndicator.iWidth, pIcon->fHeight*pIcon->fScale/3 / myData.hoverIndicator.iHeight); } else { cairo_translate (pCairoContext, pIcon->fDrawY + 2./3*pIcon->fWidth*pIcon->fScale, pIcon->fDrawX); cairo_scale (pCairoContext, pIcon->fHeight*pIcon->fScale/3 / myData.hoverIndicator.iWidth, pIcon->fWidth*pIcon->fScale/3 / myData.hoverIndicator.iHeight); } cairo_set_source_surface (pCairoContext, myData.hoverIndicator.pSurface, 0., 0.); cairo_paint_with_alpha (pCairoContext, pData->fAlphaHover); cairo_restore (pCairoContext); } } } else { if (pData->fAlpha > 0) { double fX = pDock->container.iMouseX; double fY = (pDock->container.bDirectionUp ? pDock->iActiveHeight - myData.dropIndicator.iHeight : myData.dropIndicator.iHeight); glPushMatrix(); glLoadIdentity(); if (pDock->container.bIsHorizontal) { fX = pDock->container.iMouseX; fY = (pDock->container.bDirectionUp ? pDock->iActiveHeight - myData.dropIndicator.iHeight : myData.dropIndicator.iHeight); glTranslatef (fX, fY, - myData.dropIndicator.iWidth-1.); if (! pDock->container.bDirectionUp) glScalef (1., -1., 1.); } else { fX = pDock->container.iWidth - pDock->container.iMouseX; fY = (! pDock->container.bDirectionUp ? pDock->iActiveHeight - myData.dropIndicator.iHeight : pDock->container.iHeight - pDock->iActiveHeight + myData.dropIndicator.iHeight); glTranslatef (fY, fX, - myData.dropIndicator.iWidth-1.); glRotatef ((pDock->container.bDirectionUp ? 90. : -90.), 0., 0., 1.); } glRotatef (pData->iDropIndicatorRotation, 0., 1., 0.); //\_________________ On decale la texture vers le bas. glMatrixMode(GL_TEXTURE); // On selectionne la matrice des textures glPushMatrix(); glLoadIdentity(); // On la reset glTranslatef(.0, - (double)pData->iDropIndicatorOffset / myData.dropIndicator.iHeight, 0.); glScalef (1., -2., 1.); glMatrixMode(GL_MODELVIEW); // On revient sur la matrice d'affichage //\_________________ On dessine l'indicateur. glEnable (GL_BLEND); if (pData->fAlpha != 1) _cairo_dock_set_blend_alpha (); else _cairo_dock_set_blend_over(); //glEnable(GL_DEPTH_TEST); glScalef (myData.dropIndicator.iWidth, myData.dropIndicator.iHeight, myData.dropIndicator.iWidth); glColor4f(1.0f, 1.0f, 1.0f, pData->fAlpha); glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); glEnable(GL_TEXTURE); glActiveTextureARB(GL_TEXTURE0_ARB); // Go pour le multitexturing 1ere passe glEnable(GL_TEXTURE_2D); // On active le texturing sur cette passe glBindTexture(GL_TEXTURE_2D, myData.dropIndicator.iTexture); glActiveTextureARB(GL_TEXTURE1_ARB); // Go pour le texturing 2eme passe glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, myData.iBilinearGradationTexture); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // Le mode de combinaison des textures ///glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE); // multiplier les alpha. //glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); glNormal3f(0,0,1); glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0., 0.); glMultiTexCoord2fARB( GL_TEXTURE1_ARB,0., 0.); glVertex3f(-0.5, -1., 0.); // Bottom Left Of The Texture and Quad glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1., 0.); glMultiTexCoord2fARB( GL_TEXTURE1_ARB,1., 0.); glVertex3f( 0.5, -1., 0.); // Bottom Right Of The Texture and Quad glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1., 1.); glMultiTexCoord2fARB( GL_TEXTURE1_ARB,1., 1.); glVertex3f( 0.5, 1., 0.); // Top Right Of The Texture and Quad glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0., 1.); glMultiTexCoord2fARB( GL_TEXTURE1_ARB,0., 1.); glVertex3f(-0.5, 1., 0.); // Top Left Of The Texture and Quad glNormal3f(1,0,0); glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0., 0.); glMultiTexCoord2fARB( GL_TEXTURE1_ARB,0., 0.); glVertex3f(0., -1., -0.5); // Bottom Left Of The Texture and Quad glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1., 0.); glMultiTexCoord2fARB( GL_TEXTURE1_ARB,1., 0.); glVertex3f(0., -1., 0.5); // Bottom Right Of The Texture and Quad glMultiTexCoord2fARB( GL_TEXTURE0_ARB,1., 1.); glMultiTexCoord2fARB( GL_TEXTURE1_ARB,1., 1.); glVertex3f(0., 1., 0.5); // Top Right Of The Texture and Quad glMultiTexCoord2fARB( GL_TEXTURE0_ARB,0., 1.); glMultiTexCoord2fARB( GL_TEXTURE1_ARB,0., 1.); glVertex3f(0., 1., -0.5); // Top Left Of The Texture and Quad glEnd(); glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable (GL_BLEND); _cairo_dock_set_blend_alpha (); glPopMatrix(); //\_________________ On remet la matrice des textures. glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_MODELVIEW); } if (pData->fAlphaHover > 0 && myData.hoverIndicator.iTexture != 0) { Icon *pIcon = cairo_dock_get_pointed_icon (pDock->icons); if (pIcon != NULL && ! CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon)) { _cairo_dock_enable_texture (); _cairo_dock_set_blend_alpha (); glPushMatrix (); if (pDock->container.bIsHorizontal) glTranslatef (pIcon->fDrawX + 5./6*pIcon->fWidth*pIcon->fScale, pDock->iActiveHeight - pIcon->fDrawY - 1./6*pIcon->fHeight*pIcon->fScale, 0.); else glTranslatef (pIcon->fDrawY + 5./6*pIcon->fHeight*pIcon->fScale, pDock->container.iWidth - (pIcon->fDrawX + 1./6*pIcon->fWidth*pIcon->fScale), 0.); _cairo_dock_apply_texture_at_size_with_alpha (myData.hoverIndicator.iTexture, myData.hoverIndicator.iWidth, myData.hoverIndicator.iHeight, pData->fAlphaHover); glPopMatrix (); _cairo_dock_disable_texture (); } } } return GLDI_NOTIFICATION_LET_PASS; }
static gboolean egg_panel_ebox_expose (GtkWidget *ebox, GdkEventExpose *event, EggPanel *panel) { EggPanelPrivate *priv = panel->priv; GdkRectangle alloc; cairo_pattern_t *pt; cairo_t *cr; double r1, r2, g1, g2, b1, b2; GtkStyle *style; GtkStateType state; /* * Determine state from button press. */ state = (priv->state == STATE_DRAGGING) ? GTK_STATE_SELECTED : GTK_STATE_NORMAL; /* * Create cairo context and clip drawing area to event region. */ cr = gdk_cairo_create(event->window); gdk_cairo_rectangle(cr, &event->area); cairo_clip(cr); /* * Get gradient colors. */ style = gtk_widget_get_style(ebox); r1 = style->bg[state].red / 65535.; g1 = style->bg[state].green / 65535.; b1 = style->bg[state].blue / 65535.; r2 = style->dark[state].red / 65535.; g2 = style->dark[state].green / 65535.; b2 = style->dark[state].blue / 65535.; /* * Draw the background gradient. */ gtk_widget_get_allocation(ebox, &alloc); pt = cairo_pattern_create_linear(0., 0., 0., alloc.height); cairo_pattern_add_color_stop_rgb(pt, 0., r1, g1, b1); cairo_pattern_add_color_stop_rgb(pt, 1., r2, g2, b2); cairo_rectangle(cr, 0., 0., alloc.width, alloc.height); cairo_set_source(cr, pt); cairo_fill(cr); /* * Cleanup resources. */ cairo_pattern_destroy(pt); cairo_destroy(cr); /* * Expose the child. */ gtk_container_propagate_expose(GTK_CONTAINER(ebox), panel->priv->header, event); return FALSE; }
static void gtk_border_image_render_slice (cairo_t *cr, cairo_surface_t *slice, double slice_width, double slice_height, double x, double y, double width, double height, GtkCssRepeatStyle hrepeat, GtkCssRepeatStyle vrepeat) { double hscale, vscale; double xstep, ystep; cairo_extend_t extend = CAIRO_EXTEND_PAD; cairo_matrix_t matrix; cairo_pattern_t *pattern; /* We can't draw center tiles yet */ g_assert (hrepeat == GTK_CSS_REPEAT_STYLE_STRETCH || vrepeat == GTK_CSS_REPEAT_STYLE_STRETCH); hscale = width / slice_width; vscale = height / slice_height; xstep = width; ystep = height; switch (hrepeat) { case GTK_CSS_REPEAT_STYLE_REPEAT: extend = CAIRO_EXTEND_REPEAT; hscale = vscale; break; case GTK_CSS_REPEAT_STYLE_SPACE: { double space, n; extend = CAIRO_EXTEND_NONE; hscale = vscale; xstep = hscale * slice_width; n = floor (width / xstep); space = (width - n * xstep) / (n + 1); xstep += space; x += space; width -= 2 * space; } break; case GTK_CSS_REPEAT_STYLE_STRETCH: break; case GTK_CSS_REPEAT_STYLE_ROUND: extend = CAIRO_EXTEND_REPEAT; hscale = width / (slice_width * MAX (round (width / (slice_width * vscale)), 1)); break; default: g_assert_not_reached (); break; } switch (vrepeat) { case GTK_CSS_REPEAT_STYLE_REPEAT: extend = CAIRO_EXTEND_REPEAT; vscale = hscale; break; case GTK_CSS_REPEAT_STYLE_SPACE: { double space, n; extend = CAIRO_EXTEND_NONE; vscale = hscale; ystep = vscale * slice_height; n = floor (height / ystep); space = (height - n * ystep) / (n + 1); ystep += space; y += space; height -= 2 * space; } break; case GTK_CSS_REPEAT_STYLE_STRETCH: break; case GTK_CSS_REPEAT_STYLE_ROUND: extend = CAIRO_EXTEND_REPEAT; vscale = height / (slice_height * MAX (round (height / (slice_height * hscale)), 1)); break; default: g_assert_not_reached (); break; } pattern = cairo_pattern_create_for_surface (slice); cairo_matrix_init_translate (&matrix, hrepeat == GTK_CSS_REPEAT_STYLE_REPEAT ? slice_width / 2 : 0, vrepeat == GTK_CSS_REPEAT_STYLE_REPEAT ? slice_height / 2 : 0); cairo_matrix_scale (&matrix, 1 / hscale, 1 / vscale); cairo_matrix_translate (&matrix, hrepeat == GTK_CSS_REPEAT_STYLE_REPEAT ? - width / 2 : 0, vrepeat == GTK_CSS_REPEAT_STYLE_REPEAT ? - height / 2 : 0); cairo_pattern_set_matrix (pattern, &matrix); cairo_pattern_set_extend (pattern, extend); cairo_save (cr); cairo_translate (cr, x, y); for (y = 0; y < height; y += ystep) { for (x = 0; x < width; x += xstep) { cairo_save (cr); cairo_translate (cr, x, y); cairo_set_source (cr, pattern); cairo_rectangle (cr, 0, 0, xstep, ystep); cairo_fill (cr); cairo_restore (cr); } } cairo_restore (cr); cairo_pattern_destroy (pattern); }
static gboolean gimp_color_bar_expose (GtkWidget *widget, GdkEventExpose *event) { GimpColorBar *bar = GIMP_COLOR_BAR (widget); cairo_t *cr; GtkAllocation allocation; cairo_surface_t *surface; cairo_pattern_t *pattern; guchar *src; guchar *dest; gint x, y; gint width, height; gint i; cr = gdk_cairo_create (event->window); gdk_cairo_region (cr, event->region); cairo_clip (cr); gtk_widget_get_allocation (widget, &allocation); x = y = gtk_container_get_border_width (GTK_CONTAINER (bar)); width = allocation.width - 2 * x; height = allocation.height - 2 * y; if (width < 1 || height < 1) return TRUE; cairo_translate (cr, allocation.x + x, allocation.y + y); cairo_rectangle (cr, 0, 0, width, height); cairo_clip (cr); surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 256, 1); for (i = 0, src = bar->buf, dest = cairo_image_surface_get_data (surface); i < 256; i++, src += 3, dest += 4) { GIMP_CAIRO_RGB24_SET_PIXEL(dest, src[0], src[1], src[2]); } cairo_surface_mark_dirty (surface); pattern = cairo_pattern_create_for_surface (surface); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REFLECT); cairo_surface_destroy (surface); if (bar->orientation == GTK_ORIENTATION_HORIZONTAL) { cairo_scale (cr, (gdouble) width / 256.0, 1.0); } else { cairo_translate (cr, 0, height); cairo_scale (cr, 1.0, (gdouble) height / 256.0); cairo_rotate (cr, - G_PI / 2); } cairo_set_source (cr, pattern); cairo_pattern_destroy (pattern); cairo_paint (cr); cairo_destroy (cr); return TRUE; }
static void week_view_event_item_draw (GnomeCanvasItem *canvas_item, cairo_t *cr, gint x, gint y, gint width, gint height) { EWeekViewEventItem *event_item; EWeekView *week_view; EWeekViewEvent *event; EWeekViewEventSpan *span; ECalModel *model; GtkWidget *parent; gint x1, y1, x2, y2, time_x, time_y; gint icon_x, icon_y, time_width, min_end_time_x, max_icon_x; gint rect_x, rect_w, rect_x2 = 0; gboolean one_day_event, editing_span = FALSE; gint start_hour, start_minute, end_hour, end_minute; gboolean draw_start, draw_end; gboolean draw_start_triangle = FALSE, draw_end_triangle = FALSE; GdkColor bg_color; cairo_pattern_t *pat; guint16 red, green, blue; gdouble radius, cx0, cy0, rect_height, rect_width; gdouble cc = 65535.0; cairo_region_t *draw_region; GdkRectangle rect; const gchar *color_spec; event_item = E_WEEK_VIEW_EVENT_ITEM (canvas_item); parent = gtk_widget_get_parent (GTK_WIDGET (canvas_item->canvas)); g_return_if_fail (E_IS_WEEK_VIEW (parent)); week_view = E_WEEK_VIEW (parent); if (event_item->priv->event_num == -1 || event_item->priv->span_num == -1) return; g_return_if_fail (event_item->priv->event_num < week_view->events->len); if (!is_array_index_in_bounds (week_view->events, event_item->priv->event_num)) return; event = &g_array_index (week_view->events, EWeekViewEvent, event_item->priv->event_num); if (!is_comp_data_valid (event)) return; g_return_if_fail ( event->spans_index + event_item->priv->span_num < week_view->spans->len); if (!is_array_index_in_bounds ( week_view->spans, event->spans_index + event_item->priv->span_num)) return; span = &g_array_index ( week_view->spans, EWeekViewEventSpan, event->spans_index + event_item->priv->span_num); x1 = canvas_item->x1 - x; y1 = canvas_item->y1 - y; x2 = canvas_item->x2 - x; y2 = canvas_item->y2 - y; if (x1 == x2 || y1 == y2) return; rect.x = 0; rect.y = 0; rect.width = width; rect.height = height; if (rect.width > 0 && rect.height > 0) draw_region = cairo_region_create_rectangle (&rect); else draw_region = cairo_region_create (); if (!can_draw_in_region (draw_region, x1, y1, x2 - x1, y2 - y1)) { cairo_region_destroy (draw_region); return; } icon_y = y1 + E_WEEK_VIEW_EVENT_BORDER_HEIGHT + E_WEEK_VIEW_ICON_Y_PAD; /* Get the start & end times in 24-hour format. */ start_hour = event->start_minute / 60; start_minute = event->start_minute % 60; /* Modulo 24 because a midnight end time will be '24' */ end_hour = (event->end_minute / 60) % 24; end_minute = event->end_minute % 60; time_y = y1 + E_WEEK_VIEW_EVENT_BORDER_HEIGHT + E_WEEK_VIEW_EVENT_TEXT_Y_PAD; time_width = e_week_view_get_time_string_width (week_view); one_day_event = e_week_view_is_one_day_event ( week_view, event_item->priv->event_num); model = e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)); color_spec = e_cal_model_get_color_for_component (model, event->comp_data); bg_color = week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND]; if (!gdk_color_parse (color_spec, &bg_color)) { bg_color = week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND]; } red = bg_color.red; green = bg_color.green; blue = bg_color.blue; if (one_day_event) { time_x = x1 + E_WEEK_VIEW_EVENT_L_PAD + 1; rect_x = x1 + E_WEEK_VIEW_EVENT_L_PAD; rect_w = x2 - x1 - E_WEEK_VIEW_EVENT_L_PAD - E_WEEK_VIEW_EVENT_R_PAD + 1; /* Here we draw the border around the event*/ cx0 = rect_x; cy0 = y1 + 1; rect_width = rect_w; rect_height = y2 - y1 - 1; radius = 12; if (can_draw_in_region (draw_region, cx0, cy0, rect_width, rect_height)) { cairo_save (cr); draw_curved_rectangle (cr, cx0, cy0, rect_width, rect_height, radius); cairo_set_line_width (cr, 2.0); cairo_set_source_rgb (cr, red / cc, green / cc, blue / cc); cairo_stroke (cr); cairo_restore (cr); } /* Fill it in the Event */ cx0 = rect_x + 1.5; cy0 = y1 + 2.75; rect_width = rect_w - 3.; rect_height = y2 - y1 - 4.5; radius = 8; if (can_draw_in_region (draw_region, cx0, cy0, rect_width, rect_height)) { cairo_save (cr); draw_curved_rectangle ( cr, cx0, cy0, rect_width, rect_height, radius); pat = cairo_pattern_create_linear ( rect_x + 2, y1 + 1, rect_x + 2, y2 - 7.25); cairo_pattern_add_color_stop_rgba ( pat, 1, red / cc, green / cc, blue / cc, 0.8); cairo_pattern_add_color_stop_rgba ( pat, 0, red / cc, green / cc, blue / cc, 0.4); cairo_set_source (cr, pat); cairo_fill_preserve (cr); cairo_pattern_destroy (pat); cairo_set_source_rgba (cr, red / cc, green / cc, blue / cc, 0.2); cairo_set_line_width (cr, 0.5); cairo_stroke (cr); cairo_restore (cr); } /* Draw the start and end times, as required. */ switch (week_view->time_format) { case E_WEEK_VIEW_TIME_BOTH_SMALL_MIN: case E_WEEK_VIEW_TIME_BOTH: draw_start = TRUE; draw_end = TRUE; break; case E_WEEK_VIEW_TIME_START_SMALL_MIN: case E_WEEK_VIEW_TIME_START: draw_start = TRUE; draw_end = FALSE; break; case E_WEEK_VIEW_TIME_NONE: draw_start = FALSE; draw_end = FALSE; break; default: g_return_if_reached (); draw_start = FALSE; draw_end = FALSE; break; } if (draw_start) { week_view_draw_time ( week_view, cr, time_x, time_y, start_hour, start_minute); time_x += time_width; } if (draw_end) { time_x += E_WEEK_VIEW_EVENT_TIME_SPACING; week_view_draw_time ( week_view, cr, time_x, time_y, end_hour, end_minute); time_x += time_width; } icon_x = time_x; if (draw_start) icon_x += E_WEEK_VIEW_EVENT_TIME_X_PAD; /* Draw the icons. */ week_view_event_item_draw_icons ( event_item, cr, icon_x, icon_y, x2, FALSE, draw_region); } else { rect_x = x1 + E_WEEK_VIEW_EVENT_L_PAD; rect_w = x2 - x1 - E_WEEK_VIEW_EVENT_L_PAD - E_WEEK_VIEW_EVENT_R_PAD + 1; /* Draw the triangles at the start & end, if needed. * They also use the first few pixels at the edge of the * event so we update rect_x & rect_w so we don't draw over * them. */ if (event->start < week_view->day_starts[span->start_day]) { draw_start_triangle = TRUE; rect_x += 2; rect_w -= 2; } if (event->end > week_view->day_starts[span->start_day + span->num_days]) { draw_end_triangle = TRUE; rect_w -= 2; } /* Here we draw the border around the event */ cx0 = rect_x; cy0 = y1 + 1; rect_width = rect_w; rect_height = y2 - y1 - 1; radius = 12; if (can_draw_in_region (draw_region, cx0, cy0, rect_width, rect_height)) { cairo_save (cr); draw_curved_rectangle (cr, cx0, cy0, rect_width, rect_height, radius); cairo_set_line_width (cr, 2.0); cairo_set_source_rgb (cr, red / cc, green / cc, blue / cc); cairo_stroke (cr); cairo_restore (cr); } /* Here we fill it in the event*/ cx0 = rect_x + 1.5; cy0 = y1 + 2.75; rect_width = rect_w - 3.; rect_height = y2 - y1 - 4.5; radius = 8; if (can_draw_in_region (draw_region, cx0, cy0, rect_width, rect_height)) { cairo_save (cr); draw_curved_rectangle ( cr, cx0, cy0, rect_width, rect_height, radius); pat = cairo_pattern_create_linear ( rect_x + 2, y1 + 1, rect_x + 2, y2 - 7.25); cairo_pattern_add_color_stop_rgba ( pat, 1, red / cc, green / cc, blue / cc, 0.8); cairo_pattern_add_color_stop_rgba ( pat, 0, red / cc, green / cc, blue / cc, 0.4); cairo_set_source (cr, pat); cairo_fill_preserve (cr); cairo_pattern_destroy (pat); cairo_set_source_rgba (cr, red / cc, green / cc, blue / cc, 0.2); cairo_set_line_width (cr, 0.5); cairo_stroke (cr); cairo_restore (cr); } if (draw_start_triangle) { week_view_event_item_draw_triangle ( event_item, cr, bg_color, x1 + E_WEEK_VIEW_EVENT_L_PAD + 2, y1, -3, y2 - y1 + 1, draw_region); } else if (can_draw_in_region (draw_region, rect_x, y1, 1, y2 - y1)) { EWeekViewColors wvc; GdkColor *color; wvc = E_WEEK_VIEW_COLOR_EVENT_BORDER; color = &week_view->colors[wvc]; cairo_save (cr); gdk_cairo_set_source_color (cr, color); cairo_set_line_width (cr, 0.7); cairo_move_to (cr, rect_x, y1); cairo_line_to (cr, rect_x, y2); cairo_stroke (cr); cairo_restore (cr); } if (draw_end_triangle) { week_view_event_item_draw_triangle ( event_item, cr, bg_color, x2 - E_WEEK_VIEW_EVENT_R_PAD - 2, y1, 3, y2 - y1 + 1, draw_region); } else if (can_draw_in_region (draw_region, rect_x2, y2, 1, 1)) { EWeekViewColors wvc; GdkColor *color; wvc = E_WEEK_VIEW_COLOR_EVENT_BORDER; color = &week_view->colors[wvc]; cairo_save (cr); gdk_cairo_set_source_color (cr, color); cairo_set_line_width (cr, 0.7); /* rect_x2 is used uninitialized here */ cairo_move_to (cr, rect_x2, y2); cairo_line_to (cr, rect_x2, y2); cairo_stroke (cr); cairo_restore (cr); } if (span->text_item && E_TEXT (span->text_item)->editing) editing_span = TRUE; /* Draw the start & end times, if they are not on day * boundaries. The start time would always be shown if it was * needed, though it may be clipped as the window shrinks. * The end time is only displayed if there is enough room. * We calculate the minimum position for the end time, which * depends on whether the start time is displayed. If the end * time doesn't fit, then we don't draw it. */ min_end_time_x = x1 + E_WEEK_VIEW_EVENT_L_PAD + E_WEEK_VIEW_EVENT_BORDER_WIDTH + E_WEEK_VIEW_EVENT_EDGE_X_PAD; if (!editing_span && event->start > week_view->day_starts[span->start_day]) { time_x = x1 + E_WEEK_VIEW_EVENT_L_PAD + E_WEEK_VIEW_EVENT_BORDER_WIDTH + E_WEEK_VIEW_EVENT_EDGE_X_PAD; cairo_save (cr); cairo_rectangle (cr, x1, y1, x2 - x1 - E_WEEK_VIEW_EVENT_R_PAD - E_WEEK_VIEW_EVENT_BORDER_WIDTH + 1, y2 - y1 + 1); cairo_clip (cr); week_view_draw_time ( week_view, cr, time_x, time_y, start_hour, start_minute); cairo_restore (cr); /* We don't want the end time to be drawn over the * start time, so we increase the minimum position. */ min_end_time_x += time_width + E_WEEK_VIEW_EVENT_TIME_X_PAD; } max_icon_x = x2 + 1 - E_WEEK_VIEW_EVENT_R_PAD - E_WEEK_VIEW_EVENT_BORDER_WIDTH - E_WEEK_VIEW_EVENT_EDGE_X_PAD; if (!editing_span && event->end < week_view->day_starts[span->start_day + span->num_days]) { /* Calculate where the end time should be displayed. */ time_x = x2 + 1 - E_WEEK_VIEW_EVENT_R_PAD - E_WEEK_VIEW_EVENT_BORDER_WIDTH - E_WEEK_VIEW_EVENT_EDGE_X_PAD - time_width; /* Draw the end time, if the position is greater than * the minimum calculated above. */ if (time_x >= min_end_time_x) { week_view_draw_time ( week_view, cr, time_x, time_y, end_hour, end_minute); max_icon_x -= time_width + E_WEEK_VIEW_EVENT_TIME_X_PAD; } } /* Draw the icons. */ if (span->text_item && (week_view->editing_event_num != event_item->priv->event_num || week_view->editing_span_num != event_item->priv->span_num)) { icon_x = span->text_item->x1 - E_WEEK_VIEW_ICON_R_PAD - x; week_view_event_item_draw_icons ( event_item, cr, icon_x, icon_y, max_icon_x, TRUE, draw_region); } } cairo_region_destroy (draw_region); }
static cairo_test_status_t draw (cairo_t *cr, int width, int height) { cairo_pattern_t *gradient, *image; cairo_set_source_rgb (cr, 1,1,1); cairo_paint (cr); cairo_translate (cr, PAD, PAD); /* clip to the unit size */ cairo_rectangle (cr, 0, 0, UNIT_SIZE, UNIT_SIZE); cairo_clip (cr); cairo_rectangle (cr, 0, 0, UNIT_SIZE, UNIT_SIZE); cairo_set_source_rgba (cr, 0, 0, 0, 1); cairo_set_line_width (cr, 2); cairo_stroke (cr); /* start a group */ cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR); /* draw a gradient background */ cairo_save (cr); cairo_translate (cr, INNER_PAD, INNER_PAD); cairo_new_path (cr); cairo_rectangle (cr, 0, 0, UNIT_SIZE - (INNER_PAD*2), UNIT_SIZE - (INNER_PAD*2)); gradient = cairo_pattern_create_linear (UNIT_SIZE - (INNER_PAD*2), 0, UNIT_SIZE - (INNER_PAD*2), UNIT_SIZE - (INNER_PAD*2)); cairo_pattern_add_color_stop_rgba (gradient, 0.0, 0.3, 0.3, 0.3, 1.0); cairo_pattern_add_color_stop_rgba (gradient, 1.0, 1.0, 1.0, 1.0, 1.0); cairo_set_source (cr, gradient); cairo_pattern_destroy (gradient); cairo_fill (cr); cairo_restore (cr); /* draw diamond */ cairo_move_to (cr, UNIT_SIZE / 2, 0); cairo_line_to (cr, UNIT_SIZE , UNIT_SIZE / 2); cairo_line_to (cr, UNIT_SIZE / 2, UNIT_SIZE); cairo_line_to (cr, 0 , UNIT_SIZE / 2); cairo_close_path (cr); cairo_set_source_rgba (cr, 0, 0, 1, 1); cairo_fill (cr); /* draw circle */ cairo_arc (cr, UNIT_SIZE / 2, UNIT_SIZE / 2, UNIT_SIZE / 3.5, 0, M_PI * 2); cairo_set_source_rgba (cr, 1, 0, 0, 1); cairo_fill (cr); /* and put the image on top */ cairo_translate (cr, UNIT_SIZE/2 - 8, UNIT_SIZE/2 - 8); image = argb32_source (); cairo_set_source (cr, image); cairo_pattern_destroy (image); cairo_paint (cr); cairo_pop_group_to_source (cr); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_paint (cr); return CAIRO_TEST_SUCCESS; }
static void draw (cairo_t *cr, double width, double height) { const char *text = "cairo"; cairo_text_extents_t extents; const double dash[2] = { 8, 16 }; cairo_pattern_t *pattern; cairo_save (cr); cairo_new_path (cr); cairo_set_line_width (cr, .05 * SIZE / 2.0); cairo_arc (cr, SIZE / 2.0, SIZE / 2.0, 0.875 * SIZE / 2.0, 0, 2.0 * M_PI); cairo_stroke (cr); /* use dashes to demonstrate bugs: * https://bugs.freedesktop.org/show_bug.cgi?id=9189 * https://bugs.freedesktop.org/show_bug.cgi?id=17223 */ cairo_save (cr); cairo_set_dash (cr, dash, 2, 0); cairo_arc (cr, SIZE / 2.0, SIZE / 2.0, 0.75 * SIZE / 2.0, 0, 2.0 * M_PI); cairo_stroke (cr); cairo_restore (cr); cairo_save (cr); cairo_rectangle (cr, 0, 0, SIZE/2, SIZE); cairo_clip (cr); cairo_arc (cr, SIZE / 2.0, SIZE / 2.0, 0.6 * SIZE / 2.0, 0, 2.0 * M_PI); cairo_fill (cr); cairo_restore (cr); /* use a pattern to exercise bug: * https://bugs.launchpad.net/inkscape/+bug/234546 */ cairo_save (cr); cairo_rectangle (cr, SIZE/2, 0, SIZE/2, SIZE); cairo_clip (cr); pattern = cairo_pattern_create_linear (SIZE/2, 0, SIZE, 0); cairo_pattern_add_color_stop_rgba (pattern, 0, 0, 0, 0, 1.); cairo_pattern_add_color_stop_rgba (pattern, 1, 0, 0, 0, 0.); cairo_set_source (cr, pattern); cairo_pattern_destroy (pattern); cairo_arc (cr, SIZE / 2.0, SIZE / 2.0, 0.6 * SIZE / 2.0, 0, 2.0 * M_PI); cairo_fill (cr); cairo_restore (cr); cairo_set_source_rgb (cr, 1, 1, 1); /* white */ cairo_set_font_size (cr, .25 * SIZE / 2.0); cairo_text_extents (cr, text, &extents); cairo_move_to (cr, (SIZE-extents.width)/2.0-extents.x_bearing, (SIZE-extents.height)/2.0-extents.y_bearing); cairo_show_text (cr, text); cairo_restore (cr); }
void terranova_draw_button_effect(cairo_t *cr, const WidgetParameters *params, const terranovaColors *colors, int width, int height) { const CairoColor *stripe_fill = &colors->bg[GTK_STATE_SELECTED]; CairoColor hilight, middle, shadow; cairo_pattern_t *pattern; if (params->button_effect == 1) { tn_shade_color (stripe_fill, 1.10, &middle); tn_shade_color (stripe_fill, 0.90, &shadow); tn_shade_color (stripe_fill, 1.35, &hilight); pattern = cairo_pattern_create_linear (0, 0, 0, height); cairo_pattern_add_color_stop_rgb (pattern, 0.25, hilight.r, hilight.g, hilight.b); cairo_pattern_add_color_stop_rgb (pattern, 0.05, middle.r, middle.g, middle.b); cairo_pattern_add_color_stop_rgb (pattern, 0.75, shadow.r, shadow.g, shadow.b); cairo_set_source (cr, pattern); cairo_pattern_destroy (pattern); cairo_move_to (cr, 1, 1); cairo_line_to (cr, width, 1); cairo_curve_to (cr, width, 1, 1, 1, 1, height); cairo_close_path(cr); cairo_fill(cr); } else if (params->button_effect == 2) { tn_shade_color (stripe_fill, 1.10, &middle); tn_shade_color (stripe_fill, 0.90, &shadow); tn_shade_color (stripe_fill, 1.35, &hilight); pattern = cairo_pattern_create_linear (0, 0, 0, height); cairo_pattern_add_color_stop_rgb (pattern, 0.25, hilight.r, hilight.g, hilight.b); cairo_pattern_add_color_stop_rgb (pattern, 0.05, middle.r, middle.g, middle.b); cairo_pattern_add_color_stop_rgb (pattern, 0.75, shadow.r, shadow.g, shadow.b); cairo_set_source (cr, pattern); cairo_pattern_destroy (pattern); cairo_move_to (cr, 3, height-20); cairo_line_to (cr, 3, height-3); cairo_line_to (cr, 20, height-3); cairo_line_to (cr, 8, height-9); cairo_line_to (cr, 3, height-20); cairo_close_path(cr); cairo_fill(cr); cairo_move_to (cr, width-20, 3); cairo_line_to (cr, width-3, 3); cairo_line_to (cr, width-3, 20); cairo_line_to (cr, width-8, 9); cairo_line_to (cr, width-20, 3); cairo_close_path(cr); cairo_fill(cr); } }
void Context::setSource( const Pattern &source ) { cairo_set_source( mCairo, const_cast<Pattern&>( source ).getCairoPattern() ); }
void lime_cairo_set_source (value handle, value pattern) { cairo_set_source ((cairo_t*)val_data (handle), (cairo_pattern_t*)val_data (pattern)); }
void ShowInfo(char *pchText, char *pchText2, HWND hwndClientWindow, cairo_surface_t *pCairoSurface, cairo_t *pCairoHandle) { cairo_text_extents_t CairoTextExtents; cairo_text_extents_t CairoTextExtents2; cairo_pattern_t *pattern1; cairo_set_operator(pCairoHandle, CAIRO_OPERATOR_OVER); // Set random line width cairo_set_line_width(pCairoHandle, 0.03); cairo_select_font_face(pCairoHandle, "Sans", 0, 0); cairo_set_font_size(pCairoHandle, 0.05); // Get how big the text will be! cairo_text_extents(pCairoHandle, pchText, &CairoTextExtents); cairo_text_extents(pCairoHandle, pchText2, &CairoTextExtents2); // Draw a frame pattern1 = cairo_pattern_create_linear(0.3,0,0.7,1); cairo_pattern_add_color_stop_rgba(pattern1, 0, 0, 0, 0, 1); cairo_pattern_add_color_stop_rgba(pattern1, 0.5, 0, 0.5, 0, 1); cairo_pattern_add_color_stop_rgba(pattern1, 1, 0.3, 1, 0.2, 1); //cairo_set_source_rgba(pCairoHandle, 0.2, 0.8 ,0, 0.9); cairo_set_source(pCairoHandle, pattern1); cairo_rectangle(pCairoHandle, 0.05 * dXAspect, 0.25*dYAspect, 0.90 * dXAspect, 0.5*dYAspect); cairo_fill_preserve(pCairoHandle); cairo_set_source_rgba(pCairoHandle, 0.9, 0.5, 0.2, 0.7); cairo_stroke(pCairoHandle); cairo_pattern_destroy(pattern1); pattern1 = cairo_pattern_create_linear(0,0,1,1); cairo_pattern_add_color_stop_rgba(pattern1, 0, 0.1, 0.7, 0.3, 0.4); cairo_pattern_add_color_stop_rgba(pattern1, 0.2, 0.3, 0.2, 0.4, 0.6); cairo_pattern_add_color_stop_rgba(pattern1, 0.4, 0.1, 0.1, 0.8, 0.3); cairo_pattern_add_color_stop_rgba(pattern1, 0.6, 0, 0.5, 0.7, 0.4); cairo_pattern_add_color_stop_rgba(pattern1, 0.8, 0.4, 0.5, 0.2, 0.6); cairo_pattern_add_color_stop_rgba(pattern1, 1, 0.1, 1, 0.2, 0.3); //cairo_set_source_rgba(pCairoHandle, 0.2, 0.8 ,0, 0.9); cairo_set_source(pCairoHandle, pattern1); cairo_rectangle(pCairoHandle, 0.05 * dXAspect, 0.25*dYAspect, 0.90 * dXAspect, 0.5*dYAspect); cairo_fill(pCairoHandle); cairo_pattern_destroy(pattern1); // Print the text, centered! cairo_set_source_rgba(pCairoHandle, 1, 1, 1, 0.8); cairo_move_to(pCairoHandle, (0.5*dXAspect - CairoTextExtents.width/2), (0.5*dYAspect - CairoTextExtents.height)); cairo_show_text(pCairoHandle, pchText); cairo_stroke (pCairoHandle); // Print the text, centered! cairo_move_to(pCairoHandle, 0.1 * dXAspect, (0.5*dYAspect + CairoTextExtents2.height)); cairo_scale(pCairoHandle, 0.8*dXAspect/CairoTextExtents2.width, 1); cairo_show_text(pCairoHandle, pchText2); cairo_stroke (pCairoHandle); }
/* * Draws global image with fill color onto a pixmap with the given * resolution and returns it. * */ xcb_pixmap_t draw_image(uint32_t *resolution) { xcb_pixmap_t bg_pixmap = XCB_NONE; int button_diameter_physical = ceil(scaling_factor() * BUTTON_DIAMETER); DEBUG("scaling_factor is %.f, physical diameter is %d px\n", scaling_factor(), button_diameter_physical); if (!vistype) vistype = get_root_visual_type(screen); bg_pixmap = create_bg_pixmap(conn, screen, resolution, color); /* Initialize cairo: Create one in-memory surface to render the unlock * indicator on, create one XCB surface to actually draw (one or more, * depending on the amount of screens) unlock indicators on. */ cairo_surface_t *output = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, button_diameter_physical, button_diameter_physical); cairo_t *ctx = cairo_create(output); cairo_surface_t *xcb_output = cairo_xcb_surface_create(conn, bg_pixmap, vistype, resolution[0], resolution[1]); cairo_t *xcb_ctx = cairo_create(xcb_output); if (img) { if (!tile) { cairo_set_source_surface(xcb_ctx, img, 0, 0); cairo_paint(xcb_ctx); } else { /* create a pattern and fill a rectangle as big as the screen */ cairo_pattern_t *pattern; pattern = cairo_pattern_create_for_surface(img); cairo_set_source(xcb_ctx, pattern); cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); cairo_rectangle(xcb_ctx, 0, 0, resolution[0], resolution[1]); cairo_fill(xcb_ctx); cairo_pattern_destroy(pattern); } } else { char strgroups[3][3] = {{color[0], color[1], '\0'}, {color[2], color[3], '\0'}, {color[4], color[5], '\0'}}; uint32_t rgb16[3] = {(strtol(strgroups[0], NULL, 16)), (strtol(strgroups[1], NULL, 16)), (strtol(strgroups[2], NULL, 16))}; cairo_set_source_rgb(xcb_ctx, rgb16[0] / 255.0, rgb16[1] / 255.0, rgb16[2] / 255.0); cairo_rectangle(xcb_ctx, 0, 0, resolution[0], resolution[1]); cairo_fill(xcb_ctx); } /* build indicator color arrays */ char strgroupsiv[4][3] = {{insidevercolor[0], insidevercolor[1], '\0'}, {insidevercolor[2], insidevercolor[3], '\0'}, {insidevercolor[4], insidevercolor[5], '\0'}, {insidevercolor[6], insidevercolor[7], '\0'}}; uint32_t insidever16[4] = {(strtol(strgroupsiv[0], NULL, 16)), (strtol(strgroupsiv[1], NULL, 16)), (strtol(strgroupsiv[2], NULL, 16)), (strtol(strgroupsiv[3], NULL, 16))}; char strgroupsiw[4][3] = {{insidewrongcolor[0], insidewrongcolor[1], '\0'}, {insidewrongcolor[2], insidewrongcolor[3], '\0'}, {insidewrongcolor[4], insidewrongcolor[5], '\0'}, {insidewrongcolor[6], insidewrongcolor[7], '\0'}}; uint32_t insidewrong16[4] = {(strtol(strgroupsiw[0], NULL, 16)), (strtol(strgroupsiw[1], NULL, 16)), (strtol(strgroupsiw[2], NULL, 16)), (strtol(strgroupsiw[3], NULL, 16))}; char strgroupsi[4][3] = {{insidecolor[0], insidecolor[1], '\0'}, {insidecolor[2], insidecolor[3], '\0'}, {insidecolor[4], insidecolor[5], '\0'}, {insidecolor[6], insidecolor[7], '\0'}}; uint32_t inside16[4] = {(strtol(strgroupsi[0], NULL, 16)), (strtol(strgroupsi[1], NULL, 16)), (strtol(strgroupsi[2], NULL, 16)), (strtol(strgroupsi[3], NULL, 16))}; char strgroupsrv[4][3] = {{ringvercolor[0], ringvercolor[1], '\0'}, {ringvercolor[2], ringvercolor[3], '\0'}, {ringvercolor[4], ringvercolor[5], '\0'}, {ringvercolor[6], ringvercolor[7], '\0'}}; uint32_t ringver16[4] = {(strtol(strgroupsrv[0], NULL, 16)), (strtol(strgroupsrv[1], NULL, 16)), (strtol(strgroupsrv[2], NULL, 16)), (strtol(strgroupsrv[3], NULL, 16))}; char strgroupsrw[4][3] = {{ringwrongcolor[0], ringwrongcolor[1], '\0'}, {ringwrongcolor[2], ringwrongcolor[3], '\0'}, {ringwrongcolor[4], ringwrongcolor[5], '\0'}, {ringwrongcolor[6], ringwrongcolor[7], '\0'}}; uint32_t ringwrong16[4] = {(strtol(strgroupsrw[0], NULL, 16)), (strtol(strgroupsrw[1], NULL, 16)), (strtol(strgroupsrw[2], NULL, 16)), (strtol(strgroupsrw[3], NULL, 16))}; char strgroupsr[4][3] = {{ringcolor[0], ringcolor[1], '\0'}, {ringcolor[2], ringcolor[3], '\0'}, {ringcolor[4], ringcolor[5], '\0'}, {ringcolor[6], ringcolor[7], '\0'}}; uint32_t ring16[4] = {(strtol(strgroupsr[0], NULL, 16)), (strtol(strgroupsr[1], NULL, 16)), (strtol(strgroupsr[2], NULL, 16)), (strtol(strgroupsr[3], NULL, 16))}; char strgroupsl[4][3] = {{linecolor[0], linecolor[1], '\0'}, {linecolor[2], linecolor[3], '\0'}, {linecolor[4], linecolor[5], '\0'}, {linecolor[6], linecolor[7], '\0'}}; uint32_t line16[4] = {(strtol(strgroupsl[0], NULL, 16)), (strtol(strgroupsl[1], NULL, 16)), (strtol(strgroupsl[2], NULL, 16)), (strtol(strgroupsl[3], NULL, 16))}; char strgroupst[4][3] = {{textcolor[0], textcolor[1], '\0'}, {textcolor[2], textcolor[3], '\0'}, {textcolor[4], textcolor[5], '\0'}, {textcolor[6], textcolor[7], '\0'}}; uint32_t text16[4] = {(strtol(strgroupst[0], NULL, 16)), (strtol(strgroupst[1], NULL, 16)), (strtol(strgroupst[2], NULL, 16)), (strtol(strgroupst[3], NULL, 16))}; char strgroupsk[4][3] = {{keyhlcolor[0], keyhlcolor[1], '\0'}, {keyhlcolor[2], keyhlcolor[3], '\0'}, {keyhlcolor[4], keyhlcolor[5], '\0'}, {keyhlcolor[6], keyhlcolor[7], '\0'}}; uint32_t keyhl16[4] = {(strtol(strgroupsk[0], NULL, 16)), (strtol(strgroupsk[1], NULL, 16)), (strtol(strgroupsk[2], NULL, 16)), (strtol(strgroupsk[3], NULL, 16))}; char strgroupsb[4][3] = {{bshlcolor[0], bshlcolor[1], '\0'}, {bshlcolor[2], bshlcolor[3], '\0'}, {bshlcolor[4], bshlcolor[5], '\0'}, {bshlcolor[6], bshlcolor[7], '\0'}}; uint32_t bshl16[4] = {(strtol(strgroupsb[0], NULL, 16)), (strtol(strgroupsb[1], NULL, 16)), (strtol(strgroupsb[2], NULL, 16)), (strtol(strgroupsb[3], NULL, 16))}; char strgroupss[4][3] = {{separatorcolor[0], separatorcolor[1], '\0'}, {separatorcolor[2], separatorcolor[3], '\0'}, {separatorcolor[4], separatorcolor[5], '\0'}, {separatorcolor[6], separatorcolor[7], '\0'}}; uint32_t sep16[4] = {(strtol(strgroupss[0], NULL, 16)), (strtol(strgroupss[1], NULL, 16)), (strtol(strgroupss[2], NULL, 16)), (strtol(strgroupss[3], NULL, 16))}; /* https://github.com/ravinrabbid/i3lock-clock/commit/0de3a411fa5249c3a4822612c2d6c476389a1297 */ time_t rawtime; struct tm* timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); if (unlock_indicator && (unlock_state >= STATE_KEY_PRESSED || pam_state > STATE_PAM_IDLE || show_clock)) { cairo_scale(ctx, scaling_factor(), scaling_factor()); /* Draw a (centered) circle with transparent background. */ cairo_set_line_width(ctx, 7.0); cairo_arc(ctx, BUTTON_CENTER /* x */, BUTTON_CENTER /* y */, BUTTON_RADIUS /* radius */, 0 /* start */, 2 * M_PI /* end */); /* Use the appropriate color for the different PAM states * (currently verifying, wrong password, or default) */ switch (pam_state) { case STATE_PAM_VERIFY: case STATE_PAM_LOCK: cairo_set_source_rgba(ctx, (double)insidever16[0]/255, (double)insidever16[1]/255, (double)insidever16[2]/255, (double)insidever16[3]/255); break; case STATE_PAM_WRONG: case STATE_I3LOCK_LOCK_FAILED: cairo_set_source_rgba(ctx, (double)insidewrong16[0]/255, (double)insidewrong16[1]/255, (double)insidewrong16[2]/255, (double)insidewrong16[3]/255); break; default: cairo_set_source_rgba(ctx, (double)inside16[0]/255, (double)inside16[1]/255, (double)inside16[2]/255, (double)inside16[3]/255); break; } cairo_fill_preserve(ctx); switch (pam_state) { case STATE_PAM_VERIFY: case STATE_PAM_LOCK: cairo_set_source_rgba(ctx, (double)ringver16[0]/255, (double)ringver16[1]/255, (double)ringver16[2]/255, (double)ringver16[3]/255); if (internal_line_source == 1) { line16[0] = ringver16[0]; line16[1] = ringver16[1]; line16[2] = ringver16[2]; line16[3] = ringver16[3]; } break; case STATE_PAM_WRONG: case STATE_I3LOCK_LOCK_FAILED: cairo_set_source_rgba(ctx, (double)ringwrong16[0]/255, (double)ringwrong16[1]/255, (double)ringwrong16[2]/255, (double)ringwrong16[3]/255); if (internal_line_source == 1) { line16[0] = ringwrong16[0]; line16[1] = ringwrong16[1]; line16[2] = ringwrong16[2]; line16[3] = ringwrong16[3]; } break; case STATE_PAM_IDLE: cairo_set_source_rgba(ctx, (double)ring16[0]/255, (double)ring16[1]/255, (double)ring16[2]/255, (double)ring16[3]/255); if (internal_line_source == 1) { line16[0] = ring16[0]; line16[1] = ring16[1]; line16[2] = ring16[2]; line16[3] = ring16[3]; } break; } cairo_stroke(ctx); /* Draw an inner separator line. */ if (internal_line_source != 2) { //pretty sure this only needs drawn if it's being drawn over the inside? cairo_set_source_rgba(ctx, (double)line16[0]/255, (double)line16[1]/255, (double)line16[2]/255, (double)line16[3]/255); cairo_set_line_width(ctx, 2.0); cairo_arc(ctx, BUTTON_CENTER /* x */, BUTTON_CENTER /* y */, BUTTON_RADIUS - 5 /* radius */, 0, 2 * M_PI); cairo_stroke(ctx); } cairo_set_line_width(ctx, 10.0); /* Display a (centered) text of the current PAM state. */ char *text = NULL; char *date = NULL; char time_text[40] = {0}; char date_text[40] = {0}; /* We don't want to show more than a 3-digit number. */ char buf[4]; cairo_set_source_rgba(ctx, (double)text16[0]/255, (double)text16[1]/255, (double)text16[2]/255, (double)text16[3]/255); //this was moved up to here cairo_select_font_face(ctx, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(ctx, 28.0); switch (pam_state) { case STATE_PAM_VERIFY: text = "verifying…"; break; case STATE_PAM_LOCK: text = "locking…"; break; case STATE_PAM_WRONG: text = "wrong!"; break; case STATE_I3LOCK_LOCK_FAILED: text = "lock failed!"; break; default: if (show_failed_attempts && failed_attempts > 0) { if (failed_attempts > 999) { text = "> 999"; } else { snprintf(buf, sizeof(buf), "%d", failed_attempts); text = buf; } cairo_set_source_rgba(ctx, (double)text16[0]/255, (double)text16[1]/255, (double)text16[2]/255, (double)text16[3]/255); cairo_set_font_size(ctx, 32.0); } else if (show_clock) { strftime(time_text, 40, time_format, timeinfo); strftime(date_text, 40, date_format, timeinfo); text = time_text; date = date_text; } break; } if (text) { cairo_text_extents_t extents; double x, y; cairo_text_extents(ctx, text, &extents); x = BUTTON_CENTER - ((extents.width / 2) + extents.x_bearing); if (date) { y = BUTTON_CENTER - ((extents.height / 2) + extents.y_bearing) - 6; } else { y = BUTTON_CENTER - ((extents.height / 2) + extents.y_bearing); } cairo_move_to(ctx, x, y); cairo_show_text(ctx, text); cairo_close_path(ctx); } if (date) { cairo_text_extents_t extents; double x, y; // TODO: different date/time colors cairo_set_source_rgba(ctx, (double)text16[0]/255, (double)text16[1]/255, (double)text16[2]/255, (double)text16[3]/255); cairo_set_font_size(ctx, 14.0); cairo_text_extents(ctx, date, &extents); x = BUTTON_CENTER - ((extents.width / 2) + extents.x_bearing); y = BUTTON_CENTER - ((extents.height / 2) + extents.y_bearing) + 14; cairo_move_to(ctx, x, y); cairo_show_text(ctx, date); cairo_close_path(ctx); } if (pam_state == STATE_PAM_WRONG && (modifier_string != NULL)) { cairo_text_extents_t extents; double x, y; cairo_set_font_size(ctx, 14.0); cairo_text_extents(ctx, modifier_string, &extents); x = BUTTON_CENTER - ((extents.width / 2) + extents.x_bearing); y = BUTTON_CENTER - ((extents.height / 2) + extents.y_bearing) + 28.0; cairo_move_to(ctx, x, y); cairo_show_text(ctx, modifier_string); cairo_close_path(ctx); } /* After the user pressed any valid key or the backspace key, we * highlight a random part of the unlock indicator to confirm this * keypress. */ if (unlock_state == STATE_KEY_ACTIVE || unlock_state == STATE_BACKSPACE_ACTIVE) { cairo_set_line_width(ctx, 7.0); cairo_new_sub_path(ctx); double highlight_start = (rand() % (int)(2 * M_PI * 100)) / 100.0; cairo_arc(ctx, BUTTON_CENTER /* x */, BUTTON_CENTER /* y */, BUTTON_RADIUS /* radius */, highlight_start, highlight_start + (M_PI / 3.0)); if (unlock_state == STATE_KEY_ACTIVE) { /* For normal keys, we use a lighter green. */ //lol no cairo_set_source_rgba(ctx, (double)keyhl16[0]/255, (double)keyhl16[1]/255, (double)keyhl16[2]/255, (double)keyhl16[3]/255); } else { /* For backspace, we use red. */ //lol no cairo_set_source_rgba(ctx, (double)bshl16[0]/255, (double)bshl16[1]/255, (double)bshl16[2]/255, (double)bshl16[3]/255); } cairo_stroke(ctx); /* Draw two little separators for the highlighted part of the * unlock indicator. */ cairo_set_source_rgba(ctx, (double)sep16[0]/255, (double)sep16[1]/255, (double)sep16[2]/255, (double)sep16[3]/255); cairo_arc(ctx, BUTTON_CENTER /* x */, BUTTON_CENTER /* y */, BUTTON_RADIUS /* radius */, highlight_start /* start */, highlight_start + (M_PI / 128.0) /* end */); cairo_stroke(ctx); cairo_arc(ctx, BUTTON_CENTER /* x */, BUTTON_CENTER /* y */, BUTTON_RADIUS /* radius */, highlight_start + (M_PI / 3.0) /* start */, (highlight_start + (M_PI / 3.0)) + (M_PI / 128.0) /* end */); cairo_stroke(ctx); } } if (xr_screens > 0) { /* Composite the unlock indicator in the middle of each screen. */ // excuse me, just gonna hack something in right here if (screen_number != -1 && screen_number < xr_screens) { int x = (xr_resolutions[screen_number].x + ((xr_resolutions[screen_number].width / 2) - (button_diameter_physical / 2))); int y = (xr_resolutions[screen_number].y + ((xr_resolutions[screen_number].height / 2) - (button_diameter_physical / 2))); cairo_set_source_surface(xcb_ctx, output, x, y); cairo_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical); cairo_fill(xcb_ctx); } else { for (int screen = 0; screen < xr_screens; screen++) { int x = (xr_resolutions[screen].x + ((xr_resolutions[screen].width / 2) - (button_diameter_physical / 2))); int y = (xr_resolutions[screen].y + ((xr_resolutions[screen].height / 2) - (button_diameter_physical / 2))); cairo_set_source_surface(xcb_ctx, output, x, y); cairo_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical); cairo_fill(xcb_ctx); } } } else { /* We have no information about the screen sizes/positions, so we just * place the unlock indicator in the middle of the X root window and * hope for the best. */ int x = (last_resolution[0] / 2) - (button_diameter_physical / 2); int y = (last_resolution[1] / 2) - (button_diameter_physical / 2); cairo_set_source_surface(xcb_ctx, output, x, y); cairo_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical); cairo_fill(xcb_ctx); } cairo_surface_destroy(xcb_output); cairo_surface_destroy(output); cairo_destroy(ctx); cairo_destroy(xcb_ctx); return bg_pixmap; }
static ClutterActor * make_background (const ClutterColor *color, gfloat width, gfloat height) { ClutterActor *tex = clutter_cairo_texture_new (width, height); cairo_t *cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (tex)); cairo_pattern_t *pat; gfloat x, y; #define BG_ROUND_RADIUS 12 x = y = 0; cairo_move_to (cr, BG_ROUND_RADIUS, y); cairo_line_to (cr, width - BG_ROUND_RADIUS, y); cairo_curve_to (cr, width, y, width, y, width, BG_ROUND_RADIUS); cairo_line_to (cr, width, height - BG_ROUND_RADIUS); cairo_curve_to (cr, width, height, width, height, width - BG_ROUND_RADIUS, height); cairo_line_to (cr, BG_ROUND_RADIUS, height); cairo_curve_to (cr, x, height, x, height, x, height - BG_ROUND_RADIUS); cairo_line_to (cr, x, BG_ROUND_RADIUS); cairo_curve_to (cr, x, y, x, y, BG_ROUND_RADIUS, y); cairo_close_path (cr); clutter_cairo_set_source_color (cr, color); cairo_stroke (cr); x += 4; y += 4; width -= 4; height -= 4; cairo_move_to (cr, BG_ROUND_RADIUS, y); cairo_line_to (cr, width - BG_ROUND_RADIUS, y); cairo_curve_to (cr, width, y, width, y, width, BG_ROUND_RADIUS); cairo_line_to (cr, width, height - BG_ROUND_RADIUS); cairo_curve_to (cr, width, height, width, height, width - BG_ROUND_RADIUS, height); cairo_line_to (cr, BG_ROUND_RADIUS, height); cairo_curve_to (cr, x, height, x, height, x, height - BG_ROUND_RADIUS); cairo_line_to (cr, x, BG_ROUND_RADIUS); cairo_curve_to (cr, x, y, x, y, BG_ROUND_RADIUS, y); cairo_close_path (cr); pat = cairo_pattern_create_linear (0, 0, 0, height); cairo_pattern_add_color_stop_rgba (pat, 1, .85, .85, .85, 1); cairo_pattern_add_color_stop_rgba (pat, .95, 1, 1, 1, 1); cairo_pattern_add_color_stop_rgba (pat, .05, 1, 1, 1, 1); cairo_pattern_add_color_stop_rgba (pat, 0, .85, .85, .85, 1); cairo_set_source (cr, pat); cairo_fill (cr); cairo_pattern_destroy (pat); cairo_destroy (cr); #undef BG_ROUND_RADIUS return tex; }
/** * awn_cairo_rounded_rect_shadow: * * Draws a shadow for rounded rectangle via cairo. */ void awn_cairo_rounded_rect_shadow(cairo_t *cr, double rx0, double ry0, double width, double height, double radius, AwnCairoRoundCorners state, double shadow_radius, double shadow_alpha) { cairo_pattern_t *pat; const double rx1 = rx0 + width; const double ry1 = ry0 + height; const double xr = rx0 + radius; const double yr = ry0 + radius; cairo_save (cr); cairo_rectangle (cr, rx0 - shadow_radius, ry0 - shadow_radius, width + shadow_radius * 2, height + shadow_radius * 2); awn_cairo_rounded_rect (cr, rx0, ry0, width, height, radius, state); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_clip (cr); /* top left */ pat = cairo_pattern_create_radial (xr, yr, radius, xr, yr, radius + shadow_radius); cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.0, 0.0, 0.0, shadow_alpha); cairo_pattern_add_color_stop_rgba (pat, 1./3, 0.0, 0.0, 0.0, shadow_alpha/2); cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.0, 0.0, 0.0, 0.0); cairo_set_source (cr, pat); cairo_rectangle (cr, rx0 - shadow_radius, ry0 - shadow_radius, radius + shadow_radius, radius + shadow_radius); cairo_fill (cr); cairo_pattern_destroy (pat); /* top */ pat = cairo_pattern_create_linear (0.0, ry0 - shadow_radius, 0.0, ry0); cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.0, 0.0, 0.0, 0.0); cairo_pattern_add_color_stop_rgba (pat, 2./3, 0.0, 0.0, 0.0, shadow_alpha/2); cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.0, 0.0, 0.0, shadow_alpha); cairo_set_source (cr, pat); cairo_rectangle (cr, xr, ry0 - shadow_radius, width - radius * 2, shadow_radius); cairo_fill (cr); cairo_pattern_destroy (pat); /* top right */ pat = cairo_pattern_create_radial (rx1 - radius, yr, radius, rx1 - radius, yr, radius + shadow_radius); cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.0, 0.0, 0.0, shadow_alpha); cairo_pattern_add_color_stop_rgba (pat, 1./3, 0.0, 0.0, 0.0, shadow_alpha/2); cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.0, 0.0, 0.0, 0.0); cairo_set_source (cr, pat); cairo_rectangle (cr, rx1 - radius, ry0 - shadow_radius, radius + shadow_radius, radius + shadow_radius); cairo_fill (cr); cairo_pattern_destroy (pat); /* right */ pat = cairo_pattern_create_linear (rx1, 0.0, rx1 + shadow_radius, 0.0); cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.0, 0.0, 0.0, shadow_alpha); cairo_pattern_add_color_stop_rgba (pat, 1./3, 0.0, 0.0, 0.0, shadow_alpha/2); cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.0, 0.0, 0.0, 0.0); cairo_set_source (cr, pat); cairo_rectangle (cr, rx1, ry0 + radius, shadow_radius, height - radius * 2); cairo_fill (cr); cairo_pattern_destroy (pat); /* bottom right */ pat = cairo_pattern_create_radial (rx1 - radius, ry1 - radius, radius, rx1 - radius, ry1 - radius, radius + shadow_radius); cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.0, 0.0, 0.0, shadow_alpha); cairo_pattern_add_color_stop_rgba (pat, 1./3, 0.0, 0.0, 0.0, shadow_alpha/2); cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.0, 0.0, 0.0, 0.0); cairo_set_source (cr, pat); cairo_rectangle (cr, rx1 - radius, ry1 - radius, radius + shadow_radius, radius + shadow_radius); cairo_fill (cr); cairo_pattern_destroy (pat); /* bottom */ pat = cairo_pattern_create_linear (0.0, ry1, 0.0, ry1 + shadow_radius); cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.0, 0.0, 0.0, shadow_alpha); cairo_pattern_add_color_stop_rgba (pat, 1./3, 0.0, 0.0, 0.0, shadow_alpha/2); cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.0, 0.0, 0.0, 0.0); cairo_set_source (cr, pat); cairo_rectangle (cr, xr, ry1, width - radius * 2, shadow_radius); cairo_fill (cr); cairo_pattern_destroy (pat); /* bottom left */ pat = cairo_pattern_create_radial (xr, ry1 - radius, radius, xr, ry1 - radius, radius + shadow_radius); cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.0, 0.0, 0.0, shadow_alpha); cairo_pattern_add_color_stop_rgba (pat, 1./3, 0.0, 0.0, 0.0, shadow_alpha/2); cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.0, 0.0, 0.0, 0.0); cairo_set_source (cr, pat); cairo_rectangle (cr, rx0 - shadow_radius, ry1 - radius, radius + shadow_radius, radius + shadow_radius); cairo_fill (cr); cairo_pattern_destroy (pat); /* left */ pat = cairo_pattern_create_linear (rx0 - shadow_radius, 0.0, rx0, 0.0); cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.0, 0.0, 0.0, 0.0); cairo_pattern_add_color_stop_rgba (pat, 2./3, 0.0, 0.0, 0.0, shadow_alpha/2); cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.0, 0.0, 0.0, shadow_alpha); cairo_set_source (cr, pat); cairo_rectangle (cr, rx0 - shadow_radius, yr, shadow_radius, height - radius * 2); cairo_fill (cr); cairo_pattern_destroy (pat); cairo_restore (cr); }
void render_hex (cairo_t *cr, int x, int y, int w) { cairo_pattern_t *pat; static float hexrot = 0; int r1; float scale; cairo_save(cr); cairo_set_line_width(cr, 1); cairo_set_source_rgb(cr, ORANGE); scale = 2.5; r1 = ((w)/2 * sqrt(3)); cairo_translate (cr, x, y); cairo_rotate (cr, hexrot * (M_PI/180.0)); cairo_translate (cr, -(w/2), -r1); cairo_move_to (cr, 0, 0); cairo_rel_line_to (cr, w, 0); cairo_rotate (cr, 60 * (M_PI/180.0)); cairo_rel_line_to (cr, w, 0); cairo_rotate (cr, 60 * (M_PI/180.0)); cairo_rel_line_to (cr, w, 0); cairo_rotate (cr, 60 * (M_PI/180.0)); cairo_rel_line_to (cr, w, 0); cairo_rotate (cr, 60 * (M_PI/180.0)); cairo_rel_line_to (cr, w, 0); cairo_rotate (cr, 60 * (M_PI/180.0)); cairo_rel_line_to (cr, w, 0); hexrot += 1.5; cairo_fill (cr); cairo_restore(cr); cairo_save(cr); cairo_set_line_width(cr, 1.5); cairo_set_operator(cr, CAIRO_OPERATOR_ADD); cairo_set_source_rgb(cr, GREY); cairo_translate (cr, x, y); cairo_rotate (cr, hexrot * (M_PI/180.0)); cairo_translate (cr, -((w * scale)/2), -r1 * scale); cairo_scale(cr, scale, scale); cairo_move_to (cr, 0, 0); cairo_rel_line_to (cr, w, 0); cairo_rotate (cr, 60 * (M_PI/180.0)); cairo_rel_line_to (cr, w, 0); cairo_rotate (cr, 60 * (M_PI/180.0)); cairo_rel_line_to (cr, w, 0); cairo_rotate (cr, 60 * (M_PI/180.0)); cairo_rel_line_to (cr, w, 0); cairo_rotate (cr, 60 * (M_PI/180.0)); cairo_rel_line_to (cr, w, 0); cairo_rotate (cr, 60 * (M_PI/180.0)); cairo_rel_line_to (cr, w, 0); cairo_rotate (cr, 60 * (M_PI/180.0)); cairo_set_operator(cr, CAIRO_OPERATOR_ADD); pat = cairo_pattern_create_radial (w/2, r1, 3, w/2, r1, r1*scale); cairo_pattern_add_color_stop_rgba (pat, 0, 0, 0, 1, 1); cairo_pattern_add_color_stop_rgba (pat, 0.4, 0, 0, 0, 0); cairo_set_source (cr, pat); cairo_fill (cr); cairo_pattern_destroy (pat); cairo_restore(cr); }
static gboolean _gradient_slider_expose(GtkWidget *widget, GdkEventExpose *event) { GtkDarktableGradientSlider *gslider=DTGTK_GRADIENT_SLIDER(widget); assert(gslider->position > 0); g_return_val_if_fail(widget != NULL, FALSE); g_return_val_if_fail(DTGTK_IS_GRADIENT_SLIDER(widget), FALSE); g_return_val_if_fail(event != NULL, FALSE); GtkStyle *style=gtk_rc_get_style_by_paths(gtk_settings_get_default(), NULL,"GtkButton", GTK_TYPE_BUTTON); if(!style) style = gtk_rc_get_style(widget); int state = gtk_widget_get_state(widget); /*int x = widget->allocation.x; int y = widget->allocation.y;*/ int width = widget->allocation.width; int height = widget->allocation.height; int margins = gslider->margins; // Begin cairo drawing cairo_t *cr; cr = gdk_cairo_create(widget->window); // First build the cairo gradient and then fill the gradient float gheight=height/2.0; float gwidth=width-2*margins; GList *current=NULL; cairo_pattern_t *gradient=NULL; if((current=g_list_first(gslider->colors)) != NULL) { gradient=cairo_pattern_create_linear(0,0,gwidth,gheight); do { _gradient_slider_stop_t *stop=(_gradient_slider_stop_t *)current->data; cairo_pattern_add_color_stop_rgb(gradient,stop->position,stop->color.red/65535.0,stop->color.green/65535.0,stop->color.blue/65535.0); } while((current=g_list_next(current))!=NULL); } if(gradient!=NULL) // Do we got a gradient, lets draw it { cairo_set_line_width(cr,0.1); cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND); cairo_set_source(cr,gradient); cairo_rectangle(cr,margins,(height-gheight)/2.0,gwidth,gheight); cairo_fill(cr); cairo_stroke(cr); } // Lets draw position arrows cairo_set_source_rgba(cr, style->fg[state].red/65535.0, style->fg[state].green/65535.0, style->fg[state].blue/65535.0, 1.0 ); // do we have a picker value to draw? gdouble *picker = gslider->picker; if(picker[0] >= 0.0 && picker[0] <= 1.0) { int vx_min=_scale_to_screen(widget, picker[1]); int vx_max=_scale_to_screen(widget, picker[2]); int vx_avg=_scale_to_screen(widget, picker[0]); cairo_set_source_rgba(cr, style->fg[state].red/65535.0, style->fg[state].green/65535.0, style->fg[state].blue/65535.0, 0.33 ); cairo_rectangle(cr,vx_min,(height-gheight)/2.0,fmax((float)vx_max-vx_min, 0.0f),gheight); cairo_fill(cr); cairo_set_source_rgba(cr, style->fg[state].red/65535.0, style->fg[state].green/65535.0, style->fg[state].blue/65535.0, 1.0 ); cairo_move_to(cr,vx_avg,(height-gheight)/2.0); cairo_line_to(cr,vx_avg,(height+gheight)/2.0); cairo_set_antialias(cr,CAIRO_ANTIALIAS_NONE); cairo_set_line_width(cr,1.0); cairo_stroke(cr); } int indirect[GRADIENT_SLIDER_MAX_POSITIONS]; for(int k=0; k<gslider->positions; k++) indirect[k] = gslider->selected == -1 ? k : (gslider->selected + 1 + k) % gslider->positions; for(int k=0; k<gslider->positions; k++) { int l = indirect[k]; int vx=_scale_to_screen(widget, gslider->position[l]); int mk=gslider->marker[l]; int sz=(mk & (1<<3)) ? 13 : 10; // big or small marker? if(l == gslider->selected && (gslider->is_entered == TRUE || gslider->is_dragging == TRUE)) { cairo_set_source_rgba(cr, style->fg[state].red/65535.0, style->fg[state].green/65535.0, style->fg[state].blue/65535.0 * 0.5, 1.0 ); } else { cairo_set_source_rgba(cr, style->fg[state].red/65535.0*0.8, style->fg[state].green/65535.0*0.8, style->fg[state].blue/65535.0*0.8, 1.0 ); } #if 0 if(sz < 10) { // supporting line for small markers cairo_move_to(cr,vx,2); cairo_line_to(cr,vx,height-2); cairo_set_antialias(cr,CAIRO_ANTIALIAS_NONE); cairo_set_line_width(cr,1.0); cairo_stroke(cr); } #endif cairo_set_antialias(cr,CAIRO_ANTIALIAS_DEFAULT); if(mk & 0x04) /* upper arrow */ { if (mk & 0x01) /* filled */ dtgtk_cairo_paint_solid_triangle(cr, vx-sz/2, sz < 10 ? 1 : -2,sz,sz,CPF_DIRECTION_DOWN); else dtgtk_cairo_paint_triangle(cr, vx-sz/2, sz < 10 ? 1 : -2,sz,sz,CPF_DIRECTION_DOWN); } if(mk & 0x02) /* lower arrow */ { if (mk & 0x01) /* filled */ dtgtk_cairo_paint_solid_triangle(cr, vx-sz/2,sz < 10 ? height-6 : height-11,sz,sz,CPF_DIRECTION_UP); else dtgtk_cairo_paint_triangle(cr, vx-sz/2,sz < 10 ? height-6 : height-11,sz,sz,CPF_DIRECTION_UP); } } cairo_destroy(cr); return FALSE; }
void gfxContext::SetPattern(gfxPattern *pattern) { cairo_set_source(mCairo, pattern->CairoPattern()); }