summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Brej <cbrej@cs.man.ac.uk>2009-07-01 20:20:47 +0100
committerCharlie Brej <cbrej@cs.man.ac.uk>2009-07-01 20:20:47 +0100
commit5cbba658e8801ca9fbb413e279a0c9850e831dca (patch)
treebb2339803f425e6d6c70ba72c3740c262e5d4021
parent628461212915f989933b7027b9fb8a348b99a124 (diff)
[script] Add support for getting the window width and height
The example script has been updated to use this as well as to use other features recently committed.
-rw-r--r--src/plugins/splash/script/script-lib-sprite.c22
-rw-r--r--themes/script/script.script52
2 files changed, 49 insertions, 25 deletions
diff --git a/src/plugins/splash/script/script-lib-sprite.c b/src/plugins/splash/script/script-lib-sprite.c
index 9d9cf42b..f25859b9 100644
--- a/src/plugins/splash/script/script-lib-sprite.c
+++ b/src/plugins/splash/script/script-lib-sprite.c
@@ -151,6 +151,26 @@ static script_return sprite_set_opacity (script_state* state, void* user_data)
+static script_return sprite_window_get_width (script_state* state, void* user_data)
+{
+ script_lib_sprite_data_t* data = user_data;
+ ply_frame_buffer_t *frame_buffer = ply_window_get_frame_buffer (data->window);
+ ply_frame_buffer_area_t area;
+ ply_frame_buffer_get_size (frame_buffer, &area);
+ return (script_return){SCRIPT_RETURN_TYPE_RETURN, script_obj_new_int (area.width)};
+}
+
+static script_return sprite_window_get_height (script_state* state, void* user_data)
+{
+ script_lib_sprite_data_t* data = user_data;
+ ply_frame_buffer_t *frame_buffer = ply_window_get_frame_buffer (data->window);
+ ply_frame_buffer_area_t area;
+ ply_frame_buffer_get_size (frame_buffer, &area);
+ return (script_return){SCRIPT_RETURN_TYPE_RETURN, script_obj_new_int (area.height)};
+}
+
+
+
static void
draw_area (script_lib_sprite_data_t* data,
@@ -213,6 +233,8 @@ script_lib_sprite_data_t* script_lib_sprite_setup(script_state *state, ply_windo
script_add_native_function (state->global, "SpriteSetY", sprite_set_y, data, "sprite", "value", NULL);
script_add_native_function (state->global, "SpriteSetZ", sprite_set_z, data, "sprite", "value", NULL);
script_add_native_function (state->global, "SpriteSetOpacity", sprite_set_opacity, data, "sprite", "value", NULL);
+ script_add_native_function (state->global, "SpriteWindowGetWidth", sprite_window_get_width, data, NULL);
+ script_add_native_function (state->global, "SpriteWindowGetHeight", sprite_window_get_height, data, NULL);
data->script_main_op = script_parse_string (script_lib_sprite_string);
script_return ret = script_execute(state, data->script_main_op);
diff --git a/themes/script/script.script b/themes/script/script.script
index 72eb8c98..e0dd6e9a 100644
--- a/themes/script/script.script
+++ b/themes/script/script.script
@@ -1,5 +1,6 @@
-splash_type = "fade_in"; # or "spinfinity"
+
+splash_type = "spinfinity"; # "fade_in" or "spinfinity"
if (splash_type == "spinfinity"){
logo.image = ImageNew("special://logo");
@@ -9,7 +10,7 @@ if (splash_type == "spinfinity"){
index = 0;
while (1){
- index_string = "" + index;
+ index_string = index;
if (index < 10) index_string = "0" + index_string;
frame_image[index] = ImageNew("../spinfinity/throbber-" + index_string + ".png");
if (!frame_image[index]) break;
@@ -21,14 +22,15 @@ if (splash_type == "spinfinity"){
fun refresh (){
if (status == "normal"){
- frame_index = (frame_index + 20/50) % frame_count;
+ frame_index += 20 / 50;
+ frame_index %= frame_count;
int_frame_index = MathInt(frame_index);
SpriteSetImage (throbber_sprite, frame_image[int_frame_index]);
- SpriteSetX (throbber_sprite, 400 - ImageGetWidth(frame_image[int_frame_index]) / 2);
- SpriteSetY (throbber_sprite, 300);
+ SpriteSetX (throbber_sprite, SpriteWindowGetWidth() / 2 - ImageGetWidth(frame_image[int_frame_index]) / 2);
+ SpriteSetY (throbber_sprite, SpriteWindowGetHeight() / 2);
SpriteSetOpacity (throbber_sprite, 1);
- SpriteSetX (logo.sprite, 400 - ImageGetWidth(logo.image) / 2);
- SpriteSetY (logo.sprite, 300 - ImageGetHeight(logo.image));
+ SpriteSetX (logo.sprite, SpriteWindowGetWidth() / 2 - ImageGetWidth(logo.image) / 2);
+ SpriteSetY (logo.sprite, SpriteWindowGetHeight() / 2 - ImageGetHeight(logo.image));
SpriteSetOpacity (logo.sprite, 1);
}
else{
@@ -45,17 +47,18 @@ else if (splash_type == "fade_in"){
logo.image = ImageNew("special://logo");
logo.sprite = SpriteNew();
SpriteSetImage(logo.sprite, logo.image);
- SpriteSetX (logo.sprite, 400 - ImageGetWidth(logo.image) / 2); # Place in the middle of the screen
- SpriteSetY (logo.sprite, 300 - ImageGetHeight(logo.image) / 2);
+ SpriteSetX (logo.sprite, SpriteWindowGetWidth() / 2 - ImageGetWidth(logo.image) / 2); # Place in the middle of the screen
+ SpriteSetY (logo.sprite, SpriteWindowGetHeight() / 2 - ImageGetHeight(logo.image) / 2);
logo.opacity_angle = 0;
fun refresh (){
if (status == "normal"){
- logo.opacity_angle = logo.opacity_angle + ((2 * 3.14) / 50) / 4; # 0.25 HZ
+ logo.opacity_angle = logo.opacity_angle + ((2 * 3.14) / 50) * 0.5; # 0.5 HZ
min_opacity = 0.3;
opacity = (MathCos(logo.opacity_angle) + 1) / 2;
- opacity = opacity * (1 - min_opacity) + min_opacity;
+ opacity *= 1 - min_opacity;
+ opacity += min_opacity;
SpriteSetOpacity (logo.sprite, opacity);
}
else{
@@ -100,8 +103,8 @@ fun dialogue_setup(){
box.sprite = SpriteNew();
SpriteSetImage(box.sprite, box.image);
- box.x = 400 - ImageGetWidth (box.image)/2;
- box.y = 300 - ImageGetHeight(box.image)/2;
+ box.x = SpriteWindowGetWidth() / 2 - ImageGetWidth (box.image)/2;
+ box.y = SpriteWindowGetHeight() / 2 - ImageGetHeight(box.image)/2;
box.z = 10000;
SpriteSetPosition(box.sprite, box.x, box.y, box.z);
@@ -129,7 +132,6 @@ fun dialogue_opacity(opacity){
SpriteSetOpacity (box.sprite, opacity);
SpriteSetOpacity (lock.sprite, opacity);
SpriteSetOpacity (entry.sprite, opacity);
- index = 0;
for (index = 0; bullet[index]; index++){
SpriteSetOpacity(bullet[index].sprite, opacity);
}
@@ -137,9 +139,7 @@ fun dialogue_opacity(opacity){
fun display_normal (){
global.status = "normal";
- if (!global.dialogue) return;
- dialogue_setup();
- dialogue_opacity (0);
+ if (global.dialogue) dialogue_opacity (0);
}
PlymouthSetDisplayNormalFunction(display_normal);
@@ -154,7 +154,7 @@ fun display_password (prompt, bullets){
SpriteSetImage(dialogue.bullet[index].sprite, dialogue.bullet_image);
dialogue.bullet[index].x = dialogue.entry.x + index * ImageGetWidth(dialogue.bullet_image);
SpriteSetX(dialogue.bullet[index].sprite, dialogue.bullet[index].x);
- dialogue.bullet[index].y = dialogue.entry.y + ImageGetHeight(dialogue.entry.image)/2 - ImageGetHeight(dialogue.bullet_image)/2;
+ dialogue.bullet[index].y = dialogue.entry.y + ImageGetHeight(dialogue.entry.image) / 2 - ImageGetHeight(dialogue.bullet_image) / 2;
SpriteSetY(dialogue.bullet[index].sprite, dialogue.bullet[index].y);
dialogue.bullet[index].z = dialogue.entry.z + 1;
SpriteSetZ(dialogue.bullet[index].sprite, dialogue.bullet[index].z);
@@ -177,7 +177,7 @@ PlymouthSetDisplayPasswordFunction(display_password);
-#-----------------------------------------Dialogue stuff --------------------------------
+#-----------------------------------------Progress stuff --------------------------------
@@ -186,8 +186,8 @@ progress_box.image = ImageNew("progress_box.png");
progress_box.sprite = SpriteNew();
SpriteSetImage(progress_box.sprite, progress_box.image);
-progress_box.x = 400 - ImageGetWidth(progress_box.image) / 2;
-progress_box.y = 300 * 1.5 - ImageGetHeight(progress_box.image) / 2;
+progress_box.x = SpriteWindowGetWidth() / 2 - ImageGetWidth(progress_box.image) / 2;
+progress_box.y = SpriteWindowGetHeight() * 0.75 - ImageGetHeight(progress_box.image) / 2;
SpriteSetX (progress_box.sprite, progress_box.x);
SpriteSetY (progress_box.sprite, progress_box.y);
@@ -195,15 +195,17 @@ SpriteSetY (progress_box.sprite, progress_box.y);
progress_bar.original_image = ImageNew("progress_bar.png");
progress_bar.sprite = SpriteNew();
-progress_bar.x = 400 - ImageGetWidth(progress_bar.original_image) / 2;
-progress_bar.y = 300 * 1.5 - ImageGetHeight(progress_box.image) / 2 + (ImageGetHeight(progress_box.image) - ImageGetHeight(progress_bar.original_image)) / 2;
+progress_bar.x = SpriteWindowGetWidth() / 2 - ImageGetWidth(progress_bar.original_image) / 2;
+progress_bar.y = SpriteWindowGetHeight() / 2 * 1.5 - ImageGetHeight(progress_box.image) / 2 + (ImageGetHeight(progress_box.image) - ImageGetHeight(progress_bar.original_image)) / 2;
SpriteSetX (progress_bar.sprite, progress_bar.x);
SpriteSetY (progress_bar.sprite, progress_bar.y);
fun progress (duration, progress){
- progress_bar.image = ImageScale(progress_bar.original_image, ImageGetWidth(progress_bar.original_image) * progress, ImageGetHeight(progress_bar.original_image));
- SpriteSetImage (progress_bar.sprite, progress_bar.image);
+ if (ImageGetWidth(progress_bar.image) != MathInt(ImageGetWidth(progress_bar.original_image) * progress)){
+ progress_bar.image = ImageScale(progress_bar.original_image, ImageGetWidth(progress_bar.original_image) * progress, ImageGetHeight(progress_bar.original_image));
+ SpriteSetImage (progress_bar.sprite, progress_bar.image);
+ }
}