OSDN Git Service

TPicture instance is cached
authornaru <bottle@mikage.to>
Sat, 19 Apr 2003 23:56:55 +0000 (23:56 +0000)
committernaru <bottle@mikage.to>
Sat, 19 Apr 2003 23:56:55 +0000 (23:56 +0000)
SVG.dpr

diff --git a/SVG.dpr b/SVG.dpr
index 11c79a5..5e44071 100644 (file)
--- a/SVG.dpr
+++ b/SVG.dpr
@@ -20,6 +20,9 @@ var
   GhostFile: String;
   Ghost2File: TStringList;
 
+  Pic: TPicture;       // \93Ç\82Ý\8eæ\82Á\82½\89æ\91\9c(*.png, *.bmp, *.jpg)
+  PicFileName: String; // \82»\82Ì\83t\83@\83C\83\8b\96¼
+
 // DLL\83\8d\81[\83h\8e\9e\81A\82¨\82æ\82ÑDLL\8dÄ\8f\89\8aú\89»\8e\9e\82É\8cÄ\82Î\82ê\82é\81B
 // \93Ç\82Ý\8d\9e\82Ü\82ê\82½\89æ\91\9c\82Í\81ABottle Client\91¤\82Å\81u\83T\81[\83t\83B\83X\8dÄ\93Ç\82Ý\8d\9e\82Ý\81v\82ð
 // \96¾\8e¦\93I\82É\8ew\92è\82³\82ê\82È\82¢\8cÀ\82è\82Í Bottle Client \91¤\82Å\83L\83\83\83b\83V\83\85\82³\82ê\82é\82Ì\82Å\81A
@@ -39,6 +42,8 @@ begin
   if not FileExists(GhostFile) then
     ShowMessage('SVG.dll Warning: Ghost file is not specified');
   Ghost2File := TStringList.Create;
+  Pic := TPicture.Create;
+  PicFileName := '';
 end;
 
 // DLL\83A\83\93\83\8d\81[\83h\8e\9e\82É\8cÄ\82Î\82ê\82é\81B
@@ -46,6 +51,7 @@ end;
 procedure Unload; cdecl;
 begin
   Ghost2File.Free;
+  Pic.Free;
 end;
 
 // DLL\82Ì\96¼\91O\82¨\82æ\82Ñ\83o\81[\83W\83\87\83\93\82ð\95Ô\82·\81B
@@ -57,7 +63,7 @@ end;
 // CanConfigure\82Í\81AConfigure\82ð\8cÄ\82Î\82ê\82Ä\82â\82é\82±\82Æ\82ª\82 \82é\82©\82Ç\82¤\82©\82ð\95Ô\82·\81B
 function GetVersion(DLLName: PChar; NameLen: integer;
   var Version: integer; var CanConfigure: boolean): integer; cdecl;
-const ThisDLL = 'SVG Surface Loader Ver. 2.0';
+const ThisDLL = 'SVG Surface Loader Ver. 2.1';
 begin
   Version := 1;
   CanConfigure := true;
@@ -309,7 +315,6 @@ end;
 // H\82Å\8ew\92è\82³\82ê\82Ä\82¢\82é\83r\83b\83g\83}\83b\83v\82É\8f\91\82«\8fo\82·\82±\82Æ\81B
 function GetImage(Ghost: PChar; Surface: integer; H: HBITMAP): integer; cdecl;
 var Bmp: TBitmap;
-    Pic: TPicture;
     BmpFile: String;
     Position, x, y, nCol: integer;
 begin
@@ -320,34 +325,34 @@ begin
       Result := 1;
       Exit;
     end;
-  except
-    on Exception do // \83t\83@\83C\83\8b\82ª\8c©\82Â\82©\82Á\82Ä\82È\82¢\89Â\94\\90«\82ª\82à\82Á\82Æ\82à\8d\82\82¢
-    begin
-      Result := 1;
-      Exit;
-    end;
-  end;
-
-  OutputDebugString(PChar(BmpFile + ' : ' + IntToStr(Position)));
-  //ShowMessage(BmpFile + ':' + IntToSTr(Position));
-  Bmp := TBitmap.Create;
-  try
-    Bmp.Handle := H;
-    Pic := TPicture.Create;
+    Bmp := TBitmap.Create;
     try
-      Pic.LoadFromFile(BmpFile);
+      Bmp.Handle := H;
+      if PicFileName <> BmpFile then
+      begin
+        try
+          Pic.LoadFromFile(BmpFile);
+          PicFileName := BmpFile;
+        except
+          // \8dì\82è\92¼\82µ
+          FreeAndNil(Pic);
+          Pic := TPicture.Create;
+          PicFileName := '';
+          raise;
+        end;
+      end;
       nCol := Pic.Width div SurfaceWidth;
       x := SurfaceWidth * (Position mod nCol);
       y := SurfaceHeight * (Position div nCol);
       Bmp.Canvas.Draw(-x, -y, Pic.Graphic);
     finally
-      Pic.Free;
+      Bmp.ReleaseHandle;
+      Bmp.Free;
     end;
-  finally
-    Bmp.ReleaseHandle;
-    Bmp.Free;
+    Result := 0;
+  except
+    Result := 1;
   end;
-  Result := 0;
 end;
 
 // \83C\83\81\81[\83W\82Ì\91å\82«\82³\82ð\95Ô\82·\81B