home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / DELPHIX.ZIP / Source / DXReg.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-06  |  16.2 KB  |  670 lines

  1. unit DXReg;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, SysUtils, Classes, DsgnIntf, Forms, Dialogs, Graphics, TypInfo,
  7.   DXDraws, DXSounds, DIB, Wave, DXInput, DXPlay, DXSprite, DXClass;
  8.  
  9. type
  10.  
  11.   {  TDirectDrawDisplayProperty  }
  12.  
  13.   TDirectDrawDisplayProperty = class(TClassProperty)
  14.   public
  15.     function GetAttributes: TPropertyAttributes; override;
  16.     function GetValue: string; override;
  17.     procedure GetValues(Proc: TGetStrProc); override;
  18.     procedure SetValue(const Value: string); override;
  19.   end;
  20.  
  21.   {  TDIBProperty  }
  22.  
  23.   TDIBProperty = class(TPropertyEditor)
  24.   public
  25.     procedure Edit; override;
  26.     function GetValue: string; override;
  27.     function GetAttributes: TPropertyAttributes; override;
  28.   end;
  29.  
  30.   {  TDXDIBEditor  }
  31.  
  32.   TDXDIBEditor = class(TComponentEditor)
  33.   public
  34.     procedure Edit; override;
  35.     procedure ExecuteVerb(Index: Integer); override;
  36.     function GetVerb(Index: Integer): string; override;
  37.     function GetVerbCount: Integer; override;
  38.   end;
  39.  
  40.   {  TPictureCollectionItem_PictureProperty  }
  41.  
  42.   TPictureCollectionItem_PictureProperty = class(TPropertyEditor)
  43.   public
  44.     procedure Edit; override;
  45.     function GetValue: string; override;
  46.     function GetAttributes: TPropertyAttributes; override;
  47.   end;
  48.  
  49.   {  TDXImageListEditor  }
  50.  
  51.   TDXImageListEditor = class(TComponentEditor)
  52.   public
  53.     procedure ExecuteVerb(Index: Integer); override;
  54.     function GetVerb(Index: Integer): string; override;
  55.     function GetVerbCount: Integer; override;
  56.   end;
  57.  
  58.   {  TWaveProperty  }
  59.  
  60.   TWaveProperty = class(TPropertyEditor)
  61.   public
  62.     procedure Edit; override;
  63.     function GetValue: string; override;
  64.     function GetAttributes: TPropertyAttributes; override;
  65.   end;
  66.  
  67.   {  TDXWaveEditor  }
  68.  
  69.   TDXWaveEditor = class(TComponentEditor)
  70.   public
  71.     procedure Edit; override;
  72.     procedure ExecuteVerb(Index: Integer); override;
  73.     function GetVerb(Index: Integer): string; override;
  74.     function GetVerbCount: Integer; override;
  75.   end;
  76.  
  77.   {  TDXWaveListEditor  }
  78.  
  79.   TDXWaveListEditor = class(TComponentEditor)
  80.   public
  81.     procedure ExecuteVerb(Index: Integer); override;
  82.     function GetVerb(Index: Integer): string; override;
  83.     function GetVerbCount: Integer; override;
  84.   end;
  85.  
  86.   {  TForceFeedbackEffectsProperty  }
  87.  
  88.   TForceFeedbackEffectsProperty = class(TClassProperty)
  89.   public
  90.     procedure Edit; override;
  91.     function GetValue: string; override;
  92.     function GetAttributes: TPropertyAttributes; override;
  93.   end;
  94.  
  95.   {  TDXInputEditor  }
  96.  
  97.   TDXInputEditor = class(TComponentEditor)
  98.   public
  99.     procedure Edit; override;
  100.     procedure ExecuteVerb(Index: Integer); override;
  101.     function GetVerb(Index: Integer): string; override;
  102.     function GetVerbCount: Integer; override;
  103.   end;
  104.  
  105.   {  TGUIDProperty  }
  106.  
  107.   TGUIDProperty = class(TStringProperty)
  108.   public
  109.     procedure Edit; override;
  110.     function GetAttributes: TPropertyAttributes; override;
  111.   end;
  112.  
  113. procedure Register;
  114.  
  115. implementation
  116.  
  117. uses DXPictEdit, DXWaveEdit, DXFFBEdit, DXInptEdit, DXGUIDEdit, DXConsts;
  118.  
  119. procedure Register;
  120. begin
  121.   RegisterPropertyEditor(TypeInfo(TDirectDrawDisplay), nil, '',
  122.     TDirectDrawDisplayProperty);
  123.  
  124.   RegisterPropertyEditor(TypeInfo(TDIB), nil, '', TDIBProperty);
  125.   RegisterComponentEditor(TCustomDXDIB, TDXDIBEditor);
  126.  
  127.   RegisterPropertyEditor(TypeInfo(TPicture), TPictureCollectionItem, 'Picture', TPictureCollectionItem_PictureProperty);
  128.   RegisterComponentEditor(TCustomDXImageList, TDXImageListEditor);
  129.  
  130.   RegisterPropertyEditor(TypeInfo(TWave), nil, '', TWaveProperty);
  131.   RegisterComponentEditor(TCustomDXWave, TDXWaveEditor);
  132.  
  133.   RegisterComponentEditor(TCustomDXWaveList, TDXWaveListEditor);
  134.  
  135.   RegisterPropertyEditor(TypeInfo(TForceFeedbackEffects), nil, '', TForceFeedbackEffectsProperty);
  136.  
  137.   RegisterComponentEditor(TCustomDXInput, TDXInputEditor);
  138.  
  139.   RegisterPropertyEditor(TypeInfo(string), TCustomDXPlay, 'GUID', TGUIDProperty);
  140.  
  141.   RegisterComponents('DelphiX',
  142.     [TDXDraw,
  143.     TDXDIB,
  144.     TDXImageList,
  145.     TDX3D,
  146.     TDXSound,
  147.     TDXWave,
  148.     TDXWaveList,
  149.     TDXInput,
  150.     TDXPlay,
  151.     TDXSpriteEngine,
  152.     TDXTimer,
  153.     TDXPaintBox]);
  154. end;
  155.  
  156. { TDirectDrawDisplayProperty }
  157.  
  158. function TDirectDrawDisplayProperty.GetAttributes: TPropertyAttributes;
  159. begin
  160.   Result := inherited GetAttributes + [paValueList] - [paReadOnly];
  161. end;
  162.  
  163. const
  164.   SDisplayMode = '%dx%dx%d';
  165.  
  166. function TDirectDrawDisplayProperty.GetValue: string;
  167. begin
  168.   with TDirectDrawDisplay(GetOrdValue) do
  169.     Result := Format(SDisplayMode, [Width, Height, BitCount]);
  170. end;
  171.  
  172. procedure TDirectDrawDisplayProperty.GetValues(Proc: TGetStrProc);
  173. const             
  174.   List: array[0..4] of TPoint = (
  175.   (X:  320; Y:  240),
  176.   (X:  512; Y:  384),
  177.   (X:  640; Y:  480),
  178.   (X:  800; Y:  600),
  179.   (X: 1024; Y:  768));
  180. var
  181.   BitCount, i: Integer;
  182. begin
  183.   for i:=Low(List) to High(List) do
  184.     for BitCount:=1 to 2 do
  185.       Proc(Format(SDisplayMode, [List[i].x, List[i].y, BitCount*8]));
  186. end;
  187.  
  188. procedure TDirectDrawDisplayProperty.SetValue(const Value: string);
  189. var
  190.   s: string;
  191.   i, AWidth, AHeight, ABitCount: Integer;
  192. begin
  193.   s := Value;
  194.  
  195.   i := Pos('x', s);
  196.   AWidth := StrToInt(Copy(s, 1, i-1));
  197.   s := Copy(s, i+1, Length(s));
  198.  
  199.   i := Pos('x', s);
  200.   AHeight := StrToInt(Copy(s, 1, i-1));
  201.   s := Copy(s, i+1, Length(s));
  202.  
  203.   ABitCount := StrToInt(s);
  204.  
  205.   with TDirectDrawDisplay(GetOrdValue) do
  206.   begin
  207.     Width := AWidth;
  208.     Height := AHeight;
  209.     BitCount := ABitCount;
  210.   end;
  211.  
  212.   SetOrdValue(GetOrdValue);
  213. end;
  214.  
  215. {  TDIBProperty  }
  216.  
  217. procedure TDIBProperty.Edit;
  218. var
  219.   Form: TDelphiXPictureEditForm;
  220. begin
  221.   Form := TDelphiXPictureEditForm.Create(nil);
  222.   try
  223.     Form.ViewBox.Picture.Assign(TDIB(GetOrdValue));
  224.     Form.DIBClassOnly := True;
  225.     Form.ShowModal;
  226.     if Form.Tag<>0 then
  227.     begin
  228.       SetOrdValue(Integer(Form.ViewBox.Picture.Graphic));
  229.       Designer.Modified;
  230.     end;
  231.   finally
  232.     Form.Free;
  233.   end;
  234. end;
  235.  
  236. function TDIBProperty.GetAttributes: TPropertyAttributes;
  237. begin
  238.   Result := [paDialog, paReadOnly];
  239. end;
  240.  
  241. function TDIBProperty.GetValue: string;
  242. begin
  243.   if TDIB(GetOrdValue).Size=0 then
  244.     Result := SNone
  245.   else
  246.     Result := Format('(%s)', [TObject(GetOrdValue).ClassName]);
  247. end;
  248.  
  249. {  TDXDIBEditor  }
  250.  
  251. procedure TDXDIBEditor.Edit;
  252. var
  253.   Form: TDelphiXPictureEditForm;
  254. begin
  255.   Form := TDelphiXPictureEditForm.Create(nil);
  256.   try
  257.     Form.ViewBox.Picture.Assign(TCustomDXDIB(Component).DIB);
  258.     Form.DIBClassOnly := True;
  259.     Form.ShowModal;
  260.     if Form.Tag<>0 then
  261.     begin
  262.       TCustomDXDIB(Component).DIB.Assign(TGraphic(Form.ViewBox.Picture.Graphic));
  263.       Designer.Modified;
  264.     end;
  265.   finally
  266.     Form.Free;
  267.   end;
  268. end;
  269.  
  270. procedure TDXDIBEditor.ExecuteVerb(Index: Integer);
  271. begin
  272.   case Index of
  273.     0: Edit;
  274.   end;
  275. end;
  276.  
  277. function TDXDIBEditor.GetVerb(Index: Integer): string;
  278. begin
  279.   case Index of
  280.     0: Result := SSettingImage;
  281.   end;
  282. end;
  283.  
  284. function TDXDIBEditor.GetVerbCount: Integer;
  285. begin
  286.   Result := 1;
  287. end;
  288.  
  289. {  TPictureCollectionItem_PictureProperty  }
  290.  
  291. procedure TPictureCollectionItem_PictureProperty.Edit;
  292. var
  293.   Form: TDelphiXPictureEditForm;
  294.   Item: TPictureCollectionItem;
  295.   TempDIB: TDIB;
  296. begin
  297.   Form := TDelphiXPictureEditForm.Create(nil);
  298.   try
  299.     Form.ViewBox.Picture := TPicture(GetOrdValue);
  300.     Form.ShowModal;
  301.     if Form.Tag<>0 then
  302.     begin
  303.       SetOrdValue(Integer(Form.ViewBox.Picture));
  304.  
  305.       Item := GetComponent(0) as TPictureCollectionItem;
  306.       if Item.Picture.Graphic<>nil then
  307.       begin
  308.         TempDIB := TDIB.Create;
  309.         try
  310.           TempDIB.SetSize(1, 1, 24);
  311.           TempDIB.Canvas.Draw(0, 0, Item.Picture.Graphic);
  312.           Item.TransparentColor := TempDIB.Pixels[0, 0];
  313.         finally
  314.           TempDIB.Free;
  315.         end;
  316.       end;
  317.       Designer.Modified;
  318.     end;
  319.   finally
  320.     Form.Free;
  321.   end;
  322. end;
  323.  
  324. function TPictureCollectionItem_PictureProperty.GetAttributes: TPropertyAttributes;
  325. begin
  326.   Result := [paDialog, paReadOnly];
  327. end;
  328.  
  329. function TPictureCollectionItem_PictureProperty.GetValue: string;
  330. begin
  331.   if (TPicture(GetOrdValue).Graphic=nil) or (TPicture(GetOrdValue).Graphic.Empty) then
  332.     Result := SNone
  333.   else
  334.     Result := Format('(%s)', [TPicture(GetOrdValue).Graphic.ClassName]);
  335. end;
  336.  
  337. {  TDXImageListEditor  }
  338.  
  339. procedure TDXImageListEditor.ExecuteVerb(Index: Integer);
  340. var
  341.   OpenDialog: TOpenDialog;
  342.   SaveDialog: TSaveDialog;
  343.   i: Integer;
  344. begin
  345.   case Index of
  346.     0: begin
  347.          OpenDialog := TOpenDialog.Create(nil);
  348.          try
  349.            OpenDialog.DefaultExt := 'dxg';
  350.            OpenDialog.Filter := SDXGOpenFileFilter;
  351.            OpenDialog.Options := [ofPathMustExist, ofFileMustExist, ofAllowMultiSelect];
  352.            if OpenDialog.Execute then
  353.            begin
  354.              if OpenDialog.FilterIndex=2 then
  355.              begin
  356.                for i:=0 to OpenDialog.Files.Count-1 do
  357.                  with TPictureCollectionItem.Create(TCustomDXImageList(Component).Items) do
  358.                  begin
  359.                    try
  360.                      Picture.LoadFromFile(OpenDialog.Files[i]);
  361.                      Name := ExtractFileName(OpenDialog.Files[i]);
  362.                    except
  363.                      Free;
  364.                      raise;
  365.                    end;
  366.                  end;
  367.              end else
  368.                TCustomDXImageList(Component).Items.LoadFromFile(OpenDialog.FileName);
  369.              Designer.Modified;
  370.            end;
  371.          finally
  372.            OpenDialog.Free;
  373.          end;
  374.        end;
  375.     1: begin
  376.          SaveDialog := TSaveDialog.Create(nil);
  377.          try
  378.            SaveDialog.DefaultExt := 'dxg';
  379.            SaveDialog.Filter := SDXGFileFilter;
  380.            SaveDialog.Options := [ofOverwritePrompt, ofPathMustExist];
  381.            if SaveDialog.Execute then
  382.              TCustomDXImageList(Component).Items.SaveToFile(SaveDialog.FileName);
  383.          finally
  384.            SaveDialog.Free;
  385.          end;
  386.        end;
  387.   end;
  388. end;
  389.  
  390. function TDXImageListEditor.GetVerb(Index: Integer): string;
  391. begin
  392.   case Index of
  393.     0: Result := SOpen;
  394.     1: Result := SSave;
  395.   end;
  396. end;
  397.  
  398. function TDXImageListEditor.GetVerbCount: Integer;
  399. begin
  400.   Result := 2;
  401. end;
  402.  
  403. {  TWaveProperty  }
  404.  
  405. procedure TWaveProperty.Edit;
  406. var
  407.   Form: TDelphiXWaveEditForm;
  408. begin
  409.   Form := TDelphiXWaveEditForm.Create(nil);
  410.   try
  411.     Form.Wave := TWave(GetOrdValue);
  412.     Form.ShowModal;
  413.     if Form.Tag<>0 then
  414.     begin
  415.       SetOrdValue(Integer(Form.Wave));
  416.       Designer.Modified;
  417.     end;
  418.   finally
  419.     Form.Free;
  420.   end;
  421. end;
  422.  
  423. function TWaveProperty.GetAttributes: TPropertyAttributes;
  424. begin
  425.   Result := [paDialog, paReadOnly];
  426. end;
  427.  
  428. function TWaveProperty.GetValue: string;
  429. begin
  430.   if TWave(GetOrdValue).Size=0 then
  431.     Result := SNone
  432.   else
  433.     Result := Format('(%s)', [TObject(GetOrdValue).ClassName]);
  434. end;
  435.  
  436. {  TDXWaveEditor  }
  437.  
  438. procedure TDXWaveEditor.Edit;
  439. var
  440.   Form: TDelphiXWaveEditForm;
  441. begin
  442.   Form := TDelphiXWaveEditForm.Create(nil);
  443.   try
  444.     Form.Wave := TCustomDXWave(Component).Wave;
  445.     Form.ShowModal;
  446.     if Form.Tag<>0 then
  447.     begin
  448.       TCustomDXWave(Component).Wave := Form.Wave;
  449.       Designer.Modified;
  450.     end;
  451.   finally
  452.     Form.Free;
  453.   end;
  454. end;
  455.  
  456. procedure TDXWaveEditor.ExecuteVerb(Index: Integer);
  457. begin
  458.   case Index of
  459.     0: Edit;
  460.   end;
  461. end;
  462.  
  463. function TDXWaveEditor.GetVerb(Index: Integer): string;
  464. begin
  465.   case Index of
  466.     0: Result := SSettingWave;
  467.   end;
  468. end;
  469.  
  470. function TDXWaveEditor.GetVerbCount: Integer;
  471. begin
  472.   Result := 1;
  473. end;
  474.  
  475. {  TDXWaveListEditor  }
  476.  
  477. procedure TDXWaveListEditor.ExecuteVerb(Index: Integer);
  478. var
  479.   OpenDialog: TOpenDialog;
  480.   SaveDialog: TSaveDialog;
  481.   i: Integer;
  482. begin
  483.   case Index of
  484.     0: begin
  485.          OpenDialog := TOpenDialog.Create(nil);
  486.          try
  487.            OpenDialog.DefaultExt := 'dxw';
  488.            OpenDialog.Filter := SDXWOpenFileFilter;
  489.            OpenDialog.Options := [ofPathMustExist, ofFileMustExist, ofAllowMultiSelect];
  490.            if OpenDialog.Execute then
  491.            begin
  492.              if OpenDialog.FilterIndex=2 then
  493.              begin
  494.                for i:=0 to OpenDialog.Files.Count-1 do
  495.                  with TWaveCollectionItem.Create(TCustomDXWaveList(Component).Items) do
  496.                  begin
  497.                    try
  498.                      Wave.LoadFromFile(OpenDialog.Files[i]);
  499.                      Name := ExtractFileName(OpenDialog.Files[i]);
  500.                    except
  501.                      Free;
  502.                      raise;
  503.                    end;
  504.                  end;
  505.              end else
  506.                TCustomDXWaveList(Component).Items.LoadFromFile(OpenDialog.FileName);
  507.              Designer.Modified;
  508.            end;
  509.          finally
  510.            OpenDialog.Free;
  511.          end;
  512.        end;
  513.     1: begin
  514.          SaveDialog := TSaveDialog.Create(nil);
  515.          try
  516.            SaveDialog.DefaultExt := 'dxw';
  517.            SaveDialog.Filter := SDXWFileFilter;
  518.            SaveDialog.Options := [ofOverwritePrompt, ofPathMustExist];
  519.            if SaveDialog.Execute then
  520.              TCustomDXWaveList(Component).Items.SaveToFile(SaveDialog.FileName);
  521.          finally
  522.            SaveDialog.Free;
  523.          end;
  524.        end;
  525.   end;
  526. end;
  527.  
  528. function TDXWaveListEditor.GetVerb(Index: Integer): string;
  529. begin
  530.   case Index of
  531.     0: Result := SOpen;
  532.     1: Result := SSave;
  533.   end;
  534. end;
  535.  
  536. function TDXWaveListEditor.GetVerbCount: Integer;
  537. begin
  538.   Result := 2;
  539. end;
  540.  
  541. {  TForceFeedbackEffectsProperty  }
  542.  
  543. procedure TForceFeedbackEffectsProperty.Edit;
  544. var
  545.   Form: TDelphiXFFEditForm;
  546.   Effects: TForceFeedbackEffects;
  547. begin
  548.   Effects := TForceFeedbackEffects(GetOrdValue);
  549.  
  550.   Form := TDelphiXFFEditForm.Create(nil);
  551.   try
  552.     if Effects.Input is TJoystick then
  553.       Form.Effects := Form.DXInput.Joystick.Effects
  554.     else if Effects.Input is TKeyboard then
  555.       Form.Effects := Form.DXInput.Keyboard.Effects
  556.     else Exit;
  557.  
  558.     Form.Effects.Assign(TForceFeedbackEffects(GetOrdValue));
  559.     Form.ShowModal;
  560.     if Form.Tag<>0 then
  561.     begin
  562.       SetOrdValue(Integer(Form.Effects));
  563.       Designer.Modified;
  564.     end;
  565.   finally
  566.     Form.Free;
  567.   end;
  568. end;
  569.  
  570. function TForceFeedbackEffectsProperty.GetAttributes: TPropertyAttributes;
  571. begin
  572.   Result := [paDialog, paReadOnly];
  573. end;
  574.  
  575. function TForceFeedbackEffectsProperty.GetValue: string;
  576. begin
  577.   if TForceFeedbackEffects(GetOrdValue).Count=0 then
  578.     Result := SNone
  579.   else
  580.     Result := Format('(%s)', [TObject(GetOrdValue).ClassName]);
  581. end;
  582.  
  583. {  TDXInputEditor  }
  584.  
  585. procedure TDXInputEditor.Edit;
  586. var
  587.   Form: TDelphiXInputEditForm;
  588. begin
  589.   Form := TDelphiXInputEditForm.Create(nil);
  590.   try
  591.     Form.DXInput := TCustomDXInput(Component);
  592.     Form.ShowModal;
  593.     if Form.Tag<>0 then
  594.       Designer.Modified;
  595.   finally
  596.     Form.Free;
  597.   end;
  598. end;
  599.  
  600. procedure TDXInputEditor.ExecuteVerb(Index: Integer);
  601. begin
  602.   case Index of
  603.     0: begin
  604.          with TCustomDXInput(Component) do
  605.          begin
  606.            Joystick.ID := 0;
  607.            Keyboard.KeyAssigns := DefKeyAssign;
  608.          end;
  609.          Designer.Modified;
  610.        end;
  611.     1: begin
  612.          with TCustomDXInput(Component) do
  613.          begin
  614.            Joystick.ID := 0;
  615.            Keyboard.KeyAssigns := DefKeyAssign2_1;
  616.          end;
  617.          Designer.Modified;
  618.        end;
  619.     2: begin
  620.          with TCustomDXInput(Component) do
  621.          begin
  622.            Joystick.ID := 1;
  623.            Keyboard.KeyAssigns := DefKeyAssign2_2;
  624.          end;
  625.          Designer.Modified;
  626.        end;
  627.   end;
  628. end;
  629.  
  630. function TDXInputEditor.GetVerb(Index: Integer): string;
  631. begin
  632.   case Index of
  633.     0: Result := SSinglePlayer;
  634.     1: Result := SMultiPlayer1;
  635.     2: Result := SMultiPlayer2;
  636.   end;
  637. end;
  638.  
  639. function TDXInputEditor.GetVerbCount: Integer;
  640. begin
  641.   Result := 3;
  642. end;
  643.  
  644. {  TGUIDProperty  }
  645.  
  646. procedure TGUIDProperty.Edit;
  647. var
  648.   Form: TDelphiXGUIDEditForm;
  649. begin
  650.   Form := TDelphiXGUIDEditForm.Create(nil);
  651.   try
  652.     Form.GUID := GetStrValue;
  653.     Form.ShowModal;
  654.     if Form.Tag<>0 then
  655.     begin
  656.       SetStrValue(Form.GUID);
  657.       Designer.Modified;
  658.     end;
  659.   finally
  660.     Form.Free;
  661.   end;
  662. end;
  663.  
  664. function TGUIDProperty.GetAttributes: TPropertyAttributes;
  665. begin
  666.   Result := inherited GetAttributes + [paDialog];
  667. end;
  668.  
  669. end.
  670.