Upstream tarball 10143
[amule.git] / src / MuleGifCtrl.h
blob3ae32392684dc939e951ab64996b3b9e90b3f904
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2004-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 //
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
8 // respective authors.
9 //
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #ifndef MULEGIFCTRL_H
27 #define MULEGIFCTRL_H
30 #include <wx/control.h>
31 #include <wx/timer.h>
34 const int GIFTIMERID = 271283;
37 class MuleGIFDecoder;
38 class wxBitmap;
41 /**
42 * MuleGifCtrl is a simple widget for displaying a gif animation.
43 * It is based on the animation classes by Julian Smart and
44 * Guillermo Rodriguez Garcia, but is specialized for the reduced
45 * requirements of the aMule project. It provides flicker-free
46 * redrawing using wxBufferedPaintDC.
48 * To reduce complexity, several things have been hardcoded, though
49 * they can easily be changed:
50 * - The animation will continue to loop until Stop() is called.
51 * - The gif image is assumed to be transparent.
52 * - Start will start the animation from the first frame and wont
53 * continue a stopped animation.
55 class MuleGifCtrl : public wxControl
57 private:
58 //! A pointer to the current gif-animation.
59 MuleGIFDecoder *m_decoder;
60 //! Timer used for the delay between each frame.
61 wxTimer m_timer;
62 //! Current frame.
63 wxBitmap m_frame;
65 public:
66 /**
67 * Contructor. See wxWindow class documentation for more information.
69 MuleGifCtrl(
70 wxWindow *parent, wxWindowID id,
71 const wxPoint& pos = wxDefaultPosition,
72 const wxSize& size = wxDefaultSize,
73 long style = 0,
74 const wxValidator& validator = wxDefaultValidator,
75 const wxString& name = wxControlNameStr);
77 /**
78 * Destructor
80 virtual ~MuleGifCtrl();
82 /**
83 * This loads the gif image from a char-array with a specific size.
85 * @param data The array containing the image.
86 * @param size The size of the array.
87 * @return Returns true if the data was loaded, false otherwise.
89 * This sets the current animation and displays the first frame. If another
90 * animation was loaded, it will be unloaded and the animation stopped.
92 * To convert a image to a format readable by this function, you can
93 * use the utility hexdump. Look at inetdownload.h for how to format
94 * the output.
96 bool LoadData(const char* data, int size);
98 /**
99 * This function starts playing the animation provided that a animation is
100 * set and it's not a static image.
102 void Start();
105 * Stops the animation.
107 void Stop();
110 * Returns the prefered size of the widget.
112 * @return Prefered size, which is the size of the animation.
114 virtual wxSize GetBestSize();
116 private:
118 * Timer function that selects the next frame in an animation.
120 void OnTimer( wxTimerEvent& event );
123 * Function for drawing the animation.
125 * This functions draws the current frame, which is changed in OnTimer(),
126 * using a wxBufferedPaintDC. By doing so and also catching the
127 * ERASE_BACKGROUND events we avoid flickering on redraws.
129 void OnPaint( wxPaintEvent& event );
132 * This function is used to avoid flicker when redrawing.
134 void OnErase( wxEraseEvent& WXUNUSED(event) ) {}
136 //! Enables the event functions OnErase(), OnTimer() and OnPaint().
137 DECLARE_EVENT_TABLE()
140 // Make source compatible to wx 2.8 without 2.6 backward compatibility
141 // This hack should be moved to muuli where it belongs as soon (TM) as it gets unlocked.
142 #ifndef wxGA_PROGRESSBAR
143 #define wxGA_PROGRESSBAR 0
144 #endif
146 #endif
148 // File_checked_for_headers