extra draw gui

add the extra functions for drawing gui elements
RoundedRectangle:

All draw rect functions now pass through roundedRectangle which uses a shader and can draw borders, and rounds the corners

Draw thick line:
draws a line thicker than 1 pixel, uses a geometry shader to do this

Draw Circle:
Draws a circle with a border parameter.
This commit is contained in:
marauder2k7 2024-03-06 17:27:18 +00:00
parent 39c2cc09fc
commit c9d70de609
9 changed files with 654 additions and 170 deletions

View file

@ -134,45 +134,6 @@ void GuiShaderEditor::onPreRender()
setUpdate();
}
void GuiShaderEditor::drawThickLine(const Point2I& pt1, const Point2I& pt2, U32 thickness, ColorI col1, ColorI col2)
{
Point2F dir = Point2F(pt2.x - pt1.x, pt2.y - pt1.y);
if (dir == Point2F::Zero)
return;
Point2F unitDir = dir / mSqrt(dir.x * dir.x + dir.y * dir.y);
Point2F unitPerp(-unitDir.y, unitDir.x);
Point2F offset = (thickness / 2.0f) * unitPerp;
GFX->setStateBlock(mDefaultGuiSB);
Point2F lT = Point2F(pt1.x, pt1.y) + offset;
Point2F lB = Point2F(pt1.x, pt1.y) - offset;
Point2F rT = Point2F(pt2.x, pt2.y) + offset;
Point2F rB = Point2F(pt2.x, pt2.y) - offset;
PrimBuild::begin(GFXTriangleStrip, 4);
// top left.
PrimBuild::color(col1);
PrimBuild::vertex2f(lT.x, lT.y);
// bottom left.
PrimBuild::color(col1);
PrimBuild::vertex2f(lB.x, lB.y);
// top right.
PrimBuild::color(col2);
PrimBuild::vertex2f(rT.x, rT.y);
// bottom right.
PrimBuild::color(col2);
PrimBuild::vertex2f(rB.x, rB.y);
PrimBuild::end();
}
void GuiShaderEditor::renderNodes(Point2I offset, const RectI& updateRect)
{
// Save the current clip rect
@ -224,17 +185,14 @@ void GuiShaderEditor::renderNodes(Point2I offset, const RectI& updateRect)
if (node->mSelected)
border = mProfile->mBorderColorSEL;
RectI socketRect(pos, Point2I(mNodeSize, mNodeSize));
drawer->drawRect(socketRect, border);
socketRect.inset(1, 1);
ColorI fill = mProfile->mFillColor;
if (hasConnection(input))
{
fill = ColorI::WHITE;
}
drawer->drawRectFill(socketRect, fill);
RectI socketRect(pos, Point2I(mNodeSize, mNodeSize));
drawer->drawCircleFill(socketRect, fill, mNodeSize / 2, 2.0f, border);
}
for (NodeOutput* output : node->mOutputNodes)
@ -246,9 +204,8 @@ void GuiShaderEditor::renderNodes(Point2I offset, const RectI& updateRect)
if (node->mSelected)
border = mProfile->mBorderColorSEL;
RectI socketRect(pos, Point2I(mNodeSize, mNodeSize));
drawer->drawRect(socketRect, border);
socketRect.inset(1, 1);
if(node->mSelected)
border = mProfile->mBorderColorSEL;
ColorI fill = mProfile->mFillColor;
if (hasConnection(output))
@ -256,7 +213,8 @@ void GuiShaderEditor::renderNodes(Point2I offset, const RectI& updateRect)
fill = ColorI::WHITE;
}
drawer->drawRectFill(socketRect, fill);
RectI socketRect(pos, Point2I(mNodeSize, mNodeSize));
drawer->drawCircleFill(socketRect, fill, mNodeSize / 2, 2.0f, border);
}
}
}
@ -292,7 +250,7 @@ void GuiShaderEditor::renderConnections(Point2I offset, const RectI& updateRect)
start += Point2I(mNodeSize / 2, mNodeSize / 2);
end += Point2I(mNodeSize / 2, mNodeSize / 2);
drawThickLine(start, end, mNodeSize/3);
drawer->drawThickLine(start, end,ColorI(255,255,255,255), (F32)mNodeSize/3);
}
// Restore the clip rect to what it was at the start
@ -328,11 +286,12 @@ void GuiShaderEditor::onRender(Point2I offset, const RectI& updateRect)
RectI sockActive(start, Point2I(mNodeSize, mNodeSize));
start += Point2I(mNodeSize / 2, mNodeSize / 2);
drawThickLine(start, mLastMousePos + offset, mNodeSize/3);
drawer->drawThickLine(start, mLastMousePos + offset, ColorI(255, 255, 255, 255), (F32)mNodeSize / 3);
// draw socket overlay over the top of the line.
sockActive.inset(1, 1);
drawer->drawRectFill(sockActive, ColorI(255, 255, 255));
drawer->drawCircleFill(sockActive, ColorI(255, 255, 255), mNodeSize / 2);
}
}
// Draw selection rectangle last so it is rendered on top.

View file

@ -108,7 +108,13 @@ void GuiShaderNode::renderNode(Point2I offset, const RectI& updateRect, const S3
RectI winRect;
winRect.point = offset;
winRect.extent = getExtent();
drawer->drawRectFill(winRect, mProfile->mFillColor);
ColorI border = mProfile->mBorderColor;
if (mSelected)
border = mProfile->mBorderColorSEL;
drawer->drawRoundedRect(15.0f, winRect, mProfile->mFillColor, 3.0f, border);
// draw header
ColorI header(50, 50, 50, 128);
@ -148,7 +154,7 @@ void GuiShaderNode::renderNode(Point2I offset, const RectI& updateRect, const S3
U32 headerSize = 30;
headRect.point = offset;
headRect.extent = Point2I(getExtent().x, headerSize);
drawer->drawRectFill(headRect, header);
drawer->drawRoundedRect(15.0f, headRect, header);
// draw header text.
U32 strWidth = mProfile->mFont->getStrWidth(mTitle.c_str());
@ -157,14 +163,6 @@ void GuiShaderNode::renderNode(Point2I offset, const RectI& updateRect, const S3
drawer->drawText(mProfile->mFont, headerPos + offset, mTitle);
drawer->clearBitmapModulation();
ColorI border = mProfile->mBorderColor;
if (mSelected)
border = mProfile->mBorderColorSEL;
drawer->drawRect(winRect, border);
if (mInputNodes.size() > 0 || mOutputNodes.size() > 0)
{
U32 textPadX = nodeSize, textPadY = mProfile->mFont->getFontSize() + (nodeSize / 2);
@ -175,7 +173,7 @@ void GuiShaderNode::renderNode(Point2I offset, const RectI& updateRect, const S3
drawer->drawText(mProfile->mFont, slotPos + offset, input->name);
if (input->pos == Point2I::Zero || mPrevNodeSize != nodeSize)
input->pos = Point2I(-(nodeSize / 2), slotPos.y + ((mProfile->mFont->getFontSize() / 2) - (nodeSize / 2)));
input->pos = Point2I(-(nodeSize / 2) + 1, slotPos.y + ((mProfile->mFont->getFontSize() / 2) - (nodeSize / 2)));
slotPos.y += textPadY;
}