本文整理汇总了C++中cairo_rectangle函数的典型用法代码示例。如果您正苦于以下问题:C++ cairo_rectangle函数的具体用法?C++ cairo_rectangle怎么用?C++ cairo_rectangle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cairo_rectangle函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: draw
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
cairo_surface_t *surface;
cairo_t *cr2;
cairo_rectangle_list_t *rectangle_list;
const char *phase;
cairo_bool_t uses_clip_rects;
surface = cairo_surface_create_similar (cairo_get_group_target (cr),
CAIRO_CONTENT_COLOR, 100, 100);
/* don't use cr accidentally */
cr = NULL;
cr2 = cairo_create (surface);
cairo_surface_destroy (surface);
/* Check the surface type so we ignore cairo_copy_clip_rectangle_list failures
* on surface types that don't use rectangle lists for clipping.
* Default to FALSE for the internal surface types, (meta, test-fallback, etc.)
*/
switch (cairo_surface_get_type (surface)) {
case CAIRO_SURFACE_TYPE_IMAGE:
case CAIRO_SURFACE_TYPE_XLIB:
case CAIRO_SURFACE_TYPE_XCB:
case CAIRO_SURFACE_TYPE_GLITZ:
case CAIRO_SURFACE_TYPE_WIN32:
case CAIRO_SURFACE_TYPE_BEOS:
case CAIRO_SURFACE_TYPE_DIRECTFB:
uses_clip_rects = TRUE;
break;
case CAIRO_SURFACE_TYPE_QUARTZ:
case CAIRO_SURFACE_TYPE_PDF:
case CAIRO_SURFACE_TYPE_PS:
case CAIRO_SURFACE_TYPE_SVG:
case CAIRO_SURFACE_TYPE_OS2:
default:
uses_clip_rects = FALSE;
break;
}
/* first, test basic stuff. This should not be clipped, it should
return the surface rectangle. */
phase = "No clip set";
rectangle_list = cairo_copy_clip_rectangle_list (cr2);
if (!check_count (ctx, phase, uses_clip_rects, rectangle_list, 1) ||
!check_clip_extents (ctx, phase, cr2, 0, 0, 100, 100) ||
!check_rectangles_contain (ctx, phase, uses_clip_rects, rectangle_list, 0, 0, 100, 100)) {
cairo_rectangle_list_destroy (rectangle_list);
return CAIRO_TEST_FAILURE;
}
cairo_rectangle_list_destroy (rectangle_list);
/* Test simple clip rect. */
phase = "Simple clip rect";
cairo_save (cr2);
cairo_rectangle (cr2, 10, 10, 80, 80);
cairo_clip (cr2);
rectangle_list = cairo_copy_clip_rectangle_list (cr2);
if (!check_count (ctx, phase, uses_clip_rects, rectangle_list, 1) ||
!check_clip_extents (ctx, phase, cr2, 10, 10, 80, 80) ||
!check_rectangles_contain (ctx, phase, uses_clip_rects, rectangle_list, 10, 10, 80, 80)) {
cairo_rectangle_list_destroy (rectangle_list);
return CAIRO_TEST_FAILURE;
}
cairo_rectangle_list_destroy (rectangle_list);
cairo_restore (cr2);
/* Test everything clipped out. */
phase = "All clipped out";
cairo_save (cr2);
cairo_clip (cr2);
rectangle_list = cairo_copy_clip_rectangle_list (cr2);
if (!check_count (ctx, phase, uses_clip_rects, rectangle_list, 0)) {
cairo_rectangle_list_destroy (rectangle_list);
return CAIRO_TEST_FAILURE;
}
cairo_rectangle_list_destroy (rectangle_list);
cairo_restore (cr2);
/* test two clip rects */
phase = "Two clip rects";
cairo_save (cr2);
cairo_rectangle (cr2, 10, 10, 10, 10);
cairo_rectangle (cr2, 20, 20, 10, 10);
cairo_clip (cr2);
cairo_rectangle (cr2, 15, 15, 10, 10);
cairo_clip (cr2);
rectangle_list = cairo_copy_clip_rectangle_list (cr2);
if (!check_count (ctx, phase, uses_clip_rects, rectangle_list, 2) ||
!check_clip_extents (ctx, phase, cr2, 15, 15, 10, 10) ||
!check_rectangles_contain (ctx, phase, uses_clip_rects, rectangle_list, 15, 15, 5, 5) ||
!check_rectangles_contain (ctx, phase, uses_clip_rects, rectangle_list, 20, 20, 5, 5)) {
cairo_rectangle_list_destroy (rectangle_list);
return CAIRO_TEST_FAILURE;
}
cairo_rectangle_list_destroy (rectangle_list);
cairo_restore (cr2);
/* test non-rectangular clip */
//.........这里部分代码省略.........
开发者ID:jwmcglynn,项目名称:Gadgets,代码行数:101,代码来源:get-clip.c
示例2: gtk_css_image_radial_draw
//.........这里部分代码省略.........
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);
}
开发者ID:davidyang5405,项目名称:gtk,代码行数:101,代码来源:gtkcssimageradial.c
示例3: polygon_view_draw
static void
polygon_view_draw (PolygonView *self, cairo_t *cr)
{
polygon_t *polygon;
gdouble sf_x, sf_y, sf;
gdouble mid, dim;
gdouble x0, y0;
box_t extents;
extents = self->extents;
mid = (extents.p2.x + extents.p1.x) / 2.;
dim = (extents.p2.x - extents.p1.x) / 2. * 1.25;
sf_x = self->widget.allocation.width / dim / 2;
mid = (extents.p2.y + extents.p1.y) / 2.;
dim = (extents.p2.y - extents.p1.y) / 2. * 1.25;
sf_y = self->widget.allocation.height / dim / 2;
sf = MIN (sf_x, sf_y);
mid = (extents.p2.x + extents.p1.x) / 2.;
dim = sf_x / sf * (extents.p2.x - extents.p1.x) / 2. * 1.25;
x0 = mid - dim;
mid = (extents.p2.y + extents.p1.y) / 2.;
dim = sf_y / sf * (extents.p2.y - extents.p1.y) / 2. * 1.25;
y0 = mid - dim;
if (self->pixmap_width != self->widget.allocation.width ||
self->pixmap_height != self->widget.allocation.height)
{
cairo_surface_destroy (self->pixmap);
self->pixmap = pixmap_create (self, cairo_get_target (cr));
self->pixmap_width = self->widget.allocation.width;
self->pixmap_height = self->widget.allocation.height;
}
cairo_set_source_surface (cr, self->pixmap, 0, 0);
cairo_paint (cr);
if (self->polygons == NULL)
return;
/* draw a zoom view of the area around the mouse */
if (1) {
double zoom = self->mag_zoom;
int size = self->mag_size;
int mag_x = self->mag_x;
int mag_y = self->mag_y;
if (1) {
if (self->px + size < self->widget.allocation.width/2)
mag_x = self->px + size/4;
else
mag_x = self->px - size/4 - size;
mag_y = self->py - size/2;
if (mag_y < 0)
mag_y = 0;
if (mag_y + size > self->widget.allocation.height)
mag_y = self->widget.allocation.height - size;
}
cairo_save (cr); {
/* bottom right */
cairo_rectangle (cr, mag_x, mag_y, size, size);
cairo_stroke_preserve (cr);
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_fill_preserve (cr);
cairo_clip (cr);
/* compute roi in extents */
cairo_translate (cr, mag_x + size/2, mag_y + size/2);
cairo_save (cr); {
cairo_scale (cr, zoom, zoom);
cairo_translate (cr, -(self->px / sf + x0), -(self->py /sf + y0));
for (polygon = self->polygons; polygon; polygon = polygon->next) {
if (polygon->num_edges == 0)
continue;
draw_polygon (cr, polygon, zoom);
}
if (highlight != -1) {
cairo_move_to (cr, extents.p1.x, highlight);
cairo_line_to (cr, extents.p2.x, highlight);
cairo_set_source_rgb (cr, 0, .7, 0);
cairo_save (cr);
cairo_identity_matrix (cr);
cairo_set_line_width (cr, 1.);
cairo_stroke (cr);
cairo_restore (cr);
}
} cairo_restore (cr);
/* grid */
cairo_save (cr); {
int i;
cairo_translate (cr,
//.........这里部分代码省略.........
开发者ID:AZed,项目名称:cairo,代码行数:101,代码来源:show-polygon.c
示例4: draw_page
static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context,
gint page_nr, gpointer user_data)
{
DocInfo *dinfo = user_data;
GeanyEditor *editor;
cairo_t *cr;
gdouble width, height;
gdouble x = 0.0, y = 0.0;
/*gint layout_h;*/
gint count;
GString *str;
if (dinfo == NULL || page_nr >= dinfo->n_pages)
return;
editor = dinfo->doc->editor;
if (dinfo->n_pages > 0)
{
gdouble fraction = (page_nr + 1) / (gdouble) dinfo->n_pages;
gchar *text = g_strdup_printf(_("Page %d of %d"), page_nr, dinfo->n_pages);
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(main_widgets.progressbar), fraction);
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(main_widgets.progressbar), text);
g_free(text);
}
#ifdef GEANY_PRINT_DEBUG
geany_debug("draw_page = %d, pages = %d, (real) lines_per_page = %d",
page_nr, dinfo->n_pages, dinfo->lines_per_page);
#endif
str = g_string_sized_new(256);
cr = gtk_print_context_get_cairo_context(context);
width = gtk_print_context_get_width(context);
height = gtk_print_context_get_height(context);
cairo_set_source_rgb(cr, 0, 0, 0);
#ifdef GEANY_PRINT_DEBUG
cairo_set_line_width(cr, 0.2);
cairo_rectangle(cr, 0, 0, width, height);
cairo_stroke(cr);
#endif
cairo_move_to(cr, 0, 0);
pango_layout_set_width(dinfo->layout, width * PANGO_SCALE);
pango_layout_set_alignment(dinfo->layout, PANGO_ALIGN_LEFT);
pango_layout_set_ellipsize(dinfo->layout, FALSE);
pango_layout_set_justify(dinfo->layout, FALSE);
if (printing_prefs.print_page_header)
add_page_header(dinfo, cr, width, page_nr);
count = 0; /* the actual line counter for the current page, might be different from
* dinfo->cur_line due to possible line breaks */
while (count < dinfo->lines_per_page)
{
gchar c = 'a';
gint style = -1;
PangoAttrList *layout_attr;
PangoAttribute *attr;
gint colours[3] = { 0 };
gboolean add_linenumber = TRUE;
gboolean at_eol;
while (count < dinfo->lines_per_page && c != '\0')
{
at_eol = FALSE;
g_string_erase(str, 0, str->len); /* clear the string */
/* line numbers */
if (printing_prefs.print_line_numbers && add_linenumber)
{
/* if we had a wrapped line on the last page which needs to be continued, don't
* add a line number */
if (dinfo->long_line)
{
add_linenumber = FALSE;
}
else
{
gchar *line_number = NULL;
gint cur_line_number_margin = get_line_numbers_arity(dinfo->cur_line + 1);
gchar *fill = g_strnfill(
dinfo->max_line_number_margin - cur_line_number_margin - 1, ' ');
line_number = g_strdup_printf("%s%d ", fill, dinfo->cur_line + 1);
g_string_append(str, line_number);
dinfo->cur_line++; /* increase document line */
add_linenumber = FALSE;
style = STYLE_LINENUMBER;
c = 'a'; /* dummy value */
g_free(fill);
g_free(line_number);
}
}
/* data */
else
{
style = sci_get_style_at(dinfo->doc->editor->sci, dinfo->cur_pos);
//.........这里部分代码省略.........
开发者ID:cirne100,项目名称:geany,代码行数:101,代码来源:printing.c
示例5: copyright
//.........这里部分代码省略.........
double x0, y0, x1, y1;
switch(lib->splitline_rotation)
{
case 0:
x0 = 0.0;
y0 = 0.0;
x1 = buf.width * lib->splitline_x;
y1 = buf.height;
break;
case 1:
x0 = 0.0;
y0 = 0.0;
x1 = buf.width;
y1 = buf.height * lib->splitline_y;
break;
case 2:
x0 = buf.width * lib->splitline_x;
y0 = 0.0;
x1 = buf.width;
y1 = buf.height;
break;
case 3:
x0 = 0.0;
y0 = buf.height * lib->splitline_y;
x1 = buf.width;
y1 = buf.height;
break;
default:
fprintf(stderr, "OMFG, the world will collapse, this shouldn't be reachable!\n");
dt_pthread_mutex_unlock(&cam->live_view_pixbuf_mutex);
return;
}
cairo_rectangle(cr, x0, y0, x1, y1);
cairo_clip(cr);
}
cairo_set_source_surface(cr, surface, 0, 0);
// set filter no nearest:
// in skull mode, we want to see big pixels.
// in 1 iir mode for the right mip, we want to see exactly what the pipe gave us, 1:1 pixel for pixel.
// in between, filtering just makes stuff go unsharp.
if((buf.width <= 8 && buf.height <= 8) || fabsf(scale - 1.0f) < 0.01f)
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST);
cairo_rectangle(cr, 0, 0, buf.width, buf.height);
int overlay_modes_index = dt_bauhaus_combobox_get(lib->overlay_mode);
if(overlay_modes_index >= 0)
{
cairo_operator_t mode = _overlay_modes[overlay_modes_index];
cairo_set_operator(cr, mode);
}
cairo_fill(cr);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
cairo_surface_destroy(surface);
}
cairo_restore(cr);
if(buf.buf) dt_mipmap_cache_release(darktable.mipmap_cache, &buf);
if(img) dt_image_cache_read_release(darktable.image_cache, img);
// ON CANVAS CONTROLS
if(use_splitline)
{
scale = fminf(1.0, fminf(w / pw, h / ph));
// image coordinates
lib->overlay_x0 = 0.5 * (width - pw * scale);
开发者ID:AlicVB,项目名称:darktable,代码行数:67,代码来源:live_view.c
示例6: gimp_fg_bg_view_expose
static gboolean
gimp_fg_bg_view_expose (GtkWidget *widget,
GdkEventExpose *eevent)
{
GimpFgBgView *view = GIMP_FG_BG_VIEW (widget);
GtkStyle *style = gtk_widget_get_style (widget);
GdkWindow *window = gtk_widget_get_window (widget);
cairo_t *cr;
GtkAllocation allocation;
gint rect_w, rect_h;
GimpRGB color;
if (! gtk_widget_is_drawable (widget))
return FALSE;
cr = gdk_cairo_create (eevent->window);
gdk_cairo_region (cr, eevent->region);
cairo_clip (cr);
gtk_widget_get_allocation (widget, &allocation);
cairo_translate (cr, allocation.x, allocation.y);
rect_w = allocation.width * 3 / 4;
rect_h = allocation.height * 3 / 4;
if (! view->transform)
gimp_fg_bg_view_create_transform (view);
/* draw the background area */
if (view->context)
{
gimp_context_get_background (view->context, &color);
if (view->transform)
gimp_color_transform_process_pixels (view->transform,
babl_format ("R'G'B'A double"),
&color,
babl_format ("R'G'B'A double"),
&color,
1);
gimp_cairo_set_source_rgb (cr, &color);
cairo_rectangle (cr,
allocation.width - rect_w + 1,
allocation.height - rect_h + 1,
rect_w - 2,
rect_h - 2);
cairo_fill (cr);
}
gtk_paint_shadow (style, window, GTK_STATE_NORMAL,
GTK_SHADOW_IN,
NULL, widget, NULL,
allocation.x + allocation.width - rect_w,
allocation.y + allocation.height - rect_h,
rect_w, rect_h);
/* draw the foreground area */
if (view->context)
{
gimp_context_get_foreground (view->context, &color);
if (view->transform)
gimp_color_transform_process_pixels (view->transform,
babl_format ("R'G'B'A double"),
&color,
babl_format ("R'G'B'A double"),
&color,
1);
gimp_cairo_set_source_rgb (cr, &color);
cairo_rectangle (cr, 1, 1, rect_w - 2, rect_h - 2);
cairo_fill (cr);
}
gtk_paint_shadow (style, window, GTK_STATE_NORMAL,
GTK_SHADOW_OUT,
NULL, widget, NULL,
allocation.x, allocation.y, rect_w, rect_h);
cairo_destroy (cr);
return TRUE;
}
开发者ID:LebedevRI,项目名称:gimp,代码行数:90,代码来源:gimpfgbgview.c
示例7: _lib_histogram_draw_callback
static gboolean _lib_histogram_draw_callback(GtkWidget *widget, cairo_t *crf, gpointer user_data)
{
dt_lib_module_t *self = (dt_lib_module_t *)user_data;
dt_lib_histogram_t *d = (dt_lib_histogram_t *)self->data;
dt_develop_t *dev = darktable.develop;
uint32_t *hist = dev->histogram;
float hist_max = dev->histogram_type == DT_DEV_HISTOGRAM_LINEAR ? dev->histogram_max
: logf(1.0 + dev->histogram_max);
const int inset = DT_HIST_INSET;
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
int width = allocation.width, height = allocation.height;
cairo_surface_t *cst = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cairo_t *cr = cairo_create(cst);
gtk_render_background(gtk_widget_get_style_context(widget), cr, 0, 0, allocation.width, allocation.height);
cairo_translate(cr, 4 * inset, inset);
width -= 2 * 4 * inset;
height -= 2 * inset;
if(d->mode_x == 0)
{
d->color_w = 0.06 * width;
d->button_spacing = 0.01 * width;
d->button_h = 0.06 * width;
d->button_y = d->button_spacing;
d->mode_w = d->color_w;
d->mode_x = width - 3 * (d->color_w + d->button_spacing) - (d->mode_w + d->button_spacing);
d->red_x = width - 3 * (d->color_w + d->button_spacing);
d->green_x = width - 2 * (d->color_w + d->button_spacing);
d->blue_x = width - (d->color_w + d->button_spacing);
}
// TODO: probably this should move to the configure-event callback! That would be future proof if we ever
// (again) allow to resize the side panels.
const gint stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
// this code assumes that the first expose comes before the first (preview) pipe is processed and that the
// size of the widget doesn't change!
if(dev->histogram_waveform_width == 0)
{
dev->histogram_waveform = (uint32_t *)calloc(height * stride / 4, sizeof(uint32_t));
dev->histogram_waveform_stride = stride;
dev->histogram_waveform_height = height;
dev->histogram_waveform_width = width;
// return TRUE; // there are enough expose events following ...
}
#if 1
// draw shadow around
float alpha = 1.0f;
cairo_set_line_width(cr, 0.2);
for(int k = 0; k < inset; k++)
{
cairo_rectangle(cr, -k, -k, width + 2 * k, height + 2 * k);
cairo_set_source_rgba(cr, 0, 0, 0, alpha);
alpha *= 0.5f;
cairo_fill(cr);
}
cairo_set_line_width(cr, 1.0);
#else
cairo_set_line_width(cr, 1.0);
cairo_set_source_rgb(cr, .1, .1, .1);
cairo_rectangle(cr, 0, 0, width, height);
cairo_stroke(cr);
#endif
cairo_rectangle(cr, 0, 0, width, height);
cairo_clip(cr);
cairo_set_source_rgb(cr, .3, .3, .3);
cairo_rectangle(cr, 0, 0, width, height);
cairo_fill(cr);
if(d->highlight == 1)
{
cairo_set_source_rgb(cr, .5, .5, .5);
cairo_rectangle(cr, 0, 0, .2 * width, height);
cairo_fill(cr);
}
else if(d->highlight == 2)
{
cairo_set_source_rgb(cr, .5, .5, .5);
cairo_rectangle(cr, 0.2 * width, 0, width, height);
cairo_fill(cr);
}
// draw grid
cairo_set_line_width(cr, .4);
cairo_set_source_rgb(cr, .1, .1, .1);
if(dev->histogram_type == DT_DEV_HISTOGRAM_WAVEFORM)
dt_draw_waveform_lines(cr, 0, 0, width, height);
else
dt_draw_grid(cr, 4, 0, 0, width, height);
if(hist_max > 0.0f)
{
cairo_save(cr);
if(dev->histogram_type == DT_DEV_HISTOGRAM_WAVEFORM)
//.........这里部分代码省略.........
开发者ID:dtorop,项目名称:darktable,代码行数:101,代码来源:histogram.c
示例8: column_triangles
static cairo_test_status_t
column_triangles (cairo_t *cr, int width, int height)
{
int x, y, i, channel;
state = 0x12345678;
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
cairo_paint (cr);
#if GENERATE_REFERENCE
for (x = 0; x < WIDTH; x++) {
cairo_set_source_rgba (cr, 1, 1, 1, x * 0.5 / WIDTH);
cairo_rectangle (cr, x, 0, 1, HEIGHT);
cairo_fill (cr);
}
#else
cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
for (channel = 0; channel < 3; channel++) {
switch (channel) {
default:
case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
}
for (x = 0; x < WIDTH; x++) {
double step = x / (double) (2 * WIDTH);
for (y = 0; y < HEIGHT; y++) {
for (i = 0; i < PRECISION; i++) {
double dy = random_offset (WIDTH - x, FALSE);
/*
* We want to test some sharing of edges to further
* stress the rasterisers, so instead of using one
* tall triangle, it is split into two, with vertical
* edges on either side that may co-align with their
* neighbours:
*
* s --- . ---
* t | |\ |
* e | | \ |
* p --- .... | 2 * step = x / WIDTH
* \ | |
* \| |
* . ---
* |---|
* 1 / PRECISION
*
* Each column contains two triangles of width one quantum and
* total height of (x / WIDTH), thus the total area covered by all
* columns in each pixel is .5 * (x / WIDTH).
*/
cairo_move_to (cr, x + i / (double) PRECISION, y + dy);
cairo_rel_line_to (cr, 0, step);
cairo_rel_line_to (cr, 1 / (double) PRECISION, step);
cairo_rel_line_to (cr, 0, -step);
cairo_close_path (cr);
}
cairo_fill (cr); /* do these per-pixel due to the extra volume of edges */
}
}
}
#endif
return CAIRO_TEST_SUCCESS;
}
开发者ID:AZed,项目名称:cairo,代码行数:68,代码来源:coverage.c
示例9: eom_print_preview_draw
static void
eom_print_preview_draw (EomPrintPreview *preview, cairo_t *cr)
{
EomPrintPreviewPrivate *priv;
GtkWidget *area;
GtkAllocation allocation;
gint x0, y0;
GtkStyle *style;
gboolean has_focus;
priv = preview->priv;
area = priv->area;
has_focus = gtk_widget_has_focus (area);
style = gtk_widget_get_style (area);
gtk_widget_get_allocation (area, &allocation);
/* draw the page */
gdk_cairo_set_source_color (cr, &style->white);
cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
cairo_fill (cr);
/* draw the page margins */
gdk_cairo_set_source_color (cr, &style->black);
cairo_set_line_width (cr, 0.1);
cairo_rectangle (cr,
priv->l_rmargin, priv->t_rmargin,
allocation.width - priv->l_rmargin - priv->r_rmargin,
allocation.height - priv->t_rmargin - priv->b_rmargin);
cairo_stroke (cr);
get_current_image_coordinates (preview, &x0, &y0);
if (priv->flag_create_surface) {
create_surface (preview);
}
if (priv->surface) {
cairo_set_source_surface (cr, priv->surface, x0, y0);
cairo_paint (cr);
} else if (priv->image_scaled) {
/* just in the remote case we don't have the surface */
/* adjust (x0, y0) to the new scale */
gdouble scale = priv->i_scale * priv->p_scale *
gdk_pixbuf_get_width (priv->image) / gdk_pixbuf_get_width (priv->image_scaled);
x0 /= scale;
y0 /= scale;
cairo_scale (cr, scale, scale);
gdk_cairo_set_source_pixbuf (cr, priv->image_scaled, x0, y0);
cairo_paint (cr);
} else if (priv->image) {
/* just in the remote case we don't have the surface */
/* adjust (x0, y0) to the new scale */
x0 /= priv->i_scale * priv->p_scale;
y0 /= priv->i_scale * priv->p_scale;
cairo_scale (cr, priv->i_scale*priv->p_scale, priv->i_scale*priv->p_scale);
gdk_cairo_set_source_pixbuf (cr, priv->image, x0, y0);
cairo_paint (cr);
}
if (has_focus) {
gtk_paint_focus (style, gtk_widget_get_window (area),
GTK_STATE_NORMAL, NULL, NULL, NULL,
0, 0, allocation.width, allocation.height);
}
}
开发者ID:steev,项目名称:mate-image-viewer,代码行数:72,代码来源:eom-print-preview.c
示例10: ags_note_edit_draw_position
/**
* ags_note_edit_draw_position:
* @note_edit: the #AgsNoteEdit
* @cr: the #cairo_t surface
*
* Draws the cursor.
*
* Since: 0.4
*/
void
ags_note_edit_draw_position(AgsNoteEdit *note_edit, cairo_t *cr)
{
guint selected_x, selected_y;
guint x_offset[2], y_offset[2];
guint x, y, width, height;
gint size_width, size_height;
selected_x = note_edit->selected_x * note_edit->control_unit.control_width;
selected_y = note_edit->selected_y * note_edit->control_height;
size_width = GTK_WIDGET(note_edit->drawing_area)->allocation.width;
size_height = GTK_WIDGET(note_edit->drawing_area)->allocation.height;
x_offset[0] = (guint) gtk_range_get_value(GTK_RANGE(note_edit->hscrollbar));
x_offset[1] = x_offset[0] + (guint) size_width;
y_offset[0] = (guint) gtk_range_get_value(GTK_RANGE(note_edit->vscrollbar));
y_offset[1] = y_offset[0] + (guint) size_height;
/* calculate horizontally values */
if(selected_x < x_offset[0]){
if(selected_x + note_edit->control_current.control_width > x_offset[0]){
x = 0;
width = selected_x + note_edit->control_current.control_width - x_offset[0];
}else{
return;
}
}else if(selected_x > x_offset[1]){
return;
}else{
x = selected_x - x_offset[0];
if(selected_x + note_edit->control_current.control_width < x_offset[1]){
width = note_edit->control_current.control_width;
}else{
width = x_offset[1] - (selected_x + note_edit->control_current.control_width);
}
}
/* calculate vertically values */
if(selected_y < y_offset[0]){
if(selected_y + note_edit->control_height > y_offset[0]){
y = 0;
height = selected_y + note_edit->control_height - y_offset[0];
}else{
return;
}
}else if(selected_y > y_offset[1]){
return;
}else{
y = selected_y - y_offset[0];
if(selected_y + note_edit->control_height < y_offset[1]){
height = note_edit->control_height;
}else{
height = y_offset[1] - (selected_y + note_edit->control_height);
}
}
/* draw */
cairo_set_source_rgba(cr, 0.25, 0.5, 1.0, 0.5);
cairo_rectangle(cr, (double) x, (double) y, (double) width, (double) height);
cairo_fill(cr);
}
开发者ID:paynedaddy24,项目名称:gsequencer,代码行数:74,代码来源:ags_note_edit.c
示例11: ags_note_edit_draw_notation
/**
* ags_note_edit_draw_notation:
* @note_edit: the #AgsNoteEdit
* @cr: the #cairo_t surface
*
* Draw the #AgsNotation of selected #AgsMachine on @note_edit.
*
* Since: 0.4
*/
void
ags_note_edit_draw_notation(AgsNoteEdit *note_edit, cairo_t *cr)
{
AgsMachine *machine;
AgsEditor *editor;
GtkWidget *widget;
AgsNote *note;
GList *list_notation, *list_note;
guint x_offset;
guint control_height;
guint x, y, width, height;
gint selected_channel;
gint i;
editor = (AgsEditor *) gtk_widget_get_ancestor(GTK_WIDGET(note_edit),
AGS_TYPE_EDITOR);
if(editor->selected_machine == NULL ||
(machine = editor->selected_machine) == NULL ||
machine->audio->notation == NULL)
return;
widget = (GtkWidget *) note_edit->drawing_area;
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
i = 0;
while((selected_channel = ags_notebook_next_active_tab(editor->notebook,
i)) != -1){
list_notation = g_list_nth(machine->audio->notation,
selected_channel);
list_note = AGS_NOTATION(list_notation->data)->notes;
control_height = note_edit->control_height - 2 * note_edit->control_margin_y;
x_offset = (guint) GTK_RANGE(note_edit->hscrollbar)->adjustment->value;
/* draw controls smaller than note_edit->nth_x */
while(list_note != NULL && (note = (AgsNote *) list_note->data)->x[0] < note_edit->control_unit.nth_x){
if(note->x[1] >= note_edit->control_unit.nth_x){
if(note->y >= note_edit->nth_y && note->y <= note_edit->stop_y){
x = 0;
y = (note->y - note_edit->nth_y) * note_edit->control_height + note_edit->y0 + note_edit->control_margin_y;
width = (guint) ((double) note->x[1] * note_edit->control_unit.control_width - (double) x_offset);
if(width > widget->allocation.width)
width = widget->allocation.width;
height = control_height;
/* draw note */
cairo_rectangle(cr, (double) x, (double) y, (double) width, (double) height);
cairo_fill(cr);
/* check if note is selected */
if((AGS_NOTE_IS_SELECTED & (note->flags)) != 0){
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.7);
cairo_rectangle(cr, (double) x, (double) y, (double) width, (double) height);
cairo_stroke(cr);
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
}
}else if(note->y == (note_edit->nth_y - 1) && note_edit->y0 != 0){
if(note_edit->y0 > note_edit->control_margin_y){
x = 0;
width = (guint) ((double) note->x[1] * (double) note_edit->control_unit.control_width - x_offset);
if(width > widget->allocation.width)
width = widget->allocation.width;
if(note_edit->y0 > control_height + note_edit->control_margin_y){
y = note_edit->y0 - (control_height + note_edit->control_margin_y);
height = control_height;
}else{
y = 0;
height = note_edit->y0 - note_edit->control_margin_y;
}
/* draw note */
cairo_rectangle(cr, (double) x, (double) y, (double) width, (double) height);
cairo_fill(cr);
/* check if note is selected */
if((AGS_NOTE_IS_SELECTED & (note->flags)) != 0){
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.7);
cairo_rectangle(cr, (double) x, (double) y, (double) width, (double) height);
cairo_stroke(cr);
//.........这里部分代码省略.........
开发者ID:paynedaddy24,项目名称:gsequencer,代码行数:101,代码来源:ags_note_edit.c
示例12: ags_note_edit_draw_segment
/**
* ags_note_edit_draw_segment:
* @note_edit: the #AgsNoteEdit
* @cr: the #cairo_t surface
*
* Draws horizontal and vertical lines.
*
* Since: 0.4
*/
void
ags_note_edit_draw_segment(AgsNoteEdit *note_edit, cairo_t *cr)
{
AgsEditor *editor;
GtkWidget *widget;
double tact;
guint i, j;
guint j_set;
widget = (GtkWidget *) note_edit->drawing_area;
editor = (AgsEditor *) gtk_widget_get_ancestor(GTK_WIDGET(note_edit),
AGS_TYPE_EDITOR);
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
cairo_rectangle(cr, 0.0, 0.0, (double) widget->allocation.width, (double) widget->allocation.height);
cairo_fill(cr);
cairo_set_line_width(cr, 1.0);
cairo_set_source_rgb(cr, 0.8, 0.8, 0.8);
for(i = note_edit->y0 ; i < note_edit->height;){
cairo_move_to(cr, 0.0, (double) i);
cairo_line_to(cr, (double) note_edit->width, (double) i);
cairo_stroke(cr);
i += note_edit->control_height;
}
cairo_move_to(cr, 0.0, (double) i);
cairo_line_to(cr, (double) note_edit->width, (double) i);
cairo_stroke(cr);
tact = exp2((double) gtk_combo_box_get_active(editor->toolbar->zoom) - 4.0);
i = note_edit->control_current.x0;
if(i < note_edit->width &&
tact > 1.0 ){
j_set = note_edit->control_current.nth_x % ((guint) tact);
cairo_set_source_rgb(cr, 0.6, 0.6, 0.6);
if(j_set != 0){
j = j_set;
goto ags_note_edit_draw_segment0;
}
}
for(; i < note_edit->width; ){
cairo_set_source_rgb(cr, 1.0, 1.0, 0.0);
cairo_move_to(cr, (double) i, 0.0);
cairo_line_to(cr, (double) i, (double) note_edit->height);
cairo_stroke(cr);
i += note_edit->control_current.control_width;
cairo_set_source_rgb(cr, 0.6, 0.6, 0.6);
for(j = 1; i < note_edit->width && j < tact; j++){
ags_note_edit_draw_segment0:
cairo_move_to(cr, (double) i, 0.0);
cairo_line_to(cr, (double) i, (double) note_edit->height);
cairo_stroke(cr);
i += note_edit->control_current.control_width;
}
}
}
开发者ID:paynedaddy24,项目名称:gsequencer,代码行数:80,代码来源:ags_note_edit.c
示例13: dt_iop_basecurve_expose
static gboolean
dt_iop_basecurve_expose(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
{
dt_iop_module_t *self = (dt_iop_module_t *)user_data;
dt_iop_basecurve_gui_data_t *c = (dt_iop_basecurve_gui_data_t *)self->gui_data;
dt_iop_basecurve_params_t *p = (dt_iop_basecurve_params_t *)self->params;
int nodes = p->basecurve_nodes[0];
dt_iop_basecurve_node_t *basecurve = p->basecurve[0];
if(c->minmax_curve_type != p->basecurve_type[0] || c->minmax_curve_nodes != p->basecurve_nodes[0])
{
dt_draw_curve_destroy(c->minmax_curve);
c->minmax_curve = dt_draw_curve_new(0.0, 1.0, p->basecurve_type[0]);
c->minmax_curve_nodes = p->basecurve_nodes[0];
c->minmax_curve_type = p->basecurve_type[0];
for(int k=0; k<p->basecurve_nodes[0]; k++)
(void)dt_draw_curve_add_point(c->minmax_curve, p->basecurve[0][k].x, p->basecurve[0][k].y);
}
else
{
for(int k=0; k<p->basecurve_nodes[0]; k++)
dt_draw_curve_set_point(c->minmax_curve, k, p->basecurve[0][k].x, p->basecurve[0][k].y);
}
dt_draw_curve_t *minmax_curve = c->minmax_curve;
dt_draw_curve_calc_values(minmax_curve, 0.0, 1.0, DT_IOP_TONECURVE_RES, c->draw_xs, c->draw_ys);
const float xm = basecurve[nodes-1].x;
const float x[4] = {0.7f*xm, 0.8f*xm, 0.9f*xm, 1.0f*xm};
const float y[4] = {c->draw_ys[CLAMP((int)(x[0]*DT_IOP_TONECURVE_RES), 0, DT_IOP_TONECURVE_RES-1)],
c->draw_ys[CLAMP((int)(x[1]*DT_IOP_TONECURVE_RES), 0, DT_IOP_TONECURVE_RES-1)],
c->draw_ys[CLAMP((int)(x[2]*DT_IOP_TONECURVE_RES), 0, DT_IOP_TONECURVE_RES-1)],
c->draw_ys[CLAMP((int)(x[3]*DT_IOP_TONECURVE_RES), 0, DT_IOP_TONECURVE_RES-1)]
};
float unbounded_coeffs[3];
dt_iop_estimate_exp(x, y, 4, unbounded_coeffs);
const int inset = DT_GUI_CURVE_EDITOR_INSET;
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
int width = allocation.width, height = allocation.height;
cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cairo_t *cr = cairo_create(cst);
// clear bg
cairo_set_source_rgb (cr, .2, .2, .2);
cairo_paint(cr);
cairo_translate(cr, inset, inset);
width -= 2*inset;
height -= 2*inset;
#if 0
// draw shadow around
float alpha = 1.0f;
for(int k=0; k<inset; k++)
{
cairo_rectangle(cr, -k, -k, width + 2*k, height + 2*k);
cairo_set_source_rgba(cr, 0, 0, 0, alpha);
alpha *= 0.6f;
cairo_fill(cr);
}
#else
cairo_set_line_width(cr, 1.0);
cairo_set_source_rgb (cr, .1, .1, .1);
cairo_rectangle(cr, 0, 0, width, height);
cairo_stroke(cr);
#endif
cairo_set_source_rgb (cr, .3, .3, .3);
cairo_rectangle(cr, 0, 0, width, height);
cairo_fill(cr);
cairo_translate(cr, 0, height);
cairo_scale(cr, 1.0f, -1.0f);
// draw grid
cairo_set_line_width(cr, .4);
cairo_set_source_rgb (cr, .1, .1, .1);
if(c->loglogscale)
dt_draw_loglog_grid(cr, 4, 0, 0, width, height, c->loglogscale);
else
dt_draw_grid(cr, 4, 0, 0, width, height);
// draw nodes positions
cairo_set_line_width(cr, 1.);
cairo_set_source_rgb(cr, 0.6, 0.6, 0.6);
for(int k=0; k<nodes; k++)
{
const float x = to_log(basecurve[k].x, c->loglogscale), y = to_log(basecurve[k].y, c->loglogscale);
cairo_arc(cr, x*width, y*height, 3, 0, 2.*M_PI);
cairo_stroke(cr);
}
// draw selected cursor
cairo_set_line_width(cr, 1.);
if(c->selected >= 0)
{
cairo_set_source_rgb(cr, .9, .9, .9);
const float x = to_log(basecurve[c->selected].x, c->loglogscale), y = to_log(basecurve[c->selected].y, c->loglogscale);
cairo_arc(cr, x*width, y*height, 4, 0, 2.*M_PI);
//.........这里部分代码省略.........
开发者ID:angryziber,项目名称:darktable,代码行数:101,代码来源:basecurve.c
示例14: begin_render
/*
* render functions
*/
static void
begin_render(DiaRenderer *self, const Rectangle *update)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
real onedu = 0.0;
real lmargin = 0.0, tmargin = 0.0;
gboolean paginated = renderer->surface && /* only with our own pagination, not GtkPrint */
cairo_surface_get_type (renderer->surface) == CAIRO_SURFACE_TYPE_PDF && !renderer->skip_show_page;
if (renderer->surface && !renderer->cr)
renderer->cr = cairo_create (renderer->surface);
else
g_assert (renderer->cr);
/* remember current state, so we can start from new with every page */
cairo_save (renderer->cr);
if (paginated && renderer->dia) {
DiagramData *data = renderer->dia;
/* Dia's paper.width already contains the scale, cairo needs it without
* Similar for margins, Dia's without, but cairo wants them?
*/
real width = (data->paper.lmargin + data->paper.width * data->paper.scaling + data->paper.rmargin)
* (72.0 / 2.54) + 0.5;
real height = (data->paper.tmargin + data->paper.height * data->paper.scaling + data->paper.bmargin)
* (72.0 / 2.54) + 0.5;
/* "Changes the size of a PDF surface for the current (and
* subsequent) pages." Pagination setup? */
cairo_pdf_surface_set_size (renderer->surface, width, height);
lmargin = data->paper.lmargin / data->paper.scaling;
tmargin = data->paper.tmargin / data->paper.scaling;
}
cairo_scale (renderer->cr, renderer->scale, renderer->scale);
/* to ensure no clipping at top/left we need some extra gymnastics,
* otherwise a box with a line witdh one one pixel might loose the
* top/left border as in bug #147386 */
ensure_minimum_one_device_unit (renderer, &onedu);
if (update && paginated) {
cairo_rectangle (renderer->cr, lmargin, tmargin,
update->right - update->left, update->bottom - update->top);
cairo_clip (renderer->cr);
cairo_translate (renderer->cr, -update->left + lmargin, -update->top + tmargin);
} else
cairo_translate (renderer->cr, -renderer->dia->extents.left + onedu, -renderer->dia->extents.top + onedu);
/* no more blurred UML diagrams */
cairo_set_antialias (renderer->cr, CAIRO_ANTIALIAS_NONE);
/* clear background */
if (renderer->with_alpha)
{
cairo_set_operator (renderer->cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgba (renderer->cr,
renderer->dia->bg_color.red,
renderer->dia->bg_color.green,
renderer->dia->bg_color.blue,
0.0);
}
else
{
cairo_set_source_rgba (renderer->cr,
renderer->dia->bg_color.red,
renderer->dia->bg_color.green,
renderer->dia->bg_color.blue,
1.0);
}
cairo_paint (renderer->cr);
if (renderer->with_alpha)
{
/* restore to default drawing */
cairo_set_operator (renderer->cr, CAIRO_OPERATOR_OVER);
cairo_set_source_rgba (renderer->cr,
renderer->dia->bg_color.red,
renderer->dia->bg_color.green,
renderer->dia->bg_color.blue,
1.0);
}
#ifdef HAVE_PANGOCAIRO_H
if (!renderer->layout)
renderer->layout = pango_cairo_create_layout (renderer->cr);
#endif
cairo_set_fill_rule (renderer->cr, CAIRO_FILL_RULE_EVEN_ODD);
#if 0 /* try to work around bug #341481 - no luck */
{
cairo_font_options_t *fo = cairo_font_options_create ();
cairo_get_font_options (renderer->cr, fo);
/* try to switch off kerning */
cairo_font_options_set_hint_style (fo, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_hint_metrics (fo, CAIRO_HINT_METRICS_OFF);
cairo_set_font_options (renderer->cr, fo);
cairo_font_options_destroy (fo);
#ifdef HAVE_PANGOCAIRO_H
pango_cairo_update_context (renderer->cr, pango_layout_get_context (renderer->layout));
//.........这里部分代码省略.........
开发者ID:trilomix,项目名称:dia,代码行数:101,代码来源:diacairo-renderer.c
示例15: gst_buffer_get_caps
void MediaPlayerPrivate::paint(GraphicsContext* context, const IntRect& rect)
{
if (context->paintingDisabled())
return;
if (!m_visible)
return;
if (!m_buffer)
return;
int width = 0, height = 0;
int pixelAspectRatioNumerator = 0;
int pixelAspectRatioDenominator = 0;
double doublePixelAspectRatioNumerator = 0;
double doublePixelAspectRatioDenominator = 0;
double displayWidth;
double displayHeight;
double scale, gapHeight, gapWidth;
GstCaps *caps = gst_buffer_get_caps(m_buffer);
if (!gst_video_format_parse_caps(caps, NULL, &width, &height) ||
!gst_video_parse_caps_pixel_aspect_ratio(caps, &pixelAspectRatioNumerator, &pixelAspectRatioDenominator)) {
gst_caps_unref(caps);
return;
}
displayWidth = width;
displayHeight = height;
doublePixelAspectRatioNumerator = pixelAspectRatioNumerator;
doublePixelAspectRatioDenominator = pixelAspectRatioDenominator;
cairo_t* cr = context->platformContext();
cairo_surface_t* src = cairo_image_surface_create_for_data(GST_BUFFER_DATA(m_buffer),
|
请发表评论