コード例 #1
0
void CairoFont::CairoFontTexture::Clear(Vector<4,float> color) {
    clearcol = color;
    cairo_set_source_rgba (cr, color[0], color[1], color[2], color[3]);
    cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
    cairo_paint(cr);
    cairo_surface_flush(surface);
    FireChangedEvent(0, 0, width, height);
}
コード例 #2
0
static cairo_status_t
_cairo_surface_subsurface_flush (void *abstract_surface)
{
    cairo_surface_subsurface_t *surface = abstract_surface;

    cairo_surface_flush (surface->target);
    return surface->target->status;
}
コード例 #3
0
ファイル: mume-x11-backwin.c プロジェクト: tomnotcat/mume
static void _x11_backwin_end_paint(
    struct _x11_backwin *self, cairo_t *cr)
{
    assert(self->managed);

    cairo_destroy(cr);
    cairo_surface_flush(self->surface);
}
コード例 #4
0
ファイル: vk.c プロジェクト: areslp/fcitx
void DrawVKWindow(VKWindow* vkWindow)
{
    int             i;
    int             iPos;
    cairo_t *cr;
    FcitxVKState *vkstate = vkWindow->owner;
    VKS *vks = vkstate->vks;

    FcitxConfigColor *fontColor = InvokeVaArgs(vkstate->owner, FCITX_CLASSIC_UI,
                                               GETKEYBOARDFONTCOLOR);
    char **font = InvokeVaArgs(vkstate->owner, FCITX_CLASSIC_UI, GETFONT);

    if (!fontColor || !font) {
        fontColor = &blackColor;
        font = &vkWindow->defaultFont;
    }

    cr = cairo_create(vkWindow->surface);
    cairo_surface_t* vkimage = LoadVKImage(vkWindow);
    cairo_set_source_surface(cr, vkimage, 0, 0);
    cairo_paint(cr);
    /* 显示字符 */
    /* 名称 */
    OutputString(cr, vks[vkstate->iCurrentVK].strName, *font, vkWindow->fontSize, false , (VK_WINDOW_WIDTH - StringWidth(vks[vkstate->iCurrentVK].strName, *font, vkWindow->fontSize, false)) / 2, 6, fontColor);

    /* 第一排 */
    iPos = 13;
    for (i = 0; i < 13; i++) {
        OutputString(cr, vks[vkstate->iCurrentVK].strSymbol[i][1], *font, vkWindow->fontSize, false, iPos, 27, fontColor);
        OutputString(cr, vks[vkstate->iCurrentVK].strSymbol[i][0], *font, vkWindow->fontSize, false, iPos - 5, 40, fontColor);
        iPos += 24;
    }
    /* 第二排 */
    iPos = 48;
    for (i = 13; i < 26; i++) {
        OutputString(cr, vks[vkstate->iCurrentVK].strSymbol[i][1], *font, vkWindow->fontSize, false, iPos, 55, fontColor);
        OutputString(cr, vks[vkstate->iCurrentVK].strSymbol[i][0], *font, vkWindow->fontSize, false, iPos - 5, 68, fontColor);
        iPos += 24;
    }
    /* 第三排 */
    iPos = 55;
    for (i = 26; i < 37; i++) {
        OutputString(cr, vks[vkstate->iCurrentVK].strSymbol[i][1], *font, vkWindow->fontSize, false, iPos, 83, fontColor);
        OutputString(cr, vks[vkstate->iCurrentVK].strSymbol[i][0], *font, vkWindow->fontSize, false, iPos - 5, 96, fontColor);
        iPos += 24;
    }

    /* 第四排 */
    iPos = 72;
    for (i = 37; i < 47; i++) {
        OutputString(cr, vks[vkstate->iCurrentVK].strSymbol[i][1], *font, vkWindow->fontSize, false, iPos, 111, fontColor);
        OutputString(cr, vks[vkstate->iCurrentVK].strSymbol[i][0], *font, vkWindow->fontSize, false, iPos - 5, 124, fontColor);
        iPos += 24;
    }

    cairo_destroy(cr);
    cairo_surface_flush(vkWindow->surface);
}
コード例 #5
0
ファイル: na-tray-child.c プロジェクト: ryandoyle/mate-panel
na_tray_child_expose_event (GtkWidget      *widget,
                            GdkEventExpose *event)
