Transparency issues.

Posted by Alca on Fri 05 Feb 2010 03:14 PM — 6 posts, 23,953 views.

#0
Since I updated from v4.40 to v4.30, some of my plugins don't function as they should anymore.
More specifically, the WindowDrawImage() function is what keeps them from showing what I want them to show.

I use mode 3 (transparent copy) to make 'overlays'. I could -probably- do this with WindowDrawImageAlpha(), but my question is: why doesn't mode 3 work like it used to?

In case I coded something wrong, here's one of the plugins:


winid = world.GetPluginID
path = world.GetPluginInfo(winid, 20)

background_colour =  world.ColourNameToRGB("black")
start_colour =  world.ColourNameToRGB("darkslateblue")
end_colour = world.ColourNameToRGB("turquoise")

# Window size

win_height = 586
win_width = 37

# Initial Gauge Height (when XP = 0)

gauge_height = 535

# Gauge Length = 535 - 50 = 485

def OnPluginBroadcast(msg, id, name, text):

    if id == "65b2f9550e9da2d141111e74":
        if msg == 300:
            ComputeGaugeHeight(text)

    return 0

def ComputeGaugeHeight(text):

    global gauge_height

    text_list = text.split('!')

    XP_current = float(text_list[6])
    XP_needed = float(text_list[7])
    XP_ratio = XP_current/XP_needed

    gauge_height = int(535 - (485*XP_ratio))

    DrawGauge()


def OnPluginInstall():

    world.WindowCreate(winid, 0, 0, win_width, win_height, 6, 4, background_colour)

    world.WindowLoadImage(winid, "xp_bar", path+"xp_bar.png")

    DrawGauge()

    world.WindowShow(winid, True)

def DrawGauge():

    world.WindowRectOp(winid, 2, 0, 0, win_width, win_height, background_colour, background_colour)

    world.WindowGradient(winid, 13, gauge_height, 18, win_height, start_colour, end_colour, 1)
    world.WindowGradient(winid, 18, gauge_height, 24, win_height, end_colour, start_colour, 1)

    world.WindowDrawImage(winid, "xp_bar", 0, 0, win_width, win_height, 3, 0, 0, 0, 0)

    world.WindowShow(winid, True)
Amended on Fri 05 Feb 2010 03:15 PM by Alca
Australia Forum Administrator #1
I think I would need to see your image file (xp_bar.png) - the spec says that the pixel at 0, 0 is the transparent pixel. Are you sure that that pixel is the one which is, elsewhere, the one you should be seeing through?

Meanwhile, using transparency (alpha channel) in the image lets you have more control, and you could fade the transparency out rather than having it on or off.
Australia Forum Administrator #2
Alca said:

Since I updated from v4.40 to v4.30, some of my plugins don't function as they should anymore.


Is this a typo? Sounds like a downgrade, if you moved from 4.40 to 4.30.

Try 4.47 available from:

http://www.gammon.com.au/forum/?id=10044
#3
Link to the png: http://i254.photobucket.com/albums/hh92/Ferusian/xp_bar.png

It is indeed a typo. I'm currently at version 4.43

The plugin worked before, so I always thought my offset and such was right. I've tried and fooled around with it, but it didn't work. Using a bigger black area (as to be sure I got the pixel I need) doesn't work, nor does changing the offset by one pixel. I tried simple pngs to test if it was just a wrong sort of 'black', but that didn't fix it either.

Using the alpha channel is easier and better, and I'll use it from now on, but I'm still wondering why my previous solution doesn't work anymore.
Australia Forum Administrator #4
After extensive investigation it seems that the problem is the choice of black as the transparency colour. Basically the transparency works by turning your original image into a mask, where black is transparent and white not (or vice-versa). However by using black as the transparent colour it throws all that out.

I'll amend the documentation to recommend not using black or white as the transparent colour.
#5
Thanks for clearing that up for me!


Also, I'm really, really, really relieved I didn't make an incredibly obvious mistake again.