unit uTextViewer;

interface

uses
  Windows, Messages, Classes, Controls, Forms, ExtCtrls, StdCtrls, ComCtrls,
  ToolWin, GR32_Image, SysUtils;

type
  TFormTextViewer = class(TForm)
    TextHolder: TRichEdit;
    TopImage: TImage32;
    GameIcon: TImage;
    LabelGameDescription: TLabel;
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormResize(Sender: TObject);
  private
    procedure GotoTop;
    { Private declarations }
  public
    procedure UpdateGameIcon;
    { Public declarations }
  end;

var
  FormTextViewer: TFormTextViewer;

implementation

uses uMain;

{$R *.DFM}

procedure TFormTextViewer.UpdateGameIcon;
begin
  FormMain.GetGameIcon(FormMain.IL_StandardIconsLarge, FormMain.IL_StandardIconsStandard, FormMain.IL_StandardIconsSmall, FormMain.GameInfoData.eImageIndex, GameIcon.Picture.Icon);
  GameIcon.Refresh;
end;

procedure TFormTextViewer.GotoTop;
var
  ScrollMessage: TWMVScroll;
begin
  ScrollMessage.Msg:= WM_VScroll;
  ScrollMessage.ScrollCode:= Sb_Top;
  TextHolder.Dispatch(ScrollMessage);
end;

procedure TFormTextViewer.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if ((Key = #27) or (Key = #13)) then
     Close;
end;

procedure TFormTextViewer.FormShow(Sender: TObject);
begin
  if TopImage.Tag = 0 then
     begin
       if FileExists(FormMain.FrontendPath+'resources\images\msgbox.png') then
          begin
            TopImage.Tag:= 1;
            TopImage.Bitmap.LoadFromFile(FormMain.FrontendPath+'resources\images\msgbox.png');
          end;
     end;
  if TextHolder.Font <> FormMain.MAMEInfoTextHolder.Font then
     TextHolder.Font:= FormMain.MAMEInfoTextHolder.Font;
  if TextHolder.Color <> FormMain.MAMEInfoTextHolder.Color then
     TextHolder.Color:= FormMain.MAMEInfoTextHolder.Color;
  UpdateGameIcon;
end;

procedure TFormTextViewer.FormActivate(Sender: TObject);
begin
  GotoTop;
end;

procedure TFormTextViewer.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  if FormStyle = fsStayOnTop then
     begin
       if FormMain.PopupAutomaticGameInformation.Checked then
          FormMain.PopupAutomaticGameInformation.Click;
     end;
end;

procedure TFormTextViewer.FormResize(Sender: TObject);
begin
  TextHolder.Refresh;
  LabelGameDescription.Refresh;
end;

end.
