Skip to content

Commit

Permalink
+ capture mouse click in the genome preview only in its widget
Browse files Browse the repository at this point in the history
+ arrow size in muscle movement direction limited
  • Loading branch information
chrxh committed Nov 25, 2024
1 parent 8c71bcf commit 18d4fd2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
15 changes: 8 additions & 7 deletions source/EngineGpuKernels/RenderingKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -513,25 +513,26 @@ __global__ void cudaDrawCells(
//draw muscle movements
if (cudaSimulationParameters.muscleMovementVisualization && cell->cellFunction == CellFunction_Muscle
&& (cell->cellFunctionData.muscle.lastMovementX != 0 || cell->cellFunctionData.muscle.lastMovementY != 0)) {
float2 lastMovement{cell->cellFunctionData.muscle.lastMovementX, cell->cellFunctionData.muscle.lastMovementY};
auto lastMovementLength = Math::length(lastMovement);
if (lastMovementLength > 0.05f) {
lastMovement = lastMovement / lastMovementLength * 0.05f;
}

auto color = float3{0.7f, 0.7f, 0.7f} * min(1.0f, zoom * 0.1f);
auto endPos = cell->pos + float2{cell->cellFunctionData.muscle.lastMovementX, cell->cellFunctionData.muscle.lastMovementY} * 100;
auto endPos = cell->pos + lastMovement * 100;
auto endImagePos = mapWorldPosToImagePos(rectUpperLeft, endPos, universeImageSize, zoom);
if (isLineVisible(cellImagePos, endImagePos, universeImageSize)) {
drawLine(cellImagePos, endImagePos, color, imageData, imageSize);
}

auto arrowPos1 = endPos + float2{
-cell->cellFunctionData.muscle.lastMovementX + cell->cellFunctionData.muscle.lastMovementY,
-cell->cellFunctionData.muscle.lastMovementX - cell->cellFunctionData.muscle.lastMovementY} * 20;
auto arrowPos1 = endPos + float2{-lastMovement.x + lastMovement.y, -lastMovement.x - lastMovement.y} * 20;
auto arrowImagePos1 = mapWorldPosToImagePos(rectUpperLeft, arrowPos1, universeImageSize, zoom);
if (isLineVisible(arrowImagePos1, endImagePos, universeImageSize)) {
drawLine(arrowImagePos1, endImagePos, color, imageData, imageSize);
}

auto arrowPos2 = endPos + float2{
-cell->cellFunctionData.muscle.lastMovementX - cell->cellFunctionData.muscle.lastMovementY,
+cell->cellFunctionData.muscle.lastMovementX - cell->cellFunctionData.muscle.lastMovementY} * 20;
auto arrowPos2 = endPos + float2{-lastMovement.x - lastMovement.y, +lastMovement.x - lastMovement.y} * 20;
auto arrowImagePos2 = mapWorldPosToImagePos(rectUpperLeft, arrowPos2, universeImageSize, zoom);
if (isLineVisible(arrowImagePos2, endImagePos, universeImageSize)) {
drawLine(arrowImagePos2, endImagePos, color, imageData, imageSize);
Expand Down
7 changes: 5 additions & 2 deletions source/Gui/AlienImGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,7 @@ bool AlienImGui::ShowPreviewDescription(PreviewDescription const& desc, float& z
auto result = false;

auto color = ImGui::GetStyle().Colors[ImGuiCol_WindowBg];
auto windowPos = ImGui::GetWindowPos();
auto windowSize = ImGui::GetWindowSize();

RealVector2D upperLeft;
Expand All @@ -1366,6 +1367,9 @@ bool AlienImGui::ShowPreviewDescription(PreviewDescription const& desc, float& z
}
RealVector2D previewSize = (lowerRight - upperLeft) * cellSize + RealVector2D(cellSize, cellSize) * 2;

auto mousePos = ImGui::GetMousePos();
auto clickedOnPreviewWindow = ImGui::IsMouseClicked(ImGuiMouseButton_Left) && mousePos.x >= windowPos.x && mousePos.y >= windowPos.y
&& mousePos.x <= windowPos.x + windowSize.x && mousePos.y <= windowPos.y + windowSize.y;
ImGui::SetCursorPos({std::max(0.0f, windowSize.x - previewSize.x) / 2, std::max(0.0f, windowSize.y - previewSize.y) / 2});
if (ImGui::BeginChild("##genome", ImVec2(previewSize.x, previewSize.y), false, ImGuiWindowFlags_HorizontalScrollbar)) {

Expand Down Expand Up @@ -1396,8 +1400,7 @@ bool AlienImGui::ShowPreviewDescription(PreviewDescription const& desc, float& z
}
}

if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
auto mousePos = ImGui::GetMousePos();
if (clickedOnPreviewWindow) {
if (mousePos.x >= cellPos.x - cellSize / 2 && mousePos.y >= cellPos.y - cellSize / 2 && mousePos.x <= cellPos.x + cellSize / 2
&& mousePos.y <= cellPos.y + cellSize / 2) {
selectedNode = cell.nodeIndex;
Expand Down
14 changes: 7 additions & 7 deletions source/Gui/OverlayController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ void OverlayController::processProgressAnimation()
auto center = ImVec2{viewSize.x / 2, viewSize.y - scale(60.0f)};

drawList->AddRectFilledMultiColor(
ImVec2{center.x - width, center.y - height * 5},
ImVec2{center.x, center.y + height},
ImVec2{center.x, center.y - height * 5},
ImVec2{center.x - width, center.y + height},
ImColor::HSV(0.66f, 1.0f, 0.1f, 0.0f),
ImColor::HSV(0.66f, 1.0f, 0.1f,0.0f),
ImColor::HSV(0.66f, 1.0f, 0.1f, 0.0f),
ImColor::HSV(0.66f, 1.0f, 0.1f, 1.0f * alpha),
ImColor::HSV(0.66f, 1.0f, 0.1f, 0.0f));
ImColor::HSV(0.66f, 1.0f, 0.1f, 1.0f * alpha));
drawList->AddRectFilledMultiColor(
ImVec2{center.x, center.y - height * 5},
ImVec2{center.x + width, center.y + height},
Expand All @@ -105,10 +105,10 @@ void OverlayController::processProgressAnimation()
ImColor::HSV(0.66f, 1.0f, 0.1f, 0.0f),
ImColor::HSV(0.66f, 1.0f, 0.1f, 1.0f * alpha));
drawList->AddRectFilledMultiColor(
ImVec2{center.x, center.y + height},
ImVec2{center.x + width, center.y + height * 6},
ImColor::HSV(0.66f, 1.0f, 0.1f, 1.0f * alpha),
ImVec2{center.x + width, center.y + height},
ImVec2{center.x, center.y + height * 6},
ImColor::HSV(0.66f, 1.0f, 0.1f, 0.0f),
ImColor::HSV(0.66f, 1.0f, 0.1f, 1.0f * alpha),
ImColor::HSV(0.66f, 1.0f, 0.1f, 0.0f),
ImColor::HSV(0.66f, 1.0f, 0.1f, 0.0f));
drawList->AddRectFilledMultiColor(
Expand Down

0 comments on commit 18d4fd2

Please sign in to comment.