X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Feditor%2Ff_addresource_texture.pas;h=13adf3cb958db9f2fe163717b8c574df7eb5b53c;hb=4cd27745126226e5e57a02f4c2a44ccbab16bbac;hp=1402b13328d1469f0033c5112bc7aced072c49cb;hpb=f622519cf9e20cee299cc331d35ef158bb1cb72f;p=d2df-editor.git diff --git a/src/editor/f_addresource_texture.pas b/src/editor/f_addresource_texture.pas index 1402b13..13adf3c 100644 --- a/src/editor/f_addresource_texture.pas +++ b/src/editor/f_addresource_texture.pas @@ -5,12 +5,16 @@ unit f_addresource_texture; interface uses - LCLIntf, LCLType, LMessages, SysUtils, Variants, Classes, + LCLIntf, LCLType, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, f_addresource, StdCtrls, ExtCtrls, utils, Imaging, ImagingTypes, ImagingUtility; type + + { TAddTextureForm } + TAddTextureForm = class (TAddResourceForm) + lStats: TLabel; PanelTexPreview: TPanel; iPreview: TImage; eTextureName: TEdit; @@ -35,6 +39,7 @@ type var AddTextureForm: TAddTextureForm; + NumFrames: Integer = 0; function IsAnim(Res: String): Boolean; function GetFrame(Res: String; var Data: Pointer; var DataLen: Integer; @@ -64,6 +69,8 @@ var begin Result := False; + Data := nil; + Size := 0; // Читаем файл и ресурс в нем: g_ProcessResourceStr(Res, WADName, SectionName, ResourceName); @@ -71,7 +78,7 @@ begin WAD := TWADEditor_1.Create(); if (not WAD.ReadFile(WADName)) or - (not WAD.GetResource(SectionName, ResourceName, Data, Size)) then + (not WAD.GetResource(utf2win(SectionName), utf2win(ResourceName), Data, Size)) then begin WAD.Free(); Exit; @@ -140,7 +147,7 @@ begin Exit; end; -// Ищем в них описание анимации - "AINM": +// Ищем в них описание анимации - "ANIM": ok := False; for a := 0 to High(Resources) do if Resources[a] = 'ANIM' then @@ -155,8 +162,7 @@ begin Result := ok; end; -function GetFrame(Res: String; var Data: Pointer; var DataLen: Integer; - var Width, Height: Word): Boolean; +function GetFrame(Res: String; var Data: Pointer; var DataLen: Integer; var Width, Height: Word): Boolean; var AnimWAD: Pointer; WAD: TWADEditor_1; @@ -169,6 +175,9 @@ var begin Result := False; + AnimWAD := nil; + Len := 0; + TextData := nil; // Читаем WAD: g_ProcessResourceStr(Res, WADName, SectionName, ResourceName); @@ -182,12 +191,12 @@ begin end; // Читаем WAD-ресурс из WAD: - if not WAD.GetResource(SectionName, ResourceName, AnimWAD, Len) then + if not WAD.GetResource(utf2win(SectionName), utf2win(ResourceName), AnimWAD, Len) then begin WAD.Free(); Exit; end; - + WAD.FreeWAD(); // Читаем WAD в WAD'е: @@ -232,59 +241,51 @@ begin Result := True; end; -function CreateBitMap(Data: Pointer; DataSize: Cardinal): TBitMap; +function CreateBitMap (Data: Pointer; DataSize: Cardinal): TBitMap; var - img: TImageData; - clr: TColor32Rec; - bgc: Byte; - ii: PByte; - Width, - Height: Integer; - ColorDepth: Integer; - ImageSize: Integer; - i, x, y: Integer; - BitMap: TBitMap; - + img: TImageData; + clr, bgc: TColor32Rec; + Width, Height: Integer; + x, y: Integer; + BitMap: TBitMap; begin Result := nil; - InitImage(img); if not LoadImageFromMemory(Data, DataSize, img) then Exit; Width := img.width; Height := img.height; - ColorDepth := 24; - ImageSize := Width*Height*(ColorDepth div 8); - BitMap := TBitMap.Create(); - BitMap.PixelFormat := pf24bit; - + BitMap.PixelFormat := pf24bit; BitMap.Width := Width; BitMap.Height := Height; - -// Копируем в BitMap: - ii := BitMap.RawImage.Data; - for y := 0 to height-1 do + for y := 0 to Height - 1 do begin - for x := 0 to width-1 do + for x := 0 to Width - 1 do begin clr := GetPixel32(img, x, y); // HACK: Lazarus's TBitMap doesn't seem to have a working 32 bit mode, so // mix color with checkered background. Also, can't really read // CHECKERS.tga from here. FUCK! - if (((x shr 3) and 1) = 0) xor (((y shr 3) and 1) = 0) then - bgc := 255 + if UseCheckerboard then + begin + if (((x shr 3) and 1) = 0) xor (((y shr 3) and 1) = 0) then + bgc.Color := $FDFDFD + else + bgc.Color := $CBCBCB + end else - bgc := 200; - clr.r := ClampToByte(((255 - clr.a) * bgc + clr.a * clr.r) div 255); - clr.g := ClampToByte(((255 - clr.a) * bgc + clr.a * clr.g) div 255); - clr.b := ClampToByte(((255 - clr.a) * bgc + clr.a * clr.b) div 255); - // TODO: check for RGB/BGR somehow? - ii^ := clr.b; Inc(ii); - ii^ := clr.g; Inc(ii); - ii^ := clr.r; Inc(ii); - end; + begin + bgc.r := GetRValue(PreviewColor); + bgc.g := GetGValue(PreviewColor); + bgc.b := GetBValue(PreviewColor) + end; + clr.r := ClampToByte((Byte(255 - clr.a) * bgc.r + clr.a * clr.r) div 255); + clr.g := ClampToByte((Byte(255 - clr.a) * bgc.g + clr.a * clr.g) div 255); + clr.b := ClampToByte((Byte(255 - clr.a) * bgc.b + clr.a * clr.b) div 255); + BitMap.Canvas.Pixels[x, y] := RGBToColor(clr.r, clr.g, clr.b) + end end; FreeImage(img); Result := BitMap; @@ -301,16 +302,20 @@ var config: TConfig; TextData: Pointer; TextureData: Pointer; - + begin Result := nil; + AnimWAD := nil; + Len := 0; + TextData := nil; + TextureData := nil; // Читаем WAD файл и ресурс в нем: g_ProcessResourceStr(Res, WADName, SectionName, ResourceName); WAD := TWADEditor_1.Create(); WAD.ReadFile(WADName); - WAD.GetResource(SectionName, ResourceName, AnimWAD, Len); + WAD.GetResource(utf2win(SectionName), utf2win(ResourceName), AnimWAD, Len); WAD.FreeWAD(); // Читаем описание анимации: @@ -321,18 +326,19 @@ begin // Читаем лист текстур: WAD.GetResource('TEXTURES', config.ReadStr('', 'resource', ''), TextureData, Len); + NumFrames := config.ReadInt('', 'framecount', 0); if (TextureData <> nil) and (WAD.GetLastError = DFWAD_NOERROR) then begin // Создаем BitMap из листа текстур: Result := CreateBitMap(TextureData, Len); - + // Размеры одного кадра - виден только первый кадр: Result.Height := config.ReadInt('', 'frameheight', 0); Result.Width := config.ReadInt('', 'framewidth', 0); end; - + config.Free(); WAD.Free(); @@ -352,6 +358,8 @@ var begin Result := nil; + TextureData := nil; + Len := 0; // Читаем WAD: g_ProcessResourceStr(ResourceStr, WADName, SectionName, ResourceName); @@ -364,7 +372,7 @@ begin end; // Читаем ресурс текстуры в нем: - WAD.GetResource(SectionName, ResourceName, TextureData, Len); + WAD.GetResource(utf2win(SectionName), utf2win(ResourceName), TextureData, Len); WAD.Free(); @@ -378,7 +386,8 @@ procedure TAddTextureForm.FormActivate(Sender: TObject); begin Inherited; - cbWADList.Items.Add(_lc[I_WAD_SPECIAL_TEXS]); + lStats.Caption := ''; + cbWADList.Items.Add(MsgWadSpecialTexs); eTextureName.Text := ''; iPreview.Canvas.FillRect(iPreview.Canvas.ClipRect); @@ -391,28 +400,37 @@ procedure TAddTextureForm.lbResourcesListClick(Sender: TObject); var Texture: TBitMap; wad: String; + Anim: Boolean; begin Inherited; + lStats.Caption := ''; if lbResourcesList.ItemIndex = -1 then Exit; if FResourceName = '' then Exit; - if cbWADList.Text = _lc[I_WAD_SPECIAL_TEXS] then + if cbWADList.Text = MsgWadSpecialTexs then Exit; g_ProcessResourceStr(FFullResourceName, @wad, nil, nil); - if wad = _lc[I_WAD_SPECIAL_TEXS] then + if wad = MsgWadSpecialTexs then Exit; - if IsAnim(FFullResourceName) then + Anim := IsAnim(FFullResourceName); + if Anim then Texture := ShowAnim(FFullResourceName) else Texture := ShowTGATexture(FFullResourceName); if Texture = nil then Exit; + + if Anim then + lStats.Caption := Format(MsgCapAnimation, [Texture.Width, Texture.Height, NumFrames]) + else + lStats.Caption := Format(MsgCapTexture, [Texture.Width, Texture.Height]); + iPreview.Canvas.FillRect(iPreview.Canvas.ClipRect); iPreview.Canvas.CopyRect(Texture.Canvas.ClipRect, Texture.Canvas, Texture.Canvas.ClipRect); Texture.Free(); @@ -455,7 +473,7 @@ end; procedure TAddTextureForm.cbWADListChange(Sender: TObject); begin - if cbWADList.Text = _lc[I_WAD_SPECIAL_TEXS] then + if cbWADList.Text = MsgWadSpecialTexs then begin cbSectionsList.Clear(); cbSectionsList.Items.Add('..'); @@ -467,7 +485,7 @@ end; procedure TAddTextureForm.cbSectionsListChange(Sender: TObject); begin - if cbWADList.Text = _lc[I_WAD_SPECIAL_TEXS] then + if cbWADList.Text = MsgWadSpecialTexs then begin lbResourcesList.Clear(); lbResourcesList.Items.Add(TEXTURE_NAME_WATER); @@ -492,8 +510,8 @@ begin for i := 0 to lbResourcesList.Count-1 do if lbResourcesList.Selected[i] then begin - AddTexture(utf2win(cbWADlist.Text), utf2win(cbSectionsList.Text), - utf2win(lbResourcesList.Items[i]), False); + AddTexture(cbWADlist.Text, cbSectionsList.Text, + lbResourcesList.Items[i], False); lbResourcesList.Selected[i] := False; end; end;