Changed imguiSlider argument.

This commit is contained in:
Branimir Karadžić 2014-06-29 21:53:23 -07:00
parent dc8b073172
commit 2b147081c4
13 changed files with 91 additions and 50 deletions

View File

@ -262,12 +262,12 @@ int _main_(int /*_argc*/, char** /*_argv*/)
imguiBeginScrollArea("Settings", width - width / 5 - 10, 10, width / 5, height / 3, &scrollArea);
imguiSeparatorLine();
imguiSlider("Speed", &speed, 0.0f, 1.0f, 0.01f);
imguiSlider("Speed", speed, 0.0f, 1.0f, 0.01f);
imguiSeparator();
imguiSlider("Middle gray", &middleGray, 0.1f, 1.0f, 0.01f);
imguiSlider("White point", &white, 0.1f, 2.0f, 0.01f);
imguiSlider("Treshold", &treshold, 0.1f, 2.0f, 0.01f);
imguiSlider("Middle gray", middleGray, 0.1f, 1.0f, 0.01f);
imguiSlider("White point", white, 0.1f, 2.0f, 0.01f);
imguiSlider("Treshold", treshold, 0.1f, 2.0f, 0.01f);
imguiEndScrollArea();
imguiEndFrame();

View File

@ -148,8 +148,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
imguiSeparatorLine();
bool recomputeVisibleText = false;
recomputeVisibleText |= imguiSlider("Number of lines", &visibleLineCount, 1.0f, 177.0f , 1.0f);
if (imguiSlider("Font size", &textSize, 6.0f, 64.0f , 1.0f) )
recomputeVisibleText |= imguiSlider("Number of lines", visibleLineCount, 1.0f, 177.0f , 1.0f);
if (imguiSlider("Font size", textSize, 6.0f, 64.0f , 1.0f) )
{
fontManager->destroyFont(fontScaled);
fontScaled = fontManager->createScaledFontToPixelSize(fontSdf, (uint32_t) textSize);
@ -157,9 +157,9 @@ int _main_(int /*_argc*/, char** /*_argv*/)
recomputeVisibleText = true;
}
recomputeVisibleText |= imguiSlider("Scroll", &textScroll, 0.0f, (lineCount-visibleLineCount) , 1.0f);
imguiSlider("Rotate", &textRotation, 0.0f, (float) M_PI *2.0f , 0.1f);
recomputeVisibleText |= imguiSlider("Scale", &textScale, 0.1f, 10.0f , 0.1f);
recomputeVisibleText |= imguiSlider("Scroll", textScroll, 0.0f, (lineCount-visibleLineCount) , 1.0f);
imguiSlider("Rotate", textRotation, 0.0f, (float) M_PI *2.0f , 0.1f);
recomputeVisibleText |= imguiSlider("Scale", textScale, 0.1f, 10.0f , 0.1f);
if (recomputeVisibleText)
{

View File

@ -134,7 +134,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
}
static float distance = 2.0f;
imguiSlider("Distance", &distance, 2.0f, 6.0f, .01f);
imguiSlider("Distance", distance, 2.0f, 6.0f, .01f);
imguiEndScrollArea();
imguiEndFrame();

View File

@ -1033,10 +1033,10 @@ int _main_(int /*_argc*/, char** /*_argv*/)
}
imguiSeparatorLine();
imguiSlider("Lights", &settings_numLights, 1.0f, float(MAX_NUM_LIGHTS), 1.0f);
imguiSlider("Lights", settings_numLights, 1.0f, float(MAX_NUM_LIGHTS), 1.0f);
if (scene == StencilReflectionScene)
{
imguiSlider("Reflection value", &settings_reflectionValue, 0.0f, 1.0f, 0.01f);
imguiSlider("Reflection value", settings_reflectionValue, 0.0f, 1.0f, 0.01f);
}
if (imguiCheck("Update lights", settings_updateLights) )

View File

