unit ViewPartsDrawers;

interface

uses light,convImages,types,windows,Graphics,classes;

type

 THitType =(htNone,htMove,htResizeX,htResizeY,htResizeXY);


 TViewPartsDrawer=class(TObject)
 private
  FList:TStringList;
  function IsOnRect(pt:TPoint;rec:TRect):boolean;
 public
  property List:TStringList read FList write FList;
  function getSelectedSelect(loc:TPoint):Integer;
  procedure resetSelected();
 end;


implementation

(*ポイントが特定のパーツの中に存在するか*)
function TViewPartsDrawer.IsOnRect(pt:TPoint;rec:TRect):boolean;
begin
 result:=(pt.X>rec.Left)and(pt.X<rec.Right)and(pt.Y>rec.Top)and(pt.Y<rec.Bottom);
end;

(*何かのパーツをクリックしたか*)
function TViewPartsDrawer.getSelectedSelect(loc:TPoint):Integer;
var
 i:Integer;
 parts:TImageParts;
 partsRect:TRect;
begin

 for i:=0 to List.Count-1 do
 begin

  if(List.Objects[i] is TImageParts)then
  begin
   parts:=TImageParts(List.Objects[i]);
   partsRect:=Bounds(parts.x,parts.y,parts.w,parts.h);

   if(parts.selected)and(IsOnRect(loc,partsRect))then
   begin
    result:=i;
    exit;
   end;
   
  end;

 end;

 result:=-1;

end;

(*全てのパーツの選択をリセット*)
procedure TViewPartsDrawer.resetSelected();
var
 i:Integer;
 parts:TImageParts;
begin

 for i:=0 to List.Count-1 do
 begin

  if(List.Objects[i] is TImageParts)then
  begin
   parts:=TImageParts(List.Objects[i]);
   parts.selected:=false;
  end;

 end;

end;



end.

 {
 private
  hasInitImage:boolean;
 public
  backBitmap,initBitmap:TBitmap;
  adCanvas:TADCanvas;
  ImageWidth,ImageHeight:Integer;
  procedure repaintParts();
 end;

implementation



(*全パーツをイメージに描画*)
procedure TViewPartsDrawer.repaintParts();
var
 i:Integer;
 newParts:TImageParts;
begin

 if(hasInitImage)then
  backBitmap.Canvas.CopyRect
   (bounds(0,0,ImageWidth,ImageHeight),
    initBitmap.Canvas,initBitmap.Canvas.ClipRect);

  ADCanvas.Handle:=backBitmap.Canvas.Handle;

  for i:=0 to List.Count-1 do
  begin
   newparts:=TImageParts(List.Objects[i]);
   if  (newParts<>nil)then
   ADCanvas.StretchDrawEx(bounds(newparts.X,newparts.Y,
    newParts.w,newParts.h),newparts.bitmap,newParts.mode,newParts.alpha);
  end;

  releaseDC(0,adCanvas.Handle);
  adCanvas.Handle:=0;


end;

end.

