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 // BG
if (0 == _r) drawRoundedRect( (float)xx
{ , (float)yy
drawRect( (float)xx , (float)width
, (float)yy , (float)height
, (float)width , (float)_r
, (float)height , imguiRGBA(0, 0, 0, 196)
, imguiRGBA(0, 0, 0, 196) );
);
}
else
{
drawRoundedRect( (float)xx
, (float)yy
, (float)width
, (float)height
, (float)_r
, imguiRGBA(0, 0, 0, 196)
);
}
// Bar // Bar
if (isActive(hid) ) if (isActive(hid) )
{ {
if (0 == _r) drawRoundedRect( (float)hx
{ , (float)hy
drawRect( (float)hx , (float)hw
, (float)hy , (float)hh
, (float)hw , (float)_r
, (float)hh , imguiRGBA(255, 196, 0, 196)
, imguiRGBA(255, 196, 0, 196) );
);
}
else
{
drawRoundedRect( (float)hx
, (float)hy
, (float)hw
, (float)hh
, (float)_r
, imguiRGBA(255, 196, 0, 196)
);
}
} }
else else
{ {
if (0 == _r) drawRoundedRect( (float)hx
{ , (float)hy
drawRect( (float)hx , (float)hw
, (float)hy , (float)hh
, (float)hw , (float)_r
, (float)hh , isHot(hid) ? imguiRGBA(255, 196, 0, 96) : imguiRGBA(255, 255, 255, 64)
, 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)
);
}
} }
} }
else else
@ -1174,25 +1138,13 @@ struct Imgui
const uint32_t rgb0 = _rgb0&0x00ffffff; const uint32_t rgb0 = _rgb0&0x00ffffff;
if (0 == _r) drawRoundedRect( (float)xx
{ , (float)yy
drawRect( (float)xx , (float)width
, (float)yy , (float)height
, (float)width , (float)_r
, (float)height , rgb0 | imguiRGBA(0, 0, 0, isActive(id) ? 196 : 96)
, 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)
);
}
if (enabled) if (enabled)
{ {
@ -1409,25 +1361,13 @@ 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) drawRoundedRect( (float)xx
{ , (float)yy
drawRect( (float)xx , (float)width
, (float)yy , (float)height
, (float)width , (float)_r
, (float)height , isActiveInputField(id)?imguiRGBA(255,196,0,255):imguiRGBA(128,128,128,96)
, 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)
);
}
if (isActiveInputField(id) ) if (isActiveInputField(id) )
{ {
@ -1519,25 +1459,13 @@ 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) drawRoundedRect( (float)xx
{ , (float)yy
drawRect( (float)xx , (float)width
, (float)yy , (float)_height
, (float)width , (float)_r
, (float)_height , _enabled?imguiRGBA(128,128,128,96):imguiRGBA(128,128,128,64)
, _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)
);
}
for (uint8_t ii = 0; ii < tabCount; ++ii) 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); textColor = enabled?imguiRGBA(0,0,0,255):imguiRGBA(255,255,255,100);
if (0 == _r) drawRoundedRect( (float)buttonX
{ , (float)yy
drawRect( (float)buttonX , (float)tabWidth
, (float)yy , (float)_height
, (float)tabWidth , (float)_r
, (float)_height , enabled?imguiRGBA(255,196,0,200):imguiRGBA(128,128,128,32)
, 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)
);
}
} }
else else
{ {
@ -1984,13 +1900,12 @@ 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) );
);
drawTriangle( triX drawTriangle( triX
, triY , 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] = 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);
} }