| 1 |
#include "AnimationCtrlWrapper.h" |
| 2 |
|
| 3 |
#include "allocator_mgr.h" |
| 4 |
#include "wxc_bitmap_code_generator.h" |
| 5 |
#include "wxgui_defs.h" |
| 6 |
#include "wxgui_helpers.h" |
| 7 |
|
| 8 |
#include <wx/animate.h> |
| 9 |
#include <wx/mstream.h> |
| 10 |
|
| 11 |
AnimationCtrlWrapper::AnimationCtrlWrapper() |
| 12 |
: wxcWidget(ID_WXANIMATIONCTRL) |
| 13 |
{ |
| 14 |
PREPEND_STYLE(wxAC_DEFAULT_STYLE, true); |
| 15 |
PREPEND_STYLE(wxAC_NO_AUTORESIZE, false); |
| 16 |
|
| 17 |
SetPropertyString(_("Common Settings"), "wxAnimationCtrl"); |
| 18 |
|
| 19 |
AddBool(PROP_ANIM_AUTO_PLAY, _("Load and play animation on creation"), false); |
| 20 |
AddProperty(new BitmapPickerProperty(PROP_BITMAP_PATH, "", _("Select the animation file"))); |
| 21 |
AddProperty(new BitmapPickerProperty( |
| 22 |
PROP_DISABLED_BITMAP_PATH, "", _("Sets the bitmap to show on the control when it's not playing an animation"))); |
| 23 |
|
| 24 |
m_namePattern = "m_animationCtrl"; |
| 25 |
SetName(GenerateName()); |
| 26 |
} |
| 27 |
|
| 28 |
AnimationCtrlWrapper::~AnimationCtrlWrapper() {} |
| 29 |
|
| 30 |
wxcWidget* AnimationCtrlWrapper::Clone() const { return new AnimationCtrlWrapper(); } |
| 31 |
|
| 32 |
wxString AnimationCtrlWrapper::CppCtorCode() const |
| 33 |
{ |
| 34 |
wxcCodeGeneratorHelper::Get().AddBitmap(PropertyFile(PROP_DISABLED_BITMAP_PATH)); |
| 35 |
|
| 36 |
wxString code; |
| 37 |
// wxAnimationCtrl (wxWindow *parent, wxWindowID id, const wxAnimation &anim=wxNullAnimation, const wxPoint |
| 38 |
// &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxAC_DEFAULT_STYLE, const wxString |
| 39 |
// &name=wxAnimationCtrlNameStr) |
| 40 |
code << GetName() << " = new " << GetRealClassName() << "(" << GetWindowParent() << ", " << WindowID() |
| 41 |
<< ", wxNullAnimation, wxDefaultPosition, " << SizeAsString() << ", " << StyleFlags("wxAC_DEFAULT_STYLE") |
| 42 |
<< ");\n"; |
| 43 |
|
| 44 |
// Load the image file |
| 45 |
if(PropertyBool(PROP_ANIM_AUTO_PLAY) == "true") { |
| 46 |
code << "if( wxFileName::Exists(" << wxCrafter::WXT(PropertyFile(PROP_BITMAP_PATH)) << ") && " << GetName() |
| 47 |
<< "->LoadFile(" << wxCrafter::WXT(PropertyFile(PROP_BITMAP_PATH)) << "))" << GetName() << "->Play();\n"; |
| 48 |
} |
| 49 |
code << CPPCommonAttributes(); |
| 50 |
code << GetName() << "->SetInactiveBitmap(" |
| 51 |
<< wxcCodeGeneratorHelper::Get().BitmapCode(PropertyFile(PROP_DISABLED_BITMAP_PATH)) << ");\n"; |
| 52 |
return code; |
| 53 |
} |
| 54 |
|
| 55 |
void AnimationCtrlWrapper::GetIncludeFile(wxArrayString& headers) const |
| 56 |
{ |
| 57 |
headers.Add("#include <wx/mstream.h>"); |
| 58 |
headers.Add("#include <wx/filename.h>"); |
| 59 |
headers.Add("#include <wx/animate.h>"); |
| 60 |
} |
| 61 |
|
| 62 |
wxString AnimationCtrlWrapper::GetWxClassName() const { return "wxAnimationCtrl"; } |
| 63 |
|
| 64 |
void AnimationCtrlWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 65 |
{ |
| 66 |
text << XRCPrefix() << XRCStyle() << XRCCommonAttributes() << XRCBitmap("animation") // Uses PROP_BITMAP_PATH |
| 67 |
<< "<inactive-bitmap>" << PropertyFile(PROP_DISABLED_BITMAP_PATH) << "</inactive-bitmap>" << XRCSuffix(); |
| 68 |
} |