fix firetux not being able to pickup stuff
[supertux.git] / src / display_manager.h
1 //  $Id$
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2004 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 #ifndef __DISPLAY_MANAGER_H__
20 #define __DISPLAY_MANAGER_H__
21
22 #include <vector>
23
24 #include "drawable.h"
25 #include "viewport.h"
26
27 // some constants for predefined layer values
28 enum {
29   LAYER_BACKGROUND0 = -300,
30   LAYER_BACKGROUND1 = -200,
31   LAYER_BACKGROUNDTILES = -100,
32   LAYER_TILES = 0,
33   LAYER_OBJECTS = 100,
34   LAYER_FOREGROUNDTILES = 200,
35   LAYER_FOREGROUND0 = 300,
36   LAYER_FOREGROUND1 = 400
37 };
38
39 /** This class holds a list of all things that should be drawn to screen
40  */
41 class DisplayManager
42 {
43 public:
44   DisplayManager();
45   ~DisplayManager();
46   
47   /** adds an object to the list of stuff that should be drawn each frame.
48    * The layer argument specifies how early an object is drawn.
49    */
50   void add_drawable(Drawable* object, int layer);
51
52   void remove_drawable(Drawable* object);
53
54   void draw();
55
56   ViewPort& get_viewport()
57   { return viewport; }
58
59 private:
60   class DrawingQueueEntry {
61   public:
62     DrawingQueueEntry(Drawable* newobject, int newlayer)
63       : object(newobject), layer(newlayer)
64     { }
65
66     bool operator <(int olayer) const
67     {
68       return layer < olayer;
69     }
70
71     Drawable* object;
72     int layer;
73   };
74
75   typedef std::vector<DrawingQueueEntry> DisplayList;
76   DisplayList displaylist;
77   ViewPort viewport;
78 };
79
80 #endif
81