Skip to content

Commit 5b54f11

Browse files
committed
COMMON: fix graphics mode newline handling
1 parent ffbd2ad commit 5b54f11

File tree

2 files changed

+67
-24
lines changed

2 files changed

+67
-24
lines changed

src/platform/common/screen.cpp

Lines changed: 64 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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
359419
void 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;

src/platform/common/screen.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ struct GraphicScreen : public Screen {
9999
void clear();
100100
void drawBase(bool vscroll);
101101
void drawInto(bool background=false);
102-
void newLine(int lineHeight);
103102
void drawLine(int x1, int y1, int x2, int y2);
104103
void drawRect(int x1, int y1, int x2, int y2);
105104
void drawRectFilled(int x1, int y1, int x2, int y2);
105+
void imageScroll();
106+
void imageAppend(MAHandle newImage);
107+
void newLine(int lineHeight);
106108
int print(const char *p, int lineHeight, bool allChars=false);
107109
void reset(int fontSize = -1);
108110
bool setGraphicsRendition(char c, int escValue, int lineHeight);

0 commit comments

Comments
 (0)