2 // This file is part of the aMule Project.
4 // Copyright (c) 2004-2008 aMule Team ( admin@amule.org / http://www.amule.org )
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
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.
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
30 #include <wx/control.h>
34 const int GIFTIMERID
= 271283;
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
58 //! A pointer to the current gif-animation.
59 MuleGIFDecoder
*m_decoder
;
60 //! Timer used for the delay between each frame.
67 * Contructor. See wxWindow class documentation for more information.
70 wxWindow
*parent
, wxWindowID id
,
71 const wxPoint
& pos
= wxDefaultPosition
,
72 const wxSize
& size
= wxDefaultSize
,
74 const wxValidator
& validator
= wxDefaultValidator
,
75 const wxString
& name
= wxControlNameStr
);
80 virtual ~MuleGifCtrl();
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
96 bool LoadData(const char* data
, int size
);
99 * This function starts playing the animation provided that a animation is
100 * set and it's not a static image.
105 * Stops the animation.
110 * Returns the prefered size of the widget.
112 * @return Prefered size, which is the size of the animation.
114 virtual wxSize
GetBestSize();
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
148 // File_checked_for_headers