Skip to content

Commit

Permalink
refactor: imgui, implot, imnodes context creation moved to dpg context (
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Nov 3, 2021
1 parent 5580f4d commit a68b849
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 71 deletions.
30 changes: 5 additions & 25 deletions DearPyGui/src/core/AppItems/colors/mvColorMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace Marvel {
args.push_back({ mvPyDataType::Float, "t", mvArgType::REQUIRED_ARG, "", "Value of the colormap to sample between 0.0-1.0" });

mvPythonParserSetup setup;
setup.about = "Returns a color from a colormap given t between 0.0-1.0. This command can only be ran once the app is started.";
setup.about = "Returns a color from a colormap given t between 0.0-1.0.";
setup.category = { "Widget Operations" };
setup.returnType = mvPyDataType::IntList;

Expand All @@ -73,7 +73,7 @@ namespace Marvel {
args.push_back({ mvPyDataType::Integer, "index", mvArgType::REQUIRED_ARG, "", "Desired position of the color in the colors list value of the colormap being quiered " });

mvPythonParserSetup setup;
setup.about = "Returns a color from a colormap given an index >= 0. (ex. 0 will be the first color in the color list of the color map) Modulo will be performed against the number of items in the color list. This command can only be ran once the app is started.";
setup.about = "Returns a color from a colormap given an index >= 0. (ex. 0 will be the first color in the color list of the color map) Modulo will be performed against the number of items in the color list.";
setup.category = { "Widget Operations" };
setup.returnType = mvPyDataType::IntList;

Expand All @@ -85,12 +85,7 @@ namespace Marvel {

mvColorMap::mvColorMap(mvUUID uuid)
: mvAppItem(uuid)
{
_triggerAlternativeAction = true;

// since the implot context may not have been created
static ImPlotColormap startmap = 16;
_colorMap = startmap++;
{
}

void mvColorMap::applySpecificTemplate(mvAppItem* item)
Expand Down Expand Up @@ -139,6 +134,8 @@ namespace Marvel {
break;
}
}

_colorMap = ImPlot::AddColormap(_internalLabel.c_str(), _colors.data(), (int)_colors.size(), _qualitative);
}

void mvColorMap::draw(ImDrawList* drawlist, float x, float y)
Expand All @@ -148,17 +145,6 @@ namespace Marvel {
ImPlot::ColormapButton(_internalLabel.c_str(), ImVec2(-1.0f, 0.0f), _colorMap);
}

void mvColorMap::alternativeCustomAction(void* data)
{
if (_created)
return;

_colorMap = ImPlot::AddColormap(_internalLabel.c_str(), _colors.data(), (int)_colors.size(), _qualitative);
_created = true;

_triggerAlternativeAction = false;
}

PyObject* mvColorMap::bind_colormap(PyObject* self, PyObject* args, PyObject* kwargs)
{
PyObject* itemraw;
Expand Down Expand Up @@ -281,12 +267,6 @@ namespace Marvel {
if (!Parse((GetParsers())["get_colormap_color"], args, kwargs, __FUNCTION__, &itemraw, &index))
return GetPyNone();

if(!GContext->started)
{
mvThrowPythonError(mvErrorCode::mvNone, "get_colormap_color", "This command can only be ran once the app is started.", nullptr);
return GetPyNone();
}

if (!GContext->manualMutexControl) std::lock_guard<std::mutex> lk(GContext->mutex);

mvUUID item = GetIDFromPyObject(itemraw);
Expand Down
3 changes: 0 additions & 3 deletions DearPyGui/src/core/AppItems/colors/mvColorMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ namespace Marvel {

void draw(ImDrawList* drawlist, float x, float y) override;
void handleSpecificRequiredArgs(PyObject* args) override;
void alternativeCustomAction(void* data = nullptr) override;
void applySpecificTemplate(mvAppItem* item) override;
ImPlotColormap getColorMap() const { return _colorMap; }

Expand All @@ -91,8 +90,6 @@ namespace Marvel {
ImPlotColormap _colorMap = -1;
bool _qualitative = true;
std::vector<ImVec4> _colors;
bool _created = false;

};

}
13 changes: 0 additions & 13 deletions DearPyGui/src/core/AppItems/colors/mvColorMapRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,4 @@ namespace Marvel {
ImGui::PopID();

}

void mvColorMapRegistry::alternativeCustomAction(void* data)
{
for (auto& item : _children[1])
item->alternativeCustomAction();

_triggerAlternativeAction = false;
}

void mvColorMapRegistry::onChildAdd(mvRef<mvAppItem> item)
{
_triggerAlternativeAction = true;
}
}
2 changes: 0 additions & 2 deletions DearPyGui/src/core/AppItems/colors/mvColorMapRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ namespace Marvel {
explicit mvColorMapRegistry(mvUUID uuid);

void draw(ImDrawList* drawlist, float x, float y) override;
void onChildAdd(mvRef<mvAppItem> item) override;
void alternativeCustomAction(void* data = nullptr) override;

};

Expand Down
4 changes: 0 additions & 4 deletions DearPyGui/src/core/AppItems/mvItemRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1404,11 +1404,7 @@ namespace Marvel {
}

for (auto& root : registry.colormapRoots)
{
if (root->_triggerAlternativeAction)
root->alternativeCustomAction();
root->draw(nullptr, 0.0f, 0.0f);
}

for (auto& root : registry.windowRoots)
root->draw(nullptr, 0.0f, 0.0f);
Expand Down
9 changes: 9 additions & 0 deletions DearPyGui/src/core/mvContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ namespace Marvel {

GContext->itemRegistry = new mvItemRegistry();
GContext->callbackRegistry = new mvCallbackRegistry();

IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImPlot::CreateContext();
imnodes::CreateContext();
}

mv_internal void
Expand All @@ -116,6 +121,10 @@ namespace Marvel {
return;
}

imnodes::DestroyContext();
ImPlot::DestroyContext();
ImGui::DestroyContext();

mvToolManager::Reset();
ClearItemRegistry(*GContext->itemRegistry);

Expand Down
8 changes: 0 additions & 8 deletions DearPyGui/src/platform/Apple/mvViewport.mm
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@
// Cleanup
ImGui_ImplMetal_Shutdown();
ImGui_ImplGlfw_Shutdown();
imnodes::DestroyContext();
ImPlot::DestroyContext();
ImGui::DestroyContext();

glfwDestroyWindow(ghandle);
glfwTerminate();
Expand Down Expand Up @@ -102,11 +99,6 @@
gdevice = MTLCreateSystemDefaultDevice();
gcommandQueue = [gdevice newCommandQueue];

// Setup Dear ImGui binding
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImPlot::CreateContext();
imnodes::CreateContext();
ImGuiIO &io = ImGui::GetIO();
io.ConfigWindowsMoveFromTitleBarOnly = true;

Expand Down
7 changes: 0 additions & 7 deletions DearPyGui/src/platform/Linux/mvViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ namespace Marvel {
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
imnodes::DestroyContext();
ImGui::DestroyContext();

glfwDestroyWindow(ghandle);
glfwTerminate();
Expand Down Expand Up @@ -202,11 +200,6 @@ namespace Marvel {

gl3wInit();

// Setup Dear ImGui binding
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImPlot::CreateContext();
imnodes::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigWindowsMoveFromTitleBarOnly = true;

Expand Down
9 changes: 0 additions & 9 deletions DearPyGui/src/platform/Windows/mvViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,6 @@ namespace Marvel {
if (viewport->alwaysOnTop)
SetWindowPos(ghandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);

// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImPlot::CreateContext();
imnodes::CreateContext();

ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigWindowsMoveFromTitleBarOnly = true;
if (GContext->IO.loadIniFile)
Expand Down Expand Up @@ -532,9 +526,6 @@ namespace Marvel {
// Cleanup
ImGui_ImplDX11_Shutdown();
ImGui_ImplWin32_Shutdown();
imnodes::DestroyContext();
ImPlot::DestroyContext();
ImGui::DestroyContext();

mvCleanupDeviceD3D();
::DestroyWindow(ghandle);
Expand Down

0 comments on commit a68b849

Please sign in to comment.