ecere/gui/Window: Prevent uninitialized values if base Window methods not overridden...
[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 const char * animation
37    {
38       set
39       {
40          timer.Stop();
41          if(!(animation.Load(value)))
42          {
43             String s = PrintString("Couldn't load animation ", value, ".");
44             MessageBox { caption = "Ecere FLC Player", contents = s }.Modal();
45             Destroy(0);
46             delete s;
47          }
48          else
49          {
50             image.Allocate(null, animation.width, animation.height, 0, pixelFormat8, true);
51             temp.Allocate(null, animation.width, animation.height, 0, pixelFormat888, true);
52             if(image)
53             {
54                animation.PlayFrame(image);
55                timer.delay = animation.speed;
56                timer.Start();
57             }
58          }
59
60       }
61    }
62
63    /*
64    void OnResize(int w, int h)
65    {
66       Surface surface;
67       temp.Free();
68       // temp.Allocate(null, w, h, 0, PixelFormatRGBA, false);
69       temp.Allocate(null, w, h, 0, PixelFormat888, false);
70       surface = temp.GetSurface(0,0,null);
71       surface.Stretch(image, 0,0,0,0, temp.width, temp.height,
72          image.width, image.height);
73       delete surface;
74    }
75    */
76
77    void OnRedraw(Surface surface)
78    {
79       if(animation.palUpdate)
80       {
81          display.SetPalette(animation.palette, false);
82          animation.palUpdate = false;
83       }
84       //surface.Blit(temp, 0,0,0,0,temp.width,temp.height);
85       // surface.Blit(image, 0,0,0,0,image.width,image.height);
86       surface.Stretch(temp, 0,0,0,0, clientSize.w, clientSize.h, temp.width,temp.height);
87
88       //surface.Stretch(image, 0,0,0,0, clientSize.w, clientSize.h, image.width,image.height);
89    }
90
91    void OnDestroy()
92    {
93       image.Free();
94       temp.Free();
95    }
96
97    bool OnKeyDown(Key key, unichar ch)
98    {
99       if(key == escape)
100          Destroy(0);
101       return true;
102    }
103 }