Browse Source

Various ImGui interface improvements.

legacy
Sam Hocevar 6 years ago
parent
commit
332028f00e
1 changed files with 15 additions and 16 deletions
  1. +15
    -16
      src/lolimgui.cpp

+ 15
- 16
src/lolimgui.cpp View File

@@ -187,7 +187,7 @@ void LolImGui::TickGame(float seconds)


ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();


//Init Texture
// Init Texture
if (!m_font) if (!m_font)
{ {
// Build texture // Build texture
@@ -200,22 +200,22 @@ void LolImGui::TickGame(float seconds)


Ticker::Ref(m_font = new TextureImage("", image)); Ticker::Ref(m_font = new TextureImage("", image));
} }
//Texture has been created

// Texture has been created
if (m_font && m_font->GetTexture()) if (m_font && m_font->GetTexture())
{ {
io.Fonts->TexID = (void *)(intptr_t)m_font;
io.Fonts->TexID = (void *)m_font->GetTexture();
} }


// Setup display size (every frame to accommodate for window resizing) // Setup display size (every frame to accommodate for window resizing)
vec2 video_size = vec2(0);
video_size = vec2(Video::GetSize());
io.DisplaySize = ImVec2(video_size.x, video_size.y);
auto video_size = vec2(Video::GetSize());
io.DisplaySize = video_size;


//Setup time step
// Setup time step
io.DeltaTime = seconds; io.DeltaTime = seconds;
io.MouseDrawCursor = true; io.MouseDrawCursor = true;


//Update Keyboard
// Update Keyboard
io.KeyCtrl = false; io.KeyCtrl = false;
io.KeyShift = false; io.KeyShift = false;
for (int i = LolImGuiKey::KEY_START; i < LolImGuiKey::KEY_END; ++i) for (int i = LolImGuiKey::KEY_START; i < LolImGuiKey::KEY_END; ++i)
@@ -244,13 +244,13 @@ void LolImGui::TickGame(float seconds)
for (auto ch : text) for (auto ch : text)
io.AddInputCharacter(ch); io.AddInputCharacter(ch);


//Update mouse
// Update mouse
if (m_mouse) if (m_mouse)
{ {
vec2 cursor = m_mouse->GetCursor(0); vec2 cursor = m_mouse->GetCursor(0);
cursor.y = 1.f - cursor.y; cursor.y = 1.f - cursor.y;
cursor *= video_size;
io.MousePos = ImVec2(cursor.x, cursor.y);
io.MousePos = cursor * video_size;
//msg::debug("%.2f/%.2f\n", io.MousePos.x, io.MousePos.y); //msg::debug("%.2f/%.2f\n", io.MousePos.x, io.MousePos.y);
io.MouseWheel = m_controller->GetAxisValue(LolImGuiAxis::Scroll); io.MouseWheel = m_controller->GetAxisValue(LolImGuiAxis::Scroll);


@@ -265,7 +265,7 @@ void LolImGui::TickGame(float seconds)
if (m_controller->IsKeyReleased(i)) if (m_controller->IsKeyReleased(i))
{ {
//msg::debug("Not focused .....\n"); //msg::debug("Not focused .....\n");
io.MousePos = ImVec2(-1.f, -1.f);
//io.MousePos = vec2(-1.f);
} }
else else
{ {
@@ -314,6 +314,7 @@ void LolImGui::RenderDrawLists(ImDrawData* draw_data)
{ {
g_lolimgui->RenderDrawListsMethod(draw_data); g_lolimgui->RenderDrawListsMethod(draw_data);
} }

void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data)
{ {
if (draw_data == nullptr) if (draw_data == nullptr)
@@ -394,8 +395,8 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data)
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{ {
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[(int)cmd_i]; const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[(int)cmd_i];
TextureImage* image = (TextureImage*)pcmd->TextureId;
if (image) image->Bind();
Texture* texture = (Texture*)pcmd->TextureId;
if (texture) texture->Bind();


rc.SetScissorRect(vec4(pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w)); rc.SetScissorRect(vec4(pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w));


@@ -445,8 +446,6 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data)
m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, pcmd->ElemCount, (const short*)idx_buffer_offset); m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, pcmd->ElemCount, (const short*)idx_buffer_offset);


idx_buffer_offset += pcmd->ElemCount; idx_buffer_offset += pcmd->ElemCount;

if (image) image->Unbind();
} }


m_vdecl->Unbind(); m_vdecl->Unbind();


Loading…
Cancel
Save