1
0
mirror of synced 2024-11-05 03:09:15 +00:00

Added: ImageOffsetX/Y to unaMenuBarPainter

This commit is contained in:
Mark van Renswoude 2008-05-26 10:22:50 +00:00
parent 670eb4baa5
commit 280e5f669b
2 changed files with 52 additions and 2 deletions

View File

@ -419,6 +419,7 @@ type
FHideScrollbar: Boolean; FHideScrollbar: Boolean;
FGroups: TX2MenuBarGroups; FGroups: TX2MenuBarGroups;
FImages: TCustomImageList; FImages: TCustomImageList;
FImagesChangeLink: TChangeLink;
FOnCollapsed: TX2MenuBarExpandedEvent; FOnCollapsed: TX2MenuBarExpandedEvent;
FOnCollapsing: TX2MenuBarExpandingEvent; FOnCollapsing: TX2MenuBarExpandingEvent;
FOnExpanded: TX2MenuBarExpandedEvent; FOnExpanded: TX2MenuBarExpandedEvent;
@ -455,6 +456,7 @@ type
procedure GroupsNotify(Sender: TObject; Item: TCollectionItem; Action: TCollectionNotification); procedure GroupsNotify(Sender: TObject; Item: TCollectionItem; Action: TCollectionNotification);
procedure GroupsUpdate(Sender: TObject; Item: TCollectionItem); procedure GroupsUpdate(Sender: TObject; Item: TCollectionItem);
procedure UpdateScrollbar(); procedure UpdateScrollbar();
procedure ImagesChange(Sender: TObject);
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
@ -1400,8 +1402,11 @@ begin
FGroups.OnNotify := GroupsNotify; FGroups.OnNotify := GroupsNotify;
FGroups.OnUpdate := GroupsUpdate; FGroups.OnUpdate := GroupsUpdate;
FHideScrollbar := True; FHideScrollbar := True;
FImagesChangeLink := TChangeLink.Create();
FScrollbar := True; FScrollbar := True;
TabStop := True; TabStop := True;
FImagesChangeLink.OnChange := ImagesChange;
end; end;
@ -1437,11 +1442,13 @@ end;
destructor TX2CustomMenuBar.Destroy(); destructor TX2CustomMenuBar.Destroy();
begin begin
Images := nil;
Painter := nil; Painter := nil;
FreeAndNil(FGroups); FreeAndNil(FGroups);
FreeAndNil(FBuffer); FreeAndNil(FBuffer);
FreeAndNil(FActionQueue); FreeAndNil(FActionQueue);
FreeAndNil(FImagesChangeLink);
inherited; inherited;
end; end;
@ -1452,6 +1459,7 @@ begin
Msg.Result := 0; Msg.Result := 0;
end; end;
procedure TX2CustomMenuBar.Paint(); procedure TX2CustomMenuBar.Paint();
var var
bufferRect: TRect; bufferRect: TRect;
@ -2844,6 +2852,12 @@ begin
end; end;
procedure TX2CustomMenuBar.ImagesChange(Sender: TObject);
begin
Invalidate();
end;
procedure TX2CustomMenuBar.SetAllowCollapseAll(const Value: Boolean); procedure TX2CustomMenuBar.SetAllowCollapseAll(const Value: Boolean);
begin begin
if Value <> FAllowCollapseAll then if Value <> FAllowCollapseAll then
@ -2910,12 +2924,18 @@ begin
if Value <> FImages then if Value <> FImages then
begin begin
if Assigned(FImages) then if Assigned(FImages) then
begin
FImages.UnRegisterChanges(FImagesChangeLink);
FImages.RemoveFreeNotification(Self); FImages.RemoveFreeNotification(Self);
end;
FImages := Value; FImages := Value;
if Assigned(FImages) then if Assigned(FImages) then
begin
FImages.FreeNotification(Self); FImages.FreeNotification(Self);
FImages.RegisterChanges(FImagesChangeLink);
end;
Invalidate(); Invalidate();
end; end;

View File

@ -96,6 +96,8 @@ type
FGroupHeight: Integer; FGroupHeight: Integer;
FItemHeight: Integer; FItemHeight: Integer;
FMargin: Integer; FMargin: Integer;
FImageOffsetY: Integer;
FImageOffsetX: Integer;
procedure SetAfterGroupHeader(const Value: Integer); procedure SetAfterGroupHeader(const Value: Integer);
procedure SetAfterItem(const Value: Integer); procedure SetAfterItem(const Value: Integer);
@ -106,6 +108,8 @@ type
procedure SetGroupHeight(const Value: Integer); procedure SetGroupHeight(const Value: Integer);
procedure SetItemHeight(const Value: Integer); procedure SetItemHeight(const Value: Integer);
procedure SetMargin(const Value: Integer); procedure SetMargin(const Value: Integer);
procedure SetImageOffsetX(const Value: Integer);
procedure SetImageOffsetY(const Value: Integer);
public public
constructor Create(); constructor Create();
@ -120,6 +124,8 @@ type
property GroupHeight: Integer read FGroupHeight write SetGroupHeight default 22; property GroupHeight: Integer read FGroupHeight write SetGroupHeight default 22;
property ItemHeight: Integer read FItemHeight write SetItemHeight default 21; property ItemHeight: Integer read FItemHeight write SetItemHeight default 21;
property Margin: Integer read FMargin write SetMargin default 10; property Margin: Integer read FMargin write SetMargin default 10;
property ImageOffsetX: Integer read FImageOffsetX write SetImageOffsetX default 0;
property ImageOffsetY: Integer read FImageOffsetY write SetImageOffsetY default 0;
end; end;
TX2MenuBarunaPainter = class(TX2CustomMenuBarPainter) TX2MenuBarunaPainter = class(TX2CustomMenuBarPainter)
@ -387,6 +393,26 @@ begin
end; end;
procedure TX2MenuBarunaMetrics.SetImageOffsetX(const Value: Integer);
begin
if Value <> FImageOffsetX then
begin
FImageOffsetX := Value;
Changed();
end;
end;
procedure TX2MenuBarunaMetrics.SetImageOffsetY(const Value: Integer);
begin
if Value <> FImageOffsetY then
begin
FImageOffsetY := Value;
Changed();
end;
end;
{ TX2MenuBarunaPainter } { TX2MenuBarunaPainter }
constructor TX2MenuBarunaPainter.Create(AOwner: TComponent); constructor TX2MenuBarunaPainter.Create(AOwner: TComponent);
begin begin
@ -576,6 +602,10 @@ begin
begin begin
imagePos.X := textRect.Left; imagePos.X := textRect.Left;
imagePos.Y := ABounds.Top + ((ABounds.Bottom - ABounds.Top - imageList.Height) div 2); imagePos.Y := ABounds.Top + ((ABounds.Bottom - ABounds.Top - imageList.Height) div 2);
Inc(imagePos.X, Metrics.ImageOffsetX);
Inc(imagePos.Y, Metrics.ImageOffsetY);
imageList.Draw(ACanvas, imagePos.X, imagePos.Y, AGroup.ImageIndex); imageList.Draw(ACanvas, imagePos.X, imagePos.Y, AGroup.ImageIndex);
end; end;
@ -584,6 +614,7 @@ begin
{ Text } { Text }
ACanvas.Font.Style := [fsBold]; ACanvas.Font.Style := [fsBold];
SetBkMode(ACanvas.Handle, TRANSPARENT);
DrawText(ACanvas, AGroup.Caption, textRect, taLeftJustify, taVerticalCenter, DrawText(ACanvas, AGroup.Caption, textRect, taLeftJustify, taVerticalCenter,
False, csEllipsis); False, csEllipsis);
end; end;
@ -637,14 +668,13 @@ begin
Inc(textBounds.Left, 4); Inc(textBounds.Left, 4);
Dec(textBounds.Right, 4); Dec(textBounds.Right, 4);
SetBkMode(ACanvas.Handle, TRANSPARENT);
if not AItem.Visible then if not AItem.Visible then
{ Design-time } { Design-time }
ACanvas.Font.Style := [fsItalic] ACanvas.Font.Style := [fsItalic]
else else
ACanvas.Font.Style := []; ACanvas.Font.Style := [];
SetBkMode(ACanvas.Handle, TRANSPARENT);
DrawText(ACanvas, AItem.Caption, textBounds, taRightJustify, taVerticalCenter, DrawText(ACanvas, AItem.Caption, textBounds, taRightJustify, taVerticalCenter,
False, csEllipsis); False, csEllipsis);
end; end;