User forums > Using Code::Blocks

Image field in wxImagePanel wxSmith tools

(1/4) > >>

ollydbg:
Hi, does any one know what is the Image field used for? (See image shot below)
It looks like this field does not affect the generated code.

This is the xml in the wxs file.

--- Code: --- <object class="wxImagePanel" name="ID_IMAGEPANEL3" variable="ImagePanel3" member="yes">
<image>Lenna111.png</image>
<pos>120,8</pos>
</object>

--- End code ---

This is the generated code in cpp file

--- Code: ---    ImagePanel3 = new wxImagePanel(AuiNotebook1, ID_IMAGEPANEL3, wxPoint(120,8), wxDefaultSize, wxRAISED_BORDER|wxTAB_TRAVERSAL, _T("ID_IMAGEPANEL3"));
    ImagePanel3->SetStretch(false);

--- End code ---

What I want is that I can set the Image, and the wxSmith should show the image in its GUI preview window.  :)

ollydbg:
OK, problem solved.
By looking at the source code:
https://github.com/obfuscated/codeblocks_sf/blob/master/src/plugins/contrib/wxSmithContribItems/wximagepanel/wxsimagepanel.cpp

I see that an wxImage is needed, so I simply add an wxImage, and now I can select the wxImage variable name in the "Image" field of the wxImagePanel.  ;)

ollydbg:
OK, I just found another issue.
When I use the "wxImage tool" inside wxSmith, I see all the image data(XPM char format in text mode) was saved in the wxs file. This make my wxs file a lot larger if I would like to use a big image.

Is there any way I can directly save the file like the "wxStaticBitmap" does? This control only save the path of the image file.

ollydbg:
In the file:
\src\plugins\contrib\wxSmith\wxwidgets\defitems\wxsimage.h

I see it has some code snippet:

--- Code: ---/*! \brief Class for the wxsImage tool.
 *    \note For reasons unknown, GCC emits a warning that the image is declared but not used when "Use Include File" is set.
 */
class wxsImage : public wxsTool
{
    public:

        wxsImage(wxsItemResData* Data);
        wxBitmap  GetPreview(void);
        void            DoBuild(void);



--- End code ---
So, it report the GCC will report a warning. I also see this build warning of the generated code.
But what I see is that the generated code has some issues:

1, I first add a wxImage tool by click the wxImage toolbar button in the wxSmith Tools panel. (see below image)


2, then I add an image by select an png file in the wxImage's property list, also I have select the image from disk (see image below)


3, select the "Image1" in the wxImagePanel control, see image below:


4, then I build the project, I see such warning:


--- Code: ---
-------------- Build: Debug in test-wxImagePanel (compiler: GNU GCC Compiler)---------------

g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Winvalid-pch -include wx_pch.h -DWX_PRECOMP -Wall -g -DTEST -IE:\wxWidgets-3.1.1-rc\include -IE:\wxWidgets-3.1.1-rc\lib\gcc_dll\mswu -c E:\code\test-wxImagePanel\test_wxImagePanelApp.cpp -o obj\Debug\test_wxImagePanelApp.o
In file included from E:\code\test-wxImagePanel\test_wxImagePanelMain.h:14:0,
                 from E:\code\test-wxImagePanel\test_wxImagePanelApp.cpp:14:
E:/code/test-wxImagePanel/wximages/test_wxImagePanelMain_Image1_XPM.xpm:1:20: warning: 'Image1_XPM' defined but not used [-Wunused-variable]
 static const char *Image1_XPM[] = {
                    ^~~~~~~~~~
g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Winvalid-pch -include wx_pch.h -DWX_PRECOMP -Wall -g -DTEST -IE:\wxWidgets-3.1.1-rc\include -IE:\wxWidgets-3.1.1-rc\lib\gcc_dll\mswu -c E:\code\test-wxImagePanel\test_wxImagePanelMain.cpp -o obj\Debug\test_wxImagePanelMain.o
g++.exe -LE:\wxWidgets-3.1.1-rc\lib\gcc_dll -o bin\Debug\test-wxImagePanel.exe  obj\Debug\test_wxImagePanelApp.o obj\Debug\test_wxImagePanelMain.o obj\Debug\wximagepanel.o obj\Debug\resource.res -mthreads  -lwxmsw31u -mwindows
Output file is bin\Debug\test-wxImagePanel.exe with size 1.28 MB
Process terminated with status 0 (0 minute(s), 2 second(s))
0 error(s), 1 warning(s) (0 minute(s), 2 second(s))

--- End code ---

I see the variable is used in such generated code:

--- Code: ---test_wxImagePanelFrame::test_wxImagePanelFrame(wxWindow* parent,wxWindowID id)
{
    //(*Initialize(test_wxImagePanelFrame)
...
    Image1 = new wxImage(Image1_XPM);
    Image1_BMP = new wxBitmap(Image1_XPM);

    // Set the bitmap for ImagePanel1.
    ImagePanel1->SetBitmap(*Image1_BMP);
...
    //*)
}

--- End code ---

But as you can see, "Image1_XPM" is used here. But I don't see Image1 is used in some place. Question: does GCC deduced that Image1_XPM is not used?

--- Code: ---Image1 = new wxImage(Image1_XPM);
--- End code ---

If you look at the wxs file, you will see some code snippet:


--- Code: --- <object class="wxImage" variable="Image1" member="yes">
<image>
<Item>static const char *xpm_data[] = {</Item>
<Item>&quot;225 225 48 1&quot;,</Item>
<Item>&quot;, c #FFD6D6&quot;,</Item>
<Item>&quot;x c #FF2E2E&quot;,</Item>
<Item>&quot;$ c #FF9B9B&quot;,</Item>
<Item>&quot;O c #FFD0D0&quot;,</Item>
<Item>&quot;&amp; c #FF9595&quot;,</Item>
<Item>&quot;9 c #FF5A5A&quot;,</Item>
<Item>&quot;_ c #FFFFFF&quot;,</Item>
<Item>&quot;* c #FF8F8F&quot;,</Item>
<Item>&quot;&lt; c #FF8C8C&quot;,</Item>
<Item>&quot;l c #FFC1C1&quot;,</Item>
<Item>&quot;. c #FFF6F6&quot;,</Item>
<Item>&quot;X c #FFF0F0&quot;,</Item>
......
......

--- End code ---
Look, the whole image data was saved in the wxs file(the wxs file has thousands of lines), which make the wxs file hard to read and maintain.
My question is: can we simply save the file path like <image>red-car.png</image> here? From reading the source code(mainly the \src\plugins\contrib\wxSmith\wxwidgets\defitems\wxsimage.h and \src\plugins\contrib\wxSmith\wxwidgets\defitems\wxsimage.cpp, I don't see that "wxImage tool" support such data persistence.





BlueHazzard:
generally: cool, i did not know this worked xD

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?
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?

[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?

Navigation

[0] Message Index

[#] Next page

Go to full version