3 skipped lines |
4 | | 4 | | // Author: Julian Smart and Guillermo Rodriguez Garcia |
|
|
|
7 | | // RCS-ID: $Id: animate.cpp,v 1.11 2005/05/23 23:51:06 RD Exp $ | | 7 | | // RCS-ID: $Id: animate.cpp,v 1.11.2.1 2006/01/23 07:19:35 vell Exp $ |
8 | | 8 | | // Copyright: (c) Julian Smart and Guillermo Rodriguez Garcia |
|
9 | | 9 | | // Licence: wxWindows licence |
|
10 | | 10 | | /////////////////////////////////////////////////////////////////////////////// |
|
8 skipped lines |
|
20 | | 20 | | #endif //__BORLANDC__ |
|
|
| | 22 | | #include "wx/log.h" |
22 | | 23 | | #include "wx/wfstream.h" |
|
23 | | 24 | | #include "wx/image.h" |
|
24 | | 25 | | #include "wx/gifdecod.h" |
|
25 | | #include "wx/log.h" | | |
26 | | 26 | | #include "wx/dcmemory.h" |
|
27 | | #include "wx/animate/animate.h" | | |
|
29 | | 28 | | #include "wx/dcclient.h" |
|
| | 29 | | #include "wx/animate/animate.h" |
|
|
32 | | 32 | | * wxAnimationPlayer |
|
70 skipped lines |
103 | | 103 | | bool wxAnimationPlayer::Build() |
|
|
|
106 | | if (m_animation) | | 106 | | if (!m_animation) |
| | 107 | | return false; |
| | 108 | | |
| | 109 | | int i, n; |
| | 110 | | |
| | 111 | | n = GetFrameCount(); |
| | 112 | | for (i = 0; i < n; i++) |
|
108 | | int n = GetFrameCount(); | | |
109 | | int i; | | |
110 | | for (i = 0; i < n; i++) | | |
111 | | { | | |
112 | | wxImage* image = GetFrame(i); | | 114 | | wxImage* image = GetFrame(i); |
113 | | if (image) | | 115 | | if (image == NULL) |
114 | | { | | |
115 | | // If the frame has transparency, | | |
116 | | // set the colour so converting to a bitmap | | |
117 | | // will create a mask | | |
118 | | wxColour transparentColour; | | |
119 | | if (GetTransparentColour(transparentColour)) | | |
120 | | image->SetMaskColour(transparentColour.Red(), transparentColour.Green(), transparentColour.Blue()); | | 116 | | return false; |
|
| | 118 | | // If the frame has transparency, |
| | 119 | | // set the colour so converting to a bitmap |
| | 120 | | // will create a mask |
| | 121 | | wxColour transparentColour; |
| | 122 | | if (GetTransparentColour(transparentColour)) |
| | 123 | | image->SetMaskColour(transparentColour.Red(), transparentColour.Green(), transparentColour.Blue()); |
| | 124 | | |
122 | | wxBitmap* bitmap = new wxBitmap(* image); | | 125 | | wxBitmap* bitmap = new wxBitmap(*image); |
123 | | delete image; | | 126 | | delete image; |
124 | | if (bitmap) | | 127 | | if (bitmap == NULL) |
| | 128 | | return false; |
| | 129 | | |
125 | | m_frames.Append(bitmap); | | 130 | | m_frames.Append(bitmap); |
126 | | else | | |
127 | | return FALSE; | | |
128 | | } | | |
129 | | else | | |
130 | | return FALSE; | | |
131 | | } | | |
132 | | return TRUE; | | |
|
134 | | else | | 132 | | |
135 | | return FALSE; | | 133 | | return true; |
|
|
138 | | 136 | | // Stop the animation |
|
10 skipped lines |
149 | | 147 | | dc.DrawBitmap(m_backingStore, m_position.x, m_position.y); |
|
|
|
152 | | | | |
153 | | 150 | | int wxAnimationPlayer::GetFrameCount() const |
|
|
|
312 skipped lines |
|
469 | | 466 | | int i = m_decoder->GetBackgroundColour(); |
|
|
471 | | return FALSE; | | 468 | | return false; |
472 | | else | | |
473 | | { | | |
474 | | unsigned char* pal = m_decoder->GetPalette(); | | |
|
| | 470 | | const unsigned char *pal = m_decoder->GetPalette(); |
476 | | if (pal) | | 471 | | bool result = (pal != NULL); |
477 | | { | | 472 | | |
| | 473 | | if (result) |
478 | | col = wxColour(pal[3*i + 0], pal[3*i + 1], pal[3*i + 2]); | | 474 | | col = wxColour(pal[3*i + 0], pal[3*i + 1], pal[3*i + 2]); |
479 | | return TRUE; | | 475 | | |
480 | | } | | |
481 | | else | | |
482 | | return FALSE; | | 476 | | return result; |
483 | | } | | |
|
|
486 | | 479 | | bool wxGIFAnimation::GetTransparentColour(wxColour& col) const |
|
2 skipped lines |
|
490 | | 483 | | int i = m_decoder->GetTransparentColour(); |
|
|
492 | | return FALSE; | | 485 | | return false; |
493 | | else | | |
494 | | { | | |
495 | | unsigned char* pal = m_decoder->GetPalette(); | | |
|
| | 487 | | const unsigned char *pal = m_decoder->GetPalette(); |
497 | | if (pal) | | 488 | | bool result = (pal != NULL); |
498 | | { | | 489 | | |
| | 490 | | if (result) |
499 | | col = wxColour(pal[3*i + 0], pal[3*i + 1], pal[3*i + 2]); | | 491 | | col = wxColour(pal[3*i + 0], pal[3*i + 1], pal[3*i + 2]); |
500 | | return TRUE; | | 492 | | |
501 | | } | | |
502 | | else | | |
503 | | return FALSE; | | 493 | | return result; |
504 | | } | | |
|
|
507 | | 496 | | bool wxGIFAnimation::IsValid() const |
|
3 skipped lines |
|
512 | | 501 | | bool wxGIFAnimation::LoadFile(const wxString& filename) |
|
|
| | 503 | | if (!wxFileExists(filename)) |
| | 504 | | return false; |
| | 505 | | |
| | 506 | | bool result = true; |
| | 507 | | |
|
| | 509 | | { |
515 | | 510 | | delete m_decoder; |
|
516 | | m_decoder = NULL; | | 511 | | m_decoder = NULL; |
| | 512 | | } |
|
518 | | if (wxFileExists(filename)) | | |
|
520 | | 515 | | wxFileInputStream stream(filename); |
|
521 | | m_decoder = new wxGIFDecoder(& stream, TRUE); | | |
|
523 | | if (m_decoder->ReadGIF() != wxGIF_OK) | | 517 | | if (stream.GetLength() > 0) |
524 | | { | | |
525 | | delete m_decoder; | | |
526 | | m_decoder = NULL; | | 518 | | m_decoder = new wxGIFDecoder(&stream, true); |
527 | | return FALSE; | | |
528 | | } | | |
|
530 | | if (!m_decoder->IsAnimation()) | | 520 | | result = ((m_decoder != NULL) && (m_decoder->ReadGIF() == wxGIF_OK)); |
531 | | { | | 521 | | if (result) |
532 | | delete m_decoder; | | 522 | | result = m_decoder->IsAnimation(); |
533 | | m_decoder = NULL; | | 523 | | } |
|
535 | | return FALSE; | | 525 | | if (!result && (m_decoder != NULL)) |
536 | | } | | 526 | | { |
537 | | else | | 527 | | delete m_decoder; |
538 | | return TRUE; | | 528 | | m_decoder = NULL; |
|
540 | | else | | 530 | | |
541 | | return FALSE; | | 531 | | return result; |
|
|
|
23 skipped lines |
|
569 | | 559 | | m_animationPlayer.SetCustomBackgroundColour(GetBackgroundColour()); |
|
|
571 | | // Want to give the impression of transparency by painting | | 561 | | // give the impression of transparency by painting |
572 | | // the parent background | | 562 | | // with the parent background |
|
574 | | 564 | | // m_animationPlayer.UseParentBackground(TRUE); |
|
575 | | 565 | | m_animationPlayer.SetWindow(this); |
|
101 skipped lines |