2015-01-17 09:41:37 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2014-2015 Daniel Collin. All rights reserved.
|
2016-01-01 11:11:04 +03:00
|
|
|
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
2015-01-17 09:41:37 +03:00
|
|
|
*/
|
|
|
|
|
2015-09-19 06:16:24 +03:00
|
|
|
#include <bgfx/bgfx.h>
|
2016-12-05 07:11:10 +03:00
|
|
|
#include <bgfx/embedded_shader.h>
|
2015-04-16 06:00:15 +03:00
|
|
|
#include <bx/allocator.h>
|
2015-01-17 09:41:37 +03:00
|
|
|
#include <bx/fpumath.h>
|
2015-07-18 05:57:24 +03:00
|
|
|
#include <bx/timer.h>
|
2015-01-17 09:41:37 +03:00
|
|
|
#include <ocornut-imgui/imgui.h>
|
2015-01-20 04:16:59 +03:00
|
|
|
#include "imgui.h"
|
2015-01-17 09:41:37 +03:00
|
|
|
#include "ocornut_imgui.h"
|
2016-12-23 03:18:44 +03:00
|
|
|
#include "../bgfx_utils.h"
|
2015-06-10 19:53:09 +03:00
|
|
|
|
2015-10-09 08:46:17 +03:00
|
|
|
#ifndef USE_ENTRY
|
2015-11-12 03:43:32 +03:00
|
|
|
# if defined(SCI_NAMESPACE)
|
|
|
|
# define USE_ENTRY 1
|
|
|
|
# else
|
|
|
|
# define USE_ENTRY 0
|
|
|
|
# endif // defined(SCI_NAMESPACE)
|
2015-10-09 08:46:17 +03:00
|
|
|
#endif // USE_ENTRY
|
|
|
|
|
|
|
|
#if USE_ENTRY
|
|
|
|
# include "../entry/entry.h"
|
|
|
|
#endif // USE_ENTRY
|
|
|
|
|
2015-06-10 19:53:09 +03:00
|
|
|
#if defined(SCI_NAMESPACE)
|
|
|
|
# include "../entry/input.h"
|
2015-07-18 10:30:46 +03:00
|
|
|
# include "scintilla.h"
|
2015-06-10 19:53:09 +03:00
|
|
|
#endif // defined(SCI_NAMESPACE)
|
2015-01-17 09:41:37 +03:00
|
|
|
|
|
|
|
#include "vs_ocornut_imgui.bin.h"
|
|
|
|
#include "fs_ocornut_imgui.bin.h"
|
|
|
|
|
2016-05-29 02:26:12 +03:00
|
|
|
#include "roboto_regular.ttf.h"
|
|
|
|
#include "robotomono_regular.ttf.h"
|
2016-05-28 22:12:59 +03:00
|
|
|
#include "icons_kenney.ttf.h"
|
|
|
|
#include "icons_font_awesome.ttf.h"
|
|
|
|
|
2016-12-05 07:11:10 +03:00
|
|
|
static const bgfx::EmbeddedShader s_embeddedShaders[] =
|
|
|
|
{
|
|
|
|
BGFX_EMBEDDED_SHADER(vs_ocornut_imgui),
|
|
|
|
BGFX_EMBEDDED_SHADER(fs_ocornut_imgui),
|
2016-12-06 03:55:49 +03:00
|
|
|
|
|
|
|
BGFX_EMBEDDED_SHADER_END()
|
2016-12-05 07:11:10 +03:00
|
|
|
};
|
|
|
|
|
2016-05-28 22:12:59 +03:00
|
|
|
struct FontRangeMerge
|
|
|
|
{
|
|
|
|
const void* data;
|
|
|
|
size_t size;
|
|
|
|
ImWchar ranges[3];
|
|
|
|
};
|
|
|
|
|
|
|
|
static FontRangeMerge s_fontRangeMerge[] =
|
|
|
|
{
|
2016-05-29 02:26:12 +03:00
|
|
|
{ s_iconsKenneyTtf, sizeof(s_iconsKenneyTtf), { ICON_MIN_KI, ICON_MAX_KI, 0 } },
|
|
|
|
{ s_iconsFontAwesomeTtf, sizeof(s_iconsFontAwesomeTtf), { ICON_MIN_FA, ICON_MAX_FA, 0 } },
|
2016-05-28 22:12:59 +03:00
|
|
|
};
|
|
|
|
|
2015-01-20 04:16:59 +03:00
|
|
|
struct OcornutImguiContext
|
2015-01-17 09:41:37 +03:00
|
|
|
{
|
2015-04-16 06:00:15 +03:00
|
|
|
static void* memAlloc(size_t _size);
|
|
|
|
static void memFree(void* _ptr);
|
2015-10-09 08:46:17 +03:00
|
|
|
static void renderDrawLists(ImDrawData* _drawData);
|
2015-04-16 06:00:15 +03:00
|
|
|
|
2015-10-09 08:46:17 +03:00
|
|
|
void render(ImDrawData* _drawData)
|
2015-01-20 04:16:59 +03:00
|
|
|
{
|
2015-10-09 08:46:17 +03:00
|
|
|
const ImGuiIO& io = ImGui::GetIO();
|
|
|
|
const float width = io.DisplaySize.x;
|
|
|
|
const float height = io.DisplaySize.y;
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2015-10-09 08:46:17 +03:00
|
|
|
{
|
|
|
|
float ortho[16];
|
|
|
|
bx::mtxOrtho(ortho, 0.0f, width, height, 0.0f, -1.0f, 1.0f);
|
|
|
|
bgfx::setViewTransform(m_viewId, NULL, ortho);
|
|
|
|
}
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2015-01-20 04:16:59 +03:00
|
|
|
// Render command lists
|
2015-10-09 08:46:17 +03:00
|
|
|
for (int32_t ii = 0, num = _drawData->CmdListsCount; ii < num; ++ii)
|
2015-01-20 07:34:54 +03:00
|
|
|
{
|
2015-01-20 04:16:59 +03:00
|
|
|
bgfx::TransientVertexBuffer tvb;
|
2015-07-15 20:53:37 +03:00
|
|
|
bgfx::TransientIndexBuffer tib;
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2015-10-09 08:46:17 +03:00
|
|
|
const ImDrawList* drawList = _drawData->CmdLists[ii];
|
|
|
|
uint32_t numVertices = (uint32_t)drawList->VtxBuffer.size();
|
|
|
|
uint32_t numIndices = (uint32_t)drawList->IdxBuffer.size();
|
2015-01-18 23:58:56 +03:00
|
|
|
|
2016-12-23 03:18:44 +03:00
|
|
|
if (!checkAvailTransientBuffers(numVertices, m_decl, numIndices) )
|
2015-01-20 07:34:54 +03:00
|
|
|
{
|
2015-01-20 04:16:59 +03:00
|
|
|
// not enough space in transient buffer just quit drawing the rest...
|
|
|
|
break;
|
|
|
|
}
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2015-10-09 08:46:17 +03:00
|
|
|
bgfx::allocTransientVertexBuffer(&tvb, numVertices, m_decl);
|
|
|
|
bgfx::allocTransientIndexBuffer(&tib, numIndices);
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2015-01-20 04:16:59 +03:00
|
|
|
ImDrawVert* verts = (ImDrawVert*)tvb.data;
|
2015-10-09 08:46:17 +03:00
|
|
|
memcpy(verts, drawList->VtxBuffer.begin(), numVertices * sizeof(ImDrawVert) );
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2015-07-15 20:53:37 +03:00
|
|
|
ImDrawIdx* indices = (ImDrawIdx*)tib.data;
|
2015-10-09 08:46:17 +03:00
|
|
|
memcpy(indices, drawList->IdxBuffer.begin(), numIndices * sizeof(ImDrawIdx) );
|
2015-07-15 19:52:17 +03:00
|
|
|
|
2015-10-09 08:46:17 +03:00
|
|
|
uint32_t offset = 0;
|
|
|
|
for (const ImDrawCmd* cmd = drawList->CmdBuffer.begin(), *cmdEnd = drawList->CmdBuffer.end(); cmd != cmdEnd; ++cmd)
|
2015-01-20 07:34:54 +03:00
|
|
|
{
|
2015-10-09 08:46:17 +03:00
|
|
|
if (cmd->UserCallback)
|
2015-07-15 20:53:37 +03:00
|
|
|
{
|
2015-10-09 08:46:17 +03:00
|
|
|
cmd->UserCallback(drawList, cmd);
|
2015-07-15 20:53:37 +03:00
|
|
|
}
|
2015-10-09 08:46:17 +03:00
|
|
|
else if (0 != cmd->ElemCount)
|
2015-06-03 00:28:22 +03:00
|
|
|
{
|
2015-10-10 01:37:22 +03:00
|
|
|
uint64_t state = 0
|
|
|
|
| BGFX_STATE_RGB_WRITE
|
|
|
|
| BGFX_STATE_ALPHA_WRITE
|
|
|
|
| BGFX_STATE_MSAA
|
|
|
|
;
|
|
|
|
|
|
|
|
bgfx::TextureHandle th = m_texture;
|
2016-02-16 03:55:32 +03:00
|
|
|
bgfx::ProgramHandle program = m_program;
|
2015-10-10 01:37:22 +03:00
|
|
|
|
|
|
|
if (NULL != cmd->TextureId)
|
|
|
|
{
|
2016-02-16 03:55:32 +03:00
|
|
|
union { ImTextureID ptr; struct { bgfx::TextureHandle handle; uint8_t flags; uint8_t mip; } s; } texture = { cmd->TextureId };
|
2015-10-10 01:37:22 +03:00
|
|
|
state |= 0 != (IMGUI_FLAGS_ALPHA_BLEND & texture.s.flags)
|
|
|
|
? BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA)
|
|
|
|
: BGFX_STATE_NONE
|
|
|
|
;
|
|
|
|
th = texture.s.handle;
|
2016-02-16 03:55:32 +03:00
|
|
|
if (0 != texture.s.mip)
|
|
|
|
{
|
|
|
|
extern bgfx::ProgramHandle imguiGetImageProgram(uint8_t _mip);
|
|
|
|
program = imguiGetImageProgram(texture.s.mip);
|
|
|
|
}
|
2015-10-10 01:37:22 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state |= BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA);
|
|
|
|
}
|
|
|
|
|
2015-10-09 08:46:17 +03:00
|
|
|
const uint16_t xx = uint16_t(bx::fmax(cmd->ClipRect.x, 0.0f) );
|
|
|
|
const uint16_t yy = uint16_t(bx::fmax(cmd->ClipRect.y, 0.0f) );
|
|
|
|
bgfx::setScissor(xx, yy
|
|
|
|
, uint16_t(bx::fmin(cmd->ClipRect.z, 65535.0f)-xx)
|
|
|
|
, uint16_t(bx::fmin(cmd->ClipRect.w, 65535.0f)-yy)
|
|
|
|
);
|
|
|
|
|
2015-10-10 01:37:22 +03:00
|
|
|
bgfx::setState(state);
|
|
|
|
bgfx::setTexture(0, s_tex, th);
|
2015-10-09 08:46:17 +03:00
|
|
|
bgfx::setVertexBuffer(&tvb, 0, numVertices);
|
|
|
|
bgfx::setIndexBuffer(&tib, offset, cmd->ElemCount);
|
2016-02-16 03:55:32 +03:00
|
|
|
bgfx::submit(cmd->ViewId, program);
|
2015-06-03 00:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-10-09 08:46:17 +03:00
|
|
|
offset += cmd->ElemCount;
|
2015-01-20 04:16:59 +03:00
|
|
|
}
|
2015-01-17 09:41:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-29 02:26:12 +03:00
|
|
|
void create(float _fontSize, bx::AllocatorI* _allocator)
|
2015-01-20 04:16:59 +03:00
|
|
|
{
|
2015-02-22 02:51:03 +03:00
|
|
|
m_viewId = 255;
|
2015-04-16 06:00:15 +03:00
|
|
|
m_allocator = _allocator;
|
2015-07-15 20:53:37 +03:00
|
|
|
m_lastScroll = 0;
|
2015-07-18 05:57:24 +03:00
|
|
|
m_last = bx::getHPCounter();
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2015-01-20 04:16:59 +03:00
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
2015-04-16 06:00:15 +03:00
|
|
|
io.RenderDrawListsFn = renderDrawLists;
|
|
|
|
if (NULL != m_allocator)
|
|
|
|
{
|
|
|
|
io.MemAllocFn = memAlloc;
|
|
|
|
io.MemFreeFn = memFree;
|
|
|
|
}
|
2015-07-18 05:57:24 +03:00
|
|
|
|
2015-01-20 04:16:59 +03:00
|
|
|
io.DisplaySize = ImVec2(1280.0f, 720.0f);
|
2015-07-18 05:20:10 +03:00
|
|
|
io.DeltaTime = 1.0f / 60.0f;
|
2015-04-05 10:04:16 +03:00
|
|
|
io.IniFilename = NULL;
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2016-05-11 17:44:13 +03:00
|
|
|
setupStyle(true);
|
|
|
|
|
2015-06-10 19:53:09 +03:00
|
|
|
#if defined(SCI_NAMESPACE)
|
|
|
|
io.KeyMap[ImGuiKey_Tab] = (int)entry::Key::Tab;
|
|
|
|
io.KeyMap[ImGuiKey_LeftArrow] = (int)entry::Key::Left;
|
|
|
|
io.KeyMap[ImGuiKey_RightArrow] = (int)entry::Key::Right;
|
|
|
|
io.KeyMap[ImGuiKey_UpArrow] = (int)entry::Key::Up;
|
|
|
|
io.KeyMap[ImGuiKey_DownArrow] = (int)entry::Key::Down;
|
|
|
|
io.KeyMap[ImGuiKey_Home] = (int)entry::Key::Home;
|
|
|
|
io.KeyMap[ImGuiKey_End] = (int)entry::Key::End;
|
|
|
|
io.KeyMap[ImGuiKey_Delete] = (int)entry::Key::Delete;
|
|
|
|
io.KeyMap[ImGuiKey_Backspace] = (int)entry::Key::Backspace;
|
|
|
|
io.KeyMap[ImGuiKey_Enter] = (int)entry::Key::Return;
|
|
|
|
io.KeyMap[ImGuiKey_Escape] = (int)entry::Key::Esc;
|
|
|
|
io.KeyMap[ImGuiKey_A] = (int)entry::Key::KeyA;
|
|
|
|
io.KeyMap[ImGuiKey_C] = (int)entry::Key::KeyC;
|
|
|
|
io.KeyMap[ImGuiKey_V] = (int)entry::Key::KeyV;
|
|
|
|
io.KeyMap[ImGuiKey_X] = (int)entry::Key::KeyX;
|
|
|
|
io.KeyMap[ImGuiKey_Y] = (int)entry::Key::KeyY;
|
|
|
|
io.KeyMap[ImGuiKey_Z] = (int)entry::Key::KeyZ;
|
|
|
|
#endif // defined(SCI_NAMESPACE)
|
2015-06-03 00:28:22 +03:00
|
|
|
|
2016-12-05 07:11:10 +03:00
|
|
|
bgfx::RendererType::Enum type = bgfx::getRendererType();
|
|
|
|
m_program = bgfx::createProgram(
|
|
|
|
bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_ocornut_imgui")
|
|
|
|
, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_ocornut_imgui")
|
|
|
|
, true
|
|
|
|
);
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2015-01-20 04:16:59 +03:00
|
|
|
m_decl
|
|
|
|
.begin()
|
2015-10-01 06:02:59 +03:00
|
|
|
.add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float)
|
2015-01-20 04:16:59 +03:00
|
|
|
.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
|
2015-10-01 06:02:59 +03:00
|
|
|
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
|
2015-01-20 04:16:59 +03:00
|
|
|
.end();
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2015-05-29 01:27:00 +03:00
|
|
|
s_tex = bgfx::createUniform("s_tex", bgfx::UniformType::Int1);
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2015-01-23 08:01:09 +03:00
|
|
|
uint8_t* data;
|
|
|
|
int32_t width;
|
|
|
|
int32_t height;
|
2015-11-12 03:43:32 +03:00
|
|
|
{
|
2016-05-28 22:12:59 +03:00
|
|
|
ImFontConfig config;
|
|
|
|
config.FontDataOwnedByAtlas = false;
|
|
|
|
config.MergeMode = false;
|
2016-05-29 02:26:12 +03:00
|
|
|
// config.MergeGlyphCenterV = true;
|
2016-05-28 22:12:59 +03:00
|
|
|
|
2016-05-29 03:14:19 +03:00
|
|
|
m_font[ImGui::Font::Regular] = io.Fonts->AddFontFromMemoryTTF( (void*)s_robotoRegularTtf, sizeof(s_robotoRegularTtf), _fontSize, &config);
|
|
|
|
m_font[ImGui::Font::Mono ] = io.Fonts->AddFontFromMemoryTTF( (void*)s_robotoMonoRegularTtf, sizeof(s_robotoMonoRegularTtf), _fontSize-3.0f, &config);
|
2016-05-28 22:12:59 +03:00
|
|
|
|
|
|
|
config.MergeMode = true;
|
2016-05-29 02:26:12 +03:00
|
|
|
config.DstFont = m_font[ImGui::Font::Regular];
|
2016-05-28 22:12:59 +03:00
|
|
|
|
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(s_fontRangeMerge); ++ii)
|
|
|
|
{
|
|
|
|
const FontRangeMerge& frm = s_fontRangeMerge[ii];
|
|
|
|
|
|
|
|
io.Fonts->AddFontFromMemoryTTF( (void*)frm.data
|
2016-06-01 03:45:58 +03:00
|
|
|
, (int)frm.size
|
2016-06-06 07:36:58 +03:00
|
|
|
, _fontSize-3.0f
|
2016-05-28 22:12:59 +03:00
|
|
|
, &config
|
|
|
|
, frm.ranges
|
|
|
|
);
|
|
|
|
}
|
2015-11-12 03:43:32 +03:00
|
|
|
}
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2015-01-23 08:01:09 +03:00
|
|
|
io.Fonts->GetTexDataAsRGBA32(&data, &width, &height);
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2016-08-20 07:05:37 +03:00
|
|
|
m_texture = bgfx::createTexture2D(
|
|
|
|
(uint16_t)width
|
2015-01-23 08:01:09 +03:00
|
|
|
, (uint16_t)height
|
2016-08-20 07:05:37 +03:00
|
|
|
, false
|
2015-01-20 04:16:59 +03:00
|
|
|
, 1
|
|
|
|
, bgfx::TextureFormat::BGRA8
|
2015-07-15 19:52:17 +03:00
|
|
|
, 0
|
2015-01-23 08:01:09 +03:00
|
|
|
, bgfx::copy(data, width*height*4)
|
2015-01-20 04:16:59 +03:00
|
|
|
);
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2016-10-21 08:04:01 +03:00
|
|
|
ImGui::InitDockContext();
|
2015-01-20 04:16:59 +03:00
|
|
|
}
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2015-01-20 04:16:59 +03:00
|
|
|
void destroy()
|
|
|
|
{
|
2016-10-21 08:04:01 +03:00
|
|
|
ImGui::ShutdownDockContext();
|
2015-04-16 06:00:15 +03:00
|
|
|
ImGui::Shutdown();
|
|
|
|
|
2015-01-20 04:16:59 +03:00
|
|
|
bgfx::destroyUniform(s_tex);
|
|
|
|
bgfx::destroyTexture(m_texture);
|
|
|
|
bgfx::destroyProgram(m_program);
|
2015-04-16 06:00:15 +03:00
|
|
|
|
|
|
|
m_allocator = NULL;
|
2015-01-20 04:16:59 +03:00
|
|
|
}
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2016-05-11 17:44:13 +03:00
|
|
|
void setupStyle(bool _dark)
|
|
|
|
{
|
2016-05-12 19:42:44 +03:00
|
|
|
// Doug Binks' darl color scheme
|
2016-05-11 17:44:13 +03:00
|
|
|
// https://gist.github.com/dougbinks/8089b4bbaccaaf6fa204236978d165a9
|
|
|
|
ImGuiStyle& style = ImGui::GetStyle();
|
|
|
|
|
2016-05-29 02:26:12 +03:00
|
|
|
style.FrameRounding = 4.0f;
|
|
|
|
|
2016-05-12 19:42:44 +03:00
|
|
|
// light style from Pacome Danhiez (user itamago)
|
|
|
|
// https://github.com/ocornut/imgui/pull/511#issuecomment-175719267
|
2016-05-11 17:44:13 +03:00
|
|
|
style.Colors[ImGuiCol_Text] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.94f, 0.94f, 0.94f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
|
|
|
style.Colors[ImGuiCol_Border] = ImVec4(0.00f, 0.00f, 0.00f, 0.39f);
|
|
|
|
style.Colors[ImGuiCol_BorderShadow] = ImVec4(1.00f, 1.00f, 1.00f, 0.10f);
|
|
|
|
style.Colors[ImGuiCol_FrameBg] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f);
|
|
|
|
style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
|
|
|
|
style.Colors[ImGuiCol_TitleBg] = ImVec4(0.96f, 0.96f, 0.96f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 1.00f, 1.00f, 0.51f);
|
|
|
|
style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.82f, 0.82f, 0.82f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.86f, 0.86f, 0.86f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.98f, 0.98f, 0.98f, 0.53f);
|
|
|
|
style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.69f, 0.69f, 0.69f, 0.80f);
|
|
|
|
style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.49f, 0.49f, 0.49f, 0.80f);
|
|
|
|
style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.49f, 0.49f, 0.49f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_ComboBg] = ImVec4(0.86f, 0.86f, 0.86f, 0.99f);
|
|
|
|
style.Colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f);
|
|
|
|
style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_Button] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f);
|
|
|
|
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.31f);
|
|
|
|
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f);
|
|
|
|
style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_Column] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_ColumnHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f);
|
|
|
|
style.Colors[ImGuiCol_ColumnActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.50f);
|
|
|
|
style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
|
|
|
|
style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
|
|
|
|
style.Colors[ImGuiCol_CloseButton] = ImVec4(0.59f, 0.59f, 0.59f, 0.50f);
|
|
|
|
style.Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_PlotLines] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
|
|
|
|
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
|
2016-05-12 03:02:41 +03:00
|
|
|
style.Colors[ImGuiCol_PopupBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.94f);
|
2016-05-11 17:44:13 +03:00
|
|
|
style.Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
|
|
|
|
|
|
|
|
if (_dark)
|
|
|
|
{
|
|
|
|
for (int i = 0; i <= ImGuiCol_COUNT; i++)
|
|
|
|
{
|
|
|
|
ImVec4& col = style.Colors[i];
|
|
|
|
float H, S, V;
|
|
|
|
ImGui::ColorConvertRGBtoHSV( col.x, col.y, col.z, H, S, V );
|
|
|
|
|
|
|
|
if( S < 0.1f )
|
|
|
|
{
|
|
|
|
V = 1.0f - V;
|
|
|
|
}
|
|
|
|
ImGui::ColorConvertHSVtoRGB( H, S, V, col.x, col.y, col.z );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-10 17:53:50 +03:00
|
|
|
void beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, int _width, int _height, char _inputChar, uint8_t _viewId)
|
2015-01-20 04:16:59 +03:00
|
|
|
{
|
2015-11-12 03:43:32 +03:00
|
|
|
m_viewId = _viewId;
|
2015-10-09 08:46:17 +03:00
|
|
|
|
2015-01-20 04:16:59 +03:00
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
2015-07-15 20:53:37 +03:00
|
|
|
if (_inputChar < 0x7f)
|
2015-06-10 19:53:09 +03:00
|
|
|
{
|
2015-07-15 20:53:37 +03:00
|
|
|
io.AddInputCharacter(_inputChar); // ASCII or GTFO! :(
|
2015-06-10 19:53:09 +03:00
|
|
|
}
|
|
|
|
|
2015-07-17 06:28:43 +03:00
|
|
|
io.DisplaySize = ImVec2( (float)_width, (float)_height);
|
2015-07-18 05:57:24 +03:00
|
|
|
|
|
|
|
const int64_t now = bx::getHPCounter();
|
|
|
|
const int64_t frameTime = now - m_last;
|
|
|
|
m_last = now;
|
|
|
|
const double freq = double(bx::getHPFrequency() );
|
|
|
|
io.DeltaTime = float(frameTime/freq);
|
|
|
|
|
2015-07-17 06:28:43 +03:00
|
|
|
io.MousePos = ImVec2( (float)_mx, (float)_my);
|
2015-01-20 04:16:59 +03:00
|
|
|
io.MouseDown[0] = 0 != (_button & IMGUI_MBUT_LEFT);
|
2015-06-10 19:53:09 +03:00
|
|
|
io.MouseDown[1] = 0 != (_button & IMGUI_MBUT_RIGHT);
|
2015-08-26 08:59:20 +03:00
|
|
|
io.MouseDown[2] = 0 != (_button & IMGUI_MBUT_MIDDLE);
|
2015-06-10 19:53:09 +03:00
|
|
|
io.MouseWheel = (float)(_scroll - m_lastScroll);
|
|
|
|
m_lastScroll = _scroll;
|
|
|
|
|
|
|
|
#if defined(SCI_NAMESPACE)
|
|
|
|
uint8_t modifiers = inputGetModifiersState();
|
|
|
|
io.KeyShift = 0 != (modifiers & (entry::Modifier::LeftShift | entry::Modifier::RightShift) );
|
|
|
|
io.KeyCtrl = 0 != (modifiers & (entry::Modifier::LeftCtrl | entry::Modifier::RightCtrl ) );
|
|
|
|
io.KeyAlt = 0 != (modifiers & (entry::Modifier::LeftAlt | entry::Modifier::RightAlt ) );
|
|
|
|
for (int32_t ii = 0; ii < (int32_t)entry::Key::Count; ++ii)
|
|
|
|
{
|
|
|
|
io.KeysDown[ii] = inputGetKeyState(entry::Key::Enum(ii) );
|
|
|
|
}
|
|
|
|
#endif // defined(SCI_NAMESPACE)
|
2015-06-03 00:28:22 +03:00
|
|
|
|
2015-01-20 04:16:59 +03:00
|
|
|
ImGui::NewFrame();
|
2016-08-30 08:31:30 +03:00
|
|
|
ImGuizmo::BeginFrame();
|
2015-11-12 03:43:32 +03:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ViewId, (float)_viewId);
|
2015-01-20 04:16:59 +03:00
|
|
|
}
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2015-01-20 04:16:59 +03:00
|
|
|
void endFrame()
|
|
|
|
{
|
2015-11-12 03:43:32 +03:00
|
|
|
ImGui::PopStyleVar(1);
|
2015-01-20 04:16:59 +03:00
|
|
|
ImGui::Render();
|
|
|
|
}
|
|
|
|
|
2015-04-16 06:00:15 +03:00
|
|
|
bx::AllocatorI* m_allocator;
|
2015-01-20 04:16:59 +03:00
|
|
|
bgfx::VertexDecl m_decl;
|
|
|
|
bgfx::ProgramHandle m_program;
|
|
|
|
bgfx::TextureHandle m_texture;
|
|
|
|
bgfx::UniformHandle s_tex;
|
2016-05-29 02:26:12 +03:00
|
|
|
ImFont* m_font[ImGui::Font::Count];
|
2015-07-18 05:57:24 +03:00
|
|
|
int64_t m_last;
|
2015-07-15 20:53:37 +03:00
|
|
|
int32_t m_lastScroll;
|
2015-07-18 05:57:24 +03:00
|
|
|
uint8_t m_viewId;
|
2015-01-20 04:16:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static OcornutImguiContext s_ctx;
|
2015-01-17 09:41:37 +03:00
|
|
|
|
2015-04-16 06:00:15 +03:00
|
|
|
void* OcornutImguiContext::memAlloc(size_t _size)
|
|
|
|
{
|
|
|
|
return BX_ALLOC(s_ctx.m_allocator, _size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OcornutImguiContext::memFree(void* _ptr)
|
|
|
|
{
|
|
|
|
BX_FREE(s_ctx.m_allocator, _ptr);
|
|
|
|
}
|
|
|
|
|
2015-11-12 03:43:32 +03:00
|
|
|
void OcornutImguiContext::renderDrawLists(ImDrawData* _drawData)
|
2015-01-17 09:41:37 +03:00
|
|
|
{
|
2015-11-12 03:43:32 +03:00
|
|
|
s_ctx.render(_drawData);
|
2015-01-17 09:41:37 +03:00
|
|
|
}
|
|
|
|
|
2016-05-29 02:26:12 +03:00
|
|
|
void IMGUI_create(float _fontSize, bx::AllocatorI* _allocator)
|
2015-01-17 09:41:37 +03:00
|
|
|
{
|
2016-05-29 02:26:12 +03:00
|
|
|
s_ctx.create(_fontSize, _allocator);
|
2015-01-17 09:41:37 +03:00
|
|
|
}
|
|
|
|
|
2015-01-20 04:16:59 +03:00
|
|
|
void IMGUI_destroy()
|
2015-01-17 09:41:37 +03:00
|
|
|
{
|
2015-01-20 04:16:59 +03:00
|
|
|
s_ctx.destroy();
|
2015-01-17 09:41:37 +03:00
|
|
|
}
|
|
|
|
|
2015-06-10 17:53:50 +03:00
|
|
|
void IMGUI_beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, int _width, int _height, char _inputChar, uint8_t _viewId)
|
2015-01-17 09:41:37 +03:00
|
|
|
{
|
2015-06-10 17:53:50 +03:00
|
|
|
s_ctx.beginFrame(_mx, _my, _button, _scroll, _width, _height, _inputChar, _viewId);
|
2015-01-17 09:41:37 +03:00
|
|
|
}
|
|
|
|
|
2015-01-20 04:16:59 +03:00
|
|
|
void IMGUI_endFrame()
|
2015-01-17 09:41:37 +03:00
|
|
|
{
|
2015-01-20 04:16:59 +03:00
|
|
|
s_ctx.endFrame();
|
2015-01-17 09:41:37 +03:00
|
|
|
}
|
2016-05-29 02:26:12 +03:00
|
|
|
|
|
|
|
namespace ImGui
|
|
|
|
{
|
|
|
|
void PushFont(Font::Enum _font)
|
|
|
|
{
|
|
|
|
PushFont(s_ctx.m_font[_font]);
|
|
|
|
}
|
|
|
|
} // namespace ImGui
|