1 // 2 // This file is part of the aMule Project. 3 // 4 // Copyright (c) 2004-2011 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. 14 // 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 23 // 24 25 26 #ifndef MULEGIFCTRL_H 27 #define MULEGIFCTRL_H 28 29 30 #include <wx/control.h> 31 #include <wx/timer.h> 32 33 34 const int GIFTIMERID = 271283; 35 36 37 class MuleGIFDecoder; 38 class wxBitmap; 39 40 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. 47 * 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. 54 */ 55 class MuleGifCtrl : public wxControl 56 { 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; 64 65 public: 66 /** 67 * Contructor. See wxWindow class documentation for more information. 68 */ 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); 76 77 /** 78 * Destructor 79 */ 80 virtual ~MuleGifCtrl(); 81 82 /** 83 * This loads the gif image from a char-array with a specific size. 84 * 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. 88 * 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. 91 * 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. 95 */ 96 bool LoadData(const char* data, int size); 97 98 /** 99 * This function starts playing the animation provided that a animation is 100 * set and it's not a static image. 101 */ 102 void Start(); 103 104 /** 105 * Stops the animation. 106 */ 107 void Stop(); 108 109 /** 110 * Returns the prefered size of the widget. 111 * 112 * @return Prefered size, which is the size of the animation. 113 */ 114 virtual wxSize GetBestSize(); 115 116 private: 117 /** 118 * Timer function that selects the next frame in an animation. 119 */ 120 void OnTimer( wxTimerEvent& event ); 121 122 /** 123 * Function for drawing the animation. 124 * 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. 128 */ 129 void OnPaint( wxPaintEvent& event ); 130 131 /** 132 * This function is used to avoid flicker when redrawing. 133 */ OnErase(wxEraseEvent & WXUNUSED (event))134 void OnErase( wxEraseEvent& WXUNUSED(event) ) {} 135 136 //! Enables the event functions OnErase(), OnTimer() and OnPaint(). 137 DECLARE_EVENT_TABLE() 138 }; 139 140 #endif 141 142 // File_checked_for_headers 143