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 width()39 int width() { return w; } height()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 void draw(Surface* dst, int src_x, int src_y, int x, int y, int w, int h); 46 47 void blend(int src_x, int src_y, int x, int y, int w, int h, int a=255); 48 void blend(Surface* dst, int src_x, int src_y, int x, int y, int w, int h, int a=255); 49 50 protected: 51 void alloc(); 52 void dealloc(); 53 void update(const Fl_RGB_Image* image); 54 55 protected: 56 int w, h; 57 58 #if defined(WIN32) 59 RGBQUAD* data; 60 HBITMAP bitmap; 61 #elif defined(__APPLE__) 62 unsigned char* data; 63 #else 64 Pixmap pixmap; 65 Picture picture; 66 XRenderPictFormat* visFormat; 67 #endif 68 }; 69 70 #endif 71 72