Added imguiBorderButton().

This commit is contained in:
Dario Manesku 2014-08-10 13:11:16 +01:00
parent 1f884a588e
commit 6e3f21f062
2 changed files with 142 additions and 5 deletions

View file

@ -299,6 +299,8 @@ struct Imgui
, m_halfTexel(0.0f)
, m_nvg(NULL)
, m_view(31)
, m_viewWidth(0)
, m_viewHeight(0)
, m_currentFontIdx(0)
{
m_invTextureWidth = 1.0f/m_textureWidth;
@ -636,6 +638,8 @@ struct Imgui
nvgBeginFrame(m_nvg, _width, _height, 1.0f, NVG_STRAIGHT_ALPHA);
m_view = _view;
m_viewWidth = _width;
m_viewHeight = _height;
bgfx::setViewSeq(_view, true);
bgfx::setViewRect(_view, 0, 0, _width, _height);
@ -1169,7 +1173,7 @@ struct Imgui
, cy
, CHECK_SIZE
, CHECK_SIZE
, 2
, TriangleOrientation::Up
, imguiRGBA(255, 255, 255, isActive(id) ? 255 : 200)
);
}
@ -1179,7 +1183,7 @@ struct Imgui
, cy
, CHECK_SIZE
, CHECK_SIZE
, 1
, TriangleOrientation::Right
, imguiRGBA(255, 255, 255, isActive(id) ? 255 : 200)
);
}
@ -1216,6 +1220,85 @@ struct Imgui
return res;
}
bool borderButton(ImguiBorder::Enum _border, bool _checked, bool _enabled)
{
m_widgetId++;
uint16_t id = (m_areaId << 8) | m_widgetId;
const int32_t triSize = 12;
const int32_t borderSize = 15;
int32_t xx;
int32_t yy;
int32_t width;
int32_t height;
int32_t triX;
int32_t triY;
TriangleOrientation::Enum orientation;
if (ImguiBorder::Left == _border)
{
xx = -borderSize;
yy = 0;
width = 2*borderSize;
height = m_viewHeight;
triX = 0;
triY = (m_viewHeight-triSize)/2;
orientation = _checked ? TriangleOrientation::Left : TriangleOrientation::Right;
}
else if (ImguiBorder::Right == _border)
{
xx = m_viewWidth - borderSize;
yy = 0;
width = 2*borderSize;
height = m_viewHeight;
triX = m_viewWidth - triSize - 2;
triY = (m_viewHeight-width)/2;
orientation = _checked ? TriangleOrientation::Right : TriangleOrientation::Left;
}
else if (ImguiBorder::Top == _border)
{
xx = 0;
yy = -borderSize;
width = m_viewWidth;
height = 2*borderSize;
triX = (m_viewWidth-triSize)/2;
triY = 0;
orientation = _checked ? TriangleOrientation::Up : TriangleOrientation::Down;
}
else //if (ImguiBorder::Bottom == _border).
{
xx = 0;
yy = m_viewHeight - borderSize;
width = m_viewWidth;
height = 2*borderSize;
triX = (m_viewWidth-triSize)/2;
triY = m_viewHeight-triSize;
orientation = _checked ? TriangleOrientation::Down : TriangleOrientation::Up;
}
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)
);
drawTriangle( triX
, triY
, triSize
, triSize
, orientation
, isHot(id) ? imguiRGBA(255, 196, 0, 222) : imguiRGBA(255, 255, 255, 192)
);
return res;
}
void labelVargs(const char* _format, va_list _argList)
{
char temp[8192];
@ -1603,9 +1686,31 @@ struct Imgui
drawPolygon(verts, 4, _fth, _abgr);
}
void drawTriangle(int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t _flags, uint32_t _abgr)
struct TriangleOrientation
{
if (1 == _flags)
enum Enum
{
Left,
Right,
Up,
Down,
};
};
void drawTriangle(int32_t _x, int32_t _y, int32_t _width, int32_t _height, TriangleOrientation::Enum _orientation, uint32_t _abgr)
{
if (TriangleOrientation::Left == _orientation)
{
const float verts[3 * 2] =
{
(float)_x + 0.5f + (float)_width * 1.0f, (float)_y + 0.5f,
(float)_x + 0.5f, (float)_y + 0.5f + (float)_height / 2.0f - 0.5f,
(float)_x + 0.5f + (float)_width * 1.0f, (float)_y + 0.5f + (float)_height - 1.0f,
};
drawPolygon(verts, 3, 1.0f, _abgr);
}
else if (TriangleOrientation::Right == _orientation)
{
const float verts[3 * 2] =
{
@ -1616,7 +1721,7 @@ struct Imgui
drawPolygon(verts, 3, 1.0f, _abgr);
}
else
else if (TriangleOrientation::Up == _orientation)
{
const float verts[3 * 2] =
{
@ -1625,6 +1730,17 @@ struct Imgui
(float)_x + 0.5f + (float)_width - 1.0f, (float)_y + 0.5f + (float)_height - 1.0f,
};
drawPolygon(verts, 3, 1.0f, _abgr);
}
else //if (TriangleOrientation::Down == _orientation).
{
const float verts[3 * 2] =
{
(float)_x + 0.5f, (float)_y + 0.5f,
(float)_x + 0.5f + (float)_width / 2.0f - 0.5f, (float)_y + 0.5f + (float)_height - 1.0f,
(float)_x + 0.5f + (float)_width - 1.0f, (float)_y + 0.5f,
};
drawPolygon(verts, 3, 1.0f, _abgr);
}
}
@ -2175,6 +2291,8 @@ struct Imgui
NVGcontext* m_nvg;
uint8_t m_view;
uint16_t m_viewWidth;
uint16_t m_viewHeight;
#if !USE_NANOVG_FONT
struct Font
@ -2230,6 +2348,11 @@ void imguiEndFrame()
s_imgui.endFrame();
}
bool imguiBorderButton(ImguiBorder::Enum _border, bool _checked, bool _enabled)
{
return s_imgui.borderButton(_border, _checked, _enabled);
}
bool imguiBeginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll, bool _enabled)
{
return s_imgui.beginScrollArea(_name, _x, _y, _width, _height, _scroll, _enabled);

View file

@ -55,6 +55,17 @@ struct ImguiImageAlign
};
};
struct ImguiBorder
{
enum Enum
{
Left,
Right,
Top,
Bottom
};
};
inline uint32_t imguiRGBA(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 255)
{
return 0
@ -76,6 +87,9 @@ void imguiDestroy();
void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, char _inputChar = 0, uint8_t _view = 31);
void imguiEndFrame();
/// Notice: this function is not to be called between imguiBeginScrollArea() and imguiEndScrollArea().
bool imguiBorderButton(ImguiBorder::Enum _border, bool _checked, bool _enabled = true);
bool imguiBeginScrollArea(const char* _name, int _x, int _y, int _width, int _height, int* _scroll, bool _enabled = true);
void imguiEndScrollArea();