📄 winsubclass.pas
字号:
if (i=1) then
SetTextColor(btemp.canvas.handle,fsd.button.normalcolor2);
if (i=4) then
SetTextColor(btemp.canvas.handle,fsd.button.overcolor2);
if (i=2) then
SetTextColor(btemp.canvas.handle,fsd.button.downcolor2);
if not enabled then
SetTextColor(btemp.canvas.handle,COLORREF(clBtnShadow));
DrawCaption(btemp.canvas,r1,caption,enabled,false);
BitBlt(dc,rc.left ,rc.top,rc.right-rc.left,rc.bottom-rc.Top,
btemp.Canvas.Handle ,0 ,0 ,Srccopy);
selectobject(btemp.canvas.handle,cfont);
{$IFDEF buttontest}
skinaddlog(format('Button Draw %s %1x %1x',[caption,hwnd,dc]));
{$ENDIF}
end;
{procedure TSkinButton.DrawControl( dc:HDC; rc:TRect);
var i:integer;
r1:Trect;
acolor:Tcolor;
bfont,cfont:Hfont;
begin
if fsd.button=nil then exit;
if fsd.Button.map.empty then exit;
i:=1;
Focused := (GetFocus= hWnd);
enabled := (GetWindowLong(hWnd,GWL_STYLE) and WS_DISABLED)=0;
caption:=getformcaption(hwnd);
if (caption='') and (control<>nil) then
caption:=Taccontrol(control).caption;
if focused then i:=4;
if (scDown in state) then i:=2
else if (scMouseIn in state) then i:=4;
if not enabled then i:=3;
r1:=rc;
offsetrect(r1,-r1.left,-r1.top);
bg.width:=r1.right;
bg.height:=r1.bottom;
DrawSkin(r1,fsd.button,i,5,fsd.button.Trans);
// DrawSkinMap( dc:HDC; rc:TRect;aObject:TdataSkinObject;I,N:integer)
bfont:=sendmessage(hwnd,wm_getfont,0,0);
cfont:=selectobject(bg.canvas.handle,bfont);
SetTextColor(bg.canvas.handle,fsd.colors[csButtonText]);
if (i=1) then
SetTextColor(bg.canvas.handle,fsd.button.normalcolor2);
if (i=4) then
SetTextColor(bg.canvas.handle,fsd.button.overcolor2);
if (i=2) then
SetTextColor(bg.canvas.handle,fsd.button.downcolor2);
if not enabled then
SetTextColor(bg.canvas.handle,COLORREF(clBtnShadow));
DrawCaption(bg.canvas,r1,caption,enabled,false);
SetBkMode(bg.canvas.handle,OPAQUE);
DrawBuf( dc,rc);
selectobject(bg.canvas.handle,cfont);
end;}
{procedure TButtonGlyph.CalcButtonLayout(Canvas: TCanvas; const Client: TRect;
const Offset: TPoint; const Caption: string; Layout: TButtonLayout; Margin,
Spacing: Integer; var GlyphPos: TPoint; var TextBounds: TRect;
BiDiFlags: LongInt);}
procedure TSkinBitButton.DrawControl( dc:HDC; rc:TRect);
var btn:TBitBtn;
acolor:Tcolor;
i,n,j:integer;
spacing,margin:integer;
r1,TextBounds:Trect;
Layout: TButtonLayout;
TextPos: TPoint;
GlyphPos, ClientSize, GlyphSize, TextSize: TPoint;
TotalSize: TPoint;
DrawStyle: Longint;
cfont,bfont:Hfont;
begin
if fsd.button=nil then exit;
if fsd.Button.map.empty then exit;
DrawStyle:=DT_LEFT;
Focused := (GetFocus= hWnd);
enabled := (GetWindowLong(hWnd,GWL_STYLE) and WS_DISABLED)=0;
caption:=getformcaption(hwnd);
btn:=TBitBtn(control);
i:=1;
// if btn.default then i:=5;
if btn.focused then i:=4;
if (scDown in state) then i:=2
else if (scMouseIn in state) then i:=4;
if not btn.enabled then i:=3;
case i of
1: j:=1;
2: j:=3;
3: j:=2;
4: j:=1;
end;
r1:=rc;
offsetrect(r1,-r1.left,-r1.top);
btemp.width:=r1.right;
btemp.height:=r1.bottom;
bfont:=sendmessage(hwnd,wm_getfont,0,0);
cfont:=selectobject(btemp.canvas.handle,bfont);
// DrawSkin(r1,fsd.button,i,fsd.button.frame,fsd.button.Trans);
FillBG(btemp.canvas.handle,r1);
DrawSkinMap( btemp.canvas.handle,r1,fsd.button,I,fsd.button.frame);
{ calculate the item sizes }
ClientSize := Point(btn.ClientRect.Right - btn.ClientRect.Left,
btn.ClientRect.Bottom - btn.ClientRect.Top);
// ClientSize := Point(r1.right,r1.bottom);
if btn.Glyph <> nil then
GlyphSize := Point(btn.Glyph.Width div btn.NumGlyphs, btn.glyph.Height)
else GlyphSize := Point(0, 0);
if Length(Btn.Caption) > 0 then begin
TextBounds := r1;//Rect(0, 0, r1.right, 0);
DrawText(btemp.canvas.handle, PChar(btn.Caption),-1, TextBounds,DT_CALCRECT or dt_left);
TextSize := Point(TextBounds.Right - TextBounds.Left, TextBounds.Bottom -
TextBounds.Top);
end else begin
TextBounds := Rect(0, 0, 0, 0);
TextSize := Point(0,0);
end;
{ If the layout has the glyph on the right or the left, then both the
text and the glyph are centered vertically. If the glyph is on the top
or the bottom, then both the text and the glyph are centered horizontally.}
if btn.Layout in [blGlyphLeft, blGlyphRight] then begin
GlyphPos.Y := (ClientSize.y - GlyphSize.Y + 1) div 2;
TextPos.Y := (ClientSize.y - TextSize.Y + 1) div 2;
end else begin
GlyphPos.X := (ClientSize.x - GlyphSize.X + 1) div 2;
TextPos.X := (ClientSize.x - TextSize.X + 1) div 2;
end;
margin:=btn.margin;
spacing:=btn.spacing;
{ if there is no text or no bitmap, then Spacing is irrelevant }
if (TextSize.X = 0) or (GlyphSize.X = 0) then
Spacing := 0;
{ adjust Margin and Spacing }
if btn.Margin = -1 then begin
if Spacing = -1 then begin
TotalSize := Point(GlyphSize.X + TextSize.X, GlyphSize.Y + TextSize.Y);
if btn.Layout in [blGlyphLeft, blGlyphRight] then
Margin := (ClientSize.x - TotalSize.X) div 3
else
Margin := (ClientSize.y - TotalSize.Y) div 3;
Spacing := Margin;
end else begin
TotalSize := Point(GlyphSize.X+Spacing+TextSize.X, GlyphSize.Y+
Spacing + TextSize.Y);
if btn.Layout in [blGlyphLeft, blGlyphRight] then
Margin := (ClientSize.x - TotalSize.X ) div 2
else
Margin := (ClientSize.y - TotalSize.Y ) div 2;
end;
end else begin
if Spacing = -1 then begin
TotalSize := Point(ClientSize.x - (Margin + GlyphSize.X), ClientSize.y -
(Margin + GlyphSize.Y));
if btn.Layout in [blGlyphLeft, blGlyphRight] then
Spacing := (TotalSize.X - TextSize.X) div 2
else
Spacing := (TotalSize.Y - TextSize.Y) div 2;
end;
end;
case btn.Layout of
blGlyphLeft:
begin
GlyphPos.X := Margin;
TextPos.X := GlyphPos.X + GlyphSize.X + Spacing;
DrawStyle:=DT_left;
end;
blGlyphRight:
begin
GlyphPos.X := ClientSize.x - Margin - GlyphSize.X;
TextPos.X := GlyphPos.X - Spacing - TextSize.X;
DrawStyle:=DT_RIGHT;
end;
blGlyphTop:
begin
GlyphPos.Y := Margin;
TextPos.Y := GlyphPos.Y + GlyphSize.Y + Spacing;
DrawStyle:=DT_center;
end;
blGlyphBottom:
begin
GlyphPos.Y := ClientSize.y - Margin - GlyphSize.Y;
TextPos.Y := GlyphPos.Y - Spacing - TextSize.Y;
DrawStyle:=DT_center;
end;
end;
r1:=rect(glyphpos.x,glyphpos.y,0,0);
DrawGlyph(btemp.canvas,r1,btn.glyph,j,btn.NumGlyphs);
TextBounds:= rect(textpos.x,textpos.y,textpos.x+TextSize.x,textpos.y+TextSize.y);
SetBkMode(btemp.Canvas.Handle, TRANSPARENT);
{ bg.canvas.font.assign(btn.font);
bg.canvas.Font.Color := fsd.colors[csButtonText];
if (i=1) then
bg.canvas.Font.Color:= fsd.button.normalcolor2;
if (i=4) then
bg.canvas.Font.Color:= fsd.button.overcolor2;
if (i=2) then
bg.canvas.Font.Color:= fsd.button.downcolor2;
if not btn.enabled then
bg.canvas.Font.Color := clBtnShadow;}
{ SetTextColor(btemp.canvas.handle,fsd.colors[csButtonText]);
if (i=1) then
SetTextColor(btemp.canvas.handle,fsd.button.normalcolor2);
if (i=4) then
SetTextColor(btemp.canvas.handle,fsd.button.overcolor2);
if (i=2) then
SetTextColor(btemp.canvas.handle,fsd.button.downcolor2);
if not btn.enabled then
SetTextColor(btemp.canvas.handle,COLORREF(clBtnShadow));}
btemp.canvas.Font.Assign(btn.Font);
DrawText(btemp.canvas.Handle, PChar(btn.caption),Length(btn.caption),TextBounds,DrawStyle);
BitBlt(dc,rc.left ,rc.top,rc.right-rc.left,rc.bottom-rc.Top,
btemp.Canvas.Handle ,0 ,0 ,Srccopy);
selectobject(btemp.canvas.handle,cfont);
end;
procedure TSkinBitButton.DrawGlyph( acanvas:Tcanvas; rc:TRect;
bmp:Tbitmap;I,N:integer);
var atemp:Tbitmap;
w,h,x:integer;
begin
atemp:=Tbitmap.create;
if n<>4 then i:=1;
w:=bmp.width div n;
h:=bmp.height;
atemp.height:=w;
atemp.width:=h;
x:=(i-1)*w;
atemp.canvas.copyrect( rect(0,0,w,h),
bmp.canvas,rect(x,0,x+w,h));
atemp.Transparent:=true;
// temp.Transparentcolor:=clFuchsia;
// atemp.Transparentcolor:=atemp.Canvas.Pixels[0, h-1];
atemp.Transparentcolor:=atemp.Canvas.Pixels[0, 0];
acanvas.draw(rc.left,rc.top,atemp);
atemp.free;
end;
Procedure TSkinSpeedButton.InitGraphicControl(sf:Tcomponent;sd:TSkinData;acanvas:TCanvas);
begin
fsd:=sd;
fCanvas:=acanvas;
gcontrol:=TGraphicControl(owner);
skinform:=sf;
OldWndProc:= gControl.WindowProc;
gControl.WindowProc := NewWndProc;
Twinskinform(skinform).addcontrollist(self);
skinstate:=skin_active;
end;
constructor TSkinSpeedButton.Create(AOwner: TComponent);
begin
inherited create(aowner);
// gcanvas:=Tcanvas.create;
end;
destructor TSkinSpeedButton.Destroy;
begin
// gcanvas.free;
if assigned(oldwndproc) then begin
if gcontrol<>nil then gControl.WindowProc := OldWndProc;
oldwndproc:=nil;
end;
inherited destroy;
end;
function TSkinSpeedButton.BeforeProc(var Message: TMessage):boolean;
var rc:Trect;
C :TCanvas;
begin
result:=true;
case message.msg of
WM_LBUTTONDOWN, WM_LBUTTONDBLCLK:
begin
default(message);
state:=state+[scDown];
PaintControl;
result:=false;
end;
WM_Paint: begin
C := TCanvas.Create;
C.handle := TWMPaint(Message).DC;
rc:=gcontrol.ClientRect;
// OffsetRect( rc, -rc.left, -rc.top );
DrawSpeedbtn( c,rc);
c.free;
result:=false;
message.result:=1;
end;
else result:=inherited beforeProc(message);
end;
end;
procedure TSkinSpeedButton.AfterProc(var Message: TMessage);
begin
case message.msg of
CM_MOUSEENTER:
begin
state:=state+[scMouseIn];
PaintControl;
end;
CM_MOUSELEAVE:
begin
state:=state-[scMouseIn];
state:=state-[scDown];
if gcontrol.Visible then
PaintControl;
end;
WM_LBUTTONUP:
begin
state:=state-[scDown];
PaintControl;
// TSpeedButton(gcontrol).click;
end;
WM_KEYDOWN:
if Message.WParam = VK_SPACE then begin
state:=state+[scDown];
PaintControl;
end;
WM_KEYUP:
if Message.WParam = VK_SPACE then begin
state:=state-[scDown];
PaintControl;
end;
WM_NCDESTROY,CM_RELEASE:begin
if assigned(oldwndproc) then begin
gControl.WindowProc := OldWndProc;
oldwndproc:=nil;
end;
end;
else inherited AfterProc(Message);
end;
end;
procedure TSkinSpeedButton.PaintControl(adc:HDC=0);
var rc:TRect;
begin
rc:=gcontrol.ClientRect;
OffsetRect( rc, -rc.left, -rc.top );
if TAcGraphicControl(gcontrol).Canvas.handle<>0 then
DrawSpeedbtn(TAcGraphicControl(gcontrol).Canvas,rc);
// Application.ProcessMessages;
// DrawSpeedbtn(gcontrol.Canvas,rc);
end;
procedure TSkinSpeedButton.DrawSpeedbtn( acanvas:Tcanvas; rc:TRect);
var btn:Tspeedbutton;
acolor:Tcolor;
i,n,j:integer;
spacing,margin:integer;
r1,TextBounds:Trect;
Layout: TButtonLayout;
TextPos: TPoint;
GlyphPos, ClientSize, GlyphSize, TextSize: TPoint;
TotalSize: TPoint;
DrawStyle: Longint;
begin
if fsd.button=nil then exit;
if fsd.Button.map.empty then exit;
DrawStyle:=DT_LEFT;
btn:=Tspeedbutton(gcontrol);
i:=1;
// if btn.default then i:=5;
// if btn.focused then i:=4;
if (scDown in state) then i:=2
else if (scMouseIn in state) then i:=4;
if not btn.enabled then i:=3;
if (btn.down) then i:=2 ;
j:=1;
case i of
1: j:=1;
2: j:=3;
3: j:=2;
4: j:=1;
end;
if j>btn.NumGlyphs then j:=1;
r1:=rc;
offsetrect(r1,-r1.left,-r1.top);
bg.width:=r1.right;
bg.height:=r1.bottom;
bg.canvas.font.assign(btn.font);
DrawSkin(r1,fsd.button,i,fsd.button.frame,fsd.button.Trans);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -