Merge branch 'disable-native-animation'
Allow the generic animation classes to be used on all platforms. See https://github.com/wxWidgets/wxWidgets/pull/1768
This commit is contained in:
32
interface/wx/anidecod.h
Normal file
32
interface/wx/anidecod.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/anidecod.h
|
||||
// Purpose: wxANIDecoder, ANI reader for wxImage and wxAnimation
|
||||
// Author: Francesco Montorsi
|
||||
// Copyright: (c) 2006 Francesco Montorsi
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
@class wxANIDecoder
|
||||
|
||||
An animation decoder supporting animated cursor (.ani) files.
|
||||
*/
|
||||
class wxANIDecoder : public wxAnimationDecoder
|
||||
{
|
||||
public:
|
||||
wxANIDecoder();
|
||||
~wxANIDecoder();
|
||||
|
||||
virtual bool Load( wxInputStream& stream );
|
||||
virtual wxAnimationDecoder *Clone() const;
|
||||
virtual wxAnimationType GetType() const;
|
||||
virtual bool ConvertToImage(unsigned int frame, wxImage *image) const;
|
||||
virtual wxSize GetFrameSize(unsigned int frame) const;
|
||||
virtual wxPoint GetFramePosition(unsigned int frame) const;
|
||||
virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const;
|
||||
virtual long GetDelay(unsigned int frame) const;
|
||||
virtual wxColour GetTransparentColour(unsigned int frame) const;
|
||||
|
||||
protected:
|
||||
virtual bool DoCanRead(wxInputStream& stream) const;
|
||||
};
|
@@ -39,6 +39,10 @@ enum wxAnimationType
|
||||
|
||||
It is only available if @c wxUSE_ANIMATIONCTRL is set to 1 (the default).
|
||||
|
||||
For the platforms where this control has a native implementation, it may
|
||||
have only limited support for the animation types, see @c
|
||||
wxGenericAnimationCtrl if you need to support all of them.
|
||||
|
||||
@beginStyleTable
|
||||
@style{wxAC_DEFAULT_STYLE}
|
||||
The default style: wxBORDER_NONE.
|
||||
@@ -103,6 +107,28 @@ public:
|
||||
long style = wxAC_DEFAULT_STYLE,
|
||||
const wxString& name = wxAnimationCtrlNameStr);
|
||||
|
||||
/**
|
||||
Create a new animation object compatible with this control.
|
||||
|
||||
A wxAnimation object created using this function is always compatible
|
||||
with controls of this type, see wxAnimation::IsCompatibleWith().
|
||||
|
||||
@see CreateCompatibleAnimation()
|
||||
|
||||
@since 3.1.4
|
||||
*/
|
||||
wxAnimation CreateAnimation() const;
|
||||
|
||||
/**
|
||||
Create a new animation object compatible with this control.
|
||||
|
||||
This method does the same thing as CreateAnimation() but is static,
|
||||
i.e. can be called without creating any wxAnimationCtrl objects.
|
||||
|
||||
@since 3.1.4
|
||||
*/
|
||||
static wxAnimation CreateCompatibleAnimation();
|
||||
|
||||
/**
|
||||
Returns the animation associated with this control.
|
||||
*/
|
||||
@@ -177,22 +203,109 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@class wxAnimation
|
||||
@class wxGenericAnimationCtrl
|
||||
|
||||
This class encapsulates the concept of a platform-dependent animation.
|
||||
An animation is a sequence of frames of the same size.
|
||||
Sound is not supported by wxAnimation.
|
||||
Generic implementation of wxAnimationCtrl interface.
|
||||
|
||||
Note that on wxGTK wxAnimation is capable of loading the formats supported
|
||||
by the internally-used @c gdk-pixbuf library (typically this means only
|
||||
@c wxANIMATION_TYPE_GIF).
|
||||
On other platforms wxAnimation is always capable of loading both GIF and ANI
|
||||
formats (i.e. both @c wxANIMATION_TYPE_GIF and @c wxANIMATION_TYPE_ANI).
|
||||
If the platform supports a native animation control (currently just wxGTK)
|
||||
then this class implements the same interface internally in wxWidgets.
|
||||
One advantage of using this class instead of the native version is that
|
||||
this version of the control is capable of using animations in other formats
|
||||
than the ones supported by the @c gdk-pixbuf library used by wxGTK, which
|
||||
typically only supports @c wxANIMATION_TYPE_GIF.
|
||||
|
||||
Note that to use this class you need to explicitly include the generic
|
||||
header after including the main one before using it, i.e.
|
||||
@code
|
||||
#include <wx/animate.h>
|
||||
#include <wx/generic/animate.h>
|
||||
@endcode
|
||||
|
||||
@library{wxcore}
|
||||
@category{gdi}
|
||||
*/
|
||||
|
||||
class wxGenericAnimationCtrl : public wxAnimationCtrl
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Initializes the object and calls Create() with
|
||||
all the parameters.
|
||||
*/
|
||||
wxGenericAnimationCtrl(wxWindow* parent, wxWindowID id,
|
||||
const wxAnimation& anim = wxNullAnimation,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxAC_DEFAULT_STYLE,
|
||||
const wxString& name = wxAnimationCtrlNameStr);
|
||||
|
||||
/**
|
||||
Creates the control with the given @a anim animation.
|
||||
|
||||
After control creation you must explicitly call Play() to start to play
|
||||
the animation. Until that function won't be called, the first frame
|
||||
of the animation is displayed.
|
||||
|
||||
@param parent
|
||||
Parent window, must be non-@NULL.
|
||||
@param id
|
||||
The identifier for the control.
|
||||
@param anim
|
||||
The initial animation shown in the control.
|
||||
@param pos
|
||||
Initial position.
|
||||
@param size
|
||||
Initial size.
|
||||
@param style
|
||||
The window style, see wxAC_* flags.
|
||||
@param name
|
||||
Control name.
|
||||
|
||||
@return @true if the control was successfully created or @false if
|
||||
creation failed.
|
||||
*/
|
||||
bool Create(wxWindow* parent, wxWindowID id,
|
||||
const wxAnimation& anim = wxNullAnimation,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxAC_DEFAULT_STYLE,
|
||||
const wxString& name = wxAnimationCtrlNameStr);
|
||||
|
||||
/**
|
||||
Draw the current frame of the animation into given DC.
|
||||
This is fast as current frame is always cached.
|
||||
*/
|
||||
void DrawCurrentFrame(wxDC& dc);
|
||||
|
||||
/**
|
||||
Returns a wxBitmap with the current frame drawn in it.
|
||||
*/
|
||||
wxBitmap& GetBackingStore();
|
||||
|
||||
/**
|
||||
This overload of Play() lets you specify if the animation must loop or not
|
||||
*/
|
||||
bool Play(bool looped);
|
||||
|
||||
/**
|
||||
Specify whether the animation's background colour is to be shown (the default),
|
||||
or whether the window background should show through
|
||||
*/
|
||||
void SetUseWindowBackgroundColour(bool useWinBackground = true);
|
||||
|
||||
/**
|
||||
Returns @c true if the window's background colour is being used.
|
||||
*/
|
||||
bool IsUsingWindowBackgroundColour() const;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@class wxAnimation
|
||||
|
||||
The @c wxAnimation class handles the interface between the animation
|
||||
control and the details of the animation image or data.
|
||||
|
||||
@stdobjects
|
||||
::wxNullAnimation
|
||||
@@ -203,45 +316,56 @@ class wxAnimation : public wxObject
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Default ctor.
|
||||
*/
|
||||
Constructs a new empty animation object.
|
||||
|
||||
Call Load() to initialize it.
|
||||
|
||||
@see wxAnimationCtrl::CreateAnimation()
|
||||
*/
|
||||
wxAnimation();
|
||||
|
||||
/**
|
||||
Copy ctor.
|
||||
*/
|
||||
wxAnimation(const wxAnimation& anim);
|
||||
|
||||
/**
|
||||
Loads an animation from a file.
|
||||
Constructs a new animation object and load the animation data from the
|
||||
given filename.
|
||||
|
||||
@param name
|
||||
The name of the file to load.
|
||||
A filename.
|
||||
@param type
|
||||
See LoadFile() for more info.
|
||||
*/
|
||||
wxAnimation(const wxString& name,
|
||||
wxAnimationType type = wxANIMATION_TYPE_ANY);
|
||||
One of the ::wxAnimationType values; wxANIMATION_TYPE_ANY
|
||||
means that the function should try to autodetect the filetype.
|
||||
|
||||
@see wxAnimationCtrl::CreateAnimation()
|
||||
*/
|
||||
wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY);
|
||||
|
||||
/**
|
||||
Destructor.
|
||||
See @ref overview_refcount_destruct for more info.
|
||||
Copy constructor.
|
||||
*/
|
||||
virtual ~wxAnimation();
|
||||
wxAnimation(const wxAnimation& other);
|
||||
|
||||
/**
|
||||
Returns @true if animation data is present.
|
||||
*/
|
||||
bool IsOk() const;
|
||||
|
||||
/**
|
||||
Returns @true if animation can be used with controls of the given type.
|
||||
|
||||
This function checks if this animation object can be used with
|
||||
wxAnimationCtrl of particular type. This will be always the case for
|
||||
the platforms where only a single wxAnimationCtrl implementation is
|
||||
available, but not necessarily under e.g. wxGTK where both native (but
|
||||
limited) GTK implementation and generic implementation can be used.
|
||||
|
||||
@since 3.1.4
|
||||
*/
|
||||
bool IsCompatibleWith(wxClassInfo* ci) const;
|
||||
|
||||
/**
|
||||
Returns the delay for the i-th frame in milliseconds.
|
||||
If @c -1 is returned the frame is to be displayed forever.
|
||||
*/
|
||||
virtual int GetDelay(unsigned int i) const;
|
||||
|
||||
/**
|
||||
Returns the i-th frame as a wxImage.
|
||||
|
||||
This method is not implemented in the native wxGTK implementation of
|
||||
this class and always returns an invalid image there.
|
||||
*/
|
||||
virtual wxImage GetFrame(unsigned int i) const;
|
||||
int GetDelay(unsigned int frame) const;
|
||||
|
||||
/**
|
||||
Returns the number of frames for this animation.
|
||||
@@ -249,17 +373,33 @@ public:
|
||||
This method is not implemented in the native wxGTK implementation of
|
||||
this class and always returns 0 there.
|
||||
*/
|
||||
virtual unsigned int GetFrameCount() const;
|
||||
unsigned int GetFrameCount() const;
|
||||
|
||||
/**
|
||||
Returns the size of the animation.
|
||||
Returns the i-th frame as a wxImage.
|
||||
|
||||
This method is not implemented in the native wxGTK implementation of
|
||||
this class and always returns an invalid image there.
|
||||
*/
|
||||
virtual wxSize GetSize() const;
|
||||
wxImage GetFrame(unsigned int frame);
|
||||
|
||||
/**
|
||||
Returns @true if animation data is present.
|
||||
Returns the size of the animation.
|
||||
*/
|
||||
virtual bool IsOk() const;
|
||||
wxSize GetSize() const;
|
||||
|
||||
/**
|
||||
Loads an animation from a file.
|
||||
|
||||
@param name
|
||||
A filename.
|
||||
@param type
|
||||
One of the ::wxAnimationType values; wxANIMATION_TYPE_ANY
|
||||
means that the function should try to autodetect the filetype.
|
||||
|
||||
@return @true if the operation succeeded, @false otherwise.
|
||||
*/
|
||||
bool LoadFile(const wxString& name, wxAnimationType type = wxANIMATION_TYPE_ANY);
|
||||
|
||||
/**
|
||||
Loads an animation from the given stream.
|
||||
@@ -273,30 +413,45 @@ public:
|
||||
|
||||
@return @true if the operation succeeded, @false otherwise.
|
||||
*/
|
||||
virtual bool Load(wxInputStream& stream,
|
||||
wxAnimationType type = wxANIMATION_TYPE_ANY);
|
||||
bool Load(wxInputStream& stream, wxAnimationType type = wxANIMATION_TYPE_ANY);
|
||||
|
||||
|
||||
/**
|
||||
Loads an animation from a file.
|
||||
|
||||
@param name
|
||||
A filename.
|
||||
@param type
|
||||
One of the ::wxAnimationType values; wxANIMATION_TYPE_ANY
|
||||
means that the function should try to autodetect the filetype.
|
||||
|
||||
@return @true if the operation succeeded, @false otherwise.
|
||||
*/
|
||||
virtual bool LoadFile(const wxString& name,
|
||||
wxAnimationType type = wxANIMATION_TYPE_ANY);
|
||||
Returns the list of animation decoders used by the generic animation
|
||||
and @c wxGenericAnimationCtrl.
|
||||
*/
|
||||
static inline wxAnimationDecoderList& GetHandlers();
|
||||
|
||||
/**
|
||||
Assignment operator, using @ref overview_refcount "reference counting".
|
||||
Add a new decoder to the list of animation decoders.
|
||||
*/
|
||||
static void AddHandler(wxAnimationDecoder *handler);
|
||||
|
||||
/**
|
||||
Insert a new decoder to the front of the list of animation decoders.
|
||||
*/
|
||||
static void InsertHandler(wxAnimationDecoder *handler);
|
||||
|
||||
/**
|
||||
Search for an animation decoder by type.
|
||||
*/
|
||||
static const wxAnimationDecoder *FindHandler( wxAnimationType animType );
|
||||
|
||||
/**
|
||||
Load the stock animation decoders (currently GIF and ANI) into the list
|
||||
of decoders. This is called automatically at program startup.
|
||||
*/
|
||||
wxAnimation& operator =(const wxAnimation& brush);
|
||||
static void InitStandardHandlers();
|
||||
|
||||
/**
|
||||
Clear out the animation decoder list. This is called automatically at
|
||||
program shutdown.
|
||||
*/
|
||||
static void CleanUpHandlers();
|
||||
};
|
||||
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// Global functions/macros
|
||||
// ============================================================================
|
||||
@@ -305,4 +460,3 @@ public:
|
||||
An empty animation object.
|
||||
*/
|
||||
wxAnimation wxNullAnimation;
|
||||
|
||||
|
111
interface/wx/animdecod.h
Normal file
111
interface/wx/animdecod.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/animdecod.h
|
||||
// Purpose: wxAnimationDecoder
|
||||
// Author: Francesco Montorsi
|
||||
// Copyright: (c) 2006 Francesco Montorsi
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum wxAnimationDisposal
|
||||
{
|
||||
/// No disposal specified. The decoder is not required to take any action.
|
||||
wxANIM_UNSPECIFIED = -1,
|
||||
|
||||
/// Do not dispose. The graphic is to be left in place.
|
||||
wxANIM_DONOTREMOVE = 0,
|
||||
|
||||
/// Restore to background color. The area used by the graphic must be
|
||||
/// restored to the background color.
|
||||
wxANIM_TOBACKGROUND = 1,
|
||||
|
||||
/// Restore to previous. The decoder is required to restore the area
|
||||
/// overwritten by the graphic with what was there prior to rendering the graphic.
|
||||
wxANIM_TOPREVIOUS = 2
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@class wxAnimationDecoder
|
||||
|
||||
wxAnimationDecoder is used by @c wxAnimation for loading frames and other
|
||||
information for the animation from the animation image file.
|
||||
|
||||
*/
|
||||
class wxAnimationDecoder : public wxObjectRefData
|
||||
{
|
||||
public:
|
||||
wxAnimationDecoder();
|
||||
|
||||
/**
|
||||
Load the animation image frames from the given stream.
|
||||
*/
|
||||
virtual bool Load( wxInputStream& stream ) = 0;
|
||||
|
||||
/**
|
||||
Returns @true if this decoder supports loading from the given stream.
|
||||
*/
|
||||
bool CanRead( wxInputStream& stream ) const;
|
||||
|
||||
/**
|
||||
Create a copy of this decoder.
|
||||
*/
|
||||
virtual wxAnimationDecoder *Clone() const = 0;
|
||||
|
||||
/**
|
||||
Return the animation type this decoder implements.
|
||||
*/
|
||||
virtual wxAnimationType GetType() const = 0;
|
||||
|
||||
/**
|
||||
Convert given frame to @c wxImage.
|
||||
*/
|
||||
virtual bool ConvertToImage(unsigned int frame, wxImage *image) const = 0;
|
||||
|
||||
|
||||
/*
|
||||
Get the size of the given animation frame.
|
||||
|
||||
It's possible that not all frames are of the same size; e.g. GIF allows
|
||||
to specify that between two frames only a smaller portion of the entire
|
||||
animation has changed.
|
||||
*/
|
||||
virtual wxSize GetFrameSize(unsigned int frame) const = 0;
|
||||
|
||||
/*
|
||||
Returns the position of the frame, in case it's not as big as the animation size,
|
||||
or @c wxPoint(0,0) otherwise.
|
||||
*/
|
||||
virtual wxPoint GetFramePosition(unsigned int frame) const = 0;
|
||||
|
||||
/**
|
||||
What should be done after displaying this frame.
|
||||
*/
|
||||
virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const = 0;
|
||||
|
||||
/**
|
||||
Return the number of milliseconds this frame should be displayed.
|
||||
If -1 is returned then the frame must be displayed forever.
|
||||
*/
|
||||
virtual long GetDelay(unsigned int frame) const = 0;
|
||||
|
||||
/**
|
||||
The transparent colour for this frame, if any, or @c wxNullColour.
|
||||
*/
|
||||
virtual wxColour GetTransparentColour(unsigned int frame) const = 0;
|
||||
|
||||
wxSize GetAnimationSize() const;
|
||||
wxColour GetBackgroundColour() const;
|
||||
unsigned int GetFrameCount() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
Checks the signature of the data in the given stream and returns true if it
|
||||
appears to be a valid animation format recognized by the animation decoder;
|
||||
this function should modify the stream current position without taking care
|
||||
of restoring it since @c CanRead() will do it.
|
||||
*/
|
||||
virtual bool DoCanRead(wxInputStream& stream) const = 0;
|
||||
};
|
||||
|
||||
|
34
interface/wx/gifdecod.h
Normal file
34
interface/wx/gifdecod.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/gifdecod.h
|
||||
// Purpose: wxGIFDecoder, GIF reader for wxImage and wxAnimation
|
||||
// Author: Guillermo Rodriguez Garcia <guille@iies.es>
|
||||
// Version: 3.02
|
||||
// Copyright: (c) 1999 Guillermo Rodriguez Garcia
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
@class wxGIFDecoder
|
||||
|
||||
An animation decoder supporting animated GIF files.
|
||||
*/
|
||||
class wxGIFDecoder : public wxAnimationDecoder
|
||||
{
|
||||
public:
|
||||
wxGIFDecoder();
|
||||
~wxGIFDecoder();
|
||||
|
||||
virtual bool Load( wxInputStream& stream );
|
||||
virtual wxAnimationDecoder *Clone() const;
|
||||
virtual wxAnimationType GetType() const;
|
||||
virtual bool ConvertToImage(unsigned int frame, wxImage *image) const;
|
||||
virtual wxSize GetFrameSize(unsigned int frame) const;
|
||||
virtual wxPoint GetFramePosition(unsigned int frame) const;
|
||||
virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const;
|
||||
virtual long GetDelay(unsigned int frame) const;
|
||||
virtual wxColour GetTransparentColour(unsigned int frame) const;
|
||||
|
||||
protected:
|
||||
virtual bool DoCanRead(wxInputStream& stream) const;
|
||||
};
|
||||
|
Reference in New Issue
Block a user