mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 19:19:19 +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;
|
c_bit, m_bit: byte;
|
||||||
begin
|
begin
|
||||||
c_bit := Ord(0.222 * c.red + 0.707 * c.green + 0.071 * c.blue >= $8000);
|
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);
|
AImgBits^ := AImgBits^ or (c_bit shl offset);
|
||||||
AMskBits^ := AMskBits^ or (m_bit shl offset);
|
AMskBits^ := AMskBits^ or (m_bit shl offset);
|
||||||
@ -10037,3 +10037,4 @@ end;
|
|||||||
{$C-}
|
{$C-}
|
||||||
{$EndIf}
|
{$EndIf}
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,8 +96,7 @@ begin
|
|||||||
// fill pixbuf from pixmap
|
// fill pixbuf from pixmap
|
||||||
gdk_pixbuf_get_from_drawable(pixbuf, pixmap, nil, 0, 0, 0, 0, -1, -1);
|
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, 0);
|
||||||
masked_pixbuf := GdkPixbufAddBitmapMask(pixbuf, bitmap, 1);
|
|
||||||
if masked_pixbuf <> nil then
|
if masked_pixbuf <> nil then
|
||||||
begin
|
begin
|
||||||
// masked_pixuf is a new pixbuf created from pixbuf with applying mask
|
// masked_pixuf is a new pixbuf created from pixbuf with applying mask
|
||||||
|
@ -362,33 +362,15 @@ function TQtWidgetSet.CreateCursor(ACursorInfo: PIconInfo): hCursor;
|
|||||||
var
|
var
|
||||||
Image: TQtImage;
|
Image: TQtImage;
|
||||||
Pixmap: QPixmapH;
|
Pixmap: QPixmapH;
|
||||||
ConvertedImage: QImageH;
|
|
||||||
i, j: integer;
|
|
||||||
AColor: qrgb;
|
|
||||||
begin
|
begin
|
||||||
Result := 0;
|
Result := 0;
|
||||||
if IsValidGDIObject(ACursorInfo^.hbmColor) then
|
if IsValidGDIObject(ACursorInfo^.hbmColor) then
|
||||||
begin
|
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);
|
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();
|
Pixmap := QPixmap_create();
|
||||||
QPixmap_fromImage(Pixmap, ConvertedImage);
|
QPixmap_fromImage(Pixmap, Image.Handle);
|
||||||
Result := hCursor(QCursor_create(Pixmap, ACursorInfo^.xHotspot, ACursorInfo^.yHotspot));
|
Result := hCursor(QCursor_create(Pixmap, ACursorInfo^.xHotspot, ACursorInfo^.yHotspot));
|
||||||
QPixmap_destroy(Pixmap);
|
QPixmap_destroy(Pixmap);
|
||||||
QImage_destroy(ConvertedImage);
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2830,3 +2812,4 @@ end;
|
|||||||
//##apiwiz##eps## // Do not remove, no wizard declaration after this line
|
//##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.
|
Creates a cursor by color and mask bitmaps and other indo.
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
Function TWin32WidgetSet.CreateCursor(ACursorInfo: PIconInfo): hCursor;
|
Function TWin32WidgetSet.CreateCursor(ACursorInfo: PIconInfo): hCursor;
|
||||||
|
var
|
||||||
|
ConvertedInfo: TIconInfo;
|
||||||
|
AData: PByte;
|
||||||
|
ADataSize: PtrUInt;
|
||||||
|
ABitmap : Windows.TBitmap;
|
||||||
|
ABitmapInfo: TBitmapInfo;
|
||||||
|
DC: HDC;
|
||||||
|
i: integer;
|
||||||
begin
|
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;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -3429,3 +3474,4 @@ end;
|
|||||||
{$C-}
|
{$C-}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3621,44 +3621,12 @@ begin
|
|||||||
for Row:=Img.Height-1 downto 0 do
|
for Row:=Img.Height-1 downto 0 do
|
||||||
begin
|
begin
|
||||||
ReadScanLine(Row,Stream); // Scanline in LineBuf with Size ReadSize.
|
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
|
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
|
if ((LineBuf[Column div 8] shr (7-(Column and 7)) ) and 1) <> 0 then
|
||||||
begin
|
NewColor.alpha := alphaTransparent else
|
||||||
// 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;
|
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;
|
img.colors[Column,Row] := NewColor;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user