initial commit, lordsawar source, slightly modified
[lordsawar] / src / PixMask.h
1 // Copyright (C) 2009 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 #ifndef PIXMASK_H
18 #define PIXMASK_H
19
20 #include <gtkmm.h>
21 #include "vector.h"
22 #include "rectangle.h"
23
24
25 //! A pixmap and bitmask pair.
26 /** 
27  */
28 class PixMask
29 {
30  public:
31      Glib::RefPtr<Gdk::Pixmap> get_pixmap() {return pixmap;};
32      Glib::RefPtr<Gdk::Bitmap> get_mask() {return mask;};
33      Glib::RefPtr<Gdk::GC> get_gc() {return gc;};
34      int get_width() {return width;};
35      int get_height() {return height;};
36      int get_depth();
37
38      static PixMask* create(std::string file);
39      static PixMask* create(Glib::RefPtr<Gdk::Pixbuf> buf);
40      static PixMask* create(Glib::RefPtr<Gdk::Pixmap> pixmap,
41                                          Glib::RefPtr<Gdk::Bitmap> mask);
42      PixMask* copy();
43
44      //! convert this pixmask to a pixbuf.
45      Glib::RefPtr<Gdk::Pixbuf> to_pixbuf();
46
47      //! draw a pixbuf onto this pixmask.
48      void draw_pixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf, int src_x, int src_y, int dest_x, int dest_y, int width, int height);
49
50      //! scale a pixmask in place (alters pixmask)
51      static void scale(PixMask*& pixmask, int xsize, int ysize, Gdk::InterpType intper = Gdk::INTERP_NEAREST);
52
53      //! draw this pixmask onto a pixmap.
54      void blit(Glib::RefPtr<Gdk::Pixmap> pixmap, int dest_x, int dest_y);
55      void blit(Glib::RefPtr<Gdk::Pixmap> pixmap, Vector<int> pos = Vector<int>(0,0));
56      void blit_centered(Glib::RefPtr<Gdk::Pixmap> pixmap, Vector<int> pos);
57      // blit a tile's worth of imagery from this pixmask to a pixmap.
58      void blit(Vector<int> tile, int ts, Glib::RefPtr<Gdk::Pixmap> pixmap, Vector<int> dest = Vector<int>(0,0));
59
60      //! Destructor.
61     ~PixMask();
62  protected:
63      //! Default constructor.
64      PixMask(Glib::RefPtr<Gdk::Pixbuf> pixbuf);
65
66      //! Alternative constructor.
67      PixMask(Glib::RefPtr<Gdk::Pixmap> pixmap, Glib::RefPtr<Gdk::Bitmap> mask);
68
69      //! Copy constructor.
70      PixMask(const PixMask&);
71
72      //! Loading constructor.
73      /**
74       * Load the pixmask from a file.
75       *
76       */
77      PixMask(std::string filename);
78
79     
80  private:
81     Glib::RefPtr<Gdk::Pixmap> pixmap;
82     Glib::RefPtr<Gdk::Bitmap> mask;
83     Glib::RefPtr<Gdk::GC> gc;
84     int width;
85     int height;
86
87      //! return a stretched copy of this pixmask.
88      PixMask* scale(int xsize, int ysize, 
89                     Gdk::InterpType interp = Gdk::INTERP_NEAREST);
90      
91      void blit(Rectangle src, Glib::RefPtr<Gdk::Pixmap> pixmap, Vector<int> dest);
92 };
93
94 #endif