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 » Showing bitmaps or Icons
Showing bitmaps or Icons [message #117] Sat, 26 November 2005 08:55 Go to next message
gprentice is currently offline  gprentice
Messages: 260
Registered: November 2005
Location: New Zealand
Experienced Member

Where would I look for info on how to load and show a .bmp bitmap file or an icon (given an icon handle HICON on Win32) and then get mouse events (mouse move, mouse click) for this image?

Second question : if there's a short answer, any hints on how to do this?

e.g. suppose I want a customised checkbox - I create two bitmaps (checked and unchecked) that I want to switch when the image is clicked.

Last question : I recall mention of a grid component created by Daniel. Is this part of UPP? If not, it's ok. Just wondering.


Graeme
Re: Showing bitmaps or Icons [message #123 is a reply to message #117] Sat, 26 November 2005 10:33 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Quote:


Where would I look for info on how to load and show a .bmp bitmap file or an icon (given an icon handle HICON on Win32) and then get mouse events (mouse move, mouse click) for this image?


Load it in to the Image, then create your own Ctrl, paint it in the Paint an react to the MouseMove/LeftDown etc...

To load it into the Image, use BmpEncoder. Note: this part a little bit complex, as Tom designed the interface (sorry for this little retaliation Tom :):

Image img = BmpEncode::NewBmp()->LoadImage(....

Quote:


suppose I want a customised checkbox - I create two bitmaps (checked and unchecked) that I want to switch when the image is clicked.



In this case using .bmp is quite ineffective, for U++. Just design your images in the ImageDes (in .iml file) and then use them (in U++, Image is simple value object - use it as it was String.... .iml will provide you a set of "function-constants" that will return your images designed in .iml).

See reference/iml

Quote:

I recall mention of a grid component created by Daniel. Is this part of UPP? If not, it's ok. Just wondering.


Not yet. I am lagging Smile (I have to add his DatePicker first Smile
Re: Showing bitmaps or Icons [message #126 is a reply to message #117] Sat, 26 November 2005 12:56 Go to previous messageGo to next message
gprentice is currently offline  gprentice
Messages: 260
Registered: November 2005
Location: New Zealand
Experienced Member

Quote:

In this case using .bmp is quite ineffective, for U++. Just design your images in the ImageDes (in .iml file) and then use them (in U++, Image is simple value object - use it as it was String.... .iml will provide you a set of "function-constants" that will return your images designed in .iml).

See reference/iml




Interesting, thanks. I tried the iml example and notice some "flickering effects" in the image when the window is resized. Even with a non centered image whose position isn't changing when the window is resized, I get a little bit of flickering. Is this expected? Any ideas for how to avoid it? If I drag the window round the screen I don't get any flickering in the image.

I remember flickering was an issue with wxWidgets as discussed here -
http://wiki.wxwidgets.org//wiki.pl?action=browse&id=Flic ker-Free_Drawing&revision=18

I vaguely recall one of the solutions was to avoid erasing.

Graeme
Re: Showing bitmaps or Icons [message #127 is a reply to message #117] Sat, 26 November 2005 13:24 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Quote:


Interesting, thanks. I tried the iml example and notice some "flickering effects" in the image when the window is resized. Even with a non centered image whose position isn't changing when the window is resized, I get a little bit of flickering. Is this expected? Any ideas for how to avoid it? If I drag the window round the screen I don't get any flickering in the image.



Well, simple solution is Ctrl::BackPaint. That will make Ctrl painting double-buffered.

However, this is not on by default because of performance issues.

This is the purpose of the "new Draw" research - if the "new Draw" proves to be doable/viable, "native" double-buffering is one of advantages.
Re: Showing bitmaps or Icons [message #1803 is a reply to message #127] Mon, 20 March 2006 07:45 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Why this doesn't work?
#include <CtrlLib/CtrlLib.h>

GUI_APP_MAIN
{     TopWindow w;
      Label l;
      Image img;

      w.Add(l);
	l.SetPos(l.PosLeft(0, 100), l.PosTop(0, 30));	

	img = BmpEncoder::NewBmp()->LoadImage("testImg.bmp");
	//img.Exclamation();    //at least this should work?
	l.SetImage(img);

	w.Run();
}



And how to check if image was loaded?

[Updated on: Mon, 20 March 2006 07:45]

Report message to a moderator

Re: Showing bitmaps or Icons [message #1806 is a reply to message #1803] Mon, 20 March 2006 09:12 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
fudadmin wrote on Mon, 20 March 2006 01:45

Why this doesn't work?
#include <CtrlLib/CtrlLib.h>

GUI_APP_MAIN
{     TopWindow w;
      Label l;
      Image img;

      w.Add(l);
	l.SetPos(l.PosLeft(0, 100), l.PosTop(0, 30));	

	img = BmpEncoder::NewBmp()->LoadImage("testImg.bmp");
	//img.Exclamation();    //at least this should work?
	l.SetImage(img);

	w.Run();
}



And how to check if image was loaded?


Are you sure that path is correct? (Well, there is no path, so it likely is not).

If it was not loaded, result will be empty (e.g. GetSize() == Size(0, 0))

Mirek
Re: Showing bitmaps or Icons [message #1813 is a reply to message #1806] Mon, 20 March 2006 14:27 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
luzr wrote on Mon, 20 March 2006 08:12

fudadmin wrote on Mon, 20 March 2006 01:45

Why this doesn't work?
#include <CtrlLib/CtrlLib.h>

GUI_APP_MAIN
{     TopWindow w;
      Label l;
      Image img;

      w.Add(l);
	l.SetPos(l.PosLeft(0, 100), l.PosTop(0, 30));	

	img = BmpEncoder::NewBmp()->LoadImage("testImg.bmp");
	//img.Exclamation();    //at least this should work?
	l.SetImage(img);

	w.Run();
}



And how to check if image was loaded?


Are you sure that path is correct? (Well, there is no path, so it likely is not).

If it was not loaded, result will be empty (e.g. GetSize() == Size(0, 0))

Mirek


Are you sure that you know Ultimate++?... Wink

The image loading works this way:

GUI_APP_MAIN
{
	TopWindow w;
	Label l1,l2;
	Image img1,img2;
	
	w.Add(l1);
	l1.SetPos(l1.PosLeft(10, 100), l1.PosTop(10, 30));	

	img1= PngEncoder::New()->LoadImageFile("testImg.png");
	l1.SetImage(img1);

	
	w.Add(l2);
	img2 = BmpEncoder::NewBmp()->LoadImageFile("testImg.bmp");	
	l2.SetImage(img2);
	l2.SetPos(l2.PosLeft(150, 100), l2.PosTop(10, 30));
		
	w.Run();
}


[Updated on: Mon, 20 March 2006 14:28]

Report message to a moderator

Re: Showing bitmaps or Icons [message #1971 is a reply to message #117] Wed, 29 March 2006 03:26 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
gprentice wrote on Sat, 26 November 2005 07:55


e.g. suppose I want a customised checkbox - I create two bitmaps (checked and unchecked) that I want to switch when the image is clicked.

Graeme


BTW, you can use:
ButtonOption opt;
...
	opt.SetImage( BmpEncoder::NewBmp()->LoadImageFile("OffIMG.bmp"), 
	PngEncoder::New()->LoadImageFile("OnIMG.png") );
//you can choose image formats...
//don't forget to adjust sizes accordingly...

Re: Showing bitmaps or Icons [message #2502 is a reply to message #117] Sat, 15 April 2006 13:20 Go to previous messageGo to next message
gprentice is currently offline  gprentice
Messages: 260
Registered: November 2005
Location: New Zealand
Experienced Member
Is the code below valid - it seems to work?
gp1 is the name of a bitmap in an .iml file, just like Smiley() in the reference/iml example. What does img1 = gp1() do - does img1 store a copy of the bitmap?

GUI_APP_MAIN
{
	App w;
	Label l1;
	Image img1;
	
	w.Add(l1);
	l1.SetPos(l1.PosLeft(10, 100), l1.PosTop(10, 30));	
	img1= gp1();
	l1.SetImage(img1);
	w.Run();
}


In the iml example there is
w.DrawImage((sz.cx - isz.cx) / 2, (sz.cy - isz.cy) / 2, Smiley());


What does "Smiley()" do here - does it get the "address" of the Smiley bitmap that has been embedded in the app due to the iml file being part of the project?


Graeme

BTW - in the reference/events example, the Log("Paint") in the Paint function causes continuous events ... I can't remember if this was originally a commented line and I uncommented it myself or not.

[Updated on: Sun, 16 April 2006 11:35]

Report message to a moderator

Re: Showing bitmaps or Icons [message #2550 is a reply to message #2502] Mon, 17 April 2006 18:52 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Quote:


gp1 is the name of a bitmap in an .iml file, just like Smiley() in the reference/iml example. What does img1 = gp1() do - does img1 store a copy of the bitmap?



Think about Image as of any other "value" type like "int", "Date" or "String". Copies are full and cheap (internally there is reference counting mechanism, but that is nothing you should bother you).

Now "Smiley()" is the Image you have designed and stored in .iml - it is Image constant. In fact, in ideal world, its definition would be (in header)

extern Image Smiley;

However, there are two problems with this:

- first, certain platforms (namely Win32) do not support global variables in .dll (not that we are using .dlls all that often, but it is better to be ready).

- second, global variables in C++ has unpleasant problem of "initialization" order. In practice, in constructor of global variable you are never sure which other global variables are already constructed (unless they are in the same .cpp file).

Therefore, instead of global variable, we are (quite often) using "functional constants". E.g.

const Image& Smiley();

This solves both problems.

Mirek
Previous Topic: Image with Layout (iml) painted red, why?
Next Topic: When I added "Draw" package to my project (605dev1), I get "plugin\z" added...
Goto Forum:
  


Current Time: Fri Mar 29 11:45:10 CET 2024

Total time taken to generate the page: 0.01510 seconds