@ -2195,7 +2195,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
currentScene = Scene1;
}
imguiSlider("Lights", &settings_numLights, 1.0f, float(MAX_LIGHTS_COUNT), 1.0f);
imguiSlider("Lights", settings_numLights, 1.0f, float(MAX_LIGHTS_COUNT), 1.0f);
if (imguiCheck("Update lights", settings_updateLights) )
{
@ -2261,7 +2261,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
if (Scene1 == currentScene)
{
imguiSlider("Instance count", &settings_instanceCount, 1.0f, float(MAX_INSTANCE_COUNT), 1.0f);
imguiSlider("Instance count", settings_instanceCount, 1.0f, float(MAX_INSTANCE_COUNT), 1.0f);
}
imguiLabel("CPU Time: %7.1f [ms]", double(profTime)*toMs);

View File

@ -2090,7 +2090,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
#define IMGUI_FLOAT_SLIDER(_name, _val) \
imguiSlider(_name \
, &_val \
, _val \
, *(((float*)&_val)+1) \
, *(((float*)&_val)+2) \
, *(((float*)&_val)+3) \
@ -2188,26 +2188,26 @@ int _main_(int /*_argc*/, char** /*_argv*/)
if (LightType::SpotLight == settings.m_lightType)
{
imguiLabel("Spot light");
imguiSlider("Shadow map area:", &settings.m_coverageSpotL, 45.0f, 120.0f, 1.0f);
imguiSlider("Shadow map area:", settings.m_coverageSpotL, 45.0f, 120.0f, 1.0f);
imguiSeparator();
imguiSlider("Spot outer cone:", &settings.m_spotOuterAngle, 0.0f, 91.0f, 0.1f);
imguiSlider("Spot inner cone:", &settings.m_spotInnerAngle, 0.0f, 90.0f, 0.1f);
imguiSlider("Spot outer cone:", settings.m_spotOuterAngle, 0.0f, 91.0f, 0.1f);
imguiSlider("Spot inner cone:", settings.m_spotInnerAngle, 0.0f, 90.0f, 0.1f);
}
else if (LightType::PointLight == settings.m_lightType)
{
imguiLabel("Point light");
imguiBool("Stencil pack", settings.m_stencilPack);
imguiSlider("Fov X adjust:", &settings.m_fovXAdjust, -20.0f, 20.0f, 0.0001f);
imguiSlider("Fov Y adjust:", &settings.m_fovYAdjust, -20.0f, 20.0f, 0.0001f);
imguiSlider("Fov X adjust:", settings.m_fovXAdjust, -20.0f, 20.0f, 0.0001f);
imguiSlider("Fov Y adjust:", settings.m_fovYAdjust, -20.0f, 20.0f, 0.0001f);
}
else if (LightType::DirectionalLight == settings.m_lightType)
{
imguiLabel("Directional light");
imguiBool("Stabilize cascades", settings.m_stabilize);
imguiSlider("Cascade splits:", &settings.m_numSplitsf, 1.0f, 4.0f, 1.0f);
imguiSlider("Cascade distribution:", &settings.m_splitDistribution, 0.0f, 1.0f, 0.001f);
imguiSlider("Cascade splits:", settings.m_numSplitsf, 1.0f, 4.0f, 1.0f);
imguiSlider("Cascade distribution:", settings.m_splitDistribution, 0.0f, 1.0f, 0.001f);
settings.m_numSplits = uint8_t(settings.m_numSplitsf);
}

View File

@ -162,7 +162,7 @@ bool mainloop()
autoAdjust ^= true;
}
imguiSlider("Dim", &dim, 5, 40);
imguiSlider("Dim", dim, 5, 40);
imguiLabel("Draw calls: %d", dim*dim*dim);
imguiLabel("Avg Delta Time (1 second) [ms]: %0.4f", deltaTimeAvgNs/1000.0f);

View File

@ -549,7 +549,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
imguiBool("IBL Specular", settings.m_specularIbl);
imguiSeparatorLine();
imguiSlider("Speed", &settings.m_speed, 0.0f, 1.0f, 0.01f);
imguiSlider("Speed", settings.m_speed, 0.0f, 1.0f, 0.01f);
imguiSeparatorLine();
imguiLabel("Environment:");
@ -562,15 +562,15 @@ int _main_(int /*_argc*/, char** /*_argv*/)
) );
imguiSeparator();
imguiSlider("Exposure", &settings.m_exposure, -8.0f, 8.0f, 0.01f);
imguiSlider("Exposure", settings.m_exposure, -8.0f, 8.0f, 0.01f);
imguiEndScrollArea();
imguiBeginScrollArea("Settings", 10, 70, 256, 576, &leftScrollArea);
imguiLabel("Material properties:");
imguiSeparator();
imguiSlider("Diffuse - Specular", &settings.m_diffspec, 0.0f, 1.0f, 0.01f);
imguiSlider("Glossiness" , &settings.m_glossiness, 0.0f, 1.0f, 0.01f);
imguiSlider("Diffuse - Specular", settings.m_diffspec, 0.0f, 1.0f, 0.01f);
imguiSlider("Glossiness" , settings.m_glossiness, 0.0f, 1.0f, 0.01f);
imguiSeparator();
imguiColorWheel("Diffuse color:", &settings.m_rgbDiff[0], settings.m_showDiffColorWheel);

