Allow using z-index in UiCanvas, and use it for tooltips.
Before this commit, tooltips in the text window are drawn under the red "X" indicating a disabled button. After this commit, they are moved on top of that. This commit also alters the OpenGL renderers' SetCamera() method to clear the depth buffer, as that would interfere with drawing the UI; the toolbar would get occluded by geometry.single-window
parent
92773a5770
commit
156fe73bee
|
@ -227,12 +227,13 @@ const Camera &BatchCanvas::GetCamera() const {
|
||||||
// A wrapper around Canvas that simplifies drawing UI in screen coordinates
|
// 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 },
|
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 };
|
vb = { (double)x2 + 0.5, (double)Flip(y2) + 0.5, 0.0 };
|
||||||
|
|
||||||
Canvas::Stroke stroke = {};
|
Canvas::Stroke stroke = {};
|
||||||
stroke.layer = Canvas::Layer::FRONT;
|
stroke.layer = Canvas::Layer::NORMAL;
|
||||||
|
stroke.zIndex = zIndex;
|
||||||
stroke.width = (double)width;
|
stroke.width = (double)width;
|
||||||
stroke.color = color;
|
stroke.color = color;
|
||||||
stroke.unit = Canvas::Unit::PX;
|
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);
|
canvas->DrawLine(va, vb, hcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UiCanvas::DrawRect(int l, int r, int t, int b,
|
void UiCanvas::DrawRect(int l, int r, int t, int b, RgbaColor fillColor, RgbaColor outlineColor,
|
||||||
RgbaColor fillColor, RgbaColor outlineColor) {
|
int zIndex) {
|
||||||
Vector va = { (double)l + 0.5, (double)Flip(b) + 0.5, 0.0 },
|
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 },
|
vb = { (double)l + 0.5, (double)Flip(t) + 0.5, 0.0 },
|
||||||
vc = { (double)r + 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()) {
|
if(!fillColor.IsEmpty()) {
|
||||||
Canvas::Fill fill = {};
|
Canvas::Fill fill = {};
|
||||||
fill.layer = Canvas::Layer::FRONT;
|
fill.layer = Canvas::Layer::NORMAL;
|
||||||
|
fill.zIndex = zIndex;
|
||||||
fill.color = fillColor;
|
fill.color = fillColor;
|
||||||
Canvas::hFill hcf = canvas->GetFill(fill);
|
Canvas::hFill hcf = canvas->GetFill(fill);
|
||||||
|
|
||||||
|
@ -259,7 +261,8 @@ void UiCanvas::DrawRect(int l, int r, int t, int b,
|
||||||
|
|
||||||
if(!outlineColor.IsEmpty()) {
|
if(!outlineColor.IsEmpty()) {
|
||||||
Canvas::Stroke stroke = {};
|
Canvas::Stroke stroke = {};
|
||||||
stroke.layer = Canvas::Layer::FRONT;
|
stroke.layer = Canvas::Layer::NORMAL;
|
||||||
|
stroke.zIndex = zIndex;
|
||||||
stroke.width = 1.0;
|
stroke.width = 1.0;
|
||||||
stroke.color = outlineColor;
|
stroke.color = outlineColor;
|
||||||
stroke.unit = Canvas::Unit::PX;
|
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<const Pixmap> pm, int x, int y) {
|
void UiCanvas::DrawPixmap(std::shared_ptr<const Pixmap> pm, int x, int y, int zIndex) {
|
||||||
Canvas::Fill fill = {};
|
Canvas::Fill fill = {};
|
||||||
fill.layer = Canvas::Layer::FRONT;
|
fill.layer = Canvas::Layer::NORMAL;
|
||||||
|
fill.zIndex = zIndex;
|
||||||
fill.color = { 255, 255, 255, 255 };
|
fill.color = { 255, 255, 255, 255 };
|
||||||
Canvas::hFill hcf = canvas->GetFill(fill);
|
Canvas::hFill hcf = canvas->GetFill(fill);
|
||||||
|
|
||||||
|
@ -287,11 +291,12 @@ void UiCanvas::DrawPixmap(std::shared_ptr<const Pixmap> pm, int x, int y) {
|
||||||
hcf);
|
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();
|
BitmapFont *font = BitmapFont::Builtin();
|
||||||
|
|
||||||
Canvas::Fill fill = {};
|
Canvas::Fill fill = {};
|
||||||
fill.layer = Canvas::Layer::FRONT;
|
fill.layer = Canvas::Layer::NORMAL;
|
||||||
|
fill.zIndex = zIndex;
|
||||||
fill.color = color;
|
fill.color = color;
|
||||||
Canvas::hFill hcf = canvas->GetFill(fill);
|
Canvas::hFill hcf = canvas->GetFill(fill);
|
||||||
|
|
||||||
|
@ -318,11 +323,11 @@ void UiCanvas::DrawBitmapChar(char32_t codepoint, int x, int y, RgbaColor color)
|
||||||
hcf);
|
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();
|
BitmapFont *font = BitmapFont::Builtin();
|
||||||
|
|
||||||
for(char32_t codepoint : ReadUTF8(str)) {
|
for(char32_t codepoint : ReadUTF8(str)) {
|
||||||
DrawBitmapChar(codepoint, x, y, color);
|
DrawBitmapChar(codepoint, x, y, color, zIndex);
|
||||||
x += font->GetWidth(codepoint) * 8;
|
x += font->GetWidth(codepoint) * 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,11 +197,16 @@ public:
|
||||||
std::shared_ptr<Canvas> canvas;
|
std::shared_ptr<Canvas> canvas;
|
||||||
bool flip;
|
bool flip;
|
||||||
|
|
||||||
void DrawLine(int x1, int y1, int x2, int y2, RgbaColor color, int width = 1);
|
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);
|
int zIndex = 0);
|
||||||
void DrawPixmap(std::shared_ptr<const Pixmap> pm, int x, int y);
|
void DrawRect(int l, int r, int t, int b, RgbaColor fillColor, RgbaColor outlineColor,
|
||||||
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);
|
void DrawPixmap(std::shared_ptr<const Pixmap> 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; }
|
int Flip(int y) const { return flip ? (int)canvas->GetCamera().height - y : y; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -733,6 +733,9 @@ void OpenGl1Renderer::UpdateProjection(bool flip) {
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
|
glClearDepth(1.0);
|
||||||
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGl1Renderer::BeginFrame() {
|
void OpenGl1Renderer::BeginFrame() {
|
||||||
|
|
|
@ -606,6 +606,9 @@ void OpenGl2Renderer::UpdateProjection(bool flip) {
|
||||||
edgeRenderer.SetModelview(modelview);
|
edgeRenderer.SetModelview(modelview);
|
||||||
outlineRenderer.SetProjection(projection);
|
outlineRenderer.SetProjection(projection);
|
||||||
outlineRenderer.SetModelview(modelview);
|
outlineRenderer.SetModelview(modelview);
|
||||||
|
|
||||||
|
glClearDepth(1.0);
|
||||||
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGl2Renderer::BeginFrame() {
|
void OpenGl2Renderer::BeginFrame() {
|
||||||
|
|
|
@ -578,8 +578,10 @@ void TextWindow::DrawOrHitTestIcons(UiCanvas *uiCanvas, TextWindow::DrawOrHitHow
|
||||||
|
|
||||||
uiCanvas->DrawRect(ox, ox+tw, oy, oy+LINE_HEIGHT,
|
uiCanvas->DrawRect(ox, ox+tw, oy, oy+LINE_HEIGHT,
|
||||||
/*fillColor=*/{ 255, 255, 150, 255 },
|
/*fillColor=*/{ 255, 255, 150, 255 },
|
||||||
/*outlineColor=*/{ 0, 0, 0, 255 });
|
/*outlineColor=*/{ 0, 0, 0, 255 },
|
||||||
uiCanvas->DrawBitmapText(tooltip, ox+5, oy-3+LINE_HEIGHT, { 0, 0, 0, 255 });
|
/*zIndex=*/1);
|
||||||
|
uiCanvas->DrawBitmapText(tooltip, ox+5, oy-3+LINE_HEIGHT, { 0, 0, 0, 255 },
|
||||||
|
/*zIndex=*/1);
|
||||||
} else {
|
} else {
|
||||||
if(!hoveredButton || (hoveredButton != tooltippedButton)) {
|
if(!hoveredButton || (hoveredButton != tooltippedButton)) {
|
||||||
tooltippedButton = NULL;
|
tooltippedButton = NULL;
|
||||||
|
|
Loading…
Reference in New Issue