Changeset 1298

Show
Ignore:
Timestamp:
11/01/07 21:19:30 (10 months ago)
Author:
calvin
Message:

faster machine view redrawing when connecting and selecting

Location:
trunk/src/buzelib
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/buzelib/MachineView.cpp

    r1297 r1298  
    1919#include "Utils/Keymaps.h" 
    2020 
     21#ifdef min 
     22#undef min 
     23#endif 
     24#ifdef max 
     25#undef max 
     26#endif 
     27 
    2128using namespace std; 
    2229using namespace zzub; 
     
    4552        moveType = MachineViewMoveNothing; 
    4653        SetRect(&prevDragRect, -1, -1, -1, -1); 
     54        prevConnectPos.x = prevConnectPos.y = -1; 
    4755 
    4856        dirtyOffscreenBitmap = true; 
     
    274282 
    275283LRESULT CMachineView::OnRButtonDown(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) { 
     284        if (GetCapture() != 0) return 0; 
     285 
    276286        POINT pt={LOWORD(lParam),HIWORD(lParam)}; 
    277287        RECT mRect; 
     
    287297 
    288298                document->selectMachine(propMachine); 
    289                 invalidateMachines(); 
     299 
    290300                showMachineContext(pt, propMachine); 
    291301                return 0; 
     
    302312 
    303313        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 
    307323 
    308324        RECT rc; 
     
    383399                offY=pt.y; 
    384400 
    385                 invalidateMachines(); 
     401                //invalidateMachines(); 
    386402                 
    387403                // we are certainly clicking inside a machine: 
     
    401417                if (!draggingMachine->minimized && conn && PtInRect(&pRect, pt)) { 
    402418                        initialPan = getConnectionPan(conn); 
    403                         isPanSlider=true; 
    404                         moveType=MachineViewMovePanSlider; 
     419                        isPanSlider = true; 
     420                        moveType = MachineViewMovePanSlider; 
    405421                } 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                        } 
    409428                } 
    410429 
     
    444463                } else { 
    445464                        document->clearSelectedMachines(); 
    446                         invalidateMachines();   // selection is cleared, so lets  
    447465                } 
    448466 
     
    458476} 
    459477 
    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  
    471478LRESULT CMachineView::OnMouseMove(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) { 
    472479 
    473         if (moveType==MachineViewMoveConnectMachines) { 
     480        if (moveType == MachineViewMoveConnectMachines) { 
    474481                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); 
    477484                } 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; 
    481491                        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); 
    485516        } else 
    486517        if (moveType==MachineViewMovePanSlider) { 
     
    530561                        getMachineRect(selplugin, &selrc); 
    531562                        InflateRect(&selrc, 3, 3); 
    532                         minMaxRect(&rcInvalidate, &selrc); 
     563                        UnionRect(&rcInvalidate, &rcInvalidate, &selrc); 
    533564 
    534565                        selplugin->x += mdx; 
     
    537568                        getMachineRect(selplugin, &selrc); 
    538569                        InflateRect(&selrc, 3, 3); 
    539                         minMaxRect(&rcInvalidate, &selrc); 
     570                        UnionRect(&rcInvalidate, &rcInvalidate, &selrc); 
    540571 
    541572                        // make sure the invalidation rect covers all machines we are connected to 
     
    546577                                getMachineRect(selconnplugin, &selrc); 
    547578                                InflateRect(&selrc, 3, 3); 
    548                                 minMaxRect(&rcInvalidate, &selrc); 
     579                                UnionRect(&rcInvalidate, &rcInvalidate, &selrc); 
    549580                        } 
    550581 
     
    555586                                getMachineRect(selconnplugin, &selrc); 
    556587                                InflateRect(&selrc, 3, 3); 
    557                                 minMaxRect(&rcInvalidate, &selrc); 
     588                                UnionRect(&rcInvalidate, &rcInvalidate, &selrc); 
    558589                        } 
    559590                } 
     
    672703        isLButtonDown=false; 
    673704 
    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); 
    677708                if (connectMachine && draggingMachine!=connectMachine) { 
    678709                        document->connectMachines(draggingMachine->getName(), connectMachine->getName()); 
    679710                } 
    680                 draggingMachine=0; 
    681                 isConnecting=false; 
    682  
    683                 invalidateMachines(); 
     711                 
     712                draggingMachine = 0; 
     713                prevConnectPos.x = prevConnectPos.y = -1; 
     714                isConnecting = false; 
    684715                ReleaseCapture(); 
     716                dirtyMachines = true; 
     717                Invalidate(FALSE); 
    685718        } else 
    686719        if (moveType==MachineViewMovePanSlider) { 
     
    702735        if (moveType==MachineViewMoveSelectRectangle) { 
    703736                ReleaseCapture(); 
    704                 invalidateMachines(); 
    705737                SetRect(&prevDragRect, -1, -1, -1, -1); 
     738                dirtyBackground = true; 
     739                dirtySelectionRectangle = false; 
     740                Invalidate(FALSE); 
    706741        } else  
    707742        if (moveType==MachineViewMoveNothing) { 
     
    724759        screenDC.GetClipBox(&rcClip); 
    725760 
     761        RECT rcClient; 
     762        GetClientRect(&rcClient); 
    726763        if (dirtyOffscreenBitmap) { 
    727764                if (offscreenBitmap.m_hBitmap) 
    728765                        offscreenBitmap.DeleteObject(); 
    729766 
    730                 RECT rcClient; 
    731                 GetClientRect(&rcClient); 
    732767                offscreenBitmap.CreateCompatibleBitmap(screenDC, rcClient.right, rcClient.bottom); 
    733768 
     
    737772        } 
    738773 
     774        if (dirtyBackground) dirtyMachines = true; 
     775 
    739776        CBitmapHandle oldbitmap = offscreenDC.SelectBitmap(offscreenBitmap); 
    740777 
    741778        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); 
    743782                paintMachines(offscreenDC); 
    744783                dirtyStatus = true; 
     
    754793                paintSelectionRect(offscreenDC); 
    755794 
    756  
    757         dirtyMachines = dirtySelectionRectangle = dirtyStatus = dirtyVolumeSlider = false; 
     795        if (dirtyConnecting) 
     796                paintConnectionLine(offscreenDC); 
     797 
     798        dirtyBackground = dirtyMachines = dirtySelectionRectangle = dirtyStatus = dirtyVolumeSlider = dirtyConnecting = false; 
    758799 
    759800    screenDC.BitBlt( 
     
    783824 
    784825        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; 
    801826} 
    802827 
     
    10961121 
    10971122void CMachineView::invalidateMachines() { 
    1098         dirtyMachines = true; 
     1123        dirtyBackground = true; 
    10991124        Invalidate(FALSE); 
    11001125} 
     
    11121137void CMachineView::invalidateSelectionRectangle() { 
    11131138        dirtySelectionRectangle = true; 
    1114         Invalidate(FALSE); 
     1139        RECT rcSel; 
     1140        getDragRect(&rcSel); 
     1141        if (prevDragRect.left != -1) UnionRect(&rcSel, &rcSel, &prevDragRect); 
     1142        InvalidateRect(&rcSel, FALSE); 
    11151143} 
    11161144 
     
    12031231        pts[2].y=(hy+uy*-16*scale); 
    12041232 
     1233        CPenHandle oldPen = dc.SelectPen(borderPen); 
     1234        CBrushHandle oldBrush = dc.SelectBrush(arrowBrush); 
     1235 
    12051236        dc.Polygon(pts, 3); 
    12061237 
     
    12161247        dc.TextOut(tp.x-4, tp.y-8, text.c_str()); 
    12171248        dc.SetBkMode(prevBkMode); 
     1249 
     1250        dc.SelectPen(oldPen); 
     1251        dc.SelectBrush(oldBrush); 
     1252 
    12181253} 
    12191254 
     
    13811416 
    13821417void CMachineView::paintMachines(CDC& dc) { 
    1383  
    13841418        CPenHandle oldPen = dc.SelectPen(linePen); 
    13851419 
     
    14061440                        int destHalfWidth=(getMachineWidth(conn->plugin_in)/2) * scale; 
    14071441                        int destHalfHeight=(getMachineHeight(conn->plugin_in)/2) * scale; 
     1442 
    14081443 
    14091444                        getMachineRect(conn->plugin_in, &sRect); 
     
    14241459                                } 
    14251460                        }*/ 
    1426                         dc.SelectPen(borderPen); 
    1427                         dc.SelectBrush(arrowBrush); 
    14281461                        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 
    14411465        dc.SelectPen(oldPen); 
    14421466 
     
    14971521 
    14981522void CMachineView::paintVolume(CDC& dc) { 
    1499         if (!isVolumeSlider) return ; 
     1523        if (moveType != MachineViewMoveVolumeSlider) return ; 
    15001524        connection* conn=document->getSelectedConnection(); 
    15011525        int amp = 0x4000; 
     
    15101534        getVolumeSliderRect(conn, &vsr); 
    15111535        drawVolumeSlider(dc, vsr, amp); 
     1536} 
     1537 
     1538 
     1539void 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 
     1554void 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 
    15121581} 
    15131582 
     
    15571626                document->selectMachine(machine); 
    15581627        } 
    1559         invalidateMachines(); 
    15601628        return 0; 
    15611629} 
     
    15631631LRESULT CMachineView::OnClearSelection(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled) { 
    15641632        document->clearSelectedMachines(); 
    1565         invalidateMachines(); 
    15661633        return 0; 
    15671634} 
     
    15761643                        document->clearSelectedMachines(); 
    15771644                        document->selectMachine(document->player->master); 
    1578                         invalidateMachines(); 
    15791645                        break; 
    15801646                case UpdateMachines: 
  • trunk/src/buzelib/MachineView.h

    r1297 r1298  
    3131        zzub::metaplugin* draggingMachine; 
    3232        bool isConnecting, isVolumeSlider, isPanSlider; 
    33         POINT connectPos, beginDragPt; 
     33        POINT connectPos, prevConnectPos, beginDragPt; 
    3434        RECT prevDragRect; 
    3535        std::vector<zzub::metaplugin*> machinesInDragRect; 
     
    6666        CBrush ampHandleBrush; 
    6767 
    68         bool dirtyMachines, dirtyStatus, dirtySelectionRectangle, dirtyVolumeSlider; 
     68        bool dirtyBackground, dirtyMachines, dirtyStatus, dirtySelectionRectangle, dirtyVolumeSlider, dirtyConnecting; 
    6969        bool dirtyOffscreenBitmap; 
    7070        CBitmap offscreenBitmap; 
     
    176176        void paintMachineStatus(CDC& dc); 
    177177        void paintSelectionRect(CDC& dc); 
     178        void paintConnectionLine(CDC& dc); 
    178179        void showMachineContext(POINT pt, zzub::metaplugin* mac); 
    179180        void showConnectionContext(POINT pt, zzub::connection* conn);