a528d5774975d5290deee9b67810a5d060622a5c
[nit.git] / lib / app / app_base.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2011-2014 Alexis Laferrière <alexis.laf@xymus.net>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 module app_base is
18 new_annotation app_name
19 new_annotation app_version
20 end
21
22 # App subclasses are cross-platform applications
23 #
24 # This class is redefed by plateform modules and so
25 # App can be specialized directly in the user app.
26 class App
27 protected init do end
28
29 # Starts the internal setup of graphical and other stuff
30 # Is called just before run
31 fun setup do end
32
33 # Main entry point of your application
34 fun run do end
35
36 # Prefix to all log messages, used by `log_error`, `log_warning` and `log_info`.
37 fun log_prefix: String do return "app.nit"
38
39 # Helper function for logging errors
40 fun log_error(msg: String) do sys.stderr.write "{log_prefix} error: {msg}\n"
41
42 # Helper function for logging warnings
43 fun log_warning(msg: String) do sys.stderr.write "{log_prefix} warn: {msg}\n"
44
45 # Main init method for graphical stuff
46 # Is called when display is ready so graphical assets
47 # can be loaded at this time.
48 fun window_created do end
49
50 # Called before destroying the window
51 fun window_closing do end
52 end
53
54 protected fun app: App do return once new App
55 app.setup
56 app.run