void DisplayView::OnLButtonUp(UINT nFlags, CPoint point) { point += GetScrollPosition(); // check for an overlay icon if (drag_mode == DisplayView::DRAG_OVERLAY_ICON) { Filter *current = graph.FindFilterByPos(point); if (current && current == overlay_filter) { int icon = current->CheckIcons(point); if (icon >= 0) { OnOverlayIconClick(current->overlay_icons[icon], point); } } } if (drag_mode == DisplayView::DRAG_CONNECTION) { Pin *p1 = graph.FindPinByPos(new_connection_start); Pin *p2 = graph.FindPinByPos(new_connection_end); int ret = graph.ConnectPins(p1, p2); if (ret < 0) { // TODO: error message } } new_connection_start = CPoint(-100,-100); new_connection_end = CPoint(-101, -101); drag_mode = DisplayView::DRAG_GROUP; ReleaseCapture(); graph.Dirty(); Invalidate(); }
void DisplayView::OnMouseMove(UINT nFlags, CPoint point) { point += GetScrollPosition(); bool need_invalidate = false; // loop through the filters... if (nFlags & MK_LBUTTON) { switch (drag_mode) { case DisplayView::DRAG_GROUP: { // we are dragging now int deltax = point.x - start_drag_point.x; int deltay = point.y - start_drag_point.y; // verify the deltas int i, selected_count = 0; for (i=0; i<graph.filters.GetCount(); i++) { Filter *filter = graph.filters[i]; if (filter->selected) { selected_count ++; filter->VerifyDrag(&deltax, &deltay); } } // exit if there's no selected filter if (selected_count == 0) return ; // update their position for (i=0; i<graph.filters.GetCount(); i++) { Filter *filter = graph.filters[i]; if (filter->selected) { int px = filter->start_drag_pos.x + deltax; int py = filter->start_drag_pos.y + deltay; // snap to grid px = (px+7)&~0x07; py = (py+7)&~0x07; if (px != filter->posx || py != filter->posy) { filter->posx = px; filter->posy = py; need_invalidate = true; } } } } break; case DisplayView::DRAG_CONNECTION: { new_connection_end = point; Filter *current = graph.FindFilterByPos(point); if (current) { Pin *drop_end = current->FindPinByPos(point); if (drop_end) { drop_end->GetCenterPoint(&new_connection_end); } } need_invalidate = true; } break; case DisplayView::DRAG_SELECTION: { int minx = start_drag_point.x; int miny = start_drag_point.y; int maxx = point.x; int maxy = point.y; if (minx > maxx) { minx = point.x; maxx = start_drag_point.x; } if (miny > maxy) { miny = point.y; maxy = start_drag_point.y; } end_drag_point = point; CRect rc(minx, miny, maxx, maxy); for (int i=0; i<graph.filters.GetCount(); i++) { Filter *filter = graph.filters[i]; CRect rc2(filter->posx, filter->posy, filter->posx+filter->width, filter->posy+filter->height); CRect rc3; rc3.IntersectRect(&rc, &rc2); bool sel = (rc3.IsRectEmpty() ? false : true); if (sel != filter->selected) { filter->Select(sel); need_invalidate = true; } } if (!need_invalidate) { Invalidate(); } } break; } if (need_invalidate) { graph.Dirty(); Invalidate(); } } else { /* No buttons are pressed. We only check for overlay icons */ Filter *current = graph.FindFilterByPos(point); // if there was a filter active before if (overlay_filter) { // which was not ours if (overlay_filter != current) { // make it's overlay icon disappear overlay_filter->overlay_icon_active = -1; need_invalidate = true; } } overlay_filter = current; if (current) { int cur_icon = current->overlay_icon_active; int ret = current->CheckIcons(point); if (ret != cur_icon) { need_invalidate = true; } } if (need_invalidate) { graph.Dirty(); Invalidate(); } } }
void DisplayView::OnLButtonDown(UINT nFlags, CPoint point) { point += GetScrollPosition(); SetCapture(); start_drag_point = point; end_drag_point = point; Filter *current = graph.FindFilterByPos(point); if (!current) { // deselect all filters bool need_invalidate = false; for (int i=0; i<graph.filters.GetCount(); i++) { if (graph.filters[i]->selected) { graph.filters[i]->Select(false); } graph.filters[i]->SelectConnection(nFlags, point); need_invalidate = true; } // store the selection point drag_mode = DisplayView::DRAG_SELECTION; if (need_invalidate) { graph.Dirty(); Invalidate(); } return ; } // check if we hit a pin Pin *hitpin = current->FindPinByPos(point); if (hitpin) { // deselect all filters for (int i=0; i<graph.filters.GetCount(); i++) { graph.filters[i]->Select(false); } // remember the start point hitpin->GetCenterPoint(&new_connection_start); new_connection_end = new_connection_start; drag_mode = DisplayView::DRAG_CONNECTION; } else { int icon = current->CheckIcons(point); if (icon >= 0) { drag_mode = DisplayView::DRAG_OVERLAY_ICON; return ; } if (current->selected) { if (nFlags & MK_SHIFT) { current->Select(false); graph.Dirty(); Invalidate(); } else { // nothing here... } } else { if (nFlags & MK_SHIFT) { current->Select(true); graph.Dirty(); Invalidate(); } else { // deselect all filters but this for (int i=0; i<graph.filters.GetCount(); i++) { graph.filters[i]->Select(false); } current->Select(true); graph.Dirty(); Invalidate(); } } drag_mode = DisplayView::DRAG_GROUP; // start dragging operation on all selected filters start_drag_point = point; for (int i=0; i<graph.filters.GetCount(); i++) { graph.filters[i]->BeginDrag(); } } }