Skip to content

Commit 73cf7f1

Browse files
committed
added last changes from original repo
1 parent 9175447 commit 73cf7f1

File tree

6 files changed

+164
-53
lines changed

6 files changed

+164
-53
lines changed

src/BaseEngine.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ namespace ofxImGui
2020
unsigned int BaseEngine::g_VaoHandle = 0;
2121
unsigned int BaseEngine::g_ElementsHandle = 0;
2222

23+
std::string BaseEngine::g_ClipboardText = "";
24+
2325
//--------------------------------------------------------------
2426
void BaseEngine::onKeyPressed(ofKeyEventArgs& event)
2527
{
@@ -72,15 +74,16 @@ namespace ofxImGui
7274
const char* BaseEngine::getClipboardString(void * userData)
7375
{
7476
//return &ofGetWindowPtr()->getClipboardString()[0];
75-
static std::string clip;
76-
clip = ofGetWindowPtr()->getClipboardString();
77-
return clip.c_str();
77+
g_ClipboardText = ofGetWindowPtr()->getClipboardString();
78+
return g_ClipboardText.c_str();
7879
}
7980

8081
//--------------------------------------------------------------
8182
void BaseEngine::setClipboardString(void * userData, const char * text)
8283
{
83-
ofGetWindowPtr()->setClipboardString(text);
84+
ofGetWindowPtr()->setClipboardString(text);
85+
g_ClipboardText = ofToString(text);
86+
ofGetWindowPtr()->setClipboardString(g_ClipboardText);
8487
}
8588

8689
//--------------------------------------------------------------

src/BaseEngine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ namespace ofxImGui
5151
static unsigned int g_VaoHandle;
5252
static unsigned int g_ElementsHandle;
5353

54+
static std::string g_ClipboardText;
55+
5456
bool mousePressed[5] = { false };
5557

5658
protected:

src/Gui.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -183,25 +183,16 @@ namespace ofxImGui
183183
if(!autoDraw && isRenderingManualFrame) return;
184184

185185
ImGui::SetCurrentContext(context);
186-
ImGuiIO& io = ImGui::GetIO();
186+
ImGuiIO& io = ImGui::GetIO();
187187

188-
float currentTime = ofGetElapsedTimef();
189-
if (lastTime > 0.f)
190-
{
191-
io.DeltaTime = currentTime - lastTime;
192-
}
193-
else
194-
{
195-
io.DeltaTime = 1.0f / 60.f;
196-
}
197-
lastTime = currentTime;
188+
io.DeltaTime = ofGetLastFrameTime();
198189

199-
// Update settings
200-
io.MousePos = ImVec2((float)ofGetMouseX(), (float)ofGetMouseY());
201-
for (int i = 0; i < 5; i++) {
202-
io.MouseDown[i] = engine.mousePressed[i];
203-
}
204-
ImGui::NewFrame();
190+
// Update settings
191+
io.MousePos = ImVec2((float)ofGetMouseX(), (float)ofGetMouseY());
192+
for (int i = 0; i < 5; i++) {
193+
io.MouseDown[i] = engine.mousePressed[i];
194+
}
195+
ImGui::NewFrame();
205196
isRenderingManualFrame = true;
206197
}
207198

src/Helpers.cpp renamed to src/ImHelpers.cpp

Lines changed: 108 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "Helpers.h"
1+
#include "ImHelpers.h"
22

33
//--------------------------------------------------------------
44
ofxImGui::Settings::Settings()
@@ -74,7 +74,7 @@ bool ofxImGui::BeginWindow(const std::string& name, Settings& settings, bool col
7474

7575
ImGui::SetNextWindowPos(settings.windowPos, settings.lockPosition? ImGuiCond_Always : ImGuiCond_Appearing);
7676
ImGui::SetNextWindowSize(settings.windowSize, ImGuiCond_Appearing);
77-
ImGui::SetNextWindowCollapsed(collapse, ImGuiCond_Appearing);
77+
//ImGui::SetNextWindowCollapsed(collapse, ImGuiCond_Appearing);
7878
return ImGui::Begin(name.c_str(), open, ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize | (collapse ? 0 : ImGuiWindowFlags_NoCollapse));
7979
}
8080

