Removed code duplication by merging drawRect() and drawRoundedRect().

This commit is contained in:
Dario Manesku 2014-12-03 04:33:34 +01:00
parent 53be0d1bdf
commit f448f18ae4

View file

@ -969,17 +969,6 @@ struct Imgui
} }
// BG // BG
if (0 == _r)
{
drawRect( (float)xx
, (float)yy
, (float)width
, (float)height
, imguiRGBA(0, 0, 0, 196)
);
}
else
{
drawRoundedRect( (float)xx drawRoundedRect( (float)xx
, (float)yy , (float)yy
, (float)width , (float)width
@ -987,21 +976,9 @@ struct Imgui
, (float)_r , (float)_r
, imguiRGBA(0, 0, 0, 196) , imguiRGBA(0, 0, 0, 196)
); );
}
// Bar // Bar
if (isActive(hid) ) if (isActive(hid) )
{
if (0 == _r)
{
drawRect( (float)hx
, (float)hy
, (float)hw
, (float)hh
, imguiRGBA(255, 196, 0, 196)
);
}
else
{ {
drawRoundedRect( (float)hx drawRoundedRect( (float)hx
, (float)hy , (float)hy
@ -1011,18 +988,6 @@ struct Imgui
, imguiRGBA(255, 196, 0, 196) , imguiRGBA(255, 196, 0, 196)
); );
} }
}
else
{
if (0 == _r)
{
drawRect( (float)hx
, (float)hy
, (float)hw
, (float)hh
, isHot(hid) ? imguiRGBA(255, 196, 0, 96) : imguiRGBA(255, 255, 255, 64)
);
}
else else
{ {
drawRoundedRect( (float)hx drawRoundedRect( (float)hx
@ -1034,7 +999,6 @@ struct Imgui
); );
} }
} }
}
else else
{ {
// Clear active if scroll is selected but not visible any more. // Clear active if scroll is selected but not visible any more.
@ -1174,17 +1138,6 @@ struct Imgui
const uint32_t rgb0 = _rgb0&0x00ffffff; const uint32_t rgb0 = _rgb0&0x00ffffff;
if (0 == _r)
{
drawRect( (float)xx
, (float)yy
, (float)width
, (float)height
, rgb0 | imguiRGBA(0, 0, 0, isActive(id) ? 196 : 96)
);
}
else
{
drawRoundedRect( (float)xx drawRoundedRect( (float)xx
, (float)yy , (float)yy
, (float)width , (float)width
@ -1192,7 +1145,6 @@ struct Imgui
, (float)_r , (float)_r
, rgb0 | imguiRGBA(0, 0, 0, isActive(id) ? 196 : 96) , rgb0 | imguiRGBA(0, 0, 0, isActive(id) ? 196 : 96)
); );
}
if (enabled) if (enabled)
{ {
@ -1409,17 +1361,6 @@ struct Imgui
const bool over = enabled && inRect(xx, yy, width, height); const bool over = enabled && inRect(xx, yy, width, height);
inputLogic(id, over); inputLogic(id, over);
if (0 == _r)
{
drawRect( (float)xx
, (float)yy
, (float)width
, (float)height
, isActiveInputField(id)?imguiRGBA(255,196,0,255):imguiRGBA(128,128,128,96)
);
}
else
{
drawRoundedRect( (float)xx drawRoundedRect( (float)xx
, (float)yy , (float)yy
, (float)width , (float)width
@ -1427,7 +1368,6 @@ struct Imgui
, (float)_r , (float)_r
, isActiveInputField(id)?imguiRGBA(255,196,0,255):imguiRGBA(128,128,128,96) , isActiveInputField(id)?imguiRGBA(255,196,0,255):imguiRGBA(128,128,128,96)
); );
}
if (isActiveInputField(id) ) if (isActiveInputField(id) )
{ {
@ -1519,17 +1459,6 @@ struct Imgui
const int32_t tabWidthHalf = width / (tabCount*2); const int32_t tabWidthHalf = width / (tabCount*2);
const int32_t textY = yy + _height/2 + int32_t(m_fonts[m_currentFontIdx].m_size)/2 - 2; const int32_t textY = yy + _height/2 + int32_t(m_fonts[m_currentFontIdx].m_size)/2 - 2;
if (0 == _r)
{
drawRect( (float)xx
, (float)yy
, (float)width
, (float)_height
, _enabled?imguiRGBA(128,128,128,96):imguiRGBA(128,128,128,64)
);
}
else
{
drawRoundedRect( (float)xx drawRoundedRect( (float)xx
, (float)yy , (float)yy
, (float)width , (float)width
@ -1537,7 +1466,6 @@ struct Imgui
, (float)_r , (float)_r
, _enabled?imguiRGBA(128,128,128,96):imguiRGBA(128,128,128,64) , _enabled?imguiRGBA(128,128,128,96):imguiRGBA(128,128,128,64)
); );
}
for (uint8_t ii = 0; ii < tabCount; ++ii) for (uint8_t ii = 0; ii < tabCount; ++ii)
{ {
@ -1560,17 +1488,6 @@ struct Imgui
{ {
textColor = enabled?imguiRGBA(0,0,0,255):imguiRGBA(255,255,255,100); textColor = enabled?imguiRGBA(0,0,0,255):imguiRGBA(255,255,255,100);
if (0 == _r)
{
drawRect( (float)buttonX
, (float)yy
, (float)tabWidth
, (float)_height
, enabled?imguiRGBA(255,196,0,200):imguiRGBA(128,128,128,32)
);
}
else
{
drawRoundedRect( (float)buttonX drawRoundedRect( (float)buttonX
, (float)yy , (float)yy
, (float)tabWidth , (float)tabWidth
@ -1579,7 +1496,6 @@ struct Imgui
, enabled?imguiRGBA(255,196,0,200):imguiRGBA(128,128,128,32) , enabled?imguiRGBA(255,196,0,200):imguiRGBA(128,128,128,32)
); );
} }
}
else else
{ {
textColor = isHot(id) ? imguiRGBA(255, 196, 0, enabled?255:100) : imguiRGBA(255, 255, 255, enabled?200:100); textColor = isHot(id) ? imguiRGBA(255, 196, 0, enabled?255:100) : imguiRGBA(255, 255, 255, enabled?200:100);
@ -1984,11 +1900,10 @@ struct Imgui
const bool over = _enabled && inRect(xx, yy, width, height, false); const bool over = _enabled && inRect(xx, yy, width, height, false);
const bool res = buttonLogic(id, over); const bool res = buttonLogic(id, over);
drawRoundedRect( (float)xx drawRect( (float)xx
, (float)yy , (float)yy
, (float)width , (float)width
, (float)height , (float)height
, 0.0f
, isActive(id) ? imguiRGBA(23, 23, 23, 192) : imguiRGBA(0, 0, 0, 222) , isActive(id) ? imguiRGBA(23, 23, 23, 192) : imguiRGBA(0, 0, 0, 222)
); );
@ -2322,21 +2237,26 @@ struct Imgui
} }
} }
void drawRect(float _x, float _y, float w, float h, uint32_t _argb, float _fth = 1.0f) void drawRect(float _x, float _y, float _w, float _h, uint32_t _argb, float _fth = 1.0f)
{ {
float verts[4 * 2] = float verts[4 * 2] =
{ {
_x + 0.5f, _y + 0.5f, _x + 0.5f, _y + 0.5f,
_x + w - 0.5f, _y + 0.5f, _x + _w - 0.5f, _y + 0.5f,
_x + w - 0.5f, _y + h - 0.5f, _x + _w - 0.5f, _y + _h - 0.5f,
_x + 0.5f, _y + h - 0.5f, _x + 0.5f, _y + _h - 0.5f,
}; };
drawPolygon(verts, 4, _fth, _argb); drawPolygon(verts, 4, _fth, _argb);
} }
void drawRoundedRect(float _x, float _y, float w, float h, float r, uint32_t _argb, float _fth = 1.0f) void drawRoundedRect(float _x, float _y, float _w, float _h, float _r, uint32_t _argb, float _fth = 1.0f)
{ {
if (0.0f == _r)
{
return drawRect(_x, _y, _w, _h, _argb, _fth);
}
const uint32_t num = NUM_CIRCLE_VERTS / 4; const uint32_t num = NUM_CIRCLE_VERTS / 4;
const float* cverts = m_circleVerts; const float* cverts = m_circleVerts;
float verts[(num + 1) * 4 * 2]; float verts[(num + 1) * 4 * 2];
@ -2344,30 +2264,30 @@ struct Imgui
for (uint32_t ii = 0; ii <= num; ++ii) for (uint32_t ii = 0; ii <= num; ++ii)
{ {
*vv++ = _x + w - r + cverts[ii * 2] * r; *vv++ = _x + _w - _r + cverts[ii * 2] * _r;
*vv++ = _y + h - r + cverts[ii * 2 + 1] * r; *vv++ = _y + _h - _r + cverts[ii * 2 + 1] * _r;
} }
for (uint32_t ii = num; ii <= num * 2; ++ii) for (uint32_t ii = num; ii <= num * 2; ++ii)
{ {
*vv++ = _x + r + cverts[ii * 2] * r; *vv++ = _x + _r + cverts[ii * 2] * _r;
*vv++ = _y + h - r + cverts[ii * 2 + 1] * r; *vv++ = _y + _h - _r + cverts[ii * 2 + 1] * _r;
} }
for (uint32_t ii = num * 2; ii <= num * 3; ++ii) for (uint32_t ii = num * 2; ii <= num * 3; ++ii)
{ {
*vv++ = _x + r + cverts[ii * 2] * r; *vv++ = _x + _r + cverts[ii * 2] * _r;
*vv++ = _y + r + cverts[ii * 2 + 1] * r; *vv++ = _y + _r + cverts[ii * 2 + 1] * _r;
} }
for (uint32_t ii = num * 3; ii < num * 4; ++ii) for (uint32_t ii = num * 3; ii < num * 4; ++ii)
{ {
*vv++ = _x + w - r + cverts[ii * 2] * r; *vv++ = _x + _w - _r + cverts[ii * 2] * _r;
*vv++ = _y + r + cverts[ii * 2 + 1] * r; *vv++ = _y + _r + cverts[ii * 2 + 1] * _r;
} }
*vv++ = _x + w - r + cverts[0] * r; *vv++ = _x + _w - _r + cverts[0] * _r;
*vv++ = _y + r + cverts[1] * r; *vv++ = _y + _r + cverts[1] * _r;
drawPolygon(verts, (num + 1) * 4, _fth, _argb); drawPolygon(verts, (num + 1) * 4, _fth, _argb);
} }