Changeset 1302

Show
Ignore:
Timestamp:
11/05/07 01:10:45 (10 months ago)
Author:
calvin
Message:

optimized machine view led updating, pattern editor selecting and scrolling

Location:
trunk/src/buzelib
Files:
3 modified

Legend:

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

    r1301 r1302  
    11591159                if (!machine) continue; 
    11601160                if (machine->nonSongPlugin) continue; 
    1161                 RECT rc; 
    1162                 getStatusRect(machine, &rc); 
    1163                 InvalidateRect(&rc, FALSE); 
     1161 
     1162                std::map<zzub::metaplugin*, bool>::iterator ledState = ledStates.find(machine); 
     1163 
     1164                bool newState = machine->lastWorkState || machine->lastMidiState; 
     1165 
     1166                if (ledState == ledStates.end() || newState != ledState->second) { 
     1167                        RECT rc; 
     1168                        getStatusRect(machine, &rc); 
     1169                        InvalidateRect(&rc, FALSE); 
     1170                } 
    11641171        } 
    11651172} 
     
    14941501                getStatusRect(machine, &rc); 
    14951502 
    1496                 MachineSkin* skin = mainFrame->getSkin(machine->loader->plugin_info->uri); 
    1497                 if (skin && skin->led && !machine->minimized) { 
    1498                         CDC bitmapDC; 
    1499                         bitmapDC.CreateCompatibleDC(0); 
    1500                         bitmapDC.SelectBitmap(skin->led); 
    1501                         BITMAP bm; 
    1502                         ::GetObject(skin->led, sizeof(bm), &bm); 
    1503  
    1504                         if (machine->lastWorkState || machine->lastMidiState) { 
    1505                                 dc.StretchBlt(rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, bitmapDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); 
     1503                std::map<zzub::metaplugin*, bool>::iterator ledState = ledStates.find(machine); 
     1504 
     1505                bool newState = machine->lastWorkState || machine->lastMidiState; 
     1506 
     1507                if (dirtyMachines || ledState == ledStates.end() || newState != ledState->second) { 
     1508 
     1509                        MachineSkin* skin = mainFrame->getSkin(machine->loader->plugin_info->uri); 
     1510                        if (skin && skin->led && !machine->minimized) { 
     1511                                CDC bitmapDC; 
     1512                                bitmapDC.CreateCompatibleDC(0); 
     1513                                bitmapDC.SelectBitmap(skin->led); 
     1514                                BITMAP bm; 
     1515                                ::GetObject(skin->led, sizeof(bm), &bm); 
     1516 
     1517                                if (newState) { 
     1518                                        dc.StretchBlt(rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, bitmapDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); 
     1519                                } else { 
     1520                                        // draw a rectangle from the machine skin where the led is drawn 
     1521                                        drawMachine(dc, machine, true); 
     1522                                } 
    15061523                        } else { 
    1507                                 // draw a rectangle from the machine skin where the led is drawn 
    1508                                 drawMachine(dc, machine, true); 
     1524                                CBrushHandle prevBrush = dc.SelectBrush(getMachineLedBrush(machine)); 
     1525                                dc.Rectangle(&rc); 
     1526                                dc.SelectBrush(prevBrush); 
    15091527                        } 
    1510                 } else { 
    1511                         CBrushHandle prevBrush = dc.SelectBrush(getMachineLedBrush(machine)); 
    1512                         dc.Rectangle(&rc); 
    1513                         dc.SelectBrush(prevBrush); 
     1528 
     1529                        ledStates[machine] = newState; 
    15141530                } 
    15151531 
     
    16491665                case UpdateNewDocument: 
    16501666                case UpdateOpenDocument: 
     1667                        ledStates.clear(); 
    16511668                        document->clearSelectedMachines(); 
    16521669                        document->selectMachine(document->player->master); 
     1670                        break; 
     1671                case UpdateDeleteMachine: 
     1672                        ledStates.clear(); 
    16531673                        break; 
    16541674                case UpdateMachines: 
  • trunk/src/buzelib/MachineView.h

    r1298 r1302  
    6969        bool dirtyOffscreenBitmap; 
    7070        CBitmap offscreenBitmap; 
     71 
     72        std::map<zzub::metaplugin*, bool> ledStates; 
     73 
    7174public: 
    7275        double scale; 
  • trunk/src/buzelib/PatternEditor/PatternEditorInner.cpp

    r1287 r1302  
    103103        dc.SetBkColor(colors[PE_BG]); 
    104104        dc.SetTextColor(colors[PE_TextValue]); 
    105         dc.FillSolidRect(&rcClient, colors[PE_BG]); 
     105        dc.FillSolidRect(&dc.m_rc, colors[PE_BG]); 
    106106 
    107107        int screenrows = rcClient.bottom / font_size.cy; 
    108  
    109         for (int i = 0; i <= screenrows && i+scroll.y < rows; i++) { 
     108        int cliprows = dc.m_rc.bottom / font_size.cy; 
     109        int firscliprow = dc.m_rc.top / font_size.cy; 
     110 
     111        for (int i = firscliprow; i <= cliprows && i+scroll.y < rows; i++) { 
    110112                int src_y = (i + scroll.y) * font_size.cy; 
    111113                int dest_y = i * font_size.cy; 
     
    189191bool CPatternEditorInner::GetRangeRectScreen(int from_col, int from_row, int to_col, int to_row, RECT* rc) { 
    190192        if (from_col == -1) return false; 
     193        if (columns.size() == 0) return false; 
    191194 
    192195        int left_col = std::min(from_col, to_col); 
     
    356359 
    357360                if (mouse_mode == mouse_mode_drag) { 
     361                        RECT rcPrevDrag; 
     362                        int sel_width = select_end.x - select_start.x; 
     363                        int sel_height = select_end.y - select_start.y; 
     364                        if (!GetRangeRectScreen(drag_to.x, drag_to.y, drag_to.x + sel_width, drag_to.y + sel_height, &rcPrevDrag)) { 
     365                                rcPrevDrag.left = -1; 
     366                        } 
     367 
    358368                        int scroll_diff_y = (scroll.y - drag_scroll.y); 
    359369                        int scroll_diff_x = (scroll.x - drag_scroll.x); 
     
    373383 
    374384                        GetParent().SendMessage(WM_COMMAND, MAKEWPARAM(ID_PATTERNEDITOR_SELDRAG, 0), 0); 
    375                         Invalidate(FALSE); 
     385                         
     386                        // invalidate drag rect 
     387                        RECT rcDrag; 
     388 
     389                        if (!GetRangeRectScreen(drag_to.x, drag_to.y, drag_to.x + sel_width, drag_to.y + sel_height, &rcDrag)) 
     390                                rcDrag.left = -1; 
     391 
     392                        if (rcPrevDrag.left != -1 && rcDrag.left != -1) { 
     393                                UnionRect(&rcDrag, &rcDrag, &rcPrevDrag); 
     394                        } else 
     395                        if (rcDrag.left == -1) { 
     396                                rcDrag = rcPrevDrag; 
     397                        } 
     398 
     399                        if (rcDrag.left != -1) 
     400                                InvalidateRect(&rcDrag, FALSE); 
    376401                } 
    377402 
     
    490515        if (scroll.x != last_x) { 
    491516                ScrollWindow((last_x - scroll.x) * font_size.cx, 0); 
    492                 UpdateWindow(); 
    493517                GetParent().SendMessage(WM_COMMAND, MAKEWPARAM(ID_PATTERNEDITOR_SCROLLED, 0), 0); 
    494518        } 
     
    524548 
    525549        if (scroll.y != last_y) { 
    526                 LockWindowUpdate(); 
    527550                ScrollWindow(0, (last_y - scroll.y) * font_size.cy); 
    528                 UpdateWindow(); 
    529551                GetParent().SendMessage(WM_COMMAND, MAKEWPARAM(ID_PATTERNEDITOR_SCROLLED, 0), 0); 
    530                 LockWindowUpdate(FALSE); 
    531552        } 
    532553 
     
    971992        ScrollWindow((scroll.x - new_scroll.x) * font_size.cx, (scroll.y - new_scroll.y) * font_size.cy, 0); 
    972993        scroll = new_scroll; 
    973         UpdateWindow(); 
    974994        UpdateCaretPosition(); 
    975995        GetParent().SendMessage(WM_COMMAND, MAKEWPARAM(ID_PATTERNEDITOR_SCROLLED, 0), 0); 
     
    10171037 
    10181038void CPatternEditorInner::SelectRange(int from_col, int from_row, int to_col, int to_row) { 
     1039        RECT rcPrevSel; 
     1040        if (!GetSelectionRectScreen(&rcPrevSel)) 
     1041                rcPrevSel.left = -1; 
     1042 
    10191043        select_first.x = from_col; 
    10201044        select_first.y = from_row; 
     
    10311055        SortSelection(); 
    10321056        if (!m_hWnd) return ; 
    1033         Invalidate(FALSE); 
    1034         GetParent().SendMessage(WM_COMMAND, MAKEWPARAM(ID_PATTERNEDITOR_SELCHANGED, 0), 0); 
     1057 
     1058        RECT rcSel; 
     1059        if (!GetSelectionRectScreen(&rcSel)) 
     1060                rcSel.left = -1; 
     1061 
     1062        if (rcSel.left != -1 && rcPrevSel.left != -1) { 
     1063                UnionRect(&rcSel, &rcSel, &rcPrevSel); 
     1064        } else  
     1065        if (rcSel.left == -1) { 
     1066                rcSel = rcPrevSel; 
     1067        } 
     1068 
     1069        if (rcSel.left != -1) { 
     1070                InvalidateRect(&rcSel, FALSE); 
     1071                GetParent().SendMessage(WM_COMMAND, MAKEWPARAM(ID_PATTERNEDITOR_SELCHANGED, 0), 0); 
     1072        } 
    10351073} 
    10361074