Added support for alignment in HUD items
[oweals/minetest.git] / src / hud.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef HUD_HEADER
21 #define HUD_HEADER
22
23 #include "irrlichttypes_extrabloated.h"
24
25 #define HUD_DIR_LEFT_RIGHT 0
26 #define HUD_DIR_RIGHT_LEFT 1
27 #define HUD_DIR_TOP_BOTTOM 2
28 #define HUD_DIR_BOTTOM_TOP 3
29
30 #define HUD_CORNER_UPPER  0
31 #define HUD_CORNER_LOWER  1
32 #define HUD_CORNER_CENTER 2
33
34 class Player;
35
36 enum HudElementType {
37         HUD_ELEM_IMAGE     = 0,
38         HUD_ELEM_TEXT      = 1,
39         HUD_ELEM_STATBAR   = 2,
40         HUD_ELEM_INVENTORY = 3
41 };
42
43 enum HudElementStat {
44         HUD_STAT_POS,
45         HUD_STAT_NAME,
46         HUD_STAT_SCALE,
47         HUD_STAT_TEXT,
48         HUD_STAT_NUMBER,
49         HUD_STAT_ITEM,
50         HUD_STAT_DIR,
51         HUD_STAT_ALIGN
52 };
53
54 struct HudElement {
55         HudElementType type;
56         v2f pos;
57         std::string name;
58         v2f scale;
59         std::string text;
60         u32 number;
61         u32 item;
62         u32 dir;
63         v2f align;
64 };
65
66
67 inline u32 hud_get_free_id(Player *player) {
68         size_t size = player->hud.size();
69         for (size_t i = 0; i != size; i++) {
70                 if (!player->hud[i])
71                         return i;
72         }
73         return size;
74 }
75
76 #ifndef SERVER
77
78 #include <deque>
79
80 #include <IGUIFont.h>
81
82 #include "gamedef.h"
83 #include "inventory.h"
84 #include "localplayer.h"
85
86 class Hud {
87 public:
88         video::IVideoDriver *driver;
89         gui::IGUIEnvironment *guienv;
90         gui::IGUIFont *font;
91         u32 text_height;
92         IGameDef *gamedef;
93         LocalPlayer *player;
94         Inventory *inventory;
95         
96         v2u32 screensize;
97         v2s32 displaycenter;
98         s32 hotbar_imagesize;
99         s32 hotbar_itemcount;
100         
101         video::SColor crosshair_argb;
102         video::SColor selectionbox_argb;
103         
104         Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv,
105                 gui::IGUIFont *font, u32 text_height, IGameDef *gamedef,
106                 LocalPlayer *player, Inventory *inventory);
107         
108         void drawItem(v2s32 upperleftpos, s32 imgsize, s32 itemcount,
109                 InventoryList *mainlist, u16 selectitem, u16 direction);
110         void drawLuaElements();
111         void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count);
112         
113         void drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem);
114         void resizeHotbar();
115         
116         void drawCrosshair();
117         void drawSelectionBoxes(std::vector<aabb3f> &hilightboxes);
118 };
119
120 #endif
121
122 #endif