1 // Copyright (C) 2009-2012, 2014, 2015, 2017, 2020 Ben Asselstine 2 // 3 // This program 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 3 of the License, or 6 // (at your option) any later version. 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 Library 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, write to the Free Software 15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 16 // 02110-1301, USA. 17 18 #pragma once 19 #ifndef PIXMASK_H 20 #define PIXMASK_H 21 22 #include <gtkmm.h> 23 #include "vector.h" 24 #include "rectangle.h" 25 #include <cairomm/cairomm.h> 26 27 28 //! A pixmap and bitmask pair. 29 /** 30 */ 31 class PixMask 32 { 33 public: get_pixmap()34 Cairo::RefPtr<Cairo::Surface> get_pixmap() {return pixmap;}; get_mask()35 Cairo::RefPtr<Cairo::Surface> get_mask() {return mask;}; get_gc()36 Cairo::RefPtr<Cairo::Context> get_gc() {return gc;}; get_width()37 int get_width() {return width;}; get_height()38 int get_height() {return height;}; get_unscaled_width()39 int get_unscaled_width() {return unscaled_width;}; get_unscaled_height()40 int get_unscaled_height() {return unscaled_height;}; 41 int get_depth(); 42 43 static PixMask* create(Glib::ustring file, bool &broken); 44 static PixMask* create(Glib::RefPtr<Gdk::Pixbuf> buf); 45 static PixMask* create(Cairo::RefPtr<Cairo::Surface> pixmap, 46 Cairo::RefPtr<Cairo::Surface> mask); 47 PixMask* copy(); 48 49 //! convert this pixmask to a pixbuf. 50 Glib::RefPtr<Gdk::Pixbuf> to_pixbuf(); 51 52 //! draw a pixbuf onto this pixmask. 53 void draw_pixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf, int src_x, int src_y, int dest_x, int dest_y, int width, int height); 54 55 //! scale a pixmask in place (alters pixmask) 56 static void scale(PixMask*& pixmask, int xsize, int ysize, Gdk::InterpType intper = Gdk::INTERP_BILINEAR); 57 58 //! draw this pixmask onto a pixmap. 59 void blit(Cairo::RefPtr<Cairo::Surface> pixmap, int dest_x, int dest_y); 60 void blit(Cairo::RefPtr<Cairo::Surface> pixmap, Vector<int> pos = Vector<int>(0,0)); 61 void blit_centered(Cairo::RefPtr<Cairo::Surface> pixmap, Vector<int> pos); 62 //blit a tile's worth of imagery from this pixmask to a pixmap. 63 void blit(Vector<int> tile, int ts, Cairo::RefPtr<Cairo::Surface> pixmap, Vector<int> dest = Vector<int>(0,0)); 64 65 Vector<int> get_dim() const; 66 Vector<int> get_unscaled_dim() const; 67 //! Destructor. 68 ~PixMask(); 69 protected: 70 //! Default constructor. 71 PixMask(Glib::RefPtr<Gdk::Pixbuf> pixbuf); 72 73 //! Alternative constructor. 74 PixMask(Cairo::RefPtr<Cairo::Surface> pixmap, Cairo::RefPtr<Cairo::Surface> mask); 75 76 //! Copy constructor. 77 PixMask(const PixMask&); 78 79 //! Loading constructor. 80 /** 81 * Load the pixmask from a file. 82 * 83 */ 84 PixMask(Glib::ustring filename, bool &broken); 85 set_unscaled_width(guint32 w)86 void set_unscaled_width(guint32 w) {unscaled_width = w;}; set_unscaled_height(guint32 h)87 void set_unscaled_height(guint32 h) {unscaled_height = h;}; 88 89 private: 90 Cairo::RefPtr<Cairo::Surface> pixmap; 91 Cairo::RefPtr<Cairo::Surface> mask; 92 Cairo::RefPtr<Cairo::Context> gc; 93 int width; 94 int height; 95 int unscaled_width; 96 int unscaled_height; 97 98 //! return a stretched copy of this pixmask. 99 PixMask* scale(int xsize, int ysize, 100 Gdk::InterpType interp = Gdk::INTERP_NEAREST); 101 102 void blit(LwRectangle src, Cairo::RefPtr<Cairo::Surface> pixmap, Vector<int> dest); 103 }; 104 105 #endif 106