#endif
{
  NaTrayChild *child = NA_TRAY_CHILD (widget);
  GdkWindow *window = gtk_widget_get_window (widget);

  if (na_tray_child_has_alpha (child))
    {
      /* Clear to transparent */
#if !GTK_CHECK_VERSION (3, 0, 0)
      cairo_t *cr = gdk_cairo_create (window);
#endif
      cairo_set_source_rgba (cr, 0, 0, 0, 0);
      cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
#if GTK_CHECK_VERSION (3, 0, 0)
      cairo_paint (cr);
#else
      gdk_cairo_region (cr, event->region);
      cairo_fill (cr);
      cairo_destroy (cr);
#endif
    }
  else if (child->parent_relative_bg)
    {
      /* Clear to parent-relative pixmap */
#if GTK_CHECK_VERSION (3, 0, 0)
      GdkWindow *window;
      cairo_surface_t *target;
      GdkRectangle clip_rect;

      window = gtk_widget_get_window (widget);
      target = cairo_get_group_target (cr);

      gdk_cairo_get_clip_rectangle (cr, &clip_rect);

      /* Clear to parent-relative pixmap
       * We need to use direct X access here because GDK doesn't know about
       * the parent relative pixmap. */
      cairo_surface_flush (target);

      XClearArea (GDK_WINDOW_XDISPLAY (window),
                  GDK_WINDOW_XID (window),
                  clip_rect.x, clip_rect.y,
                  clip_rect.width, clip_rect.height,
                  False);
      cairo_surface_mark_dirty_rectangle (target,
                                          clip_rect.x, clip_rect.y,
                                          clip_rect.width, clip_rect.height);
#else
      gdk_window_clear_area (window,
                             event->area.x, event->area.y,
                             event->area.width, event->area.height);
#endif
    }

  return FALSE;
}
コード例 #6
0
ファイル: pycairo-surface.c プロジェクト: curaloucura/enso
static PyObject *
surface_flush (PycairoSurface *o)
{
    cairo_surface_flush (o->surface);

    if (Pycairo_Check_Status (cairo_surface_status(o->surface)))
	return NULL;
    Py_RETURN_NONE;
}
コード例 #7
0
ファイル: pycairo-surface.c プロジェクト: bdon/pycairo
static PyObject *
surface_flush (PycairoSurface *o)
{
    Py_BEGIN_ALLOW_THREADS
    cairo_surface_flush (o->surface);
    Py_END_ALLOW_THREADS
    RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
    Py_RETURN_NONE;
}
コード例 #8
0
ファイル: scale.c プロジェクト: sgrady2/C-VtkVis
void drawPointerText(){
	cairo_surface_t *surface;
        cairo_t *cr;
	const unsigned char* surfaceData;

	if (viewType == TWO_D){
		xX = 1.4, yY = Ypointer + 0.1, zZ = 0;
		}
	else {
		xX = Xpointer - 0.1, yY = 0.45, zZ = 0;
		}
	
	if (viewType == TWO_D){
		sprintf(textToRender, " %d Hz", (int)(storedFreq * hzStep));
		}
	else {
		sprintf(textToRender, "%d Hz      %f dB", (int)(storedFreq * hzStep), storedIntensity);
		}
		
	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 32);
	cr = cairo_create (surface);
	cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
	cairo_set_font_size (cr, 10.0);
	cairo_move_to (cr, 0, 16);
	cairo_show_text (cr, textToRender);
	cairo_surface_flush(surface);
	surfaceData = cairo_image_surface_get_data (surface);

	unsigned Texture = 0;

	glGenTextures(1, &Texture);
	glBindTexture(GL_TEXTURE_2D, Texture);

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, cairo_image_surface_get_width(surface), cairo_image_surface_get_height(surface), 0, GL_BGRA, GL_UNSIGNED_BYTE, surfaceData);
	
	glBegin(GL_QUADS);
	glColor3f(1, 1, 1);
	glTexCoord2d(0, 0); glVertex3d(xX, yY, 0.01);
	glTexCoord2d(1, 0); glVertex3d(xX+0.3, yY, 0.01);
	glTexCoord2d(1, 1); glVertex3d(xX+0.3, yY-0.15, 0.01);
	glTexCoord2d(0, 1); glVertex3d(xX, yY-0.15, 0.01);
	glEnd();
	
	glDeleteTextures(1, &Texture);
	cairo_destroy (cr);
        cairo_surface_destroy (surface);
	
	if (viewType == TWO_D){
		yY += y_2d/10;
		}
	else {
		xX += x/10;
		}
}
コード例 #9
0
ファイル: glide-window.c プロジェクト: racarr/Glide
static void
glide_window_export_pdf_real (GlideWindow *w,
			      const gchar *filename)
{
  cairo_surface_t *pdf_surface;
  cairo_t *cr;
  gint width, height;
  gint o_slide;
  int i = 0;
  
  glide_window_fullscreen_stage (w);  
  while (g_main_context_pending (NULL))
    g_main_context_iteration (NULL, TRUE);
  
  width = clutter_actor_get_width (w->priv->stage);
  height = clutter_actor_get_height (w->priv->stage);

  pdf_surface = cairo_pdf_surface_create (filename, width, height);
  cr = cairo_create (pdf_surface);
  
  o_slide = glide_stage_manager_get_current_slide (w->priv->manager);
  
  for (i = 0; i < glide_document_get_n_slides (w->priv->document); i++)
    {
      guchar *pixels;
      guchar *p;
      GdkPixbuf *pb;

      glide_stage_manager_set_current_slide (w->priv->manager, i);

      pixels = clutter_stage_read_pixels (CLUTTER_STAGE (w->priv->stage), 0, 0, width, height);
      for (p = pixels + width * height * 4; p > pixels; p -= 3)
	*(--p) = 255; 


      pb = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, TRUE,
				     8, width, height, width * 4,
				     (GdkPixbufDestroyNotify) g_free,
				     NULL); 
      
      gdk_cairo_set_source_pixbuf (cr, pb, 0, 0);
      cairo_rectangle (cr, 0, 0, width, height);
      cairo_fill (cr);

      cairo_surface_show_page (pdf_surface);      
      
      g_object_unref (G_OBJECT (pb));
    }
  cairo_surface_flush (pdf_surface);

  cairo_destroy (cr);
  cairo_surface_destroy (pdf_surface);
  
  glide_window_unfullscreen_stage (w);
  glide_stage_manager_set_current_slide (w->priv->manager, o_slide);
}
コード例 #10
0
ファイル: test_cairo.c プロジェクト: peko/tttm2
int 
main(int argc, char** argv) {
   
   cairo_surface_t *sfc;
   cairo_t *ctx;
   
   int x, y;
   struct timespec ts = {0, 500000000};
   
   int running;

   x = y = 0;
   sfc = cairo_create_x11_surface(&x, &y);
   ctx = cairo_create(sfc);
   cairo_set_antialias(ctx, CAIRO_ANTIALIAS_NONE);

   mesh_t* m = mesh_create(x, y);

   for (running = 1; running;) {

      cairo_push_group(ctx);
      
         cairo_set_source_rgb(ctx, 0.1, 0.1, 0.1);
         cairo_paint(ctx);
         
         mesh_draw(ctx, m);

      cairo_pop_group_to_source(ctx);
      cairo_paint(ctx);

      cairo_surface_flush(sfc);

      int event=0;
      switch (event=cairo_check_event(sfc, 0)) {
         case 0xff53:   // right cursor
            break;

         case 0xff51:   // left cursor
            break;

         case 0xff1b:   // Esc
         case -1:       // left mouse button
            running = 0;
            break;
      }

      nanosleep(&ts, NULL);
   }

   mesh_free(m);

   cairo_destroy(ctx);
   cairo_close_x11_surface(sfc);

   return 0;
}
コード例 #11
0
ファイル: widget.cpp プロジェクト: BG1/warzone2100
void widgetDraw(widget *self)
{
	int i;

	// See if we need to be redrawn
	if (self->needsRedraw)
	{
		void *bits = cairo_image_surface_get_data(cairo_get_target(self->cr));

		self->needsRedraw = false;

		// Mark the texture as needing uploading
		self->textureNeedsUploading = true;

		// Clear the current context
		cairo_set_operator(self->cr, CAIRO_OPERATOR_SOURCE);
		cairo_set_source_rgba(self->cr, 0.0, 0.0, 0.0, 0.0);
		cairo_paint(self->cr);

		// Restore the compositing operator back to the default
		cairo_set_operator(self->cr, CAIRO_OPERATOR_OVER);

		// Save (push) the current context
		cairo_save(self->cr);

		// Redaw ourself
		widgetDoDraw(self);

		// Restore the context
		cairo_restore(self->cr);

		// Update the texture if widgetEndGL has not done it for us
		if (self->textureNeedsUploading)
		{
			// Flush the cairo surface to ensure that all drawing is completed
			cairo_surface_flush(cairo_get_target(self->cr));

			glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self->textureId);

			glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, self->size.x,
			             self->size.y, 0, GL_BGRA, GL_UNSIGNED_BYTE, bits);

			self->textureNeedsUploading = false;
		}

	}

	// Draw our children (even if we did not need redrawing our children might)
	for (i = 0; i < vectorSize(self->children); i++)
	{
		widget *child = vectorAt(self->children, i);

		// Ask the child to re-draw itself
		widgetDraw(child);
	}
}
コード例 #12
0
void ttk_window_draw(ttk_window_t * window) {
	draw_fill(window->core_context, rgb(TTK_BACKGROUND_DEFAULT));
	ttk_redraw_borders(window);

	/* TODO actual drawing */
	{
		/* TODO move these surfaces into the ttk_window_t object */
		int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, window->core_window->width);
		cairo_surface_t * core_surface = cairo_image_surface_create_for_data(window->core_context->backbuffer, CAIRO_FORMAT_ARGB32, window->core_window->width, window->core_window->height, stride);
		cairo_t * cr_main = cairo_create(core_surface);

		/* TODO move this surface to a ttk_frame_t or something; GUIs man, go look at some Qt or GTK APIs! */
		cairo_surface_t * internal_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, window->width, window->height);
		cairo_t * cr = cairo_create(internal_surface);

		_ttk_draw_menu(cr, 0, 0, window->width);

		_ttk_draw_button(cr, 4, TTK_MENU_HEIGHT + 4, window->width - 8, 40, "Regular Button");

		_ttk_draw_button(cr, 4, TTK_MENU_HEIGHT + 48 + 4, (window->width / 2) - 8, 40, "Regular Button");
		_ttk_draw_button_hover(cr, 4 + (window->width / 2), TTK_MENU_HEIGHT + 48 + 4, (window->width / 2) - 8, 40, "Hover Button");

		_ttk_draw_button_select(cr, 4, TTK_MENU_HEIGHT + 2 * 48 + 4, (window->width / 2) - 8, 40, "Selected");
		_ttk_draw_button_disabled(cr, 4 + (window->width / 2), TTK_MENU_HEIGHT + 2 * 48 + 4, (window->width / 2) - 8, 40, "Disabled Button");

		_ttk_draw_button(cr, 4, TTK_MENU_HEIGHT + 3 * 48 + 4, window->width - 8, window->height - (3 * 48) - TTK_MENU_HEIGHT - 8, "Regular Button");

		/* Paint the window's internal surface onto the backbuffer */
		cairo_set_source_surface(cr_main, internal_surface, (double)window->off_x, (double)window->off_y);
		cairo_paint(cr_main);
		cairo_surface_flush(internal_surface);
		cairo_destroy(cr);
		cairo_surface_destroy(internal_surface);

		/* In theory, we don't actually want to destroy much of any of this; maybe the cairo_t */
		cairo_surface_flush(core_surface);
		cairo_destroy(cr_main);
		cairo_surface_destroy(core_surface);
	}

	flip(window->core_context);
	yutani_flip(yctx, window->core_window);
}
コード例 #13
0
    void start()
    {
        cairo_surface_t* cairo_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, m_width, m_height);
        cairo_t* cr = cairo_create(cairo_surface);

        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
        cairo_paint(cr);

        PangoFontDescription *font_description = pango_font_description_new();
        pango_font_description_set_family(font_description, m_font.Family.c_str());
        pango_font_description_set_style(font_description, m_font.Style);
        pango_font_description_set_weight(font_description, m_font.Weight);
        pango_font_description_set_variant(font_description, m_font.Variant);
        pango_font_description_set_size(font_description, m_font.Size * PANGO_SCALE);

        PangoLayout *layout = pango_cairo_create_layout(cr);
        pango_layout_set_font_description(layout, font_description);
        pango_layout_set_text(layout, m_text_file.file_content_p(), -1);

        unsigned char* color = m_font.ColorRGB; // shortcut
        cairo_set_source_rgb(cr, color[0] / 255.0, color[1] / 255.0, color[2] / 255.0);
        cairo_move_to(cr, 0.0, 0.0);
        pango_cairo_show_layout(cr, layout);

        // To texture
        {
            cairo_surface_flush(cairo_surface);
            std::vector<unsigned char> rgba_data;
            rgba_from_cairo_ARGB32(
                cairo_image_surface_get_data(cairo_surface)
                , m_width
                , m_height
                , cairo_image_surface_get_stride(cairo_surface)
                , rgba_data
            );

            glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 );
            m_texture.bind();

            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &(rgba_data[0]));

            assert(glGetError() == GL_NO_ERROR);

            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            assert(glGetError() == GL_NO_ERROR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            assert(glGetError() == GL_NO_ERROR);
        }

        g_object_unref(layout);
        pango_font_description_free(font_description);

        cairo_destroy(cr);
        cairo_surface_destroy(cairo_surface);
    }
