User forums > Using Code::Blocks
Image field in wxImagePanel wxSmith tools
ollydbg:
--- Quote from: BlueHazzard on October 23, 2018, 10:34:49 pm ---What does "use include file" mean? Embed the image in the source code? Why is then the image stored in the wxs file? Is a header with the image code generated?
--- End quote ---
When the checkbox "use include file" is on, this means the big data array "static const char *Image1_XPM[]" is defined in a file "./wximages/test_wxImagePanelMain_Image1_XPM.xpm", this xpm file is included by the file "test_wxImagePanelMain.h"
--- Code: ---//(*Headers(test_wxImagePanelFrame)
#include "./wximages/test_wxImagePanelMain_Image1_XPM.xpm"
#include "wx/wxImagePanel.h"
#include <wx/bitmap.h>
#include <wx/frame.h>
#include <wx/image.h>
#include <wx/menu.h>
#include <wx/statusbr.h>
//*)
--- End code ---
If the checkbox "use include file" is off, then the "static const char *Image1_XPM[]" is directly inserted in the "test_wxImagePanelMain.cpp".
--- Quote ---Why is then the image stored in the wxs file? Is a header with the image code generated?
--- End quote ---
Whether the checkbox "use include file" is on or off, the wxs file always hold the whole XPM data array, which make the wxs file big. See the screen shot image below of the wxs file.
So, the genereated image code in either XPM file or in cpp file are a direct copy of the <image> in the wxs file.
--- Quote ---Is the basic idea that wxSmith needs the source image somewhere to restore the generated code if the user messes with it and saves the source image in the wxs-file?
--- End quote ---
The "wxImage tool" in wxSmith currently can only store the image code inside wxs. Which from my point is not necessary, why not directly store the path of the original image file. For example, we can store "<image>red-car.png</image>".
If you use the "wxStaticBitmap" control in the wxSmith, you will see it store the image file path.
--- Quote ---[Edit:]
--- Quote ---But I don't see Image1 is used in some place
--- End quote ---
Where should
--- Code: ---Image1
--- End code ---
be used? Isn't it only a name for the image tool?
--- End quote ---
Yes, I see that the name "Image1" is only a name. In the source code, I don't see any one use this file. If you look at the generated code in the mainframe's constructor:
--- Code: --- Image1 = new wxImage(Image1_XPM);
Image1_BMP = new wxBitmap(Image1_XPM);
// Set the bitmap for ImagePanel1.
ImagePanel1->SetBitmap(*Image1_BMP);
--- End code ---
You see, instead of using Image1, we actually use Image1_BMP, which is a wxBitmap type, and for wxImagePanel, we only call the function "SetBitmap(*Image1_BMP)".
I now know why the GCC warning comes:
Because the #include "./wximages/test_wxImagePanelMain_Image1_XPM.xpm" is included in "test_wxImagePanelMain.h". And the later on is included in both test_wxImagePanelMain.cpp and test_wxImagePanelApp.cpp. While the xpm image code is only used in the test_wxImagePanelMain.cpp. So building the test_wxImagePanelApp.cpp, GCC will give warnings that this "static const char *Image1_XPM[]" is not used.
EDIT
I add my project in attachment, you can have a look. The file wximagepanel.cpp/h is added to the project otherwise you have link error.
The wximagepanel.cpp/h files are modified versions of myself, I can't remember their original version(maybe from C::B source :) )
BlueHazzard:
I see.... I would also vote to use a path instead of the content, but i still wonder why the autor did it in the first place... I is a lot work to embed it, so i think he had some problem he wanted to circumvent...
ollydbg:
--- Quote from: BlueHazzard on October 24, 2018, 10:56:53 pm ---I see.... I would also vote to use a path instead of the content, but i still wonder why the autor did it in the first place... I is a lot work to embed it, so i think he had some problem he wanted to circumvent...
--- End quote ---
I don't know who is the original author of this wxImagePanel support in wxSmith.
I just looked at this code:
--- Code: ---wxObject* wxsStaticBitmap::OnBuildPreview(wxWindow* Parent,long Flags)
{
// Cryogen 24/3/10 Bug #15354. Since we're no longer using the Background class we don't need to differentiate between cases where
// the user has assigned a bitmap and those where he hasn't and we're using the fake background. Just return the preview.
wxStaticBitmap* Preview = new wxStaticBitmap(Parent,GetId(),Bitmap.GetPreview(Size(Parent)),Pos(Parent),Size(Parent),Style());
return SetupWindow(Preview,Flags);
}
--- End code ---
For the wxStaticBitmap, this code create the wxBitmap:
--- Code: ---wxBitmap wxsBitmapIconData::GetPreview(const wxSize& Size,const wxString& DefaultClient)
{
if ( Id.empty() )
{
if ( FileName.empty() )
{
return wxNullBitmap;
}
wxImage Img(FileName);
if ( !Img.Ok() ) return wxNullBitmap;
if ( Size != wxDefaultSize )
{
Img.Rescale(Size.GetWidth(),Size.GetHeight());
}
return wxBitmap(Img);
}
wxString TempClient = Client.empty() ? DefaultClient : Client;
return wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(Id),wxART_MAKE_CLIENT_ID_FROM_STR(TempClient),Size);
}
--- End code ---
So, it support both the ID and the filename to construct the wxBitmap.
While, for wxImagePanel, it use such code:
--- Code: ---wxObject* wxsImagePanel::OnBuildPreview(wxWindow* Parent, long Flags) {
wxImagePanel *ap;
wxsImage *image;
wxBitmap bmp;
// make a panel
ap = new wxImagePanel(Parent, GetId(), Pos(Parent), Size(Parent), Style());
if (ap == NULL) return NULL;
// get the wxsImage pointer
image = (wxsImage *) wxsImageListEditorDlg::FindTool(this, mImage);
// and make the preview image
if (image != NULL) {
bmp = ((wxsImage *) image)->GetPreview();
ap->SetBitmap(bmp);
};
// and stretch it?
ap->SetStretch(mStretch);
// set all decorations
SetupWindow(ap, Flags);
// add the children
AddChildrenPreview(ap, Flags);
// done
return ap;
}
--- End code ---
The "mImage" is the Id name, in my test case, it is "Image1", you can see it just lookup the name in the wxImage tool dict, and if can't find any one, it just failed to create the wxBitmap.
So, my idea is that we can use the "mImage" to support both the Id name in the wxImage tool dict and the file path. So, if lookup failed, I can interpret this string as a file path, so if someone write "aaa.png" in the mImage field, I will try the similar way as function " wxsBitmapIconData::GetPreview" did, and construct the wxBitmap. ;)
ollydbg:
--- Quote from: ollydbg on October 26, 2018, 02:57:55 am ---The "mImage" is the Id name, in my test case, it is "Image1", you can see it just lookup the name in the wxImage tool dict, and if can't find any one, it just failed to create the wxBitmap.
So, my idea is that we can use the "mImage" to support both the Id name in the wxImage tool dict and the file path. So, if lookup failed, I can interpret this string as a file path, so if someone write "aaa.png" in the mImage field, I will try the similar way as function " wxsBitmapIconData::GetPreview" did, and construct the wxBitmap. ;)
--- End quote ---
OK, this works, see the below patch:
--- Code: --- .../contrib/wxSmithContribItems/wximagepanel/wxsimagepanel.cpp | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/plugins/contrib/wxSmithContribItems/wximagepanel/wxsimagepanel.cpp b/src/plugins/contrib/wxSmithContribItems/wximagepanel/wxsimagepanel.cpp
index f9b8430f..d52365e1 100644
--- a/src/plugins/contrib/wxSmithContribItems/wximagepanel/wxsimagepanel.cpp
+++ b/src/plugins/contrib/wxSmithContribItems/wximagepanel/wxsimagepanel.cpp
@@ -166,6 +166,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 ---
ollydbg:
The reason I would like this feature is that I want to put some wxTextCtrl on an image, so that I can tweak their values, see below two screen shot images:
First image, under wxsmith designer:
Second image, the test application:
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version