animate.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk/animate.h
  3. // Purpose: Animation classes
  4. // Author: Julian Smart and Guillermo Rodriguez Garcia
  5. // Modified by: Francesco Montorsi
  6. // Created: 13/8/99
  7. // Copyright: (c) Julian Smart and Guillermo Rodriguez Garcia
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_GTKANIMATEH__
  11. #define _WX_GTKANIMATEH__
  12. typedef struct _GdkPixbufAnimation GdkPixbufAnimation;
  13. typedef struct _GdkPixbufAnimationIter GdkPixbufAnimationIter;
  14. // ----------------------------------------------------------------------------
  15. // wxAnimation
  16. // Unlike the generic wxAnimation object (see generic\animate.cpp), we won't
  17. // use directly wxAnimationHandlers as gdk-pixbuf already provides the
  18. // concept of handler and will automatically use the available handlers.
  19. // Like generic wxAnimation object, this implementation of wxAnimation is
  20. // refcounted so that assignment is very fast
  21. // ----------------------------------------------------------------------------
  22. class WXDLLIMPEXP_ADV wxAnimation : public wxAnimationBase
  23. {
  24. public:
  25. wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY)
  26. : m_pixbuf(NULL) { LoadFile(name, type); }
  27. wxAnimation(GdkPixbufAnimation *p = NULL);
  28. wxAnimation(const wxAnimation&);
  29. ~wxAnimation() { UnRef(); }
  30. wxAnimation& operator= (const wxAnimation&);
  31. virtual bool IsOk() const
  32. { return m_pixbuf != NULL; }
  33. // unfortunately GdkPixbufAnimation does not expose these info:
  34. virtual unsigned int GetFrameCount() const { return 0; }
  35. virtual wxImage GetFrame(unsigned int frame) const;
  36. // we can retrieve the delay for a frame only after building
  37. // a GdkPixbufAnimationIter...
  38. virtual int GetDelay(unsigned int WXUNUSED(frame)) const { return 0; }
  39. virtual wxSize GetSize() const;
  40. virtual bool LoadFile(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY);
  41. virtual bool Load(wxInputStream &stream, wxAnimationType type = wxANIMATION_TYPE_ANY);
  42. // Implementation
  43. public: // used by GTK callbacks
  44. GdkPixbufAnimation *GetPixbuf() const
  45. { return m_pixbuf; }
  46. void SetPixbuf(GdkPixbufAnimation* p);
  47. protected:
  48. GdkPixbufAnimation *m_pixbuf;
  49. private:
  50. void UnRef();
  51. typedef wxAnimationBase base_type;
  52. DECLARE_DYNAMIC_CLASS(wxAnimation)
  53. };
  54. // ----------------------------------------------------------------------------
  55. // wxAnimationCtrl
  56. // ----------------------------------------------------------------------------
  57. // Resize to animation size if this is set
  58. #define wxAN_FIT_ANIMATION 0x0010
  59. class WXDLLIMPEXP_ADV wxAnimationCtrl: public wxAnimationCtrlBase
  60. {
  61. public:
  62. wxAnimationCtrl() { Init(); }
  63. wxAnimationCtrl(wxWindow *parent,
  64. wxWindowID id,
  65. const wxAnimation& anim = wxNullAnimation,
  66. const wxPoint& pos = wxDefaultPosition,
  67. const wxSize& size = wxDefaultSize,
  68. long style = wxAC_DEFAULT_STYLE,
  69. const wxString& name = wxAnimationCtrlNameStr)
  70. {
  71. Init();
  72. Create(parent, id, anim, pos, size, style, name);
  73. }
  74. bool Create(wxWindow *parent, wxWindowID id,
  75. const wxAnimation& anim = wxNullAnimation,
  76. const wxPoint& pos = wxDefaultPosition,
  77. const wxSize& size = wxDefaultSize,
  78. long style = wxAC_DEFAULT_STYLE,
  79. const wxString& name = wxAnimationCtrlNameStr);
  80. ~wxAnimationCtrl();
  81. public: // event handler
  82. void OnTimer(wxTimerEvent &);
  83. public: // public API
  84. virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY);
  85. virtual bool Load(wxInputStream& stream, wxAnimationType type = wxANIMATION_TYPE_ANY);
  86. virtual void SetAnimation(const wxAnimation &anim);
  87. virtual wxAnimation GetAnimation() const
  88. { return wxAnimation(m_anim); }
  89. virtual bool Play();
  90. virtual void Stop();
  91. virtual bool IsPlaying() const;
  92. bool SetBackgroundColour( const wxColour &colour );
  93. protected:
  94. virtual void DisplayStaticImage();
  95. virtual wxSize DoGetBestSize() const;
  96. void FitToAnimation();
  97. void ClearToBackgroundColour();
  98. void ResetAnim();
  99. void ResetIter();
  100. protected: // internal vars
  101. GdkPixbufAnimation *m_anim;
  102. GdkPixbufAnimationIter *m_iter;
  103. wxTimer m_timer;
  104. bool m_bPlaying;
  105. private:
  106. typedef wxAnimationCtrlBase base_type;
  107. void Init();
  108. DECLARE_DYNAMIC_CLASS(wxAnimationCtrl)
  109. DECLARE_EVENT_TABLE()
  110. };
  111. #endif // _WX_GTKANIMATEH__