public function insert(Canvas $canvas, $y, $x = 0, $h = 0, $w = 0) { $this->logger->debug("Inserting canvas at X:{$x}, Y:{$y}. Replacing W:{$w}, H:{$h}", ['canvas' => $canvas]); //remove height for ($i = $y; $i < $y + $h; $i++) { if (isset($this[$i])) { if ($x > 0) { foreach ($this[$i] as $ci => $col) { if ($ci > $x) { unset($this[$i][$x]); } } } else { unset($this[$i]); } } } //make space $insertHeight = $canvas->getHeight(); foreach ($this->getArrayCopy() as $thisRowNum => $row) { if ($thisRowNum >= $y + $h && $x === 0) { $this->logger->debug("Shifting row {$thisRowNum} to " . ($thisRowNum + $insertHeight) . " due to >= Y:{$y} + H:{$h} = " . ($y + $h) . " and X === 0. Insertheight is: {$insertHeight}", ['row' => $row]); //unset($this[$thisRowNum]); $this[$thisRowNum + $insertHeight - $h] = $row; } } /*$startRowNum = $canvas->getLowestRow(); $insertWidth = $canvas->getHighestCol() - $w; foreach ($this->getArrayCopy() as $thisRowNum => $row) { if ($thisRowNum == $startRowNum) { foreach ($row as $thisColNum => $col) { if ($thisColNum > $x + $w && $col != '') { $this[$thisRowNum][$thisColNum + $insertWidth] = $col; } } } }*/ $r = $c = 0; foreach ($canvas as $row) { foreach ($row as $c => $col) { $this->set($x + $c, $y + $r, $col); } $r++; } $this->sort(); }