|
|
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » image drawn in Paint(Draw &w) does not stay when refereshed
image drawn in Paint(Draw &w) does not stay when refereshed [message #12917] |
Wed, 28 November 2007 13:10  |
amit
Messages: 17 Registered: November 2007
|
Promising Member |
|
|
hi,
problem:
1) I am trying to write a small app with a logo in the start of it.
2) the logo was made in the constructor from RGB raw data.
3) the image is painted on Paint() function.
-- when build and executed the logo works out fine
-- but if refreshed (window size changed, alt-tabbed back or if Refresh() is called), the image goes away.
-- note: other stuff as DrawRect(..) and DrawText(..) works fine it just the image is not redrawn.
code:
#include "my_class.h"
#include "logo.h"
#include "windows.h"
my_class::my_class()
{
CtrlLayout(*this, "Window title");
//ToolWindow(true);
//ExStyle(WS_EX_TOOLWINDOW | WS_OVERLAPPED);
//Style(WS_POPUP);
login_btn <<= THISBACK(process_login);
////////////< ------------------------------------------------------------ ------------------------------------------------------------ --------------------------logo stuff start
logo = ImageBuffer(150,30);
RGBA *pixel = logo;
byte *raw_image_data = (byte *)logo_hex_data;
for(int i=0; i<150*30; i++)
{
pixel->a = 255;
pixel->r = *raw_image_data++;
pixel->g = *raw_image_data++;
pixel->b = *raw_image_data++;
pixel++;
}
logo.SetKind(IMAGE_OPAQUE);
////////////< ------------------------------------------------------------ ------------------------------------------------------------ ----------------------------------------logo stuff end
//Maximize(true);
Sizeable(false);
Sizeable().Zoomable();
BackPaint();
}
void my_class::Paint(Draw& w)
{
w.DrawRect(GetSize(), SWhite);
w.DrawImage(10, 20, logo); ///////////< ------------------------------------------------------------ -------------------------------------------- logo drawn
w.DrawText(20, 20, "Hello world!", Arial(30), Magenta);
}
void my_class::process_login()
{
console.SetText((user_id.GetText() + password.GetText()).ToString());
//MessageBox( NULL, (user_id.GetText() + password.GetText()).ToString(), "wow", MB_OK);
}
GUI_APP_MAIN
{
my_class().Run();
}
[Updated on: Wed, 28 November 2007 13:15] Report message to a moderator
|
|
|
|
|
Re: image drawn in Paint(Draw &w) does not stay when refereshed [message #12942 is a reply to message #12926] |
Fri, 30 November 2007 00:19   |
amit
Messages: 17 Registered: November 2007
|
Promising Member |
|
|
hi Nick, no, it not that ..
1) firstly .... i am using a .lay file (hence there are a few controls like edit box and buttons) (sorry, it was included in .h file) so a layout is required.
2) I still tried commenting " CtrlLayout(*this, "Window title"); ", but ...
---------a) there was no change in the mentioned behavior.
---------b) as expected the controls in .lay disappeared.
...thanks anyways
... i think James might be right i'll try that and get back
....... ok Back ... good news, got it working, see the next message ..
[Updated on: Fri, 30 November 2007 00:31] Report message to a moderator
|
|
|
|
Re: image drawn in Paint(Draw &w) does not stay when refereshed [message #12952 is a reply to message #12943] |
Fri, 30 November 2007 10:33   |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
You are correct in that it is a performance feature. ImageBuffers are only designed to be used for image processing, then converted to Images for storage. When you do Image = ImageBuffer, instead of using memcpy to duplicate the pixel data the ownership of the memory is just transfered.
The problem occurred in this case because the parameters for Draw::DrawImage are all something like:
void DrawImage(const Rect& r, const Image& img);
so that if you pass in an ImageBuffer it is implicitly converted to a temporary Image (because it has operator Image), loosing ownership of the pixel data. The Image is passed to DrawImage and then destroyed, deleting the pixel data. Viola! The Image no longer exists 
Glad I could help.
[Updated on: Fri, 30 November 2007 10:36] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Tue May 13 11:23:33 CEST 2025
Total time taken to generate the page: 0.00560 seconds
|
|
|