本文整理汇总了C++中cairo_image_surface_create函数的典型用法代码示例。如果您正苦于以下问题:C++ cairo_image_surface_create函数的具体用法?C++ cairo_image_surface_create怎么用?C++ cairo_image_surface_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cairo_image_surface_create函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: __guac_terminal_set
/**
* Sends the given character to the terminal at the given row and column,
* rendering the character immediately. This bypasses the guac_terminal_display
* mechanism and is intended for flushing of updates only.
*/
int __guac_terminal_set(guac_terminal_display* display, int row, int col, int codepoint) {
int width;
int bytes;
char utf8[4];
/* Use foreground color */
const guac_terminal_color* color = &display->glyph_foreground;
/* Use background color */
const guac_terminal_color* background = &display->glyph_background;
cairo_surface_t* surface;
cairo_t* cairo;
int surface_width, surface_height;
PangoLayout* layout;
int layout_width, layout_height;
int ideal_layout_width, ideal_layout_height;
/* Calculate width in columns */
width = wcwidth(codepoint);
if (width < 0)
width = 1;
/* Do nothing if glyph is empty */
if (width == 0)
return 0;
/* Convert to UTF-8 */
bytes = guac_terminal_encode_utf8(codepoint, utf8);
surface_width = width * display->char_width;
surface_height = display->char_height;
ideal_layout_width = surface_width * PANGO_SCALE;
ideal_layout_height = surface_height * PANGO_SCALE;
/* Prepare surface */
surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24,
surface_width, surface_height);
cairo = cairo_create(surface);
/* Fill background */
cairo_set_source_rgb(cairo,
background->red / 255.0,
background->green / 255.0,
background->blue / 255.0);
cairo_rectangle(cairo, 0, 0, surface_width, surface_height);
cairo_fill(cairo);
/* Get layout */
layout = pango_cairo_create_layout(cairo);
pango_layout_set_font_description(layout, display->font_desc);
pango_layout_set_text(layout, utf8, bytes);
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
pango_layout_get_size(layout, &layout_width, &layout_height);
/* If layout bigger than available space, scale it back */
if (layout_width > ideal_layout_width || layout_height > ideal_layout_height) {
double scale = fmin(ideal_layout_width / (double) layout_width,
ideal_layout_height / (double) layout_height);
cairo_scale(cairo, scale, scale);
/* Update layout to reflect scaled surface */
pango_layout_set_width(layout, ideal_layout_width / scale);
pango_layout_set_height(layout, ideal_layout_height / scale);
pango_cairo_update_layout(cairo, layout);
}
/* Draw */
cairo_set_source_rgb(cairo,
color->red / 255.0,
color->green / 255.0,
color->blue / 255.0);
cairo_move_to(cairo, 0.0, 0.0);
pango_cairo_show_layout(cairo, layout);
/* Draw */
guac_common_surface_draw(display->display_surface,
display->char_width * col,
display->char_height * row,
surface);
/* Free all */
g_object_unref(layout);
cairo_destroy(cairo);
cairo_surface_destroy(surface);
//.........这里部分代码省略.........
开发者ID:jamesshew,项目名称:guacamole-server,代码行数:101,代码来源:display.c
示例2: blur_surface
void
blur_surface(cairo_surface_t *surface, int margin)
{
cairo_surface_t *tmp;
int32_t width, height, stride, x, y, z, w;
uint8_t *src, *dst;
uint32_t *s, *d, a, p;
int i, j, k, size = 17, half;
uint8_t kernel[100];
double f;
width = cairo_image_surface_get_width(surface);
height = cairo_image_surface_get_height(surface);
stride = cairo_image_surface_get_stride(surface);
src = cairo_image_surface_get_data(surface);
tmp = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
dst = cairo_image_surface_get_data(tmp);
half = size / 2;
a = 0;
for (i = 0; i < size; i++) {
f = (i - half);
kernel[i] = exp(- f * f / 30.0) * 80;
a += kernel[i];
}
for (i = 0; i < height; i++) {
s = (uint32_t *) (src + i * stride);
d = (uint32_t *) (dst + i * stride);
for (j = 0; j < width; j++) {
if (margin < j && j < width - margin &&
margin < i && i < height - margin)
continue;
x = 0;
y = 0;
z = 0;
w = 0;
for (k = 0; k < size; k++) {
if (j - half + k < 0 || j - half + k >= width)
continue;
p = s[j - half + k];
x += (p >> 24) * kernel[k];
y += ((p >> 16) & 0xff) * kernel[k];
z += ((p >> 8) & 0xff) * kernel[k];
w += (p & 0xff) * kernel[k];
}
d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
}
}
for (i = 0; i < height; i++) {
s = (uint32_t *) (dst + i * stride);
d = (uint32_t *) (src + i * stride);
for (j = 0; j < width; j++) {
if (margin <= j && j < width - margin &&
margin <= i && i < height - margin)
continue;
x = 0;
y = 0;
z = 0;
w = 0;
for (k = 0; k < size; k++) {
if (i - half + k < 0 || i - half + k >= height)
continue;
s = (uint32_t *) (dst + (i - half + k) * stride);
p = s[j];
x += (p >> 24) * kernel[k];
y += ((p >> 16) & 0xff) * kernel[k];
z += ((p >> 8) & 0xff) * kernel[k];
w += (p & 0xff) * kernel[k];
}
d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
}
}
cairo_surface_destroy(tmp);
}
开发者ID:qiuTED,项目名称:wayland,代码行数:80,代码来源:cairo-util.c
示例3: draw_image
/*
* 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_t *ctx1 = 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);
cairo_text_extents_t extents;
double x, y;
cairo_set_source_rgb(ctx1, 0, 0, 0);
cairo_set_font_size(ctx1, 12.0);
cairo_text_extents(ctx1, flg_string, &extents);
x = BUTTON_CENTER - ((extents.width / 2) + extents.x_bearing) - 12;
y = BUTTON_CENTER - ((extents.height / 2) + extents.y_bearing) + 75 ;
cairo_move_to(ctx1, x, y);
cairo_show_text(ctx1, flg_string);
cairo_close_path(ctx1);
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);
}
if (unlock_state >= STATE_KEY_PRESSED && unlock_indicator) {
cairo_scale(ctx, scaling_factor(), scaling_factor());
/* Draw a (centered) circle with transparent background. */
cairo_set_line_width(ctx, 10.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:
cairo_set_source_rgba(ctx, 0, 114.0/255, 255.0/255, 0.75);
break;
case STATE_PAM_WRONG:
cairo_set_source_rgba(ctx, 250.0/255, 0, 0, 0.75);
break;
default:
cairo_set_source_rgba(ctx, 0, 0, 0, 0.75);
break;
}
cairo_fill_preserve(ctx);
switch (pam_state) {
case STATE_PAM_VERIFY:
cairo_set_source_rgb(ctx, 51.0/255, 0, 250.0/255);
break;
case STATE_PAM_WRONG:
//.........这里部分代码省略.........
开发者ID:Kamori,项目名称:i3lock,代码行数:101,代码来源:unlock_indicator.c
示例4: cairo_image_surface_create
void PangoTexture::generate(const std::string& text){
cairo_t* layout_context;
cairo_t* render_context;
cairo_surface_t* temp_surface;
cairo_surface_t* surface;
unsigned char* surface_data = NULL;
PangoFontDescription *desc;
PangoLayout* layout;
//create layout context
cairo_surface_t* ltemp_surface;
ltemp_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
layout_context = cairo_create(ltemp_surface);
cairo_surface_destroy(ltemp_surface);
//cairo surface set, make pango layout
layout = pango_cairo_create_layout(layout_context);
pango_layout_set_text(layout, text.c_str(), -1);
//load fond
desc = pango_font_description_from_string(font.c_str());
pango_layout_set_font_description(layout, desc);
pango_font_description_free(desc);
//get_text_size(layout, text_width, text_height);
pango_layout_get_size(layout, &width, &height);
//printf("width is %d\n", width);
//printf("height is %d\n", height);
width /= PANGO_SCALE;
height /= PANGO_SCALE;
//printf("width is %d\n", width);
//printf("pango height is %d\n", height);
surface_data = (unsigned char*)calloc(4 * width * height, sizeof(unsigned char));
surface = cairo_image_surface_create_for_data(surface_data,
CAIRO_FORMAT_ARGB32,
width,
height,
4 * width);
//channels == 4
render_context = cairo_create(surface);
cairo_set_source_rgba(render_context, 1, 1, 1, 1);
pango_cairo_show_layout( render_context, layout);
glBindTexture(GL_TEXTURE_2D, texture_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
width,
height,
0,
GL_BGRA,
GL_UNSIGNED_BYTE,
surface_data);
}
开发者ID:jheise,项目名称:grid,代码行数:63,代码来源:pangotexture.cpp
示例5: photos_utils_create_symbolic_icon_for_scale
GIcon *
photos_utils_create_symbolic_icon_for_scale (const gchar *name, gint base_size, gint scale)
{
g_autoptr (GIcon) icon = NULL;
GIcon *ret_val = NULL;
g_autoptr (GdkPixbuf) pixbuf = NULL;
g_autoptr (GtkIconInfo) info = NULL;
GtkIconTheme *theme;
g_autoptr (GtkStyleContext) style = NULL;
g_autoptr (GtkWidgetPath) path = NULL;
cairo_surface_t *icon_surface = NULL; /* TODO: use g_autoptr */
cairo_surface_t *surface; /* TODO: use g_autoptr */
cairo_t *cr; /* TODO: use g_autoptr */
g_autofree gchar *symbolic_name = NULL;
const gint bg_size = 24;
const gint emblem_margin = 4;
gint emblem_pos;
gint emblem_size;
gint total_size;
gint total_size_scaled;
total_size = base_size / 2;
total_size_scaled = total_size * scale;
emblem_size = bg_size - emblem_margin * 2;
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, total_size_scaled, total_size_scaled);
cairo_surface_set_device_scale (surface, (gdouble) scale, (gdouble) scale);
cr = cairo_create (surface);
style = gtk_style_context_new ();
path = gtk_widget_path_new ();
gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW);
gtk_style_context_set_path (style, path);
gtk_style_context_add_class (style, "photos-icon-bg");
gtk_render_background (style, cr, total_size - bg_size, total_size - bg_size, bg_size, bg_size);
symbolic_name = g_strconcat (name, "-symbolic", NULL);
icon = g_themed_icon_new_with_default_fallbacks (symbolic_name);
theme = gtk_icon_theme_get_default();
info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, icon, emblem_size, scale, GTK_ICON_LOOKUP_FORCE_SIZE);
if (info == NULL)
goto out;
pixbuf = gtk_icon_info_load_symbolic_for_context (info, style, NULL, NULL);
if (pixbuf == NULL)
goto out;
icon_surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);
emblem_pos = total_size - emblem_size - emblem_margin;
gtk_render_icon_surface (style, cr, icon_surface, emblem_pos, emblem_pos);
ret_val = G_ICON (gdk_pixbuf_get_from_surface (surface, 0, 0, total_size_scaled, total_size_scaled));
out:
cairo_surface_destroy (icon_surface);
cairo_surface_destroy (surface);
cairo_destroy (cr);
return ret_val;
}
开发者ID:uajain,项目名称:gnome-photos,代码行数:65,代码来源:photos-utils.c
示例6: ImageSource
bool GraphicsContext3D::ImageExtractor::extractImage(bool premultiplyAlpha, bool ignoreGammaAndColorProfile)
{
if (!m_image)
return false;
// We need this to stay in scope because the native image is just a shallow copy of the data.
m_decoder = new ImageSource(premultiplyAlpha ? ImageSource::AlphaPremultiplied : ImageSource::AlphaNotPremultiplied, ignoreGammaAndColorProfile ? ImageSource::GammaAndColorProfileIgnored : ImageSource::GammaAndColorProfileApplied);
if (!m_decoder)
return false;
ImageSource& decoder = *m_decoder;
m_alphaOp = AlphaDoNothing;
if (m_image->data()) {
decoder.setData(m_image->data(), true);
if (!decoder.frameCount() || !decoder.frameIsCompleteAtIndex(0))
return false;
m_imageSurface = decoder.createFrameAtIndex(0);
} else {
m_imageSurface = m_image->nativeImageForCurrentFrame();
// 1. For texImage2D with HTMLVideoElment input, assume no PremultiplyAlpha had been applied and the alpha value is 0xFF for each pixel,
// which is true at present and may be changed in the future and needs adjustment accordingly.
// 2. For texImage2D with HTMLCanvasElement input in which Alpha is already Premultiplied in this port,
// do AlphaDoUnmultiply if UNPACK_PREMULTIPLY_ALPHA_WEBGL is set to false.
if (!premultiplyAlpha && m_imageHtmlDomSource != HtmlDomVideo)
m_alphaOp = AlphaDoUnmultiply;
// if m_imageSurface is not an image, extract a copy of the surface
if (m_imageSurface && cairo_surface_get_type(m_imageSurface.get()) != CAIRO_SURFACE_TYPE_IMAGE) {
RefPtr<cairo_surface_t> tmpSurface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, m_imageWidth, m_imageHeight));
copyRectFromOneSurfaceToAnother(m_imageSurface.get(), tmpSurface.get(), IntSize(), IntRect(0, 0, m_imageWidth, m_imageHeight), IntSize(), CAIRO_OPERATOR_SOURCE);
m_imageSurface = tmpSurface.release();
}
}
if (!m_imageSurface)
return false;
ASSERT(cairo_surface_get_type(m_imageSurface.get()) == CAIRO_SURFACE_TYPE_IMAGE);
IntSize imageSize = cairoSurfaceSize(m_imageSurface.get());
m_imageWidth = imageSize.width();
m_imageHeight = imageSize.height();
if (!m_imageWidth || !m_imageHeight)
return false;
if (cairo_image_surface_get_format(m_imageSurface.get()) != CAIRO_FORMAT_ARGB32)
return false;
unsigned int srcUnpackAlignment = 1;
size_t bytesPerRow = cairo_image_surface_get_stride(m_imageSurface.get());
size_t bitsPerPixel = 32;
unsigned padding = bytesPerRow - bitsPerPixel / 8 * m_imageWidth;
if (padding) {
srcUnpackAlignment = padding + 1;
while (bytesPerRow % srcUnpackAlignment)
++srcUnpackAlignment;
}
m_imagePixelData = cairo_image_surface_get_data(m_imageSurface.get());
m_imageSourceFormat = DataFormatBGRA8;
m_imageSourceUnpackAlignment = srcUnpackAlignment;
return true;
}
开发者ID:boska,项目名称:webkit,代码行数:62,代码来源:GraphicsContext3DCairo.cpp
示例7: cairo_image_surface_create
void text_rsrc::updatePixels_setup( text_update_context* context )
{
// Set up Cairo then Pango with initial values /////////////////////////////////////////////////////////////////////////////////////////////////////////
context -> c_surf = cairo_image_surface_create( CAIRO_FORMAT_A8, // We only need alpha, coloring is handled by OpenGL
dimensions[ 0 ],
dimensions[ 1 ] );
context -> c_status = cairo_surface_status( context -> c_surf );
if( context -> c_status )
{
exception e;
ff::write( *e,
"text_rsrc::updatePixels(): Error creating Cairo surface: ",
cairo_status_to_string( context -> c_status ) );
throw e;
}
context -> c_context = cairo_create( context -> c_surf );
context -> c_status = cairo_status( context -> c_context );
if( context -> c_status )
{
exception e;
ff::write( *e,
"text_rsrc::updatePixels(): Error creating Cairo context: ",
cairo_status_to_string( context -> c_status ) );
throw e;
}
cairo_surface_destroy( context -> c_surf ); // Dereference surface
context -> p_layout = pango_cairo_create_layout( context -> c_context );
// Customize Pango layout & font ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if( max_dimensions[ 0 ] < 0 )
pango_layout_set_width( context -> p_layout,
-1 );
else
pango_layout_set_width( context -> p_layout,
max_dimensions[ 0 ] * PANGO_SCALE );
if( max_dimensions[ 1 ] < 0 )
pango_layout_set_height( context -> p_layout,
-1 );
else
pango_layout_set_height( context -> p_layout,
max_dimensions[ 1 ] * PANGO_SCALE );
context -> c_fontops = cairo_font_options_create();
if( hinting_enabled )
cairo_font_options_set_hint_style( context -> c_fontops,
CAIRO_HINT_STYLE_DEFAULT );
else
cairo_font_options_set_hint_style( context -> c_fontops,
CAIRO_HINT_STYLE_NONE );
if( antialiasing_enabled )
cairo_font_options_set_antialias( context -> c_fontops,
CAIRO_ANTIALIAS_DEFAULT );
else
cairo_font_options_set_antialias( context -> c_fontops,
CAIRO_ANTIALIAS_NONE );
// TODO: Potentially set subpixel rendering
pango_cairo_context_set_font_options( pango_layout_get_context( context -> p_layout ),
context -> c_fontops ); // Many thanks to ui/gfc/pango_util.cc from the Chromium project, which appears
// to be the only online example of setting PangoCairo font options
context -> p_fontd = pango_font_description_from_string( font.c_str() );
pango_font_description_set_absolute_size( context -> p_fontd,
point_size * PANGO_SCALE );
pango_layout_set_font_description( context -> p_layout,
context -> p_fontd );
pango_font_description_free( context -> p_fontd ); // Dereference font description
switch( ellipsize )
{
case NONE:
pango_layout_set_ellipsize( context -> p_layout,
PANGO_ELLIPSIZE_NONE );
break;
case BEGINNING:
pango_layout_set_ellipsize( context -> p_layout,
PANGO_ELLIPSIZE_START );
break;
case MIDDLE:
pango_layout_set_ellipsize( context -> p_layout,
PANGO_ELLIPSIZE_MIDDLE );
break;
case END:
pango_layout_set_ellipsize( context -> p_layout,
PANGO_ELLIPSIZE_END );
break;
default:
throw exception( "text_rsrc::updatePixels(): Unknown ellipsize mode" );
}
pango_layout_set_text( context -> p_layout,
//.........这里部分代码省略.........
开发者ID:JadeMatrix,项目名称:BQTDraw,代码行数:101,代码来源:bqt_gui_text_rsrc.cpp
示例8: ease_slide_button_panel_pixbuf
GdkPixbuf* ease_slide_button_panel_pixbuf (EaseSlide* slide, gint width) {
#line 428 "ease-slide-button-panel.c"
GdkPixbuf* result = NULL;
gint height;
cairo_surface_t* surface;
cairo_t* context;
char* _tmp0_;
char* _tmp1_;
char* _tmp2_;
char* path;
GError * _inner_error_ = NULL;
#line 178 "ease-slide-button-panel.vala"
g_return_val_if_fail (slide != NULL, NULL);
#line 180 "ease-slide-button-panel.vala"
height = (gint) ((((float) width) * ease_slide_get_height (slide)) / ease_slide_get_width (slide));
#line 182 "ease-slide-button-panel.vala"
surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height);
#line 184 "ease-slide-button-panel.vala"
context = cairo_create (surface);
#line 185 "ease-slide-button-panel.vala"
cairo_save (context);
#line 186 "ease-slide-button-panel.vala"
cairo_scale (context, (double) (((float) width) / ease_slide_get_width (slide)), (double) (((float) height) / ease_slide_get_height (slide)));
#line 450 "ease-slide-button-panel.c"
{
#line 191 "ease-slide-button-panel.vala"
ease_slide_cairo_render_small (slide, context);
#line 454 "ease-slide-button-panel.c"
}
goto __finally17;
__catch17_g_error:
{
GError * e;
e = _inner_error_;
_inner_error_ = NULL;
{
#line 195 "ease-slide-button-panel.vala"
g_critical (_ ("Error drawing slide preview: %s"), e->message);
#line 465 "ease-slide-button-panel.c"
_g_error_free0 (e);
}
}
__finally17:
if (_inner_error_ != NULL) {
_cairo_destroy0 (context);
_cairo_surface_destroy0 (surface);
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
g_clear_error (&_inner_error_);
return NULL;
}
#line 199 "ease-slide-button-panel.vala"
cairo_restore (context);
#line 201 "ease-slide-button-panel.vala"
cairo_rectangle (context, (double) 0, (double) 0, (double) width, (double) height);
#line 202 "ease-slide-button-panel.vala"
cairo_set_source_rgb (context, (double) 0, (double) 0, (double) 0);
#line 203 "ease-slide-button-panel.vala"
cairo_stroke (context);
#line 206 "ease-slide-button-panel.vala"
path = (_tmp2_ = g_build_filename (ease_slide_button_panel_get_temp_dir (), _tmp1_ = g_strconcat (_tmp0_ = g_strdup_printf ("%i", ease_slide_button_panel_temp_count++), ".png", NULL), NULL), _g_free0 (_tmp1_), _g_free0 (_tmp0_), _tmp2_);
#line 208 "ease-slide-button-panel.vala"
cairo_surface_write_to_png (surface, path);
#line 489 "ease-slide-button-panel.c"
{
GdkPixbuf* pb;
#line 212 "ease-slide-button-panel.vala"
pb = gdk_pixbuf_new_from_file (path, &_inner_error_);
#line 494 "ease-slide-button-panel.c"
if (_inner_error_ != NULL) {
goto __catch18_g_error;
}
#line 213 "ease-slide-button-panel.vala"
g_remove (path);
#line 500 "ease-slide-button-panel.c"
result = pb;
_g_free0 (path);
_cairo_destroy0 (context);
_cairo_surface_destroy0 (surface);
#line 214 "ease-slide-button-panel.vala"
return result;
#line 507 "ease-slide-button-panel.c"
}
goto __finally18;
__catch18_g_error:
{
GError * e;
e = _inner_error_;
_inner_error_ = NULL;
{
#line 216 "ease-slide-button-panel.vala"
g_error ("ease-slide-button-panel.vala:216: %s", e->message);
#line 518 "ease-slide-button-panel.c"
_g_error_free0 (e);
}
}
__finally18:
{
_g_free0 (path);
_cairo_destroy0 (context);
_cairo_surface_destroy0 (surface);
//.........这里部分代码省略.........
开发者ID:rmujica,项目名称:Nitido,代码行数:101,代码来源:ease-slide-button-panel.c
示例9: on_screenshot_finished
static void
on_screenshot_finished (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
ScreenshotData *data = user_data;
CcBackgroundPanel *panel = data->panel;
CcBackgroundPanelPrivate *priv;
GError *error;
GdkPixbuf *pixbuf;
cairo_surface_t *surface;
cairo_t *cr;
GVariant *result;
error = NULL;
result = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source),
res,
&error);
if (result == NULL) {
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
g_error_free (error);
g_free (data);
return;
}
g_debug ("Unable to get screenshot: %s",
error->message);
g_error_free (error);
/* fallback? */
priv = panel->priv;
goto out;
}
g_variant_unref (result);
priv = panel->priv;
pixbuf = gdk_pixbuf_new_from_file (panel->priv->screenshot_path, &error);
if (pixbuf == NULL)
{
g_debug ("Unable to use GNOME Shell's builtin screenshot interface: %s",
error->message);
g_error_free (error);
goto out;
}
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
data->monitor_rect.width, data->monitor_rect.height);
cr = cairo_create (surface);
gdk_cairo_set_source_pixbuf (cr, pixbuf,
data->capture_rect.x - data->monitor_rect.x,
data->capture_rect.y - data->monitor_rect.y);
cairo_paint (cr);
g_object_unref (pixbuf);
if (data->whole_monitor) {
/* clear the workarea */
cairo_save (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
cairo_rectangle (cr, data->workarea_rect.x - data->monitor_rect.x,
data->workarea_rect.y - data->monitor_rect.y,
data->workarea_rect.width,
data->workarea_rect.height);
cairo_fill (cr);
cairo_restore (cr);
}
g_clear_object (&panel->priv->display_screenshot);
panel->priv->display_screenshot = gdk_pixbuf_get_from_surface (surface,
0, 0,
data->monitor_rect.width,
data->monitor_rect.height);
/* remove the temporary file created by the shell */
g_unlink (panel->priv->screenshot_path);
g_clear_pointer (&priv->screenshot_path, g_free);
cairo_destroy (cr);
cairo_surface_destroy (surface);
out:
update_display_preview (panel, WID ("background-desktop-drawingarea"), priv->current_background);
g_free (data);
}
开发者ID:mariospr,项目名称:gnome-control-center,代码行数:83,代码来源:cc-background-panel.c
示例10: draw_shadow
void
draw_shadow (cairo_t* cr,
gdouble width,
gdouble height,
gint shadow_radius,
gint corner_radius)
{
cairo_surface_t* tmp_surface = NULL;
cairo_surface_t* new_surface = NULL;
cairo_pattern_t* pattern = NULL;
cairo_t* cr_surf = NULL;
cairo_matrix_t matrix;
raico_blur_t* blur = NULL;
tmp_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
4 * shadow_radius,
4 * shadow_radius);
if (cairo_surface_status (tmp_surface) != CAIRO_STATUS_SUCCESS)
return;
cr_surf = cairo_create (tmp_surface);
if (cairo_status (cr_surf) != CAIRO_STATUS_SUCCESS)
{
cairo_surface_destroy (tmp_surface);
return;
}
cairo_scale (cr_surf, 1.0f, 1.0f);
cairo_set_operator (cr_surf, CAIRO_OPERATOR_CLEAR);
cairo_paint (cr_surf);
cairo_set_operator (cr_surf, CAIRO_OPERATOR_OVER);
cairo_set_source_rgba (cr_surf, 0.0f, 0.0f, 0.0f, 0.75f);
cairo_arc (cr_surf,
2 * shadow_radius,
2 * shadow_radius,
2.0f * corner_radius,
0.0f,
360.0f * (G_PI / 180.f));
cairo_fill (cr_surf);
cairo_destroy (cr_surf);
// create and setup blur
blur = raico_blur_create (RAICO_BLUR_QUALITY_LOW);
raico_blur_set_radius (blur, shadow_radius);
// now blur it
raico_blur_apply (blur, tmp_surface);
// blur no longer needed
raico_blur_destroy (blur);
new_surface = cairo_image_surface_create_for_data (
cairo_image_surface_get_data (tmp_surface),
cairo_image_surface_get_format (tmp_surface),
cairo_image_surface_get_width (tmp_surface) / 2,
cairo_image_surface_get_height (tmp_surface) / 2,
cairo_image_surface_get_stride (tmp_surface));
pattern = cairo_pattern_create_for_surface (new_surface);
if (cairo_pattern_status (pattern) != CAIRO_STATUS_SUCCESS)
{
cairo_surface_destroy (tmp_surface);
cairo_surface_destroy (new_surface);
return;
}
// top left
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
cairo_set_source (cr, pattern);
cairo_rectangle (cr,
0.0f,
0.0f,
width - 2 * shadow_radius,
2 * shadow_radius);
cairo_fill (cr);
// bottom left
cairo_matrix_init_scale (&matrix, 1.0f, -1.0f);
cairo_matrix_translate (&matrix, 0.0f, -height);
cairo_pattern_set_matrix (pattern, &matrix);
cairo_rectangle (cr,
0.0f,
2 * shadow_radius,
2 * shadow_radius,
height - 2 * shadow_radius);
cairo_fill (cr);
// top right
cairo_matrix_init_scale (&matrix, -1.0f, 1.0f);
cairo_matrix_translate (&matrix, -width, 0.0f);
cairo_pattern_set_matrix (pattern, &matrix);
cairo_rectangle (cr,
width - 2 * shadow_radius,
0.0f,
2 * shadow_radius,
height - 2 * shadow_radius);
cairo_fill (cr);
// bottom right
cairo_matrix_init_scale (&matrix, -1.0f, -1.0f);
cairo_matrix_translate (&matrix, -width, -height);
//.........这里部分代码省略.........
开发者ID:chappyhome,项目名称:notify-osd-customizable,代码行数:101,代码来源:test-grow-bubble.c
示例11: setup_tile
void
setup_tile (gint w, gint h)
{
cairo_status_t status;
cairo_t* cr = NULL;
cairo_surface_t* cr_surf = NULL;
cairo_surface_t* tmp = NULL;
cairo_surface_t* dummy_surf = NULL;
cairo_surface_t* norm_surf = NULL;
cairo_surface_t* blur_surf = NULL;
gdouble width = (gdouble) w;
gdouble height = (gdouble) h;
raico_blur_t* blur = NULL;
cr_surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
3 * BUBBLE_SHADOW_SIZE,
3 * BUBBLE_SHADOW_SIZE);
status = cairo_surface_status (cr_surf);
if (status != CAIRO_STATUS_SUCCESS)
g_print ("Error: \"%s\"\n", cairo_status_to_string (status));
cr = cairo_create (cr_surf);
status = cairo_status (cr);
if (status != CAIRO_STATUS_SUCCESS)
{
cairo_surface_destroy (cr_surf);
g_print ("Error: \"%s\"\n", cairo_status_to_string (status));
}
// clear and render drop-shadow and bubble-background
cairo_scale (cr, 1.0f, 1.0f);
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
cairo_paint (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
if (g_composited)
{
draw_shadow (cr,
width,
height,
BUBBLE_SHADOW_SIZE,
CORNER_RADIUS);
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
draw_round_rect (cr,
1.0f,
(gdouble) BUBBLE_SHADOW_SIZE,
(gdouble) BUBBLE_SHADOW_SIZE,
(gdouble) CORNER_RADIUS,
(gdouble) (width - 2.0f * BUBBLE_SHADOW_SIZE),
(gdouble) (height - 2.0f* BUBBLE_SHADOW_SIZE));
cairo_fill (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_set_source_rgba (cr,
BUBBLE_BG_COLOR_R,
BUBBLE_BG_COLOR_G,
BUBBLE_BG_COLOR_B,
0.95f);
}
else
cairo_set_source_rgb (cr,
BUBBLE_BG_COLOR_R,
BUBBLE_BG_COLOR_G,
BUBBLE_BG_COLOR_B);
draw_round_rect (cr,
1.0f,
BUBBLE_SHADOW_SIZE,
BUBBLE_SHADOW_SIZE,
CORNER_RADIUS,
(gdouble) (width - 2.0f * BUBBLE_SHADOW_SIZE),
(gdouble) (height - 2.0f * BUBBLE_SHADOW_SIZE));
cairo_fill (cr);
tmp = cairo_image_surface_create_for_data (
cairo_image_surface_get_data (cr_surf),
cairo_image_surface_get_format (cr_surf),
3 * BUBBLE_SHADOW_SIZE,
3 * BUBBLE_SHADOW_SIZE,
cairo_image_surface_get_stride (cr_surf));
dummy_surf = copy_surface (tmp);
cairo_surface_destroy (tmp);
tmp = cairo_image_surface_create_for_data (
cairo_image_surface_get_data (dummy_surf),
cairo_image_surface_get_format (dummy_surf),
2 * BUBBLE_SHADOW_SIZE,
2 * BUBBLE_SHADOW_SIZE,
cairo_image_surface_get_stride (dummy_surf));
norm_surf = copy_surface (tmp);
cairo_surface_destroy (tmp);
blur = raico_blur_create (RAICO_BLUR_QUALITY_LOW);
raico_blur_set_radius (blur, 6);
raico_blur_apply (blur, dummy_surf);
raico_blur_destroy (blur);
tmp = cairo_image_surface_create_for_data (
cairo_image_surface_get_data (dummy_surf),
cairo_image_surface_get_format (dummy_surf),
2 * BUBBLE_SHADOW_SIZE,
2 * BUBBLE_SHADOW_SIZE,
//.........这里部分代码省略.........
开发者ID:chappyhome,项目名称:notify-osd-customizable,代码行数:101,代码来源:test-grow-bubble.c
示例12: gnm_so_path_set_property
static void
gnm_so_path_set_property (GObject *obj, guint param_id,
GValue const *value, GParamSpec *pspec)
{
GnmSOPath *sop = GNM_SO_PATH (obj);
switch (param_id) {
case SOP_PROP_STYLE: {
GOStyle *style = go_style_dup (g_value_get_object (value));
style->interesting_fields = GO_STYLE_OUTLINE | GO_STYLE_FILL;
g_object_unref (sop->style);
sop->style = style;
break;
}
case SOP_PROP_PATH: {
GOPath *path = g_value_get_boxed (value);
if (sop->path)
go_path_free (sop->path);
else if (sop->paths)
g_ptr_array_unref (sop->paths);
sop->path = NULL;
sop->paths = NULL;
if (path) {
cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
cairo_t *cr = cairo_create (surface);
sop->path = go_path_ref (path);
/* evaluates the bounding rectangle */
go_path_to_cairo (path, GO_PATH_DIRECTION_FORWARD, cr);
cairo_fill_extents (cr,
&sop->x_offset, &sop->y_offset,
&sop->width, &sop->height);
sop->width -= sop->x_offset;
sop->height -= sop->y_offset;
cairo_destroy (cr);
cairo_surface_destroy (surface);
}
break;
}
case SOP_PROP_PATHS: {
GPtrArray *paths = g_value_get_boxed (value);
unsigned i;
for (i = 0; i < paths->len; i++)
/* we can only check that the path is not NULL */
g_return_if_fail (g_ptr_array_index (paths, i) != NULL);
if (sop->path)
go_path_free (sop->path);
else if (sop->paths)
g_ptr_array_unref (sop->paths);
sop->path = NULL;
sop->paths = NULL;
if (paths) {
cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
cairo_t *cr = cairo_create (surface);
sop->paths = g_ptr_array_ref (paths);
/* evaluates the bounding rectangle */
for (i = 0; i < paths->len; i++)
go_path_to_cairo ((GOPath *) g_ptr_array_index (paths, i),
GO_PATH_DIRECTION_FORWARD, cr);
cairo_fill_extents (cr,
&sop->x_offset, &sop->y_offset,
&sop->width, &sop->height);
sop->width -= sop->x_offset;
sop->height -= sop->y_offset;
cairo_destroy (cr);
cairo_surface_destroy (surface);
}
break;
}
case SOP_PROP_TEXT: {
char const *str = g_value_get_string (value);
g_free (sop->text);
sop->text = g_strdup (str == NULL ? "" : str);
break;
}
case SOP_PROP_MARKUP:
if (sop->markup != NULL)
pango_attr_list_unref (sop->markup);
sop->markup = g_value_peek_pointer (value);
if (sop->markup != NULL)
pango_attr_list_ref (sop->markup);
break;
case SOP_PROP_VIEWBOX:
/* not settable */
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec);
return;
}
}
开发者ID:nzinfo,项目名称:gnumeric,代码行数:91,代码来源:gnm-so-path.c
示例13: py_fill_surface
/*
* This function must be called with a range of samples, and a desired
* width and height.
* It will average samples if needed.
*/
static PyObject *
py_fill_surface (PyObject * self, PyObject * args)
{
PyObject *samples;
PyObject *sampleObj;
int length, i;
double sample;
cairo_surface_t *surface;
cairo_t *ctx;
int width, height;
float pixelsPerSample;
float currentPixel;
int samplesInAccum;
float x = 0.;
double accum;
if (!PyArg_ParseTuple (args, "O!ii", &PyList_Type, &samples, &width, &height))
return NULL;
length = PyList_Size (samples);
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
ctx = cairo_create (surface);
cairo_set_source_rgb (ctx, 0.2, 0.6, 0.0);
cairo_set_line_width (ctx, 0.5);
cairo_move_to (ctx, 0, height);
pixelsPerSample = width / (float) length;
currentPixel = 0.;
samplesInAccum = 0;
accum = 0.;
for (i = 0; i < length; i++) {
/* Guaranteed to return something */
sampleObj = PyList_GetItem (samples, i);
sample = PyFloat_AsDouble (sampleObj);
/* If the object was not a float or convertible to float */
if (PyErr_Occurred ()) {
cairo_surface_finish (surface);
Py_DECREF (samples);
return NULL;
}
currentPixel += pixelsPerSample;
samplesInAccum += 1;
accum += sample;
if (currentPixel > 1.0) {
accum /= samplesInAccum;
cairo_line_to (ctx, x, height - accum);
accum = 0;
currentPixel -= 1.0;
samplesInAccum = 0;
}
x += pixelsPerSample;
}
Py_DECREF (samples);
cairo_line_to (ctx, width, height);
cairo_close_path (ctx);
cairo_fill_preserve (ctx);
return PycairoSurface_FromSurface (surface, NULL);
}
开发者ID:cfoch,项目名称:pitivi,代码行数:71,代码来源:renderer.c
示例14: configure_event
/******************************************************************************
* Basic events handlers *
******************************************************************************/
static gboolean
configure_event(GtkWidget* widget, GdkEventConfigure* dummy, gpointer data)
{
(void) dummy;
GtkAllocation allocation;
int new_pixmap_width, new_pixmap_height;
gtk_widget_get_allocation(widget, &allocation);
new_pixmap_width = allocation.width - BORDER_SIZE * 2;
new_pixmap_height = allocation.height - BORDER_SIZE *2;
Monitor *m;
m = (Monitor *) data;
if (new_pixmap_width > 0 && new_pixmap_height > 0)
{
/*
* If the stats buffer does not exist (first time we get inside this
* function) or its size changed, reallocate the buffer and preserve
* existing data.
*/
if (!m->stats || (new_pixmap_width != m->pixmap_width))
{
stats_set *new_stats = g_new0(stats_set, new_pixmap_width);
if (!new_stats)
return TRUE;
if (m->stats)
{
/* New allocation is larger.
* Add new "oldest" samples of zero following the cursor*/
if (new_pixmap_width > m->pixmap_width)
{
/* Number of values between the ring cursor and the end of
* the buffer */
int nvalues = m->pixmap_width - m->ring_cursor;
memcpy(new_stats,
m->stats,
m->ring_cursor * sizeof (stats_set));
memcpy(new_stats + nvalues,
m->stats + m->ring_cursor,
nvalues * sizeof(stats_set));
}
/* New allocation is smaller, but still larger than the ring
* buffer cursor */
else if (m->ring_cursor <= new_pixmap_width)
{
/* Numver of values that can be stored between the end of
* the new buffer and the ring cursor */
int nvalues = new_pixmap_width - m->ring_cursor;
memcpy(new_stats,
m->stats,
m->ring_cursor * sizeof(stats_set));
memcpy(new_stats + m->ring_cursor,
m->stats + m->pixmap_width - nvalues,
nvalues * sizeof(stats_set));
}
/* New allocation is smaller, and also smaller than the ring
* buffer cursor. Discard all oldest samples following the ring
* buffer cursor and additional samples at the beginning of the
* buffer. */
else
{
memcpy(new_stats,
m->stats + m->ring_cursor - new_pixmap_width,
new_pixmap_width * sizeof(stats_set));
}
g_free(m->stats);
}
m->stats = new_stats;
}
m->pixmap_width = new_pixmap_width;
m->pixmap_height = new_pixmap_height;
if (m->pixmap)
cairo_surface_destroy(m->pixmap);
m->pixmap = cairo_image_surface_create(CAIRO_FORMAT_RGB24,
m->pixmap_width,
m->pixmap_height);
check_cairo_surface_status(&m->pixmap);
redraw_pixmap(m);
}
return TRUE;
}
开发者ID:setzer22,项目名称:lxpanel,代码行数:91,代码来源:monitors.c
示例15: gtk_codegraph_save
void gtk_codegraph_save(GtkCodeGraph *box){
g_return_if_fail (GTK_IS_CODEGRAPH (box));
//Создается диалог выбора места сохранения тренда
GtkWidget *_dialog = gtk_file_chooser_dialog_new("Сохранить", NULL, GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
请发表评论