From b18e29a930f985c6c217accf7fbb52ca76ab134a Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 11 Aug 2014 09:51:42 +0100 Subject: [PATCH 01/24] Added optional parameters for imguiIndent(). --- examples/common/imgui/imgui.cpp | 20 ++++++++++---------- examples/common/imgui/imgui.h | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index d1d817e8c..6e5622adb 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -1517,16 +1517,16 @@ struct Imgui return res || valChanged; } - void indent() + void indent(uint16_t _width) { - m_widgetX += INDENT_SIZE; - m_widgetW -= INDENT_SIZE; + m_widgetX += _width; + m_widgetW -= _width; } - void unindent() + void unindent(uint16_t _width) { - m_widgetX -= INDENT_SIZE; - m_widgetW += INDENT_SIZE; + m_widgetX -= _width; + m_widgetW += _width; } void separator(uint16_t _height) @@ -2438,14 +2438,14 @@ void imguiEndScrollArea() s_imgui.endScrollArea(); } -void imguiIndent() +void imguiIndent(uint16_t _width) { - s_imgui.indent(); + s_imgui.indent(_width); } -void imguiUnindent() +void imguiUnindent(uint16_t _width) { - s_imgui.unindent(); + s_imgui.unindent(_width); } void imguiSeparator(uint16_t _height) diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index 1bd0b7f9b..cd66a2bdd 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -93,8 +93,8 @@ bool imguiBorderButton(ImguiBorder::Enum _border, bool _checked, bool _enabled = bool imguiBeginScrollArea(const char* _name, int _x, int _y, int _width, int _height, int* _scroll, bool _enabled = true); void imguiEndScrollArea(); -void imguiIndent(); -void imguiUnindent(); +void imguiIndent(uint16_t _width = 16); +void imguiUnindent(uint16_t _width = 16); void imguiSeparator(uint16_t _height = 12); void imguiSeparatorLine(uint16_t _height = 12); From 20f09a01a9b69663636631b4a0edb011d2e4c0cd Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 11 Aug 2014 10:12:40 +0100 Subject: [PATCH 02/24] Fixing imguiTabs() indentation problem. --- examples/common/imgui/imgui.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 6e5622adb..67b4bcbbc 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -1076,13 +1076,13 @@ struct Imgui m_widgetY += height + DEFAULT_SPACING; uint8_t selected = _selected; - const int32_t tabWidth = m_scrollAreaInnerWidth / count; - const int32_t tabWidthHalf = m_scrollAreaInnerWidth / (count*2); + const int32_t tabWidth = m_widgetW / count; + const int32_t tabWidthHalf = m_widgetW / (count*2); const int32_t textY = yy + height/2 + int32_t(m_fonts[m_currentFontIdx].m_size)/2 - 1; drawRoundedRect( (float)m_widgetX , (float)yy-1 - , (float)m_scrollAreaInnerWidth + , (float)m_widgetW , (float)height+2 , (float)BUTTON_HEIGHT / 2 - 1 , imguiRGBA(128, 128, 128, 96) From a7cc06499be7ff9e497f3f5a34c19748e49c155a Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 11 Aug 2014 10:38:13 +0100 Subject: [PATCH 03/24] Fine tuning imguiScrollArea sizes. --- examples/common/imgui/imgui.cpp | 99 +++++++++++++++++---------------- 1 file changed, 52 insertions(+), 47 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 67b4bcbbc..da42c974f 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -57,7 +57,7 @@ static const int32_t DEFAULT_SPACING = 4; static const int32_t TEXT_HEIGHT = 8; static const int32_t SCROLL_AREA_PADDING = 6; static const int32_t INDENT_SIZE = 16; -static const int32_t AREA_HEADER = 28; +static const int32_t AREA_HEADER = 20; static const int32_t COLOR_WHEEL_PADDING = 60; static const float s_tabStops[4] = {150, 210, 270, 330}; @@ -283,15 +283,13 @@ struct Imgui , m_enabledAreaIds(0) , m_scissor(UINT16_MAX) , m_scrollTop(0) - , m_scrollBottom(0) + , m_scrollHeight(0) , m_scrollRight(0) , m_scrollAreaTop(0) , m_scrollAreaWidth(0) , m_scrollAreaInnerWidth(0) , m_scrollAreaX(0) , m_scrollVal(NULL) - , m_focusTop(0) - , m_focusBottom(0) , m_scrollId(0) , m_insideScrollArea(false) , m_textureWidth(512) @@ -683,54 +681,63 @@ struct Imgui setEnabled(m_areaId); } - m_widgetX = _x + SCROLL_AREA_PADDING; - m_widgetY = _y + AREA_HEADER + (*_scroll); + drawRoundedRect( (float)_x + , (float)_y + , (float)_width + , (float)_height + , 6 + , imguiRGBA(0, 0, 0, 192) + ); + + const bool hasTitle = (NULL != _name && '\0' != _name[0]); + + int32_t header = 0; + if (hasTitle) + { + drawText(_x + 10 + , _y + 18 + , ImguiTextAlign::Left + , _name + , imguiRGBA(255, 255, 255, 128) + ); + header = AREA_HEADER; + } + + const int32_t contentX = _x + SCROLL_AREA_PADDING; + const int32_t contentY = _y + SCROLL_AREA_PADDING + header - 1; + const int32_t contentWidth = _width - SCROLL_AREA_PADDING * 3; + const int32_t contentHeight = _height - 2*SCROLL_AREA_PADDING - header + 1; + + nvgScissor(m_nvg + , float(contentX) + , float(contentY) + , float(contentWidth) + , float(contentHeight) + ); + + m_scissor = bgfx::setScissor(uint16_t(contentX) + , uint16_t(contentY) + , uint16_t(contentWidth) + , uint16_t(contentHeight) + ); + + m_widgetX = contentX; + m_widgetY = contentY + (*_scroll); m_widgetW = _width - SCROLL_AREA_PADDING * 4 - 2; - m_scrollTop = _y + AREA_HEADER; - m_scrollBottom = _y + _height; + m_scrollTop = contentY; + m_scrollHeight = contentHeight; m_scrollRight = _x + _width - SCROLL_AREA_PADDING * 3; m_scrollVal = _scroll; - m_scrollAreaX = _x; + m_scrollAreaX = _x; m_scrollAreaWidth = _width; m_scrollAreaInnerWidth = m_widgetW; - m_scrollAreaTop = m_widgetY; - - m_focusTop = _y - AREA_HEADER; - m_focusBottom = _y - AREA_HEADER + _height; + m_scrollAreaTop = m_widgetY; m_insideScrollArea = inRect(_x, _y, _width, _height, false); m_insideCurrentScroll = m_insideScrollArea; - drawRoundedRect( (float)_x - , (float)_y - , (float)_width - , (float)_height - , 6 - , imguiRGBA(0, 0, 0, 192) - ); - - drawText(_x + AREA_HEADER / 2 - , _y + AREA_HEADER / 2 - , ImguiTextAlign::Left - , _name - , imguiRGBA(255, 255, 255, 128) - ); - - nvgScissor(m_nvg - , float(_x + SCROLL_AREA_PADDING) - , float(_y + AREA_HEADER - 1) - , float(_width - SCROLL_AREA_PADDING * 3) - , float(_height - AREA_HEADER - SCROLL_AREA_PADDING) - ); - - m_scissor = bgfx::setScissor(uint16_t(_x + SCROLL_AREA_PADDING) - , uint16_t(_y + AREA_HEADER - 1) - , uint16_t(_width - SCROLL_AREA_PADDING * 3) - , uint16_t(_height - AREA_HEADER - SCROLL_AREA_PADDING) - ); - return m_insideScrollArea; } @@ -744,10 +751,10 @@ struct Imgui int32_t xx = m_scrollRight + SCROLL_AREA_PADDING / 2; int32_t yy = m_scrollTop; int32_t width = SCROLL_AREA_PADDING * 2; - int32_t height = m_scrollBottom - m_scrollTop; + int32_t height = m_scrollHeight; int32_t stop = m_scrollAreaTop; - int32_t sbot = m_widgetY + SCROLL_AREA_PADDING; + int32_t sbot = m_widgetY - DEFAULT_SPACING; int32_t sh = sbot - stop; // The scrollable area height. float barHeight = (float)height / (float)sh; @@ -1078,7 +1085,7 @@ struct Imgui uint8_t selected = _selected; const int32_t tabWidth = m_widgetW / count; const int32_t tabWidthHalf = m_widgetW / (count*2); - const int32_t textY = yy + height/2 + int32_t(m_fonts[m_currentFontIdx].m_size)/2 - 1; + const int32_t textY = yy + height/2 + int32_t(m_fonts[m_currentFontIdx].m_size)/2 - 2; drawRoundedRect( (float)m_widgetX , (float)yy-1 @@ -2344,15 +2351,13 @@ struct Imgui float m_circleVerts[NUM_CIRCLE_VERTS * 2]; int32_t m_scrollTop; - int32_t m_scrollBottom; + int32_t m_scrollHeight; int32_t m_scrollRight; int32_t m_scrollAreaTop; int32_t m_scrollAreaWidth; int32_t m_scrollAreaInnerWidth; int32_t m_scrollAreaX; int32_t* m_scrollVal; - int32_t m_focusTop; - int32_t m_focusBottom; uint16_t m_scrollId; bool m_insideScrollArea; From 6388d1a657dd0f261412a55e4f92909ced684bdd Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 11 Aug 2014 10:59:49 +0100 Subject: [PATCH 04/24] Added optional _r (corner radius) parameter for imguiBeginScrollArea(). --- examples/common/imgui/imgui.cpp | 32 ++++++++++++++++++++++---------- examples/common/imgui/imgui.h | 2 +- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index da42c974f..dbd378984 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -670,7 +670,7 @@ struct Imgui nvgEndFrame(m_nvg); } - bool beginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll, bool _enabled) + bool beginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll, int32_t _r, bool _enabled) { m_areaId++; m_widgetId = 0; @@ -681,13 +681,25 @@ struct Imgui setEnabled(m_areaId); } - drawRoundedRect( (float)_x - , (float)_y - , (float)_width - , (float)_height - , 6 - , imguiRGBA(0, 0, 0, 192) - ); + if (0 == _r) + { + drawRect( (float)_x + , (float)_y + , (float)_width + , (float)_height + 0.3f /*border fix for seamlessly joining two scroll areas*/ + , imguiRGBA(0, 0, 0, 192) + ); + } + else + { + drawRoundedRect( (float)_x + , (float)_y + , (float)_width + , (float)_height + , (float)_r + , imguiRGBA(0, 0, 0, 192) + ); + } const bool hasTitle = (NULL != _name && '\0' != _name[0]); @@ -2433,9 +2445,9 @@ 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) +bool imguiBeginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll, int32_t _r, bool _enabled) { - return s_imgui.beginScrollArea(_name, _x, _y, _width, _height, _scroll, _enabled); + return s_imgui.beginScrollArea(_name, _x, _y, _width, _height, _scroll, _r, _enabled); } void imguiEndScrollArea() diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index cd66a2bdd..1ff293e54 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -90,7 +90,7 @@ 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); +bool imguiBeginScrollArea(const char* _name, int _x, int _y, int _width, int _height, int* _scroll, int32_t _r = 6, bool _enabled = true); void imguiEndScrollArea(); void imguiIndent(uint16_t _width = 16); From 0c7dea6cb3534b8772a373ea0fe809de56049b1e Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 11 Aug 2014 19:48:37 +0100 Subject: [PATCH 05/24] Minor imgui fixes. --- examples/common/imgui/imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index dbd378984..9e86240b2 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -685,7 +685,7 @@ struct Imgui { drawRect( (float)_x , (float)_y - , (float)_width + , (float)_width + 0.3f /*border fix for seamlessly joining two scroll areas*/ , (float)_height + 0.3f /*border fix for seamlessly joining two scroll areas*/ , imguiRGBA(0, 0, 0, 192) ); @@ -1052,7 +1052,7 @@ struct Imgui // Draw input area. int32_t height = BUTTON_HEIGHT; - int32_t width = m_widgetW - 2; + int32_t width = m_widgetW; if (drawLabel) { uint32_t numVertices = 0; //unused From fcc642483f5b020136b931b88fa55c5a8ee127ec Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 11 Aug 2014 19:49:48 +0100 Subject: [PATCH 06/24] Added imguiLabel() overload. --- examples/common/imgui/imgui.cpp | 14 +++++++++++--- examples/common/imgui/imgui.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 9e86240b2..acea0a1ef 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -1392,7 +1392,7 @@ struct Imgui return res; } - void labelVargs(const char* _format, va_list _argList) + void labelVargs(const char* _format, va_list _argList, bool _enabled) { char temp[8192]; char* out = temp; @@ -1411,7 +1411,7 @@ struct Imgui , yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2 , ImguiTextAlign::Left , out - , imguiRGBA(255, 255, 255, 255) + , _enabled?imguiRGBA(255, 255, 255, 255):imguiRGBA(255, 255, 255, 128) ); } @@ -2499,7 +2499,15 @@ void imguiLabel(const char* _format, ...) { va_list argList; va_start(argList, _format); - s_imgui.labelVargs(_format, argList); + s_imgui.labelVargs(_format, argList, true); + va_end(argList); +} + +void imguiLabel(bool _enabled, const char* _format, ...) +{ + va_list argList; + va_start(argList, _format); + s_imgui.labelVargs(_format, argList, _enabled); va_end(argList); } diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index 1ff293e54..82ba29e17 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -103,6 +103,7 @@ bool imguiItem(const char* _text, bool _enabled = true); bool imguiCheck(const char* _text, bool _checked, bool _enabled = true); bool imguiCollapse(const char* _text, const char* _subtext, bool _checked, bool _enabled = true); void imguiLabel(const char* _format, ...); +void imguiLabel(bool _enabled, const char* _format, ...); void imguiValue(const char* _text); bool imguiSlider(const char* _text, float& _val, float _vmin, float _vmax, float _vinc, bool _enabled = true); bool imguiSlider(const char* _text, int32_t& _val, int32_t _vmin, int32_t _vmax, bool _enabled = true); From 06d617639283ce890ea072592cdc95d4af9e4cb8 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 11 Aug 2014 20:22:08 +0100 Subject: [PATCH 07/24] Added overload for imguiTabs() with look customization parameters. --- examples/common/imgui/imgui.cpp | 73 ++++++++++++++++++++++++--------- examples/common/imgui/imgui.h | 2 + 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index acea0a1ef..d84c7ae97 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -1080,7 +1080,7 @@ struct Imgui ); } - uint8_t tabs(uint8_t _selected, bool _enabled, va_list _argList) + uint8_t tabs(uint8_t _selected, bool _enabled, int32_t _height, int32_t _r, va_list _argList) { uint8_t count; const char* titles[16]; @@ -1091,21 +1091,32 @@ struct Imgui } const int32_t yy = m_widgetY; - const int32_t height = BUTTON_HEIGHT; - m_widgetY += height + DEFAULT_SPACING; + m_widgetY += _height + DEFAULT_SPACING; uint8_t selected = _selected; const int32_t tabWidth = m_widgetW / count; const int32_t tabWidthHalf = m_widgetW / (count*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; - drawRoundedRect( (float)m_widgetX - , (float)yy-1 - , (float)m_widgetW - , (float)height+2 - , (float)BUTTON_HEIGHT / 2 - 1 - , imguiRGBA(128, 128, 128, 96) - ); + if (0 == _r) + { + drawRect( (float)m_widgetX + , (float)yy-1 + , (float)m_widgetW + , (float)_height+2 + , imguiRGBA(128, 128, 128, 96) + ); + } + else + { + drawRoundedRect( (float)m_widgetX + , (float)yy-1 + , (float)m_widgetW + , (float)_height+2 + , (float)_r + , imguiRGBA(128, 128, 128, 96) + ); + } for (uint8_t ii = 0; ii < count; ++ii) { @@ -1116,7 +1127,7 @@ struct Imgui int32_t textX = xx + tabWidthHalf; const bool enabled = _enabled && isEnabled(m_areaId); - const bool over = enabled && inRect(xx, yy, tabWidth, height); + const bool over = enabled && inRect(xx, yy, tabWidth, _height); const bool res = buttonLogic(id, over); if (res) @@ -1129,13 +1140,25 @@ struct Imgui { textColor = enabled?imguiRGBA(0,0,0,255):imguiRGBA(255,255,255,100); - drawRoundedRect( (float)xx - , (float)yy-1 - , (float)tabWidth - , (float)height+2 - , (float)BUTTON_HEIGHT / 2 - 1 - , enabled?imguiRGBA(255,196,0,200):imguiRGBA(128,128,128,96) - ); + if (0 == _r) + { + drawRect( (float)xx + , (float)yy-1 + , (float)tabWidth + , (float)_height+2 + , enabled?imguiRGBA(255,196,0,200):imguiRGBA(128,128,128,96) + ); + } + else + { + drawRoundedRect( (float)xx + , (float)yy-1 + , (float)tabWidth + , (float)_height+2 + , (float)_r + , enabled?imguiRGBA(255,196,0,200):imguiRGBA(128,128,128,96) + ); + } } else { @@ -2538,7 +2561,17 @@ uint8_t imguiTabsUseMacroInstead(uint8_t _selected, bool _enabled, ...) { va_list argList; va_start(argList, _enabled); - const uint8_t result = s_imgui.tabs(_selected, _enabled, argList); + const uint8_t result = s_imgui.tabs(_selected, _enabled, BUTTON_HEIGHT, BUTTON_HEIGHT/2 - 1, argList); + va_end(argList); + + return result; +} + +uint8_t imguiTabsUseMacroInstead(uint8_t _selected, bool _enabled, int32_t _height, int32_t _r, ...) +{ + va_list argList; + va_start(argList, _r); + const uint8_t result = s_imgui.tabs(_selected, _enabled, _height, _r, argList); va_end(argList); return result; diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index 82ba29e17..66d25a37f 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -110,6 +110,8 @@ bool imguiSlider(const char* _text, int32_t& _val, int32_t _vmin, int32_t _vmax, void imguiInput(const char* _label, char* _str, uint32_t _len, bool _enabled = true); uint8_t imguiTabsUseMacroInstead(uint8_t _selected, bool _enabled, ...); +uint8_t imguiTabsUseMacroInstead(uint8_t _selected, bool _enabled, int32_t _height, int32_t _r, ...); +// Notice: this macro can be used for both overloads. #define imguiTabs(_selected, _enabled, ...) imguiTabsUseMacroInstead(_selected, _enabled, __VA_ARGS__, NULL) uint32_t imguiChooseUseMacroInstead(uint32_t _selected, ...); From c2b0ee89cb43c745cd6ad88a116b0047698deb1a Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 11 Aug 2014 20:26:53 +0100 Subject: [PATCH 08/24] Reordering imguiBeginScrollArea() parameters. --- examples/common/imgui/imgui.cpp | 6 +++--- examples/common/imgui/imgui.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index d84c7ae97..9dc868b9c 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -670,7 +670,7 @@ struct Imgui nvgEndFrame(m_nvg); } - bool beginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll, int32_t _r, bool _enabled) + bool beginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll, bool _enabled, int32_t _r) { m_areaId++; m_widgetId = 0; @@ -2468,9 +2468,9 @@ 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, int32_t _r, bool _enabled) +bool imguiBeginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, int32_t* _scroll, bool _enabled, int32_t _r) { - return s_imgui.beginScrollArea(_name, _x, _y, _width, _height, _scroll, _r, _enabled); + return s_imgui.beginScrollArea(_name, _x, _y, _width, _height, _scroll, _enabled, _r); } void imguiEndScrollArea() diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index 66d25a37f..5e789173a 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -90,7 +90,7 @@ 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, int32_t _r = 6, bool _enabled = true); +bool imguiBeginScrollArea(const char* _name, int _x, int _y, int _width, int _height, int* _scroll, bool _enabled = true, int32_t _r = 6); void imguiEndScrollArea(); void imguiIndent(uint16_t _width = 16); From 762c423b4295d1354b746ce2f3d726c6104da004 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 11 Aug 2014 21:28:39 +0100 Subject: [PATCH 09/24] Added optional parameter for imguiButton(). --- examples/common/imgui/imgui.cpp | 32 ++++++++++++++++++++++---------- examples/common/imgui/imgui.h | 2 +- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 9dc868b9c..e4eaea6ea 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -845,7 +845,7 @@ struct Imgui m_insideCurrentScroll = false; } - bool button(const char* _text, bool _enabled) + bool button(const char* _text, bool _enabled, int32_t _r) { m_widgetId++; uint16_t id = (m_areaId << 8) | m_widgetId; @@ -860,13 +860,25 @@ struct Imgui bool over = enabled && inRect(xx, yy, width, height); bool res = buttonLogic(id, over); - drawRoundedRect( (float)xx - , (float)yy - , (float)width - , (float)height - , (float)BUTTON_HEIGHT / 2 - 1 - , imguiRGBA(128, 128, 128, isActive(id) ? 196 : 96) - ); + if (0 == _r) + { + drawRect( (float)xx + , (float)yy + , (float)width + , (float)height + , imguiRGBA(128, 128, 128, isActive(id) ? 196 : 96) + ); + } + else + { + drawRoundedRect( (float)xx + , (float)yy + , (float)width + , (float)height + , (float)_r + , imguiRGBA(128, 128, 128, isActive(id) ? 196 : 96) + ); + } if (enabled) { @@ -2498,9 +2510,9 @@ void imguiSeparatorLine(uint16_t _height) s_imgui.separatorLine(_height); } -bool imguiButton(const char* _text, bool _enabled) +bool imguiButton(const char* _text, bool _enabled, int32_t _r) { - return s_imgui.button(_text, _enabled); + return s_imgui.button(_text, _enabled, _r); } bool imguiItem(const char* _text, bool _enabled) diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index 5e789173a..17d0f776e 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -98,7 +98,7 @@ void imguiUnindent(uint16_t _width = 16); void imguiSeparator(uint16_t _height = 12); void imguiSeparatorLine(uint16_t _height = 12); -bool imguiButton(const char* _text, bool _enabled = true); +bool imguiButton(const char* _text, bool _enabled = true, int32_t _r = 9); bool imguiItem(const char* _text, bool _enabled = true); bool imguiCheck(const char* _text, bool _checked, bool _enabled = true); bool imguiCollapse(const char* _text, const char* _subtext, bool _checked, bool _enabled = true); From 4501e17f4b65be9ded63fa91146d86795970e145 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 11 Aug 2014 22:26:29 +0100 Subject: [PATCH 10/24] Added optional parameter for imguiEndScrollArea(). --- examples/common/imgui/imgui.cpp | 86 +++++++++++++++++++++++---------- examples/common/imgui/imgui.h | 2 +- 2 files changed, 62 insertions(+), 26 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index e4eaea6ea..b0036d455 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -753,7 +753,7 @@ struct Imgui return m_insideScrollArea; } - void endScrollArea() + void endScrollArea(int32_t _r) { // Disable scissoring. m_scissor = UINT16_MAX; @@ -802,36 +802,72 @@ struct Imgui } // BG - drawRoundedRect( (float)xx - , (float)yy - , (float)width - , (float)height - , (float)width / 2 - 1 - , imguiRGBA(0, 0, 0, 196) - ); - - // Bar - if (isActive(hid) ) + if (0 == _r) { - drawRoundedRect( (float)hx - , (float)hy - , (float)hw - , (float)hh - , (float)width / 2 - 1 - , imguiRGBA(255, 196, 0, 196) + drawRect( (float)xx + , (float)yy + , (float)width + , (float)height + , imguiRGBA(0, 0, 0, 196) ); } else { - drawRoundedRect( (float)hx - , (float)hy - , (float)hw - , (float)hh - , (float)width / 2 - 1 - , isHot(hid) ? imguiRGBA(255, 196, 0, 96) : imguiRGBA(255, 255, 255, 64) + 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) + ); + } + } + 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) + ); + } + } + // Handle mouse scrolling. if (m_insideScrollArea) // && !anyActive() ) { @@ -2485,9 +2521,9 @@ bool imguiBeginScrollArea(const char* _name, int32_t _x, int32_t _y, int32_t _wi return s_imgui.beginScrollArea(_name, _x, _y, _width, _height, _scroll, _enabled, _r); } -void imguiEndScrollArea() +void imguiEndScrollArea(int32_t _r) { - s_imgui.endScrollArea(); + s_imgui.endScrollArea(_r); } void imguiIndent(uint16_t _width) diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index 17d0f776e..3363e852c 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -91,7 +91,7 @@ void imguiEndFrame(); 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, int32_t _r = 6); -void imguiEndScrollArea(); +void imguiEndScrollArea(int32_t _r = 5); void imguiIndent(uint16_t _width = 16); void imguiUnindent(uint16_t _width = 16); From 6e69a02906c12313ca41cd04d47bcb0e8fe0c0af Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 11 Aug 2014 22:28:22 +0100 Subject: [PATCH 11/24] Added optional parameter for imguiInput(). --- examples/common/imgui/imgui.cpp | 32 ++++++++++++++++++++++---------- examples/common/imgui/imgui.h | 2 +- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index b0036d455..b0b4970e5 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -1057,7 +1057,7 @@ struct Imgui return res; } - void input(const char* _label, char* _str, uint32_t _len, bool _enabled) + void input(const char* _label, char* _str, uint32_t _len, bool _enabled, int32_t _r) { m_widgetId++; const uint16_t id = (m_areaId << 8) | m_widgetId; @@ -1112,13 +1112,25 @@ struct Imgui const bool over = enabled && inRect(xx, yy, width, height); inputLogic(id, over); - drawRoundedRect( (float)xx - , (float)yy - , (float)width - , (float)height - , (float)BUTTON_HEIGHT / 5 - 1 - , isActiveInputField(id)?imguiRGBA(255,196,0,255):imguiRGBA(128,128,128,96) - ); + 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) + ); + } drawText(xx + 6 , yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2 @@ -2600,9 +2612,9 @@ bool imguiSlider(const char* _text, int32_t& _val, int32_t _vmin, int32_t _vmax, return result; } -void imguiInput(const char* _label, char* _str, uint32_t _len, bool _enabled) +void imguiInput(const char* _label, char* _str, uint32_t _len, bool _enabled, int32_t _r) { - s_imgui.input(_label, _str, _len, _enabled); + s_imgui.input(_label, _str, _len, _enabled, _r); } uint8_t imguiTabsUseMacroInstead(uint8_t _selected, bool _enabled, ...) diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index 3363e852c..6e7d46142 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -107,7 +107,7 @@ void imguiLabel(bool _enabled, const char* _format, ...); void imguiValue(const char* _text); bool imguiSlider(const char* _text, float& _val, float _vmin, float _vmax, float _vinc, bool _enabled = true); bool imguiSlider(const char* _text, int32_t& _val, int32_t _vmin, int32_t _vmax, bool _enabled = true); -void imguiInput(const char* _label, char* _str, uint32_t _len, bool _enabled = true); +void imguiInput(const char* _label, char* _str, uint32_t _len, bool _enabled = true, int32_t _r = 4); uint8_t imguiTabsUseMacroInstead(uint8_t _selected, bool _enabled, ...); uint8_t imguiTabsUseMacroInstead(uint8_t _selected, bool _enabled, int32_t _height, int32_t _r, ...); From 3f25e22df29ec0e1dedc5e1376e376769bcda2fb Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 12 Aug 2014 10:24:03 +0100 Subject: [PATCH 12/24] Removed imguiImageSwizzle() and added imguiImageChannel(). --- examples/common/imgui/imgui.cpp | 22 ++++++++++++++-------- examples/common/imgui/imgui.h | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index b0b4970e5..21a8c101f 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -1280,8 +1280,10 @@ struct Imgui image(_image, _lod, int32_t(width), int32_t(height), _align); } - void imageSwizzle(bgfx::TextureHandle _image, const float _swizzle[4], float _lod, int32_t _width, int32_t _height, ImguiImageAlign::Enum _align) + void imageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiImageAlign::Enum _align) { + BX_CHECK(_channel < 4, "Channel param must be from 0 to 3!"); + int32_t xx; if (ImguiImageAlign::Left == _align) { @@ -1309,7 +1311,11 @@ struct Imgui screenQuad(xx, yy, _width, _height); bgfx::setUniform(u_imageLod, &_lod); - bgfx::setUniform(u_imageSwizzle, _swizzle); + + float swizz[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + swizz[_channel] = 1.0f; + bgfx::setUniform(u_imageSwizzle, swizz); + bgfx::setTexture(0, s_texColor, bgfx::isValid(_image) ? _image : m_missingTexture); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); bgfx::setProgram(m_imageSwizzProgram); @@ -1317,12 +1323,12 @@ struct Imgui bgfx::submit(m_view); } - void imageSwizzle(bgfx::TextureHandle _image, const float _swizzle[4], float _lod, float _width, float _aspect, ImguiImageAlign::Enum _align) + void imageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, float _width, float _aspect, ImguiImageAlign::Enum _align) { const float width = _width*float(m_scrollAreaInnerWidth); const float height = width/_aspect; - imageSwizzle(_image, _swizzle, _lod, int32_t(width), int32_t(height), _align); + imageChannel(_image, _channel, _lod, int32_t(width), int32_t(height), _align); } bool collapse(const char* _text, const char* _subtext, bool _checked, bool _enabled) @@ -2719,12 +2725,12 @@ void imguiImage(bgfx::TextureHandle _image, float _lod, float _width, float _asp s_imgui.image(_image, _lod, _width, _aspect, _align); } -void imguiImageSwizzle(bgfx::TextureHandle _image, const float _swizzle[4], float _lod, int32_t _width, int32_t _height, ImguiImageAlign::Enum _align) +void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiImageAlign::Enum _align) { - s_imgui.imageSwizzle(_image, _swizzle, _lod, _width, _height, _align); + s_imgui.imageChannel(_image, _channel, _lod, _width, _height, _align); } -void imguiImageSwizzle(bgfx::TextureHandle _image, const float _swizzle[4], float _lod, float _width, float _aspect, ImguiImageAlign::Enum _align) +void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, float _width, float _aspect, ImguiImageAlign::Enum _align) { - s_imgui.imageSwizzle(_image, _swizzle, _lod, _width, _aspect, _align); + s_imgui.imageChannel(_image, _channel, _lod, _width, _aspect, _align); } diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index 6e7d46142..13f4f3dee 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -128,7 +128,7 @@ void imguiColorWheel(const char* _str, float _rgb[3], bool& _activated, bool _en void imguiImage(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t _height, ImguiImageAlign::Enum _align = ImguiImageAlign::LeftIndented); void imguiImage(bgfx::TextureHandle _image, float _lod, float _scale, float _aspect, ImguiImageAlign::Enum _align = ImguiImageAlign::LeftIndented); -void imguiImageSwizzle(bgfx::TextureHandle _image, const float _swizzle[4], float _lod, int32_t _width, int32_t _height, ImguiImageAlign::Enum _align = ImguiImageAlign::LeftIndented); -void imguiImageSwizzle(bgfx::TextureHandle _image, const float _swizzle[4], float _lod, float _scale, float _aspect, ImguiImageAlign::Enum _align = ImguiImageAlign::LeftIndented); +void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiImageAlign::Enum _align = ImguiImageAlign::LeftIndented); +void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, float _scale, float _aspect, ImguiImageAlign::Enum _align = ImguiImageAlign::LeftIndented); #endif // IMGUI_H_HEADER_GUARD From 9715d6fab4994c6bb5a55db2eeda1fb88c9a2a4c Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 12 Aug 2014 10:51:00 +0100 Subject: [PATCH 13/24] Added macro constants for default imgui parameters. --- examples/common/imgui/imgui.h | 42 ++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index 13f4f3dee..f77004b32 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -31,6 +31,32 @@ #define IMGUI_MBUT_LEFT 0x01 #define IMGUI_MBUT_RIGHT 0x02 +/// For custom values, define these macros before including imgui.h + +#ifndef IMGUI_SCROLL_AREA_R + #define IMGUI_SCROLL_AREA_R 6 +#endif //IMGUI_SCROLL_AREA_R + +#ifndef IMGUI_SCROLL_BAR_R + #define IMGUI_SCROLL_BAR_R 5 +#endif //IMGUI_SCROLL_BAR_R + +#ifndef IMGUI_BUTTON_R + #define IMGUI_BUTTON_R 9 +#endif //IMGUI_BUTTON_R + +#ifndef IMGUI_INPUT_R + #define IMGUI_INPUT_R 4 +#endif //IMGUI_INPUT_R + +#ifndef IMGUI_INDENT_VALUE + #define IMGUI_INDENT_VALUE 16 +#endif //IMGUI_INDENT_VALUE + +#ifndef IMGUI_SEPARATOR_VALUE + #define IMGUI_SEPARATOR_VALUE 12 +#endif //IMGUI_SEPARATOR_VALUE + struct ImguiTextAlign { enum Enum @@ -90,15 +116,15 @@ 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, int32_t _r = 6); -void imguiEndScrollArea(int32_t _r = 5); +bool imguiBeginScrollArea(const char* _name, int _x, int _y, int _width, int _height, int* _scroll, bool _enabled = true, int32_t _r = IMGUI_SCROLL_AREA_R); +void imguiEndScrollArea(int32_t _r = IMGUI_SCROLL_BAR_R); -void imguiIndent(uint16_t _width = 16); -void imguiUnindent(uint16_t _width = 16); -void imguiSeparator(uint16_t _height = 12); -void imguiSeparatorLine(uint16_t _height = 12); +void imguiIndent(uint16_t _width = IMGUI_INDENT_VALUE); +void imguiUnindent(uint16_t _width = IMGUI_INDENT_VALUE); +void imguiSeparator(uint16_t _height = IMGUI_SEPARATOR_VALUE); +void imguiSeparatorLine(uint16_t _height = IMGUI_SEPARATOR_VALUE); -bool imguiButton(const char* _text, bool _enabled = true, int32_t _r = 9); +bool imguiButton(const char* _text, bool _enabled = true, int32_t _r = IMGUI_BUTTON_R); bool imguiItem(const char* _text, bool _enabled = true); bool imguiCheck(const char* _text, bool _checked, bool _enabled = true); bool imguiCollapse(const char* _text, const char* _subtext, bool _checked, bool _enabled = true); @@ -107,7 +133,7 @@ void imguiLabel(bool _enabled, const char* _format, ...); void imguiValue(const char* _text); bool imguiSlider(const char* _text, float& _val, float _vmin, float _vmax, float _vinc, bool _enabled = true); bool imguiSlider(const char* _text, int32_t& _val, int32_t _vmin, int32_t _vmax, bool _enabled = true); -void imguiInput(const char* _label, char* _str, uint32_t _len, bool _enabled = true, int32_t _r = 4); +void imguiInput(const char* _label, char* _str, uint32_t _len, bool _enabled = true, int32_t _r = IMGUI_INPUT_R); uint8_t imguiTabsUseMacroInstead(uint8_t _selected, bool _enabled, ...); uint8_t imguiTabsUseMacroInstead(uint8_t _selected, bool _enabled, int32_t _height, int32_t _r, ...); From d64a62866aa97ee4956332430b7cfd32f3dd4b99 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 12 Aug 2014 11:41:57 +0100 Subject: [PATCH 14/24] Imgui scroll fix for variable scrollable area height. --- examples/common/imgui/imgui.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 21a8c101f..2440e0c78 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -773,6 +773,10 @@ struct Imgui if (barHeight < 1.0f) { + // Handle m_scrollVal properly on variable scrollable area height. + const int32_t diff = height - sh; + *m_scrollVal = (*m_scrollVal < diff) ? diff : *m_scrollVal; // m_scrollVal = max(m_scrollVal, diff). + float barY = bx::fsaturate( (float)(yy - stop) / (float)sh); // Handle scroll bar logic. From 677ef2d6c55429518af65da78e03c489d76b98d3 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 12 Aug 2014 12:20:00 +0100 Subject: [PATCH 15/24] Exposing optional imguiButton() color parameter. --- examples/common/imgui/imgui.cpp | 12 +++++++----- examples/common/imgui/imgui.h | 6 +++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 2440e0c78..204279bd0 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -885,7 +885,7 @@ struct Imgui m_insideCurrentScroll = false; } - bool button(const char* _text, bool _enabled, int32_t _r) + bool button(const char* _text, bool _enabled, uint32_t _rgb0, int32_t _r) { m_widgetId++; uint16_t id = (m_areaId << 8) | m_widgetId; @@ -900,13 +900,15 @@ struct Imgui bool over = enabled && inRect(xx, yy, width, height); bool res = buttonLogic(id, over); + const uint32_t rgb0 = _rgb0&0x00ffffff; + if (0 == _r) { drawRect( (float)xx , (float)yy , (float)width , (float)height - , imguiRGBA(128, 128, 128, isActive(id) ? 196 : 96) + , rgb0 | imguiRGBA(0, 0, 0, isActive(id) ? 196 : 96) ); } else @@ -916,7 +918,7 @@ struct Imgui , (float)width , (float)height , (float)_r - , imguiRGBA(128, 128, 128, isActive(id) ? 196 : 96) + , rgb0 | imguiRGBA(0, 0, 0, isActive(id) ? 196 : 96) ); } @@ -2568,9 +2570,9 @@ void imguiSeparatorLine(uint16_t _height) s_imgui.separatorLine(_height); } -bool imguiButton(const char* _text, bool _enabled, int32_t _r) +bool imguiButton(const char* _text, bool _enabled, uint32_t _rgb0, int32_t _r) { - return s_imgui.button(_text, _enabled, _r); + return s_imgui.button(_text, _enabled, _rgb0, _r); } bool imguiItem(const char* _text, bool _enabled) diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index f77004b32..008e547c3 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -45,6 +45,10 @@ #define IMGUI_BUTTON_R 9 #endif //IMGUI_BUTTON_R +#ifndef IMGUI_BUTTON_RGB0 + #define IMGUI_BUTTON_RGB0 imguiRGBA(128, 128, 128, 0) +#endif //IMGUI_BUTTON_RGB0 + #ifndef IMGUI_INPUT_R #define IMGUI_INPUT_R 4 #endif //IMGUI_INPUT_R @@ -124,7 +128,7 @@ void imguiUnindent(uint16_t _width = IMGUI_INDENT_VALUE); void imguiSeparator(uint16_t _height = IMGUI_SEPARATOR_VALUE); void imguiSeparatorLine(uint16_t _height = IMGUI_SEPARATOR_VALUE); -bool imguiButton(const char* _text, bool _enabled = true, int32_t _r = IMGUI_BUTTON_R); +bool imguiButton(const char* _text, bool _enabled = true, uint32_t _rgb0 = IMGUI_BUTTON_RGB0, int32_t _r = IMGUI_BUTTON_R); bool imguiItem(const char* _text, bool _enabled = true); bool imguiCheck(const char* _text, bool _checked, bool _enabled = true); bool imguiCollapse(const char* _text, const char* _subtext, bool _checked, bool _enabled = true); From 7225bba1a1225fc0efc6328829090baec27ce050 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 12 Aug 2014 13:54:04 +0100 Subject: [PATCH 16/24] Tuning imgui spacing parameters. --- examples/common/imgui/imgui.cpp | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 204279bd0..868806ef1 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -1348,8 +1348,10 @@ struct Imgui int32_t height = BUTTON_HEIGHT; m_widgetY += BUTTON_HEIGHT + DEFAULT_SPACING; - const int32_t cx = xx + BUTTON_HEIGHT / 2 - CHECK_SIZE / 2; - const int32_t cy = yy + BUTTON_HEIGHT / 2 - CHECK_SIZE / 2; + const int32_t cx = xx + BUTTON_HEIGHT/2 - CHECK_SIZE/2; + const int32_t cy = yy + BUTTON_HEIGHT/2 - CHECK_SIZE/2 + DEFAULT_SPACING/2; + + const int32_t textY = yy + BUTTON_HEIGHT/2 + TEXT_HEIGHT/2 + DEFAULT_SPACING/2; bool enabled = _enabled && isEnabled(m_areaId); bool over = enabled && inRect(xx, yy, width, height); @@ -1379,7 +1381,7 @@ struct Imgui if (enabled) { drawText(xx + BUTTON_HEIGHT - , yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2 + , textY , ImguiTextAlign::Left , _text , isHot(id) ? imguiRGBA(255, 196, 0, 255) : imguiRGBA(255, 255, 255, 200) @@ -1388,7 +1390,7 @@ struct Imgui else { drawText(xx + BUTTON_HEIGHT - , yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2 + , textY , ImguiTextAlign::Left , _text , imguiRGBA(128, 128, 128, 200) @@ -1398,7 +1400,7 @@ struct Imgui if (_subtext) { drawText(xx + width - BUTTON_HEIGHT / 2 - , yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2 + , textY , ImguiTextAlign::Right , _subtext , imguiRGBA(255, 255, 255, 128) @@ -1501,9 +1503,9 @@ struct Imgui int32_t xx = m_widgetX; int32_t yy = m_widgetY; - m_widgetY += BUTTON_HEIGHT; + m_widgetY += BUTTON_HEIGHT + DEFAULT_SPACING; drawText(xx - , yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2 + , yy + BUTTON_HEIGHT/2 + TEXT_HEIGHT/2 + DEFAULT_SPACING/2 , ImguiTextAlign::Left , out , _enabled?imguiRGBA(255, 255, 255, 255):imguiRGBA(255, 255, 255, 128) @@ -1650,18 +1652,18 @@ struct Imgui void separatorLine(uint16_t _height) { - int32_t xx = m_widgetX; - int32_t yy = m_widgetY + _height/2; - int32_t width = m_widgetW; - int32_t height = 1; + const int32_t rectWidth = m_widgetW; + const int32_t rectHeight = 1; + const int32_t xx = m_widgetX; + const int32_t yy = m_widgetY + _height/2 - rectHeight; m_widgetY += _height; drawRect( (float)xx - , (float)yy - , (float)width - , (float)height - , imguiRGBA(255, 255, 255, 32) - ); + , (float)yy + , (float)rectWidth + , (float)rectHeight + , imguiRGBA(255, 255, 255, 32) + ); } void drawPolygon(const float* _coords, uint32_t _numCoords, float _r, uint32_t _abgr) From f3fb007471c30b8e3bff9fc518d25225aa54e0d9 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 12 Aug 2014 19:21:32 +0100 Subject: [PATCH 17/24] Fixed imgui scroll value handling on window resize. --- examples/common/imgui/imgui.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 868806ef1..df4d60701 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -771,12 +771,19 @@ struct Imgui float barHeight = (float)height / (float)sh; + // Handle m_scrollVal properly on variable scrollable area height. + const int32_t diff = height - sh; + if (diff < 0) + { + *m_scrollVal = (*m_scrollVal > diff) ? *m_scrollVal : diff; // m_scrollVal = max(diff, m_scrollVal). + } + else + { + *m_scrollVal = 0; + } + if (barHeight < 1.0f) { - // Handle m_scrollVal properly on variable scrollable area height. - const int32_t diff = height - sh; - *m_scrollVal = (*m_scrollVal < diff) ? diff : *m_scrollVal; // m_scrollVal = max(m_scrollVal, diff). - float barY = bx::fsaturate( (float)(yy - stop) / (float)sh); // Handle scroll bar logic. From e4a067efe654a958ce3013ac9b6397951a3d1c71 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 12 Aug 2014 19:49:06 +0100 Subject: [PATCH 18/24] Fixing border pixel scissor. --- examples/common/imgui/imgui.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index df4d60701..87e3388e3 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -716,21 +716,21 @@ struct Imgui } const int32_t contentX = _x + SCROLL_AREA_PADDING; - const int32_t contentY = _y + SCROLL_AREA_PADDING + header - 1; + const int32_t contentY = _y + SCROLL_AREA_PADDING + header; const int32_t contentWidth = _width - SCROLL_AREA_PADDING * 3; - const int32_t contentHeight = _height - 2*SCROLL_AREA_PADDING - header + 1; + const int32_t contentHeight = _height - 2*SCROLL_AREA_PADDING - header; nvgScissor(m_nvg , float(contentX) - , float(contentY) + , float(contentY-1) , float(contentWidth) - , float(contentHeight) + , float(contentHeight+1) ); m_scissor = bgfx::setScissor(uint16_t(contentX) - , uint16_t(contentY) + , uint16_t(contentY-1) , uint16_t(contentWidth) - , uint16_t(contentHeight) + , uint16_t(contentHeight+1) ); m_widgetX = contentX; From 83587d51d0feab681a87e2a27142644aa51ebd51 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 12 Aug 2014 19:55:57 +0100 Subject: [PATCH 19/24] Draw parameters fixup for imguiTabs(). --- examples/common/imgui/imgui.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 87e3388e3..d99cbd370 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -1174,18 +1174,18 @@ struct Imgui if (0 == _r) { drawRect( (float)m_widgetX - , (float)yy-1 + , (float)yy , (float)m_widgetW - , (float)_height+2 + , (float)_height , imguiRGBA(128, 128, 128, 96) ); } else { drawRoundedRect( (float)m_widgetX - , (float)yy-1 + , (float)yy , (float)m_widgetW - , (float)_height+2 + , (float)_height , (float)_r , imguiRGBA(128, 128, 128, 96) ); @@ -1216,18 +1216,18 @@ struct Imgui if (0 == _r) { drawRect( (float)xx - , (float)yy-1 + , (float)yy , (float)tabWidth - , (float)_height+2 + , (float)_height , enabled?imguiRGBA(255,196,0,200):imguiRGBA(128,128,128,96) ); } else { drawRoundedRect( (float)xx - , (float)yy-1 + , (float)yy , (float)tabWidth - , (float)_height+2 + , (float)_height , (float)_r , enabled?imguiRGBA(255,196,0,200):imguiRGBA(128,128,128,96) ); From b5abdcb24bb9b41ae1302433afba38535ab33855 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 12 Aug 2014 20:30:07 +0100 Subject: [PATCH 20/24] Tuning up imguiInput(). --- examples/common/imgui/imgui.cpp | 41 ++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index d99cbd370..6a02069fd 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -582,10 +582,8 @@ struct Imgui return res; } - bool inputLogic(uint32_t _id, bool _over) + void inputLogic(uint32_t _id, bool _over) { - bool res = false; - if (!anyActive() ) { if (_over) @@ -596,7 +594,15 @@ struct Imgui if (isHot(_id) && m_leftPressed) { - setActiveInputField(_id); + // Toggle active input. + if (isActiveInputField(_id)) + { + clearActiveInputField(); + } + else + { + setActiveInputField(_id); + } } } @@ -610,10 +616,7 @@ struct Imgui && m_inputField != 0) { clearActiveInputField(); - res = true; } - - return res; } void updateInput(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, char _inputChar) @@ -1145,12 +1148,24 @@ struct Imgui ); } - drawText(xx + 6 - , yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2 - , ImguiTextAlign::Left - , _str - , isActiveInputField(id)?imguiRGBA(0, 0, 0, 255):imguiRGBA(255,255,255,255) - ); + if (isActiveInputField(id) ) + { + drawText(xx + 6 + , yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2 + , ImguiTextAlign::Left + , _str + , imguiRGBA(0, 0, 0, 255) + ); + } + else + { + drawText(xx + 6 + , yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2 + , ImguiTextAlign::Left + , _str + , isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,255) + ); + } } uint8_t tabs(uint8_t _selected, bool _enabled, int32_t _height, int32_t _r, va_list _argList) From 2701efa60acbaf302ca874eb8979ddc6a0852a8d Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 12 Aug 2014 20:51:13 +0100 Subject: [PATCH 21/24] Reverting back imguiLabel() spacing parameters. --- examples/common/imgui/imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 6a02069fd..91cd29d8b 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -1525,9 +1525,9 @@ struct Imgui int32_t xx = m_widgetX; int32_t yy = m_widgetY; - m_widgetY += BUTTON_HEIGHT + DEFAULT_SPACING; + m_widgetY += BUTTON_HEIGHT; drawText(xx - , yy + BUTTON_HEIGHT/2 + TEXT_HEIGHT/2 + DEFAULT_SPACING/2 + , yy + BUTTON_HEIGHT/2 + TEXT_HEIGHT/2 , ImguiTextAlign::Left , out , _enabled?imguiRGBA(255, 255, 255, 255):imguiRGBA(255, 255, 255, 128) From eec6e82c2958d21a43004b29a8f14b6428456229 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 12 Aug 2014 21:30:20 +0100 Subject: [PATCH 22/24] SetWindowTitle() on Windows now changes start menu title as well. --- examples/common/entry/entry_windows.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/common/entry/entry_windows.cpp b/examples/common/entry/entry_windows.cpp index 0a35fb70d..772b1530c 100644 --- a/examples/common/entry/entry_windows.cpp +++ b/examples/common/entry/entry_windows.cpp @@ -637,6 +637,7 @@ namespace entry void setWindowTitle(const char* _title) { SetWindowTextA(s_ctx.m_hwnd, _title); + SetWindowTextA(GetWindow(s_ctx.m_hwnd, GW_HWNDNEXT), _title); } void toggleWindowFrame() From 63d7db800c19af34b752c4394bab74da65d3267b Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 12 Aug 2014 21:41:24 +0100 Subject: [PATCH 23/24] Added imgui getters for widgetX and widgetY. --- examples/common/imgui/imgui.cpp | 10 ++++++++++ examples/common/imgui/imgui.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 91cd29d8b..ed16e3234 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -2594,6 +2594,16 @@ void imguiSeparatorLine(uint16_t _height) s_imgui.separatorLine(_height); } +int32_t imguiGetWidgetX() +{ + return s_imgui.m_widgetX; +} + +int32_t imguiGetWidgetY() +{ + return s_imgui.m_widgetY; +} + bool imguiButton(const char* _text, bool _enabled, uint32_t _rgb0, int32_t _r) { return s_imgui.button(_text, _enabled, _rgb0, _r); diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index 008e547c3..b47f6d8e4 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -128,6 +128,9 @@ void imguiUnindent(uint16_t _width = IMGUI_INDENT_VALUE); void imguiSeparator(uint16_t _height = IMGUI_SEPARATOR_VALUE); void imguiSeparatorLine(uint16_t _height = IMGUI_SEPARATOR_VALUE); +int32_t imguiGetWidgetX(); +int32_t imguiGetWidgetY(); + bool imguiButton(const char* _text, bool _enabled = true, uint32_t _rgb0 = IMGUI_BUTTON_RGB0, int32_t _r = IMGUI_BUTTON_R); bool imguiItem(const char* _text, bool _enabled = true); bool imguiCheck(const char* _text, bool _checked, bool _enabled = true); From ef4c57b7a9b5f4ad2cec65dfef4673eb82707346 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 12 Aug 2014 22:04:56 +0100 Subject: [PATCH 24/24] Added macro definitions for imguiTabs() parameters. --- examples/common/imgui/imgui.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/common/imgui/imgui.h b/examples/common/imgui/imgui.h index b47f6d8e4..d8d5c19b1 100644 --- a/examples/common/imgui/imgui.h +++ b/examples/common/imgui/imgui.h @@ -53,6 +53,14 @@ #define IMGUI_INPUT_R 4 #endif //IMGUI_INPUT_R +#ifndef IMGUI_TABS_HEIGHT + #define IMGUI_TABS_HEIGHT 20 +#endif //IMGUI_TABS_HEIGHT + +#ifndef IMGUI_TABS_R + #define IMGUI_TABS_R 9 +#endif //IMGUI_TABS_R + #ifndef IMGUI_INDENT_VALUE #define IMGUI_INDENT_VALUE 16 #endif //IMGUI_INDENT_VALUE