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 |
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 |
Oblivion
Messages: 1112 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
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[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 |
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.
|
|
|
Goto Forum:
Current Time: Fri Sep 20 07:03:36 CEST 2024
Total time taken to generate the page: 0.03266 seconds
|