User forums > Using Code::Blocks
Image field in wxImagePanel wxSmith tools
ollydbg:
OK, I have added the code generation part, so now the full patch comes, any comments?
--- Code: --- .../wximagepanel/wxsimagepanel.cpp | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/plugins/contrib/wxSmithContribItems/wximagepanel/wxsimagepanel.cpp b/src/plugins/contrib/wxSmithContribItems/wximagepanel/wxsimagepanel.cpp
index f9b8430f..8d6ec110 100644
--- a/src/plugins/contrib/wxSmithContribItems/wximagepanel/wxsimagepanel.cpp
+++ b/src/plugins/contrib/wxSmithContribItems/wximagepanel/wxsimagepanel.cpp
@@ -134,7 +134,17 @@ wxString tt;
tt.Printf(_T("%s->SetBitmap(*%s);\n"), vname.c_str(), iname.c_str());
#endif
AddEventCode(tt);
- };
+ }
+ else
+ {
+ // if we can't find the image in wxsImage, we fallback to interpret it as a file path
+ // some code need to be like below:
+ // wxBitmap bmp = wxBitmap(wxImage(_T("circuit.png")));
+ // ImagePanel1->SetBitmap(bmp);
+ wxString bmpFilename = vname + "_bmp";
+ Codef(_T("wxBitmap %s = wxBitmap(wxImage((\"%s\")));\n"), bmpFilename.wx_str(), mImage.wx_str());
+ Codef(_T("%ASetBitmap(%s);\n"), bmpFilename.wx_str());
+ }
// do the rest of it
@@ -166,6 +176,15 @@ wxBitmap bmp;
if (image != NULL) {
bmp = ((wxsImage *) image)->GetPreview();
ap->SetBitmap(bmp);
+ }
+ else{ // in case we can't find the name in ImageList, we try to interpret it as a filepath
+ // see discussion http://forums.codeblocks.org/index.php/topic,22888.0.html
+ wxImage Img(mImage);
+ if (Img.Ok())
+ {
+ bmp = wxBitmap(Img);
+ ap->SetBitmap(bmp);
+ }
};
// and stretch it?
--- End code ---
BlueHazzard:
With your patches: if i put a filename in the "Image" property then this will get used? And the path will also be saved in the xrc resource?
ollydbg:
--- Quote from: BlueHazzard on October 27, 2018, 11:18:56 pm ---With your patches: if i put a filename in the "Image" property then this will get used? And the path will also be saved in the xrc resource?
--- End quote ---
Without the patch, the "Image" property of the wxImagePanel is only depend on the wxImage tool, so if I put a string in the property, it will look up the string as the image ID in the wxImage tool, and if it can't find one, it just doesn't show the image in the wxImagePanel's preview.
While, with this patch, the above lookup mechinism still exists, but if it failed, we can try to interpret the property's string as a filename, so the "Image" property support both the "Image ID in wxImage tool" and "the filename of the image".
About the wxsmith's wxImage control: my patch doesn't touch this control, so it still store the raw XPM text string in .wxs file.
Hope you understand my explanation. :)
ollydbg:
I will commit this changes next week if there is no objections. :)
Thanks.
oBFusCATed:
I'm not following the topic, but please check that old wxs files still work and produce correct code!
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version