summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/common/imgui/imgui.cpp
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2015-09-12 10:23:53 +0200
committer Miodrag Milanovic <mmicko@gmail.com>2015-09-12 10:23:53 +0200
commit7ca8f88a5c399317265d9a2f5132eab2ab7723ac (patch)
treecf7af75fb307bd040508c4c2455d3bd6755619f4 /3rdparty/bgfx/examples/common/imgui/imgui.cpp
parent6d06509293e2fe6b1743085471f0ff5268a1b351 (diff)
Added latest BGFX (nw)
Diffstat (limited to '3rdparty/bgfx/examples/common/imgui/imgui.cpp')
-rw-r--r--3rdparty/bgfx/examples/common/imgui/imgui.cpp75
1 files changed, 52 insertions, 23 deletions
diff --git a/3rdparty/bgfx/examples/common/imgui/imgui.cpp b/3rdparty/bgfx/examples/common/imgui/imgui.cpp
index d44a4a46a45..1ff8e090818 100644
--- a/3rdparty/bgfx/examples/common/imgui/imgui.cpp
+++ b/3rdparty/bgfx/examples/common/imgui/imgui.cpp
@@ -29,7 +29,6 @@
#include <bx/fpumath.h>
#include <bx/handlealloc.h>
-#include "../entry/dbg.h"
#include "imgui.h"
#include "ocornut_imgui.h"
#include "../nanovg/nanovg.h"
@@ -486,9 +485,9 @@ struct Imgui
PosUvVertex::init();
PosNormalVertex::init();
- u_imageLodEnabled = bgfx::createUniform("u_imageLodEnabled", bgfx::UniformType::Uniform4fv);
- u_imageSwizzle = bgfx::createUniform("u_swizzle", bgfx::UniformType::Uniform4fv);
- s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Uniform1i);
+ u_imageLodEnabled = bgfx::createUniform("u_imageLodEnabled", bgfx::UniformType::Vec4);
+ u_imageSwizzle = bgfx::createUniform("u_swizzle", bgfx::UniformType::Vec4);
+ s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Int1);
const bgfx::Memory* vs_imgui_color;
const bgfx::Memory* fs_imgui_color;
@@ -533,6 +532,20 @@ struct Imgui
fs_imgui_image = bgfx::makeRef(fs_imgui_image_dx11, sizeof(fs_imgui_image_dx11) );
fs_imgui_image_swizz = bgfx::makeRef(fs_imgui_image_swizz_dx11, sizeof(fs_imgui_image_swizz_dx11) );
break;
+
+ case bgfx::RendererType::Metal:
+ vs_imgui_color = bgfx::makeRef(vs_imgui_color_mtl, sizeof(vs_imgui_color_mtl) );
+ fs_imgui_color = bgfx::makeRef(fs_imgui_color_mtl, sizeof(fs_imgui_color_mtl) );
+ vs_imgui_texture = bgfx::makeRef(vs_imgui_texture_mtl, sizeof(vs_imgui_texture_mtl) );
+ fs_imgui_texture = bgfx::makeRef(fs_imgui_texture_mtl, sizeof(fs_imgui_texture_mtl) );
+ vs_imgui_cubemap = bgfx::makeRef(vs_imgui_cubemap_mtl, sizeof(vs_imgui_cubemap_mtl) );
+ fs_imgui_cubemap = bgfx::makeRef(fs_imgui_cubemap_mtl, sizeof(fs_imgui_cubemap_mtl) );
+ vs_imgui_latlong = bgfx::makeRef(vs_imgui_latlong_mtl, sizeof(vs_imgui_latlong_mtl) );
+ fs_imgui_latlong = bgfx::makeRef(fs_imgui_latlong_mtl, sizeof(fs_imgui_latlong_mtl) );
+ vs_imgui_image = bgfx::makeRef(vs_imgui_image_mtl, sizeof(vs_imgui_image_mtl) );
+ fs_imgui_image = bgfx::makeRef(fs_imgui_image_mtl, sizeof(fs_imgui_image_mtl) );
+ fs_imgui_image_swizz = bgfx::makeRef(fs_imgui_image_swizz_mtl, sizeof(fs_imgui_image_swizz_mtl) );
+ break;
default:
vs_imgui_color = bgfx::makeRef(vs_imgui_color_glsl, sizeof(vs_imgui_color_glsl) );
@@ -771,7 +784,7 @@ struct Imgui
&& m_leftPressed)
{
// Toggle active input.
- if (isActiveInputField(_id))
+ if (isActiveInputField(_id) )
{
clearActiveInputField();
}
@@ -824,7 +837,7 @@ struct Imgui
const int32_t mx = int32_t(float(_mx)*xscale);
const int32_t my = int32_t(float(_my)*yscale);
- IMGUI_beginFrame(mx, my, _button, _width, _height, _inputChar, _view);
+ IMGUI_beginFrame(mx, my, _button, _scroll, _width, _height, _inputChar, _view);
nvgBeginFrameScaled(m_nvg, m_viewWidth, m_viewHeight, m_surfaceWidth, m_surfaceHeight, 1.0f);
nvgViewId(m_nvg, _view);
@@ -832,7 +845,7 @@ struct Imgui
bgfx::setViewSeq(_view, true);
const bgfx::HMD* hmd = bgfx::getHMD();
- if (NULL != hmd)
+ if (NULL != hmd && 0 != (hmd->flags & BGFX_HMD_RENDERING) )
{
m_viewWidth = _width / 2;
m_surfaceWidth = _surfaceWidth / 2;
@@ -1081,7 +1094,7 @@ struct Imgui
else
{
// Clear active if scroll is selected but not visible any more.
- if (isActive(hid))
+ if (isActive(hid) )
{
clearActive();
}
@@ -1208,6 +1221,11 @@ struct Imgui
const uint32_t rgb0 = _rgb0&0x00ffffff;
+ if (!visible(yy, height, area.m_scissorY, area.m_scissorHeight))
+ {
+ return false;
+ }
+
drawRoundedRect( (float)xx
, (float)yy
, (float)width
@@ -1253,6 +1271,11 @@ struct Imgui
const bool over = enabled && inRect(xx, yy, width, height);
const bool res = buttonLogic(id, over);
+ if (!visible(yy, height, area.m_scissorY, area.m_scissorHeight))
+ {
+ return false;
+ }
+
if (isHot(id) )
{
drawRoundedRect( (float)xx
@@ -1303,6 +1326,12 @@ struct Imgui
const int32_t cx = xx + BUTTON_HEIGHT / 2 - CHECK_SIZE / 2;
const int32_t cy = yy + BUTTON_HEIGHT / 2 - CHECK_SIZE / 2;
+
+ if (!visible(cy, CHECK_SIZE+6, area.m_scissorY, area.m_scissorHeight))
+ {
+ return false;
+ }
+
drawRoundedRect( (float)cx - 3
, (float)cy - 3
, (float)CHECK_SIZE + 6
@@ -1400,7 +1429,7 @@ struct Imgui
// Handle input.
if (isActiveInputField(id) )
{
- const size_t cursor = size_t(strlen(_str));
+ const size_t cursor = size_t(strlen(_str) );
if (m_char == 0x08 || m_char == 0x7f) //backspace or delete
{
@@ -1423,7 +1452,7 @@ struct Imgui
if (drawLabel)
{
uint32_t numVertices = 0; //unused
- const int32_t labelWidth = int32_t(getTextLength(m_fonts[m_currentFontIdx].m_cdata, _label, numVertices));
+ const int32_t labelWidth = int32_t(getTextLength(m_fonts[m_currentFontIdx].m_cdata, _label, numVertices) );
xx += (labelWidth + 6);
width -= (labelWidth + 6);
}
@@ -1563,7 +1592,7 @@ struct Imgui
, enabled?imguiRGBA(255,196,0,200):imguiRGBA(128,128,128,32)
);
}
- else if (isActive(id))
+ else if (isActive(id) )
{
drawRoundedRect( (float)buttonX
, (float)yy
@@ -1633,9 +1662,8 @@ struct Imgui
|BGFX_STATE_ALPHA_WRITE
|BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA)
);
- bgfx::setProgram(m_imageProgram);
setCurrentScissor();
- bgfx::submit(m_view);
+ bgfx::submit(m_view, m_imageProgram);
return res;
}
@@ -1701,9 +1729,8 @@ struct Imgui
|BGFX_STATE_ALPHA_WRITE
|BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA)
);
- bgfx::setProgram(m_imageSwizzProgram);
setCurrentScissor();
- bgfx::submit(m_view);
+ bgfx::submit(m_view, m_imageSwizzProgram);
return res;
}
@@ -1762,9 +1789,8 @@ struct Imgui
|BGFX_STATE_ALPHA_WRITE
|BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA)
);
- bgfx::setProgram(m_latlongProgram);
setCurrentScissor();
- bgfx::submit(m_view);
+ bgfx::submit(m_view, m_latlongProgram);
return res;
}
@@ -1895,7 +1921,6 @@ struct Imgui
bgfx::setTransform(mtx);
bgfx::setTexture(0, s_texColor, _cubemap);
- bgfx::setProgram(m_cubeMapProgram);
bgfx::setVertexBuffer(&tvb);
bgfx::setIndexBuffer(&tib);
bgfx::setState(BGFX_STATE_RGB_WRITE
@@ -1903,7 +1928,7 @@ struct Imgui
|BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA)
);
setCurrentScissor();
- bgfx::submit(m_view);
+ bgfx::submit(m_view, m_cubeMapProgram);
return res;
}
@@ -2411,9 +2436,8 @@ struct Imgui
| BGFX_STATE_ALPHA_WRITE
| BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA)
);
- bgfx::setProgram(m_colorProgram);
setCurrentScissor();
- bgfx::submit(m_view);
+ bgfx::submit(m_view, m_colorProgram);
}
}
@@ -2717,9 +2741,8 @@ struct Imgui
| BGFX_STATE_ALPHA_WRITE
| BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA)
);
- bgfx::setProgram(m_textureProgram);
setCurrentScissor();
- bgfx::submit(m_view);
+ bgfx::submit(m_view, m_textureProgram);
}
#endif // USE_NANOVG_FONT
}
@@ -3055,6 +3078,12 @@ struct Imgui
bool m_scissorEnabled;
};
+ bool visible(int32_t _elemY, int32_t _elemHeight, int32_t _scissorY, int32_t _scissorHeight)
+ {
+ return _elemY > _scissorY
+ && (_elemY+_elemHeight) < (_scissorY+_scissorHeight);
+ }
+
inline Area& getCurrentArea()
{
return m_areas[m_areaId];