Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
amit is currently offline  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 #12926 is a reply to message #12917] Wed, 28 November 2007 23:43 Go to previous messageGo to next message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
Hi Amit,

I'm no expert but try getting rid of the first line in your constructor. You are not using a layout and you are painting yourself so you dont need this line.

Please let me know if that works. If not I'll run your code and take a closer look.

Nick
Re: image drawn in Paint(Draw &w) does not stay when refereshed [message #12937 is a reply to message #12926] Thu, 29 November 2007 14:16 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
I can't get that code to compile in GCC, but my best guess is that logo is an ImageBuffer - When DrawImage is called it converted to an Image and this clears the ImageBuffer so that next Refresh it is empty.

Try changing logo to an Image and doing:
ImageBuffer ib(150,30);
RGBA *pixel = ~ib;
...
logo = ib;


James

[Updated on: Thu, 29 November 2007 14:28]

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 Go to previous messageGo to next message
amit is currently offline  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

icon14.gif  Re: image drawn in Paint(Draw &w) does not stay when refereshed [message #12943 is a reply to message #12937] Fri, 30 November 2007 00:28 Go to previous messageGo to next message
amit is currently offline  amit
Messages: 17
Registered: November 2007
Promising Member
mrjt wrote on Thu, 29 November 2007 18:46

I can't get that code to compile in GCC, but my best guess is that logo is an ImageBuffer - When DrawImage is called it converted to an Image and this clears the ImageBuffer so that next Refresh it is empty.

Try changing logo to an Image and doing:
ImageBuffer ib(150,30);
RGBA *pixel = ~ib;
...
logo = ib;


James



Smile Smile Smile thats exactly what it was ... it perfectly solved the problem .... thanks a lot, the change made were exact ... but why does it clears the ImageBuffer in DrawImage()?? let me guess , it is a trade off for performance and stuff?? that works perfectly fine with me (off course it would be fine ... there is another 'clean' method of doing my requirement )

thanks a lot ... i was using ImageCtrl as a solution but there were some side effect as ImageCtrl is a control itself and hence did not behave like the rest of surface client on mouse functions.

the final code is:

Image logo; // changed form ImageBuffer logo; (in the .h main class)

 ----------------------

////////////< ------------------------------------------------------------ ------------------------------------------------------------ --------------------------logo stuff start
ImageBuffer ib = ImageBuffer(150,30); // changed
RGBA *pixel = ~ib; // or (... = ib ) //changed
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++;
}
ib.SetKind(IMAGE_OPAQUE); // changed

logo = ib; // changed

////////////< ------------------------------------------------------------ ------------------------------------------------------------ ----------------------------------------logo stuff end



one more help ... just wanted to know the exact reason why DrawImage() clears ImageBuffer

[Updated on: Fri, 30 November 2007 07:27]

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 Go to previous messageGo to next message
mrjt is currently offline  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 Smile

Glad I could help.

[Updated on: Fri, 30 November 2007 10:36]

Report message to a moderator

Re: image drawn in Paint(Draw &w) does not stay when refereshed [message #12962 is a reply to message #12952] Fri, 30 November 2007 15:31 Go to previous message
amit is currently offline  amit
Messages: 17
Registered: November 2007
Promising Member
mrjt wrote on Fri, 30 November 2007 15:03

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 Smile

Glad I could help.



ahaa ... thats it, thanks again



Previous Topic: Display bug in ArrayCtrl
Next Topic: Why BMPEncoder::NewBmp() doesn´t exists anymoe?
Goto Forum:
  


Current Time: Wed Nov 20 17:59:12 CET 2019

Total time taken to generate the page: 0.01173 seconds