📄 winsubclass.pas
字号:
end;
if 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 (TextSize.X = 0) or (GlyphSize.X = 0) then
Spacing := 0;
s := GetEnumProperty(control,'Alignment');
if (Margin = -1) or (s='taCenter') then begin
if Spacing = -1 then begin
TotalSize := Point(GlyphSize.X + TextSize.X, GlyphSize.Y + TextSize.Y);
if 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 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 Layout in [blGlyphLeft, blGlyphRight] then
Spacing := (TotalSize.X - TextSize.X) div 2
else
Spacing := (TotalSize.Y - TextSize.Y) div 2;
end;
end;
case 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);
if (bglyph<>nil) and (not bglyph.Empty) then
DrawGlyph(btemp.canvas,r1,bglyph,j,NumGlyphs)
else if (bglist<>nil) then begin
if enabled then begin
if (imageindex<>-1) then
bglist.Draw(btemp.canvas, r1.Left, r1.Top, ImageIndex,Enabled);
end else begin
if (disabledindex<>-1) then
bglist.Draw(btemp.canvas, r1.Left, r1.Top, disabledIndex,enabled)
else if (imageindex<>-1) then
bglist.Draw(btemp.canvas, r1.Left, r1.Top, ImageIndex,Enabled);
end;
end;
TextBounds:= rect(textpos.x,textpos.y,textpos.x+TextSize.x,textpos.y+TextSize.y);
SetBkMode(btemp.Canvas.Handle, TRANSPARENT);
if (i=1) and (fsd.button.newnormal) then
btemp.canvas.Font.Color:= fsd.button.normalcolor2;
if (i=4) and (fsd.button.newover) then
btemp.canvas.Font.Color:= fsd.button.overcolor2;
if (i=2) and (fsd.Button.newdown) then
btemp.canvas.Font.Color:= fsd.button.downcolor2;
if not enabled then
btemp.canvas.Font.Color := clBtnShadow;
// btemp.canvas.Font.Assign(btn.Font);
// DrawText(btemp.canvas.Handle, PChar(btn.caption),Length(btn.caption),TextBounds,DrawStyle);
Tnt_DrawTextW(btemp.canvas.Handle,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,j:integer;
begin
atemp:=Tbitmap.create;
j:=i;
if n<>4 then i:=1;
w:=bmp.width div n;
h:=bmp.height;
atemp.height:=h;
atemp.width:=w;
x:=(i-1)*w;
atemp.canvas.copyrect( rect(0,0,w,h),bmp.canvas,rect(x,0,x+w,h));
if (j=2) then ConvertBitmapToGrayscale (atemp);
atemp.Transparent := true;
atemp.TransparentMode := tmAuto;
// 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 acolor:Tcolor;
i,n,j:integer;
r1,TextBounds:Trect;
TextPos: TPoint;
GlyphPos, ClientSize, GlyphSize, TextSize: TPoint;
TotalSize: TPoint;
DrawStyle: Longint;
Layout: TButtonLayout;
NumGlyphs,margin,spacing :integer;
bglyph:Tbitmap;
s:string;
font:Tfont;
flat:boolean;
enable:boolean;
begin
if fsd.button=nil then exit;
if fsd.Button.map.empty then exit;
DrawStyle:=DT_LEFT;
i:=1;
if (scDown in state) then i:=2
else if (scMouseIn in state) then i:=4;
s:=lowercase(GetEnumProperty(gcontrol,'Enabled'));
if s='true' then enable:=true
else enable:=false;
if not enable then i:=3;
s:=lowercase(GetEnumProperty(gcontrol,'Down'));
if s='true' 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;
caption := GetStringProp(gcontrol,'Caption');
font := Tfont(GetObjProp(gcontrol,'Font',Tfont));
bglyph := Tbitmap(GetObjProp(gcontrol,'Glyph',Tbitmap));
NumGlyphs := GetIntProperty(gcontrol,'NumGlyphs') ;
if NumGlyphs=0 then NumGlyphs:=1;
// bglist := Timagelist(GetObjProp(gcontrol,'Images',Timagelist));
// imageindex := GetIntProperty(gcontrol,'ImageIndex') ;
// disabledindex := GetIntProperty(gcontrol,'DisabledIndex') ;
s:=lowercase(GetEnumProperty(gcontrol,'Flat'));
if s='true' then flat:=true
else flat:=false;
Margin := GetIntProperty(gcontrol,'Margin') ;
Spacing := GetIntProperty(gcontrol,'Spacing') ;
s := lowercase(GetEnumProperty(gcontrol,'Layout'));
if s='blglyphleft' then layout:=blGlyphLeft
else if s='blglyphright' then layout:=blGlyphRight
else if s='blglyphtop' then layout:=blGlyphTop
else if s='blglyphbottom' then layout:=blGlyphbottom;
r1:=rc;
offsetrect(r1,-r1.left,-r1.top);
btemp.width:=r1.right;
btemp.height:=r1.bottom;
btemp.canvas.font.assign(font);
FillBG(btemp.canvas.handle,r1);
if (i<>1) or (not Flat) then
DrawSkinMap( btemp.canvas.handle,r1,fsd.button,I,fsd.button.frame);
ClientSize := Point(r1.right,r1.bottom);
if Length(Caption) > 0 then begin
TextBounds := Rect(0, 0, clientsize.x,clientsize.y);
//DrawText(btemp.canvas.handle, PChar(Caption),length(caption), TextBounds,DT_CALCRECT or dt_left);
Tnt_DrawTextW(btemp.canvas.handle,Caption, 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 (bGlyph <> nil) and (not bGlyph.empty) then
GlyphSize := Point(bGlyph.Width div NumGlyphs, bglyph.Height)
else begin
GlyphSize := Point(0, 0);
// DrawCaption(btemp.canvas,r1,caption,enable,false);
DrawBtnText(btemp.canvas,r1,caption);
aCanvas.draw(rc.left,rc.top,btemp);
exit;
end;
if 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 (GlyphSize.X = 0) or (TextSize.X = 0) then
Spacing := 0;
{ adjust Margin and Spacing }
if Margin = -1 then begin
if Spacing = -1 then begin
TotalSize := Point(GlyphSize.X + TextSize.X, GlyphSize.Y + TextSize.Y);
if 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 Layout in [blGlyphLeft, blGlyphRight] then
Margin := (r1.right - TotalSize.X ) div 2+1
else
Margin := (ClientSize.y - TotalSize.Y ) div 2+1;
end;
end else begin
if Spacing = -1 then begin
TotalSize := Point(ClientSize.x - (Margin + GlyphSize.X), ClientSize.y -
(Margin + GlyphSize.Y));
if Layout in [blGlyphLeft, blGlyphRight] then
Spacing := (TotalSize.X - TextSize.X) div 2
else
Spacing := (TotalSize.Y - TextSize.Y) div 2;
end;
end;
case 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,bglyph,j,NumGlyphs);
TextBounds:= rect(textpos.x,textpos.y,textpos.x+TextSize.x,textpos.y+TextSize.y);
if (i=1) and (fsd.button.newnormal) then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -