Debian Codegraph @

wxcrafter/controls/bitmap_wrapepr.cpp

raw
1 #include "bitmap_wrapepr.h"
2 #include "allocator_mgr.h"
3 #include "file_ficker_property.h"
4 #include "wxc_bitmap_code_generator.h"
5 #include "wxc_project_metadata.h"
6 #include "wxgui_defs.h"
7 #include "wxgui_helpers.h"
8
9 BitmapWrapepr::BitmapWrapepr()
10 : wxcWidget(ID_WXBITMAP)
11 {
12 m_properties.DeleteValues();
13 m_styles.Clear();
14 m_sizerFlags.Clear();
15
16 AddProperty(new CategoryProperty(_("wxBitmap")));
17 AddProperty(new StringProperty(
18 PROP_NAME, wxT(""),
19 _("A unique name for the bitmap (across your project)\nThis name can be used later to load the bitmap from the "
20 "generated class\nby simply calling: wxBitmap bmp = myimglist.Bitmap(\"my-bitmap-name\")")));
21 AddProperty(new FilePickerProperty(PROP_BITMAP_PATH, wxT(""), _("Select the bitmap file")));
22 m_namePattern = "m_bmp";
23 SetName(GenerateName());
24 }
25
26 BitmapWrapepr::~BitmapWrapepr() {}
27
28 wxcWidget* BitmapWrapepr::Clone() const { return new BitmapWrapepr(); }
29
30 wxString BitmapWrapepr::CppCtorCode() const
31 {
32 wxArrayString exts;
33 exts.Add("");
34 exts.Add("@2x");
35 exts.Add("@1.25x");
36 exts.Add("@1.5x");
37
38 wxString bmpPath = PropertyString(PROP_BITMAP_PATH);
39 wxFileName fn(bmpPath);
40 // Support for hi-res images
41 // The logic:
42 // If we find files with the following perfixes: @2x, @1.5x, @1.25x
43 // add them to the resource files as well
44 for(size_t i = 0; i < exts.size(); ++i) {
45 wxFileName hiResImage = fn;
46 hiResImage.MakeAbsolute(wxcProjectMetadata::Get().GetProjectPath());
47 hiResImage.SetName(hiResImage.GetName() + exts.Item(i));
48 if(hiResImage.FileExists()) {
49 wxcCodeGeneratorHelper::Get().AddBitmap(hiResImage.GetFullPath(), GetName() + exts.Item(i));
50 }
51 }
52
53 wxString cppCode;
54 for(size_t i = 0; i < exts.size(); ++i) {
55 if(wxcCodeGeneratorHelper::Get().Contains(GetName() + exts.Item(i))) {
56 cppCode << "{\n";
57 cppCode << " wxBitmap bmp;\n";
58 cppCode << " wxIcon icn;\n";
59 cppCode << " bmp = "
60 << wxcCodeGeneratorHelper::Get().BitmapCode(PropertyString(PROP_BITMAP_PATH),
61 GetName() + exts.Item(i))
62 << ";\n";
63 cppCode << " if(bmp.IsOk()) {\n";
64 cppCode << " if((m_imagesWidth == bmp.GetWidth()) && (m_imagesHeight == bmp.GetHeight())){\n";
65 cppCode << " icn.CopyFromBitmap(bmp);\n";
66 cppCode << " this->Add(icn);\n";
67 cppCode << " }\n";
68 cppCode << " m_bitmaps.insert(std::make_pair(" << wxCrafter::WXT(GetName() + exts.Item(i))
69 << ", bmp));\n";
70 cppCode << " }\n";
71 cppCode << "}\n";
72 }
73 }
74 return cppCode;
75 }
76
77 void BitmapWrapepr::GetIncludeFile(wxArrayString& headers) const
78 {
79 headers.Add("#include <wx/bitmap.h>");
80 headers.Add("#include <wx/icon.h>");
81 }
82
83 wxString BitmapWrapepr::GetWxClassName() const { return ""; }
84
85 void BitmapWrapepr::ToXRC(wxString& text, XRC_TYPE type) const
86 {
87 if(type == XRC_DESIGNER) {
88 wxString designerXRC;
89 designerXRC << "<object class=\"sizeritem\">"
90 << "<border>5</border>"
91 << "<flag>wxALL</flag>"
92 << "<object class=\"wxStaticBitmap\" name=\"" << GetName() << "\">" << wxT("<bitmap>")
93 << PropertyFile(PROP_BITMAP_PATH) << wxT("</bitmap>") << XRCSuffix() // wxStaticBitmap
94 << XRCSuffix(); // sizeritem
95 text << designerXRC;
96
97 } else if(type == XRC_LIVE) {
98 text << XRCPrefix() << PropertyFile(PROP_BITMAP_PATH) << XRCSuffix();
99 }
100 }