日別アーカイブ: 2014年5月7日

CopyFromBitmap, DrawBitmap がうまくいなないので

CopyFromBitmap, DrawBitmap がうまくいなないので、とりあえずの苦肉の策




procedure TBoard.DrawAllTiles;
var
  i, j, k: Integer;
  tmpTileListIndex: Integer;
  tmpBitmap: TBitmap;
  tmpPatternName: String;
  tmpTileBitmap: TBitmap;
  tmpSelectedBitmap: TBitmap;
  tmpRect: TRect;
begin
  tmpBitmap := TBitmap.Create(BoardWidth, BoardHeight);
  tmpBitmap.Clear($0);
  tmpBitmap.Canvas.BeginScene;

  for k := GameController.TileManager.Grid3D.ZMin to GameController.TileManager.Grid3D.ZMax do
    for i := GameController.TileManager.Grid3D.XMin to GameController.TileManager.Grid3D.XMax do
      for j := GameController.TileManager.Grid3D.YMin to GameController.TileManager.Grid3D.YMax do
      begin
        tmpTileListIndex := GameController.TileManager.Grid3D[i,j,k];
        if tmpTileListIndex <> VALUE_OF_TILE_EMPTY then
        begin
          tmpPatternName := 'animal' + IntToStr(GameController.TileManager.TileList[tmpTileListIndex].KindSerial);
          tmpTileBitmap := frmASMain.ImageManager.Item(tmpPatternName);
          tmpRect := Pos3DToAreaRect(GameController.TileManager.TileList[tmpTileListIndex].Pos3D);

          tmpBitmap.Canvas.DrawBitmap(tmpTileBitmap,
                                      RectF(0,
                                            0,
                                            tmpTileBitmap.Width,
                                            tmpTileBitmap.Height),
                                      RectF(tmpRect.Left,
                                            tmpRect.Top,
                                            tmpRect.Right,
                                            tmpRect.Bottom),
                                      1);

          if GameController.TileManager.TileList[tmpTileListIndex].IsSelected then
          begin
            tmpSelectedBitmap := frmASMain.ImageManager.Item('selected');
            tmpBitmap.Canvas.DrawBitmap(tmpSelectedBitmap,
                                        RectF(0,
                                              0,
                                              tmpSelectedBitmap.Width,
                                              tmpSelectedBitmap.Height),
                                        RectF(tmpRect.Left,
                                              tmpRect.Top,
                                              tmpRect.Right,
                                              tmpRect.Bottom),
                                        1);

          end;
        end;
      end;
  tmpBitmap.Canvas.EndScene;

  frmASMain.imgTileCanvas.Bitmap.Assign(tmpBitmap);
  frmASMain.lblCount.Text := IntToStr(GameController.TileManager.TileList.Count);
  tmpBitmap.Free;
end;