Luanti 5.15.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 <CMeshBuffer.h>
12#include "irr_ptr.h"
13#include "irr_aabb3d.h"
14#include "hud_element.h"
15
16class Client;
17class ITextureSource;
18class Inventory;
19class InventoryList;
20class LocalPlayer;
21struct ItemStack;
22
23namespace scene
24{
25 class IMesh;
26}
27
28namespace 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
78 {
80 }
81
86
87 void setSelectionMeshColor(const video::SColor &color)
88 {
90 }
91
92 void setSelectedFaceNormal(const v3f &face_normal)
93 {
94 m_selected_face_normal = face_normal;
95 }
96
98
99 void drawLuaElements(const v3s16 &camera_offset);
100
101private:
102 bool calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *pos);
103 void drawStatbar(v2s32 pos, u16 corner, u16 drawdir,
104 const std::string &texture, const std::string& bgtexture,
105 s32 count, s32 maxcount, v2s32 offset, v2s32 size = v2s32());
106
107 void drawItems(v2s32 screen_pos, v2s32 screen_offset, s32 itemcount, v2f alignment,
108 s32 inv_offset, InventoryList *mainlist, u16 selectitem,
109 u16 direction, bool is_hotbar);
110
111 void drawItem(const ItemStack &item, const core::rect<s32> &rect, bool selected);
112
113 void drawCompassTranslate(HudElement *e, video::ITexture *texture,
114 const core::rect<s32> &rect, int way);
115
116 void drawCompassRotate(HudElement *e, video::ITexture *texture,
117 const core::rect<s32> &rect, int way);
118
119 Client *client = nullptr;
120 video::IVideoDriver *driver = nullptr;
121 LocalPlayer *player = nullptr;
124
125 float m_hud_scaling; // cached minetest setting
130 s32 m_hotbar_imagesize; // Takes hud_scaling into account, updated by resizeHotbar()
131 s32 m_padding; // Takes hud_scaling into account, updated by resizeHotbar()
132 video::SColor hbar_colors[4];
133
134 std::vector<aabb3f> m_selection_boxes;
135 std::vector<aabb3f> m_halo_boxes;
139
140 scene::IMesh *m_selection_mesh = nullptr;
143
144 video::SMaterial m_selection_material;
145 video::SMaterial m_block_bounds_material;
146
147 irr_ptr<scene::SMeshBuffer> m_rotation_mesh_buffer;
148
149 enum
150 {
155};
Definition client.h:106
Definition hud.h:35
video::SColor m_selection_mesh_color
Definition hud.h:141
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:235
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:309
scene::IMesh * m_selection_mesh
Definition hud.h:140
void drawSelectionMesh()
Definition hud.cpp:875
ITextureSource * tsrc
Definition hud.h:123
~Hud()
Definition hud.cpp:148
void readScalingSetting()
Definition hud.cpp:138
bool pointing_at_object
Definition hud.h:54
v3f m_selected_face_normal
Definition hud.h:142
video::IVideoDriver * driver
Definition hud.h:120
void setSelectionMeshColor(const video::SColor &color)
Definition hud.h:87
std::vector< aabb3f > m_selection_boxes
Definition hud.h:134
enum BlockBoundsMode toggleBlockBounds()
Definition hud.cpp:917
v3f m_selection_pos
Definition hud.h:136
irr_ptr< scene::SMeshBuffer > m_rotation_mesh_buffer
Definition hud.h:147
bool calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *pos)
Definition hud.cpp:319
void drawItem(const ItemStack &item, const core::rect< s32 > &rect, bool selected)
Definition hud.cpp:156
Hud(Client *client, LocalPlayer *player, Inventory *inventory)
Definition hud.cpp:40
@ HIGHLIGHT_NONE
Definition hud.h:153
@ HIGHLIGHT_BOX
Definition hud.h:151
@ HIGHLIGHT_HALO
Definition hud.h:152
v2s32 m_displaycenter
Definition hud.h:129
bool use_crosshair_image
Definition hud.h:47
void setSelectionPos(const v3f &pos, const v3s16 &camera_offset)
Definition hud.cpp:868
Inventory * inventory
Definition hud.h:122
void drawLuaElements(const v3s16 &camera_offset)
Definition hud.cpp:338
s32 m_hotbar_imagesize
Definition hud.h:130
v3f getSelectionRotationRadians() const
Definition hud.h:82
void drawCrosshair()
Definition hud.cpp:817
bool use_object_crosshair_image
Definition hud.h:48
enum Hud::BlockBoundsMode m_block_bounds_mode
video::SColor crosshair_argb
Definition hud.h:44
float m_scale_factor
Definition hud.h:126
void resizeHotbar()
Definition hud.cpp:1032
enum Hud::@17 m_mode
v3s16 m_camera_offset
Definition hud.h:127
void drawCompassTranslate(HudElement *e, video::ITexture *texture, const core::rect< s32 > &rect, int way)
Definition hud.cpp:582
void drawBlockBounds()
Definition hud.cpp:932
v2u32 m_screensize
Definition hud.h:128
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:651
void setSelectionRotationRadians(v3f rotation)
Definition hud.h:77
void updateSelectionMesh(const v3s16 &camera_offset)
Definition hud.cpp:987
void setSelectedFaceNormal(const v3f &face_normal)
Definition hud.h:92
std::string hotbar_selected_image
Definition hud.h:51
void disableBlockBounds()
Definition hud.cpp:927
LocalPlayer * player
Definition hud.h:121
video::SMaterial m_block_bounds_material
Definition hud.h:145
void drawCompassRotate(HudElement *e, video::ITexture *texture, const core::rect< s32 > &rect, int way)
Definition hud.cpp:622
video::SMaterial m_selection_material
Definition hud.h:144
v3f m_selection_rotation_radians
Definition hud.h:138
std::string hotbar_image
Definition hud.h:49
video::SColor hbar_colors[4]
Definition hud.h:132
float m_hud_scaling
Definition hud.h:125
s32 m_padding
Definition hud.h:131
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:784
v3f getSelectionPos() const
Definition hud.h:75
v3f m_selection_pos_with_offset
Definition hud.h:137
std::vector< aabb3f > m_halo_boxes
Definition hud.h:135
Definition texturesource.h:45
Definition inventory.h:157
Definition inventory.h:277
Definition localplayer.h:48
HudElementType
Definition hud_element.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 camera.h:24
Definition clientmap.h:36
Definition hud_element.h:84
Definition inventory.h:21