-
-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace Dropzone VTKActor by IMGUI #1990
base: master
Are you sure you want to change the base?
Conversation
Do you think you could put an outline around the text, like its done for the filename ? |
Other than that, its looking good! Dont hesitate to share such screenshot on discord :) |
You just need to update the baselines |
Sorry I don't understand ? Where I can find the example to put outline on text ? because my update on DropText look very similar at what it is done for FileName |
I think its handled by |
@Ni-g-3l I would suggest trying absurdly high values for For example, using: constexpr float tickThickness = 25.0f;
constexpr float tickLength = 40.0f; this PR's ImGui code shows: The key point here is that the previous code was drawing rectangles and the new code is drawing thick lines so there's going to be some (also check to make sure it all still works when resizing the window) possible fix/improvementdiff --git a/vtkext/private/module/vtkF3DImguiActor.cxx b/vtkext/private/module/vtkF3DImguiActor.cxx
index b54e941c..c386d537 100644
--- a/vtkext/private/module/vtkF3DImguiActor.cxx
+++ b/vtkext/private/module/vtkF3DImguiActor.cxx
@@ -299,8 +299,8 @@ void vtkF3DImguiActor::RenderDropZone()
constexpr float tickLength = 10.0f;
int dropzonePad = static_cast<int>(std::min(viewport->WorkSize.x, viewport->WorkSize.y) * 0.1);
- int dropZoneW = viewport->WorkSize.x - dropzonePad;
- int dropZoneH = viewport->WorkSize.y - dropzonePad;
+ int dropZoneW = viewport->WorkSize.x - dropzonePad * 2;
+ int dropZoneH = viewport->WorkSize.y - dropzonePad * 2;
::SetupNextWindow(ImVec2(0, 0), viewport->WorkSize);
ImGui::SetNextWindowBgAlpha(0.f);
@@ -312,7 +312,7 @@ void vtkF3DImguiActor::RenderDropZone()
ImDrawList* draw_list = ImGui::GetWindowDrawList();
ImVec2 p0(dropzonePad, dropzonePad);
- ImVec2 p1(dropZoneW, dropZoneH);
+ ImVec2 p1(dropzonePad + dropZoneW, dropzonePad + dropZoneH);
int tickNumberW = static_cast<int>(std::ceil(dropZoneW / (tickLength * 2.0f)));
int tickNumberH = static_cast<int>(std::ceil(dropZoneH / (tickLength * 2.0f)));
double tickSpaceW =
@@ -323,22 +323,24 @@ void vtkF3DImguiActor::RenderDropZone()
// Draw top and bottom line
for (float x = p0.x; x < p1.x; x += tickLength + tickSpaceW)
{
- draw_list->AddLine(ImVec2(x, p0.y), ImVec2(x + tickLength, p0.y), color, tickThickness);
- draw_list->AddLine(ImVec2(x, p1.y), ImVec2(x + tickLength, p1.y), color, tickThickness);
+ const float y0 = p0.y + tickThickness / 2.f;
+ const float y1 = p1.y - tickThickness / 2.f;
+ draw_list->AddLine(ImVec2(x, y0), ImVec2(x + tickLength, y0), color, tickThickness);
+ draw_list->AddLine(ImVec2(x, y1), ImVec2(x + tickLength, y1), color, tickThickness);
}
// Draw left and right line
for (float y = p0.y; y < p1.y; y += tickLength + tickSpaceH)
{
- draw_list->AddLine(ImVec2(p0.x, y), ImVec2(p0.x, y + tickLength), color, tickThickness);
- draw_list->AddLine(ImVec2(p1.x, y), ImVec2(p1.x, y + tickLength), color, tickThickness);
+ const float x0 = p0.x + tickThickness / 2.f;
+ const float x1 = p1.x - tickThickness / 2.f;
+ draw_list->AddLine(ImVec2(x0, y), ImVec2(x0, y + tickLength), color, tickThickness);
+ draw_list->AddLine(ImVec2(x1, y), ImVec2(x1, y + tickLength), color, tickThickness);
}
ImGui::End();
ImVec2 dropTextSize = ImGui::CalcTextSize(this->DropText.c_str());
- dropTextSize.x += 2.f * ImGui::GetStyle().WindowPadding.x;
- dropTextSize.y += 2.f * ImGui::GetStyle().WindowPadding.y;
ImGui::Begin("DropZoneText", nullptr, flags);
ImGui::SetCursorPos(ImVec2(viewport->GetWorkCenter().x - 0.5f * dropTextSize.x, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ni-g-3l I believe you forgot to double the padding at the beginning and ended up trying to compensate for that all along later
double tickBBSizeW = tickLength + tickSpaceW; | ||
double tickBBSizeH = tickLength + tickSpaceH; | ||
|
||
// Draw top and bottom line | ||
for (float x = p0.x - tickHalfThickness; x < p1.x - tickBBSizeW; x += tickBBSizeW) | ||
{ | ||
draw_list->AddLine(ImVec2(x, p0.y), ImVec2(x + tickLength, p0.y), color, tickThickness); | ||
draw_list->AddLine(ImVec2(x, p1.y), ImVec2(x + tickLength, p1.y), color, tickThickness); | ||
} | ||
|
||
draw_list->AddLine(ImVec2(p1.x - tickLength, p0.y), ImVec2(p1.x + tickHalfThickness, p0.y), | ||
color, tickThickness); | ||
draw_list->AddLine(ImVec2(p1.x - tickLength, p1.y), ImVec2(p1.x + tickHalfThickness, p1.y), | ||
color, tickThickness); | ||
|
||
// Draw left and right line | ||
for (float y = p0.y - tickHalfThickness; y < p1.y - tickBBSizeH; y += tickBBSizeH) | ||
{ | ||
draw_list->AddLine(ImVec2(p0.x, y), ImVec2(p0.x, y + tickLength), color, tickThickness); | ||
draw_list->AddLine(ImVec2(p1.x, y), ImVec2(p1.x, y + tickLength), color, tickThickness); | ||
} | ||
|
||
draw_list->AddLine(ImVec2(p0.x, p1.y - tickLength), ImVec2(p0.x, p1.y + tickHalfThickness), | ||
color, tickThickness); | ||
draw_list->AddLine(ImVec2(p1.x, p1.y - tickLength), ImVec2(p1.x, p1.y + tickHalfThickness), | ||
color, tickThickness); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the half-thickness offset you want is only to draw the lines inside the target rectangle rather that on it:
vs
So you just have to to shift the top/bottom lines down/up and the right/left lines left/right, no need to modify/extend the loops:
double tickBBSizeW = tickLength + tickSpaceW; | |
double tickBBSizeH = tickLength + tickSpaceH; | |
// Draw top and bottom line | |
for (float x = p0.x - tickHalfThickness; x < p1.x - tickBBSizeW; x += tickBBSizeW) | |
{ | |
draw_list->AddLine(ImVec2(x, p0.y), ImVec2(x + tickLength, p0.y), color, tickThickness); | |
draw_list->AddLine(ImVec2(x, p1.y), ImVec2(x + tickLength, p1.y), color, tickThickness); | |
} | |
draw_list->AddLine(ImVec2(p1.x - tickLength, p0.y), ImVec2(p1.x + tickHalfThickness, p0.y), | |
color, tickThickness); | |
draw_list->AddLine(ImVec2(p1.x - tickLength, p1.y), ImVec2(p1.x + tickHalfThickness, p1.y), | |
color, tickThickness); | |
// Draw left and right line | |
for (float y = p0.y - tickHalfThickness; y < p1.y - tickBBSizeH; y += tickBBSizeH) | |
{ | |
draw_list->AddLine(ImVec2(p0.x, y), ImVec2(p0.x, y + tickLength), color, tickThickness); | |
draw_list->AddLine(ImVec2(p1.x, y), ImVec2(p1.x, y + tickLength), color, tickThickness); | |
} | |
draw_list->AddLine(ImVec2(p0.x, p1.y - tickLength), ImVec2(p0.x, p1.y + tickHalfThickness), | |
color, tickThickness); | |
draw_list->AddLine(ImVec2(p1.x, p1.y - tickLength), ImVec2(p1.x, p1.y + tickHalfThickness), | |
color, tickThickness); | |
// Draw top and bottom line | |
for (float x = p0.x; x < p1.x; x += tickLength + tickSpaceW) | |
{ | |
const float y0 = p0.y + tickThickness / 2.f; | |
const float y1 = p1.y - tickThickness / 2.f; | |
draw_list->AddLine(ImVec2(x, y0), ImVec2(x + tickLength, y0), color, tickThickness); | |
draw_list->AddLine(ImVec2(x, y1), ImVec2(x + tickLength, y1), color, tickThickness); | |
} | |
// Draw left and right line | |
for (float y = p0.y; y < p1.y; y += tickLength + tickSpaceH) | |
{ | |
const float x0 = p0.x + tickThickness / 2.f; | |
const float x1 = p1.x - tickThickness / 2.f; | |
draw_list->AddLine(ImVec2(x0, y), ImVec2(x0, y + tickLength), color, tickThickness); | |
draw_list->AddLine(ImVec2(x1, y), ImVec2(x1, y + tickLength), color, tickThickness); | |
} |
Hi @Ni-g-3l Do you need help or review into order to move forward ? |
Co-authored-by: snoyer <noyer.stephane@gmail.com>
Co-authored-by: snoyer <noyer.stephane@gmail.com>
Hello ! Sorry I was quite busy last week ! I will try to take a look this week in order to provide healthy base for the future implementation of the new drop zone |
c68a5cb
to
4268995
Compare
So I try all of your propositions @snoyer, but it wasn't worked as expected. If we want to ensure the dropZone rectangle is always correctly closed we have to draw the the last tick independantly from the loop. The current implementation is looking like this : The only problem that I can see is the different space length between the last tick of each line and the previous one. Feel free to review and comment if you think I should try another implementation ! |
@Ni-g-3l I think you should refer to the original computations for the dashing (you may want to keep the comments too) f3d/vtkext/private/module/vtkF3DDropZoneActor.cxx Lines 66 to 77 in c7f7a99
I believe your original version was only missing the offsetting to draw inside of the target rectangle instead of exactly on it (see this 2 images #1990 (comment)). Here's a snippet that seem to work for me: const double tickSpaceW =
static_cast<double>(dropZoneW - tickNumberW * tickLength) / (tickNumberW - 1);
const double tickSpaceH =
static_cast<double>(dropZoneH - tickNumberH * tickLength) / (tickNumberH - 1);
::SetupNextWindow(ImVec2(0, 0), viewport->WorkSize);
ImGui::SetNextWindowBgAlpha(0.f);
ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoMove;
ImGui::Begin("DropZoneText", nullptr, flags);
ImDrawList* draw_list = ImGui::GetWindowDrawList();
const ImVec2 p0(dropzonePad, dropzonePad);
const ImVec2 p1(dropzonePad + dropZoneW, dropzonePad + dropZoneH);
// Draw top and bottom line
for (float x = p0.x; x < p1.x; x += tickLength + tickSpaceW)
{
const float y0 = p0.y + tickThickness / 2.f;
const float y1 = p1.y - tickThickness / 2.f;
draw_list->AddLine(ImVec2(x, y0), ImVec2(x + tickLength, y0), color, tickThickness);
draw_list->AddLine(ImVec2(x, y1), ImVec2(x + tickLength, y1), color, tickThickness);
}
// Draw left and right line
for (float y = p0.y; y < p1.y; y += tickLength + tickSpaceH)
{
const float x0 = p0.x + tickThickness / 2.f;
const float x1 = p1.x - tickThickness / 2.f;
draw_list->AddLine(ImVec2(x0, y), ImVec2(x0, y + tickLength), color, tickThickness);
draw_list->AddLine(ImVec2(x1, y), ImVec2(x1, y + tickLength), color, tickThickness);
}
{
/* target rectangle for debugging ;) */
constexpr ImU32 red = IM_COL32(255, 0, 0, 255);
draw_list->AddLine(ImVec2(p0.x, p0.x), ImVec2(p1.x, p0.y), red, 1);
draw_list->AddLine(ImVec2(p0.x, p1.y), ImVec2(p1.x, p1.y), red, 1);
draw_list->AddLine(ImVec2(p0.x, p0.x), ImVec2(p0.x, p1.y), red, 1);
draw_list->AddLine(ImVec2(p1.x, p0.x), ImVec2(p1.x, p1.y), red, 1);
} |
Hello !
I try to replace DropZone Actor by a IMGUI window. I'm not ImGUI expert if you see a better way to do it do not hesitate to comment.
Linked issue : #1975