extras/gui/genericEditor: Promoted from samples/db/MovieCollection
[sdk] / extras / fliPlay.ec
1 import "fli.ec"
2
3 class FliPlay : Window
4 {
5    Bitmap temp {};
6    Bitmap image {};
7    Fli animation {};
8    Timer timer
9    {
10       this;
11
12       bool DelayExpired()
13       {
14          Surface surface;
15
16          animation.PlayFrame(image);   
17          
18          surface = temp.GetSurface(0,0,null);
19          /*
20          if(surface)
21             surface.Stretch(image, 0,0,0,0, temp.width, temp.height, image.width, image.height);
22          */
23          if(surface)
24             surface.Blit(image, 0,0,0,0, image.width, image.height);
25          delete surface;
26
27          if(animation.frame >= animation.numFrames)
28             //Destroy(0);
29             animation.frame = 0;
30
31          Update(null);
32          return true;
33       }
34    };
35
36    property char * animation
37    {
38       set
39       {
40          timer.Stop();
41          if(!(animation.Load(value)))
42             Logf("Couldn't load animation %s.\n", value);
43          else
44          {
45             image.Allocate(null, animation.width, animation.height, 0, pixelFormat8, true);
46             temp.Allocate(null, animation.width, animation.height, 0, pixelFormat888, true);
47             if(image)
48             {
49                animation.PlayFrame(image);
50                timer.delay = animation.speed;
51                timer.Start();
52
53             }
54          }
55
56       }
57    }
58
59    /*
60    void OnResize(int w, int h)
61    {
62       Surface surface;
63       temp.Free();
64       // temp.Allocate(null, w, h, 0, PixelFormatRGBA, false);
65       temp.Allocate(null, w, h, 0, PixelFormat888, false);
66       surface = temp.GetSurface(0,0,null);
67       surface.Stretch(image, 0,0,0,0, temp.width, temp.height, 
68          image.width, image.height);
69       delete surface;
70    }
71    */
72
73    void OnRedraw(Surface surface)
74    {
75       if(animation.palUpdate)
76       {
77          display.SetPalette(animation.palette, false);
78          animation.palUpdate = false;
79       }
80       //surface.Blit(temp, 0,0,0,0,temp.width,temp.height);
81       // surface.Blit(image, 0,0,0,0,image.width,image.height);
82       surface.Stretch(temp, 0,0,0,0, clientSize.w, clientSize.h, temp.width,temp.height);
83
84       //surface.Stretch(image, 0,0,0,0, clientSize.w, clientSize.h, image.width,image.height);
85    }
86    
87    void OnDestroy()
88    {
89       image.Free();
90       temp.Free();
91    }
92
93    bool OnKeyDown(Key key, unichar ch)
94    {
95       if(key == escape) 
96          Destroy(0); 
97       return true;
98    }
99 }