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