~thumper/nux/more-leaks

« back to all changes in this revision

Viewing changes to Nux/CairoWrapper.h

  • Committer: Mirco Müller
  • Date: 2011-08-10 09:12:53 UTC
  • mfrom: (409.3.3 nux.cairo-wrapper)
  • Revision ID: mirco.mueller@ubuntu.com-20110810091253-t38tlcrwghempc8o
Added class nux::CairoWrapper, which is a complementary class to nux::Canvas.
It intentionally doesn't derive from nux::View and creates bitmaps and
textures based on the passed in nux::Geometry and cairo-drawing callback.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011 Canonical Ltd
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Mirco Müller <mirco.mueller@canonical.com
 
17
 */
 
18
 
 
19
#ifndef CAIRO_WRAPPER_H
 
20
#define CAIRO_WRAPPER_H
 
21
 
 
22
#include <cairo.h>
 
23
 
 
24
#include "Nux/Nux.h"
 
25
 
 
26
namespace nux
 
27
{
 
28
  typedef sigc::slot<void, Geometry const&, cairo_t*> DrawCanvasCallback;
 
29
 
 
30
  class CairoWrapper
 
31
  {
 
32
    public:
 
33
      CairoWrapper (Geometry const& geom, DrawCanvasCallback callback);
 
34
      ~CairoWrapper ();
 
35
 
 
36
      bool               Invalidate (Geometry const& geom);
 
37
      void               SetDrawCanvasCallback (DrawCanvasCallback callback);
 
38
      cairo_surface_t*   GetCairoSurface () const;
 
39
      cairo_t*           GetCairoContext () const;
 
40
      bool               DumpToFile (std::string const& filename);
 
41
      BaseTexture*       GetTexture () const;
 
42
      NBitmapData*       GetBitmap () const;
 
43
      bool               Recreate ();
 
44
 
 
45
    private:
 
46
      bool               CreateBitmap ();
 
47
 
 
48
    private:
 
49
      Geometry           geometry_;
 
50
      DrawCanvasCallback draw_canvas_callback_;
 
51
      cairo_t*           cr_;
 
52
      cairo_surface_t*   surface_;
 
53
      NBitmapData*       bitmap_;
 
54
      BaseTexture*       texture_;
 
55
  };
 
56
}
 
57
 
 
58
#endif // CAIRO_WRAPPER_H