Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
hud.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4// Copyright (C) 2017 red-001 <red-001@outlook.ie>
5
6#pragma once
7
8#include <vector>
9#include <IGUIFont.h>
10#include <SMaterial.h>
11#include <SMeshBuffer.h>
12#include "irr_ptr.h"
13#include "irr_aabb3d.h"
14#include "../hud.h"
15
16class Client;
17class ITextureSource;
18class Inventory;
19class InventoryList;
20class LocalPlayer;
21struct ItemStack;
22
23namespace irr::scene
24{
25 class IMesh;
26}
27
28namespace irr::video
29{
30 class ITexture;
31 class IVideoDriver;
32}
33
34class Hud
35{
36public:
43
44 video::SColor crosshair_argb;
45 video::SColor selectionbox_argb;
46
47 bool use_crosshair_image = false;
49 std::string hotbar_image = "";
50 bool use_hotbar_image = false;
51 std::string hotbar_selected_image = "";
53
54 bool pointing_at_object = false;
55
58 void readScalingSetting();
59 ~Hud();
60
62 void disableBlockBounds();
63 void drawBlockBounds();
64
65 void drawHotbar(const v2s32 &pos, const v2f &offset, u16 direction, const v2f &align);
66 void resizeHotbar();
67 void drawCrosshair();
68 void drawSelectionMesh();
69 void updateSelectionMesh(const v3s16 &camera_offset);
70
71 std::vector<aabb3f> *getSelectionBoxes() { return &m_selection_boxes; }
72
73 void setSelectionPos(const v3f &pos, const v3s16 &camera_offset);
74
76
77 void setSelectionRotation(v3f rotation) { m_selection_rotation = rotation; }
78
80
81 void setSelectionMeshColor(const video::SColor &color)
82 {
84 }
85
86 void setSelectedFaceNormal(const v3f &face_normal)
87 {
88 m_selected_face_normal = face_normal;
89 }
90
92
93 void drawLuaElements(const v3s16 &camera_offset);
94
95private:
96 bool calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *pos);
97 void drawStatbar(v2s32 pos, u16 corner, u16 drawdir,
98 const std::string &texture, const std::string& bgtexture,
99 s32 count, s32 maxcount, v2s32 offset, v2s32 size = v2s32());
100
101 void drawItems(v2s32 screen_pos, v2s32 screen_offset, s32 itemcount, v2f alignment,
102 s32 inv_offset, InventoryList *mainlist, u16 selectitem,
103 u16 direction, bool is_hotbar);
104
105 void drawItem(const ItemStack &item, const core::rect<s32> &rect, bool selected);
106
107 void drawCompassTranslate(HudElement *e, video::ITexture *texture,
108 const core::rect<s32> &rect, int way);
109
110 void drawCompassRotate(HudElement *e, video::ITexture *texture,
111 const core::rect<s32> &rect, int way);
112
113 Client *client = nullptr;
114 video::IVideoDriver *driver = nullptr;
115 LocalPlayer *player = nullptr;
118
119 float m_hud_scaling; // cached minetest setting
124 s32 m_hotbar_imagesize; // Takes hud_scaling into account, updated by resizeHotbar()
125 s32 m_padding; // Takes hud_scaling into account, updated by resizeHotbar()
126 video::SColor hbar_colors[4];
127
128 std::vector<aabb3f> m_selection_boxes;
129 std::vector<aabb3f> m_halo_boxes;
133
134 scene::IMesh *m_selection_mesh = nullptr;
137
138 video::SMaterial m_selection_material;
139 video::SMaterial m_block_bounds_material;
140
141 irr_ptr<scene::SMeshBuffer> m_rotation_mesh_buffer;
142
143 enum
144 {
149};
150
159
160void drawItemStack(video::IVideoDriver *driver,
161 gui::IGUIFont *font,
162 const ItemStack &item,
163 const core::rect<s32> &rect,
164 const core::rect<s32> *clip,
165 Client *client,
166 ItemRotationKind rotation_kind);
167
168void drawItemStack(
169 video::IVideoDriver *driver,
170 gui::IGUIFont *font,
171 const ItemStack &item,
172 const core::rect<s32> &rect,
173 const core::rect<s32> *clip,
174 Client *client,
175 ItemRotationKind rotation_kind,
176 const v3s16 &angle,
177 const v3s16 &rotation_speed);
178
Definition client.h:105
Definition hud.h:35
video::SColor m_selection_mesh_color
Definition hud.h:135
void drawItems(v2s32 screen_pos, v2s32 screen_offset, s32 itemcount, v2f alignment, s32 inv_offset, InventoryList *mainlist, u16 selectitem, u16 direction, bool is_hotbar)
Definition hud.cpp:243
BlockBoundsMode
Definition hud.h:38
@ BLOCK_BOUNDS_NEAR
Definition hud.h:41
@ BLOCK_BOUNDS_CURRENT
Definition hud.h:40
@ BLOCK_BOUNDS_OFF
Definition hud.h:39
bool hasElementOfType(HudElementType type)
Definition hud.cpp:317
v3f m_selection_rotation
Definition hud.h:132
scene::IMesh * m_selection_mesh
Definition hud.h:134
void drawSelectionMesh()
Definition hud.cpp:881
ITextureSource * tsrc
Definition hud.h:117
~Hud()
Definition hud.cpp:156
void readScalingSetting()
Definition hud.cpp:146
bool pointing_at_object
Definition hud.h:54
v3f m_selected_face_normal
Definition hud.h:136
video::IVideoDriver * driver
Definition hud.h:114
void setSelectionMeshColor(const video::SColor &color)
Definition hud.h:81
std::vector< aabb3f > m_selection_boxes
Definition hud.h:128
enum BlockBoundsMode toggleBlockBounds()
Definition hud.cpp:925
v3f m_selection_pos
Definition hud.h:130
irr_ptr< scene::SMeshBuffer > m_rotation_mesh_buffer
Definition hud.h:141
bool calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *pos)
Definition hud.cpp:330
void drawItem(const ItemStack &item, const core::rect< s32 > &rect, bool selected)
Definition hud.cpp:164
Hud(Client *client, LocalPlayer *player, Inventory *inventory)
Definition hud.cpp:39
v2s32 m_displaycenter
Definition hud.h:123
bool use_crosshair_image
Definition hud.h:47
void setSelectionPos(const v3f &pos, const v3s16 &camera_offset)
Definition hud.cpp:874
Inventory * inventory
Definition hud.h:116
void drawLuaElements(const v3s16 &camera_offset)
Definition hud.cpp:349
s32 m_hotbar_imagesize
Definition hud.h:124
void setSelectionRotation(v3f rotation)
Definition hud.h:77
void drawCrosshair()
Definition hud.cpp:823
bool use_object_crosshair_image
Definition hud.h:48
enum Hud::BlockBoundsMode m_block_bounds_mode
video::SColor crosshair_argb
Definition hud.h:44
v3f getSelectionRotation() const
Definition hud.h:79
float m_scale_factor
Definition hud.h:120
void resizeHotbar()
Definition hud.cpp:1048
v3s16 m_camera_offset
Definition hud.h:121
void drawCompassTranslate(HudElement *e, video::ITexture *texture, const core::rect< s32 > &rect, int way)
Definition hud.cpp:588
void drawBlockBounds()
Definition hud.cpp:940
v2u32 m_screensize
Definition hud.h:122
video::SColor selectionbox_argb
Definition hud.h:45
bool use_hotbar_image
Definition hud.h:50
void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, const std::string &texture, const std::string &bgtexture, s32 count, s32 maxcount, v2s32 offset, v2s32 size=v2s32())
Definition hud.cpp:657
void updateSelectionMesh(const v3s16 &camera_offset)
Definition hud.cpp:1003
void setSelectedFaceNormal(const v3f &face_normal)
Definition hud.h:86
std::string hotbar_selected_image
Definition hud.h:51
void disableBlockBounds()
Definition hud.cpp:935
@ HIGHLIGHT_NONE
Definition hud.h:147
@ HIGHLIGHT_BOX
Definition hud.h:145
@ HIGHLIGHT_HALO
Definition hud.h:146
LocalPlayer * player
Definition hud.h:115
enum Hud::@16 m_mode
video::SMaterial m_block_bounds_material
Definition hud.h:139
void drawCompassRotate(HudElement *e, video::ITexture *texture, const core::rect< s32 > &rect, int way)
Definition hud.cpp:628
video::SMaterial m_selection_material
Definition hud.h:138
std::string hotbar_image
Definition hud.h:49
video::SColor hbar_colors[4]
Definition hud.h:126
float m_hud_scaling
Definition hud.h:119
s32 m_padding
Definition hud.h:125
std::vector< aabb3f > * getSelectionBoxes()
Definition hud.h:71
bool use_hotbar_selected_image
Definition hud.h:52
void drawHotbar(const v2s32 &pos, const v2f &offset, u16 direction, const v2f &align)
Definition hud.cpp:790
v3f getSelectionPos() const
Definition hud.h:75
v3f m_selection_pos_with_offset
Definition hud.h:131
std::vector< aabb3f > m_halo_boxes
Definition hud.h:129
Definition texturesource.h:36
Definition inventory.h:194
Definition inventory.h:314
Definition localplayer.h:49
void drawItemStack(video::IVideoDriver *driver, gui::IGUIFont *font, const ItemStack &item, const core::rect< s32 > &rect, const core::rect< s32 > *clip, Client *client, ItemRotationKind rotation_kind)
Definition hud.cpp:1339
ItemRotationKind
Definition hud.h:152
@ IT_ROT_OTHER
Definition hud.h:156
@ IT_ROT_NONE
Definition hud.h:157
@ IT_ROT_HOVERED
Definition hud.h:154
@ IT_ROT_DRAGGED
Definition hud.h:155
@ IT_ROT_SELECTED
Definition hud.h:153
HudElementType
Definition hud.h:47
core::vector2d< s32 > v2s32
Definition irr_v2d.h:13
core::vector2d< f32 > v2f
Definition irr_v2d.h:11
core::vector2d< u32 > v2u32
Definition irr_v2d.h:14
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
core::vector3df v3f
Definition irr_v3d.h:11
Definition activeobjectmgr.cpp:11
Definition clientmap.h:30
Definition clientmap.h:35
Definition hud.h:84
Definition inventory.h:19