Pierre Ossman | 403ac27 | 2017-01-02 17:00:41 +0100 | [diff] [blame] | 1 | /* 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 |
| 26 | typedef struct CGImage* CGImageRef; |
| 27 | #else |
| 28 | #include <X11/extensions/Xrender.h> |
| 29 | #endif |
| 30 | |
| 31 | class Fl_RGB_Image; |
| 32 | |
| 33 | class Surface { |
| 34 | public: |
| 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); |
Pierre Ossman | 3d74d88 | 2017-01-02 19:49:52 +0100 | [diff] [blame^] | 45 | void draw(Surface* dst, int src_x, int src_y, int x, int y, int w, int h); |
Pierre Ossman | 403ac27 | 2017-01-02 17:00:41 +0100 | [diff] [blame] | 46 | |
| 47 | protected: |
| 48 | void alloc(); |
| 49 | void dealloc(); |
| 50 | void update(const Fl_RGB_Image* image); |
| 51 | |
| 52 | protected: |
| 53 | int w, h; |
| 54 | |
| 55 | #if defined(WIN32) |
| 56 | RGBQUAD* data; |
| 57 | HBITMAP bitmap; |
| 58 | #elif defined(__APPLE__) |
| 59 | unsigned char* data; |
| 60 | CGImageRef image; |
| 61 | #else |
| 62 | Pixmap pixmap; |
| 63 | Picture picture; |
| 64 | XRenderPictFormat* visFormat; |
| 65 | #endif |
| 66 | }; |
| 67 | |
| 68 | #endif |
| 69 | |