Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Аватара для Johny777

Ветеран


Сообщения: 649
Благодарности: 444

Профиль | Отправить PM | Цитировать


Ivan_009,
текстурирование кнопок
2 состояния - обычное и при нажатии
код:
читать дальше »
Код: Выделить весь код
#define ButtonWidth "80" ; ширина кнопки
#define ButtonHeight "25" ; высота

#define ButtonFontColor "clWhite" ;цвет шрифта кнопок

#define TextureWidth "160" ;ширина картинки-текстуры
#define TextureHeight "25" ;высота


[Setup]
AppName=Test
AppVerName=Test
DefaultDirName={pf}\Test
OutputDir=.

;Изображение размером 160х25 (можете поменять в купе с настройками в препроцессоре, в шапке)
;левая половина - обычное состояние, правая - при нажатии
BitmapResource=button:button.bmp


[code]
var
  ButtonPanel: array [0..4] of TPanel;
  ButtonImage: array [0..4] of TBitmapImage;
  ButtonLabel: array [0..4] of TLabel;

procedure ButtonLabelClick(Sender: TObject);
var
  Button: TButton;
begin
  with WizardForm do
  begin
    case TLabel(Sender).Tag of
      0: Button := BackButton;
      1: Button := NextButton;
      2: Button := CancelButton;
      3: Button := DirBrowseButton;
      4: Button := GroupBrowseButton;
    else exit
    end;
  end;
  Button.OnClick(Button);
end;

procedure ButtonLabelMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ButtonImage[TLabel(Sender).Tag].Left:= -ScaleX({#ButtonWidth});
end;

procedure ButtonLabelMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ButtonImage[TLabel(Sender).Tag].Left := ScaleX(0);
end;

procedure LoadButtonImage(AButton: TButton; AButtonIndex: integer);
var
  Image: TBitmapImage;
  Panel: TPanel;
  Labl: TLabel;
begin
  Panel:=TPanel.Create(WizardForm)
  with Panel do
  begin
    SetBounds(AButton.Left,AButton.Top,AButton.Width,AButton.Height);
    Tag := AButtonIndex;
    Parent := AButton.Parent;
  end;

  ButtonPanel[AButtonIndex] := Panel;

  Image:=TBitmapImage.Create(WizardForm)
  with Image do
  begin
    Width := ScaleX({#TextureWidth});
    Height := ScaleY({#TextureHeight});
    Enabled := False;
    Bitmap.LoadFromResourceName(HInstance, '_IS_BUTTON');
    Parent := Panel;
  end;

  ButtonImage[AButtonIndex]:=Image;

  with TLabel.Create(WizardForm) do
  begin
    Tag := AButtonIndex;
    Parent := Panel;
    Width := Panel.Width;
    Height := Panel.Height;
    Transparent := True;
    OnClick := @ButtonLabelClick;
    OnDblClick := @ButtonLabelClick;
    OnMouseDown := @ButtonLabelMouseDown;
    OnMouseUp := @ButtonLabelMouseUp;
  end;

  Labl:=TLabel.Create(WizardForm)
  with Labl do
  begin
    Autosize := True;
    Alignment := taCenter;
    Tag := AButtonIndex;
    Transparent := True;            
    Font.Color := {#ButtonFontColor};
    Caption := AButton.Caption;
    OnClick := @ButtonLabelClick;
    OnMouseDown := @ButtonLabelMouseDown;
    OnMouseUp := @ButtonLabelMouseUp;
    OnDblClick := @ButtonLabelClick;
    Parent := Panel;
  end;
  
  ButtonLabel[AButtonIndex]:= Labl;
end;

procedure UpdateButton(AButton: TButton;AButtonIndex: integer);
begin
  ButtonPanel[AButtonIndex].Visible := AButton.Visible;
  with ButtonLabel[AButtonIndex] do
  begin
    Caption := AButton.Caption;
    Left := ButtonPanel[AButtonIndex].Width div 2 - ButtonLabel[AButtonIndex].Width div 2;
    Top := ButtonPanel[AButtonIndex].Height div 2 - ButtonLabel[AButtonIndex].Height div 2;
  end;
end;


procedure InitializeWizard();
begin
  with WizardForm do
  begin
    BackButton.Width:={#ButtonWidth};
    BackButton.Height:={#ButtonHeight};
    NextButton.Width:={#ButtonWidth};
    NextButton.Height:={#ButtonHeight};
    CancelButton.Width:={#ButtonWidth};
    CancelButton.Height:={#ButtonHeight};
    DirBrowseButton.Width:={#ButtonWidth};
    DirBrowseButton.Height:={#ButtonHeight};
    GroupBrowseButton.Width:={#ButtonWidth};
    GroupBrowseButton.Height:={#ButtonHeight};
    
    LoadButtonImage(BackButton,0);
    LoadButtonImage(NextButton,1);
    LoadButtonImage(CancelButton,2);
    LoadButtonImage(DirBrowseButton,3);
    LoadButtonImage(GroupBrowseButton,4);
  end;
end;

procedure CurPageChanged(CurPageID: Integer);  
begin
  UpdateButton(WizardForm.BackButton,0);
  UpdateButton(WizardForm.NextButton,1);
  UpdateButton(WizardForm.CancelButton,2);
  UpdateButton(WizardForm.DirBrowseButton,3);
  UpdateButton(WizardForm.GroupBrowseButton,4);
end;


текстура (положить рядом со скриптом) :

Последний раз редактировалось Johny777, 22-04-2013 в 16:15.

Это сообщение посчитали полезным следующие участники:

Отправлено: 18:40, 09-08-2012 | #579