Skip to content

Commit f9603f2

Browse files
committed
UI: use imgui for rendering the ui
1 parent c08037d commit f9603f2

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/modules/ui/UI.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,21 @@ void UI::renderImage (Texture* texture, int x, int y, int w, int h, int16_t angl
329329
{
330330
if (!texture || !texture->isValid())
331331
return;
332-
_frontend->setColor(color);
333-
_frontend->renderImage(texture, x, y, w, h, angle, color[3]);
334-
_frontend->resetColor();
332+
333+
if (w == -1)
334+
w = texture->getWidth();
335+
if (h == -1)
336+
h = texture->getHeight();
337+
338+
_frontend->getTrimmed(texture, x, y, w, h);
339+
340+
const TextureRect& r = texture->getSourceRect();
341+
const SDL_Rect srcRect { r.x, r.y, r.w, r.h };
342+
const ImColor imcolor(color[0], color[1], color[2], color[3]);
343+
const ImVec2 uvmin(srcRect.x / (float)texture->getFullWidth(), srcRect.y / (float)texture->getFullHeight());
344+
const ImVec2 uvmax((srcRect.x + srcRect.w) / (float)texture->getFullWidth(), (srcRect.y + srcRect.h) / (float)texture->getFullHeight());
345+
const ImTextureID texId = (ImTextureID)_frontend->getTextureData(texture);
346+
ImGui::GetWindowDrawList()->AddImage(texId, ImVec2(x, y), ImVec2(x + w, y + h), uvmin, uvmax, imcolor);
335347
}
336348

337349
void UI::update (uint32_t deltaTime)

src/modules/ui/nodes/IUINodeMap.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ void IUINodeMap::onWindowResize ()
166166

167167
void IUINodeMap::render (int x, int y) const
168168
{
169-
renderFilledRect(getRenderX(), getRenderY(), getRenderWidth(), getRenderHeight(), colorBlack);
170-
if (_map.isActive())
169+
// renderFilledRect(getRenderX(), getRenderY(), getRenderWidth(), getRenderHeight(), colorBlack);
170+
if (_map.isActive()) {
171171
_map.render();
172+
}
172173
UINode::render(0, 0);
173174

174175
if (_map.isStarted())

src/modules/ui/nodes/UINode.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,22 +394,22 @@ bool UINode::renderDebug (int x, int y, int textY, bool& focusHandled) const
394394
void UINode::renderRect (int x, int y, int w, int h, const Color& color) const
395395
{
396396
const float alpha = fequals(_alpha, 1.0f) ? color[3] : _alpha;
397-
const Color alphaColor = { color[0], color[1], color[2], alpha };
398-
_frontend->renderRect(x, y, w, h, alphaColor);
397+
const ImVec4 alphaColor = { color[0], color[1], color[2], alpha };
398+
ImGui::GetWindowDrawList()->AddRect(ImVec2(x, y), ImVec2(x + w, y + h), ImColor(alphaColor));
399399
}
400400

401401
void UINode::renderFilledRect (int x, int y, int w, int h, const Color& color) const
402402
{
403403
const float alpha = fequals(_alpha, 1.0f) ? color[3] : _alpha;
404-
const Color alphaColor = { color[0], color[1], color[2], alpha };
405-
_frontend->renderFilledRect(x, y, w, h, alphaColor);
404+
const ImVec4 alphaColor = { color[0], color[1], color[2], alpha };
405+
ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(x, y), ImVec2(x + w, y + h), ImColor(alphaColor));
406406
}
407407

408408
void UINode::renderLine (int x1, int y1, int x2, int y2, const Color& color) const
409409
{
410410
const float alpha = fequals(_alpha, 1.0f) ? color[3] : _alpha;
411-
const Color alphaColor = { color[0], color[1], color[2], alpha };
412-
_frontend->renderLine(x1, y1, x2, y2, alphaColor);
411+
const ImVec4 alphaColor = { color[0], color[1], color[2], alpha };
412+
ImGui::GetWindowDrawList()->AddLine(ImVec2(x1, y1), ImVec2(x2, y2), ImColor(alphaColor));
413413
}
414414

415415
void UINode::renderImage (const TexturePtr& texture, int x, int y, int w, int h, float alpha) const

0 commit comments

Comments
 (0)