Merge: gamnit: abstract camera scroll and zoom service
authorJean Privat <jean@pryen.org>
Tue, 11 Apr 2017 12:30:26 +0000 (08:30 -0400)
committerJean Privat <jean@pryen.org>
Tue, 11 Apr 2017 12:30:26 +0000 (08:30 -0400)
The new service `accept_scroll_and_zoom` lets the user adjust the camera using platform specific controls. On desktop computers, the mouse wheel controls the zoom and the middle mouse button drags the world/camera. On Android, a pinch gesture controls the zoom and 2 fingers slide the scroll.

This reuse the previous `accept_two_fingers_motion` and intro an implementation for desktop computers. It will be used by, at least, Sputnit in which it will replace the current implementation which is broken since the upgrade to SDL2.

Pull-Request: #2407

1  2 
lib/gamnit/flat.nit

diff --combined lib/gamnit/flat.nit
@@@ -41,10 -41,8 +41,9 @@@ import performance_analysi
  
  import gamnit
  import gamnit::cameras
 +import gamnit::dynamic_resolution
  import gamnit::limit_fps
- import android_two_fingers_motion is conditional(android)
+ import gamnit::camera_control
  
  # Draw a `texture` at `center`
  #
@@@ -218,20 -216,20 +217,20 @@@ redef class Ap
  
        # Camera for world `sprites` and `depth::actors` with perspective
        #
 -      # By default, the camera is configured to respect the resolution
 -      # of the screen in world coordinates at `z == 0.0`.
 +      # By default, the camera is configured to a height of 1080 units
 +      # of world coordinates at `z == 0.0`.
        var world_camera: EulerCamera is lazy do
                var camera = new EulerCamera(app.display.as(not null))
  
 -              # Aim for pixel resolution at level 0
 -              camera.reset_height
 -              camera.near = 100.0
 +              # Aim for full HD pixel resolution at level 0
 +              camera.reset_height 1080.0
 +              camera.near = 10.0
  
                return camera
        end
  
        # Camera for `ui_sprites` using an orthogonal view
 -      var ui_camera: UICamera = new UICamera(app.display.as(not null)) is lazy
 +      var ui_camera = new UICamera(app.display.as(not null)) is lazy
  
        # World sprites to draw as seen by `world_camera`
        var sprites: Set[Sprite] = new SpriteSet
        # Draw the whole screen, all `glDraw...` calls should be executed here
        protected fun frame_core_draw(display: GamnitDisplay)
        do
 -              perf_clock_main.lapse
 +              frame_core_dynamic_resolution_before display
  
 +              perf_clock_main.lapse
                frame_core_world_sprites display
                perfs["gamnit flat world_sprites"].add perf_clock_main.lapse
  
                frame_core_ui_sprites display
                perfs["gamnit flat ui_sprites"].add perf_clock_main.lapse
 +
 +              frame_core_dynamic_resolution_after display
        end
  
        private fun frame_core_sprites(display: GamnitDisplay, sprite_set: SpriteSet, camera: Camera)