RigsofRods
Soft-body Physics Simulation
OgreImGui.cpp
Go to the documentation of this file.
1 
2 // -------------------------------------------
3 // OGRE-IMGUI bindings
4 // See file 'README-OgreImGui.txt' for details
5 // -------------------------------------------
6 
7 /*
8  This source file is part of Rigs of Rods
9  Copyright 2016-2020 Petr Ohlidal
10 
11  For more information, see http://www.rigsofrods.org/
12 
13  Rigs of Rods is free software: you can redistribute it and/or modify
14  it under the terms of the GNU General Public License version 3, as
15  published by the Free Software Foundation.
16 
17  Rigs of Rods is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
24 */
25 
26 #include "OgreImGui.h"
27 
28 #include "Actor.h"
29 #include "AppContext.h"
30 #include "ContentManager.h"
31 #include "OgreImGuiOverlay.h"
32 
33 #include <imgui.h>
34 #include <Ogre.h>
35 
36 using namespace RoR;
37 
39 {
40  m_imgui_overlay = std::unique_ptr<Ogre::ImGuiOverlay>(new Ogre::ImGuiOverlay());
41 
42  ImGuiIO& io = ImGui::GetIO();
43 
44  // Disable 'imgui.ini' - we don't need to persist window positions.
45  io.IniFilename = nullptr;
46 
47  // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime.
48  io.KeyMap[ImGuiKey_Tab] = OIS::KC_TAB;
49  io.KeyMap[ImGuiKey_LeftArrow] = OIS::KC_LEFT;
50  io.KeyMap[ImGuiKey_RightArrow] = OIS::KC_RIGHT;
51  io.KeyMap[ImGuiKey_UpArrow] = OIS::KC_UP;
52  io.KeyMap[ImGuiKey_DownArrow] = OIS::KC_DOWN;
53  io.KeyMap[ImGuiKey_PageUp] = OIS::KC_PGUP;
54  io.KeyMap[ImGuiKey_PageDown] = OIS::KC_PGDOWN;
55  io.KeyMap[ImGuiKey_Home] = OIS::KC_HOME;
56  io.KeyMap[ImGuiKey_End] = OIS::KC_END;
57  io.KeyMap[ImGuiKey_Delete] = OIS::KC_DELETE;
58  io.KeyMap[ImGuiKey_Backspace] = OIS::KC_BACK;
59  io.KeyMap[ImGuiKey_Enter] = OIS::KC_RETURN;
60  io.KeyMap[ImGuiKey_Escape] = OIS::KC_ESCAPE;
61  io.KeyMap[ImGuiKey_A] = OIS::KC_A;
62  io.KeyMap[ImGuiKey_C] = OIS::KC_C;
63  io.KeyMap[ImGuiKey_V] = OIS::KC_V;
64  io.KeyMap[ImGuiKey_X] = OIS::KC_X;
65  io.KeyMap[ImGuiKey_Y] = OIS::KC_Y;
66  io.KeyMap[ImGuiKey_Z] = OIS::KC_Z;
67  io.KeyMap[ImGuiKey_KeyPad0] = OIS::KC_NUMPAD0;
68  io.KeyMap[ImGuiKey_KeyPad1] = OIS::KC_NUMPAD1;
69  io.KeyMap[ImGuiKey_KeyPad2] = OIS::KC_NUMPAD2;
70  io.KeyMap[ImGuiKey_KeyPad3] = OIS::KC_NUMPAD3;
71  io.KeyMap[ImGuiKey_KeyPad4] = OIS::KC_NUMPAD4;
72  io.KeyMap[ImGuiKey_KeyPad5] = OIS::KC_NUMPAD5;
73  io.KeyMap[ImGuiKey_KeyPad6] = OIS::KC_NUMPAD6;
74  io.KeyMap[ImGuiKey_KeyPad7] = OIS::KC_NUMPAD7;
75  io.KeyMap[ImGuiKey_KeyPad8] = OIS::KC_NUMPAD8;
76  io.KeyMap[ImGuiKey_KeyPad9] = OIS::KC_NUMPAD9;
77  io.KeyMap[ImGuiKey_Slash] = OIS::KC_SLASH;
78 
79  // Load font
80  m_imgui_overlay->addFont("rigsofrods/fonts/Roboto-Medium",
81  ContentManager::ResourcePack::FONTS.resource_group_name);
82 
83  // Start rendering
84  m_imgui_overlay->setZOrder(300);
85  m_imgui_overlay->initialise(); // Build font texture
86  m_imgui_overlay->show();
87 }
88 
89 void OgreImGui::InjectMouseMoved( const OIS::MouseEvent &arg )
90 {
91 
92  ImGuiIO& io = ImGui::GetIO();
93 
94  io.MousePos.x = arg.state.X.abs;
95  io.MousePos.y = arg.state.Y.abs;
96  io.MouseWheel = Ogre::Math::Clamp((float)arg.state.Z.rel, -1/3.f, 1/3.f);
97 }
98 
99 void OgreImGui::SetMouseButtonState( OIS::MouseButtonID id, bool down )
100 {
101  ImGuiIO& io = ImGui::GetIO();
102  if (id >= 0 && id < 5)
103  {
104  io.MouseDown[id] = down;
105  }
106 }
107 
109 {
110  ImGuiIO& io = ImGui::GetIO();
111  io.MouseDown[0] = false;
112  io.MouseDown[1] = false;
113  io.MouseDown[2] = false;
114  io.MouseDown[3] = false;
115  io.MouseDown[4] = false;
116 }
117 
118 void OgreImGui::InjectKeyPressed( const OIS::KeyEvent &arg )
119 {
120  ImGuiIO& io = ImGui::GetIO();
121  io.KeysDown[arg.key] = true;
122 
123  if (arg.text>0)
124  {
125  io.AddInputCharacter((unsigned short)arg.text);
126  }
127 }
128 
129 void OgreImGui::InjectKeyReleased( const OIS::KeyEvent &arg )
130 {
131  ImGuiIO& io = ImGui::GetIO();
132  io.KeysDown[arg.key] = false;
133 }
134 
135 void OgreImGui::renderQueueStarted(Ogre::uint8 queueGroupId,
136  const Ogre::String& invocation, bool& skipThisInvocation)
137 {
138  // Shamelessly copy-pasted from `Ogre::OverlaySystem::renderQueueStarted()`
139  if(queueGroupId == Ogre::RENDER_QUEUE_OVERLAY)
140  {
141  Ogre::Viewport* vp = Ogre::Root::getSingletonPtr()->getRenderSystem()->_getViewport();
142  if(vp != NULL)
143  {
144  Ogre::SceneManager* sceneMgr = vp->getCamera()->getSceneManager();
145  if (vp->getOverlaysEnabled() && sceneMgr->_getCurrentRenderStage() != Ogre::SceneManager::IRS_RENDER_TO_TEXTURE)
146  {
147  // Checking `sceneMgr->_getCurrentRenderStage() == Ogre::SceneManager::IRS_RENDER_TO_TEXTURE`)
148  // doesn't do the trick if the RTT is updated by calling `Ogre::RenderTarget::update()` by hand,
149  // which we do frequently.
150  // To compensate, we also check if the active viewport matches our screen viewport.
151  Ogre::Viewport* vp_target = App::GetAppContext()->GetViewport();
152  if (vp == vp_target)
153  {
154  m_imgui_overlay->_findVisibleObjects(vp->getCamera(), sceneMgr->getRenderQueue(), vp);
155  }
156  }
157  }
158  }
159 }
Script2Game::KC_NUMPAD1
enum Script2Game::inputEvents KC_NUMPAD1
OgreImGui::SetMouseButtonState
void SetMouseButtonState(OIS::MouseButtonID id, bool down)
Definition: OgreImGui.cpp:99
Script2Game::KC_HOME
enum Script2Game::inputEvents KC_HOME
Copyright
MIT License Copyright(c) 2000-2013 Torus Knot Software Ltd Permission is hereby granted
Script2Game::KC_NUMPAD7
enum Script2Game::inputEvents KC_NUMPAD7
restriction
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without restriction
Definition: LICENSE-ImGui.txt:7
LIABILITY
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY
Definition: LICENSE-OGRE.txt:19
FROM
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR ARISING FROM
Definition: LICENSE-OGRE.txt:19
Script2Game::KC_NUMPAD4
enum Script2Game::inputEvents KC_NUMPAD4
Script2Game::KC_PGDOWN
enum Script2Game::inputEvents KC_PGDOWN
Script2Game::KC_DELETE
enum Script2Game::inputEvents KC_DELETE
Script2Game::KC_NUMPAD9
enum Script2Game::inputEvents KC_NUMPAD9
copy
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to copy
Definition: LICENSE-ImGui.txt:8
Script2Game::KC_PGUP
enum Script2Game::inputEvents KC_PGUP
ContentManager.h
RoR::App::GetAppContext
AppContext * GetAppContext()
Definition: Application.cpp:266
restriction
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without restriction
Definition: LICENSE-OGRE.txt:7
CONTRACT
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF CONTRACT
Definition: LICENSE-ImGui.txt:19
KIND
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY KIND
Definition: LICENSE-OGRE.txt:15
Script2Game::KC_RETURN
enum Script2Game::inputEvents KC_RETURN
use
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: LICENSE-OGRE.txt:8
OgreImGui::InjectKeyReleased
void InjectKeyReleased(const OIS::KeyEvent &arg)
Definition: OgreImGui.cpp:129
merge
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to merge
Definition: LICENSE-ImGui.txt:8
MERCHANTABILITY
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY
Definition: LICENSE-OGRE.txt:16
Script2Game::KC_RIGHT
enum Script2Game::inputEvents KC_RIGHT
AppContext.h
System integration layer; inspired by OgreBites::ApplicationContext.
Script2Game::KC_ESCAPE
enum Script2Game::inputEvents KC_ESCAPE
modify
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to modify
Definition: LICENSE-ImGui.txt:8
RoR::AppContext::GetViewport
Ogre::Viewport * GetViewport()
Definition: AppContext.h:66
Software
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the Software
Definition: LICENSE-OGRE.txt:9
Script2Game::KC_SLASH
enum Script2Game::inputEvents KC_SLASH
OgreImGui.h
copy
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to copy
Definition: LICENSE-OGRE.txt:8
Ogre::ImGuiOverlay
Definition: OgreImGuiOverlay.h:13
Actor.h
OgreImGui::Init
void Init()
Definition: OgreImGui.cpp:38
MERCHANTABILITY
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY
Definition: LICENSE-ImGui.txt:16
OgreImGui::ResetAllMouseButtons
void ResetAllMouseButtons()
Definition: OgreImGui.cpp:108
files
The MIT free of to any person obtaining a copy of this software and associated documentation files(the "Software")
Script2Game::KC_NUMPAD0
enum Script2Game::inputEvents KC_NUMPAD0
IMPLIED
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR IMPLIED
Definition: LICENSE-OGRE.txt:16
KIND
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY KIND
Definition: LICENSE-ImGui.txt:15
OgreImGui::InjectMouseMoved
void InjectMouseMoved(const OIS::MouseEvent &arg)
Definition: OgreImGui.cpp:89
Script2Game::KC_NUMPAD6
enum Script2Game::inputEvents KC_NUMPAD6
Script2Game::KC_NUMPAD5
enum Script2Game::inputEvents KC_NUMPAD5
Script2Game::KC_TAB
enum Script2Game::inputEvents KC_TAB
publish
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to publish
Definition: LICENSE-OGRE.txt:8
sublicense
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to sublicense
Definition: LICENSE-ImGui.txt:8
sublicense
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to sublicense
Definition: LICENSE-OGRE.txt:8
Script2Game::KC_END
enum Script2Game::inputEvents KC_END
modify
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to modify
Definition: LICENSE-OGRE.txt:8
merge
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to merge
Definition: LICENSE-OGRE.txt:8
OgreImGui::InjectKeyPressed
void InjectKeyPressed(const OIS::KeyEvent &arg)
Definition: OgreImGui.cpp:118
Script2Game::KC_DOWN
enum Script2Game::inputEvents KC_DOWN
OTHERWISE
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR OTHERWISE
Definition: LICENSE-ImGui.txt:19
OTHERWISE
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR OTHERWISE
Definition: LICENSE-OGRE.txt:19
LIABILITY
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY
Definition: LICENSE-ImGui.txt:19
charge
MIT License free of charge
Definition: LICENSE-OGRE.txt:5
IMPLIED
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR IMPLIED
Definition: LICENSE-ImGui.txt:16
publish
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to publish
Definition: LICENSE-ImGui.txt:8
use
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: LICENSE-ImGui.txt:8
License
The MIT License(MIT) Copyright(c) 2014-2019 Omar Cornut Permission is hereby granted
OgreImGuiOverlay.h
Script2Game::KC_NUMPAD8
enum Script2Game::inputEvents KC_NUMPAD8
OgreImGui::renderQueueStarted
virtual void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &skipThisInvocation) override
Definition: OgreImGui.cpp:135
files
MIT License free of to any person obtaining a copy of this software and associated documentation files(the "Software")
Software
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the Software
Definition: LICENSE-ImGui.txt:9
so
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do so
Definition: LICENSE-OGRE.txt:10
conditions
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following conditions
Definition: LICENSE-OGRE.txt:15
FROM
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR ARISING FROM
Definition: LICENSE-ImGui.txt:19
Script2Game::KC_UP
enum Script2Game::inputEvents KC_UP
conditions
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following conditions
Definition: LICENSE-ImGui.txt:15
CONTRACT
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF CONTRACT
Definition: LICENSE-OGRE.txt:19
Script2Game::KC_LEFT
enum Script2Game::inputEvents KC_LEFT
Script2Game::KC_NUMPAD3
enum Script2Game::inputEvents KC_NUMPAD3
CLAIM
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM
Definition: LICENSE-ImGui.txt:18
charge
The MIT free of charge
Definition: LICENSE-ImGui.txt:5
Script2Game::KC_NUMPAD2
enum Script2Game::inputEvents KC_NUMPAD2
RoR
Definition: AppContext.h:36
RoR::ContentManager::ResourcePack::FONTS
static const ResourcePack FONTS
Definition: ContentManager.h:56
distribute
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to distribute
Definition: LICENSE-ImGui.txt:8
so
The MIT free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do so
Definition: LICENSE-ImGui.txt:10
CLAIM
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do subject to the following WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM
Definition: LICENSE-OGRE.txt:18
distribute
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to distribute
Definition: LICENSE-OGRE.txt:8