本文整理汇总了C++中cairo_surface_create_similar函数的典型用法代码示例。如果您正苦于以下问题:C++ cairo_surface_create_similar函数的具体用法?C++ cairo_surface_create_similar怎么用?C++ cairo_surface_create_similar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cairo_surface_create_similar函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
size_t i = 0;
cairo_operator_t op;
cairo_t *bgcr, *fgcr;
cairo_surface_t *bg, *fg;
bg = cairo_surface_create_similar (cairo_get_target (cr),
CAIRO_CONTENT_COLOR_ALPHA, SIZE * STEPS, SIZE * STEPS);
fg = cairo_surface_create_similar (cairo_get_target (cr),
CAIRO_CONTENT_COLOR_ALPHA, SIZE * STEPS, SIZE * STEPS);
bgcr = cairo_create (bg);
fgcr = cairo_create (fg);
cairo_scale (bgcr, SIZE, SIZE);
cairo_scale (fgcr, SIZE, SIZE);
create_patterns (bgcr, fgcr);
cairo_destroy (bgcr);
cairo_destroy (fgcr);
for (op = START_OPERATOR; op <= STOP_OPERATOR; op++, i++) {
cairo_save (cr);
cairo_translate (cr,
SIZE * (STEPS + 1) * (i % COUNT),
SIZE * (STEPS + 1) * (i / COUNT));
do_blend (cr, op, bg, fg);
cairo_restore (cr);
}
cairo_surface_destroy (fg);
cairo_surface_destroy (bg);
return CAIRO_TEST_SUCCESS;
}
示例2: subdraw
static void
subdraw (cairo_t *cr, int width, int height)
{
size_t i = 0;
cairo_operator_t op;
cairo_t *bgcr, *fgcr;
cairo_surface_t *bg, *fg;
bg = cairo_surface_create_similar (cairo_get_target (cr),
CAIRO_CONTENT_COLOR_ALPHA, SIZE * STEPS, SIZE * STEPS);
fg = cairo_surface_create_similar (cairo_get_target (cr),
CAIRO_CONTENT_COLOR_ALPHA, SIZE * STEPS, SIZE * STEPS);
bgcr = cairo_create (bg);
fgcr = cairo_create (fg);
cairo_scale (bgcr, SIZE, SIZE);
cairo_scale (fgcr, SIZE, SIZE);
create_patterns (bgcr, fgcr);
cairo_destroy (bgcr);
cairo_destroy (fgcr);
for (op = START_OPERATOR; op <= STOP_OPERATOR; op++, i++) {
cairo_save (cr);
cairo_translate (cr,
SIZE * (STEPS + 1) * (i % COUNT),
SIZE * (STEPS + 1) * (i / COUNT));
cairo_rectangle (cr, 0, 0, SIZE * (STEPS + 1), SIZE * (STEPS+1));
cairo_clip (cr);
do_composite (cr, op, bg, fg);
cairo_restore (cr);
}
cairo_surface_destroy (fg);
cairo_surface_destroy (bg);
}
示例3: paint_window
static void paint_window(GtkWidget* widget, WindowData* windata)
{
cairo_t* context;
cairo_surface_t* surface;
cairo_t* cr;
if (windata->width == 0 || windata->height == 0)
{
#if GTK_CHECK_VERSION(3, 0, 0)
GtkAllocation allocation;
gtk_widget_get_allocation(windata->win, &allocation);
windata->width = MAX(allocation.width, 1);
windata->height = MAX(allocation.height, 1);
#else
windata->width = MAX(windata->win->allocation.width, 1);
windata->height = MAX(windata->win->allocation.height, 1);
#endif
}
context = gdk_cairo_create(widget->window);
cairo_set_operator(context, CAIRO_OPERATOR_SOURCE);
#if GTK_CHECK_VERSION(3, 0, 0)
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
surface = cairo_surface_create_similar(cairo_get_target(context), CAIRO_CONTENT_COLOR_ALPHA, allocation.width, allocation.height);
#else
surface = cairo_surface_create_similar(cairo_get_target(context), CAIRO_CONTENT_COLOR_ALPHA, widget->allocation.width, widget->allocation.height);
#endif
cr = cairo_create(surface);
fill_background(widget, windata, cr);
cairo_destroy(cr);
cairo_set_source_surface(context, surface, 0, 0);
cairo_paint(context);
cairo_surface_destroy(surface);
cairo_destroy(context);
update_shape(windata);
}
示例4: _similar_surface_create
static cairo_surface_t *
_similar_surface_create (void *closure,
cairo_content_t content,
double width,
double height,
long uid)
{
cairo_surface_t *surface;
struct scache skey, *s;
if (uid == 0 || surface_cache == NULL)
return cairo_surface_create_similar (closure, content, width, height);
skey.entry.hash = uid;
s = _cairo_hash_table_lookup (surface_cache, &skey.entry);
if (s != NULL) {
if (s->content == content &&
s->width == width &&
s->height == height)
{
return cairo_surface_reference (s->surface);
}
/* The surface has been resized, allow the original entry to expire
* as it becomes inactive.
*/
}
surface = cairo_surface_create_similar (closure, content, width, height);
s = malloc (sizeof (struct scache));
if (s == NULL)
return surface;
s->entry.hash = uid;
s->content = content;
s->width = width;
s->height = height;
s->surface = surface;
if (_cairo_hash_table_insert (surface_cache, &s->entry)) {
free (s);
} else if (cairo_surface_set_user_data
(surface,
(const cairo_user_data_key_t *) &surface_cache,
s, scache_remove))
{
scache_remove (s);
}
return surface;
}
示例5: void
/* cache buttons as small surfaces */
static cairo_surface_t *cache_button(Gameboard *g,
void (*draw)(cairo_t *c,
double x,
double y),
double pR,double pG,double pB,double pA,
double fR,double fG,double fB,double fA){
cairo_t *wc = gdk_cairo_create(g->w.window);
cairo_surface_t *ret =
cairo_surface_create_similar (cairo_get_target (wc),
CAIRO_CONTENT_COLOR_ALPHA,
BUTTON_RADIUS*2+1,
BUTTON_RADIUS*2+1);
cairo_t *c = cairo_create(ret);
cairo_destroy (wc);
cairo_save(c);
cairo_set_operator(c,CAIRO_OPERATOR_CLEAR);
cairo_set_source_rgba (c, 1,1,1,1);
cairo_paint(c);
cairo_restore(c);
cairo_set_source_rgba(c,fR,fG,fB,fA);
cairo_set_line_width(c,BUTTON_LINE_WIDTH);
draw(c,BUTTON_RADIUS+.5,BUTTON_RADIUS+.5);
cairo_set_source_rgba(c,pR,pG,pB,pA);
cairo_stroke(c);
cairo_destroy(c);
return ret;
}
示例6: cairo_image_surface_get_width
/* Scale the surface with the width and height requested */
cairo_surface_t *
scale_surface (cairo_surface_t *surface,
gdouble width,
gdouble height)
{
gdouble old_width = cairo_image_surface_get_width (surface);
gdouble old_height = cairo_image_surface_get_height (surface);
cairo_surface_t *new_surface = cairo_surface_create_similar(surface, CAIRO_CONTENT_COLOR_ALPHA, width, height);
cairo_t *cr = cairo_create (new_surface);
/* Scale *before* setting the source surface (1) */
cairo_scale (cr, width / old_width, height / old_height);
cairo_set_source_surface (cr, surface, 0, 0);
/* To avoid getting the edge pixels blended with 0 alpha, which would
* occur with the default EXTEND_NONE. Use EXTEND_PAD for 1.2 or newer (2)
*/
cairo_pattern_set_extend (cairo_get_source(cr), CAIRO_EXTEND_REFLECT);
/* Replace the destination with the source instead of overlaying */
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
/* Do the actual drawing */
cairo_paint (cr);
cairo_destroy (cr);
return new_surface;
}
示例7: resize_window
/**
* windows resize funtion
*/
static gboolean
resize_window (GtkWidget *widget,
GdkEventMotion *mev)
{
int w,h;
if(isFullSreen)
gdk_window_get_size(widget->window,&w,&h);
else {
w = DEFAULT_WIDTH;
h = DEFAULT_HEIGHT;
}
if(w!=window_w && h!=window_h){
window_w = w;
window_h = h;
surface = cairo_surface_create_similar (
surface,
CAIRO_CONTENT_COLOR_ALPHA,
w, h);
gtk_widget_set_size_request(widget,w,h);
CleanPaint();
}
/* tell the canvas widget that it needs to redraw itself */
gtk_widget_queue_draw (widget);
return FALSE;
}
示例8: configure_cb
static gboolean configure_cb (GtkWidget *widget,
GdkEventConfigure *evt, gpointer user_data) {
canvasbacken_data_t *data = user_data;
assert (data);
int w = gtk_widget_get_allocated_width (widget);
int h = gtk_widget_get_allocated_height (widget);
if (data->track)
cairo_surface_destroy (data->track);
data->track = gdk_window_create_similar_surface (
gtk_widget_get_window (widget),
CAIRO_CONTENT_COLOR_ALPHA,
w, h);
clear_surface (data->track);
if (data->surf)
cairo_surface_destroy (data->surf);
data->surf = cairo_surface_create_similar (
data->track,
CAIRO_CONTENT_COLOR_ALPHA,
w, h);
clear_surface (data->surf);
canvas_draw (data);
gtk_widget_queue_draw (widget);
return TRUE;
}
示例9: draw_mask
static void
draw_mask (cairo_t *cr, int x, int y)
{
cairo_surface_t *mask_surface;
cairo_t *cr2;
double width = (int)(0.9 * WIDTH);
double height = (int)(0.9 * HEIGHT);
x += 0.05 * WIDTH;
y += 0.05 * HEIGHT;
mask_surface = cairo_surface_create_similar (cairo_get_group_target (cr),
CAIRO_CONTENT_ALPHA,
width, height);
cr2 = cairo_create (mask_surface);
cairo_surface_destroy (mask_surface);
cairo_save (cr2);
cairo_set_source_rgba (cr2, 0, 0, 0, 0); /* transparent */
cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE);
cairo_paint (cr2);
cairo_restore (cr2);
cairo_set_source_rgb (cr2, 1, 1, 1); /* white */
cairo_arc (cr2, 0.5 * width, 0.5 * height, 0.45 * height, 0, 2 * M_PI);
cairo_fill (cr2);
cairo_mask_surface (cr, cairo_get_target (cr2), x, y);
cairo_destroy (cr2);
}
示例10: ink_cairo_surface_create_same_size
cairo_surface_t *
ink_cairo_surface_create_same_size(cairo_surface_t *s, cairo_content_t c)
{
cairo_surface_t *ns = cairo_surface_create_similar(s, c,
ink_cairo_surface_get_width(s), ink_cairo_surface_get_height(s));
return ns;
}
示例11: seed_cairo_surface_create_similar
static SeedValue
seed_cairo_surface_create_similar (SeedContext ctx,
SeedObject function,
SeedObject this_object,
gsize argument_count,
const SeedValue arguments[],
SeedException *exception)
{
gint width, height;
cairo_surface_t *surface, *ret;
cairo_content_t content;
CHECK_THIS();
if (argument_count != 3)
{
EXPECTED_EXCEPTION("create_similar", "3 arguments");
}
surface = seed_object_to_cairo_surface (ctx, this_object, exception);
if (!surface)
return seed_make_undefined (ctx);
content = seed_value_to_long (ctx, arguments[0], exception);
width = seed_value_to_int (ctx, arguments[1], exception);
height = seed_value_to_int (ctx, arguments[2], exception);
ret = cairo_surface_create_similar (surface, content, width, height);
return seed_object_from_cairo_surface (ctx, ret);
}
示例12: scale_icon
static inline cairo_surface_t *
scale_icon (cairo_surface_t *icon,
double width,
double height)
{
cairo_surface_t *scaled_icon;
cairo_t *cr;
scaled_icon = cairo_surface_create_similar (icon,
cairo_surface_get_content (icon),
THUMBNAIL_WIDTH,
THUMBNAIL_HEIGHT);
cr = cairo_create (scaled_icon);
cairo_scale (cr,
THUMBNAIL_WIDTH / width,
THUMBNAIL_HEIGHT / height);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_surface (cr,
icon,
0.0,
0.0);
cairo_paint (cr);
cairo_destroy (cr);
return scaled_icon;
}
示例13: exit
mWindow::mWindow() {
looping = false;
if (!(display = XOpenDisplay(NULL)))
exit(1);
screenID = DefaultScreen(display);
topWin = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0,
winWidth, winHeight, 0, 100, 0xfffacd);
XSelectInput(display, topWin,
ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask
| PointerMotionMask | StructureNotifyMask | ExposureMask);
frontSurface = cairo_xlib_surface_create(display, topWin,
DefaultVisual(display, screenID), winWidth, winHeight);
frontContext = cairo_create(frontSurface);
GUI_surface = cairo_surface_create_similar(cairo_get_target(frontContext),
CAIRO_CONTENT_COLOR_ALPHA, winWidth, winHeight);
// MAP_surface = cairo_surface_create_similar(cairo_get_target(frontContext),
// CAIRO_CONTENT_COLOR_ALPHA, winWidth, winHeight);
GUI_context = cairo_create(GUI_surface);
//MAP_context = cairo_create(MAP_surface);
Gmanager = new GUIManager(GUI_context);
eventDispatcher = new EventDispatcher(winWidth, winHeight);
Gmanager->registerEventDispatcher(eventDispatcher,
eventDispatcher->getGUImap());
eventDispatcher->registerGUImanager(Gmanager);
animator = new Animator();
Animatable::animator = animator;
}
示例14: set_surface_pattern
static void
set_surface_pattern (cairo_t *cr, int x, int y)
{
cairo_surface_t *source_surface;
cairo_t *cr2;
double width = (int)(0.6 * WIDTH);
double height = (int)(0.6 * HEIGHT);
x += 0.2 * WIDTH;
y += 0.2 * HEIGHT;
source_surface = cairo_surface_create_similar (cairo_get_group_target (cr),
CAIRO_CONTENT_COLOR_ALPHA,
width, height);
cr2 = cairo_create (source_surface);
cairo_surface_destroy (source_surface);
cairo_set_source_rgb (cr2, 1, 0, 0); /* red */
cairo_paint (cr2);
cairo_set_source_rgb (cr2, 1, 1, 1); /* white */
cairo_arc (cr2, 0.5 * width, 0.5 * height, 0.5 * height, 0, 2 * M_PI);
cairo_fill (cr2);
cairo_set_source_surface (cr, cairo_get_target (cr2), x, y);
cairo_destroy (cr2);
}
示例15: _gtk_css_image_get_surface
cairo_surface_t *
_gtk_css_image_get_surface (GtkCssImage *image,
cairo_surface_t *target,
int surface_width,
int surface_height)
{
cairo_surface_t *result;
cairo_t *cr;
g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), NULL);
g_return_val_if_fail (surface_width > 0, NULL);
g_return_val_if_fail (surface_height > 0, NULL);
if (target)
result = cairo_surface_create_similar (target,
CAIRO_CONTENT_COLOR_ALPHA,
surface_width,
surface_height);
else
result = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
surface_width,
surface_height);
cr = cairo_create (result);
_gtk_css_image_draw (image, cr, surface_width, surface_height);
cairo_destroy (cr);
return result;
}