Rearranged TTextBox immediate mode draw.
This commit is contained in:
parent
e8b0102bfb
commit
a845d0d630
|
@ -145,6 +145,43 @@ void TTextBox::Display(const char* text, float time)
|
|||
}
|
||||
}
|
||||
|
||||
void TTextBox::DrawImGui()
|
||||
{
|
||||
// Do nothing when using a font (the text will be rendered to VScreen in TTextBox::Draw)
|
||||
if (Font || !Message1)
|
||||
return;
|
||||
|
||||
char windowName[64];
|
||||
SDL_Rect rect;
|
||||
ImGuiWindowFlags window_flags =
|
||||
ImGuiWindowFlags_NoBackground |
|
||||
ImGuiWindowFlags_NoDecoration |
|
||||
ImGuiWindowFlags_NoSavedSettings |
|
||||
ImGuiWindowFlags_NoFocusOnAppearing |
|
||||
ImGuiWindowFlags_NoInputs;
|
||||
|
||||
rect.x = OffsetX;
|
||||
rect.y = OffsetY;
|
||||
rect.w = Width;
|
||||
rect.h = Height;
|
||||
|
||||
rect = fullscrn::GetScreenRectFromPinballRect(rect);
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2(rect.x, rect.y));
|
||||
ImGui::SetNextWindowSize(ImVec2(rect.w, rect.h));
|
||||
|
||||
// Use the pointer to generate a window unique name per text box
|
||||
snprintf(windowName, sizeof(windowName), "TTextBox_%p", this);
|
||||
if (ImGui::Begin(windowName, nullptr, window_flags))
|
||||
{
|
||||
ImGui::SetWindowFontScale(fullscrn::GetScreenToPinballRatio());
|
||||
|
||||
// ToDo: centered text in FT
|
||||
ImGui::TextWrapped("%s", Message1->Text);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void TTextBox::Draw()
|
||||
{
|
||||
auto bmp = BgBmp;
|
||||
|
@ -189,7 +226,7 @@ void TTextBox::Draw()
|
|||
{
|
||||
if (!Font)
|
||||
{
|
||||
// Handled by gdrv::grtext_draw_ttext_in_box()
|
||||
// Immediate mode drawing using system font is handled by TTextBox::DrawImGui
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ public:
|
|||
int Message(int code, float value) override;
|
||||
void Clear();
|
||||
void Display(const char* text, float time);
|
||||
void DrawImGui();
|
||||
|
||||
private:
|
||||
struct LayoutResult
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "winmain.h"
|
||||
#include "TTextBox.h"
|
||||
#include "fullscrn.h"
|
||||
#include "pinball.h"
|
||||
|
||||
ColorRgba gdrv::current_palette[256]{};
|
||||
|
||||
|
@ -271,40 +272,15 @@ void gdrv::ScrollBitmapHorizontal(gdrv_bitmap8* bmp, int xStart)
|
|||
}
|
||||
|
||||
|
||||
void gdrv::grtext_draw_ttext_in_box(TTextBox* textBox)
|
||||
void gdrv::grtext_draw_ttext_in_box()
|
||||
{
|
||||
// Do nothing when using a font (the text will be rendered in TTextBox::Draw)
|
||||
if(textBox->Font)
|
||||
return;
|
||||
|
||||
char windowName[64];
|
||||
SDL_Rect rect;
|
||||
ImGuiWindowFlags window_flags =
|
||||
ImGuiWindowFlags_NoBackground |
|
||||
ImGuiWindowFlags_NoDecoration |
|
||||
ImGuiWindowFlags_NoSavedSettings |
|
||||
ImGuiWindowFlags_NoFocusOnAppearing |
|
||||
ImGuiWindowFlags_NoInputs;
|
||||
|
||||
rect.x = textBox->OffsetX;
|
||||
rect.y = textBox->OffsetY;
|
||||
rect.w = textBox->Width;
|
||||
rect.h = textBox->Height;
|
||||
|
||||
rect = fullscrn::GetScreenRectFromPinballRect(rect);
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2(rect.x, rect.y));
|
||||
ImGui::SetNextWindowSize(ImVec2(rect.w, rect.h));
|
||||
|
||||
// Use the pointer to generate a window unique name per text box
|
||||
snprintf(windowName, sizeof(windowName), "TTextBox_%p", textBox);
|
||||
if (ImGui::Begin(windowName, nullptr, window_flags))
|
||||
for (const auto textBox : { pinball::InfoTextBox, pinball::MissTextBox })
|
||||
{
|
||||
ImGui::SetWindowFontScale(fullscrn::GetScreenToPinballRatio());
|
||||
if(textBox->Message1)
|
||||
ImGui::TextWrapped("%s", textBox->Message1->Text);
|
||||
if (textBox)
|
||||
{
|
||||
textBox->DrawImGui();
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void gdrv::ApplyPalette(gdrv_bitmap8& bmp)
|
||||
|
|
|
@ -82,7 +82,7 @@ public:
|
|||
static void copy_bitmap_w_transparency(gdrv_bitmap8* dstBmp, int width, int height, int xOff, int yOff,
|
||||
gdrv_bitmap8* srcBmp, int srcXOff, int srcYOff);
|
||||
static void ScrollBitmapHorizontal(gdrv_bitmap8* bmp, int xStart);
|
||||
static void grtext_draw_ttext_in_box(TTextBox* textBox);
|
||||
static void grtext_draw_ttext_in_box();
|
||||
static void ApplyPalette(gdrv_bitmap8& bmp);
|
||||
static void CreatePreview(gdrv_bitmap8& bmp);
|
||||
|
||||
|
|
|
@ -714,13 +714,7 @@ void winmain::RenderUi()
|
|||
RenderFrameTimeDialog();
|
||||
|
||||
// Print game texts on the sidebar
|
||||
for(auto textToDraw : {pinball::InfoTextBox, pinball::MissTextBox})
|
||||
{
|
||||
if(textToDraw)
|
||||
{
|
||||
gdrv::grtext_draw_ttext_in_box(textToDraw);
|
||||
}
|
||||
}
|
||||
gdrv::grtext_draw_ttext_in_box();
|
||||
}
|
||||
|
||||
int winmain::event_handler(const SDL_Event* event)
|
||||
|
|
Loading…
Reference in New Issue