Skip to content

Commit

Permalink
added RangeSlider and other widgets from here:
Browse files Browse the repository at this point in the history
ocornut/imgui#76
Taken from: wasikuss/imgui@a50515a

needed SliderBehaviorCalcRatioFromValue() added to imgui.cpp to compile

added timeline and curveeditor widgets from imgui_user files from here:
https://github.com/nem0/LumixEngine/tree/master/external/imgui
  • Loading branch information
Glenn Silver committed Mar 5, 2017
1 parent b0d3806 commit 98222cc
Show file tree
Hide file tree
Showing 18 changed files with 5,055 additions and 0 deletions.
88 changes: 88 additions & 0 deletions libs/imgui/src/imconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//-----------------------------------------------------------------------------
// USER IMPLEMENTATION
// This file contains compile-time options for ImGui.
// Other options (memory allocation overrides, callbacks, etc.) can be set at runtime via the ImGuiIO structure - ImGui::GetIO().
//-----------------------------------------------------------------------------

#pragma once

//---- Define assertion handler. Defaults to calling assert().
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)

//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows.
//#define IMGUI_API __declspec( dllexport )
//#define IMGUI_API __declspec( dllimport )

//---- Include imgui_user.inl at the end of imgui.cpp so you can include code that extends ImGui using its private data/functions.
#define IMGUI_INCLUDE_IMGUI_USER_INL

//---- Include imgui_user.h at the end of imgui.h
#define IMGUI_INCLUDE_IMGUI_USER_H

//---- Don't implement default handlers for Windows (so as not to link with OpenClipboard() and others Win32 functions)
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS

//---- Don't implement help and test window functionality (ShowUserGuide()/ShowStyleEditor()/ShowTestWindow() methods will be empty)
//#define IMGUI_DISABLE_TEST_WINDOWS

//---- Don't define obsolete functions names
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS

//---- Implement STB libraries in a namespace to avoid conflicts
//#define IMGUI_STB_NAMESPACE ImGuiStb

//---- Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4.

#include "ofVectorMath.h"
#include "ofColor.h"

#if OF_VERSION_MINOR >= 10
#define IM_VEC2_CLASS_EXTRA \
ImVec2(const ofVec2f& f) { x = f.x; y = f.y; } \
operator ofVec2f() const { return ofVec2f(x, y); } \
ImVec2(const glm::vec2& f) { x = f.x; y = f.y; } \
operator glm::vec2() const { return glm::vec2(x, y); }
#else
#define IM_VEC2_CLASS_EXTRA \
ImVec2(const ofVec2f& f) { x = f.x; y = f.y; } \
operator ofVec2f() const { return ofVec2f(x, y); }
#endif

#if OF_VERSION_MINOR >= 10
#define IM_VEC4_CLASS_EXTRA \
ImVec4(const ofVec4f& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
operator ofVec4f() const { return ofVec4f(x,y,z,w); } \
ImVec4(const glm::vec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
operator glm::vec4() const { return glm::vec4(x,y,z,w); } \
ImVec4(ofColor& color, float alpha) { static const float sc = 1.0f/255.0f; x = color.r*sc; y = color.g*sc; z = color.b*sc; w = alpha; } \
ImVec4(const ofColor& f) { static const float sc = 1.0f/255.0f; x = f.r*sc; y = f.g*sc; z = f.b*sc; w = f.a*sc; } \
operator ofColor() const { return ofColor((int) (x*255.0f+0.5f), (int) (y*255.0f+0.5f), (int) (z*255.0f+0.5f), (int) (w*255.0f+0.5f)); } \
ImVec4(ofFloatColor& color, float alpha) { x = color.r; y = color.g; z = color.b; w = alpha; } \
ImVec4(const ofFloatColor& f) { x = f.r; y = f.g; z = f.b; w = f.a; } \
operator ofFloatColor() const { return ofFloatColor(x, y, z, w); }
#else
#define IM_VEC4_CLASS_EXTRA \
ImVec4(const ofVec4f& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
operator ofVec4f() const { return ofVec4f(x,y,z,w); } \
ImVec4(ofColor& color, float alpha) { static const float sc = 1.0f/255.0f; x = color.r*sc; y = color.g*sc; z = color.b*sc; w = alpha; } \
ImVec4(const ofColor& f) { static const float sc = 1.0f/255.0f; x = f.r*sc; y = f.g*sc; z = f.b*sc; w = f.a*sc; } \
operator ofColor() const { return ofColor((int) (x*255.0f+0.5f), (int) (y*255.0f+0.5f), (int) (z*255.0f+0.5f), (int) (w*255.0f+0.5f)); } \
ImVec4(ofFloatColor& color, float alpha) { x = color.r; y = color.g; z = color.b; w = alpha; } \
ImVec4(const ofFloatColor& f) { x = f.r; y = f.g; z = f.b; w = f.a; } \
operator ofFloatColor() const { return ofFloatColor(x, y, z, w); }
#endif

#define ImDrawIdx ofIndexType

//---- Freely implement extra functions within the ImGui:: namespace.
//---- Declare helpers or widgets implemented in imgui_user.inl or elsewhere, so end-user doesn't need to include multiple files.
//---- e.g. you can create variants of the ImGui::Value() helper for your low-level math types, or your own widgets/helpers.
/*
namespace ImGui
{
void Value(const char* prefix, const MyVec2& v, const char* float_format = NULL);
void Value(const char* prefix, const MyVec4& v, const char* float_format = NULL);
}
*/

26 changes: 26 additions & 0 deletions libs/imgui/src/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6344,6 +6344,32 @@ float ImGui::RoundScalar(float value, int decimal_precision)
return negative ? -value : value;
}

static inline float SliderBehaviorCalcRatioFromValue(float v, float v_min, float v_max, float power, float linear_zero_pos)
{
if (v_min == v_max)
return 0.0f;

const bool is_non_linear = (power < 1.0f-0.00001f) || (power > 1.0f+0.00001f);
const float v_clamped = (v_min < v_max) ? ImClamp(v, v_min, v_max) : ImClamp(v, v_max, v_min);
if (is_non_linear)
{
if (v_clamped < 0.0f)
{
const float f = 1.0f - (v_clamped - v_min) / (ImMin(0.0f,v_max) - v_min);
return (1.0f - powf(f, 1.0f/power)) * linear_zero_pos;
}
else
{
const float f = (v_clamped - ImMax(0.0f,v_min)) / (v_max - ImMax(0.0f,v_min));
return linear_zero_pos + powf(f, 1.0f/power) * (1.0f - linear_zero_pos);
}
}

// Linear slider
return (v_clamped - v_min) / (v_max - v_min);
}


bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, ImGuiSliderFlags flags)
{
ImGuiContext& g = *GImGui;
Expand Down
51 changes: 51 additions & 0 deletions libs/imgui/src/imgui_user.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <stdint.h>
#include <inttypes.h>

namespace ImGui
{
struct Font
{
enum Enum
{
Regular,
Mono,

Count
};
};

void PushFont(Font::Enum _font);

// BK - simple string class for convenience.
class ImString
{
public:
ImString();
ImString(const ImString& rhs);
ImString(const char* rhs);
~ImString();

ImString& operator=(const ImString& rhs);
ImString& operator=(const char* rhs);

void Clear();
bool IsEmpty() const;

const char* CStr() const
{
return NULL == Ptr ? "" : Ptr;
}

private:
char* Ptr;
};

} // namespace ImGui

#include "widgets/color_picker.h"
#include "widgets/dock.h"
#include "widgets/file_list.h"
#include "widgets/gizmo.h"
#include "widgets/memory_editor.h"
#include "widgets/range_slider.h"
#include "widgets/timeline.h"
80 changes: 80 additions & 0 deletions libs/imgui/src/imgui_user.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
namespace ImGui
{
ImString::ImString()
: Ptr(NULL)
{
}

ImString::ImString(const ImString& rhs)
: Ptr(NULL)
{
if (NULL != rhs.Ptr
&& 0 != strcmp(rhs.Ptr, ""))
{
Ptr = ImStrdup(rhs.Ptr);
}
}

ImString::ImString(const char* rhs)
: Ptr(NULL)
{
if (NULL != rhs
&& 0 != strcmp(rhs, ""))
{
Ptr = ImStrdup(rhs);
}
}

ImString::~ImString()
{
Clear();
}

ImString& ImString::operator=(const ImString& rhs)
{
if (this != &rhs)
{
*this = rhs.Ptr;
}

return *this;
}

ImString& ImString::operator=(const char* rhs)
{
if (Ptr != rhs)
{
Clear();

if (NULL != rhs
&& 0 != strcmp(rhs, ""))
{
Ptr = ImStrdup(rhs);
}
}

return *this;
}

void ImString::Clear()
{
if (NULL != Ptr)
{
MemFree(Ptr);
Ptr = NULL;
}
}

bool ImString::IsEmpty() const
{
return NULL == Ptr;
}
} // namespace

#include "widgets/color_picker.inl"
#include "widgets/dock.inl"
#include "widgets/file_list.inl"
#include "widgets/gizmo.inl"
#include "widgets/memory_editor.inl"
#include "widgets/range_slider.inl"
#include "widgets/timeline.inl"
24 changes: 24 additions & 0 deletions libs/imgui/src/widgets/color_picker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace ImGui
{
bool ColorPicker4(float* col, bool show_alpha);
bool ColorPicker3(float col[3]);

inline bool ColorEdit4(const char* label, uint32_t* _rgba, bool show_alpha = true)
{
uint8_t* rgba = (uint8_t*)_rgba;
float col[4] =
{
rgba[0]/255.0f,
rgba[1]/255.0f,
rgba[2]/255.0f,
rgba[3]/255.0f,
};
bool result = ColorEdit4(label, col, show_alpha);
rgba[0] = uint8_t(col[0]*255.0f);
rgba[1] = uint8_t(col[1]*255.0f);
rgba[2] = uint8_t(col[2]*255.0f);
rgba[3] = uint8_t(col[3]*255.0f);
return result;
}

} // namespace ImGui
Loading

0 comments on commit 98222cc

Please sign in to comment.