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 » U++ Widgets - General questions or Mixed problems » How to draw random images in ArrayCtrl-cell using Display? [SOLVED]
How to draw random images in ArrayCtrl-cell using Display? [SOLVED] [message #53656] Sun, 19 April 2020 08:19 Go to next message
slashupp is currently offline  slashupp
Messages: 231
Registered: July 2009
Experienced Member
How do I pass an Image as a Value to a Display and access the image in the Display-code so I can draw it?
(The images are all of size 20x20)
E.g.:
struct MyPicDisplay : public Display
{
	virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
	{
		w.DrawRect(r, paper);
		Image img{};
		img= ??? how to get it from q ???
		if (!img.IsNullInstance()||img.IsEmpty()) w.DrawImage(r, img);
	}
};
//background info:
void someclass::ArShowPic(Image pic)
{
	//ar is an ArrayCtrl..
	//the column was declared with: ar.AddColumn().SetDisplay(Single<MyPicDisplay>());
	ar.Add(pic); //this invokes the display code where I have my problem.
}


[Updated on: Mon, 20 April 2020 07:02]

Report message to a moderator

Re: How to draw random images in ArrayCtrl-cell using Display? [message #53658 is a reply to message #53656] Sun, 19 April 2020 12:50 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1094
Registered: August 2007
Senior Contributor
Hello slashupp

Quote:
How do I pass an Image as a Value to a Display and access the image in the Display-code so I can draw it?


There is already ImageDisplay(), FittedImageDisplay(), CenteredImageDisplay(), and CenteredHighlightImageDisplay() classes in UPP for this task. You can use them if you are not going to further process the images before they are displayed.

However, if you want to use your code, below code should work.

virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
	{
		w.DrawRect(r, paper);
		Image img = q; // This should be enough if q is a Upp::Image.
		if (!img.IsNullInstance()||img.IsEmpty()) w.DrawImage(r, img);
	}



Or, if you like strict/pedantic code

    const Image& img = q.To<Image>();


This will work too.

Best regards,
Oblivion


[Updated on: Sun, 19 April 2020 12:56]

Report message to a moderator

Re: How to draw random images in ArrayCtrl-cell using Display? [SOLVED] [message #53664 is a reply to message #53658] Mon, 20 April 2020 07:00 Go to previous message
slashupp is currently offline  slashupp
Messages: 231
Registered: July 2009
Experienced Member
Thx for your answer.

Got it to work by simply doing
ar.AddColumn().SetDisplay(ImageDisplay())

and removing MyPicDisplay. I somehow missed ImageDisplay() when I searched (Ctrl-J) on 'Display'

For some reason could not get MyPicDisplay to work using either of your suggestions, which was why I asked the question originally.

Anyway it is working now, thanks.
Previous Topic: [GLCtrl] Adding an Initilisation function to GLPaint
Next Topic: [Proposal] EditSecret dialogs (EditText variants), for password, etc input..
Goto Forum:
  


Current Time: Sun Jun 16 08:38:01 CEST 2024

Total time taken to generate the page: 0.01456 seconds