mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-11 16:56:01 +02:00
- fixed error in cursor reading previously introduced by me
- fixed cursor creating code in widgetsets git-svn-id: trunk@10779 -
This commit is contained in:
parent
eb25220d96
commit
aec06c66dd
@ -1273,7 +1273,7 @@ function TGtkWidgetSet.CreateCursor(ACursorInfo: PIconInfo): hCursor;
|
||||
c_bit, m_bit: byte;
|
||||
begin
|
||||
c_bit := Ord(0.222 * c.red + 0.707 * c.green + 0.071 * c.blue >= $8000);
|
||||
m_bit := ord(MaskPixel = 0);
|
||||
m_bit := ord(MaskPixel = 1);
|
||||
|
||||
AImgBits^ := AImgBits^ or (c_bit shl offset);
|
||||
AMskBits^ := AMskBits^ or (m_bit shl offset);
|
||||
@ -10037,3 +10037,4 @@ end;
|
||||
{$C-}
|
||||
{$EndIf}
|
||||
|
||||
|
||||
|
@ -96,8 +96,7 @@ begin
|
||||
// fill pixbuf from pixmap
|
||||
gdk_pixbuf_get_from_drawable(pixbuf, pixmap, nil, 0, 0, 0, 0, -1, -1);
|
||||
|
||||
// dont know why, but transparent color is black
|
||||
masked_pixbuf := GdkPixbufAddBitmapMask(pixbuf, bitmap, 1);
|
||||
masked_pixbuf := GdkPixbufAddBitmapMask(pixbuf, bitmap, 0);
|
||||
if masked_pixbuf <> nil then
|
||||
begin
|
||||
// masked_pixuf is a new pixbuf created from pixbuf with applying mask
|
||||
|
@ -362,33 +362,15 @@ function TQtWidgetSet.CreateCursor(ACursorInfo: PIconInfo): hCursor;
|
||||
var
|
||||
Image: TQtImage;
|
||||
Pixmap: QPixmapH;
|
||||
ConvertedImage: QImageH;
|
||||
i, j: integer;
|
||||
AColor: qrgb;
|
||||
begin
|
||||
Result := 0;
|
||||
if IsValidGDIObject(ACursorInfo^.hbmColor) then
|
||||
begin
|
||||
// we can get here only QImage. This is not so good as 2 QBitmaps and not
|
||||
// so good as QPixmap :(
|
||||
// So, we need process mask ourself
|
||||
Image := TQtImage(ACursorInfo^.hbmColor);
|
||||
ConvertedImage := QImage_create(Image.Handle);
|
||||
|
||||
// convert alpha channel
|
||||
for j := 0 to Image.Height - 1 do
|
||||
for i := 0 to Image.Width - 1 do
|
||||
begin
|
||||
AColor := QImage_pixel(ConvertedImage, j, i);
|
||||
AColor := ((not Byte(AColor shr 24)) shl 24) or (AColor and $00FFFFFF);
|
||||
QImage_setPixel(ConvertedImage, j, i, AColor);
|
||||
end;
|
||||
//
|
||||
Pixmap := QPixmap_create();
|
||||
QPixmap_fromImage(Pixmap, ConvertedImage);
|
||||
QPixmap_fromImage(Pixmap, Image.Handle);
|
||||
Result := hCursor(QCursor_create(Pixmap, ACursorInfo^.xHotspot, ACursorInfo^.yHotspot));
|
||||
QPixmap_destroy(Pixmap);
|
||||
QImage_destroy(ConvertedImage);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -2830,3 +2812,4 @@ end;
|
||||
//##apiwiz##eps## // Do not remove, no wizard declaration after this line
|
||||
|
||||
|
||||
|
||||
|
@ -730,8 +730,53 @@ End;
|
||||
Creates a cursor by color and mask bitmaps and other indo.
|
||||
------------------------------------------------------------------------------}
|
||||
Function TWin32WidgetSet.CreateCursor(ACursorInfo: PIconInfo): hCursor;
|
||||
var
|
||||
ConvertedInfo: TIconInfo;
|
||||
AData: PByte;
|
||||
ADataSize: PtrUInt;
|
||||
ABitmap : Windows.TBitmap;
|
||||
ABitmapInfo: TBitmapInfo;
|
||||
DC: HDC;
|
||||
i: integer;
|
||||
begin
|
||||
Result := Windows.CreateIconIndirect(ACursorInfo);
|
||||
Result := 0;
|
||||
// create a copy of info to prevent it changing
|
||||
Move(ACursorInfo^, ConvertedInfo, SizeOf(TIconInfo));
|
||||
if (GetObject(ACursorInfo^.hbmMask, SizeOf(ABitmap), @ABitmap) > 0) then
|
||||
begin
|
||||
// create new mask bitmap
|
||||
ConvertedInfo.hbmMask := Windows.CreateBitmap(ABitmap.bmWidth,
|
||||
ABitmap.bmHeight, 1, 1, nil);
|
||||
if ConvertedInfo.hbmMask <> 0 then
|
||||
begin
|
||||
FillChar(ABitmapInfo, SizeOf(ABitmapInfo), 0);
|
||||
ABitmapInfo.bmiHeader.biSize := SizeOf(ABitmapInfo.bmiHeader);
|
||||
ABitmapInfo.bmiHeader.biWidth := ABitmap.bmWidth;
|
||||
ABitmapInfo.bmiHeader.biHeight := -ABitmap.bmHeight;
|
||||
ABitmapInfo.bmiHeader.biPlanes := 1;
|
||||
ABitmapInfo.bmiHeader.biBitCount := ABitmap.bmBitsPixel;
|
||||
ABitmapInfo.bmiHeader.biCompression := BI_RGB;
|
||||
ADataSize := ((ABitmap.bmWidthBytes+3) and not 3) * ABitmap.bmHeight;
|
||||
GetMem(AData, ADataSize);
|
||||
DC := GetDC(0);
|
||||
// get mask data
|
||||
Windows.GetDIBits(DC, ACursorInfo^.hbmMask, 0, ABitmap.bmHeight, AData,
|
||||
Windows.BitmapInfo(ABitmapInfo), DIB_RGB_COLORS);
|
||||
// convert it
|
||||
for i := 0 to ADataSize - 1 do
|
||||
(AData + i)^ := (AData + i)^ xor $FF;
|
||||
// set to new mask bitmap
|
||||
Windows.SetDIBits(DC, ConvertedInfo.hbmMask, 0, ABitmap.bmHeight, AData,
|
||||
Windows.BitmapInfo(ABitmapInfo), DIB_RGB_COLORS);
|
||||
ReleaseDC(0, DC);
|
||||
// create cursor
|
||||
Result := Windows.CreateIconIndirect(@ConvertedInfo);
|
||||
// no more need new bitmap
|
||||
DeleteObject(ConvertedInfo.hbmMask);
|
||||
// and data
|
||||
FreeMem(AData);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -3429,3 +3474,4 @@ end;
|
||||
{$C-}
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
|
@ -3621,46 +3621,14 @@ begin
|
||||
for Row:=Img.Height-1 downto 0 do
|
||||
begin
|
||||
ReadScanLine(Row,Stream); // Scanline in LineBuf with Size ReadSize.
|
||||
{
|
||||
---------------- delete this comment, or apply ------------------------
|
||||
Paul Ishenin: My suggestion is to skip this color setting at all
|
||||
and replace it with direct writing of LineBuf into FMaskData. This will
|
||||
significantly speed up mask setting.
|
||||
|
||||
e.g. I test this code and it works fine:
|
||||
|
||||
if (Img is TLazIntfImage) and (TLazIntfImage(Img).FMaskData <> nil) then
|
||||
for i := 0 to ReadSize - 1 do
|
||||
TLazIntfImage(Img).FMaskData[(Row * ReadSize) + i] := LineBuf[i];
|
||||
|
||||
---------------- now it works so: --------------------------------------
|
||||
For cursors: we should not change main bitmap colors, but we should
|
||||
set mask. If we get 1 in LineBuf bit, then we need set 1 into Mask.
|
||||
If alpha part of color is alphaOpaque ($FFFF) then we set 1 into Mask
|
||||
else if alpha is alphaTransparent ($0000) then we set 0 into Mask
|
||||
so it is just "bit by bit copying" from LineBuf into FMaskData
|
||||
if we need speed up this copying then read my comment before
|
||||
}
|
||||
|
||||
for Column:=0 to Img.Width-1 do
|
||||
begin
|
||||
NewColor := img.colors[Column,Row];
|
||||
if ((LineBuf[Column div 8] shr (7-(Column and 7)) ) and 1) <> 0 then
|
||||
begin
|
||||
// I dont want change something in Icon loading code, so I add conditions
|
||||
// ClassType = TLazReaderCursor when need
|
||||
if ClassType = TLazReaderCursor then
|
||||
begin
|
||||
NewColor := img.colors[Column,Row];
|
||||
NewColor.alpha := alphaOpaque;
|
||||
end else
|
||||
NewColor := colTransparent;
|
||||
img.colors[Column,Row] := NewColor;
|
||||
end else
|
||||
if ClassType = TLazReaderCursor then
|
||||
begin
|
||||
NewColor := img.colors[Column,Row];
|
||||
NewColor.alpha := alphaTransparent;
|
||||
img.colors[Column,Row] := NewColor;
|
||||
end;
|
||||
NewColor.alpha := alphaTransparent else
|
||||
NewColor.alpha := alphaOpaque;
|
||||
img.colors[Column,Row] := NewColor;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
FreeBufs;
|
||||
|
Loading…
Reference in New Issue
Block a user