1
-- ---------------------------------------------------------------------------------------
2
-- This file demonstrates the 'celestia:overlay' command
3
-- The command allows you to display an image in the format BMP, JPG, PNG, which must be
4
-- Pre-located in the "images" folder or its sub-folders of the Celestia main directory.
5
-- Supports image scaling, transparency and positioning.
6
-- Script author: Vincent (June 2006, contact: vince.gian@free.fr)
7
-- Modified by: Sergey Leonov aka Leserg <leserg@ua.fm>
9
-- This command accepts 6 arguments:
11
-- celestia:overlay ( float [duration], float [xoffset], float [yoffset], float [alpha], str [filename], int [fitscreen] )
13
-- duration - Determines the duration of the image display.
14
-- If not specified, the default time is 3 seconds.
16
-- xoffset - Determines the placement of the image horizontally
17
-- relative to the center of the working area of the Celestia window.
18
-- If not specified, the default value is 0.0.
19
-- Valid values are in the range from -1 to 1 relative to the center of the Celestia window:
20
-- > if xoffset = -1 -> The image is placed in the center of the left edge
21
-- Celestia window => You will only see the right half of the image;
22
-- > if xoffset = 1 -> The image is placed in the center of the right edge
23
-- Celestia window => You will only see the left half of the image;
25
-- yoffset - Determines the placement of the image vertically
26
-- relative to the center of the working area of the Celestia window.
27
-- If not specified, the default value is 0.0.
28
-- Valid values are in the range from -1 to 1 relative to the center of the Celestia window:
29
-- > if yoffset = -1 -> The image is placed in the center of the bottom edge
30
-- of Celestia window => You will only see the upper half of the image;
31
-- > if yoffset = 1 -> The image is placed in the center of the upper edge
32
-- of Celestia window => You will only see the bottom half of the image;
33
-- > if xoffset = 0.0 and yoffset = 0.0 -> The image is centered.
35
-- alpha - Determines the transparency of the image on the screen.
36
-- If not specified, the default value is 1.0
37
-- Valid values are in the range from 0.0 to 1.0
38
-- > if alpha = 0.0 -> The image is completely transparent (ie invisible);
39
-- > if alpha = 1.0 -> The image is opaque (i.e., fully visible).
41
-- filename - Specifies the name of the image file to display.
42
-- The search for files is relative to the "images" subfolder,
43
-- which should be located in the Celestia main directory.
44
-- Thus, all the images for display using the script command must be in the
45
-- "images" folder or its subfolders.
47
-- fitscreen - Determines the image zoom mode:
48
-- > if fitscreen = 0 -> The image will be shown in the original size;
49
-- > if fitscreen = 1 -> The image will be scaled by the Celestia window.
50
-- If not specified, the default value is 0.
51
-- --------------------------------------------------------------------------------------
53
celestia:print ( "Welcome!\n\nYou start a script with examples of displaying the image on the screen.", 5.0, -1, -1, 3, 5 )
56
-- ======< Example 1 >======
57
-- In the center of the Celestia window, display the image file "image.jpg". Time 6 seconds.
58
-- Set the transparency level to 0.7. The parameter 'fitscreen' is used with default value,
59
-- so do not specify it.
60
celestia:overlay ( 6, 0, 0, 0.7, "image.jpg" )
62
celestia:print ( "The image is placed in the center of the window.", 4.0, -1, -1, 3, 5 )
66
-- ======< Example 2 >======
67
-- We will deduce on the center an image file "image.jpg" and we will deploy it on all window Celestia.
68
-- Set the transparency level to 0.5. Time 6 seconds.
69
celestia:overlay ( 6, 0, 0, 0.5, "image.jpg", 1 )
72
celestia:print ( "The image is maximized on the whole window.", 4.0, -1, -1, 3, 5 )
76
-- ======< Example 3 >======
77
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78
-- Now we will display the image sequentially at the corners of the Celestia window.
79
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81
-- The original width of the image in pixels
83
-- The original height of the image in pixels
85
-- Determine the width and height for the working area of the Celestia window
86
screen_width, screen_height = celestia:getscreendimension()
88
xoffset_left = (image_width/screen_width) - 1
89
-- (xoffset_right = - xoffset_left).
90
xoffset_right = 1 - (image_width/screen_width)
91
yoffset_bottom = (image_height/screen_height) - 1
92
-- (yoffset_top = - yoffset_bottom).
93
yoffset_top = 1 - (image_height/screen_height)
95
celestia:print ( "Now the image will be shown at the corners of the window.", 5.0, -1, -1, 3, 5 )
98
celestia:overlay (3, xoffset_left, yoffset_bottom, 0.5, "image.jpg")
101
celestia:overlay (3, xoffset_left, yoffset_top, 0.5, "image.jpg")
104
celestia:overlay (3, xoffset_right, yoffset_top, 0.5, "image.jpg")
107
celestia:overlay (3, xoffset_right, yoffset_bottom, 0.5, "image.jpg")
112
-- ======< Example 4 >======
113
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114
-- Now the image will move around the screen with the 'ping-pong' effect.
115
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123
celestia:print ( "Now the image will move around the screen.", 5.0, -1, -1, 3, 5 )
127
-- Define the keystroke processing function
128
function celestia_keyboard_callback(str)
129
script_running = false
131
-- Enable event handling by keystrokes
132
celestia:requestkeyboard(true)
134
-- Run the execution of the loop, which will work until you press any key on the keyboard.
135
while script_running do
138
screen_width, screen_height = celestia:getscreendimension()
139
xoffset_left = (image_width/screen_width) - 1
140
xoffset_right = - xoffset_left
141
yoffset_bottom = (image_height/screen_height) - 1
142
yoffset_top = - yoffset_bottom
144
if x_pos < xoffset_left then
149
if x_pos > xoffset_right then
150
x_pos = xoffset_right
154
if y_pos < yoffset_bottom then
155
y_pos = yoffset_bottom
159
if y_pos > yoffset_top then
164
-- Display the image on the screen, according to the calculated coordinates.
165
celestia:overlay (0.01, x_pos, y_pos, 0.5, "image.jpg")
166
-- Calculate the new coordinates of the image.
167
x_pos = x_pos + x_mod
168
y_pos = y_pos + y_mod
170
celestia:print("Press any key to end the script ...", 0.5, -1, -1, 2, 4)