Changeset 5093 in josm


Ignore:
Timestamp:
2012-03-17T11:18:59+01:00 (12 years ago)
Author:
xeen
Message:

only repaint when the to-be-highlighted primitives change.

The patch only affects the select mode when not dragging. While this should
reduce CPU usage with target highlighting enabled, it’s doubtful it will have
visible effect on those systems where target highlighting feels sluggish. See
#7503 for more ideas to improve the situation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r5075 r5093  
    268268    }
    269269
     270    private boolean repaintIfRequired(HashSet<OsmPrimitive> newHighlights) {
     271        if(!drawTargetHighlight)
     272            return false;
     273
     274        boolean needsRepaint = false;
     275        for(OsmPrimitive x : newHighlights) {
     276            if(oldHighlights.contains(x)) {
     277                continue;
     278            }
     279            needsRepaint = true;
     280            x.setHighlighted(true);
     281        }
     282        oldHighlights.removeAll(newHighlights);
     283        for(OsmPrimitive x : oldHighlights) {
     284            x.setHighlighted(false);
     285            needsRepaint = true;
     286        }
     287        oldHighlights = newHighlights;
     288        return needsRepaint;
     289    }
     290
    270291    /**
    271292     * handles adding highlights and updating the cursor for the given mouse event.
     
    286307     */
    287308    private boolean giveUserFeedback(MouseEvent e, int modifiers) {
    288         boolean needsRepaint = false;
    289 
    290309        Collection<OsmPrimitive> c = MapView.asColl(
    291310                mv.getNearestNodeOrWay(e.getPoint(), OsmPrimitive.isSelectablePredicate, true));
     
    294313        determineMapMode(!c.isEmpty());
    295314
    296         if(drawTargetHighlight) {
    297             needsRepaint = removeHighlighting();
    298         }
     315        HashSet<OsmPrimitive> newHighlights = new HashSet<OsmPrimitive>();
    299316
    300317        virtualWays.clear();
     
    302319        if(mode == Mode.move && setupVirtual(e)) {
    303320            DataSet ds = getCurrentDataSet();
    304             if (ds != null) {
    305                 if(drawTargetHighlight) ds.setHighlightedVirtualNodes(virtualWays);
     321            if (ds != null && drawTargetHighlight) {
     322                ds.setHighlightedVirtualNodes(virtualWays);
    306323            }
    307324            mv.setNewCursor(SelectActionCursor.virtual_node.cursor(), this);
    308325            // don't highlight anything else if a virtual node will be
    309             return drawTargetHighlight; // if no highlighting, repaint is not needed
     326            return repaintIfRequired(newHighlights);
    310327        }
    311328
     
    314331        // return early if there can't be any highlights
    315332        if(!drawTargetHighlight || mode != Mode.move || c.isEmpty())
    316             return needsRepaint;
     333            return repaintIfRequired(newHighlights);
    317334
    318335        // CTRL toggles selection, but if while dragging CTRL means merge
     
    323340            // we are in toggle mode.
    324341            if(isToggleMode || !x.isSelected()) {
    325                 x.setHighlighted(true);
    326                 oldHighlights.add(x);
    327             }
    328         }
    329         return needsRepaint || !oldHighlights.isEmpty();
     342                newHighlights.add(x);
     343            }
     344        }
     345        return repaintIfRequired(newHighlights);
    330346    }
    331347
Note: See TracChangeset for help on using the changeset viewer.