]> git.saurik.com Git - wxWidgets.git/blob - include/wx/animdecod.h
added wxAnimationCtrl (patch 1570325)
[wxWidgets.git] / include / wx / animdecod.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/animdecod.h
3 // Purpose: wxAnimationDecoder
4 // Author: Francesco Montorsi
5 // CVS-ID: $Id$
6 // Copyright: (c) 2006 Francesco Montorsi
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_ANIMDECOD_H
11 #define _WX_ANIMDECOD_H
12
13 #include "wx/defs.h"
14
15 #if wxUSE_STREAMS && wxUSE_GIF
16
17 #include "wx/stream.h"
18 #include "wx/image.h"
19
20 /*
21
22 Differences between a wxAnimationDecoder and a wxImageHandler:
23
24 1) wxImageHandlers always load an input stream directly into a given wxImage
25 object converting from the format-specific data representation to the
26 wxImage native format (RGB24).
27 wxAnimationDecoders always load an input stream using some optimized format
28 to store it which is format-depedent. This allows to store a (possibly big)
29 animation using a format which is a good compromise between required memory
30 and time required to blit in on the screen.
31
32 2) wxAnimationDecoders contain the animation data in some internal var.
33 That's why they derive from wxObjectRefData: they are data which can be shared.
34
35 3) wxAnimationDecoders can be used by a wxImageHandler to retrieve a frame
36 in wxImage format; the viceversa cannot be done.
37
38 4) wxAnimationDecoders are decoders only, thus do not support save features.
39
40 5) wxAnimationDecoders are directly used by wxAnimation (generic implementation)
41 as wxObjectRefData while they need to be 'wrapped' by a wxImageHandler for
42 wxImage uses.
43
44 */
45
46
47 // --------------------------------------------------------------------------
48 // Constants
49 // --------------------------------------------------------------------------
50
51 // NB: the values of these enum items are not casual but coincide with the
52 // GIF disposal codes. Do not change them !!
53 enum wxAnimationDisposal
54 {
55 // No disposal specified. The decoder is not required to take any action.
56 wxANIM_UNSPECIFIED = -1,
57
58 // Do not dispose. The graphic is to be left in place.
59 wxANIM_DONOTREMOVE = 0,
60
61 // Restore to background color. The area used by the graphic must be
62 // restored to the background color.
63 wxANIM_TOBACKGROUND = 1,
64
65 // Restore to previous. The decoder is required to restore the area
66 // overwritten by the graphic with what was there prior to rendering the graphic.
67 wxANIM_TOPREVIOUS = 2
68 };
69
70 enum wxAnimationType
71 {
72 wxANIMATION_TYPE_INVALID,
73 wxANIMATION_TYPE_GIF,
74 wxANIMATION_TYPE_ANI,
75
76 wxANIMATION_TYPE_ANY
77 };
78
79
80 // --------------------------------------------------------------------------
81 // wxAnimationDecoder class
82 // --------------------------------------------------------------------------
83
84 class WXDLLEXPORT wxAnimationDecoder : public wxObjectRefData
85 {
86 protected:
87 wxSize m_szAnimation;
88 size_t m_nFrames;
89
90 // this is the colour to use for the wxANIM_TOBACKGROUND disposal.
91 // if not specified by the animation, it's set to wxNullColour
92 wxColour m_background;
93
94 public: // frame specific data getters
95
96 // not all frames may be of the same size; e.g. GIF allows to
97 // specify that between two frames only a smaller portion of the
98 // entire animation has changed.
99 virtual wxSize GetFrameSize(size_t frame) const = 0;
100
101 // the position of this frame in case it's not as big as m_szAnimation
102 // or wxPoint(0,0) otherwise.
103 virtual wxPoint GetFramePosition(size_t frame) const = 0;
104
105 // what should be done after displaying this frame.
106 virtual wxAnimationDisposal GetDisposalMethod(size_t frame) const = 0;
107
108 // the number of milliseconds this frame should be displayed.
109 // if returns -1 then the frame must be displayed forever.
110 virtual long GetDelay(size_t frame) const = 0;
111
112 // get global data
113 wxSize GetAnimationSize() const { return m_szAnimation; }
114 wxColour GetBackgroundColour() const { return m_background; }
115 size_t GetFrameCount() const { return m_nFrames; }
116
117 public:
118 wxAnimationDecoder()
119 {
120 m_background = wxNullColour;
121 m_nFrames = 0;
122 }
123 ~wxAnimationDecoder() {}
124
125
126 virtual bool Load( wxInputStream& stream ) = 0;
127 virtual bool CanRead( wxInputStream& stream ) const = 0;
128
129 virtual wxAnimationDecoder *Clone() const = 0;
130 virtual wxAnimationType GetType() const = 0;
131
132 // convert given frame to wxImage
133 virtual bool ConvertToImage(size_t frame, wxImage *image) const = 0;
134 };
135
136
137 #endif // wxUSE_STREAM && wxUSE_GIF
138 #endif // _WX_ANIMDECOD_H
139