コード例 #14
0
PP_Bool
ppb_browser_font_trusted_draw_text_at(PP_Resource font, PP_Resource image_data,
                                      const struct PP_BrowserFont_Trusted_TextRun *text,
                                      const struct PP_Point *position, uint32_t color,
                                      const struct PP_Rect *clip, PP_Bool image_data_is_opaque)
{
    (void)image_data_is_opaque; // TODO: is it worth implementing?
    struct pp_browser_font_s *bf = pp_resource_acquire(font, PP_RESOURCE_BROWSER_FONT);
    if (!bf)
        return PP_FALSE;
    struct pp_image_data_s *id = pp_resource_acquire(image_data, PP_RESOURCE_IMAGE_DATA);
    if (!id) {
        pp_resource_release(font);
        return PP_FALSE;
    }

    cairo_t *cr = cairo_create(id->cairo_surf);
    if (clip) {
        cairo_rectangle(cr, clip->point.x, clip->point.y, clip->size.width, clip->size.height);
        cairo_clip(cr);
    }

    PangoFontMetrics *m = pango_font_get_metrics(bf->font, NULL);
    int32_t ascent = pango_font_metrics_get_ascent(m) / PANGO_SCALE;
    cairo_surface_mark_dirty(id->cairo_surf);
    if (position)
        cairo_move_to(cr, position->x, position->y - ascent);
    else
        cairo_move_to(cr, 0, 0);
    pango_font_metrics_unref(m);

    cairo_set_source_rgba(cr, ((color >> 16) & 0xffu) / 255.0,
                              ((color >> 8) & 0xffu) / 255.0,
                              ((color >> 0) & 0xffu) / 255.0,
                              ((color >> 24) & 0xffu) / 255.0);

    PangoLayout *layout = pango_cairo_create_layout(cr);
    uint32_t len = 0;
    const char *s = "";
    if (text->text.type == PP_VARTYPE_STRING)
        s = ppb_var_var_to_utf8(text->text, &len);

    // TODO: factor into rtl direction
    pango_layout_set_font_description(layout, bf->font_desc);
    pango_layout_set_text(layout, s, len);
    pango_cairo_layout_path(cr, layout);
    cairo_fill(cr);
    g_object_unref(layout);
    cairo_surface_flush(id->cairo_surf);
    cairo_destroy(cr);

    pp_resource_release(font);
    pp_resource_release(image_data);
    return PP_FALSE;
}
コード例 #15
0
ファイル: graphics_cairo.c プロジェクト: simongog/genometools
int gt_graphics_cairo_save_to_file(const GtGraphics *gg, const char *filename,
                                GtError *err)
{
  const GtGraphicsCairo *g = (const GtGraphicsCairo*) gg;
  cairo_surface_t *bgsurf = NULL;
  cairo_t *bgc = NULL;
  cairo_status_t rval;
  GtFile *outfile;
  gt_error_check(err);
  gt_assert(g && filename);

  /* do nothing if no surface was created */
  if (g->from_context)
    return 0;
  switch (g->type)
  {
    case GT_GRAPHICS_PNG:
      /* blend rendered image with background color */
      bgsurf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, g->width,
                                          g->height);
      bgc = cairo_create(bgsurf);
      cairo_set_source_rgba(bgc, g->bg_color.red, g->bg_color.green,
                                 g->bg_color.blue, g->bg_color.alpha);
      cairo_paint(bgc);
      cairo_set_source_surface(bgc, g->surf, 0, 0);
      cairo_paint(bgc);
      rval = cairo_surface_write_to_png(bgsurf, filename);
      gt_assert(rval == CAIRO_STATUS_SUCCESS ||
                rval == CAIRO_STATUS_WRITE_ERROR);
      if (rval == CAIRO_STATUS_WRITE_ERROR)
      {
        cairo_destroy(bgc);
        cairo_surface_destroy(bgsurf);
        gt_error_set(err, "an I/O error occurred while attempting "
                          "to write image file \"%s\"", filename);
        return -1;
      }
      cairo_destroy(bgc);
      cairo_surface_destroy(bgsurf);
      break;
    default:
      cairo_show_page(g->cr);
      cairo_surface_flush(g->surf);
      cairo_surface_finish(g->surf);
      outfile = gt_file_open(GT_FILE_MODE_UNCOMPRESSED, filename, "w+", err);
      if (outfile)
      {
        gt_file_xwrite(outfile, gt_str_get_mem(g->outbuf),
                       gt_str_length(g->outbuf));
        gt_file_delete(outfile);
      } else return -1;
      break;
  }
  return 0;
}
コード例 #16
0
int window_get_pixel_color(struct OsecpuWindow* window, int x, int y)
{
	// XXX: 必ずARGB32形式であると仮定して処理が書いてある
	// 透過はされてないはずなので上位8bitは必ず0になるようにする
	const unsigned char* surface_data;
	int width;
	width = cairo_image_surface_get_width(window->surface);
	cairo_surface_flush(window->surface);
	surface_data = cairo_image_surface_get_data(window->surface);
	return *((int*)surface_data + x + y*width) & 0x00ffffff;
}
コード例 #17
0
ファイル: icongen.cpp プロジェクト: sebesbal/simciv2
void TileSet::save(const std::wstring filename)
{
	FILE *file;
	errno_t err;
	if ((err = _wfopen_s(&file, filename.c_str(), L"wb")) == 0)  
	{
		cairo_surface_flush(surf);
		cairo_surface_write_to_png_stream(surf, cairo_write_to_file_cb, file);
		fclose(file);
	}
}
コード例 #18
0
ファイル: towel.c プロジェクト: kanru/towel
static void
towel_window_render_time(towel_window_t *win, int timer)
{
  cairo_surface_t *buf;
  cairo_t *cr;
  cairo_text_extents_t extents;
  int min = timer / 60;
  int sec = timer % 60;
  char time_str[6];
  int x, y, w, h;

  buf = cairo_surface_create_similar(win->cs, CAIRO_CONTENT_COLOR,
                                     win->width, win->height);
  cr = cairo_create(buf);
  towel_window_set_background_color(win, cr);

  snprintf(time_str, sizeof(time_str), "%02d:%02d", min, sec);
  cairo_select_font_face(cr, "Serif",
                         CAIRO_FONT_SLANT_NORMAL,
                         CAIRO_FONT_WEIGHT_BOLD);
  cairo_set_font_size(cr, 120);
  cairo_text_extents(cr, "00:00", &extents);
  x = (win->width - extents.width)/2;
  y = (win->height - extents.height)/2+6;
  w = extents.width;
  h = extents.height;
  cairo_set_source_rgb(cr, .1, .1, .1);
  cairo_move_to(cr, x+2, y+2);
  cairo_show_text(cr, time_str);
  cairo_set_source_rgb(cr, 1, 1, 1);
  cairo_move_to(cr, x, y);
  cairo_show_text(cr, time_str);
  cairo_surface_flush(buf);

  cairo_set_source_surface(win->cr, buf, 0, 0);
  cairo_paint(win->cr);
  cairo_destroy(cr);
  cairo_surface_destroy(buf);

  cairo_surface_flush(win->cs);
}
コード例 #19
0
void ofCairoRenderer::close(){
	if(surface){
		cairo_surface_flush(surface);
		cairo_surface_finish(surface);
		cairo_surface_destroy(surface);
		surface = NULL;
	}
	if(cr){
		cairo_destroy(cr);
		cr = NULL;
	}
}
コード例 #20
0
ファイル: seed-cairo-surface.c プロジェクト: iRi-E/GNOME-Seed
static SeedValue
seed_cairo_surface_flush (SeedContext ctx,
			  SeedObject function,
			  SeedObject this_object,
			  gsize argument_count,
			  const SeedValue arguments[],
			  SeedException *exception)
{
  CHECK_THIS();
  cairo_surface_flush (seed_object_to_cairo_surface(ctx, this_object, exception));
  return seed_make_undefined (ctx);
}
コード例 #21
0
static cairo_status_t
_cairo_boilerplate_xcb_finish_surface (cairo_surface_t *surface)
{
    xcb_target_closure_t *xtc = cairo_surface_get_user_data (surface,
							     &xcb_closure_key);
    xcb_generic_event_t *ev;

    if (xtc->surface != NULL) {
	cairo_t *cr;

	cr = cairo_create (xtc->surface);
	cairo_surface_set_device_offset (surface, 0, 0);
	cairo_set_source_surface (cr, surface, 0, 0);
	cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
	cairo_paint (cr);
	cairo_destroy (cr);

	surface = xtc->surface;
    }

    cairo_surface_flush (surface);
    if (cairo_surface_status (surface))
	return cairo_surface_status (surface);

    while ((ev = xcb_poll_for_event (xtc->c)) != NULL) {
	cairo_status_t status = CAIRO_STATUS_SUCCESS;

	if (ev->response_type == 0 /* trust me! */) {
	    xcb_generic_error_t *error = (xcb_generic_error_t *) ev;

#if XCB_GENERIC_ERROR_HAS_MAJOR_MINOR_CODES
	    fprintf (stderr,
		     "Detected error during xcb run: %d major=%d, minor=%d\n",
		     error->error_code, error->major_code, error->minor_code);
#else
	    fprintf (stderr,
		     "Detected error during xcb run: %d\n",
		     error->error_code);
#endif
	    free (error);

	    status = CAIRO_STATUS_WRITE_ERROR;
	}

	if (status)
	    return status;
    }

    if (xcb_connection_has_error (xtc->c))
	return CAIRO_STATUS_WRITE_ERROR;

    return CAIRO_STATUS_SUCCESS;
}
コード例 #22
0
ファイル: plotstuff.c プロジェクト: barentsen/astrometry.net
int plotstuff_output(plot_args_t* pargs) {
	switch (pargs->outformat) {
	case PLOTSTUFF_FORMAT_PDF:
		cairo_surface_flush(pargs->target);
		cairo_surface_finish(pargs->target);
		cairoutils_surface_status_errors(pargs->target);
		cairoutils_cairo_status_errors(pargs->cairo);
		if (pargs->outfn) {
			if (fclose(pargs->fout)) {
				SYSERROR("Failed to close output file \"%s\"", pargs->outfn);
				return -1;
			}
		}
		break;

	case PLOTSTUFF_FORMAT_JPG:
	case PLOTSTUFF_FORMAT_PPM:
	case PLOTSTUFF_FORMAT_PNG:
	case PLOTSTUFF_FORMAT_MEMIMG:
		{
			int res;
			unsigned char* img = cairo_image_surface_get_data(pargs->target);
			// Convert image for output...
 			cairoutils_argb32_to_rgba(img, pargs->W, pargs->H);
			if (pargs->outformat == PLOTSTUFF_FORMAT_MEMIMG) {
				pargs->outimage = img;
				res = 0;
				img = NULL;
			} else if (pargs->outformat == PLOTSTUFF_FORMAT_JPG) {
				res = cairoutils_write_jpeg(pargs->outfn, img, pargs->W, pargs->H);
			} else if (pargs->outformat == PLOTSTUFF_FORMAT_PPM) {
				res = cairoutils_write_ppm(pargs->outfn, img, pargs->W, pargs->H);
			} else if (pargs->outformat == PLOTSTUFF_FORMAT_PNG) {
				res = cairoutils_write_png(pargs->outfn, img, pargs->W, pargs->H);
			} else {
				res=-1; // for gcc
				assert(0);
			}
			if (res)
				ERROR("Failed to write output image");
			if (img)
				// Convert image back...
				cairoutils_rgba_to_argb32(img, pargs->W, pargs->H);
			return res;
		}
		break;
	default:
		ERROR("Unknown output format.");
		return -1;
	}
	return 0;
}
コード例 #23
0
ファイル: JSCairoSurface.cpp プロジェクト: artcom/y60
static JSBool
flush(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
    DOC_BEGIN("");
    DOC_END;
    cairo_surface_t *mySurface = NULL;
    convertFrom(cx, OBJECT_TO_JSVAL(obj), mySurface);

    ensureParamCount(argc, 0);

    cairo_surface_flush(mySurface);

    return checkForErrors(cx, mySurface);
}
コード例 #24
0
bool Image::loadFromImageData(ImageData* im)
{
	complete = false;
	_surface = cairo_image_surface_create_for_data(im->data, CAIRO_FORMAT_ARGB32, im->width, im->height, 4 * im->width);
	cairo_surface_flush(_surface);
	complete = (cairo_surface_status(_surface) == CAIRO_STATUS_SUCCESS);
	if (complete)
	{
		naturalWidth = width = cairo_image_surface_get_width(_surface);
		naturalHeight = height = cairo_image_surface_get_height(_surface);
	}
	return complete;
}
コード例 #25
0
ファイル: GtkDrawImage.cpp プロジェクト: dreamsxin/ultimatepp
cairo_surface_t *CreateCairoSurface(const Image& img)
{
	Size isz = img.GetSize();
	cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, isz.cx, isz.cy);
	cairo_surface_flush(surface);
	byte *a = (byte *)cairo_image_surface_get_data(surface);
	int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, isz.cx);
	for(int yy = 0; yy < isz.cy; yy++) {
		Copy((RGBA *)a, img[yy], isz.cx);
		a += stride;
	}
	cairo_surface_mark_dirty(surface);
	return surface;
}
コード例 #26
0
ファイル: plot.c プロジェクト: magnunleno/C-CairoPlot
/*
 * This function terminates the environment (Cairo Surface and Cairo main
 * object, cairo_t). It must be called at the end of the plot.
 * 		@context:
 * 			CP_Context which holds the pointers to the cairo structures, and
 * 			other plot settings.
 * 		@ft:
 * 			File Type, to be plotted. For supported filetypes check the util.h
 * 			file (_CP_FILETYPE_ structure).
 */
