blob: 02917e3127c6b2cc9e16734cef8a5df680b5092f [file] [log] [blame]
Pierre Ossman403ac272017-01-02 17:00:41 +01001/* Copyright 2016 Pierre Ossman for Cendio AB
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software 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 software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19#ifndef __SURFACE_H__
20#define __SURFACE_H__
21
22#if defined(WIN32)
23#include <windows.h>
24#elif defined(__APPLE__)
25// Apple headers conflict with FLTK, so redefine types here
26typedef struct CGImage* CGImageRef;
27#else
28#include <X11/extensions/Xrender.h>
29#endif
30
31class Fl_RGB_Image;
32
33class Surface {
34public:
35 Surface(int width, int height);
36 Surface(const Fl_RGB_Image* image);
37 ~Surface();
38
39 int width() { return w; }
40 int height() { return h; }
41
42 void clear(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255);
43
44 void draw(int src_x, int src_y, int x, int y, int w, int h);
45
46protected:
47 void alloc();
48 void dealloc();
49 void update(const Fl_RGB_Image* image);
50
51protected:
52 int w, h;
53
54#if defined(WIN32)
55 RGBQUAD* data;
56 HBITMAP bitmap;
57#elif defined(__APPLE__)
58 unsigned char* data;
59 CGImageRef image;
60#else
61 Pixmap pixmap;
62 Picture picture;
63 XRenderPictFormat* visFormat;
64#endif
65};
66
67#endif
68