mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 10:35:43 -05:00
Cleanup.
This commit is contained in:
parent
af2bb3874d
commit
1cf4f92152
3 changed files with 59 additions and 33 deletions
2
3rdparty/ocornut-imgui/imgui.cpp
vendored
2
3rdparty/ocornut-imgui/imgui.cpp
vendored
|
@ -9707,6 +9707,8 @@ void ImFontAtlas::ClearInputData()
|
|||
ImGui::MemFree(ConfigData[i].FontData);
|
||||
ConfigData[i].FontData = NULL;
|
||||
}
|
||||
|
||||
ConfigData.clear();
|
||||
}
|
||||
|
||||
void ImFontAtlas::ClearTexData()
|
||||
|
|
|
@ -38,11 +38,11 @@ struct OcornutImguiContext
|
|||
for (int32_t ii = 0; ii < draw_data->CmdListsCount; ++ii)
|
||||
{
|
||||
bgfx::TransientVertexBuffer tvb;
|
||||
bgfx::TransientIndexBuffer tib;
|
||||
bgfx::TransientIndexBuffer tib;
|
||||
|
||||
const ImDrawList* cmd_list = draw_data->CmdLists[ii];
|
||||
uint32_t vtx_size = (uint32_t)cmd_list->VtxBuffer.size();
|
||||
uint32_t idx_size = (uint32_t)cmd_list->IdxBuffer.size();
|
||||
uint32_t vtx_size = (uint32_t)cmd_list->VtxBuffer.size();
|
||||
uint32_t idx_size = (uint32_t)cmd_list->IdxBuffer.size();
|
||||
|
||||
if (!bgfx::checkAvailTransientVertexBuffer(vtx_size, m_decl) || !bgfx::checkAvailTransientIndexBuffer(idx_size))
|
||||
{
|
||||
|
@ -51,25 +51,25 @@ struct OcornutImguiContext
|
|||
}
|
||||
|
||||
bgfx::allocTransientVertexBuffer(&tvb, vtx_size, m_decl);
|
||||
bgfx::allocTransientIndexBuffer(&tib, idx_size);
|
||||
bgfx::allocTransientIndexBuffer(&tib, idx_size);
|
||||
|
||||
ImDrawVert* verts = (ImDrawVert*)tvb.data;
|
||||
memcpy(verts, cmd_list->VtxBuffer.begin(), vtx_size * sizeof(ImDrawVert));
|
||||
memcpy(verts, cmd_list->VtxBuffer.begin(), vtx_size * sizeof(ImDrawVert));
|
||||
|
||||
ImDrawIdx* indices = (ImDrawIdx*)tib.data;
|
||||
memcpy(indices, cmd_list->IdxBuffer.begin(), idx_size * sizeof(ImDrawIdx));
|
||||
ImDrawIdx* indices = (ImDrawIdx*)tib.data;
|
||||
memcpy(indices, cmd_list->IdxBuffer.begin(), idx_size * sizeof(ImDrawIdx));
|
||||
|
||||
uint32_t elem_offset = 0;
|
||||
const ImDrawCmd* pcmd_begin = cmd_list->CmdBuffer.begin();
|
||||
const ImDrawCmd* pcmd_end = cmd_list->CmdBuffer.end();
|
||||
const ImDrawCmd* pcmd_begin = cmd_list->CmdBuffer.begin();
|
||||
const ImDrawCmd* pcmd_end = cmd_list->CmdBuffer.end();
|
||||
for (const ImDrawCmd* pcmd = pcmd_begin; pcmd != pcmd_end; pcmd++)
|
||||
{
|
||||
if (pcmd->UserCallback)
|
||||
{
|
||||
pcmd->UserCallback(cmd_list, pcmd);
|
||||
elem_offset += pcmd->ElemCount;
|
||||
continue;
|
||||
}
|
||||
if (pcmd->UserCallback)
|
||||
{
|
||||
pcmd->UserCallback(cmd_list, pcmd);
|
||||
elem_offset += pcmd->ElemCount;
|
||||
continue;
|
||||
}
|
||||
if (0 == pcmd->ElemCount)
|
||||
{
|
||||
continue;
|
||||
|
@ -82,11 +82,11 @@ struct OcornutImguiContext
|
|||
| BGFX_STATE_MSAA
|
||||
);
|
||||
bgfx::setScissor(uint16_t(bx::fmax(pcmd->ClipRect.x, 0.0f))
|
||||
, uint16_t(bx::fmax(pcmd->ClipRect.y, 0.0f))
|
||||
, uint16_t(bx::fmin(pcmd->ClipRect.z, 65535.0f)-bx::fmax(pcmd->ClipRect.x, 0.0f))
|
||||
, uint16_t(bx::fmin(pcmd->ClipRect.w, 65535.0f)-bx::fmax(pcmd->ClipRect.y, 0.0f))
|
||||
);
|
||||
union { void* ptr; bgfx::TextureHandle handle; } texture = { pcmd->TextureId };
|
||||
, uint16_t(bx::fmax(pcmd->ClipRect.y, 0.0f))
|
||||
, uint16_t(bx::fmin(pcmd->ClipRect.z, 65535.0f)-bx::fmax(pcmd->ClipRect.x, 0.0f))
|
||||
, uint16_t(bx::fmin(pcmd->ClipRect.w, 65535.0f)-bx::fmax(pcmd->ClipRect.y, 0.0f))
|
||||
);
|
||||
union { void* ptr; bgfx::TextureHandle handle; } texture ={ pcmd->TextureId };
|
||||
|
||||
bgfx::setTexture(0, s_tex, 0 != texture.handle.idx
|
||||
? texture.handle
|
||||
|
@ -94,7 +94,7 @@ struct OcornutImguiContext
|
|||
);
|
||||
|
||||
bgfx::setVertexBuffer(&tvb, 0, vtx_size);
|
||||
bgfx::setIndexBuffer(&tib, elem_offset, pcmd->ElemCount);
|
||||
bgfx::setIndexBuffer(&tib, elem_offset, pcmd->ElemCount);
|
||||
bgfx::setProgram(m_program);
|
||||
bgfx::submit(m_viewId);
|
||||
|
||||
|
@ -107,7 +107,7 @@ struct OcornutImguiContext
|
|||
{
|
||||
m_viewId = 255;
|
||||
m_allocator = _allocator;
|
||||
m_lastScroll = 0;
|
||||
m_lastScroll = 0;
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.RenderDrawListsFn = renderDrawLists;
|
||||
|
@ -185,7 +185,7 @@ struct OcornutImguiContext
|
|||
|
||||
io.Fonts->GetTexDataAsRGBA32(&data, &width, &height);
|
||||
|
||||
m_texture = bgfx::createTexture2D( (uint16_t)width
|
||||
m_texture = bgfx::createTexture2D((uint16_t)width
|
||||
, (uint16_t)height
|
||||
, 1
|
||||
, bgfx::TextureFormat::BGRA8
|
||||
|
@ -212,9 +212,9 @@ struct OcornutImguiContext
|
|||
{
|
||||
m_viewId = _viewId;
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
if (_inputChar < 0x7f)
|
||||
if (_inputChar < 0x7f)
|
||||
{
|
||||
io.AddInputCharacter(_inputChar); // ASCII or GTFO! :(
|
||||
io.AddInputCharacter(_inputChar); // ASCII or GTFO! :(
|
||||
}
|
||||
|
||||
io.DisplaySize = ImVec2((float)_width, (float)_height);
|
||||
|
@ -252,7 +252,7 @@ struct OcornutImguiContext
|
|||
bgfx::TextureHandle m_texture;
|
||||
bgfx::UniformHandle s_tex;
|
||||
uint8_t m_viewId;
|
||||
int32_t m_lastScroll;
|
||||
int32_t m_lastScroll;
|
||||
};
|
||||
|
||||
static OcornutImguiContext s_ctx;
|
||||
|
|
|
@ -80,8 +80,8 @@ static inline uint32_t makeRgba(uint32_t r, uint32_t g, uint32_t b, uint32_t a =
|
|||
|
||||
struct FontInt
|
||||
{
|
||||
ImFont* m_font;
|
||||
float m_scale;
|
||||
ImFont* m_font;
|
||||
float m_scale;
|
||||
float m_fontSize;
|
||||
};
|
||||
|
||||
|
@ -236,7 +236,7 @@ public:
|
|||
virtual Scintilla::XYPOSITION WidthChar(Scintilla::Font& _font, char ch) BX_OVERRIDE
|
||||
{
|
||||
FontInt* fi = (FontInt*)_font.GetID();
|
||||
return fi->m_font->GetCharAdvance((unsigned int)ch) * fi->m_scale;
|
||||
return fi->m_font->GetCharAdvance((unsigned int)ch) * fi->m_scale;
|
||||
}
|
||||
|
||||
virtual Scintilla::XYPOSITION Ascent(Scintilla::Font& _font) BX_OVERRIDE
|
||||
|
@ -251,14 +251,14 @@ public:
|
|||
return -fi->m_font->Descent * fi->m_scale;
|
||||
}
|
||||
|
||||
virtual Scintilla::XYPOSITION InternalLeading(Scintilla::Font& /*_font*/) BX_OVERRIDE
|
||||
virtual Scintilla::XYPOSITION InternalLeading(Scintilla::Font& /*_font*/) BX_OVERRIDE
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual Scintilla::XYPOSITION ExternalLeading(Scintilla::Font& /*_font*/) BX_OVERRIDE
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual Scintilla::XYPOSITION Height(Scintilla::Font& _font) BX_OVERRIDE
|
||||
|
@ -633,7 +633,7 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
intptr_t command(unsigned int _msg, uintptr_t _p0 = 0, intptr_t _p1 = 0)
|
||||
intptr_t command(unsigned int _msg, uintptr_t _p0 = 0, intptr_t _p1 = 0)
|
||||
{
|
||||
return WndProc(_msg, _p0, _p1);
|
||||
}
|
||||
|
@ -854,7 +854,7 @@ namespace Scintilla
|
|||
}
|
||||
|
||||
void Font::Create(const FontParameters& fp)
|
||||
{
|
||||
{
|
||||
FontInt* newFont = (FontInt*)ImGui::MemAlloc(sizeof(FontInt) );
|
||||
fid = newFont;
|
||||
newFont->m_font = ImGui::GetIO().Fonts->Fonts[0];
|
||||
|
@ -1063,4 +1063,28 @@ namespace Scintilla
|
|||
|
||||
} // namespace Scintilla
|
||||
|
||||
ScintillaEditor* ImGuiScintilla(const char* _name, bool* _opened, const ImVec2& _size)
|
||||
{
|
||||
ScintillaEditor* sci = NULL;
|
||||
|
||||
if (ImGui::Begin(_name, _opened, _size) )
|
||||
{
|
||||
ImGuiStorage* storage = ImGui::GetStateStorage();
|
||||
|
||||
ImGuiID id = ImGui::GetID(_name);
|
||||
sci = (ScintillaEditor*)storage->GetVoidPtr(id);
|
||||
if (NULL == sci)
|
||||
{
|
||||
ImVec2 size = ImGui::GetWindowSize();
|
||||
sci = ScintillaEditor::create(size.x, size.y);
|
||||
storage->SetVoidPtr(id, (void*)sci);
|
||||
}
|
||||
|
||||
sci->draw();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
return sci;
|
||||
}
|
||||
|
||||
#endif // defined(SCI_NAMESPACE)
|
||||
|
|
Loading…
Reference in a new issue