MCPcopy Create free account
hub / github.com/REGoth-project/REGoth / update

Method update

src/ui/SubtitleBox.cpp:29–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29void UI::SubtitleBox::update(double dt, Engine::Input::MouseState& mstate, Render::RenderConfig& config)
30{
31 if (m_IsHidden)
32 return;
33
34 const UI::zFont* fnt = m_Engine.getFontCache().getFont(DEFAULT_FONT);
35
36 if (!fnt)
37 return;
38
39 View::update(dt, mstate, config);
40
41 // Draw our choices
42 /*const int height = config.state.viewHeight / 10;
43 const int halfwidth = config.state.viewHeight / 2;
44 imguiBeginScrollArea(m_Text.speaker.c_str(), (config.state.viewWidth / 2) - halfwidth, 10, halfwidth * 2, height,
45 &m_ScrollArea);
46
47 imguiLabel(m_Text.text.c_str());
48
49 imguiEndScrollArea();*/
50
51 m_Scaling += static_cast<float>(dt) / GROW_SHRINK_TIME * m_growDirection;
52 m_Scaling = Math::clamp(m_Scaling, 0.0f, 1.0f);
53
54 // Un-normalize transforms
55 Math::float2 absTranslation = getAbsoluteTranslation();
56
57 float pxMax = absTranslation.x * config.state.viewWidth;
58 float pyMax = (absTranslation.y + 0.02f) * config.state.viewHeight;
59
60 float sxMax = 0.5f * config.state.viewWidth;
61 int wrapAroundWidth = Math::iround(0.95f * sxMax);
62 std::vector<std::string> lines = fnt->layoutText(m_Text.text, wrapAroundWidth);
63 auto fontHeight = fnt->getFontHeight();
64 int linesOfText = static_cast<int>(lines.size()) + 1; // +1 for speaker
65 // render the Box as if there were at least 4 lines of text
66 // so that the size won't change as often, but is still adjusted for very long texts (mods?)
67 linesOfText = std::max(linesOfText, 4);
68 float syMax = fontHeight * (linesOfText + 2); // +2 for some extra space
69
70 Math::float2 maxSize = {sxMax, syMax};
71 Math::float2 posMax = {pxMax, pyMax};
72 Math::float2 center = posMax + maxSize / 2;
73 // Draw background image
74 {
75 Math::float2 pos = center - maxSize / 2 * m_Scaling;
76 Math::float2 size = maxSize * m_Scaling;
77
78 // Get background image
79 Textures::Texture& background = m_Engine.getEngineTextureAlloc().getTexture(m_BackgroundTexture);
80
81 bgfx::ProgramHandle program = config.programs.imageProgram;
82 drawTexture(BGFX_VIEW,
83 Math::iround(pos.x), Math::iround(pos.y),
84 Math::iround(size.x), Math::iround(size.y),
85 config.state.viewWidth, config.state.viewHeight, background.m_TextureHandle, program,
86 config.uniforms.diffuseTexture);

Callers

nothing calls this directly

Calls 8

clampFunction · 0.85
iroundFunction · 0.85
getFontMethod · 0.80
layoutTextMethod · 0.80
getFontHeightMethod · 0.80
insertMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected