@@ -355,6 +355,66 @@ int GraphicScreen::getPixel(int x, int y) {
355355 return result;
356356}
357357
358+ // extend the image to allow for additioal content on the newline
359+ void GraphicScreen::imageAppend (MAHandle newImage) {
360+ MARect srcRect;
361+ MAPoint2d dstPoint;
362+
363+ srcRect.left = 0 ;
364+ srcRect.top = 0 ;
365+ srcRect.width = _imageWidth;
366+ srcRect.height = _imageHeight;
367+ dstPoint.x = 0 ;
368+ dstPoint.y = 0 ;
369+
370+ maSetDrawTarget (newImage);
371+ maDrawImageRegion (_image, &srcRect, &dstPoint, TRANS_NONE);
372+
373+ // clear the new segment
374+ maSetColor (_bg);
375+ maFillRect (0 , _imageHeight, _imageWidth, _imageHeight + _height);
376+ _imageHeight += _height;
377+
378+ // cleanup the old image
379+ maDestroyPlaceholder (_image);
380+ _image = newImage;
381+ }
382+
383+ // scroll back the image to allow for additioal content on the newline
384+ void GraphicScreen::imageScroll () {
385+ MAHandle newImage = maCreatePlaceholder ();
386+ int newHeight = _imageHeight;
387+ if (maCreateDrawableImage (newImage, _imageWidth, newHeight) == RES_OK) {
388+ MARect srcRect;
389+ MAPoint2d dstPoint;
390+ int scrollBack = _height;
391+ int copiedHeight = _imageHeight - scrollBack;
392+
393+ srcRect.left = 0 ;
394+ srcRect.top = scrollBack;
395+ srcRect.width = _imageWidth;
396+ srcRect.height = copiedHeight;
397+ dstPoint.x = 0 ;
398+ dstPoint.y = 0 ;
399+
400+ maSetDrawTarget (newImage);
401+ maDrawImageRegion (_image, &srcRect, &dstPoint, TRANS_NONE);
402+
403+ // clear the new segment
404+ maSetColor (_bg);
405+ maFillRect (0 , copiedHeight, _imageWidth, scrollBack);
406+
407+ // cleanup the old image
408+ maDestroyPlaceholder (_image);
409+ _image = newImage;
410+ _scrollY -= scrollBack;
411+ _curY -= scrollBack;
412+ } else {
413+ // unable to create duplicate
414+ clear ();
415+ }
416+ }
417+
358418// handles the \n character
359419void GraphicScreen::newLine (int lineHeight) {
360420 lineHeight += _linePadding;
@@ -368,31 +428,12 @@ void GraphicScreen::newLine(int lineHeight) {
368428 MAHandle newImage = maCreatePlaceholder ();
369429 int newHeight = _imageHeight + _height;
370430 if (maCreateDrawableImage (newImage, _imageWidth, newHeight) != RES_OK) {
371- // failed to create image
372- clear ();
431+ // maximum image size reached
432+ maDestroyPlaceholder (newImage);
433+ imageScroll ();
373434 lineHeight = 0 ;
374435 } else {
375- MARect srcRect;
376- MAPoint2d dstPoint;
377-
378- srcRect.left = 0 ;
379- srcRect.top = 0 ;
380- srcRect.width = _imageWidth;
381- srcRect.height = _imageHeight;
382- dstPoint.x = 0 ;
383- dstPoint.y = 0 ;
384-
385- maSetDrawTarget (newImage);
386- maDrawImageRegion (_image, &srcRect, &dstPoint, TRANS_NONE);
387-
388- // clear the new segment
389- maSetColor (_bg);
390- maFillRect (0 , _imageHeight, _imageWidth, _imageHeight + _height);
391- _imageHeight += _height;
392-
393- // cleanup the old image
394- maDestroyPlaceholder (_image);
395- _image = newImage;
436+ imageAppend (newImage);
396437 }
397438 }
398439 _scrollY += lineHeight;
0 commit comments