📄 bsskinmenus.pas
字号:
if not MenuItem.Bitmap.Empty
then
begin
if IsNullRect(MI.ImageRct)
then
begin
GX := TR.Left + 2;
GY := TR.Top + RectHeight(TR) div 2 - MenuItem.Bitmap.Height div 2;
end
else
begin
GX := MI.ImageRct.Left + RectWidth(MI.ImageRct) div 2 -
MenuItem.Bitmap.Width div 2;
GY := MI.ImageRct.Top + RectHeight(MI.ImageRct) div 2 - MenuItem.Bitmap.Height div 2;
end;
if MenuItem.Checked
then
begin
Brush.Style := bsClear;
Pen.Color := Font.Color;
Rectangle(GX - 1, GY - 1,
GX + MenuItem.Bitmap.Width + 1,
GY + MenuItem.Bitmap.Height + 1);
end;
end
else
begin
if IsNullRect(MI.ImageRct)
then
begin
GX := TR.Left + 2;
GY := TR.Top + RectHeight(TR) div 2 - Parent.ImgL.Height div 2;
end
else
begin
GX := MI.ImageRct.Left + RectWidth(MI.ImageRct) div 2 -
Parent.ImgL.Width div 2;
GY := MI.ImageRct.Top + RectHeight(MI.ImageRct) div 2 - Parent.ImgL.Height div 2;
end;
if MenuItem.Checked
then
begin
Brush.Style := bsClear;
Pen.Color := Font.Color;
Rectangle(GX - 1, GY - 1,
GX + Parent.ImgL.Width + 1,
GY + Parent.ImgL.Height + 1);
end;
end;
end
else
begin
if IsNullRect(MI.ImageRct)
then
begin
IY := TR.Top + RectHeight(TR) div 2 - 4;
IX := TR.Left + 2;
end
else
begin
IY := MI.ImageRct.Top + RectHeight(MI.ImageRct) div 2 - 4;
IX := MI.ImageRct.Left + RectWidth(MI.ImageRct) div 2 - 4
end;
if (MenuItem.Name = MI_CLOSENAME) or (MenuItem.Name = TMI_CLOSENAME)
then DrawCloseImage(B.Canvas, IX, IY, B.Canvas.Font.Color) else
if MenuItem.Name = MI_MINNAME
then DrawMinimizeImage(B.Canvas, IX, IY, B.Canvas.Font.Color)
else
if MenuItem.Name = MI_MAXNAME
then DrawMaximizeImage(B.Canvas, IX, IY, B.Canvas.Font.Color)
else
if (MenuItem.Name = MI_RESTORENAME) or (MenuItem.Name = TMI_RESTORENAME)
then DrawRestoreImage(B.Canvas, IX, IY, B.Canvas.Font.Color)
else
if MenuItem.Name = MI_ROLLUPNAME
then DrawRollUpImage(B.Canvas, IX, IY, B.Canvas.Font.Color)
else
if MenuItem.Name = MI_MINTOTRAYNAME
then DrawMTImage(B.Canvas, IX, IY, B.Canvas.Font.Color)
else
if MenuItem.Checked
then
if MenuItem.RadioItem
then
DrawRadioImage(B.Canvas,
IX, IY + 1,
B.Canvas.Font.Color)
else
DrawCheckImage(B.Canvas,
IX, IY,
B.Canvas.Font.Color);
end;
end;
//
if DrawGlyph
then
if not MenuItem.Bitmap.Empty
then
B.Canvas.Draw(GX, GY, MenuItem.BitMap)
else
Parent.ImgL.Draw(B.Canvas, GX, GY,
MenuItem.ImageIndex, MenuItem.Enabled);
end;
function GetAnimationFrameRect: TRect;
var
fs: Integer;
begin
if RectHeight(MI.AnimateSkinRect) > RectHeight(MI.SkinRect)
then
begin
fs := RectHeight(MI.AnimateSkinRect) div MI.FrameCount;
Result := Rect(MI.AnimateSkinRect.Left,
MI.AnimateSkinRect.Top + (CurrentFrame - 1) * fs,
MI.AnimateSkinRect.Right,
MI.AnimateSkinRect.Top + CurrentFrame * fs);
end
else
begin
fs := RectWidth(MI.AnimateSkinRect) div MI.FrameCount;
Result := Rect(MI.AnimateSkinRect.Left + (CurrentFrame - 1) * fs,
MI.AnimateSkinRect.Top,
MI.AnimateSkinRect.Left + CurrentFrame * fs,
MI.AnimateSkinRect.Bottom);
end;
end;
var
B, AB: TBitMap;
EffB, EffAB: TbsEffectBmp;
AD: Boolean;
begin
if not FVisible then Exit;
if MI = nil
then
begin
DefaultDraw(Cnvs);
Exit;
end;
B := TBitMap.Create;
if MenuItem.Caption = '-'
then
begin
CreateHSkinImage(MI.DividerLO, MI.DividerRO,
B, ActivePicture, MI.DividerRect,
RectWidth(ObjectRect), RectHeight(ObjectRect), MI.DividerStretchEffect);
end
else
begin
AD := Active or Down;
if EnableAnimation and
(CurrentFrame >= 1) and (CurrentFrame <= MI.FrameCount)
then
begin
SpecRect := GetAnimationFrameRect;
CreateItemImage(B, AD, True);
end
else
if not EnableMorphing or
((AD and (MorphKf = 1)) or (not AD and (MorphKf = 0)))
then
CreateItemImage(B, AD, False)
else
begin
CreateItemImage(B, False, False);
AB := TBitMap.Create;
CreateItemImage(AB, True, False);
EffB := TbsEffectBmp.CreateFromhWnd(B.Handle);
EffAB := TbsEffectBmp.CreateFromhWnd(AB.Handle);
case MI.MorphKind of
mkDefault: EffB.Morph(EffAB, MorphKf);
mkGradient: EffB.MorphGrad(EffAB, MorphKf);
mkLeftGradient: EffB.MorphLeftGrad(EffAB, MorphKf);
mkRightGradient: EffB.MorphRightGrad(EffAB, MorphKf);
mkLeftSlide: EffB.MorphLeftSlide(EffAB, MorphKf);
mkRightSlide: EffB.MorphRightSlide(EffAB, MorphKf);
mkPush: EffB.MorphPush(EffAB, MorphKf);
end;
EffB.Draw(B.Canvas.Handle, 0, 0);
AB.Free;
EffB.Free;
EffAB.Free;
end;
end;
Cnvs.Draw(ObjectRect.Left, ObjectRect.Top, B);
B.Free;
end;
//================TbsSkinPopupWindow======================//
constructor TbsSkinPopupWindow.CreateEx;
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csNoDesignVisible, csReplicatable,
csAcceptsControls];
ParentMenu := AParentMenu;
Ctl3D := False;
ParentCtl3D := False;
Visible := False;
ItemList := TList.Create;
MouseTimer := TTimer.Create(Self);
MouseTimer.Enabled := False;
MouseTimer.OnTimer := TestMouse;
MouseTimer.Interval := MouseTimerInterval;
MorphTimer := TTimer.Create(Self);
MorphTimer.Enabled := False;
MorphTimer.OnTimer := TestMorph;
MorphTimer.Interval := MorphTimerInterval;
FRgn := 0;
WindowPicture := nil;
MaskPicture := nil;
if (AData = nil) or (AData.WindowPictureIndex = -1)
then
begin
PW := nil;
SD := nil;
end
else
begin
PW := AData;
SD := ParentMenu.SkinData;
with PW do
begin
if (WindowPictureIndex <> - 1) and
(WindowPictureIndex < SD.FActivePictures.Count)
then
WindowPicture := SD.FActivePictures.Items[WindowPictureIndex];
if (MaskPictureIndex <> - 1) and
(MaskPictureIndex < SD.FActivePictures.Count)
then
MaskPicture := SD.FActivePictures.Items[MaskPictureIndex];
end;
end;
ActiveItem := -1;
OldActiveItem := -1;
OMX := -1;
OMY := -1;
DSMI := nil;
ScrollCode := 0;
Scroll2 := False;
end;
destructor TbsSkinPopupWindow.Destroy;
var
i: Integer;
begin
for i := 0 to ItemList.Count - 1 do
TbsSkinMenuItem(ItemList.Items[i]).Free;
ItemList.Clear;
ItemList.Free;
MouseTimer.Free;
MorphTimer.Free;
inherited Destroy;
if FRgn <> 0 then DeleteObject(FRgn);
end;
procedure TbsSkinPopupWindow.TestMorph;
var
i: Integer;
StopMorph: Boolean;
begin
if PW = nil then Exit;
StopMorph := True;
for i := 0 to ItemList.Count - 1 do
with TbsSkinMenuItem(ItemList.Items[i]) do
begin
if EnableMorphing and CanMorphing
then
begin
DoMorphing;
StopMorph := False;
end
else
if EnableAnimation
then
begin
if Active and (CurrentFrame <= MI.FrameCount)
then
begin
Inc(CurrentFrame);
Draw(Canvas);
StopMorph := False;
end
else
if not Active and (CurrentFrame > 0)
then
begin
Dec(CurrentFrame);
Draw(Canvas);
StopMorph := False;
end;
end;
end;
if StopMorph then MorphTimer.Enabled := False;
end;
function TbsSkinPopupWindow.CanScroll;
begin
Result := False;
case AScrollCode of
1: Result := VisibleStartIndex > 0;
2: Result := VisibleStartIndex + VisibleCount - 1 < ItemList.Count - 1;
end;
end;
procedure TbsSkinPopupWindow.WMTimer;
begin
inherited;
case ScrollCode of
1: if CanScroll(1) then ScrollUp(False) else StopScroll;
2: if CanScroll(2) then ScrollDown(False) else StopScroll;
end;
end;
procedure TbsSkinPopupWindow.DrawUpMarker;
var
R: TRect;
C: TColor;
begin
if PW <> nil
then
begin
R := Rect(NewItemsRect.Left, NewItemsRect.Top,
NewItemsRect.Right, NewItemsRect.Top + MarkerItemHeight);
if ScrollCode = 1
then C := PW.ScrollMarkerActiveColor
else C := PW.ScrollMarkerColor;
end
else
begin
R := Rect(3, 3, Width - 3, 3 + MarkerItemHeight);
if ScrollCode = 1
then C := clBtnText
else C := clBtnShadow;
end;
DrawArrowImage(Cnvs, R, C, 3);
end;
procedure TbsSkinPopupWindow.DrawDownMarker;
var
R: TRect;
C: TColor;
begin
if PW <> nil
then
begin
R := Rect(NewItemsRect.Left, NewItemsRect.Bottom - MarkerItemHeight,
NewItemsRect.Right, NewItemsRect.Bottom);
if ScrollCode = 2
then C := PW.ScrollMarkerActiveColor
else C := PW.ScrollMarkerColor;
end
else
begin
R := Rect(3, Height - MarkerItemHeight, Width - 3, Height - 3);
if ScrollCode = 2
then C := clBtnText
else C := clBtnShadow;
end;
DrawArrowImage(Cnvs, R, C, 4);
end;
procedure TbsSkinPopupWindow.StartScroll;
var
i: Integer;
begin
i := ParentMenu.GetPWIndex(Self);
ParentMenu.CloseMenu(i + 1);
KillTimer(Handle, 1);
SetTimer(Handle, 1, ScrollTimerInterval, nil);
end;
procedure TbsSkinPopupWindow.StopScroll;
begin
ScrollCode := 0;
DrawUpMarker(Canvas);
DrawDownMarker(Canvas);
KillTimer(Handle, 1);
end;
procedure TbsSkinPopupWindow.ScrollUp;
begin
if VisibleStartIndex > 0
then
begin
VisibleStartIndex := VisibleStartIndex - 1;
CalcItemRects;
RePaint;
end
else
if Cycle
then
begin
VisibleStartIndex := GetEndStartVisibleIndex;
CalcItemRects;
RePaint;
end;
end;
procedure TbsSkinPopupWindow.ScrollDown(Cycle: Boolean);
begin
if VisibleStartIndex + VisibleCount - 1 < ItemList.Count - 1
then
begin
VisibleStartIndex := VisibleStartIndex + 1;
CalcItemRects;
RePaint;
end
else
if Cycle
then
begin
VisibleStartIndex := 0;
CalcItemRects;
RePaint;
end;
end;
procedure TbsSkinPopupWindow.PopupKeyDown(CharCode: Integer);
var
PW: TbsSkinPopupWindow;
procedure NextItem;
var
i, j: Integer;
begin
if Scroll and (ScrollCode = 0) and (ActiveItem = VisibleStartIndex + VisibleCount - 1)
then ScrollDown(True);
OldActiveItem := ActiveItem;
if ActiveItem < 0 then j := 0 else j := ActiveItem + 1;
if j = ItemList.Count then j := 0;
for i := j to ItemList.Count - 1 do
with TbsSkinMenuItem(ItemList.Items[i]) do
begin
if MenuItem.Enabled and (MenuItem.Caption <> '-')
then
begin
ActiveItem := i;
Break;
end
else
begin
if Scroll and (ScrollCode = 0) and (i = VisibleStartIndex + VisibleCount - 1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -