⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 videooptions.pas

📁 一个不出名的GBA模拟器
💻 PAS
字号:
//////////////////////////////////////////////////////////////////////
//                                                                  //
// VideoOptions.pas: Video Options Dialog                           //
//                                                                  //
// The contents of this file are subject to the Bottled Light       //
// Public License Version 1.0 (the "License"); you may not use this //
// file except in compliance with the License. You may obtain a     //
// copy of the License at http://www.bottledlight.com/BLPL/         //
//                                                                  //
// Software distributed under the License is distributed on an      //
// "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or   //
// implied. See the License for the specific language governing     //
// rights and limitations under the License.                        //
//                                                                  //
// The Original Code is the Mappy VM User Interface, released       //
// April 1st, 2003. The Initial Developer of the Original Code is   //
// Bottled Light, Inc. Portions created by Bottled Light, Inc. are  //
// Copyright (C) 2001-2003 Bottled Light, Inc. All Rights Reserved. //
//                                                                  //
// Author(s):                                                       //
//   Michael Noland (joat), michael@bottledlight.com                //
//                                                                  //
// Changelog:                                                       //
//   1.0: First public release (April 1st, 2003)                    //
//                                                                  //
// Notes:                                                           //
//   None at present.                                               //
//                                                                  //
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
unit VideoOptions; ///////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
interface ////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IniFiles, ExtCtrls, ComCtrls,
  CpuObservers, platformVideo, nexus, Math, Spin;

//////////////////////////////////////////////////////////////////////

