#include <wx/wxprec.h>
#include <wx/wx.h>
#include <wx/animate.h>
#include <wx/mstream.h>
#include "wxdragon.h"
WXD_EXPORTED wxd_AnimationCtrl_t*
wxd_AnimationCtrl_Create(wxd_Window_t* parent, wxd_Id id, const char* animation_file, int x, int y,
int width, int height, int64_t style, const char* name)
{
if (!parent) {
return nullptr;
}
wxWindow* wx_parent = (wxWindow*)parent;
wxString wx_animation_file = WXD_STR_TO_WX_STRING_UTF8_NULL_OK(animation_file);
wxString wx_name = WXD_STR_TO_WX_STRING_UTF8_NULL_OK(name);
wxPoint wx_pos = wxPoint(x, y);
wxSize wx_size = wxSize(width, height);
wxAnimation animation;
if (!wx_animation_file.IsEmpty()) {
animation.LoadFile(wx_animation_file);
}
wxAnimationCtrl* ctrl = new wxAnimationCtrl(wx_parent, id,
animation, wx_pos, wx_size, style, wx_name);
return (wxd_AnimationCtrl_t*)ctrl;
}
WXD_EXPORTED bool
wxd_AnimationCtrl_Play(wxd_AnimationCtrl_t* self)
{
if (!self)
return false;
return ((wxAnimationCtrl*)self)->Play();
}
WXD_EXPORTED void
wxd_AnimationCtrl_Stop(wxd_AnimationCtrl_t* self)
{
if (!self)
return;
((wxAnimationCtrl*)self)->Stop();
}
WXD_EXPORTED bool
wxd_AnimationCtrl_IsPlaying(wxd_AnimationCtrl_t* self)
{
if (!self)
return false;
return ((wxAnimationCtrl*)self)->IsPlaying();
}
WXD_EXPORTED bool
wxd_AnimationCtrl_LoadFile(wxd_AnimationCtrl_t* self, const char* animation_file)
{
if (!self)
return false;
wxString wx_animation_file = WXD_STR_TO_WX_STRING_UTF8_NULL_OK(animation_file);
if (wx_animation_file.IsEmpty())
return false;
return ((wxAnimationCtrl*)self)->LoadFile(wx_animation_file);
}
WXD_EXPORTED bool
wxd_AnimationCtrl_LoadFromBytes(wxd_AnimationCtrl_t* self, const unsigned char* data, size_t len)
{
if (!self || !data || len == 0)
return false;
wxAnimationCtrl* ctrl = (wxAnimationCtrl*)self;
wxMemoryInputStream stream(data, len);
if (!stream.IsOk()) {
return false; }
wxAnimation animation;
if (animation.Load(stream)) {
ctrl->SetAnimation(animation); return true; }
else {
return false;
}
}