MCPcopy Create free account
hub / github.com/AdaCompNUS/summit / _compute_scale

Method _compute_scale

PythonAPI/examples/no_rendering_mode.py:1252–1272  ·  view source on GitHub ↗

Based on the mouse wheel and mouse position, it will compute the scale and move the map so that it is zoomed in or out based on mouse position

(self, scale_factor)

Source from the content-addressed store, hash-verified

1250 self.result_surface.set_clip(clipping_rect)
1251
1252 def _compute_scale(self, scale_factor):
1253 """Based on the mouse wheel and mouse position, it will compute the scale and move the map so that it is zoomed in or out based on mouse position"""
1254 m = self._input.mouse_pos
1255
1256 # Percentage of surface where mouse position is actually
1257 px = (m[0] - self.scale_offset[0]) / float(self.prev_scaled_size)
1258 py = (m[1] - self.scale_offset[1]) / float(self.prev_scaled_size)
1259
1260 # Offset will be the previously accumulated offset added with the
1261 # difference of mouse positions in the old and new scales
1262 diff_between_scales = ((float(self.prev_scaled_size) * px) - (float(self.scaled_size) * px),
1263 (float(self.prev_scaled_size) * py) - (float(self.scaled_size) * py))
1264
1265 self.scale_offset = (self.scale_offset[0] + diff_between_scales[0],
1266 self.scale_offset[1] + diff_between_scales[1])
1267
1268 # Update previous scale
1269 self.prev_scaled_size = self.scaled_size
1270
1271 # Scale performed
1272 self.map_image.scale_map(scale_factor)
1273
1274 def render(self, display):
1275 """Renders the map and all the actors in hero and map mode"""

Callers 1

renderMethod · 0.95

Calls 1

scale_mapMethod · 0.80

Tested by

no test coverage detected