| 
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -32,6 +32,26 @@ struct stable_cursor_hook : df::viewscreen_dwarfmodest
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    bool check_viewport_near_enough()
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        df::coord view = Gui::getViewportPos();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        auto dims = Gui::getDwarfmodeViewDims();
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        int view_size = min(dims.map_x2 - dims.map_x1, dims.map_y2 - dims.map_y1);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        // Heuristic to keep the cursor position if the view is still in the
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        // part of the map that was already visible
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        int near_enough_distance = min(30, view_size / 2);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        return
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            // Is the viewport near enough to the old viewport?
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            abs(view.x - last_view.x) <= near_enough_distance &&
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            abs(view.y - last_view.y) <= near_enough_distance &&
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            view.z == last_view.z &&
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            // And is the last cursor visible in the current viewport?
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            last_cursor.x >= view.x && last_cursor.y >= view.y &&
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            last_cursor.x <= view.x + dims.map_x2 - dims.map_x1 &&
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            last_cursor.y <= view.y + dims.map_y2 - dims.map_y1;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    DEFINE_VMETHOD_INTERPOSE(void, feed, (set<df::interface_key> *input))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				    {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        bool was_default = check_default();
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -47,9 +67,8 @@ struct stable_cursor_hook : df::viewscreen_dwarfmodest
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            last_view = view; last_cursor = cursor;
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        }
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        else if (!is_default && was_default &&
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                 Gui::getViewportPos() == last_view &&
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                 last_cursor.isValid() && cur_cursor.isValid())
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        else if (!is_default && was_default && cur_cursor.isValid() &&
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				                 last_cursor.isValid() && check_viewport_near_enough())
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				        {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            Gui::setCursorCoords(last_cursor.x, last_cursor.y, last_cursor.z);
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				            Gui::refreshSidebar();
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
			
			 | 
			 | 
			
				
 
 |