lazarus/lcl/interfaces/win32/win32debug.pp
marc 04b4e27b62 * Implemented basic alpha support
* Implemented LCL side of imagelist
* restructured rawimage to more OO

Merged revisions 11289-11617 via svnmerge from 
http://svn.freepascal.org/svn/lazarus/branches/marc-lcl

........
  r11289 | marc | 2007-06-06 22:50:05 +0200 (Wed, 06 Jun 2007) | 1 line
  
  private branch for bitmap rework
........
  r11290 | marc | 2007-06-06 23:30:09 +0200 (Wed, 06 Jun 2007) | 2 lines
  
  * Initial linux and win32 implementation
........
  r11291 | paul | 2007-06-07 03:20:11 +0200 (Thu, 07 Jun 2007) | 3 lines
  
  - fix compilation with fpc 2.3.1
  - remove unneded code for converting cursor mask
  - enabled loading of standard windows status icons instead of LCL
........
  r11292 | paul | 2007-06-07 11:03:27 +0200 (Thu, 07 Jun 2007) | 1 line
  
  - some bugs with mask and alpha
........
  r11299 | marc | 2007-06-08 00:59:26 +0200 (Fri, 08 Jun 2007) | 2 lines
  
  * force alpha channel when PNG has alpha
........
  r11302 | paul | 2007-06-09 04:45:12 +0200 (Sat, 09 Jun 2007) | 1 line
  
  - fix black rectangles instead of manu item images
........
  r11303 | paul | 2007-06-09 04:46:14 +0200 (Sat, 09 Jun 2007) | 1 line
  
  formatting
........
  r11309 | marc | 2007-06-11 02:25:07 +0200 (Mon, 11 Jun 2007) | 3 lines
  
  * Added alpha premultiply
  * Published Colorbox selection property
........
  r11310 | paul | 2007-06-11 19:10:18 +0200 (Mon, 11 Jun 2007) | 1 line
  
  misc
........
  r11312 | marc | 2007-06-12 01:44:03 +0200 (Tue, 12 Jun 2007) | 2 lines
  
  * start with carbon
........
  r11313 | paul | 2007-06-12 14:02:48 +0200 (Tue, 12 Jun 2007) | 1 line
  
  - BitBtn glyph transparency
........
  r11315 | paul | 2007-06-13 05:20:40 +0200 (Wed, 13 Jun 2007) | 1 line
  
  - problems with internal bitmap saving/loading (is was 24bpp when 32bpp needed)
........
  r11319 | paul | 2007-06-14 06:32:04 +0200 (Thu, 14 Jun 2007) | 1 line
  
  - More LCL way of painting images through ThemeServices
........
  r11320 | paul | 2007-06-14 06:32:56 +0200 (Thu, 14 Jun 2007) | 1 line
  
  - ability to override bitbtn glyph to nothing
........
  r11321 | paul | 2007-06-14 06:34:49 +0200 (Thu, 14 Jun 2007) | 1 line
  
  painting headercontrol images through ThemeServices
........
  r11325 | paul | 2007-06-17 10:14:27 +0200 (Sun, 17 Jun 2007) | 1 line
  
  fixing painting of 32bpp bitmaps with no Alpha
........
  r11326 | paul | 2007-06-17 10:16:00 +0200 (Sun, 17 Jun 2007) | 1 line
  
  missed file
........
  r11337 | paul | 2007-06-20 03:44:47 +0200 (Wed, 20 Jun 2007) | 3 lines
  
  - revert previous commit
  - create 24bpp bitmaps by default
........
  r11342 | marc | 2007-06-21 01:47:30 +0200 (Thu, 21 Jun 2007) | 3 lines
  
  * Added Alpha support on Carbon
  * Simplified win32 rawimage_fromdevice
........
  r11343 | paul | 2007-06-21 04:36:28 +0200 (Thu, 21 Jun 2007) | 1 line
  
  - adopt gtk2 code
........
  r11344 | paul | 2007-06-21 04:41:41 +0200 (Thu, 21 Jun 2007) | 1 line
  
  make gtk2 work
........
  r11353 | paul | 2007-06-22 10:12:19 +0200 (Fri, 22 Jun 2007) | 1 line
  
  - default WS imagelist implementation
........
  r11358 | marc | 2007-06-23 13:29:06 +0200 (Sat, 23 Jun 2007) | 2 lines
  
  * Implemented MaskBlit
........
  r11359 | paul | 2007-06-23 20:02:52 +0200 (Sat, 23 Jun 2007) | 1 line
  
  draw new imagelist bitmap on widget canvas
........
  r11371 | marc | 2007-06-25 23:50:13 +0200 (Mon, 25 Jun 2007) | 2 lines
  
  * Rawimage rework
........
  r11372 | marc | 2007-06-25 23:51:00 +0200 (Mon, 25 Jun 2007) | 2 lines
  
  + Added header
........
  r11373 | marc | 2007-06-26 00:05:55 +0200 (Tue, 26 Jun 2007) | 2 lines
  
  * Swapped RGBA <-> ARGB defualt format since most widgetsets use ARGB
........
  r11374 | marc | 2007-06-26 00:09:36 +0200 (Tue, 26 Jun 2007) | 2 lines
  
  * added
........
  r11462 | marc | 2007-07-12 00:16:02 +0200 (Thu, 12 Jul 2007) | 2 lines
  
  + added header
........
  r11463 | marc | 2007-07-12 00:18:49 +0200 (Thu, 12 Jul 2007) | 2 lines
  
  * Added alpha/masked strechblt support
........
  r11464 | marc | 2007-07-12 00:21:27 +0200 (Thu, 12 Jul 2007) | 2 lines
  
  * create DIBSection instead of DIBitmap
........
  r11502 | marc | 2007-07-14 00:23:42 +0200 (Sat, 14 Jul 2007) | 2 lines
  
  * Fixed transparentcolor after loading bitmap
........
  r11505 | marc | 2007-07-14 15:10:56 +0200 (Sat, 14 Jul 2007) | 2 lines
  
  - Removed ARGB dataconversion, internal format is by default the same now
........
  r11531 | marc | 2007-07-17 01:23:34 +0200 (Tue, 17 Jul 2007) | 2 lines
  
  * changed TRawImage into object
........
  r11533 | paul | 2007-07-17 05:10:31 +0200 (Tue, 17 Jul 2007) | 3 lines
  
  - change several occurrence of FillChar(..TRawImageDescription..) with call to Init
  - change imagelist defines to use old imagelist (new is crashes ide)
  - change TWin32ThemeServices to use old imagelist
........
  r11534 | paul | 2007-07-17 05:19:02 +0200 (Tue, 17 Jul 2007) | 3 lines
  
  - change several occurrence of FillChar(..TRawImageDescription..) with call to Init in Qt widgetset
  - change TRawImageDescription.IsEqual and TRawImage.IsEqual
........
  r11535 | paul | 2007-07-17 05:23:53 +0200 (Tue, 17 Jul 2007) | 1 line
  
  - change several occurrence of FillChar(..TRawImageDescription..) with call to Init in wince widgetset
........
  r11554 | marc | 2007-07-18 00:10:11 +0200 (Wed, 18 Jul 2007) | 2 lines
  
  * fixed compilation on 2.0.4
........
  r11555 | marc | 2007-07-18 00:10:44 +0200 (Wed, 18 Jul 2007) | 2 lines
  
  * fixed compilation
........
  r11556 | marc | 2007-07-18 00:11:43 +0200 (Wed, 18 Jul 2007) | 2 lines
  
  * fixed fillchar on TRawImage object
........
  r11572 | marc | 2007-07-19 01:41:35 +0200 (Thu, 19 Jul 2007) | 2 lines
  
  * fixed crash when object has vmt
