Ticket #7503: only_repaint_if_changed.patch
| File only_repaint_if_changed.patch, 4.1 KB (added by , 14 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
251 251 * @return true if a repaint is required 252 252 */ 253 253 private boolean removeHighlighting() { 254 System.out.println("removing highlights"); 254 255 boolean needsRepaint = false; 255 256 DataSet ds = getCurrentDataSet(); 256 257 if(ds != null && !ds.getHighlightedVirtualNodes().isEmpty()) { … … 267 268 return true; 268 269 } 269 270 271 private boolean repaintIfRequired(HashSet<OsmPrimitive> newHighlights) { 272 if(!drawTargetHighlight) 273 return false; 274 275 boolean needsRepaint = false; 276 for(OsmPrimitive x : newHighlights) { 277 if(oldHighlights.contains(x)) { 278 continue; 279 } 280 needsRepaint = true; 281 x.setHighlighted(true); 282 } 283 oldHighlights.removeAll(newHighlights); 284 for(OsmPrimitive x : oldHighlights) { 285 x.setHighlighted(false); 286 needsRepaint = true; 287 } 288 oldHighlights = newHighlights; 289 if(needsRepaint) { 290 System.out.println("repainting" + System.currentTimeMillis()); 291 } 292 return needsRepaint; 293 } 294 270 295 /** 271 296 * handles adding highlights and updating the cursor for the given mouse event. 272 297 * Please note that the highlighting for merging while moving is handled via mouseDragged. … … 285 310 * @return true if repaint is required 286 311 */ 287 312 private boolean giveUserFeedback(MouseEvent e, int modifiers) { 288 boolean needsRepaint = false;289 290 313 Collection<OsmPrimitive> c = MapView.asColl( 291 314 mv.getNearestNodeOrWay(e.getPoint(), OsmPrimitive.isSelectablePredicate, true)); 292 315 293 316 updateKeyModifiers(modifiers); 294 317 determineMapMode(!c.isEmpty()); 295 318 296 if(drawTargetHighlight) { 297 needsRepaint = removeHighlighting(); 298 } 319 HashSet<OsmPrimitive> newHighlights = new HashSet<OsmPrimitive>(); 299 320 300 321 virtualWays.clear(); 301 322 virtualNode = null; 302 323 if(mode == Mode.move && setupVirtual(e)) { 303 324 DataSet ds = getCurrentDataSet(); 304 if (ds != null ) {305 if(drawTargetHighlight)ds.setHighlightedVirtualNodes(virtualWays);325 if (ds != null && drawTargetHighlight) { 326 ds.setHighlightedVirtualNodes(virtualWays); 306 327 } 307 328 mv.setNewCursor(SelectActionCursor.virtual_node.cursor(), this); 308 329 // don't highlight anything else if a virtual node will be 309 return drawTargetHighlight; // if no highlighting, repaint is not needed330 return repaintIfRequired(newHighlights); 310 331 } 311 332 312 333 mv.setNewCursor(getCursor(c), this); 313 334 314 335 // return early if there can't be any highlights 315 336 if(!drawTargetHighlight || mode != Mode.move || c.isEmpty()) 316 return needsRepaint;337 return repaintIfRequired(newHighlights); 317 338 318 339 // CTRL toggles selection, but if while dragging CTRL means merge 319 340 final boolean isToggleMode = ctrl && !dragInProgress(); … … 322 343 // when clicked. I.e. don't highlight selected elements unless 323 344 // we are in toggle mode. 324 345 if(isToggleMode || !x.isSelected()) { 325 x.setHighlighted(true); 326 oldHighlights.add(x); 346 newHighlights.add(x); 327 347 } 328 348 } 329 return needsRepaint || !oldHighlights.isEmpty();349 return repaintIfRequired(newHighlights); 330 350 } 331 351 332 352 /** … … 445 465 return; 446 466 447 467 Command c = !Main.main.undoRedo.commands.isEmpty() 448 ? Main.main.undoRedo.commands.getLast() : null;468 ? Main.main.undoRedo.commands.getLast() : null; 449 469 if (c instanceof SequenceCommand) { 450 470 c = ((SequenceCommand) c).getLastCommand(); 451 471 }
