PeriDyno 1.0.0
Loading...
Searching...
No Matches
ImGuiRenderer.h
Go to the documentation of this file.
1// The MIT License (MIT)
2
3// Copyright (c) 2017 Ryohei Ikegami
4
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22#pragma once
23
24#include <imgui.h>
25#include <memory>
26
27#include <QOpenGLExtraFunctions>
28#include <QObject>
29#include <QPoint>
30#include <imgui.h>
31#include <memory>
32
33class QMouseEvent;
34class QWheelEvent;
35class QKeyEvent;
36
37namespace QtImGui {
38
40public:
41 virtual ~WindowWrapper() {}
42 virtual void installEventFilter(QObject *object) = 0;
43 virtual QSize size() const = 0;
44 virtual qreal devicePixelRatio() const = 0;
45 virtual bool isActive() const = 0;
46 virtual QPoint mapFromGlobal(const QPoint &p) const = 0;
47 virtual QObject* object() = 0;
48
49 virtual void setCursorShape(Qt::CursorShape shape) = 0;
50 virtual void setCursorPos(const QPoint& local_pos) = 0;
51};
52
53class ImGuiRenderer : public QObject, QOpenGLExtraFunctions {
54 Q_OBJECT
55public:
56 void initialize(WindowWrapper *window);
57 void newFrame();
58 void render();
59 bool eventFilter(QObject *watched, QEvent *event);
60
61 static ImGuiRenderer *instance();
62
63public:
66
67private:
68 void onMousePressedChange(QMouseEvent *event);
69 void onWheel(QWheelEvent *event);
70 void onKeyPressRelease(QKeyEvent *event);
71
72 void updateCursorShape(const ImGuiIO &io);
73 void setCursorPos(const ImGuiIO &io);
74
75 void renderDrawList(ImDrawData *draw_data);
76 bool createFontsTexture();
78
79 std::unique_ptr<WindowWrapper> m_window;
80 double g_Time = 0.0f;
81 bool g_MousePressed[3] = { false, false, false };
84 GLuint g_FontTexture = 0;
88 unsigned int g_VboHandle = 0, g_VaoHandle = 0, g_ElementsHandle = 0;
89
90 ImGuiContext* g_ctx = nullptr;
91};
92
93} // namespace QtImGui
unsigned int g_ElementsHandle
void renderDrawList(ImDrawData *draw_data)
static ImGuiRenderer * instance()
void initialize(WindowWrapper *window)
void updateCursorShape(const ImGuiIO &io)
void onWheel(QWheelEvent *event)
std::unique_ptr< WindowWrapper > m_window
bool eventFilter(QObject *watched, QEvent *event)
void onKeyPressRelease(QKeyEvent *event)
void onMousePressedChange(QMouseEvent *event)
void setCursorPos(const ImGuiIO &io)
virtual QPoint mapFromGlobal(const QPoint &p) const =0
virtual QSize size() const =0
virtual void setCursorShape(Qt::CursorShape shape)=0
virtual qreal devicePixelRatio() const =0
virtual bool isActive() const =0
virtual void setCursorPos(const QPoint &local_pos)=0
virtual QObject * object()=0
virtual void installEventFilter(QObject *object)=0