bgfx/examples/common/imgui/imgui.h

132 lines
3.7 KiB
C
Raw Normal View History

2013-04-25 08:01:11 +04:00
/*
2022-01-15 22:59:06 +03:00
* Copyright 2011-2022 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
2013-04-25 08:01:11 +04:00
*/
#ifndef IMGUI_H_HEADER_GUARD
#define IMGUI_H_HEADER_GUARD
2013-04-25 08:01:11 +04:00
#include <bgfx/bgfx.h>
2018-05-06 18:57:48 +03:00
#include <dear-imgui/imgui.h>
2016-05-28 22:12:59 +03:00
#include <iconfontheaders/icons_kenney.h>
#include <iconfontheaders/icons_font_awesome.h>
2014-08-06 04:44:00 +04:00
#define IMGUI_MBUT_LEFT 0x01
#define IMGUI_MBUT_RIGHT 0x02
#define IMGUI_MBUT_MIDDLE 0x04
2013-04-25 08:01:11 +04:00
inline uint32_t imguiRGBA(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 255)
{
return 0
2014-06-23 06:15:38 +04:00
| (uint32_t(_r) << 0)
2013-04-25 08:01:11 +04:00
| (uint32_t(_g) << 8)
| (uint32_t(_b) << 16)
| (uint32_t(_a) << 24)
;
}
2015-04-16 06:00:15 +03:00
namespace bx { struct AllocatorI; }
2017-07-08 20:51:38 +03:00
void imguiCreate(float _fontSize = 18.0f, bx::AllocatorI* _allocator = NULL);
2013-04-25 08:01:11 +04:00
void imguiDestroy();
2019-05-10 11:01:45 +03:00
void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, int _inputChar = -1, bgfx::ViewId _view = 255);
2013-04-25 08:01:11 +04:00
void imguiEndFrame();
2017-06-26 07:44:04 +03:00
namespace entry { class AppI; }
void showExampleDialog(entry::AppI* _app, const char* _errorText = NULL);
2017-06-26 07:44:04 +03:00
namespace ImGui
{
2016-02-16 03:55:32 +03:00
#define IMGUI_FLAGS_NONE UINT8_C(0x00)
#define IMGUI_FLAGS_ALPHA_BLEND UINT8_C(0x01)
2015-10-10 01:37:22 +03:00
2021-04-02 22:51:59 +03:00
///
2020-02-07 07:09:38 +03:00
inline ImTextureID toId(bgfx::TextureHandle _handle, uint8_t _flags, uint8_t _mip)
{
union { struct { bgfx::TextureHandle handle; uint8_t flags; uint8_t mip; } s; ImTextureID id; } tex;
tex.s.handle = _handle;
tex.s.flags = _flags;
tex.s.mip = _mip;
return tex.id;
}
2015-10-10 01:37:22 +03:00
// Helper function for passing bgfx::TextureHandle to ImGui::Image.
inline void Image(bgfx::TextureHandle _handle
2016-02-16 03:55:32 +03:00
, uint8_t _flags
, uint8_t _mip
2015-10-10 01:37:22 +03:00
, const ImVec2& _size
, const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
, const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
, const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
, const ImVec4& _borderCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
)
{
2020-02-07 07:09:38 +03:00
Image(toId(_handle, _flags, _mip), _size, _uv0, _uv1, _tintCol, _borderCol);
2015-10-10 01:37:22 +03:00
}
// Helper function for passing bgfx::TextureHandle to ImGui::Image.
2015-10-10 01:37:22 +03:00
inline void Image(bgfx::TextureHandle _handle
, const ImVec2& _size
, const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
, const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
, const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
, const ImVec4& _borderCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
)
{
2016-02-16 03:55:32 +03:00
Image(_handle, IMGUI_FLAGS_ALPHA_BLEND, 0, _size, _uv0, _uv1, _tintCol, _borderCol);
2015-10-10 01:37:22 +03:00
}
// Helper function for passing bgfx::TextureHandle to ImGui::ImageButton.
inline bool ImageButton(bgfx::TextureHandle _handle
2016-02-16 03:55:32 +03:00
, uint8_t _flags
, uint8_t _mip
2015-10-10 01:37:22 +03:00
, const ImVec2& _size
, const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
, const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
, const ImVec4& _bgCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
, const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
)
{
2022-08-07 08:28:07 +03:00
return ImageButton("image", toId(_handle, _flags, _mip), _size, _uv0, _uv1, _bgCol, _tintCol);
}
2015-09-10 20:59:19 +03:00
// Helper function for passing bgfx::TextureHandle to ImGui::ImageButton.
2015-10-10 01:37:22 +03:00
inline bool ImageButton(bgfx::TextureHandle _handle
, const ImVec2& _size
, const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
, const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
, const ImVec4& _bgCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
, const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
)
2015-09-10 20:59:19 +03:00
{
2022-08-07 08:28:07 +03:00
return ImageButton(_handle, IMGUI_FLAGS_ALPHA_BLEND, 0, _size, _uv0, _uv1, _bgCol, _tintCol);
2015-09-10 20:59:19 +03:00
}
2021-04-02 22:51:59 +03:00
///
2016-04-24 18:49:49 +03:00
inline void NextLine()
{
SetCursorPosY(GetCursorPosY() + GetTextLineHeightWithSpacing() );
}
2021-04-02 22:51:59 +03:00
///
2017-06-24 01:26:28 +03:00
inline bool MouseOverArea()
{
return false
2020-12-21 09:42:16 +03:00
|| ImGui::IsAnyItemActive()
2017-06-24 01:26:28 +03:00
|| ImGui::IsAnyItemHovered()
2018-01-12 09:10:53 +03:00
|| ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow)
2020-12-28 23:57:46 +03:00
// || ImGuizmo::IsOver()
2017-06-24 01:26:28 +03:00
;
}
2017-06-24 00:35:53 +03:00
2021-04-02 22:51:59 +03:00
///
void PushEnabled(bool _enabled);
2021-04-02 06:09:16 +03:00
2021-04-02 22:51:59 +03:00
///
void PopEnabled();
2021-04-02 06:09:16 +03:00
} // namespace ImGui
#endif // IMGUI_H_HEADER_GUARD