safe draw

Signed-off-by: Sergey Isakov <isakov-sl@bk.ru>
This commit is contained in:
Sergey Isakov 2020-04-09 21:04:35 +03:00
parent dc52af47f0
commit fd2547c281
2 changed files with 18 additions and 26 deletions

View File

@ -562,6 +562,13 @@ void XImage::Draw(INTN x, INTN y, float scale, bool Opaque)
return;
}
if (x < 0) {
x = 0;
}
if (y < 0) {
y = 0;
}
XImage Top(*this, scale); //can accept 0 as scale
XImage Background(Width, Height);
UINTN AreaWidth = (x + Width > (UINTN)UGAWidth) ? (UGAWidth - x) : Width;
@ -569,32 +576,7 @@ void XImage::Draw(INTN x, INTN y, float scale, bool Opaque)
Background.GetArea(x, y, AreaWidth, AreaHeight); //it will resize the Background image
Background.Compose(0, 0, Top, Opaque);
Background.DrawWithoutCompose(x, y);
#if 0
// prepare protocols
EFI_STATUS Status;
EFI_GUID UgaDrawProtocolGuid = EFI_UGA_DRAW_PROTOCOL_GUID;
EFI_UGA_DRAW_PROTOCOL *UgaDraw = NULL;
EFI_GUID GraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput = NULL;
Status = EfiLibLocateProtocol(&GraphicsOutputProtocolGuid, (VOID **)&GraphicsOutput);
if (EFI_ERROR(Status)) {
GraphicsOutput = NULL;
Status = EfiLibLocateProtocol(&UgaDrawProtocolGuid, (VOID **)&UgaDraw);
if (EFI_ERROR(Status))
UgaDraw = NULL;
}
//output combined image
if (GraphicsOutput != NULL) {
GraphicsOutput->Blt(GraphicsOutput, Background.GetPixelPtr(0, 0),
EfiBltBufferToVideo,
0, 0, x, y, AreaWidth, AreaHeight, AreaWidth*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
}
else if (UgaDraw != NULL) {
UgaDraw->Blt(UgaDraw, (EFI_UGA_PIXEL *)Background.GetPixelPtr(0, 0), EfiUgaBltBufferToVideo,
0, 0, x, y, AreaWidth, AreaHeight, AreaWidth*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
}
#endif
}
void XImage::DrawOnBack(INTN XPos, INTN YPos, const XImage& Plate)

View File

@ -861,9 +861,19 @@ void XTheme::InitBar()
//TODO replace by some existing procedure
VOID XTheme::FillRectAreaOfScreen(IN INTN XPos, IN INTN YPos, IN INTN Width, IN INTN Height)
{
XImage TmpBuffer(Width, Height);
// TmpBuffer.CopyScaled(Background, 1.f);
INTN X = XPos - (Width >> 1); //X_IS_CENTRE
if (X < 0) {
X = 0;
}
if (X + Width > UGAWidth) {
Width = UGAWidth - X;
}
if (YPos + Height > UGAHeight) {
Height = UGAHeight - YPos;
}
XImage TmpBuffer(Width, Height);
TmpBuffer.CopyRect(Background, X, YPos); //a part of BackGround image
TmpBuffer.DrawWithoutCompose(X, YPos);
// TmpBuffer.Draw(X, YPos, 0, true);