Tobias Herzke
2006-Apr-10 21:35 UTC
[fxruby-users] Display an arrow, or transparent image colors
I want to display an arrow in the user interface between 2 GUI Components.
I think I know how I can do it, but I ran into a problem displaying
pixel images with transparent background. I describe this image display
problem here and ask for advice. but if someone knows of a different and
easier way to display arrows, please tell me.
Example Problem: I want a FXHorizontalFrame to contain, from left to
right, (1) a FXTextField, (2) the arrow, pointing from to the right, (3)
a FXDial.
I figured I can display the Arrow using a .png image containing a red
arrow on transparent background, loading that image using FXPNGIcon, and
display it in FXImageFrame. Example code:
require "fox14"
include Fox
app = FXApp.new
window = FXMainWindow.new(app, "Demo")
window.place(PLACEMENT_SCREEN)
hframe = FXHorizontalFrame.new(window)
file_display = FXTextField.new(hframe, 40, nil, 0, LAYOUT_CENTER_Y)
file_display.text = "SoundFile.wav"
arrow_image = File.open("ArrowShortRightRedT.png", "rb")
{|f|
FXPNGIcon.new(app, f.read)
}
# arrow_image.options = IMAGE_ALPHACOLOR | IMAGE_ALPHAGUESS
arrow = FXImageFrame.new(hframe, arrow_image, FRAME_NONE)
dial = FXDial.new(hframe, nil, 0,
DIAL_VERTICAL | DIAL_HAS_NOTCH | LAYOUT_FILL_Y)
app.create
window.show
app.mainloop
Using this program, my red arrow will display on black background. I had
expected the background to be of the same gray as used everywhere else
in the fox window. Anyone know how to achieve this? I''ve tried various
combinations of setting the options as in the commented-out line above,
and using images without transparent background in .png and .gif format.
The result was that the background color that should have been
transparent was actually displayed.
I know I can use a .png image of my red arrow with grey background
already present in the bitmap. But this is calling for trouble: fox uses
different shades of gray on linux and windows, and I don''t know about
other platforms.
Please help!
Tobias
Lyle Johnson
2006-Apr-11 00:29 UTC
[fxruby-users] Display an arrow, or transparent image colors
On Apr 10, 2006, at 4:35 PM, Tobias Herzke wrote:> Using this program, my red arrow will display on black background. I > had > expected the background to be of the same gray as used everywhere else > in the fox window. Anyone know how to achieve this? I''ve tried various > combinations of setting the options as in the commented-out line above, > and using images without transparent background in .png and .gif > format. > The result was that the background color that should have been > transparent was actually displayed.The problem, I think, is that the FXImageFrame widget isn''t aware of icon transparency. That is, it assumes that whatever you''re passing it is a "plain old" image, without a transparency mask. I would recommend replacing the image frame with a label, and assigning your icon to that label, e.g. arrow_image = File.open("ArrowShortRightRedT.png", "rb") {|f| FXPNGIcon.new(app, f.read, 0, IMAGE_ALPHAGUESS) } arrow = FXLabel.new(hframe, "", arrow_image) Hope this helps, Lyle