View File

@ -411,7 +411,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
imguiBeginScrollArea("Settings", width - width / 5 - 10, 10, width / 5, height / 3, &scrollArea);
imguiSeparatorLine();
imguiSlider("Num lights", &numLights, 1, 2048);
imguiSlider("Num lights", numLights, 1, 2048);
if (imguiCheck("Show G-Buffer.", showGBuffer) )
{
@ -428,7 +428,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
animateMesh = !animateMesh;
}
imguiSlider("Lights animation speed", &lightAnimationSpeed, 0.0f, 0.4f, 0.01f);
imguiSlider("Lights animation speed", lightAnimationSpeed, 0.0f, 0.4f, 0.01f);
imguiEndScrollArea();
imguiEndFrame();

View File

@ -38,6 +38,8 @@
#include "vs_imgui_texture.bin.h"
#include "fs_imgui_texture.bin.h"
#define USE_NANOVG_FONT 0
#define MAX_TEMP_COORDS 100
#define NUM_CIRCLE_VERTS (8 * 4)
@ -273,7 +275,9 @@ struct Imgui
m_invTextureHeight = 1.0f/m_textureHeight;
u_texColor.idx = bgfx::invalidHandle;
#if !USE_NANOVG_FONT
m_fontTexture.idx = bgfx::invalidHandle;
#endif // !USE_NANOVG_FONT
m_colorProgram.idx = bgfx::invalidHandle;
m_textureProgram.idx = bgfx::invalidHandle;
}
@ -281,6 +285,9 @@ struct Imgui
bool create(const void* _data)
{
m_nvg = nvgCreate(512, 512, 1, m_view);
nvgCreateFontMem(m_nvg, "default", (unsigned char*)_data, INT32_MAX, 0);
nvgFontSize(m_nvg, 15.0f);
nvgFontFace(m_nvg, "default");
for (int32_t ii = 0; ii < NUM_CIRCLE_VERTS; ++ii)
{
@ -339,9 +346,11 @@ struct Imgui
bgfx::destroyShader(vsh);
bgfx::destroyShader(fsh);
#if !USE_NANOVG_FONT
const bgfx::Memory* mem = bgfx::alloc(m_textureWidth * m_textureHeight);
stbtt_BakeFontBitmap( (uint8_t*)_data, 0, 15.0f, mem->data, m_textureWidth, m_textureHeight, 32, 96, m_cdata);
m_fontTexture = bgfx::createTexture2D(m_textureWidth, m_textureHeight, 1, bgfx::TextureFormat::R8, BGFX_TEXTURE_NONE, mem);
#endif // !USE_NANOVG_FONT
return true;
}
@ -349,7 +358,9 @@ struct Imgui
void destroy()
{
bgfx::destroyUniform(u_texColor);
#if !USE_NANOVG_FONT
bgfx::destroyTexture(m_fontTexture);
#endif // !USE_NANOVG_FONT
bgfx::destroyProgram(m_colorProgram);
bgfx::destroyProgram(m_textureProgram);
nvgDelete(m_nvg);
@ -514,9 +525,9 @@ struct Imgui
m_scrollVal = _scroll;
m_scrollAreaX = _x;
m_scrollAreaWidth = _width;
m_scrollAreaTop = m_widgetY + SCROLL_AREA_PADDING;
m_scrollAreaTop = m_widgetY;
m_focusTop = _y - AREA_HEADER;
m_focusTop = _y - AREA_HEADER;
m_focusBottom = _y - AREA_HEADER + _height;
m_insideScrollArea = inRect(_x, _y, _width, _height, false);
@ -566,7 +577,7 @@ struct Imgui
int32_t height = m_scrollBottom - m_scrollTop;
int32_t stop = m_scrollAreaTop;
int32_t sbot = m_widgetY;
int32_t sbot = m_widgetY + SCROLL_AREA_PADDING;
int32_t sh = sbot - stop; // The scrollable area height.
float barHeight = (float)height / (float)sh;
@ -914,7 +925,7 @@ struct Imgui
);
}
bool slider(const char* _text, float* _val, float _vmin, float _vmax, float _vinc, bool _enabled)
bool slider(const char* _text, float& _val, float _vmin, float _vmax, float _vinc, bool _enabled)
{
m_widgetId++;
uint32_t id = (m_areaId << 16) | m_widgetId;
@ -929,7 +940,7 @@ struct Imgui
const int32_t range = width - SLIDER_MARKER_WIDTH;
float uu = bx::fsaturate( (*_val - _vmin) / (_vmax - _vmin) );
float uu = bx::fsaturate( (_val - _vmin) / (_vmax - _vmin) );
int32_t m = (int)(uu * range);
bool over = _enabled && inRect(xx + m, yy, SLIDER_MARKER_WIDTH, SLIDER_HEIGHT);
@ -948,8 +959,8 @@ struct Imgui
{
uu = bx::fsaturate(m_dragOrig + (float)(m_mx - m_dragX) / (float)range);
*_val = _vmin + uu * (_vmax - _vmin);
*_val = floorf(*_val / _vinc + 0.5f) * _vinc; // Snap to vinc
_val = _vmin + uu * (_vmax - _vmin);
_val = floorf(_val / _vinc + 0.5f) * _vinc; // Snap to vinc
m = (int)(uu * range);
valChanged = true;
}
@ -981,7 +992,7 @@ struct Imgui
char fmt[16];
bx::snprintf(fmt, 16, "%%.%df", digits >= 0 ? 0 : -digits);
char msg[128];
bx::snprintf(msg, 128, fmt, *_val);
bx::snprintf(msg, 128, fmt, _val);
if (_enabled)
{
@ -1288,6 +1299,7 @@ struct Imgui
}
}
#if !USE_NANOVG_FONT
void getBakedQuad(stbtt_bakedchar* _chardata, int32_t char_index, float* _xpos, float* _ypos, stbtt_aligned_quad* _quad)
{
stbtt_bakedchar* b = _chardata + char_index;
@ -1344,6 +1356,7 @@ struct Imgui
return len;
}
#endif // !USE_NANOVG_FONT
void drawText(int32_t _x, int32_t _y, ImguiTextAlign::Enum _align, const char* _text, uint32_t _abgr)
{
@ -1352,11 +1365,20 @@ struct Imgui
void drawText(float _x, float _y, const char* _text, ImguiTextAlign::Enum _align, uint32_t _abgr)
{
if (!_text)
#if USE_NANOVG_FONT
static uint32_t textAlign[ImguiTextAlign::Count] =
{
return;
}
NVG_ALIGN_LEFT,
NVG_ALIGN_CENTER,
NVG_ALIGN_RIGHT,
};
nvgTextAlign(m_nvg, textAlign[_align]);
nvgFontBlur(m_nvg, 0.0f);
nvgFillColor(m_nvg, nvgRGBAu(_abgr) );
nvgText(m_nvg, _x, _y, _text, NULL);
#else
uint32_t numVertices = 0;
if (_align == ImguiTextAlign::Center)
{
@ -1457,6 +1479,7 @@ struct Imgui
bgfx::setScissor(m_scissor);
bgfx::submit(m_view);
}
#endif // USE_NANOVG_FONT
}
void colorWheelWidget(float _rgb[3], bool _respectIndentation, bool _enabled)
@ -1730,8 +1753,6 @@ struct Imgui
uint32_t m_scrollId;
bool m_insideScrollArea;
stbtt_bakedchar m_cdata[96]; // ASCII 32..126 is 95 glyphs
uint16_t m_textureWidth;
uint16_t m_textureHeight;
float m_invTextureWidth;
@ -1742,9 +1763,13 @@ struct Imgui
uint8_t m_view;
bgfx::UniformHandle u_texColor;
bgfx::TextureHandle m_fontTexture;
bgfx::ProgramHandle m_colorProgram;
bgfx::ProgramHandle m_textureProgram;
#if !USE_NANOVG_FONT
stbtt_bakedchar m_cdata[96]; // ASCII 32..126 is 95 glyphs
bgfx::TextureHandle m_fontTexture;
#endif // !USE_NANOVG_FONT
};
static Imgui s_imgui;
@ -1832,16 +1857,16 @@ void imguiValue(const char* _text)
s_imgui.value(_text);
}
bool imguiSlider(const char* _text, float* _val, float _vmin, float _vmax, float _vinc, bool _enabled)
bool imguiSlider(const char* _text, float& _val, float _vmin, float _vmax, float _vinc, bool _enabled)
{
return s_imgui.slider(_text, _val, _vmin, _vmax, _vinc, _enabled);
}
bool imguiSlider(const char* _text, int32_t* _val, int32_t _vmin, int32_t _vmax, bool _enabled)
bool imguiSlider(const char* _text, int32_t& _val, int32_t _vmin, int32_t _vmax, bool _enabled)
{
float val = (float)*_val;
bool result = s_imgui.slider(_text, &val, (float)_vmin, (float)_vmax, 1.0f, _enabled);
*_val = (int32_t)val;
float val = (float)_val;
bool result = s_imgui.slider(_text, val, (float)_vmin, (float)_vmax, 1.0f, _enabled);
_val = (int32_t)val;
return result;
}

