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