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,70 +969,34 @@ struct Imgui
}
// BG
if (0 == _r)
{
drawRect( (float)xx
, (float)yy
, (float)width
, (float)height
, imguiRGBA(0, 0, 0, 196)
);
}
else
{
drawRoundedRect( (float)xx
, (float)yy
, (float)width
, (float)height
, (float)_r
, imguiRGBA(0, 0, 0, 196)
);
}
drawRoundedRect( (float)xx
, (float)yy
, (float)width
, (float)height
, (float)_r
, imguiRGBA(0, 0, 0, 196)
);
// Bar
if (isActive(hid) )
{
if (0 == _r)
{
drawRect( (float)hx
, (float)hy
, (float)hw
, (float)hh
, imguiRGBA(255, 196, 0, 196)
);
}
else
{
drawRoundedRect( (float)hx
, (float)hy
, (float)hw
, (float)hh
, (float)_r
, imguiRGBA(255, 196, 0, 196)
);
}
drawRoundedRect( (float)hx
, (float)hy
, (float)hw
, (float)hh
, (float)_r
, 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
{
drawRoundedRect( (float)hx
, (float)hy
, (float)hw
, (float)hh
, (float)_r
, isHot(hid) ? imguiRGBA(255, 196, 0, 96) : imguiRGBA(255, 255, 255, 64)
);
}
drawRoundedRect( (float)hx
, (float)hy
, (float)hw
, (float)hh
, (float)_r
, isHot(hid) ? imguiRGBA(255, 196, 0, 96) : imguiRGBA(255, 255, 255, 64)
);
}
}
else
@ -1174,25 +1138,13 @@ struct Imgui
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
, (float)yy
, (float)width
, (float)height
, (float)_r
, rgb0 | imguiRGBA(0, 0, 0, isActive(id) ? 196 : 96)
);
}
drawRoundedRect( (float)xx
, (float)yy
, (float)width
, (float)height
, (float)_r
, rgb0 | imguiRGBA(0, 0, 0, isActive(id) ? 196 : 96)
);
if (enabled)
{
@ -1409,25 +1361,13 @@ struct Imgui
const bool over = enabled && inRect(xx, yy, width, height);
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
, (float)yy
, (float)width
, (float)height
, (float)_r
, isActiveInputField(id)?imguiRGBA(255,196,0,255):imguiRGBA(128,128,128,96)
);
}
drawRoundedRect( (float)xx
, (float)yy
, (float)width
, (float)height
, (float)_r
, isActiveInputField(id)?imguiRGBA(255,196,0,255):imguiRGBA(128,128,128,96)
);
if (isActiveInputField(id) )
{
@ -1519,25 +1459,13 @@ struct Imgui
const int32_t tabWidthHalf = width / (tabCount*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
, (float)yy
, (float)width
, (float)_height
, (float)_r
, _enabled?imguiRGBA(128,128,128,96):imguiRGBA(128,128,128,64)
);
}
drawRoundedRect( (float)xx
, (float)yy
, (float)width
, (float)_height
, (float)_r
, _enabled?imguiRGBA(128,128,128,96):imguiRGBA(128,128,128,64)
);
for (uint8_t ii = 0; ii < tabCount; ++ii)
{
@ -1560,25 +1488,13 @@ struct Imgui
{
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
, (float)yy
, (float)tabWidth
, (float)_height
, (float)_r
, enabled?imguiRGBA(255,196,0,200):imguiRGBA(128,128,128,32)
);
}
drawRoundedRect( (float)buttonX
, (float)yy
, (float)tabWidth
, (float)_height
, (float)_r
, enabled?imguiRGBA(255,196,0,200):imguiRGBA(128,128,128,32)
);
}
else
{
@ -1984,13 +1900,12 @@ struct Imgui
const bool over = _enabled && inRect(xx, yy, width, height, false);
const bool res = buttonLogic(id, over);
drawRoundedRect( (float)xx
, (float)yy
, (float)width
, (float)height
, 0.0f
, isActive(id) ? imguiRGBA(23, 23, 23, 192) : imguiRGBA(0, 0, 0, 222)
);
drawRect( (float)xx
, (float)yy
, (float)width
, (float)height
, isActive(id) ? imguiRGBA(23, 23, 23, 192) : imguiRGBA(0, 0, 0, 222)
);
drawTriangle( triX
, triY
@ -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] =
{
_x + 0.5f, _y + 0.5f,
_x + w - 0.5f, _y + 0.5f,
_x + w - 0.5f, _y + h - 0.5f,
_x + 0.5f, _y + h - 0.5f,
_x + 0.5f, _y + 0.5f,
_x + _w - 0.5f, _y + 0.5f,
_x + _w - 0.5f, _y + _h - 0.5f,
_x + 0.5f, _y + _h - 0.5f,
};
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 float* cverts = m_circleVerts;
float verts[(num + 1) * 4 * 2];
@ -2344,30 +2264,30 @@ struct Imgui
for (uint32_t ii = 0; ii <= num; ++ii)
{
*vv++ = _x + w - r + cverts[ii * 2] * r;
*vv++ = _y + h - r + cverts[ii * 2 + 1] * r;
*vv++ = _x + _w - _r + cverts[ii * 2] * _r;
*vv++ = _y + _h - _r + cverts[ii * 2 + 1] * _r;
}
for (uint32_t ii = num; ii <= num * 2; ++ii)
{
*vv++ = _x + r + cverts[ii * 2] * r;
*vv++ = _y + h - r + cverts[ii * 2 + 1] * r;
*vv++ = _x + _r + cverts[ii * 2] * _r;
*vv++ = _y + _h - _r + cverts[ii * 2 + 1] * _r;
}
for (uint32_t ii = num * 2; ii <= num * 3; ++ii)
{
*vv++ = _x + r + cverts[ii * 2] * r;
*vv++ = _y + r + cverts[ii * 2 + 1] * r;
*vv++ = _x + _r + cverts[ii * 2] * _r;
*vv++ = _y + _r + cverts[ii * 2 + 1] * _r;
}
for (uint32_t ii = num * 3; ii < num * 4; ++ii)
{
*vv++ = _x + w - r + cverts[ii * 2] * r;
*vv++ = _y + r + cverts[ii * 2 + 1] * r;
*vv++ = _x + _w - _r + cverts[ii * 2] * _r;
*vv++ = _y + _r + cverts[ii * 2 + 1] * _r;
}
*vv++ = _x + w - r + cverts[0] * r;
*vv++ = _y + r + cverts[1] * r;
*vv++ = _x + _w - _r + cverts[0] * _r;
*vv++ = _y + _r + cverts[1] * _r;
drawPolygon(verts, (num + 1) * 4, _fth, _argb);
}