1. Win 32Lib0.42: how use XPM graphics?
David,
I assume this is another really silly question, but: how do you use XPM
graphics in a program?
The data structure of the xpm constant looks reasonable & understandable,
but I can't get an xpm to display. I've tried reading the documentation &
examples, particularly "generic". Then I tried creating a bitmap control
with xpmToBmp(my_xpm) as last parameter; then a bitmap control with "0" as
last parameter & then setBitmap(control,xpmToBmp(my_xpm)); & then I tried
making a bitmap control with "createDIB(xpmToBmp(my_xpm))" as last
parameter, but only the last put anything at all on the screen & it wasn't
right.
Dan Moyer
2. Re: Win 32Lib0.42: how use XPM graphics?
Dan Moyer wondered:
> I assume this is another really silly question, but:
> how do you use XPM graphics in a program?
Typically, you convert the XPM to a EuBmp, and then a DIB.
Here's a demo that works with the latest version of Win32Lib. If you set
Trans=True, it uses transBlt instead of copyBlt. If you knew that the
bitmaps would never overlap, you could set the background color to
BrightWhite and have the same effect - only the code would run faster.
I'm not pleased with the all the different names of graphics: bitmap,
pixmap, euBitmap, dib, xpm - it gets downright confusing, even for me. I
hope to clean it up some time.
Another point that I'm not sure the documentation makes clear is that
because bitmaps have no 'transparency' concept, when you convert an XPM into
a bitmap/dib, it *loses* it's transparency. The value passed in
setTransparentColor tells Win32Lib what color to convert the transparent
color into. In reverse, when using transBlt the value in setTransparentColor
tells Win32Lib to treat as if it were transparent.
Hope this helps!
-- David Cuny
include win32lib.ew
include tbar_xpm.e
constant Trans = False
constant
Win = create( Window, "Demo", 0, 0, 0, 300, 300, 0 ),
PBtn = create( PictureButton, "", Win, 2, 2, 40, 40, 0 )
-- set the transparent color of the xpm to the button color
setTransparentColor( getSysColor( COLOR_BTNFACE ) )
-- create a dib from the XPM
-- the 'transparent' color will be set to the button color
constant DIB1 = createDIB( xpmToEuBmp( source_xpm ) )
-- attach an XPM to the picture button
setBitmap( PBtn, DIB1 )
-- set transparent color to bright pink (default)
setTransparentColor( {255,0,255} )
-- create a dib from an XPM
-- the 'transparent' color will be pink
constant DIB2 = createDIB( xpmToEuBmp( help_xpm ) )
procedure drawXpm()
-- when the button is pressed, draw the DIB2 at
-- a random location.
integer x, y
sequence extent
-- get extent of window
extent = getExtent( Win )
-- pick random location
x = rand( extent[1] )
y = rand( extent[2] )
-- draw the bitmap randomly
if Trans then
-- treat transparent color as transparent
transBlt( Win, x, y, DIB2 )
else
-- draw transparent color
copyBlt( Win, x, y, DIB2 )
end if
end procedure
onClick[ PBtn ] = routine_id( "drawXpm" )
WinMain( Win, Normal )
3. Re: Win 32Lib0.42: how use XPM graphics?
Thanks David, that does help; & I really like the html with your new
version!
Dan
On Wed, 13 Oct 1999 15:48:35 -0700, Cuny, David <David.Cuny at DSS.CA.GOV>
wrote:
>Dan Moyer wondered:
>
>> I assume this is another really silly question, but:
>> how do you use XPM graphics in a program?
>
>Typically, you convert the XPM to a EuBmp, and then a DIB.
>
>Here's a demo that works with the latest version of Win32Lib. If you set
>Trans=True, it uses transBlt instead of copyBlt. If you knew that the
>bitmaps would never overlap, you could set the background color to
>BrightWhite and have the same effect - only the code would run faster.
>
>I'm not pleased with the all the different names of graphics: bitmap,
>pixmap, euBitmap, dib, xpm - it gets downright confusing, even for me. I
>hope to clean it up some time.
>
>Another point that I'm not sure the documentation makes clear is that
>because bitmaps have no 'transparency' concept, when you convert an XPM
into
>a bitmap/dib, it *loses* it's transparency. The value passed in
>setTransparentColor tells Win32Lib what color to convert the transparent
>color into. In reverse, when using transBlt the value in
setTransparentColor
>tells Win32Lib to treat as if it were transparent.
>
>Hope this helps!
>
>-- David Cuny
>