Re: Question about blend()

JVZ <[email protected]> Thu, 12 Dec 2024 20:09:35 -0600
Newsgroups gmane.comp.lib.fox-toolkit.user
Organization FOX-Toolkit
Message-ID <20241212200935.63a89b11@yellowstone>
On Thu, 12 Dec 2024 11:01:30 +0100
Jean Truc <[email protected]> wrote:

>Sorry, I forgot to paste some lines. Here is the working code:
>
>// Use IMAGE_KEEP for blending to background
>miniIcon->setOptions(IMAGE_KEEP);
>
>miniIcon->create();
>
>[...]
>
>FXColor* tmpdata;
>FXuint w = miniIcon->getWidth();
>FXuint h = miniIcon->getHeight();
>
>if (isSelected())
>{
>// Save original pixels
>if (!FXMEMDUP(&tmpdata, miniIcon->getData(), FXColor, w * h))
>{
>throw FXMemoryException(_("Unable to load image"));
>}
>
>  // Blend to list selection color
>  miniIcon->blend(app->getSelbackColor());
>miniIcon->render();
>
>// Restore original pixels
>miniIcon->setData(tmpdata, IMAGE_KEEP, w, h);
>}
>else
>{
>// Save original pixels
>FXColor* tmpdata;
>if (!FXMEMDUP(&tmpdata, miniIcon->getData(), FXColor, w * h))
>{
>throw FXMemoryException(_("Unable to load image"));
>}
>
>  // Blend to list background color
>  miniIcon->blend(app->getBackColor());
>miniIcon->render();
>
>// Restore original pixels
>miniIcon->setData(tmpdata, IMAGE_KEEP, w, h);
>}
>
>Le jeu. 12 déc. 2024 à 10:40, Jean Truc <[email protected]> a écrit :
>
>> OK, sorry I missed the important part that original pixels are destroyed
>> after blending.
>>
>> Now, it works! Here is the code for an icon with blending to background or
>> to selection background if the icon is selected:
>>
>> // Use IMAGE_KEEP for blending to background
>> miniIcon->setOptions(IMAGE_KEEP);
>>
>> miniIcon->create();
>>
>> [...]
>>
>> if (isSelected())
>> {
>> // Save original pixels
>> if (!FXMEMDUP(&tmpdata, miniIcon->getData(), FXColor, w * h))
>> {
>> throw FXMemoryException(_("Unable to load image"));
>> }
>>
>>   // Blend to list selection color
>>   miniIcon->blend(app->getSelbackColor());
>> miniIcon->render();
>>
>> // Restore original pixels
>> miniIcon->setData(tmpdata, IMAGE_KEEP, w, h);
>> }
>> else
>> {
>> // Save original pixels
>> FXColor* tmpdata;
>> if (!FXMEMDUP(&tmpdata, miniIcon->getData(), FXColor, w * h))
>> {
>> throw FXMemoryException(_("Unable to load image"));
>> }
>>
>>   // Blend to list background color
>>   miniIcon->blend(app->getBackColor());
>> miniIcon->render();
>>
>> // Restore original pixels
>> miniIcon->setData(tmpdata, IMAGE_KEEP, w, h);
>> }
>>
>> Thanks a lot Jeroen for your detailed explanations!
>> JT


Now of course, if you're switching between selected and unselected,
it'll probably be faster to just keep two versions of the icon,
and switch the icon out by intercepting the list widget's select/deselect
messages.  This should be quite fast if both icons are created ahead
of time and kept around somewhere.

 -- JVZ



-- 
+----------------------------------------------------------------------------+
| Copyright (C) 12:00 03/31/2018 Jeroen van der Zijp.   All Rights Reserved. |
+----------------------------------------------------------------------------+


_______________________________________________
Foxgui-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/foxgui-users