lib/mnit: use abstract attributes
[nit.git] / lib / mnit / display.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2011-2013 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 # Defines abstract display classes
18 module display
19
20 import mnit::input
21
22 # Any class with a size
23 interface Sized
24 fun width: Int is abstract
25 fun height: Int is abstract
26 end
27
28 # General image class, will be specialized for each classes
29 interface Image
30 super Sized
31
32 fun destroy is abstract
33
34 # Scale this image when blit
35 var scale: Float is abstract, writable
36
37 # Use blending on this image?
38 var blended: Bool is abstract, writable
39
40 # Get another image from this one
41 fun subimage( x, y, w, h: Int ): Image is abstract
42 end
43
44 # General class for everything drawable to
45 # Is used by drawable images and display
46 interface Drawable
47 type I: Image
48
49 # Call to prepare for drawing
50 fun begin is abstract
51
52 # Call when drawing is finished
53 fun finish is abstract
54
55 # Set viewport for drawing
56 fun set_viewport( x, y, w, h: Int ) is abstract
57
58 # Draw image on self, for top left position
59 fun blit(image: I, x, y: Numeric) is abstract
60
61 # Draw image on self, for top left position but scaled
62 # the width and height of the target rectangle is specified
63 fun blit_scaled(image: Image, x, y, w, h: Numeric)
64 do
65 var fx = x.to_f
66 var fy = y.to_f
67 var fx2 = fx + w.to_f
68 var fy2 = fy + h.to_f
69 blit_stretched(image, fx, fy, fx, fy2, fx2, fy2, fx2, fy)
70 end
71
72 # Draw image, centered at position
73 fun blit_centered(image: I, x, y: Numeric) is abstract
74
75 # Draw image, centered at position but rotated
76 fun blit_rotated(image: I, x, y: Numeric, angle: Float) is abstract
77
78 # Draw image, centered, rotated and scaled
79 fun blit_rotated_scaled(image: I, x, y: Numeric, angle, scale: Float) is abstract
80
81 # Draw image by specifying the positon of each image corners
82 # Corners are in counter-clockwise order stating top left
83 # a is top left, b is bottom left, c is bottom right and d is top right
84 # ~~~raw
85 # a-d
86 # | |
87 # b-c
88 # ~~~
89 fun blit_stretched(image: I, ax, ay, bx, by, cx, cy, dx, dy: Numeric)
90 is abstract
91
92 # Clear entire window with given color
93 fun clear( r, g, b: Float ) is abstract
94 end
95
96 # General display class, is sized and drawable
97 interface Display
98 super Sized
99 super Drawable
100 end
101
102 # General drawable display image
103 interface DrawableImage
104 super Drawable
105 super Image
106 end