View File

@ -38,6 +38,8 @@ struct ImguiTextAlign
Left,
Center,
Right,
Count
};
};
@ -71,8 +73,8 @@ 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 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);
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);
uint32_t imguiChooseUseMacroInstead(uint32_t _selected, ...);
#define imguiChoose(...) imguiChooseUseMacroInstead(__VA_ARGS__, NULL)

View File

@ -300,6 +300,17 @@ struct NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsig
return color;
}
struct NVGcolor nvgRGBAu(unsigned int abgr)
{
struct NVGcolor color;
// Use longer initialization to suppress warning.
color.r = ( (abgr>> 0)&0xff) / 255.0f;
color.g = ( (abgr>> 8)&0xff) / 255.0f;
color.b = ( (abgr>>16)&0xff) / 255.0f;
color.a = ( (abgr>>24)&0xff) / 255.0f;
return color;
}
struct NVGcolor nvgRGBAf(float r, float g, float b, float a)
{
struct NVGcolor color;

View File

@ -133,6 +133,9 @@ struct NVGcolor nvgRGBf(float r, float g, float b);
// Returns a color value from red, green, blue and alpha values.
struct NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
//
struct NVGcolor nvgRGBAu(unsigned int abgr);
// Returns a color value from red, green, blue and alpha values.
struct NVGcolor nvgRGBAf(float r, float g, float b, float a);