gtk: fix compilation and some crashes after recent alpha support

git-svn-id: trunk@19506 -
This commit is contained in:
paul 2009-04-19 10:52:12 +00:00
parent 1e362205e8
commit a6bc789bed
3 changed files with 50 additions and 8 deletions

View File

@ -497,6 +497,24 @@ begin
gdkpixbuf.gdk_pixbuf_render_pixmap_and_mask(pixbuf, @pixmap_return, @mask_return, alpha_threshold);
end;
function gdk_pixbuf_new_subpixbuf(src_pixbuf: PGdkPixbuf; src_x: longint; src_y: longint; width: longint; height: longint): PGdkPixbuf;
var
tmp: PGdkPixbuf;
buf: PChar;
rowstride: Integer;
begin
buf := gdk_pixbuf_get_pixels(src_pixbuf);
rowstride := gdk_pixbuf_get_rowstride(src_pixbuf);
inc(buf, src_y * rowstride + src_x * gdk_pixbuf_get_n_channels(src_pixbuf));
tmp := gdk_pixbuf_new_from_data(buf, gdk_pixbuf_get_colorspace(src_pixbuf),
gdk_pixbuf_get_has_alpha(src_pixbuf), gdk_pixbuf_get_bits_per_sample(src_pixbuf),
width, height, rowstride, nil, nil);
Result := gdk_pixbuf_copy(tmp);
gdk_pixbuf_unref(tmp);
end;
function gdk_drawable_get_depth(Drawable : PGDKDrawable) : gint;
begin
gdk_window_get_geometry(Drawable, nil, nil, nil, nil, @result);

View File

@ -93,6 +93,8 @@ function gdk_pixmap_colormap_create_from_xpm (window: PGdkWindow;
procedure gdk_pixbuf_render_pixmap_and_mask(pixbuf: PGdkPixbuf;
var pixmap_return: PGdkPixmap; var mask_return: PGdkBitmap;
alpha_threshold: gint);
function gdk_pixbuf_new_subpixbuf(src_pixbuf: PGdkPixbuf; src_x: longint;
src_y: longint; width: longint; height: longint): PGdkPixbuf;
//Wrapper around window functions like gtk2 -->
function gdk_drawable_get_depth(Drawable: PGDKDrawable): gint;

View File

@ -1917,6 +1917,7 @@ function TGTKWidgetSet.CreateIconIndirect(IconInfo: PIconInfo): HICON;
var
FG, BG: TGDKColor;
Img, Msk: PGdkPixmap;
Pixbuf: PGdkPixbuf;
srcbitmap, mskbitmap: PGdkBitmap;
W, H, bitlen: integer;
ImgBits, MskBits: array of byte;
@ -1924,21 +1925,40 @@ begin
Result := 0;
if not IsValidGDIObject(IconInfo^.hbmColor) then Exit;
Img := PGDIObject(IconInfo^.hbmColor)^.GDIBitmapObject;
gdk_drawable_get_size(Img, @W, @H);
if PGDIObject(IconInfo^.hbmColor)^.GDIBitmapType = gbPixbuf then
begin
Pixbuf := PGDIObject(IconInfo^.hbmColor)^.GDIPixbufObject;
if IconInfo^.fIcon then
begin
// Creating PixBuf from pixmap and mask
Result := HICON(PtrUInt(gdk_pixbuf_copy(pixbuf)));
Exit;
end;
W := gdk_pixbuf_get_width(Pixbuf);
H := gdk_pixbuf_get_height(Pixbuf);
Img := gdk_pixmap_new(nil, W, H, 24);
Msk := gdk_pixmap_new(nil, W, H, 1);
gdk_pixbuf_render_pixmap_and_mask(Pixbuf, Img, Msk, $80);
end
else
begin
Img := PGDIObject(IconInfo^.hbmColor)^.GDIBitmapObject;
gdk_drawable_get_size(Img, @W, @H);
Msk := CreateGdkMaskBitmap(IconInfo^.hbmColor, IconInfo^.hbmMask);
//DbgDumpPixmap(Img, 'Image');
//DbgDumpPixmap(Msk, 'Mask');
try
Msk := CreateGdkMaskBitmap(IconInfo^.hbmColor, IconInfo^.hbmMask);
//DbgDumpPixmap(Img, 'Image');
//DbgDumpPixmap(Msk, 'Mask');
if IconInfo^.fIcon then
begin
// Creating PixBuf from pixmap and mask
Result := HICON(PtrUInt(CreatePixbufFromImageAndMask(Img, 0, 0, W, H, nil, Msk)));
if Msk <> nil then
gdk_bitmap_unref(Msk);
Exit;
end;
end;
try
// Create cursor
bitlen := (W * H) shr 3;
@ -1972,6 +1992,8 @@ begin
finally
if msk <> nil
then gdk_bitmap_unref(msk);
if Img <> PGDIObject(IconInfo^.hbmColor)^.GDIBitmapObject
then gdk_pixmap_unref(Img);
end;
end;