void cp_endEnv(CP_Context *context, CP_FileType ft)
{
	if (ft == CP_PNG){
		cp_addFileExtension(&(context->fname), context->name, ft);
		cairo_surface_write_to_png(context->surface, context->fname);
	}else{
		cairo_surface_flush(context->surface);
		cairo_surface_finish(context->surface);
	}
	cairo_destroy(context->cr);
	cairo_surface_destroy(context->surface);
	context->cr = NULL;
	context->surface = NULL;
}
コード例 #27
0
void ofCairoRenderer::update(){
	cairo_surface_flush(surface);
	if(page==0 || !multiPage){
		page=1;
	}else{
		page++;
		if(bClearBg()){
			cairo_show_page(cr);
		}else{
			cairo_copy_page(cr);
		}
	}
	ofSetStyle(ofGetStyle());
}
コード例 #28
0
static cairo_status_t
_cairo_surface_snapshot_flush (void *abstract_surface)
{
    cairo_surface_snapshot_t *surface = abstract_surface;
    cairo_surface_t *target;
    cairo_status_t status;

    target = _cairo_surface_snapshot_get_target (&surface->base);
    cairo_surface_flush (target);
    status = target->status;
    cairo_surface_destroy (target);

    return status;
}
コード例 #29
0
/** Refresh the window content by copying its pixmap data to its window.
 * \param drawin The drawin to refresh.
 * \param x The copy starting point x component.
 * \param y The copy starting point y component.
 * \param w The copy width from the x component.
 * \param h The copy height from the y component.
 */
