2
0
Эх сурвалжийг харах

Use icons for the Images.res images instead of bitmaps. Higher quality and less code.

Martijn Laan 4 жил өмнө
parent
commit
962295b823

+ 23 - 8
Components/BitmapImage.pas

@@ -41,7 +41,8 @@ type
   public
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
-    procedure InitializeFromResource(const hInstance: HINST; const ResourceName: PChar; const AWidth, AHeight: Integer; const BkColor: TColor);
+    procedure InitializeFromIcon(const Icon: TIcon; const BkColor: TColor); overload;
+    procedure InitializeFromIcon(const hInstance: HINST; const ResourceName: PChar; const BkColor: TColor); overload;
   published
     property Align;
     property Anchors;
@@ -82,16 +83,30 @@ begin
   RegisterComponents('JR', [TBitmapImage]);
 end;
 
-procedure TBitmapImage.InitializeFromResource(const hInstance: HINST; const ResourceName: PChar; const AWidth, AHeight: Integer; const BkColor: TColor);
+procedure TBitmapImage.InitializeFromIcon(const Icon: TIcon; const BkColor: TColor);
 begin
   { Set sizes (overrides any scaling) }
-  Width := AWidth;
-  Height := AHeight;
+  Width := Icon.Width;
+  Height := Icon.Height;
 
-  { Load bitmap }
-  Bitmap.Handle := LoadBitmap(hInstance, ResourceName);
-  ReplaceColor := RGB(255, 0, 255);
-  ReplaceWithColor := BkColor;
+  { Draw icon into bitmap }
+  Bitmap.Canvas.Brush.Color := BkColor;
+  Bitmap.Width := Width;
+  Bitmap.Height := Height;
+  Bitmap.Canvas.Draw(0, 0, Icon);
+end;
+
+procedure TBitmapImage.InitializeFromIcon(const hInstance: HINST; const ResourceName: PChar; const BkColor: TColor);
+var
+  Icon: TIcon;
+begin
+  Icon := TIcon.Create;
+  try
+    Icon.Handle := LoadImage(hInstance, ResourceName, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
+    InitializeFromIcon(Icon, BkColor);
+  finally
+    Icon.Free;
+  end;
 end;
 
 constructor TBitmapImage.Create(AOwner: TComponent);

BIN
Projects/Images.res


+ 1 - 1
Projects/NewDisk.pas

@@ -80,7 +80,7 @@ begin
   OKButton.Caption := SetupMessages[msgButtonOK];
   CancelButton.Caption := SetupMessages[msgButtonCancel];
 
-  DiskBitmapImage.InitializeFromResource(HInstance, 'DISKIMAGE', 48, 48, Color); {don't localize}
+  DiskBitmapImage.InitializeFromIcon(HInstance, 'DISKICON', Color); {don't localize}
 
   TryEnableAutoCompleteFileSystem(PathEdit.Handle);
 

+ 1 - 4
Projects/UninstProgressForm.pas

@@ -112,10 +112,7 @@ begin
 
   PageNameLabel.Font.Style := [fsBold];
   PageNameLabel.Caption := SetupMessages[msgWizardUninstalling];
-  WizardSmallBitmapImage.Bitmap.Canvas.Brush.Color := MainPanel.Color;
-  WizardSmallBitmapImage.Bitmap.Width := Application.Icon.Width;
-  WizardSmallBitmapImage.Bitmap.Height := Application.Icon.Height;
-  WizardSmallBitmapImage.Bitmap.Canvas.Draw(0, 0, Application.Icon);
+  WizardSmallBitmapImage.InitializeFromIcon(Application.Icon, MainPanel.Color);
   if SetupMessages[msgBeveledLabel] <> '' then begin
     BeveledLabel.Caption := ' ' + SetupMessages[msgBeveledLabel] + ' ';
     BeveledLabel.Visible := True;

+ 3 - 3
Projects/Wizard.pas

@@ -871,9 +871,9 @@ begin
   WizardBitmapImage2.Stretch := (shWizardImageStretch in SetupHeader.Options);
   WizardSmallBitmapImage.Bitmap := SelectBestImage(WizardSmallImages, WizardSmallBitmapImage.Width, WizardSmallBitmapImage.Height);
   WizardSmallBitmapImage.Stretch := (shWizardImageStretch in SetupHeader.Options);
-  SelectDirBitmapImage.InitializeFromResource(HInstance, 'DIRIMAGE', 32, 32, SelectDirPage.Color); {don't localize}
-  SelectGroupBitmapImage.InitializeFromResource(HInstance, 'GROUPIMAGE', 32, 32, SelectProgramGroupPage.Color); {don't localize}
-  PreparingErrorBitmapImage.InitializeFromResource(HInstance, 'STOPIMAGE', 16, 16, PreparingPage.Color); {don't localize}
+  SelectDirBitmapImage.InitializeFromIcon(HInstance, 'DIRICON', SelectDirPage.Color); {don't localize}
+  SelectGroupBitmapImage.InitializeFromIcon(HInstance, 'GROUPICON', SelectProgramGroupPage.Color); {don't localize}
+  PreparingErrorBitmapImage.InitializeFromIcon(HInstance, 'STOPICON', PreparingPage.Color); {don't localize}
 
   { Initialize wpWelcome page }
   RegisterExistingPage(wpWelcome, WelcomePage, nil, '', '');