........
  r11573 | marc | 2007-07-19 01:42:14 +0200 (Thu, 19 Jul 2007) | 2 lines
  
  * Made TRawimage compatible with record again
........
  r11580 | marc | 2007-07-20 01:33:20 +0200 (Fri, 20 Jul 2007) | 2 lines
  
  * enabled newimagelist
........
  r11581 | marc | 2007-07-20 01:33:48 +0200 (Fri, 20 Jul 2007) | 2 lines
  
  * fixed font
........

git-svn-id: trunk@11861 -
2007-08-25 01:49:40 +00:00

215 lines
6.1 KiB
ObjectPascal

{ $Id$ }
{
------------------------------------
win32debug.pp - graphic dump utils
------------------------------------
@created(Fri Jun 1th WET 2007)
@lastmod($Date$)
@author(Marc Weustink <marc@@lazarus.dommelstein.net>)
This unit contains utility functions to show the contents of graphics
*****************************************************************************
* *
* This file is part of the Lazarus Component Library (LCL) *
* *
* See the file COPYING.modifiedLGPL, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
}
unit Win32Debug;
{$mode objfpc}{$H+}
interface
uses
windows, ctypes, sysutils, win32Extra;
procedure DbgDumpBitmap(ABitmap: HBITMAP; ATitle: String = ''; AWidth: Integer = -1; AHeight: Integer = -1);
procedure DbgDumpDC(ADC: HDC; ATitle: String = ''; AWidth: Integer = -1; AHeight: Integer = -1);
implementation
type
PDbgDumpInfo = ^TDbgDumpInfo;
TDbgDumpInfo = record
Width, Height: Integer;
OrgWidth, OrgHeight: Integer;
Bitmap: HBITMAP;
ColorIdx: Byte;
UseAlphaBlend: Boolean;
end;
function DbgWindowProc(Wnd: HWnd; Msg: UINT; WParam: WPAram; LParam: LPARAM): LRESULT; stdcall;
function GetInfo: Pointer;
begin
// grrr.... this function isn't mapped to GetWindowLong
{$ifdef CPU64}
Result := Pointer(GetWindowLongPtr(wnd, GWL_USERDATA));
{$else}
Result := Pointer(GetWindowLong(wnd, GWL_USERDATA));
{$endif}
end;
const
COLORS: array[0..7] of COLORREF = (
$00000000,
$000000FF,
$0000FF00,
$0000FFFF,
$00FF0000,
$00FF00FF,
$00FFFF00,
$00FFFFFF
);
var
Info: PDbgDumpInfo;
PS: TPaintStruct;
DC: HDC;
OldBmp: HBITMAP;
Blend: TBlendFunction;
br: HBRUSH;
begin
Result := 0;
case Msg of
WM_PAINT: begin
Info := GetInfo;
BeginPaint(Wnd, PS);
br := CreateSolidBrush(COLORS[Info^.ColorIdx and $7]);
FillRect(PS.hDC, PS.rcPaint, br);
DeleteObject(br);
DC := CreateCompatibleDC(PS.hdc);
OldBmp := SelectObject(DC, Info^.Bitmap);
if Info^.UseAlphaBlend
then begin
Blend.BlendOp := AC_SRC_OVER;
Blend.BlendFlags := 0;
Blend.SourceConstantAlpha := 255;
Blend.AlphaFormat := AC_SRC_ALPHA;
Win32Extra.AlphaBlend(PS.hDC, 0, 0, Info^.Width, Info^.Height, DC, 0,0, Info^.OrgWidth, Info^.OrgHeight, Blend);
end
else begin
BitBlt(PS.hDC, 0, 0, Info^.Width, Info^.Height, DC, 0,0, SRCCOPY);
end;
SelectObject(DC, OldBmp);
DeleteDC(DC);
EndPaint(Wnd, PS);
end;
WM_DESTROY: begin
Info := GetInfo;
DeleteObject(Info^.Bitmap);
Dispose(Info);
end;
WM_LBUTTONUP: begin
Info := GetInfo;
Info^.ColorIdx := (Info^.ColorIdx + 1) and $7;
InvalidateRect(Wnd, nil, False);
end;
else
Result := DefWindowProc(wnd, Msg, WParam, LParam);
end;
end;
var
MDbgClassCreated: Boolean = False;
procedure DbgCreateClass;
var
wc: TWndClass;
begin
if MDbgClassCreated then Exit;
FillByte(wc, SizeOf(wc), 0);
wc.style := CS_HREDRAW or CS_VREDRAW;
wc.lpfnWndProc := @DbgWindowProc;
wc.hInstance := hinstance;
wc.hbrBackground := GetStockObject(BLACK_BRUSH);
wc.lpszClassName := 'LazDbgWindow';
RegisterClass(wc);
MDbgClassCreated := True;
end;
procedure DbgCreateWindow(AInfo: PDbgDumpInfo; const ATitle: String);
var
window: HWND;
w, h: Integer;
begin
DbgCreateClass;
if AInfo^.Width < 50 then W := 50 else w := AInfo^.Width;
if AInfo^.Height < 25 then H := 25 else H := AInfo^.Height;
window := CreateWindowEx(WS_EX_TOOLWINDOW, 'LazDbgWindow', PChar(ATitle), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, W + 8, H+ 25, 0, 0, HINSTANCE, nil);
{$ifdef CPU64}
SetWindowLongPtr(window, GWL_USERDATA, PtrInt(AInfo));
{$else}
SetWindowLong(window, GWL_USERDATA, PtrInt(AInfo));
{$endif}
ShowWindow(window, SW_SHOWNOACTIVATE);
end;
procedure InternalDumpBitmap(ABitmap: HBITMAP; ADesc, ATitle: String; AWidth: Integer; AHeight: Integer);
var
Info: PDbgDumpInfo;
h,w,d: Integer;
WinBmp: Windows.TBitmap;
begin
New(Info);
if (ABitmap = 0)
or (Windows.GetObject(ABitmap, SizeOf(WinBmp), @WinBmp) = 0)
then begin
w := 0; h:= 0; d := 0;
Info^.Bitmap := 0;
if AWidth = -1 then AWidth := 0;
if AHeight = -1 then AHeight := 0;
end
else begin
w := WinBmp.bmWidth;
h := WinBmp.bmHeight;
d := WinBmp.bmBitsPixel;
if AWidth = -1 then AWidth := W;
if AHeight = -1 then AHeight := H;
Info^.Bitmap := CopyImage(ABitmap, IMAGE_BITMAP, AWidth, AHeight, 0);
end;
Info^.Width := AWidth;
Info^.Height := AHeight;
Info^.OrgWidth := w;
Info^.OrgHeight := h;
Info^.UseAlphaBlend := d > 24;
ATitle := ATitle + Format(' (%s W:%d H:%d D:%d)', [ADesc, w, h, d]);
DbgCreateWindow(Info, ATitle);
end;
procedure DbgDumpBitmap(ABitmap: HBITMAP; ATitle: String = ''; AWidth: Integer = -1; AHeight: Integer = -1);
begin
InternalDumpBitmap(ABitmap, Format('Bitmap:$%x', [ABitmap]), ATitle, AWidth, AHeight);
end;
procedure DbgDumpDC(ADC: HDC; ATitle: String; AWidth, AHeight: Integer);
var
bmp: HBITMAP;
begin
bmp := CreateBitmap(1,1,1,1,nil);
// select dummy to get selected bitmap
bmp := SelectObject(ADC, bmp);
InternalDumpBitmap(bmp, Format('DC:$%x', [ADC]), ATitle, AWidth, AHeight);
// restore bitmap and delete dummy
DeleteObject(SelectObject(ADC, bmp));
end;
end.