diff --git a/src/dearpygui_commands.h b/src/dearpygui_commands.h index b707e24b6..4c4a755bf 100644 --- a/src/dearpygui_commands.h +++ b/src/dearpygui_commands.h @@ -21,7 +21,7 @@ bind_colormap(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["bind_colormap"], args, kwargs, __FUNCTION__, &itemraw, &sourceraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); mvUUID source = GetIDFromPyObject(sourceraw); @@ -97,7 +97,7 @@ sample_colormap(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["sample_colormap"], args, kwargs, __FUNCTION__, &itemraw, &t)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -139,7 +139,7 @@ get_colormap_color(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["get_colormap_color"], args, kwargs, __FUNCTION__, &itemraw, &index)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -174,7 +174,7 @@ get_file_dialog_info(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["get_file_dialog_info"], args, kwargs, __FUNCTION__, &file_dialog_raw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID file_dialog = GetIDFromPyObject(file_dialog_raw); @@ -207,7 +207,7 @@ set_x_scroll(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw, &value)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -253,7 +253,7 @@ set_y_scroll(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw, &value)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -298,7 +298,7 @@ get_x_scroll(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -342,7 +342,7 @@ get_y_scroll(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -386,7 +386,7 @@ get_x_scroll_max(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -430,7 +430,7 @@ get_y_scroll_max(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -479,7 +479,7 @@ set_clip_space(PyObject* self, PyObject* args, PyObject* kwargs) &topleftx, &toplefty, &width, &height, &mindepth, &maxdepth)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -529,7 +529,7 @@ apply_transform(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["apply_transform"], args, kwargs, __FUNCTION__, &itemraw, &transform)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -570,7 +570,7 @@ create_rotation_matrix(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["create_rotation_matrix"], args, kwargs, __FUNCTION__, &angle, &axis)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvVec4 aaxis = ToVec4(axis); @@ -596,7 +596,7 @@ create_perspective_matrix(PyObject* self, PyObject* args, PyObject* kwargs) &fov, &aspect, &zNear, &zFar)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); PyObject* newbuffer = nullptr; PymvMat4* newbufferview = nullptr; @@ -622,7 +622,7 @@ create_orthographic_matrix(PyObject* self, PyObject* args, PyObject* kwargs) &left, &right, &bottom, &top, &zNear, &zFar)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); PyObject* newbuffer = nullptr; PymvMat4* newbufferview = nullptr; @@ -643,7 +643,7 @@ create_translation_matrix(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["create_translation_matrix"], args, kwargs, __FUNCTION__, &axis)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvVec4 aaxis = ToVec4(axis); @@ -666,7 +666,7 @@ create_scale_matrix(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["create_scale_matrix"], args, kwargs, __FUNCTION__, &axis)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvVec4 aaxis = ToVec4(axis); @@ -692,7 +692,7 @@ create_lookat_matrix(PyObject* self, PyObject* args, PyObject* kwargs) &eye, ¢er, &up)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvVec4 aeye = ToVec4(eye); mvVec4 acenter = ToVec4(center); @@ -720,7 +720,7 @@ create_fps_matrix(PyObject* self, PyObject* args, PyObject* kwargs) &eye, &pitch, &yaw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvVec4 aeye = ToVec4(eye); PyObject* newbuffer = nullptr; @@ -743,7 +743,7 @@ bind_font(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -789,7 +789,7 @@ get_text_size(PyObject* self, PyObject* args, PyObject* kwargs) &text, &wrap_width, &fontRaw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID font = GetIDFromPyObject(fontRaw); @@ -844,7 +844,7 @@ get_selected_nodes(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["get_selected_nodes"], args, kwargs, __FUNCTION__, &node_editor_raw)) return ToPyBool(false); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID node_editor = GetIDFromPyObject(node_editor_raw); @@ -879,7 +879,7 @@ get_selected_links(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["get_selected_links"], args, kwargs, __FUNCTION__, &node_editor_raw)) return ToPyBool(false); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID node_editor = GetIDFromPyObject(node_editor_raw); @@ -913,7 +913,7 @@ clear_selected_links(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["clear_selected_links"], args, kwargs, __FUNCTION__, &node_editor_raw)) return ToPyBool(false); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID node_editor = GetIDFromPyObject(node_editor_raw); @@ -947,7 +947,7 @@ clear_selected_nodes(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["clear_selected_nodes"], args, kwargs, __FUNCTION__, &node_editor_raw)) return ToPyBool(false); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID node_editor = GetIDFromPyObject(node_editor_raw); @@ -981,7 +981,7 @@ is_plot_queried(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["is_plot_queried"], args, kwargs, __FUNCTION__, &plotraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID plot = GetIDFromPyObject(plotraw); @@ -1013,7 +1013,7 @@ get_plot_query_area(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["get_plot_query_area"], args, kwargs, __FUNCTION__, &plotraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID plot = GetIDFromPyObject(plotraw); @@ -1049,7 +1049,7 @@ set_axis_ticks(PyObject* self, PyObject* args, PyObject* kwargs) auto mlabel_pairs = ToVectPairStringFloat(label_pairs); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID plot = GetIDFromPyObject(plotraw); @@ -1101,7 +1101,7 @@ set_axis_limits(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["set_axis_limits"], args, kwargs, __FUNCTION__, &axisraw, &ymin, &ymax)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID axis = GetIDFromPyObject(axisraw); @@ -1134,7 +1134,7 @@ set_axis_limits_auto(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["set_axis_limits_auto"], args, kwargs, __FUNCTION__, &axisraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID axis = GetIDFromPyObject(axisraw); @@ -1168,7 +1168,7 @@ fit_axis_data(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["fit_axis_data"], args, kwargs, __FUNCTION__, &axisraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID axis = GetIDFromPyObject(axisraw); @@ -1204,7 +1204,7 @@ get_axis_limits(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["get_axis_limits"], args, kwargs, __FUNCTION__, &plotraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID plot = GetIDFromPyObject(plotraw); @@ -1237,7 +1237,7 @@ reset_axis_ticks(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["reset_axis_ticks"], args, kwargs, __FUNCTION__, &plotraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID plot = GetIDFromPyObject(plotraw); @@ -1275,7 +1275,7 @@ highlight_table_column(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["highlight_table_column"], args, kwargs, __FUNCTION__, &tableraw, &column, &color)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID table = GetIDFromPyObject(tableraw); @@ -1319,7 +1319,7 @@ unhighlight_table_column(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["unhighlight_table_column"], args, kwargs, __FUNCTION__, &tableraw, &column)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID table = GetIDFromPyObject(tableraw); @@ -1362,7 +1362,7 @@ set_table_row_color(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["set_table_row_color"], args, kwargs, __FUNCTION__, &tableraw, &row, &color)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID table = GetIDFromPyObject(tableraw); @@ -1406,7 +1406,7 @@ unset_table_row_color(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["unset_table_row_color"], args, kwargs, __FUNCTION__, &tableraw, &row)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID table = GetIDFromPyObject(tableraw); @@ -1448,7 +1448,7 @@ highlight_table_row(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["highlight_table_row"], args, kwargs, __FUNCTION__, &tableraw, &row, &color)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID table = GetIDFromPyObject(tableraw); @@ -1492,7 +1492,7 @@ unhighlight_table_row(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["unhighlight_table_row"], args, kwargs, __FUNCTION__, &tableraw, &row)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID table = GetIDFromPyObject(tableraw); @@ -1536,7 +1536,7 @@ highlight_table_cell(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["highlight_table_cell"], args, kwargs, __FUNCTION__, &tableraw, &row, &column, &color)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID table = GetIDFromPyObject(tableraw); @@ -1581,7 +1581,7 @@ unhighlight_table_cell(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["unhighlight_table_cell"], args, kwargs, __FUNCTION__, &tableraw, &row, &column)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID table = GetIDFromPyObject(tableraw); @@ -1624,7 +1624,7 @@ is_table_cell_highlighted(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["is_table_cell_highlighted"], args, kwargs, __FUNCTION__, &tableraw, &row, &column)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID table = GetIDFromPyObject(tableraw); @@ -1671,7 +1671,7 @@ is_table_row_highlighted(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["is_table_row_highlighted"], args, kwargs, __FUNCTION__, &tableraw, &row)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID table = GetIDFromPyObject(tableraw); @@ -1711,7 +1711,7 @@ is_table_column_highlighted(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["is_table_column_highlighted"], args, kwargs, __FUNCTION__, &tableraw, &column)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID table = GetIDFromPyObject(tableraw); @@ -1752,7 +1752,7 @@ bind_theme(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -1795,7 +1795,7 @@ set_global_font_scale(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["set_global_font_scale"], args, kwargs, __FUNCTION__, &scale)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvToolManager::GetFontManager().setGlobalFontScale(scale); return GetPyNone(); @@ -1901,7 +1901,7 @@ static PyObject* get_viewport_configuration(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); PyObject* pdict = PyDict_New(); @@ -1938,7 +1938,7 @@ static PyObject* is_viewport_ok(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvViewport* viewport = GContext->viewport; if (viewport) @@ -2035,6 +2035,8 @@ static PyObject* configure_viewport(PyObject* self, PyObject* args, PyObject* kwargs) { + std::lock_guard lk(GContext->mutex); + mvViewport* viewport = GContext->viewport; if (viewport) { @@ -2067,7 +2069,7 @@ configure_viewport(PyObject* self, PyObject* args, PyObject* kwargs) static PyObject* maximize_viewport(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvSubmitTask([=]() { mvMaximizeViewport(*GContext->viewport); @@ -2079,7 +2081,7 @@ maximize_viewport(PyObject* self, PyObject* args, PyObject* kwargs) static PyObject* minimize_viewport(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvSubmitTask([=]() { mvMinimizeViewport(*GContext->viewport); @@ -2091,7 +2093,7 @@ minimize_viewport(PyObject* self, PyObject* args, PyObject* kwargs) static PyObject* toggle_viewport_fullscreen(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvSubmitTask([=]() { mvToggleFullScreen(*GContext->viewport); @@ -2125,7 +2127,7 @@ split_frame(PyObject* self, PyObject* args, PyObject* kwargs) &delay)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); Py_BEGIN_ALLOW_THREADS; GContext->waitOneFrame = true; @@ -2140,7 +2142,6 @@ static PyObject* lock_mutex(PyObject* self, PyObject* args, PyObject* kwargs) { GContext->mutex.lock(); - GContext->manualMutexControl = true; return GetPyNone(); } @@ -2149,7 +2150,6 @@ static PyObject* unlock_mutex(PyObject* self, PyObject* args, PyObject* kwargs) { GContext->mutex.unlock(); - GContext->manualMutexControl = false; return GetPyNone(); } @@ -2157,7 +2157,7 @@ unlock_mutex(PyObject* self, PyObject* args, PyObject* kwargs) static PyObject* get_frame_count(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); return ToPyInt(GContext->frame); } @@ -2394,7 +2394,7 @@ static PyObject* setup_dearpygui(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); Py_BEGIN_ALLOW_THREADS; @@ -2463,7 +2463,7 @@ create_context(PyObject* self, PyObject* args, PyObject* kwargs) static PyObject* destroy_context(PyObject* self, PyObject* args, PyObject* kwargs) { - //if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + //std::lock_guard lk(GContext->mutex); Py_BEGIN_ALLOW_THREADS; @@ -2519,7 +2519,7 @@ destroy_context(PyObject* self, PyObject* args, PyObject* kwargs) static PyObject* stop_dearpygui(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); GContext->started = false; auto viewport = GContext->viewport; if (viewport) @@ -2530,14 +2530,14 @@ stop_dearpygui(PyObject* self, PyObject* args, PyObject* kwargs) static PyObject* get_total_time(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); return ToPyFloat((f32)GContext->time); } static PyObject* get_delta_time(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); return ToPyFloat(GContext->deltaTime); } @@ -2545,7 +2545,7 @@ get_delta_time(PyObject* self, PyObject* args, PyObject* kwargs) static PyObject* get_frame_rate(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); return ToPyFloat((f32)GContext->framerate); } @@ -2572,7 +2572,7 @@ configure_app(PyObject* self, PyObject* args, PyObject* kwargs) return GetPyNone(); } - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); if (PyObject* item = PyDict_GetItemString(kwargs, "auto_device")) GContext->IO.info_auto_device = ToBool(item); if (PyObject* item = PyDict_GetItemString(kwargs, "docking")) GContext->IO.docking = ToBool(item); @@ -2603,7 +2603,7 @@ configure_app(PyObject* self, PyObject* args, PyObject* kwargs) static PyObject* get_app_configuration(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); PyObject* pdict = PyDict_New(); PyDict_SetItemString(pdict, "auto_device", mvPyObject(ToPyBool(GContext->IO.info_auto_device))); PyDict_SetItemString(pdict, "docking", mvPyObject(ToPyBool(GContext->IO.docking))); @@ -2770,7 +2770,7 @@ static PyObject* pop_container_stack(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); if (GContext->itemRegistry->containers.empty()) { @@ -2792,7 +2792,7 @@ pop_container_stack(PyObject* self, PyObject* args, PyObject* kwargs) static PyObject* empty_container_stack(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); while (!GContext->itemRegistry->containers.empty()) GContext->itemRegistry->containers.pop(); return GetPyNone(); @@ -2801,7 +2801,7 @@ empty_container_stack(PyObject* self, PyObject* args, PyObject* kwargs) static PyObject* top_container_stack(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvAppItem* item = nullptr; if (!GContext->itemRegistry->containers.empty()) @@ -2816,7 +2816,7 @@ top_container_stack(PyObject* self, PyObject* args, PyObject* kwargs) static PyObject* last_item(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); return ToPyUUID(GContext->itemRegistry->lastItemAdded); } @@ -2824,7 +2824,7 @@ last_item(PyObject* self, PyObject* args, PyObject* kwargs) static PyObject* last_container(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); return ToPyUUID(GContext->itemRegistry->lastContainerAdded); } @@ -2832,7 +2832,7 @@ last_container(PyObject* self, PyObject* args, PyObject* kwargs) static PyObject* last_root(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); return ToPyUUID(GContext->itemRegistry->lastRootAdded); } @@ -2845,7 +2845,7 @@ push_container_stack(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["push_container_stack"], args, kwargs, __FUNCTION__, &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -2873,7 +2873,7 @@ set_primary_window(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["set_primary_window"], args, kwargs, __FUNCTION__, &itemraw, &value)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -2951,7 +2951,7 @@ set_primary_window(PyObject* self, PyObject* args, PyObject* kwargs) static PyObject* get_active_window(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); return ToPyUUID(GContext->itemRegistry->activeWindow); } @@ -2968,7 +2968,7 @@ move_item(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw, &parentraw, &beforeraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); mvUUID parent = GetIDFromPyObject(parentraw); @@ -2990,7 +2990,7 @@ delete_item(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["delete_item"], args, kwargs, __FUNCTION__, &itemraw, &childrenOnly, &slot)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -3010,7 +3010,7 @@ does_item_exist(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["does_item_exist"], args, kwargs, __FUNCTION__, &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -3028,7 +3028,7 @@ move_item_up(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["move_item_up"], args, kwargs, __FUNCTION__, &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -3047,7 +3047,7 @@ move_item_down(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["move_item_down"], args, kwargs, __FUNCTION__, &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -3068,7 +3068,7 @@ reorder_items(PyObject* self, PyObject* args, PyObject* kwargs) &containerraw, &slot, &new_order)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); auto anew_order = ToUUIDVect(new_order); mvUUID container = GetIDFromPyObject(containerraw); @@ -3105,7 +3105,7 @@ unstage(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["unstage"], args, kwargs, __FUNCTION__, &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -3147,7 +3147,7 @@ show_item_debug(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["show_item_debug"], args, kwargs, __FUNCTION__, &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -3207,7 +3207,7 @@ static PyObject* get_all_items(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); std::vector childList; @@ -3232,7 +3232,7 @@ static PyObject* show_imgui_demo(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); GContext->itemRegistry->showImGuiDebug = true; return GetPyNone(); @@ -3242,7 +3242,7 @@ static PyObject* show_implot_demo(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); GContext->itemRegistry->showImPlotDebug = true; return GetPyNone(); @@ -3252,7 +3252,7 @@ static PyObject* get_windows(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); std::vector childList; for (auto& root : GContext->itemRegistry->colormapRoots) childList.emplace_back(root->uuid); @@ -3282,7 +3282,7 @@ add_alias(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["add_alias"], args, kwargs, __FUNCTION__, &alias, &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -3301,7 +3301,7 @@ remove_alias(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["remove_alias"], args, kwargs, __FUNCTION__, &alias)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); RemoveAlias((*GContext->itemRegistry), alias); @@ -3318,7 +3318,7 @@ does_alias_exist(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["does_alias_exist"], args, kwargs, __FUNCTION__, &alias)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); bool result = GContext->itemRegistry->aliases.count(alias) != 0; @@ -3334,7 +3334,7 @@ get_alias_id(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["get_alias_id"], args, kwargs, __FUNCTION__, &alias)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID result = GetIdFromAlias((*GContext->itemRegistry), alias); @@ -3345,7 +3345,7 @@ static PyObject* get_aliases(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); std::vector aliases; @@ -3355,6 +3355,39 @@ get_aliases(PyObject* self, PyObject* args, PyObject* kwargs) return ToPyList(aliases); } +static PyObject* +bind_template_registry(PyObject* self, PyObject* args, PyObject* kwargs) +{ + + PyObject* itemraw; + + if (!Parse((GetParsers())["bind_template_registry"], args, kwargs, __FUNCTION__, + &itemraw)) + return GetPyNone(); + + std::lock_guard lk(GContext->mutex); + + mvUUID item = GetIDFromPyObject(itemraw); + + + if (item == 0) + GContext->itemRegistry->boundedTemplateRegistry = nullptr; + else + { + auto actualItem = GetRefItem((*GContext->itemRegistry), item); + if (actualItem) + GContext->itemRegistry->boundedTemplateRegistry = std::move(actualItem); + else + { + mvThrowPythonError(mvErrorCode::mvItemNotFound, "bind_template_registry", + "Item not found: " + std::to_string(item), nullptr); + return GetPyNone(); + } + } + + return GetPyNone(); +} + static PyObject* focus_item(PyObject* self, PyObject* args, PyObject* kwargs) { @@ -3363,7 +3396,7 @@ focus_item(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["focus_item"], args, kwargs, __FUNCTION__, &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); @@ -3436,7 +3469,7 @@ get_item_info(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["get_item_info"], args, kwargs, __FUNCTION__, &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); mvAppItem* appitem = GetItem((*GContext->itemRegistry), item); @@ -3521,7 +3554,7 @@ get_item_configuration(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["get_item_configuration"], args, kwargs, __FUNCTION__, &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); mvAppItem* appitem = GetItem((*GContext->itemRegistry), item); @@ -3609,7 +3642,7 @@ set_item_children(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw, &sourceraw, &slot)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); mvUUID source = GetIDFromPyObject(sourceraw); @@ -3680,7 +3713,7 @@ bind_item_font(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw, &fontraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); mvUUID font = GetIDFromPyObject(fontraw); @@ -3722,7 +3755,7 @@ bind_item_theme(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw, &themeraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); mvUUID theme = GetIDFromPyObject(themeraw); @@ -3769,7 +3802,7 @@ bind_item_handler_registry(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw, ®raw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); mvUUID reg = GetIDFromPyObject(regraw); @@ -3816,7 +3849,7 @@ reset_pos(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); mvAppItem* appitem = GetItem((*GContext->itemRegistry), item); @@ -3838,7 +3871,7 @@ get_item_state(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["get_item_state"], args, kwargs, __FUNCTION__, &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); mvAppItem* appitem = GetItem((*GContext->itemRegistry), item); @@ -3858,7 +3891,7 @@ static PyObject* get_item_types(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); PyObject* pdict = PyDict_New(); #define X(el) PyDict_SetItemString(pdict, #el, PyLong_FromLong((int)mvAppItemType::el)); @@ -3872,7 +3905,7 @@ static PyObject* configure_item(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(PyTuple_GetItem(args, 0)); mvAppItem* appitem = GetItem((*GContext->itemRegistry), item); @@ -3897,7 +3930,7 @@ get_value(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["get_value"], args, kwargs, __FUNCTION__, &nameraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID name = GetIDFromPyObject(nameraw); mvAppItem* item = GetItem(*GContext->itemRegistry, name); @@ -3915,7 +3948,7 @@ get_values(PyObject* self, PyObject* args, PyObject* kwargs) if (!Parse((GetParsers())["get_values"], args, kwargs, __FUNCTION__, &items)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); auto aitems = ToUUIDVect(items); PyObject* pyvalues = PyList_New(aitems.size()); @@ -3948,7 +3981,7 @@ set_value(PyObject* self, PyObject* args, PyObject* kwargs) if (value) Py_XINCREF(value); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID name = GetIDFromPyObject(nameraw); @@ -3976,7 +4009,7 @@ set_item_alias(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw, &alias)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); mvAppItem* appitem = GetItem((*GContext->itemRegistry), item); @@ -3994,7 +4027,7 @@ get_item_alias(PyObject* self, PyObject* args, PyObject* kwargs) &itemraw)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); mvUUID item = GetIDFromPyObject(itemraw); mvAppItem* appitem = GetItem((*GContext->itemRegistry), item); @@ -4013,7 +4046,7 @@ capture_next_item(PyObject* self, PyObject* args, PyObject* kwargs) &callable, &user_data)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); if (GContext->itemRegistry->captureCallback) Py_XDECREF(GContext->itemRegistry->captureCallback); @@ -4081,7 +4114,7 @@ set_clipboard_text(PyObject* self, PyObject* args, PyObject* kwargs) &text)) return GetPyNone(); - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); ImGui::SetClipboardText(text); @@ -4092,7 +4125,7 @@ static PyObject* get_clipboard_text(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); const char* text = ImGui::GetClipboardText(); @@ -4103,7 +4136,7 @@ static PyObject* get_platform(PyObject* self, PyObject* args, PyObject* kwargs) { - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); #ifdef _WIN32 return ToPyInt(0L); diff --git a/src/mvContext.cpp b/src/mvContext.cpp index e736628ef..3f0fe9b58 100644 --- a/src/mvContext.cpp +++ b/src/mvContext.cpp @@ -194,7 +194,7 @@ Render() mvToolManager::Draw(); { - std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); if (GContext->resetTheme) { SetDefaultTheme(); diff --git a/src/mvContext.h b/src/mvContext.h index ea5c5101e..8da80f638 100644 --- a/src/mvContext.h +++ b/src/mvContext.h @@ -102,9 +102,8 @@ struct mvIO struct mvContext { std::atomic_bool waitOneFrame = false; - std::atomic_bool manualMutexControl = false; std::atomic_bool started = false; - std::mutex mutex; + std::recursive_mutex mutex; std::future future; float deltaTime = 0.0f; // time since last frame double time = 0.0; // total time since starting diff --git a/src/mvItemRegistry.cpp b/src/mvItemRegistry.cpp index 17cb631f7..f883c8db6 100644 --- a/src/mvItemRegistry.cpp +++ b/src/mvItemRegistry.cpp @@ -1365,7 +1365,7 @@ AddItemWithRuntimeChecks(mvItemRegistry& registry, std::shared_ptr it }; AddTechnique technique = AddTechnique::NONE; - if (!GContext->manualMutexControl) std::lock_guard lk(GContext->mutex); + std::lock_guard lk(GContext->mutex); //--------------------------------------------------------------------------- // STEP 2: handle root case diff --git a/src/mvLayoutWindow.cpp b/src/mvLayoutWindow.cpp index c471c19ef..e320b58c3 100644 --- a/src/mvLayoutWindow.cpp +++ b/src/mvLayoutWindow.cpp @@ -119,6 +119,8 @@ void mvLayoutWindow::renderTreeNode(std::shared_ptr& item) void mvLayoutWindow::drawWidgets() { + std::lock_guard lk(GContext->mutex); + mvUUID parentName = 0; if (_itemref == nullptr && GContext->itemRegistry->windowRoots.size() > 0) diff --git a/src/mvToolWindow.cpp b/src/mvToolWindow.cpp index f36a3b902..2b373dc7b 100644 --- a/src/mvToolWindow.cpp +++ b/src/mvToolWindow.cpp @@ -38,6 +38,8 @@ void mvToolWindow::draw() GContext->input.mousePos.x = (int)x; GContext->input.mousePos.y = (int)y; + std::lock_guard lk(GContext->mutex); + if (GContext->itemRegistry->activeWindow != getUUID()) GContext->itemRegistry->activeWindow = getUUID(); diff --git a/src/mvViewport_win32.cpp b/src/mvViewport_win32.cpp index 9892d9290..c5ade114b 100644 --- a/src/mvViewport_win32.cpp +++ b/src/mvViewport_win32.cpp @@ -44,40 +44,45 @@ mvPrerender(mvViewport& viewport) if (viewportData->msg.message == WM_QUIT) viewport.running = false; - if (viewport.posDirty) { - int horizontal_shift = get_horizontal_shift(viewportData->handle); - SetWindowPos(viewportData->handle, viewport.alwaysOnTop ? HWND_TOPMOST : HWND_TOP, viewport.xpos-horizontal_shift, viewport.ypos, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE); - viewport.posDirty = false; - } - - if (viewport.sizeDirty) - { - SetWindowPos(viewportData->handle, viewport.alwaysOnTop ? HWND_TOPMOST : HWND_TOP, 0, 0, viewport.actualWidth, viewport.actualHeight, SWP_SHOWWINDOW | SWP_NOMOVE); - viewport.sizeDirty = false; - } + // TODO: we probably need a separate mutex for this + std::lock_guard lk(GContext->mutex); - if (viewport.modesDirty) - { - viewportData->modes = WS_OVERLAPPED; - - if (viewport.resizable && viewport.decorated) viewportData->modes |= WS_THICKFRAME; - if (viewport.decorated) { - viewportData->modes |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX; + if (viewport.posDirty) + { + int horizontal_shift = get_horizontal_shift(viewportData->handle); + SetWindowPos(viewportData->handle, viewport.alwaysOnTop ? HWND_TOPMOST : HWND_TOP, viewport.xpos-horizontal_shift, viewport.ypos, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE); + viewport.posDirty = false; } - else { - viewportData->modes |= WS_POPUP; + + if (viewport.sizeDirty) + { + SetWindowPos(viewportData->handle, viewport.alwaysOnTop ? HWND_TOPMOST : HWND_TOP, 0, 0, viewport.actualWidth, viewport.actualHeight, SWP_SHOWWINDOW | SWP_NOMOVE); + viewport.sizeDirty = false; } - SetWindowLongPtr(viewportData->handle, GWL_STYLE, viewportData->modes); - SetWindowPos(viewportData->handle, viewport.alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); - viewport.modesDirty = false; - } + if (viewport.modesDirty) + { + viewportData->modes = WS_OVERLAPPED; - if (viewport.titleDirty) - { - SetWindowTextA(viewportData->handle, viewport.title.c_str()); - viewport.titleDirty = false; + if (viewport.resizable && viewport.decorated) viewportData->modes |= WS_THICKFRAME; + if (viewport.decorated) { + viewportData->modes |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX; + } + else { + viewportData->modes |= WS_POPUP; + } + + SetWindowLongPtr(viewportData->handle, GWL_STYLE, viewportData->modes); + SetWindowPos(viewportData->handle, viewport.alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); + viewport.modesDirty = false; + } + + if (viewport.titleDirty) + { + SetWindowTextA(viewportData->handle, viewport.title.c_str()); + viewport.titleDirty = false; + } } // Poll and handle messages (inputs, window resize, etc.) @@ -96,11 +101,16 @@ mvPrerender(mvViewport& viewport) //continue; } - if (mvToolManager::GetFontManager().isInvalid()) { - mvToolManager::GetFontManager().rebuildAtlas(); - ImGui_ImplDX11_InvalidateDeviceObjects(); - mvToolManager::GetFontManager().updateAtlas(); + // Font manager is thread-unsafe, so we'd better sync it + std::lock_guard lk(GContext->mutex); + + if (mvToolManager::GetFontManager().isInvalid()) + { + mvToolManager::GetFontManager().rebuildAtlas(); + ImGui_ImplDX11_InvalidateDeviceObjects(); + mvToolManager::GetFontManager().updateAtlas(); + } } // Start the Dear ImGui frame @@ -146,30 +156,34 @@ mvHandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept cheight = crect.bottom - crect.top; } - viewport->actualWidth = awidth; - viewport->actualHeight = aheight; - - - if (viewport->decorated) { - GContext->viewport->clientHeight = cheight; - GContext->viewport->clientWidth = cwidth; - } - else - { - GContext->viewport->clientHeight = cheight; - GContext->viewport->clientWidth = cwidth; - } - - //GContext->viewport->resized = true; - mvOnResize(); - GContext->viewport->resized = false; - - if (mvToolManager::GetFontManager().isInvalid()) - { - mvToolManager::GetFontManager().rebuildAtlas(); - ImGui_ImplDX11_InvalidateDeviceObjects(); - mvToolManager::GetFontManager().updateAtlas(); + std::lock_guard lk(GContext->mutex); + + viewport->actualWidth = awidth; + viewport->actualHeight = aheight; + + + if (viewport->decorated) + { + GContext->viewport->clientHeight = cheight; + GContext->viewport->clientWidth = cwidth; + } + else + { + GContext->viewport->clientHeight = cheight + 39; + GContext->viewport->clientWidth = cwidth + 16; + } + + //GContext->viewport->resized = true; + mvOnResize(); + GContext->viewport->resized = false; + + if (mvToolManager::GetFontManager().isInvalid()) + { + mvToolManager::GetFontManager().rebuildAtlas(); + ImGui_ImplDX11_InvalidateDeviceObjects(); + mvToolManager::GetFontManager().updateAtlas(); + } } // Start the Dear ImGui frame ImGui_ImplDX11_NewFrame(); @@ -182,6 +196,8 @@ mvHandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept case WM_GETMINMAXINFO: { + // TODO: lock the mutex? + LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam; lpMMI->ptMinTrackSize.x = viewport->minwidth; lpMMI->ptMinTrackSize.y = viewport->minheight; @@ -192,6 +208,8 @@ mvHandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept case WM_MOVING: { + std::lock_guard lk(GContext->mutex); + int horizontal_shift = get_horizontal_shift(viewportData->handle); RECT rect = *(RECT*)(lParam); viewport->xpos = rect.left + horizontal_shift; @@ -221,6 +239,8 @@ mvHandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept cheight = crect.bottom - crect.top; } + std::lock_guard lk(GContext->mutex); + viewport->actualWidth = awidth; viewport->actualHeight = aheight;