/** * @brief Manage the DND when we move the mouse */ static void UI_DNDMouseMove (int mousePosX, int mousePosY) { uiNode_t* node = UI_GetNodeAtPosition(mousePosX, mousePosY); if (node != targetNode) { if (nodeAcceptDND && targetNode) { UI_Node_DndLeave(targetNode); } targetNode = node; if (targetNode) { nodeAcceptDND = UI_Node_DndEnter(targetNode); } } if (targetNode == nullptr) { nodeAcceptDND = false; positionAcceptDND = false; return; } if (!nodeAcceptDND) { positionAcceptDND = false; return; } positionAcceptDND = UI_Node_DndMove(targetNode, mousePosX, mousePosY); }
void uiEditorNode::drawOverWindow (uiNode_t* node) { uiNode_t* hovered = nullptr; if (UI_GetMouseCapture() != node) { if (anchoredNode) UI_EditorNodeHighlightNode(anchoredNode, red, false); return; } if (dragStatus == ZONE_NONE) { #if 0 /* it does nothing, remember why we need that... */ if (anchoredNode) UI_EditorNodeGetElementAtPosition(anchoredNode, mousePosX, mousePosY); #endif hovered = UI_GetNodeAtPosition(mousePosX, mousePosY); /* do not edit node from editor window */ if (hovered && hovered->root == node->root) hovered = nullptr; } if (hovered && hovered != anchoredNode) UI_EditorNodeHighlightNode(hovered, grey, true); if (anchoredNode) UI_EditorNodeHighlightNode(anchoredNode, red, true); }
void uiEditorNode::onMouseDown (uiNode_t* node, int x, int y, int button) { uiNode_t* hovered; if (UI_GetMouseCapture() != node) return; if (button != K_MOUSE1) return; hovered = UI_GetNodeAtPosition(mousePosX, mousePosY); /* stop the capture */ if (hovered && hovered->root == node->root) { UI_MouseRelease(); return; } if (hovered == anchoredNode) hovered = nullptr; if (anchoredNode) { dragStatus = UI_EditorNodeGetElementAtPosition(anchoredNode, x, y); if (dragStatus == ZONE_BODY) { if (hovered == nullptr) { startX = x; startY = y; return; } } else if (dragStatus != ZONE_NONE) { startX = x; startY = y; return; } } /* select the node */ UI_EditorNodeSelectNode(node, hovered); }
/** * @brief Is called every time the mouse position change */ void UI_MouseMove (int x, int y) { if (UI_DNDIsDragging()) return; if (pressedNode && !capturedNode) { if (pressedNodeLocationX != UI_STARTDRAG_ALREADY_SENT) { UI_TimerStop(longPressTimer); int dist = abs(pressedNodeLocationX - x) + abs(pressedNodeLocationY - y); if (dist > 4) { uiNode_t* node = pressedNode; while (node) { if (UI_Node_StartDragging(node, pressedNodeLocationX, pressedNodeLocationY, x, y, pressedNodeButton)) break; node = node->parent; } pressedNodeLocationX = UI_STARTDRAG_ALREADY_SENT; } } } /* send the captured move mouse event */ if (capturedNode) { UI_Node_CapturedMouseMove(capturedNode, x, y); return; } hoveredNode = UI_GetNodeAtPosition(x, y); /* update houvered node by sending messages */ if (oldHoveredNode != hoveredNode) { uiNode_t* commonNode = hoveredNode; uiNode_t* node; /* search the common node */ while (commonNode) { node = oldHoveredNode; while (node) { if (node == commonNode) break; node = node->parent; } if (node != nullptr) break; commonNode = commonNode->parent; } /* send 'leave' event from old node to common node */ node = oldHoveredNode; while (node != commonNode) { UI_Node_MouseLeave(node); node = node->parent; } if (oldHoveredNode) oldHoveredNode->state = false; /* send 'enter' event from common node to new node */ while (commonNode != hoveredNode) { /** @todo we can remove that loop with an array allocation */ node = hoveredNode; while (node->parent != commonNode) node = node->parent; commonNode = node; UI_Node_MouseEnter(node); } if (hoveredNode) { hoveredNode->state = true; UI_Node_MouseEnter(node); } } oldHoveredNode = hoveredNode; /* send the move event */ if (hoveredNode) UI_Node_MouseMove(hoveredNode, x, y); }