Changeset 1298
- Timestamp:
- 11/01/07 21:19:30 (10 months ago)
- Location:
- trunk/src/buzelib
- Files:
-
- 2 modified
-
MachineView.cpp (modified) (31 diffs)
-
MachineView.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/buzelib/MachineView.cpp
r1297 r1298 19 19 #include "Utils/Keymaps.h" 20 20 21 #ifdef min 22 #undef min 23 #endif 24 #ifdef max 25 #undef max 26 #endif 27 21 28 using namespace std; 22 29 using namespace zzub; … … 45 52 moveType = MachineViewMoveNothing; 46 53 SetRect(&prevDragRect, -1, -1, -1, -1); 54 prevConnectPos.x = prevConnectPos.y = -1; 47 55 48 56 dirtyOffscreenBitmap = true; … … 274 282 275 283 LRESULT CMachineView::OnRButtonDown(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) { 284 if (GetCapture() != 0) return 0; 285 276 286 POINT pt={LOWORD(lParam),HIWORD(lParam)}; 277 287 RECT mRect; … … 287 297 288 298 document->selectMachine(propMachine); 289 invalidateMachines(); 299 290 300 showMachineContext(pt, propMachine); 291 301 return 0; … … 302 312 303 313 if (isVolumeSlider) { 304 isVolumeSlider=false; 305 invalidateMachines(); 306 } 314 isVolumeSlider = false; 315 } 316 317 if (moveType != MachineViewMoveNothing) { 318 moveType = MachineViewMoveNothing; 319 dirtyBackground = true; 320 Invalidate(FALSE); 321 } 322 307 323 308 324 RECT rc; … … 383 399 offY=pt.y; 384 400 385 invalidateMachines();401 //invalidateMachines(); 386 402 387 403 // we are certainly clicking inside a machine: … … 401 417 if (!draggingMachine->minimized && conn && PtInRect(&pRect, pt)) { 402 418 initialPan = getConnectionPan(conn); 403 isPanSlider =true;404 moveType =MachineViewMovePanSlider;419 isPanSlider = true; 420 moveType = MachineViewMovePanSlider; 405 421 } else { 406 isConnecting=((wParam&MK_SHIFT) != 0) || mbuttonState ; 407 if (isConnecting) 408 moveType=MachineViewMoveConnectMachines; 422 isConnecting = ((wParam&MK_SHIFT) != 0) || mbuttonState ; 423 if (isConnecting) { 424 connectPos.x = (signed short)LOWORD(lParam); 425 connectPos.y = (signed short)HIWORD(lParam); 426 moveType = MachineViewMoveConnectMachines; 427 } 409 428 } 410 429 … … 444 463 } else { 445 464 document->clearSelectedMachines(); 446 invalidateMachines(); // selection is cleared, so lets447 465 } 448 466 … … 458 476 } 459 477 460 void minMaxRect(RECT* rcOut, RECT* rcIn) {461 if (rcIn->left < rcOut->left)462 rcOut->left = rcIn->left;463 if (rcIn->top < rcOut->top)464 rcOut->top = rcIn->top;465 if (rcIn->right > rcOut->right)466 rcOut->right = rcIn->right;467 if (rcIn->bottom > rcOut->bottom)468 rcOut->bottom = rcIn->bottom;469 }470 471 478 LRESULT CMachineView::OnMouseMove(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) { 472 479 473 if (moveType ==MachineViewMoveConnectMachines) {480 if (moveType == MachineViewMoveConnectMachines) { 474 481 if (((wParam&MK_SHIFT) != 0) || mbuttonState ) { 475 connectPos.x =(signed short)LOWORD(lParam);476 connectPos.y =(signed short)HIWORD(lParam);482 connectPos.x = (signed short)LOWORD(lParam); 483 connectPos.y = (signed short)HIWORD(lParam); 477 484 } else { 478 draggingMachine=0; 479 isConnecting=false; 480 moveType=MachineViewMoveNothing; // because, if we say there is connecting going on, and draggingMachine=0, there will be crashes 485 // shift or mbutton was released, stop connection action 486 // because, if we say there is connecting going on, and draggingMachine=0, there will be crashes 487 draggingMachine = 0; 488 isConnecting = false; 489 moveType = MachineViewMoveNothing; 490 prevConnectPos.x = prevConnectPos.y = -1; 481 491 ReleaseCapture(); 482 } 483 // redraw the line 484 invalidateMachines(); 492 dirtyBackground = true; 493 Invalidate(FALSE); 494 return 0; 495 } 496 497 // invalidate only the area covered by the line 498 499 dirtyConnecting = true; 500 501 RECT mRect; 502 getMachineRect(draggingMachine, &mRect); 503 POINT mp = { mRect.left + (mRect.right - mRect.left) / 2, mRect.top + (mRect.bottom - mRect.top) / 2 }; 504 505 RECT rcCurrent = { 506 std::min(mp.x, connectPos.x), std::min(mp.y, connectPos.y), 507 std::max(mp.x, connectPos.x), std::max(mp.y, connectPos.y), 508 }; 509 RECT rcPrev = { 510 std::min(mp.x, prevConnectPos.x), std::min(mp.y, prevConnectPos.y), 511 std::max(mp.x, prevConnectPos.x), std::max(mp.y, prevConnectPos.y), 512 }; 513 UnionRect(&rcCurrent, &rcCurrent, &rcPrev); 514 InflateRect(&rcCurrent, 1, 1); 515 InvalidateRect(&rcCurrent, FALSE); 485 516 } else 486 517 if (moveType==MachineViewMovePanSlider) { … … 530 561 getMachineRect(selplugin, &selrc); 531 562 InflateRect(&selrc, 3, 3); 532 minMaxRect(&rcInvalidate, &selrc);563 UnionRect(&rcInvalidate, &rcInvalidate, &selrc); 533 564 534 565 selplugin->x += mdx; … … 537 568 getMachineRect(selplugin, &selrc); 538 569 InflateRect(&selrc, 3, 3); 539 minMaxRect(&rcInvalidate, &selrc);570 UnionRect(&rcInvalidate, &rcInvalidate, &selrc); 540 571 541 572 // make sure the invalidation rect covers all machines we are connected to … … 546 577 getMachineRect(selconnplugin, &selrc); 547 578 InflateRect(&selrc, 3, 3); 548 minMaxRect(&rcInvalidate, &selrc);579 UnionRect(&rcInvalidate, &rcInvalidate, &selrc); 549 580 } 550 581 … … 555 586 getMachineRect(selconnplugin, &selrc); 556 587 InflateRect(&selrc, 3, 3); 557 minMaxRect(&rcInvalidate, &selrc);588 UnionRect(&rcInvalidate, &rcInvalidate, &selrc); 558 589 } 559 590 } … … 672 703 isLButtonDown=false; 673 704 674 if (moveType ==MachineViewMoveConnectMachines) {675 POINT pt ={LOWORD(lParam),HIWORD(lParam)};676 metaplugin* connectMachine =getMachineAtPt(pt);705 if (moveType == MachineViewMoveConnectMachines) { 706 POINT pt = {LOWORD(lParam),HIWORD(lParam)}; 707 metaplugin* connectMachine = getMachineAtPt(pt); 677 708 if (connectMachine && draggingMachine!=connectMachine) { 678 709 document->connectMachines(draggingMachine->getName(), connectMachine->getName()); 679 710 } 680 draggingMachine=0;681 isConnecting=false;682 683 i nvalidateMachines();711 712 draggingMachine = 0; 713 prevConnectPos.x = prevConnectPos.y = -1; 714 isConnecting = false; 684 715 ReleaseCapture(); 716 dirtyMachines = true; 717 Invalidate(FALSE); 685 718 } else 686 719 if (moveType==MachineViewMovePanSlider) { … … 702 735 if (moveType==MachineViewMoveSelectRectangle) { 703 736 ReleaseCapture(); 704 invalidateMachines();705 737 SetRect(&prevDragRect, -1, -1, -1, -1); 738 dirtyBackground = true; 739 dirtySelectionRectangle = false; 740 Invalidate(FALSE); 706 741 } else 707 742 if (moveType==MachineViewMoveNothing) { … … 724 759 screenDC.GetClipBox(&rcClip); 725 760 761 RECT rcClient; 762 GetClientRect(&rcClient); 726 763 if (dirtyOffscreenBitmap) { 727 764 if (offscreenBitmap.m_hBitmap) 728 765 offscreenBitmap.DeleteObject(); 729 766 730 RECT rcClient;731 GetClientRect(&rcClient);732 767 offscreenBitmap.CreateCompatibleBitmap(screenDC, rcClient.right, rcClient.bottom); 733 768 … … 737 772 } 738 773 774 if (dirtyBackground) dirtyMachines = true; 775 739 776 CBitmapHandle oldbitmap = offscreenDC.SelectBitmap(offscreenBitmap); 740 777 741 778 if (dirtyMachines) { 742 offscreenDC.FillSolidRect(rcClip.left, rcClip.top, rcClip.right - rcClip.left, rcClip.bottom - rcClip.top, backgroundColor); 779 if (dirtyBackground) 780 offscreenDC.FillSolidRect(rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, backgroundColor); else 781 offscreenDC.FillSolidRect(rcClip.left, rcClip.top, rcClip.right - rcClip.left, rcClip.bottom - rcClip.top, backgroundColor); 743 782 paintMachines(offscreenDC); 744 783 dirtyStatus = true; … … 754 793 paintSelectionRect(offscreenDC); 755 794 756 757 dirtyMachines = dirtySelectionRectangle = dirtyStatus = dirtyVolumeSlider = false; 795 if (dirtyConnecting) 796 paintConnectionLine(offscreenDC); 797 798 dirtyBackground = dirtyMachines = dirtySelectionRectangle = dirtyStatus = dirtyVolumeSlider = dirtyConnecting = false; 758 799 759 800 screenDC.BitBlt( … … 783 824 784 825 SetRect(rc, minx, miny, maxx, maxy); 785 }786 787 void CMachineView::paintSelectionRect(CDC& dc) {788 RECT rc;789 getDragRect(&rc);790 791 // SetRect(&rc, minx, miny, maxx-minx, maxy-miny);792 SIZE sz = { 2, 2 };793 794 if (prevDragRect.left==-1) {795 dc.DrawDragRect(&rc, sz, 0, sz);796 } else {797 dc.DrawDragRect(&rc, sz, &prevDragRect, sz);798 }799 800 prevDragRect = rc;801 826 } 802 827 … … 1096 1121 1097 1122 void CMachineView::invalidateMachines() { 1098 dirty Machines= true;1123 dirtyBackground = true; 1099 1124 Invalidate(FALSE); 1100 1125 } … … 1112 1137 void CMachineView::invalidateSelectionRectangle() { 1113 1138 dirtySelectionRectangle = true; 1114 Invalidate(FALSE); 1139 RECT rcSel; 1140 getDragRect(&rcSel); 1141 if (prevDragRect.left != -1) UnionRect(&rcSel, &rcSel, &prevDragRect); 1142 InvalidateRect(&rcSel, FALSE); 1115 1143 } 1116 1144 … … 1203 1231 pts[2].y=(hy+uy*-16*scale); 1204 1232 1233 CPenHandle oldPen = dc.SelectPen(borderPen); 1234 CBrushHandle oldBrush = dc.SelectBrush(arrowBrush); 1235 1205 1236 dc.Polygon(pts, 3); 1206 1237 … … 1216 1247 dc.TextOut(tp.x-4, tp.y-8, text.c_str()); 1217 1248 dc.SetBkMode(prevBkMode); 1249 1250 dc.SelectPen(oldPen); 1251 dc.SelectBrush(oldBrush); 1252 1218 1253 } 1219 1254 … … 1381 1416 1382 1417 void CMachineView::paintMachines(CDC& dc) { 1383 1384 1418 CPenHandle oldPen = dc.SelectPen(linePen); 1385 1419 … … 1406 1440 int destHalfWidth=(getMachineWidth(conn->plugin_in)/2) * scale; 1407 1441 int destHalfHeight=(getMachineHeight(conn->plugin_in)/2) * scale; 1442 1408 1443 1409 1444 getMachineRect(conn->plugin_in, &sRect); … … 1424 1459 } 1425 1460 }*/ 1426 dc.SelectPen(borderPen);1427 dc.SelectBrush(arrowBrush);1428 1461 drawDirectionTriangle(dc, mRect, sRect, conntxt); 1429 dc.SelectPen(linePen); 1430 } 1431 } 1432 1433 if (draggingMachine && isConnecting) { 1434 int halfWidth=(getMachineWidth(draggingMachine)/2) * scale; 1435 int halfHeight=(getMachineHeight(draggingMachine)/2) * scale; 1436 RECT mRect; 1437 getMachineRect(draggingMachine, &mRect); 1438 dc.MoveTo(mRect.left+halfWidth, mRect.top+halfHeight, 0); 1439 dc.LineTo(connectPos.x, connectPos.y); 1440 } 1462 } 1463 } 1464 1441 1465 dc.SelectPen(oldPen); 1442 1466 … … 1497 1521 1498 1522 void CMachineView::paintVolume(CDC& dc) { 1499 if ( !isVolumeSlider) return ;1523 if (moveType != MachineViewMoveVolumeSlider) return ; 1500 1524 connection* conn=document->getSelectedConnection(); 1501 1525 int amp = 0x4000; … … 1510 1534 getVolumeSliderRect(conn, &vsr); 1511 1535 drawVolumeSlider(dc, vsr, amp); 1536 } 1537 1538 1539 void CMachineView::paintSelectionRect(CDC& dc) { 1540 RECT rc; 1541 getDragRect(&rc); 1542 1543 SIZE sz = { 2, 2 }; 1544 1545 if (prevDragRect.left==-1) { 1546 dc.DrawDragRect(&rc, sz, 0, sz); 1547 } else { 1548 dc.DrawDragRect(&rc, sz, &prevDragRect, sz); 1549 } 1550 1551 prevDragRect = rc; 1552 } 1553 1554 void CMachineView::paintConnectionLine(CDC& dc) { 1555 1556 if (draggingMachine && moveType == MachineViewMoveConnectMachines) { 1557 1558 int halfWidth = (getMachineWidth(draggingMachine)/2) * scale; 1559 int halfHeight = (getMachineHeight(draggingMachine)/2) * scale; 1560 1561 RECT mRect; 1562 getMachineRect(draggingMachine, &mRect); 1563 1564 CPenHandle oldPen = dc.SelectPen(linePen); 1565 int prevROP = dc.SetROP2(R2_NOT); 1566 1567 if (prevConnectPos.x != -1) { 1568 dc.MoveTo(mRect.left + halfWidth, mRect.top + halfHeight, 0); 1569 dc.LineTo(prevConnectPos.x, prevConnectPos.y); 1570 } 1571 1572 dc.MoveTo(mRect.left + halfWidth, mRect.top + halfHeight, 0); 1573 dc.LineTo(connectPos.x, connectPos.y); 1574 1575 dc.SetROP2(prevROP); 1576 dc.SelectPen(oldPen); 1577 1578 prevConnectPos = connectPos; 1579 } 1580 1512 1581 } 1513 1582 … … 1557 1626 document->selectMachine(machine); 1558 1627 } 1559 invalidateMachines();1560 1628 return 0; 1561 1629 } … … 1563 1631 LRESULT CMachineView::OnClearSelection(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled) { 1564 1632 document->clearSelectedMachines(); 1565 invalidateMachines();1566 1633 return 0; 1567 1634 } … … 1576 1643 document->clearSelectedMachines(); 1577 1644 document->selectMachine(document->player->master); 1578 invalidateMachines();1579 1645 break; 1580 1646 case UpdateMachines: -
trunk/src/buzelib/MachineView.h
r1297 r1298 31 31 zzub::metaplugin* draggingMachine; 32 32 bool isConnecting, isVolumeSlider, isPanSlider; 33 POINT connectPos, beginDragPt;33 POINT connectPos, prevConnectPos, beginDragPt; 34 34 RECT prevDragRect; 35 35 std::vector<zzub::metaplugin*> machinesInDragRect; … … 66 66 CBrush ampHandleBrush; 67 67 68 bool dirty Machines, dirtyStatus, dirtySelectionRectangle, dirtyVolumeSlider;68 bool dirtyBackground, dirtyMachines, dirtyStatus, dirtySelectionRectangle, dirtyVolumeSlider, dirtyConnecting; 69 69 bool dirtyOffscreenBitmap; 70 70 CBitmap offscreenBitmap; … … 176 176 void paintMachineStatus(CDC& dc); 177 177 void paintSelectionRect(CDC& dc); 178 void paintConnectionLine(CDC& dc); 178 179 void showMachineContext(POINT pt, zzub::metaplugin* mac); 179 180 void showConnectionContext(POINT pt, zzub::connection* conn);