void
drawin_refresh_pixmap_partial(drawin_t *drawin,
                              int16_t x, int16_t y,
                              uint16_t w, uint16_t h)
{
    if (!drawin->drawable || !drawin->drawable->pixmap || !drawin->drawable->refreshed)
        return;

    /* Make cairo do all pending drawing */
    cairo_surface_flush(drawin->drawable->surface);
    xcb_copy_area(globalconf.connection, drawin->drawable->pixmap,
                  drawin->window, globalconf.gc, x, y, x, y,
                  w, h);
}
コード例 #30
0
ファイル: bcard.c プロジェクト: pacew/bcard
int
main (int argc, char **argv)
{
	int c;
	int row, col;
	double x, y;
	char *outname;
		
	outname = "cards.pdf";

	while ((c = getopt (argc, argv, "n")) != EOF) {
		switch (c) {
		case 'n':
			draw_outline = 0;
			break;
		default:
			usage ();
		}
	}

	if (optind != argc)
		usage ();

	init_pdf (outname);
	setup_fonts ();

	code_surface
		= cairo_image_surface_create_from_png ("code-med-high.png");
	code_pattern = cairo_pattern_create_for_surface (code_surface);

	for (row = 0; row < 5; row++) {
		for (col = 0; col < 2; col++) {
			cairo_save (cr);

			x = LEFT_MARGIN + col * CARD_WIDTH;
			y = TOP_MARGIN + row * CARD_HEIGHT;
			cairo_translate (cr, x, y);
			draw_card ();

			cairo_restore (cr);
		}
	}

	cairo_destroy(cr);
	cairo_surface_flush(surface);
	cairo_surface_destroy(surface);
	printf ("evince %s\n", outname);
	return (0);
}