Re-integrated anim in trunk, fixing the 999-layer limit at the same time
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1841 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
266
src/layers.c
266
src/layers.c
@@ -29,8 +29,9 @@
|
||||
#include "input.h"
|
||||
#include "help.h"
|
||||
#include "misc.h"
|
||||
#include "readline.h"
|
||||
|
||||
void Layer_activate(byte layer, short side)
|
||||
void Layer_activate(int layer, short side)
|
||||
{
|
||||
word old_layers;
|
||||
|
||||
@@ -103,8 +104,18 @@ void Button_Layer_add(void)
|
||||
Backup_layers(0);
|
||||
if (!Add_layer(Main_backups,Main_current_layer+1))
|
||||
{
|
||||
#ifdef NOLAYERS
|
||||
// Make a copy of current image, so the display is unchanged
|
||||
memcpy(
|
||||
Main_backups->Pages->Image[Main_current_layer].Pixels,
|
||||
Main_backups->Pages->Image[Main_current_layer-1].Pixels,
|
||||
Main_backups->Pages->Width*Main_backups->Pages->Height);
|
||||
#else
|
||||
Update_depth_buffer();
|
||||
// I just noticed this might be unneeded, since the new layer
|
||||
// is transparent, it shouldn't have any visible effect.
|
||||
Display_all_screen();
|
||||
#endif
|
||||
Display_layerbar();
|
||||
End_of_modification();
|
||||
}
|
||||
@@ -154,7 +165,7 @@ void Button_Layer_select(void)
|
||||
|
||||
void Button_Layer_toggle(void)
|
||||
{
|
||||
short layer;
|
||||
int layer;
|
||||
// Determine which button is clicked according to mouse position
|
||||
layer = (Mouse_X/Menu_factor_X - Menu_bars[MENUBAR_LAYERS].Skin_width)
|
||||
/ Layer_button_width;
|
||||
@@ -318,7 +329,7 @@ void Button_Layer_up(void)
|
||||
|
||||
if (Main_current_layer < (Main_backups->Pages->Nb_layers-1))
|
||||
{
|
||||
byte * tmp;
|
||||
T_Image tmp;
|
||||
dword layer_flags;
|
||||
|
||||
// Backup with unchanged layers
|
||||
@@ -357,7 +368,7 @@ void Button_Layer_down(void)
|
||||
|
||||
if (Main_current_layer > 0)
|
||||
{
|
||||
byte * tmp;
|
||||
T_Image tmp;
|
||||
dword layer_flags;
|
||||
|
||||
// Backup with unchanged layers
|
||||
@@ -389,3 +400,250 @@ void Button_Layer_down(void)
|
||||
Unselect_button(BUTTON_LAYER_DOWN);
|
||||
Display_cursor();
|
||||
}
|
||||
|
||||
int Interpret_delay(int delay)
|
||||
{
|
||||
// Firefox behavior
|
||||
if (delay>30)
|
||||
return delay;
|
||||
if (delay==0)
|
||||
return 100;
|
||||
return 30;
|
||||
}
|
||||
void Button_Anim_time(void)
|
||||
{
|
||||
short clicked_button;
|
||||
int mode=0;
|
||||
int frame;
|
||||
char buffer[5+1];
|
||||
T_Special_button * input_duration_button;
|
||||
int duration=Main_backups->Pages->Image[Main_current_layer].Duration;
|
||||
|
||||
Open_window(166,110,"Animation speed");
|
||||
|
||||
Print_in_window(80,20,"ms",MC_Black,MC_Light);
|
||||
input_duration_button = Window_set_input_button(33,18,5); // 1
|
||||
|
||||
Num2str(duration,buffer,5);
|
||||
Print_in_window_limited(input_duration_button->Pos_X+2,input_duration_button->Pos_Y+2,buffer,input_duration_button->Width/8,MC_Black,MC_Light);
|
||||
|
||||
Print_in_window(24,37,"Set this frame",MC_Black,MC_Light);
|
||||
Window_set_normal_button(7, 34, 13,13,"X" , 0,1,KEY_NONE); // 2
|
||||
|
||||
Print_in_window(24,55,"Set all frames",MC_Black,MC_Light);
|
||||
Window_set_normal_button(7, 52, 13,13,"" , 0,1,KEY_NONE); // 3
|
||||
|
||||
Print_in_window(24,73,"Add to all frames",MC_Black,MC_Light);
|
||||
Window_set_normal_button(7, 70, 13,13,"" , 0,1,KEY_NONE); // 4
|
||||
|
||||
Window_set_normal_button( 7, 92, 51,14,"OK" , 0,1,SDLK_RETURN); // 5
|
||||
Window_set_normal_button(63, 92, 51,14,"Cancel", 0,1,KEY_ESC); // 6
|
||||
|
||||
Update_window_area(0,0,Window_width, Window_height);
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
clicked_button=Window_clicked_button();
|
||||
if (Is_shortcut(Key,0x100+BUTTON_HELP))
|
||||
Window_help(BUTTON_ANIM_TIME, NULL);
|
||||
switch(clicked_button)
|
||||
{
|
||||
case 1: // duration
|
||||
Num2str(duration,buffer,5);
|
||||
Hide_cursor();
|
||||
if (Readline(input_duration_button->Pos_X+2,
|
||||
input_duration_button->Pos_Y+2,
|
||||
buffer,
|
||||
5,
|
||||
INPUT_TYPE_DECIMAL))
|
||||
{
|
||||
duration=atoi(buffer);
|
||||
}
|
||||
Print_in_window_limited(input_duration_button->Pos_X+2,input_duration_button->Pos_Y+2,buffer,input_duration_button->Width/8,MC_Black,MC_Light);
|
||||
Display_cursor();
|
||||
break;
|
||||
case 2: // Radio: set 1
|
||||
case 3: // Radio: set all
|
||||
case 4: // Radio: add
|
||||
mode=clicked_button-2;
|
||||
Hide_cursor();
|
||||
Print_in_window(10,37,mode==0?"X":" ",MC_Black,MC_Light);
|
||||
Print_in_window(10,55,mode==1?"X":" ",MC_Black,MC_Light);
|
||||
Print_in_window(10,73,mode==2?"X":" ",MC_Black,MC_Light);
|
||||
Display_cursor();
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (clicked_button<5);
|
||||
|
||||
// On exit
|
||||
Hide_cursor();
|
||||
Close_window();
|
||||
if (clicked_button==5)
|
||||
{
|
||||
// Accept changes
|
||||
Backup_layers(0);
|
||||
switch(mode)
|
||||
{
|
||||
case 0:
|
||||
if (duration<1)
|
||||
duration=1;
|
||||
Main_backups->Pages->Image[Main_current_layer].Duration = duration;
|
||||
break;
|
||||
case 1:
|
||||
if (duration<1)
|
||||
duration=1;
|
||||
for (frame=0; frame<Main_backups->Pages->Nb_layers; frame++)
|
||||
{
|
||||
Main_backups->Pages->Image[frame].Duration = duration;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
for (frame=0; frame<Main_backups->Pages->Nb_layers; frame++)
|
||||
{
|
||||
int cur_duration = Main_backups->Pages->Image[frame].Duration+duration;
|
||||
if (cur_duration<1)
|
||||
cur_duration=1;
|
||||
else if (cur_duration>32767)
|
||||
cur_duration=32767;
|
||||
Main_backups->Pages->Image[frame].Duration = cur_duration;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
End_of_modification();
|
||||
}
|
||||
|
||||
Unselect_button(BUTTON_ANIM_TIME);
|
||||
Display_cursor();
|
||||
}
|
||||
|
||||
void Button_Anim_first_frame(void)
|
||||
{
|
||||
if (Main_current_layer>0)
|
||||
Layer_activate(0,LEFT_SIDE);
|
||||
|
||||
Hide_cursor();
|
||||
Unselect_button(BUTTON_ANIM_FIRST_FRAME);
|
||||
Display_cursor();
|
||||
}
|
||||
|
||||
void Button_Anim_prev_frame(void)
|
||||
{
|
||||
if (Main_backups->Pages->Nb_layers>1)
|
||||
{
|
||||
if (Main_current_layer==0)
|
||||
Layer_activate(Main_backups->Pages->Nb_layers-1,LEFT_SIDE);
|
||||
else
|
||||
Layer_activate(Main_current_layer-1,LEFT_SIDE);
|
||||
}
|
||||
Hide_cursor();
|
||||
Unselect_button(BUTTON_ANIM_PREV_FRAME);
|
||||
Display_cursor();
|
||||
}
|
||||
|
||||
void Button_Anim_next_frame(void)
|
||||
{
|
||||
if (Main_backups->Pages->Nb_layers>1)
|
||||
{
|
||||
if (Main_current_layer==Main_backups->Pages->Nb_layers-1)
|
||||
Layer_activate(0,LEFT_SIDE);
|
||||
else
|
||||
Layer_activate(Main_current_layer+1,LEFT_SIDE);
|
||||
}
|
||||
|
||||
Hide_cursor();
|
||||
Unselect_button(BUTTON_ANIM_NEXT_FRAME);
|
||||
Display_cursor();
|
||||
}
|
||||
|
||||
void Button_Anim_last_frame(void)
|
||||
{
|
||||
if (Main_current_layer < (Main_backups->Pages->Nb_layers-1))
|
||||
Layer_activate((Main_backups->Pages->Nb_layers-1),LEFT_SIDE);
|
||||
|
||||
Hide_cursor();
|
||||
Unselect_button(BUTTON_ANIM_LAST_FRAME);
|
||||
Display_cursor();
|
||||
}
|
||||
|
||||
void Button_Anim_play(void)
|
||||
{
|
||||
Hide_cursor();
|
||||
|
||||
//
|
||||
|
||||
Unselect_button(BUTTON_ANIM_PLAY);
|
||||
Display_cursor();
|
||||
}
|
||||
|
||||
void Button_Anim_continuous_next(void)
|
||||
{
|
||||
Uint32 time_start;
|
||||
int time_in_current_frame=0;
|
||||
|
||||
time_start = SDL_GetTicks();
|
||||
|
||||
do
|
||||
{
|
||||
int target_frame;
|
||||
Uint32 time_now;
|
||||
|
||||
Get_input(20);
|
||||
|
||||
time_now=SDL_GetTicks();
|
||||
time_in_current_frame += time_now-time_start;
|
||||
time_start=time_now;
|
||||
target_frame = Main_current_layer;
|
||||
while (time_in_current_frame > Main_backups->Pages->Image[target_frame].Duration)
|
||||
{
|
||||
time_in_current_frame -= Interpret_delay(Main_backups->Pages->Image[target_frame].Duration);
|
||||
target_frame = (target_frame+1) % Main_backups->Pages->Nb_layers;
|
||||
}
|
||||
if (target_frame != Main_current_layer)
|
||||
{
|
||||
Layer_activate(target_frame,LEFT_SIDE);
|
||||
}
|
||||
|
||||
} while (Mouse_K);
|
||||
|
||||
Hide_cursor();
|
||||
Unselect_button(BUTTON_ANIM_NEXT_FRAME);
|
||||
Display_cursor();
|
||||
}
|
||||
|
||||
void Button_Anim_continuous_prev(void)
|
||||
{
|
||||
Uint32 time_start;
|
||||
int time_in_current_frame=0;
|
||||
|
||||
time_start = SDL_GetTicks();
|
||||
|
||||
do
|
||||
{
|
||||
int target_frame;
|
||||
Uint32 time_now;
|
||||
|
||||
Get_input(20);
|
||||
|
||||
time_now=SDL_GetTicks();
|
||||
time_in_current_frame += time_now-time_start;
|
||||
time_start=time_now;
|
||||
target_frame = Main_current_layer;
|
||||
while (time_in_current_frame > Main_backups->Pages->Image[target_frame].Duration)
|
||||
{
|
||||
time_in_current_frame -= Interpret_delay(Main_backups->Pages->Image[target_frame].Duration);
|
||||
target_frame = (target_frame+Main_backups->Pages->Nb_layers-1) % Main_backups->Pages->Nb_layers;
|
||||
}
|
||||
if (target_frame != Main_current_layer)
|
||||
{
|
||||
Layer_activate(target_frame,LEFT_SIDE);
|
||||
}
|
||||
|
||||
} while (Mouse_K);
|
||||
|
||||
Hide_cursor();
|
||||
Unselect_button(BUTTON_ANIM_NEXT_FRAME);
|
||||
Display_cursor();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user