gamnit: intro `camera_control` an abstraction of `accept_two_fingers_motion`
[nit.git] / lib / gamnit / camera_control.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Simple camera control for user, as the method `accept_scroll_and_zoom`
16 module camera_control
17
18 import gamnit
19 import cameras
20
21 import camera_control_linux is conditional(linux)
22 import camera_control_android is conditional(android)
23
24 redef class EulerCamera
25 # Zoom and scroll this camera from user input
26 #
27 # Scrolling is accomplished by moving the camera on the XY plane and
28 # zooming by moving it on the Z axis.
29 #
30 # This method has distinct implementations per platform.
31 # On desktop computers, the mouse wheel changes the zoom level, and
32 # holding down the middle mouse button scrolls the camera.
33 # On Android, a two finger pinch and slide gesture zoom and scroll.
34 #
35 # Returns `true` if the event is used.
36 #
37 # Should be called from `App::accept_event` before accepting pointer events:
38 #
39 # ~~~nitish
40 # redef class App
41 # redef fun accept_event(event)
42 # do
43 # if world_camera.accept_scroll_and_zoom(event) then return true
44 #
45 # # Handle other events...
46 # return false
47 # end
48 # end
49 # ~~~
50 fun accept_scroll_and_zoom(event: InputEvent): Bool do return false
51 end