2 // This file is part of the aMule Project.
4 // Copyright (c) 2004-2011 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
26 #include <wx/mstream.h>
27 #include <wx/gifdecod.h>
28 #include <wx/dcbuffer.h>
31 #include "MuleGifCtrl.h"
35 BEGIN_EVENT_TABLE(MuleGifCtrl
, wxControl
)
36 EVT_TIMER(GIFTIMERID
, MuleGifCtrl::OnTimer
)
37 EVT_PAINT(MuleGifCtrl::OnPaint
)
38 EVT_ERASE_BACKGROUND(MuleGifCtrl::OnErase
)
41 class MuleGIFDecoder
: public wxGIFDecoder
51 void GoFirstFrame() { m_nframe
= 0; }
52 void GoNextFrame() { (m_nframe
< GetFrameCount() - 1) ? m_nframe
++ : m_nframe
= 0; }
53 void GoLastFrame() { m_nframe
= GetFrameCount() - 1; }
55 void ConvertToImage(wxImage
* image
) { wxGIFDecoder::ConvertToImage(m_nframe
, image
); }
57 long GetDelay() { return wxGIFDecoder::GetDelay(m_nframe
); }
63 MuleGifCtrl::MuleGifCtrl(
69 const wxValidator
& validator
,
72 wxControl(parent
, id
, pos
, size
, style
, validator
, name
),
74 m_timer(this, GIFTIMERID
)
79 MuleGifCtrl::~MuleGifCtrl()
89 bool MuleGifCtrl::LoadData(const char* data
, int size
)
97 wxMemoryInputStream
stream(data
, size
);
98 m_decoder
= new MuleGIFDecoder();
99 if ( m_decoder
->LoadGIF(stream
) != wxGIF_OK
) {
105 m_decoder
->GoFirstFrame();
107 m_decoder
->ConvertToImage( &frame
);
108 m_frame
= wxBitmap(frame
);
114 void MuleGifCtrl::Start()
116 if (m_decoder
&& m_decoder
->IsAnimation()) {
118 m_decoder
->GoLastFrame();
119 #if wxCHECK_VERSION(2, 9, 0)
120 wxTimerEvent
evt(m_timer
);
129 void MuleGifCtrl::Stop()
135 wxSize
MuleGifCtrl::GetBestSize()
137 return m_decoder
->GetAnimationSize();
141 void MuleGifCtrl::OnTimer(wxTimerEvent
& WXUNUSED(event
))
144 if (m_decoder
->IsAnimation()) {
145 m_decoder
->GoNextFrame();
149 m_decoder
->ConvertToImage(&frame
);
150 m_frame
= wxBitmap(frame
);
154 if (m_decoder
->IsAnimation()) {
155 m_timer
.Start(m_decoder
->GetDelay(), true);
161 void MuleGifCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
163 wxBufferedPaintDC
dc(this);
165 wxSize clientsize
= GetClientSize();
166 wxSize gifsize
= m_decoder
->GetAnimationSize();
167 int x
= (clientsize
.GetWidth()-gifsize
.GetWidth())/2;
168 int y
= (clientsize
.GetHeight()-gifsize
.GetHeight())/2;
170 dc
.SetBackground(*(wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
)));
172 dc
.DrawBitmap(m_frame
, x
, y
, true);
176 // File_checked_for_headers