Storing and repainting a rectangular region of interest

David Weiß <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <E8D289FB71C3004B832D1702922D3A200313C1D6F7@SKA-WN-E25CEX.ptvag.ptv.de>
Hello,

I have the following problem:
I have to integrate cairo into an existing rendering application so I need to stick to the applications API as close as possible.
It requires me to implement two functions which work on rectangles:
The first gets a rectangle specification (x,y,width,height) and needs to save that exact area of the painted surface somehow, the second just restores the last saved rectangle.

My (not working) implementation looks like this:

void CairoEngine::SaveRegion(ptvlib::CRectI region)
{
    cairo_surface_t* saved_surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, region.Width(), region.Height());
    cairo_t* saved_context = cairo_create(saved_surface);

    cairo_set_source_surface(saved_context, win32_surface, -region.left, -region.top);
    cairo_set_operator(saved_context, CAIRO_OPERATOR_SOURCE);
    cairo_paint(saved_context);
    cairo_surface_flush(saved_surface);
    cairo_destroy(saved_context);

    saved_regions.push(std::make_pair(region, saved_surface));
}

void CairoEngine::ReplayRegion()
{
    if(saved_regions.empty()) return;
    ptvlib::CRectI region = saved_regions.top().first;
    cairo_surface_t* saved_surface = saved_regions.top().second;

    cairo_save(win32_context);
    cairo_set_operator(win32_context, CAIRO_OPERATOR_SOURCE);
    cairo_set_source_surface(win32_context, saved_surface, region.left, region.bottom);
    cairo_paint(win32_context);
   cairo_surface_flush(win32_surface);
    cairo_surface_destroy(saved_surface);
    cairo_restore(win32_context);

    saved_regions.pop();
}

Any hints what I'm doing wrong?

Cheers,
--
David Weiß

Logistics Geographic Components
PTV GROUP

Haid-und-Neu-Str. 15, 76131 Karlsruhe, Germany

Phone +49 (0) 721 9651-7416

[email protected]<mailto:[email protected]>
www.ptvgroup.com<http://www.ptvgroup.com/>
http://www.facebook.com/pages/PTV-AG/308012842618

PTV Planung Transport Verkehr AG
Headquarters: Karlsruhe
Executive Board: Vincent Kobesen (CEO), Dr.-Ing. Thomas Schwerdtfeger
Chairman of the Supervisory Board: Dr. h.c. Frank-Jürgen Weise
Commercial Register (HRB-Nr): 109262
Local Court: Mannheim

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.