diff --git a/src/render/render.cpp b/src/render/render.cpp index 6382fc2..3beb83d 100644 --- a/src/render/render.cpp +++ b/src/render/render.cpp @@ -227,12 +227,13 @@ const Camera &BatchCanvas::GetCamera() const { // A wrapper around Canvas that simplifies drawing UI in screen coordinates //----------------------------------------------------------------------------- -void UiCanvas::DrawLine(int x1, int y1, int x2, int y2, RgbaColor color, int width) { +void UiCanvas::DrawLine(int x1, int y1, int x2, int y2, RgbaColor color, int width, int zIndex) { Vector va = { (double)x1 + 0.5, (double)Flip(y1) + 0.5, 0.0 }, vb = { (double)x2 + 0.5, (double)Flip(y2) + 0.5, 0.0 }; Canvas::Stroke stroke = {}; - stroke.layer = Canvas::Layer::FRONT; + stroke.layer = Canvas::Layer::NORMAL; + stroke.zIndex = zIndex; stroke.width = (double)width; stroke.color = color; stroke.unit = Canvas::Unit::PX; @@ -241,8 +242,8 @@ void UiCanvas::DrawLine(int x1, int y1, int x2, int y2, RgbaColor color, int wid canvas->DrawLine(va, vb, hcs); } -void UiCanvas::DrawRect(int l, int r, int t, int b, - RgbaColor fillColor, RgbaColor outlineColor) { +void UiCanvas::DrawRect(int l, int r, int t, int b, RgbaColor fillColor, RgbaColor outlineColor, + int zIndex) { Vector va = { (double)l + 0.5, (double)Flip(b) + 0.5, 0.0 }, vb = { (double)l + 0.5, (double)Flip(t) + 0.5, 0.0 }, vc = { (double)r + 0.5, (double)Flip(t) + 0.5, 0.0 }, @@ -250,7 +251,8 @@ void UiCanvas::DrawRect(int l, int r, int t, int b, if(!fillColor.IsEmpty()) { Canvas::Fill fill = {}; - fill.layer = Canvas::Layer::FRONT; + fill.layer = Canvas::Layer::NORMAL; + fill.zIndex = zIndex; fill.color = fillColor; Canvas::hFill hcf = canvas->GetFill(fill); @@ -259,7 +261,8 @@ void UiCanvas::DrawRect(int l, int r, int t, int b, if(!outlineColor.IsEmpty()) { Canvas::Stroke stroke = {}; - stroke.layer = Canvas::Layer::FRONT; + stroke.layer = Canvas::Layer::NORMAL; + stroke.zIndex = zIndex; stroke.width = 1.0; stroke.color = outlineColor; stroke.unit = Canvas::Unit::PX; @@ -272,9 +275,10 @@ void UiCanvas::DrawRect(int l, int r, int t, int b, } } -void UiCanvas::DrawPixmap(std::shared_ptr pm, int x, int y) { +void UiCanvas::DrawPixmap(std::shared_ptr pm, int x, int y, int zIndex) { Canvas::Fill fill = {}; - fill.layer = Canvas::Layer::FRONT; + fill.layer = Canvas::Layer::NORMAL; + fill.zIndex = zIndex; fill.color = { 255, 255, 255, 255 }; Canvas::hFill hcf = canvas->GetFill(fill); @@ -287,11 +291,12 @@ void UiCanvas::DrawPixmap(std::shared_ptr pm, int x, int y) { hcf); } -void UiCanvas::DrawBitmapChar(char32_t codepoint, int x, int y, RgbaColor color) { +void UiCanvas::DrawBitmapChar(char32_t codepoint, int x, int y, RgbaColor color, int zIndex) { BitmapFont *font = BitmapFont::Builtin(); Canvas::Fill fill = {}; - fill.layer = Canvas::Layer::FRONT; + fill.layer = Canvas::Layer::NORMAL; + fill.zIndex = zIndex; fill.color = color; Canvas::hFill hcf = canvas->GetFill(fill); @@ -318,11 +323,11 @@ void UiCanvas::DrawBitmapChar(char32_t codepoint, int x, int y, RgbaColor color) hcf); } -void UiCanvas::DrawBitmapText(const std::string &str, int x, int y, RgbaColor color) { +void UiCanvas::DrawBitmapText(const std::string &str, int x, int y, RgbaColor color, int zIndex) { BitmapFont *font = BitmapFont::Builtin(); for(char32_t codepoint : ReadUTF8(str)) { - DrawBitmapChar(codepoint, x, y, color); + DrawBitmapChar(codepoint, x, y, color, zIndex); x += font->GetWidth(codepoint) * 8; } } diff --git a/src/render/render.h b/src/render/render.h index e7c9400..0b6cfcd 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -197,11 +197,16 @@ public: std::shared_ptr canvas; bool flip; - void DrawLine(int x1, int y1, int x2, int y2, RgbaColor color, int width = 1); - void DrawRect(int l, int r, int t, int b, RgbaColor fillColor, RgbaColor outlineColor); - void DrawPixmap(std::shared_ptr pm, int x, int y); - void DrawBitmapChar(char32_t codepoint, int x, int y, RgbaColor color); - void DrawBitmapText(const std::string &str, int x, int y, RgbaColor color); + void DrawLine(int x1, int y1, int x2, int y2, RgbaColor color, int width = 1, + int zIndex = 0); + void DrawRect(int l, int r, int t, int b, RgbaColor fillColor, RgbaColor outlineColor, + int zIndex = 0); + void DrawPixmap(std::shared_ptr pm, int x, int y, + int zIndex = 0); + void DrawBitmapChar(char32_t codepoint, int x, int y, RgbaColor color, + int zIndex = 0); + void DrawBitmapText(const std::string &str, int x, int y, RgbaColor color, + int zIndex = 0); int Flip(int y) const { return flip ? (int)canvas->GetCamera().height - y : y; } }; diff --git a/src/render/rendergl1.cpp b/src/render/rendergl1.cpp index a868c32..e3f8c5d 100644 --- a/src/render/rendergl1.cpp +++ b/src/render/rendergl1.cpp @@ -733,6 +733,9 @@ void OpenGl1Renderer::UpdateProjection(bool flip) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + + glClearDepth(1.0); + glClear(GL_DEPTH_BUFFER_BIT); } void OpenGl1Renderer::BeginFrame() { diff --git a/src/render/rendergl2.cpp b/src/render/rendergl2.cpp index 343dfa5..e4b81da 100644 --- a/src/render/rendergl2.cpp +++ b/src/render/rendergl2.cpp @@ -606,6 +606,9 @@ void OpenGl2Renderer::UpdateProjection(bool flip) { edgeRenderer.SetModelview(modelview); outlineRenderer.SetProjection(projection); outlineRenderer.SetModelview(modelview); + + glClearDepth(1.0); + glClear(GL_DEPTH_BUFFER_BIT); } void OpenGl2Renderer::BeginFrame() { diff --git a/src/textwin.cpp b/src/textwin.cpp index a86a617..77322f0 100644 --- a/src/textwin.cpp +++ b/src/textwin.cpp @@ -578,8 +578,10 @@ void TextWindow::DrawOrHitTestIcons(UiCanvas *uiCanvas, TextWindow::DrawOrHitHow uiCanvas->DrawRect(ox, ox+tw, oy, oy+LINE_HEIGHT, /*fillColor=*/{ 255, 255, 150, 255 }, - /*outlineColor=*/{ 0, 0, 0, 255 }); - uiCanvas->DrawBitmapText(tooltip, ox+5, oy-3+LINE_HEIGHT, { 0, 0, 0, 255 }); + /*outlineColor=*/{ 0, 0, 0, 255 }, + /*zIndex=*/1); + uiCanvas->DrawBitmapText(tooltip, ox+5, oy-3+LINE_HEIGHT, { 0, 0, 0, 255 }, + /*zIndex=*/1); } else { if(!hoveredButton || (hoveredButton != tooltippedButton)) { tooltippedButton = NULL;