2013-04-25 08:01:11 +04:00
|
|
|
/*
|
2016-01-01 11:11:04 +03:00
|
|
|
* Copyright 2011-2016 Branimir Karadzic. All rights reserved.
|
|
|
|
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
2013-04-25 08:01:11 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
// This code is based on:
|
|
|
|
//
|
|
|
|
// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would be
|
|
|
|
// appreciated but is not required.
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
// misrepresented as being the original software.
|
|
|
|
// 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
//
|
|
|
|
// Source altered and distributed from https://github.com/AdrienHerubel/imgui
|
|
|
|
|
2013-11-15 07:10:10 +04:00
|
|
|
#ifndef IMGUI_H_HEADER_GUARD
|
|
|
|
#define IMGUI_H_HEADER_GUARD
|
2013-04-25 08:01:11 +04:00
|
|
|
|
2015-09-19 06:16:24 +03:00
|
|
|
#include <bgfx/bgfx.h>
|
2015-01-20 07:34:54 +03:00
|
|
|
#include <ocornut-imgui/imgui.h>
|
2015-10-01 02:22:51 +03:00
|
|
|
#include <ocornut-imgui/imgui_wm.h>
|
2014-08-06 04:44:00 +04:00
|
|
|
|
2015-08-26 08:59:20 +03:00
|
|
|
#define IMGUI_MBUT_LEFT 0x01
|
|
|
|
#define IMGUI_MBUT_RIGHT 0x02
|
|
|
|
#define IMGUI_MBUT_MIDDLE 0x04
|
2013-04-25 08:01:11 +04:00
|
|
|
|
2014-08-12 13:51:00 +04:00
|
|
|
/// For custom values, define these macros before including imgui.h
|
|
|
|
|
|
|
|
#ifndef IMGUI_SCROLL_AREA_R
|
2014-10-03 08:35:32 +04:00
|
|
|
# define IMGUI_SCROLL_AREA_R 6
|
2014-08-12 13:51:00 +04:00
|
|
|
#endif //IMGUI_SCROLL_AREA_R
|
|
|
|
|
|
|
|
#ifndef IMGUI_SCROLL_BAR_R
|
2014-10-03 08:35:32 +04:00
|
|
|
# define IMGUI_SCROLL_BAR_R 5
|
2014-08-12 13:51:00 +04:00
|
|
|
#endif //IMGUI_SCROLL_BAR_R
|
|
|
|
|
|
|
|
#ifndef IMGUI_BUTTON_R
|
2014-10-03 08:35:32 +04:00
|
|
|
# define IMGUI_BUTTON_R 9
|
2014-08-12 13:51:00 +04:00
|
|
|
#endif //IMGUI_BUTTON_R
|
|
|
|
|
2014-08-12 15:20:00 +04:00
|
|
|
#ifndef IMGUI_BUTTON_RGB0
|
2014-10-03 08:35:32 +04:00
|
|
|
# define IMGUI_BUTTON_RGB0 imguiRGBA(128, 128, 128, 0)
|
2014-08-12 15:20:00 +04:00
|
|
|
#endif //IMGUI_BUTTON_RGB0
|
|
|
|
|
2014-08-12 13:51:00 +04:00
|
|
|
#ifndef IMGUI_INPUT_R
|
2014-10-03 08:35:32 +04:00
|
|
|
# define IMGUI_INPUT_R 4
|
2014-08-12 13:51:00 +04:00
|
|
|
#endif //IMGUI_INPUT_R
|
|
|
|
|
2014-08-13 01:04:56 +04:00
|
|
|
#ifndef IMGUI_TABS_HEIGHT
|
2014-10-03 08:35:32 +04:00
|
|
|
# define IMGUI_TABS_HEIGHT 20
|
2014-08-13 01:04:56 +04:00
|
|
|
#endif //IMGUI_TABS_HEIGHT
|
|
|
|
|
|
|
|
#ifndef IMGUI_TABS_R
|
2014-10-03 08:35:32 +04:00
|
|
|
# define IMGUI_TABS_R 9
|
2014-08-13 01:04:56 +04:00
|
|
|
#endif //IMGUI_TABS_R
|
|
|
|
|
2014-08-12 13:51:00 +04:00
|
|
|
#ifndef IMGUI_INDENT_VALUE
|
2014-10-03 08:35:32 +04:00
|
|
|
# define IMGUI_INDENT_VALUE 16
|
2014-08-12 13:51:00 +04:00
|
|
|
#endif //IMGUI_INDENT_VALUE
|
|
|
|
|
|
|
|
#ifndef IMGUI_SEPARATOR_VALUE
|
2014-10-03 08:35:32 +04:00
|
|
|
# define IMGUI_SEPARATOR_VALUE 12
|
2014-08-12 13:51:00 +04:00
|
|
|
#endif //IMGUI_SEPARATOR_VALUE
|
|
|
|
|
2013-08-07 08:04:28 +04:00
|
|
|
struct ImguiTextAlign
|
2013-04-25 08:01:11 +04:00
|
|
|
{
|
2013-08-07 08:04:28 +04:00
|
|
|
enum Enum
|
|
|
|
{
|
|
|
|
Left,
|
|
|
|
Center,
|
|
|
|
Right,
|
2014-06-30 08:53:23 +04:00
|
|
|
|
|
|
|
Count
|
2013-08-07 08:04:28 +04:00
|
|
|
};
|
2013-04-25 08:01:11 +04:00
|
|
|
};
|
|
|
|
|
2014-09-20 23:33:17 +04:00
|
|
|
struct ImguiAlign
|
2014-07-05 04:09:31 +04:00
|
|
|
{
|
|
|
|
enum Enum
|
|
|
|
{
|
|
|
|
Left,
|
2014-07-05 07:33:00 +04:00
|
|
|
LeftIndented,
|
2014-07-05 04:09:31 +04:00
|
|
|
Center,
|
2014-07-05 04:50:11 +04:00
|
|
|
CenterIndented,
|
2014-07-05 07:33:00 +04:00
|
|
|
Right,
|
2014-07-05 04:09:31 +04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-02-12 04:47:28 +03:00
|
|
|
struct ImguiCubemap
|
|
|
|
{
|
|
|
|
enum Enum
|
|
|
|
{
|
|
|
|
Cross,
|
|
|
|
Latlong,
|
|
|
|
Hex,
|
|
|
|
|
|
|
|
Count,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-08-10 16:11:16 +04:00
|
|
|
struct ImguiBorder
|
|
|
|
{
|
|
|
|
enum Enum
|
|
|
|
{
|
|
|
|
Left,
|
|
|
|
Right,
|
|
|
|
Top,
|
|
|
|
Bottom
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2014-07-12 14:25:41 +04:00
|
|
|
BGFX_HANDLE(ImguiFontHandle);
|
|
|
|
|
|
|
|
ImguiFontHandle imguiCreateFont(const void* _data, float _fontSize=15.0f);
|
|
|
|
void imguiSetFont(ImguiFontHandle _handle);
|
2014-09-20 23:33:17 +04:00
|
|
|
ImguiFontHandle imguiGetCurrentFont();
|
2014-07-12 14:25:41 +04:00
|
|
|
|
2015-04-16 06:00:15 +03:00
|
|
|
namespace bx { struct AllocatorI; }
|
|
|
|
|
|
|
|
ImguiFontHandle imguiCreate(const void* _data = NULL, uint32_t _size = 0, float _fontSize = 15.0f, bx::AllocatorI* _allocator = NULL);
|
2013-04-25 08:01:11 +04:00
|
|
|
void imguiDestroy();
|
|
|
|
|
2015-02-22 02:51:03 +03:00
|
|
|
void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, char _inputChar = 0, uint8_t _view = 255);
|
2015-03-16 15:51:47 +03:00
|
|
|
void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, uint16_t _surfaceWidth, uint16_t _surfaceHeight, char _inputChar = 0, uint8_t _view = 255);
|
2013-04-25 08:01:11 +04:00
|
|
|
void imguiEndFrame();
|
|
|
|
|
2014-09-23 17:34:05 +04:00
|
|
|
void imguiDrawText(int _x, int _y, ImguiTextAlign::Enum _align, const char* _text, uint32_t _argb);
|
|
|
|
void imguiDrawLine(float _x0, float _y0, float _x1, float _y1, float _r, uint32_t _argb);
|
|
|
|
void imguiDrawRoundedRect(float _x, float _y, float _w, float _h, float _r, uint32_t _argb);
|
|
|
|
void imguiDrawRect(float _x, float _y, float _w, float _h, uint32_t _argb);
|
|
|
|
|
2014-09-20 23:33:17 +04:00
|
|
|
/// Notice: this function is not to be called between imguiBeginArea() and imguiEndArea().
|
2014-08-10 16:11:16 +04:00
|
|
|
bool imguiBorderButton(ImguiBorder::Enum _border, bool _checked, bool _enabled = true);
|
|
|
|
|
2014-09-20 23:33:17 +04:00
|
|
|
bool imguiBeginArea(const char* _name, int _x, int _y, int _width, int _height, bool _enabled = true, int32_t _r = IMGUI_SCROLL_AREA_R);
|
|
|
|
void imguiEndArea();
|
|
|
|
bool imguiBeginScroll(int32_t _height, int32_t* _scroll, bool _enabled = true);
|
|
|
|
void imguiEndScroll(int32_t _r = IMGUI_SCROLL_BAR_R);
|
|
|
|
|
2014-08-12 13:51:00 +04:00
|
|
|
bool imguiBeginScrollArea(const char* _name, int _x, int _y, int _width, int _height, int* _scroll, bool _enabled = true, int32_t _r = IMGUI_SCROLL_AREA_R);
|
|
|
|
void imguiEndScrollArea(int32_t _r = IMGUI_SCROLL_BAR_R);
|
2013-04-25 08:01:11 +04:00
|
|
|
|
2014-08-12 13:51:00 +04:00
|
|
|
void imguiIndent(uint16_t _width = IMGUI_INDENT_VALUE);
|
|
|
|
void imguiUnindent(uint16_t _width = IMGUI_INDENT_VALUE);
|
|
|
|
void imguiSeparator(uint16_t _height = IMGUI_SEPARATOR_VALUE);
|
2015-03-16 16:20:45 +03:00
|
|
|
void imguiSeparatorLine(uint16_t _height = IMGUI_SEPARATOR_VALUE, ImguiAlign::Enum = ImguiAlign::LeftIndented);
|
2013-04-25 08:01:11 +04:00
|
|
|
|
2014-08-13 00:41:24 +04:00
|
|
|
int32_t imguiGetWidgetX();
|
|
|
|
int32_t imguiGetWidgetY();
|
2014-12-24 04:33:47 +03:00
|
|
|
int32_t imguiGetWidgetW();
|
2014-11-23 03:07:58 +03:00
|
|
|
void imguiSetCurrentScissor(); // Call before drawing custom widgets over imgui area.
|
2014-08-13 00:41:24 +04:00
|
|
|
|
2014-09-20 23:33:17 +04:00
|
|
|
bool imguiButton(const char* _text, bool _enabled = true, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, uint32_t _rgb0 = IMGUI_BUTTON_RGB0, int32_t _r = IMGUI_BUTTON_R);
|
2013-04-25 08:01:11 +04:00
|
|
|
bool imguiItem(const char* _text, bool _enabled = true);
|
|
|
|
bool imguiCheck(const char* _text, bool _checked, bool _enabled = true);
|
2015-12-30 22:36:49 +03:00
|
|
|
bool imguiBool(const char* _text, bool& _flag, bool _enabled = true);
|
2013-04-25 08:01:11 +04:00
|
|
|
bool imguiCollapse(const char* _text, const char* _subtext, bool _checked, bool _enabled = true);
|
|
|
|
void imguiLabel(const char* _format, ...);
|
2014-09-20 23:33:17 +04:00
|
|
|
void imguiLabel(uint32_t _rgba, const char* _format, ...);
|
2013-04-25 08:01:11 +04:00
|
|
|
void imguiValue(const char* _text);
|
2014-09-20 23:33:17 +04:00
|
|
|
bool imguiSlider(const char* _text, float& _val, float _vmin, float _vmax, float _vinc, bool _enabled = true, ImguiAlign::Enum _align = ImguiAlign::LeftIndented);
|
|
|
|
bool imguiSlider(const char* _text, int32_t& _val, int32_t _vmin, int32_t _vmax, bool _enabled = true, ImguiAlign::Enum _align = ImguiAlign::LeftIndented);
|
|
|
|
void imguiInput(const char* _label, char* _str, uint32_t _len, bool _enabled = true, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, int32_t _r = IMGUI_INPUT_R);
|
2013-04-25 08:01:11 +04:00
|
|
|
|
2014-11-19 18:18:57 +03:00
|
|
|
/// Usage example:
|
|
|
|
/// imguiTabs(0, true, ImguiAlign::CenterIndented, 20, 0, 3, 2, "Tab0", "Tab1", "Tab2", true, false);
|
|
|
|
/// _nTabs - Number of tabs (in the above example, 3, and their labes are 'Tab0', 'Tab1' and 'Tab2'.
|
|
|
|
/// _nEnabled - Number of specified 'enabled' flags. All other unspecified tabs are considered enabled by default.
|
|
|
|
/// In the above example, there are 2 enabled flags: 'Tab0' is specified as enabled and 'Tab1' is specified as disabled.
|
|
|
|
/// Tab2 is unspecified and therefore is treated as enabled.
|
|
|
|
uint8_t imguiTabs(uint8_t _selected, bool _enabled, ImguiAlign::Enum _align, int32_t _height, int32_t _r, uint8_t _nTabs, uint8_t _nEnabled, ...);
|
2014-11-20 20:43:27 +03:00
|
|
|
uint8_t imguiTabs(uint8_t _selected, bool _enabled, ImguiAlign::Enum _align, int32_t _height, int32_t _r, uint8_t _nTabs, ...);
|
2014-08-10 18:17:37 +04:00
|
|
|
|
2014-01-19 12:28:17 +04:00
|
|
|
uint32_t imguiChooseUseMacroInstead(uint32_t _selected, ...);
|
2014-01-19 08:07:00 +04:00
|
|
|
#define imguiChoose(...) imguiChooseUseMacroInstead(__VA_ARGS__, NULL)
|
|
|
|
|
2014-11-23 02:44:38 +03:00
|
|
|
void imguiColorWheel(float _rgb[3], bool _respectIndentation = false, float _size = 0.8f, bool _enabled = true);
|
|
|
|
void imguiColorWheel(const char* _str, float _rgb[3], bool& _activated, float _size = 0.8f, bool _enabled = true);
|
2014-06-23 06:15:38 +04:00
|
|
|
|
2014-11-22 21:08:18 +03:00
|
|
|
bool imguiImage(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _enabled = true, bool _originBottomLeft = false);
|
|
|
|
bool imguiImage(bgfx::TextureHandle _image, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _enabled = true, bool _originBottomLeft = false);
|
|
|
|
bool imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _enabled = true);
|
|
|
|
bool imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _enabled = true);
|
2015-02-12 04:47:28 +03:00
|
|
|
bool imguiCube(bgfx::TextureHandle _cubemap, float _lod = 0.0f, ImguiCubemap::Enum _display = ImguiCubemap::Cross, bool _sameHeight = false, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _enabled = true);
|
2014-09-20 23:33:17 +04:00
|
|
|
|
|
|
|
float imguiGetTextLength(const char* _text, ImguiFontHandle _handle);
|
2014-09-23 17:34:05 +04:00
|
|
|
bool imguiMouseOverArea();
|
2014-07-05 08:03:43 +04:00
|
|
|
|
2015-04-24 03:14:29 +03:00
|
|
|
namespace ImGui
|
|
|
|
{
|
2015-10-10 01:37:22 +03:00
|
|
|
#define IMGUI_FLAGS_NONE UINT16_C(0x0000)
|
|
|
|
#define IMGUI_FLAGS_ALPHA_BLEND UINT16_C(0x0001)
|
|
|
|
|
|
|
|
// Helper function for passing bgfx::TextureHandle to ImGui::Image.
|
|
|
|
inline void Image(bgfx::TextureHandle _handle
|
|
|
|
, uint16_t _flags
|
|
|
|
, 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)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
union { struct { uint16_t flags; bgfx::TextureHandle handle; } s; ImTextureID ptr; } texture;
|
|
|
|
texture.s.flags = _flags;
|
|
|
|
texture.s.handle = _handle;
|
|
|
|
Image(texture.ptr, _size, _uv0, _uv1, _tintCol, _borderCol);
|
|
|
|
}
|
|
|
|
|
2015-04-24 03:14:29 +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)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
Image(_handle, IMGUI_FLAGS_ALPHA_BLEND, _size, _uv0, _uv1, _tintCol, _borderCol);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper function for passing bgfx::TextureHandle to ImGui::ImageButton.
|
|
|
|
inline bool ImageButton(bgfx::TextureHandle _handle
|
|
|
|
, uint16_t _flags
|
|
|
|
, const ImVec2& _size
|
|
|
|
, const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
|
|
|
|
, const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
|
|
|
|
, int _framePadding = -1
|
|
|
|
, 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-04-24 03:14:29 +03:00
|
|
|
{
|
2015-10-10 01:37:22 +03:00
|
|
|
union { struct { uint16_t flags; bgfx::TextureHandle handle; } s; ImTextureID ptr; } texture;
|
|
|
|
texture.s.flags = _flags;
|
|
|
|
texture.s.handle = _handle;
|
|
|
|
return ImageButton(texture.ptr, _size, _uv0, _uv1, _framePadding, _bgCol, _tintCol);
|
2015-04-24 03:14:29 +03:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
, int _framePadding = -1
|
|
|
|
, 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
|
|
|
{
|
2015-10-10 01:37:22 +03:00
|
|
|
return ImageButton(_handle, IMGUI_FLAGS_ALPHA_BLEND, _size, _uv0, _uv1, _framePadding, _bgCol, _tintCol);
|
2015-09-10 20:59:19 +03:00
|
|
|
}
|
|
|
|
|
2015-04-24 03:14:29 +03:00
|
|
|
} // namespace ImGui
|
|
|
|
|
2013-11-15 07:10:10 +04:00
|
|
|
#endif // IMGUI_H_HEADER_GUARD
|