]> git.lizzy.rs Git - minetest.git/blob - src/gui/guiScene.h
Improve a translation string
[minetest.git] / src / gui / guiScene.h
1 /*
2 Minetest
3 Copyright (C) 2020 Jean-Patrick Guerrero <jeanpatrick.guerrero@gmail.com>
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 #pragma once
21
22 #include "irrlichttypes_extrabloated.h"
23 #include "ICameraSceneNode.h"
24 #include "StyleSpec.h"
25
26 using namespace irr;
27
28 class GUIScene : public gui::IGUIElement
29 {
30 public:
31         GUIScene(gui::IGUIEnvironment *env, scene::ISceneManager *smgr,
32                  gui::IGUIElement *parent, core::recti rect, s32 id = -1);
33
34         ~GUIScene();
35
36         scene::IAnimatedMeshSceneNode *setMesh(scene::IAnimatedMesh *mesh = nullptr);
37         void setTexture(u32 idx, video::ITexture *texture);
38         void setBackgroundColor(const video::SColor &color) noexcept { m_bgcolor = color; };
39         void setFrameLoop(s32 begin, s32 end);
40         void setAnimationSpeed(f32 speed);
41         void enableMouseControl(bool enable) noexcept { m_mouse_ctrl = enable; };
42         void setRotation(v2f rot) noexcept { m_custom_rot = rot; };
43         void enableContinuousRotation(bool enable) noexcept { m_inf_rot = enable; };
44         void setStyles(const std::array<StyleSpec, StyleSpec::NUM_STATES> &styles);
45
46         virtual void draw();
47         virtual bool OnEvent(const SEvent &event);
48
49 private:
50         void calcOptimalDistance();
51         void updateTargetPos();
52         void updateCamera(scene::ISceneNode *target);
53         void setCameraRotation(v3f rot);
54         /// @return true indicates that the rotation was corrected
55         bool correctBounds(v3f &rot);
56         void cameraLoop();
57
58         void updateCameraPos() { m_cam_pos = m_cam->getPosition(); };
59         v3f getCameraRotation() const { return (m_cam_pos - m_target_pos).getHorizontalAngle(); };
60         void rotateCamera(const v3f &delta) { setCameraRotation(getCameraRotation() + delta); };
61
62         scene::ISceneManager *m_smgr;
63         video::IVideoDriver *m_driver;
64         scene::ICameraSceneNode *m_cam;
65         scene::ISceneNode *m_target = nullptr;
66         scene::IAnimatedMeshSceneNode *m_mesh = nullptr;
67
68         f32 m_cam_distance = 50.f;
69
70         u64 m_last_time = 0;
71
72         v3f m_cam_pos;
73         v3f m_target_pos;
74         v3f m_last_target_pos;
75         // Cursor positions
76         v2f m_curr_pos;
77         v2f m_last_pos;
78         // Initial rotation
79         v2f m_custom_rot;
80
81         bool m_mouse_ctrl = true;
82         bool m_update_cam = false;
83         bool m_inf_rot    = false;
84         bool m_initial_rotation = true;
85
86         video::SColor m_bgcolor = 0;
87 };