(newWidth: number, newHeight: number, character: string = " ")
| 453 | } |
| 454 | |
| 455 | public resize(newWidth: number, newHeight: number, character: string = " "): boolean{ |
| 456 | // We store the old size |
| 457 | var oldWidth = this.width; |
| 458 | var oldHeight = this.height; |
| 459 | |
| 460 | // We check if the character is correct, return false if it isn't |
| 461 | if(character.length != 1) |
| 462 | return false; |
| 463 | |
| 464 | // We try to change the size, return false if failure |
| 465 | if(this.setSize(newWidth, newHeight) == false) |
| 466 | return false; |
| 467 | |
| 468 | // We resize the height |
| 469 | if(newHeight > oldHeight){ // If the new height is higher |
| 470 | for(var i = oldHeight; i < newHeight; i++){ // We add the lines corresponding to the new height |
| 471 | // We resize the tags |
| 472 | this.tags.push([]); |
| 473 | |
| 474 | // We resize the area |
| 475 | this.area.push(""); |
| 476 | // If the new width is higher |
| 477 | if(newWidth > oldWidth){ |
| 478 | for(var j = 0; j < oldWidth; j++){ // We fill the new lines from 0 to the old width |
| 479 | this.area[i] += character; |
| 480 | } |
| 481 | } |
| 482 | // Else, if the old width is higher |
| 483 | else if(oldWidth > newWidth){ |
| 484 | for(var j = 0; j < newWidth; j++){ // We fill the new lines from 0 to the new width |
| 485 | this.area[i] += character; |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | else if(oldHeight > newHeight){ // Else, if the old height was higher |
| 491 | // We resize the tags |
| 492 | this.tags.splice(this.tags.length - (oldHeight - newHeight), oldHeight - newHeight); // We remove some lines to reduce the height |
| 493 | |
| 494 | // We resize the area |
| 495 | this.area.splice(this.area.length - (oldHeight - newHeight), oldHeight - newHeight); // We remove some lines to reduce the height |
| 496 | } |
| 497 | |
| 498 | // We resize the width |
| 499 | if(newWidth > oldWidth){ // If the new width is higher |
| 500 | // We add characters at the end of the lines (lines 0 to new height) |
| 501 | for(var i = 0; i < newHeight; i++){ |
| 502 | for(var j = oldWidth; j < newWidth; j++){ |
| 503 | this.area[i] += character; |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | else if(oldWidth > newWidth){ // Else, if the old width was higher |
| 508 | // We each line (0 to new height), we only keep the beginning of the string |
| 509 | for(var i = 0; i < newHeight; i++){ |
| 510 | this.area[i] = this.area[i].substr(0, newWidth); |
| 511 | } |
| 512 | } |
no test coverage detected