type
  TVideoOptionsDialog = class(TCpuObserver)
    orientationGroup: TRadioGroup;
    curveGroup: TGroupBox;
    bResetCurve: TButton;
    bLoadCurve: TButton;
    bSaveCurveAs: TButton;
    curveSelect: TTabControl;
    curve: TImage;
    effectsGroup: TGroupBox;
    fxShowGrid: TCheckBox;
    fxSplitRGB: TCheckBox;
    syncGroup: TGroupBox;
    doFramerateLimit: TCheckBox;
    lPercentIdeal: TLabel;
    screenSizeGroup: TGroupBox;
    screenSizes: TListBox;
    switchVideoMode: TButton;
    openDialog: TOpenDialog;
    saveDialog: TSaveDialog;
    param1: TTrackBar;
    lParam1: TLabel;
    bResetSize: TButton;
    percentIdeal: TSpinEdit;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure toggleSplitRGB(Sender: TObject);
    procedure toggleShowGrid(Sender: TObject);
    procedure changeOrientation(Sender: TObject);
    procedure toggleFramerateLimit(Sender: TObject);
    procedure curveMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure curveMouseClick(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure ResetCurve(Sender: TObject);
    procedure LoadCurve(Sender: TObject);
    procedure SaveCurve(Sender: TObject);
    procedure percentIdealChange(Sender: TObject);
    procedure ParametricGeneration(Sender: TObject);
    procedure bResetSizeClick(Sender: TObject);
  private
    procedure redrawCurve;
    procedure SetRampCaption;
  public
    procedure UpdateObserver; override;
    class function OCaption: string; override;
    procedure LoadSettings(ini: TIniFile); override;
    procedure SaveSettings(ini: TIniFile); override;
  end;

//////////////////////////////////////////////////////////////////////

procedure LoadVideoOptions(ini: TIniFile);
procedure SaveVideoOptions(ini: TIniFile);

//////////////////////////////////////////////////////////////////////
implementation ///////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

{$R *.DFM}

//////////////////////////////////////////////////////////////////////

var
  rampFilename: string;

//////////////////////////////////////////////////////////////////////

procedure ReloadRamp;
var
  stream: TFileStream;
  i: integer;
  temp: byte;
begin
  if FileExists(rampFilename) then begin
    stream := TFileStream.Create(rampFilename, fmOpenRead);
    for i := 0 to 31 do begin
      stream.Read(temp, 1);  writeRampEntry(0, i, temp);
      stream.Read(temp, 1);  writeRampEntry(1, i, temp);
      stream.Read(temp, 1);  writeRampEntry(2, i, temp);
    end;
    stream.Free;
    InvalidateRamp;
  end;
end;

//////////////////////////////////////////////////////////////////////
// TVideoOptionsDialog ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.FormCreate(Sender: TObject);
begin
  HelpContext := LinkHelp('video_options.html');
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.FormShow(Sender: TObject);
begin
  // Synchroization
  if msBetweenFrames = 0 then begin
    percentIdeal.Value := 100;
    doFramerateLimit.checked := false;
  end else begin
    percentIdeal.Value := Min(1000, Max(10, Trunc((1000*100/msBetweenFrames)/59.727)));
    doFramerateLimit.checked := true;
  end;

  // Orientation
  orientationGroup.ItemIndex := Ord(renderRotationMode);

  // Special effects
  fxSplitRGB.Checked := renderSplitRGB;
  fxShowGrid.Checked := renderShowGrid;

  // Screen size

  // Ramp
  SetRampCaption;
  redrawCurve;

  // Load the translation
  LoadTranslation(self, translation);
  lParam1.Caption := 'Darkness: 1.00';
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.toggleSplitRGB(Sender: TObject);
begin
  renderSplitRGB := fxSplitRGB.Checked;
  InitRenderModes;
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.toggleShowGrid(Sender: TObject);
begin
  renderShowGrid := fxShowGrid.Checked;
  InitRenderModes;
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.changeOrientation(Sender: TObject);
begin
  case orientationGroup.ItemIndex of
    0: renderRotationMode := rm0;
    1: renderRotationMode := rm90;
    2: renderRotationMode := rm180;
    3: renderRotationMode := rm270;
  end;

  InitRenderModes;
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.toggleFramerateLimit(Sender: TObject);
begin
  percentIdeal.Enabled := doFramerateLimit.checked;
  lPercentIdeal.Enabled := doFramerateLimit.checked;
  percentIdealChange(Sender);
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.curveMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  x := x div 8;
  y := 256 - y;
  if (x >= 0) and (x < 32) and (y >= 0) and (y < 255) and (ssLeft in Shift) then begin
    case curveSelect.TabIndex of
      0: Exit;
      1: writeRampEntry(0, x, y);
      2: writeRampEntry(1, x, y);
      3: writeRampEntry(2, x, y);
    end;

    rampFilename := '';
    SetRampCaption;
    redrawCurve;
    InvalidateRamp;
  end;
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.redrawCurve;
var
  i: integer;
begin
  curve.Canvas.Brush.Color := clWhite;
  curve.Canvas.FillRect(Rect(0, 0, 264, 256));
  //curve.Canvas.FillRect(Rect(x*8-4, 0, x*8+12, 256));

  curve.Canvas.Pen.Color := clRed;
  curve.Canvas.MoveTo(4, 256-readRampEntry(0, 0));
  for i := 0 to 31 do
    curve.Canvas.LineTo(i*8+4, 256-readRampEntry(0, i));

  curve.Canvas.Pen.Color := clGreen;
  curve.Canvas.MoveTo(4, 256-readRampEntry(1, 0));
  for i := 0 to 31 do
    curve.Canvas.LineTo(i*8+4, 256-readRampEntry(1, i));

  curve.Canvas.Pen.Color := clBlue;
  curve.Canvas.MoveTo(4, 256-readRampEntry(2, 0));
  for i := 0 to 31 do
    curve.Canvas.LineTo(i*8+4, 256-readRampEntry(2, i));
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.curveMouseClick(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  curveMouseMove(Sender, Shift, X, Y);
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.ResetCurve(Sender: TObject);
begin
  rampFilename := '';
  videoResetRamp;

  SetRampCaption;
  redrawCurve;
  InvalidateRamp;
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.LoadCurve(Sender: TObject);
begin
  openDialog.InitialDir := ExtractFilePath(ParamStr(0));
  openDialog.FileName := rampFilename;
  if openDialog.Execute then begin
    rampFilename := openDialog.FileName;
    ReloadRamp;
    SetRampCaption;
    redrawCurve;
  end;
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.SaveCurve(Sender: TObject);
var
  stream: TFileStream;
  i: integer;
  temp: byte;
begin
  saveDialog.InitialDir := ExtractFilePath(ParamStr(0));
  saveDialog.FileName := rampFilename;
  if saveDialog.Execute then begin
    stream := TFileStream.Create(saveDialog.Filename, fmCreate);
    for i := 0 to 31 do begin
      temp := readRampEntry(0, i);  stream.Write(temp, 1);
      temp := readRampEntry(1, i);  stream.Write(temp, 1);
      temp := readRampEntry(2, i);  stream.Write(temp, 1);
    end;
    stream.Free;

    rampFilename := saveDialog.FileName;
    SetRampCaption;
    redrawCurve;
    InvalidateRamp;
  end;
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.SetRampCaption;
begin
  if FileExists(rampFilename) then
    curveGroup.Caption := ' Color Callibration [' + ExtractFileName(rampFilename) + ']'
  else begin
    curveGroup.Caption := ' Color Callibration [custom curve]';
    rampFilename := '';
  end;
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.percentIdealChange(Sender: TObject);
begin
  if percentIdeal.Enabled then
    msBetweenFrames := Trunc(1000/(59.727*percentIdeal.Value/100.0))
  else
    msBetweenFrames := 0;
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.LoadSettings(ini: TIniFile);
begin
  inherited;
end;

//////////////////////////////////////////////////////////////////////

class function TVideoOptionsDialog.OCaption: string;
begin
  Result := 'Video Options';
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.SaveSettings(ini: TIniFile);
begin
  inherited;
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.UpdateObserver;
begin
//
end;

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

procedure StringToRamp(st: string);
var
  i: integer;
begin
  if Length(st) <> 192 then
    videoResetRamp
  else for i := 0 to 31 do begin
    writeRampEntry(0, i, StrToInt('$' + Copy(st, i*6+1, 2)));
    writeRampEntry(1, i, StrToInt('$' + Copy(st, i*6+3, 2)));
    writeRampEntry(2, i, StrToInt('$' + Copy(st, i*6+5, 2)));
  end;
end;

//////////////////////////////////////////////////////////////////////

function RampToString: string;
var
  i: integer;
begin
  Result := '';
  for i := 0 to 31 do begin
    Result := Result + IntToHex(readRampEntry(0, i), 2) +
                       IntToHex(readRampEntry(1, i), 2) +
                       IntToHex(readRampEntry(2, i), 2);
  end;
end;

//////////////////////////////////////////////////////////////////////

procedure LoadVideoOptions(ini: TIniFile);
begin
  msBetweenFrames := ini.ReadInteger('Video Options', 'ForcedDelay', 0);

  renderRotationMode := TRotationMode(ini.ReadInteger('Video Options', 'Rotation', Ord(rm0)));
  renderSplitRGB := ini.ReadBool('Video Options', 'SplitRGB', false);
  renderShowGrid := ini.ReadBool('Video Options', 'ShowGrid', false);
  InitRenderModes;

  rampFilename := ini.ReadString('Video Options', 'RampFilename', '');
  if FileExists(rampFilename) then
    ReloadRamp
  else begin
    StringToRamp(ini.ReadString('Video Options', 'RampData', ''));
    InvalidateRamp;
  end;
end;

//////////////////////////////////////////////////////////////////////

procedure SaveVideoOptions(ini: TIniFile);
begin
  ini.WriteInteger('Video Options', 'ForcedDelay', msBetweenFrames);
  ini.WriteBool('Video Options', 'SplitRGB', renderSplitRGB);
  ini.WriteBool('Video Options', 'ShowGrid', renderShowGrid);
  ini.WriteString('Video Options', 'RampFilename', rampFilename);
  ini.WriteString('Video Options', 'RampData', RampToString);
  ini.WriteInteger('Video Options', 'Rotation', Ord(renderRotationMode));
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.ParametricGeneration(Sender: TObject);
var
  f1: single;
  i, t: byte;
begin
  f1 := (param1.Position / (100.0/5.0)); 
  lParam1.Caption := Format('Darkness: %.2f', [f1]);

  // ErrorDocument 404 /error/404.html
//[00:31] <SlasherX> append that to your .htaccess or httpd.conf joat

  for i := 0 to 31 do begin
    t := Trunc(Min(Max(Power((i/31), f1)*255, 0), 255));
    writeRampEntry(0, i, t);
    writeRampEntry(1, i, t);
    writeRampEntry(2, i, t);
  end;

  rampFilename := '';
  SetRampCaption;
  redrawCurve;
  InvalidateRamp;
end;

//////////////////////////////////////////////////////////////////////

procedure TVideoOptionsDialog.bResetSizeClick(Sender: TObject);
begin
  InitRenderModes;
end;

//////////////////////////////////////////////////////////////////////

initialization
  RegisterDialog(TVideoOptionsDialog);
end.

//////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -