def ProcessMotion(vf_time):
  """Process pygame events for the window. Mousedown in the target area
  starts the simulation. Mouse movement is reported to the 'vf_time' arg
  to adjust the current time. Mouseup stop the simulation.
  """
  last_pos = None
  for event in pygame.event.get():
    if event.type == pygame.QUIT or event.type == pygame.KEYDOWN:
      return sys.exit(0)
    if vf_time.IsActive():
      if event.type == pygame.MOUSEMOTION:
        if event.buttons[0]:
          last_pos = event.pos
      elif event.type == pygame.MOUSEBUTTONUP:
        if event.button == 1:
          vf_time.Stop()
    else:
      if event.type == pygame.MOUSEBUTTONDOWN:
        if event.button == 1:
          pos = PixelsToDimensions(event.pos)
          x, y = pos
          if x > iphone_dims[0] - target_box_width - target_box_padding and \
                x < iphone_dims[0] - target_box_padding and \
                y > target_box_padding and \
                y < iphone_dims[1] - target_box_padding:
            vf_time.Start(pos)

  if last_pos:
    vf_time.AdjustTime(PixelsToDimensions(last_pos))
dataset/ETHPy150Open viewfinderco/viewfinder/clients/experimental/viewfinder.py/ProcessMotion/original