transparency in image vs button

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

transparency in image vs button

Post by SteveTX » Thu Jul 04, 2013 1:03 am

I have mouseUp handlers assigned to images, but I notice that the transparent icons in the images aren't treated the same way is in buttons. In buttons, the whole area including transparent and alphatransparent registers mouseUp events. It appears that on images this is not the case, and only opaque pixels will register a mouseUp event. Is there a way to make the transparent pixels on the images also respond to mouseUp?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: transparency in image vs button

Post by Simon » Thu Jul 04, 2013 7:04 am

Hi Steve,
Nope, best to set their transparency to 1%... maybe 5%.
If you don't have the original image you can try adding a layer @ 1 % and then saving it as a png.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: transparency in image vs button

Post by Mag » Thu Jul 04, 2013 9:50 am

Hi Steve,

in most cases the best way to display images which needs interactions with the user is to display them in buttons

Code: Select all

    set the icon of button "myButton" to "myImage"
Where "myImage" is any name of an image that you have in a card of a stack or substack.

Another solution could be to put a button with opaque set to false over the image, but in this case you need more effort to move them together if you need to.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: transparency in image vs button

Post by bn » Thu Jul 04, 2013 1:50 pm

Steve,

while Mag's suggestion to use a button is usually the way to go here is a little script that sets the alphaData (the data for transparency) just from 0 (completely transparent) to 1 (hardly noticeble less transparent).
Sometimes one wants to stick to image nonetheless.

This only applies to images with transparent areas, usually png.

Transparent parts of your image will now get the mouse events.

Code: Select all

on mouseUp
   put the alphaData of image "myImage" into tData
   put the length of tData into tHowOften
   put numToChar(0) into tTrans -- transparent
   put numToChar(1) into tAlmostTrans -- almost transparent
   repeat with i = 1 to tHowOften
      if char i of tData = tTrans then put tAlmostTrans into char i of tData
   end repeat
   set the alphaData of image "myImage" to tData
end mouseUp
Kind regards
Bernd

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: transparency in image vs button

Post by Simon » Thu Jul 04, 2013 7:40 pm

Nice one Bernd!

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: transparency in image vs button

Post by bn » Thu Jul 04, 2013 7:59 pm

Thanks Simon,

though one caveat:

If you apply this script to a referenced image (an image the has its fileName set and thus points to a file) then the image will loose the filename and is not longer a referenced image but a local image.

If you want to apply this change to a referenced image and you want to make that change permanent in the file you would have to export that image. After export the image in the file keeps the alpha-channel setting.

Kind regards
Bernd

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: transparency in image vs button

Post by SparkOut » Sun Jul 07, 2013 4:38 pm

This old thread may also prove worthwhile to examine

http://forums.runrev.com/phpBB2/viewtop ... 938#p38938

fpierron
Posts: 56
Joined: Thu Dec 16, 2010 11:12 am
Contact:

Re: transparency in image vs button

Post by fpierron » Wed Jul 17, 2013 11:34 pm

Hi
I am searching an opposite solution :

I have a map of France with 95 regions in it.
I want the user be able to select 1 region to get information on it.

If it is images, it works fine : the transparent part of the image is not selected by the rollover or the mouseUp event.
But if I want to change the color of the region on rollover or on mouseUp, I can not change the image because it is in a group and the group is not a background. Then, I have tried the color overlay functions, it works but it is far too slow !

I have tried to put these 95 regions in 95 buttons, but when buttons have transparent background that overlap, it does not work at all as 1 region can be highlighted when another is selected...

I think the best way would be to change dynamically the image of the selected region, but I can not go through that : as the 95 regions are grouped all together.

If anyone has an idea, thanks in advance.

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: transparency in image vs button

Post by SteveTX » Thu Jul 18, 2013 6:01 am

You aren't going to want buttons considering the overlap of rect transparency. You need 95 images on top of each other, not 95 buttons, and embed inside the script of each image object the mouseUp event and actions per image. The grouping of the images should make no difference.

fpierron
Posts: 56
Joined: Thu Dec 16, 2010 11:12 am
Contact:

Re: transparency in image vs button

Post by fpierron » Thu Jul 18, 2013 9:43 pm

Thanks.
I do not want to make one script per image, it is too tricky to manage.
I use mouseUp, Down, Leave, Enter, Move on the group with "the target".
I still can not modify images inside the group. I am almost sure there is something to do with the background as it is in the error msg (can not find the background).

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: transparency in image vs button

Post by Simon » Thu Jul 18, 2013 10:25 pm

Hi fpierron,
95 images sounds like a good time to build yourself an LC tool.
What I mean is that you use LC to do the hard/repetitive work for you.
Lookup "script" in the dictionary.

Now hopefully your images have sequential names, it would make this easy:

Code: Select all

repeat with i = 1 to 95
set the script of img "Provence" & i to "on mouseEnter...
You could refer to them by just their number:

Code: Select all

repeat with i = 1 to 95
set the script of img i to "on mouseEnter...
Yes that should do it, their numbering is in their layer e.g. img 1 is below img 2 etc.

I'm attaching a sample LC tool that I made to change normal text into LC strings. You probably use it to convert the mouseEnter etc into a string for that set the script.

I'm probably not making myself too clear :)
Write back with questions.

Oh, the attached tool is an external stack but it could all be written into a button that you delete when you are done.

Simon
Attachments
infamous_quotes.zip
LC 6.0
(838 Bytes) Downloaded 381 times
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply