Skip to content

Commit

Permalink
support menuitem.Bitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
Alextp committed Sep 20, 2020
1 parent 89b0b16 commit e72f99b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
Binary file added icon1.bmp
Binary file not shown.
3 changes: 3 additions & 0 deletions unit1.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ object Form1: TForm1
ImageIndex = 4
RadioItem = True
end
object MenuItemBmp: TMenuItem
Caption = 'with bitmap'
end
end
object ImageList1: TImageList
AllocBy = 8
Expand Down
10 changes: 10 additions & 0 deletions unit1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ TForm1 = class(TForm)
MenuItem39: TMenuItem;
MenuItem4: TMenuItem;
MenuItem40: TMenuItem;
MenuItemBmp: TMenuItem;
MenuItem5: TMenuItem;
normal: TMenuItem;
MenuItem6: TMenuItem;
Expand All @@ -74,6 +75,7 @@ TForm1 = class(TForm)
private
FOrigWndState: TWindowState;
FOrigBounds: TRect;
bmp: TBitmap;
procedure SetFullScreen(AValue: boolean);
procedure SetTheme(AColor: TColor);

Expand Down Expand Up @@ -101,7 +103,15 @@ procedure TForm1.btnTheme2Click(Sender: TObject);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
fn: string;
begin
bmp:= TBitmap.Create;
fn:= ExtractFilePath(Application.ExeName)+'icon1.bmp';
if FileExists(fn) then
bmp.LoadFromFile(fn);
MenuItemBmp.Bitmap:= bmp;

SetTheme(clPurple);
end;

Expand Down
24 changes: 19 additions & 5 deletions win32menustyler.pas
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,20 @@ procedure TWin32MenuStyler.HandleMenuDrawItem(Sender: TObject; ACanvas: TCanvas;

IconW:= 0;
IconH:= 0;

if Assigned(mi.Bitmap) then
begin
IconW:= mi.Bitmap.Width;
IconH:= mi.Bitmap.Height;
end;

Images:= mi.GetParentMenu.Images;
if Assigned(Images) then
begin
IconW:= Images.Width;
IconH:= Images.Height;
IconW:= Max(IconW, Images.Width);
IconH:= Max(IconH, Images.Height);
end;

//todo: support MenuItem.Bitmap
if IconW>0 then
dxBig:= Max(dxBig, IconW + dxCell * MenuStylerTheme.IndentIconPercents * 2 div 100);

Expand Down Expand Up @@ -216,11 +222,19 @@ procedure TWin32MenuStyler.HandleMenuDrawItem(Sender: TObject; ACanvas: TCanvas;
R.Bottom:= ARect.Bottom;
Windows.DrawTextW(ACanvas.Handle, PWideChar(BufW), Length(BufW), R, NDrawFlags);

if (not bInBar) and Assigned(mi.Bitmap) then
begin
ACanvas.Draw(
ARect.Left + (dx-mi.Bitmap.Width) div 2,
(ARect.Top+ARect.Bottom-mi.Bitmap.Height) div 2,
mi.Bitmap);
end
else
if (not bInBar) and Assigned(Images) and (mi.ImageIndex>=0) then
begin
Images.Draw(ACanvas,
dxCell * MenuStylerTheme.IndentIconPercents div 100,
(ARect.Top+ARect.Bottom-IconH) div 2,
ARect.Left + (dx-Images.Width) div 2,
(ARect.Top+ARect.Bottom-Images.Height) div 2,
mi.ImageIndex, not bDisabled);
end
else
Expand Down

0 comments on commit e72f99b

Please sign in to comment.