@@ -165,7 +165,7 @@ bool ofxImGui::BeginTree(const std::string& name, Settings& settings)
165165
void ofxImGui::EndTree(Settings& settings)
166166
{
167167
ImGui::TreePop();
168-
168+
169169
settings.treeLevel = std::max(0, settings.treeLevel - 1);
170170

171171
// Clear the list of names from the stack.
@@ -439,9 +439,9 @@ bool ofxImGui::AddParameter(ofParameter<std::string>& parameter, size_t maxChars
439439
}
440440

441441
//--------------------------------------------------------------
442-
bool ofxImGui::AddParameter(ofParameter<void>& parameter)
442+
bool ofxImGui::AddParameter(ofParameter<void>& parameter, float width)
443443
{
444-
if (ImGui::Button(GetUniqueName(parameter)))
444+
if (ImGui::Button(GetUniqueName(parameter), glm::vec2(width, 0.0f)))
445445
{
446446
parameter.trigger();
447447
return true;
@@ -516,6 +516,18 @@ bool ofxImGui::AddStepper(ofParameter<int>& parameter, int step, int stepFast)
516516
return false;
517517
}
518518

519+
//--------------------------------------------------------------
520+
bool ofxImGui::AddSlider(ofParameter<float>& parameter, const char* format, float power)
521+
{
522+
auto tmpRef = parameter.get();
523+
if (ImGui::SliderFloat(GetUniqueName(parameter), (float*)&tmpRef, parameter.getMin(), parameter.getMax(), format, power))
524+
{
525+
parameter.set(tmpRef);
526+
return true;
527+
}
528+
return false;
529+
}
530+
519531
//--------------------------------------------------------------
520532
bool ofxImGui::AddRange(const std::string& name, ofParameter<int>& parameterMin, ofParameter<int>& parameterMax, int speed)
521533
{
@@ -638,7 +650,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<glm::tvec2<int>>&
638650
for (size_t i = 0; i < values.size(); ++i)
639651
{
640652
const auto iname = name + " " + ofToString(i);
641-
result |= ImGui::SliderInt2(GetUniqueName(iname), glm::value_ptr(values[i]), minValue, maxValue);
653+
if (minValue == 0 && maxValue == 0)
654+
{
655+
result |= ImGui::DragInt2(GetUniqueName(iname), glm::value_ptr(values[i]));
656+
}
657+
else
658+
{
659+
result |= ImGui::SliderInt2(GetUniqueName(iname), glm::value_ptr(values[i]), minValue, maxValue);
660+
}
642661
}
643662
return result;
644663
}
@@ -650,7 +669,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<glm::tvec3<int>>&
650669
for (size_t i = 0; i < values.size(); ++i)
651670
{
652671
const auto iname = name + " " + ofToString(i);
653-
result |= ImGui::SliderInt3(GetUniqueName(iname), glm::value_ptr(values[i]), minValue, maxValue);
672+
if (minValue == 0 && maxValue == 0)
673+
{
674+
result |= ImGui::DragInt3(GetUniqueName(iname), glm::value_ptr(values[i]));
675+
}
676+
else
677+
{
678+
result |= ImGui::SliderInt3(GetUniqueName(iname), glm::value_ptr(values[i]), minValue, maxValue);
679+
}
654680
}
655681
return result;
656682
}
@@ -662,7 +688,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<glm::tvec4<int>>&
662688
for (size_t i = 0; i < values.size(); ++i)
663689
{
664690
const auto iname = name + " " + ofToString(i);
665-
result |= ImGui::SliderInt4(GetUniqueName(iname), glm::value_ptr(values[i]), minValue, maxValue);
691+
if (minValue == 0 && maxValue == 0)
692+
{
693+
result |= ImGui::DragInt4(GetUniqueName(iname), glm::value_ptr(values[i]));
694+
}
695+
else
696+
{
697+
result |= ImGui::SliderInt4(GetUniqueName(iname), glm::value_ptr(values[i]), minValue, maxValue);
698+
}
666699
}
667700
return result;
668701
}
@@ -674,7 +707,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<glm::vec2>& values
674707
for (size_t i = 0; i < values.size(); ++i)
675708
{
676709
const auto iname = name + " " + ofToString(i);
677-
result |= ImGui::SliderFloat2(GetUniqueName(iname), glm::value_ptr(values[i]), minValue, maxValue);
710+
if (minValue == 0 && maxValue == 0)
711+
{
712+
result |= ImGui::DragFloat2(GetUniqueName(iname), glm::value_ptr(values[i]));
713+
}
714+
else
715+
{
716+
result |= ImGui::SliderFloat2(GetUniqueName(iname), glm::value_ptr(values[i]), minValue, maxValue);
717+
}
678718
}
679719
return result;
680720
}
@@ -686,7 +726,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<glm::vec3>& values
686726
for (size_t i = 0; i < values.size(); ++i)
687727
{
688728
const auto iname = name + " " + ofToString(i);
689-
result |= ImGui::SliderFloat3(GetUniqueName(iname), glm::value_ptr(values[i]), minValue, maxValue);
729+
if (minValue == 0 && maxValue == 0)
730+
{
731+
result |= ImGui::DragFloat3(GetUniqueName(iname), glm::value_ptr(values[i]));
732+
}
733+
else
734+
{
735+
result |= ImGui::SliderFloat3(GetUniqueName(iname), glm::value_ptr(values[i]), minValue, maxValue);
736+
}
690737
}
691738
return result;
692739
}
@@ -698,7 +745,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<glm::vec4>& values
698745
for (size_t i = 0; i < values.size(); ++i)
699746
{
700747
const auto iname = name + " " + ofToString(i);
701-
result |= ImGui::SliderFloat4(GetUniqueName(iname), glm::value_ptr(values[i]), minValue, maxValue);
748+
if (minValue == 0 && maxValue == 0)
749+
{
750+
result |= ImGui::DragFloat4(GetUniqueName(iname), glm::value_ptr(values[i]));
751+
}
752+
else
753+
{
754+
result |= ImGui::SliderFloat4(GetUniqueName(iname), glm::value_ptr(values[i]), minValue, maxValue);
755+
}
702756
}
703757
return result;
704758
}
@@ -712,7 +766,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<ofVec2f>& values,
712766
for (size_t i = 0; i < values.size(); ++i)
713767
{
714768
const auto iname = name + " " + ofToString(i);
715-
result |= ImGui::SliderFloat2(GetUniqueName(iname), values[i].getPtr(), minValue, maxValue);
769+
if (minValue == 0 && maxValue == 0)
770+
{
771+
result |= ImGui::DragFloat2(GetUniqueName(iname), values[i].getPtr());
772+
}
773+
else
774+
{
775+
result |= ImGui::SliderFloat2(GetUniqueName(iname), values[i].getPtr(), minValue, maxValue);
776+
}
716777
}
717778
return result;
718779
}
@@ -724,7 +785,14 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<ofVec3f>& values,
724785
for (size_t i = 0; i < values.size(); ++i)
725786
{
726787
const auto iname = name + " " + ofToString(i);
727-
result |= ImGui::SliderFloat3(GetUniqueName(iname), values[i].getPtr(), minValue, maxValue);
788+
if (minValue == 0 && maxValue == 0)
789+
{
790+
result |= ImGui::DragFloat3(GetUniqueName(iname), values[i].getPtr());
791+
}
792+
else
793+
{
794+
result |= ImGui::SliderFloat3(GetUniqueName(iname), values[i].getPtr(), minValue, maxValue);
795+
}
728796
}
729797
return result;
730798
}
@@ -736,24 +804,48 @@ bool ofxImGui::AddValues(const std::string& name, std::vector<ofVec4f>& values,
736804
for (size_t i = 0; i < values.size(); ++i)
737805
{
738806
const auto iname = name + " " + ofToString(i);
739-
result |= ImGui::SliderFloat4(GetUniqueName(iname), values[i].getPtr(), minValue, maxValue);
807+
if (minValue == 0 && maxValue == 0)
808+
{
809+
result |= ImGui::DragFloat4(GetUniqueName(iname), values[i].getPtr());
810+
}
811+
else
812+
{
813+
result |= ImGui::SliderFloat4(GetUniqueName(iname), values[i].getPtr(), minValue, maxValue);
814+
}
740815
}
741816
return result;
742817
}
743818

744819
//--------------------------------------------------------------
745-
void ofxImGui::AddImage(ofBaseHasTexture& hasTexture, const ofVec2f& size)
820+
void ofxImGui::AddImage(const ofBaseHasTexture& hasTexture, const ofVec2f& size)
746821
{
747822
ofxImGui::AddImage(hasTexture.getTexture(), size);
748823
}
749824

750825
//--------------------------------------------------------------
751-
void ofxImGui::AddImage(ofTexture& texture, const ofVec2f& size)
826+
void ofxImGui::AddImage(const ofTexture& texture, const ofVec2f& size)
752827
{
753828
ImTextureID textureID = GetImTextureID(texture);
754829
ImGui::Image(textureID, size);
755830
}
756831

832+
#if OF_VERSION_MINOR >= 10
833+
834+
//--------------------------------------------------------------
835+
void ofxImGui::AddImage(const ofBaseHasTexture& hasTexture, const glm::vec2& size)
836+
{
837+
ofxImGui::AddImage(hasTexture.getTexture(), size);
838+
}
839+
840+
//--------------------------------------------------------------
841+
void ofxImGui::AddImage(const ofTexture& texture, const glm::vec2& size)
842+
{
843+
ImTextureID textureID = GetImTextureID(texture);
844+
ImGui::Image(textureID, size);
845+
}
846+
847+
#endif
848+
757849

758850
static auto vector_getter = [](void* vec, int idx, const char** out_text)
759851
{
@@ -776,4 +868,3 @@ bool ofxImGui::VectorListBox(const char* label, int* currIndex, std::vector<std:
776868
return ImGui::ListBox(label, currIndex, vector_getter,
777869
static_cast<void*>(&values), values.size());
778870
}
779-

0 commit comments

Comments
 (0)