From a447466ab740870ef82f2242a433ca8c768d5cc3 Mon Sep 17 00:00:00 2001 From: Wenbo Hou Date: Tue, 16 Jul 2024 22:38:11 +0800 Subject: [PATCH] MsGraphicsPkg: Fix issues in coordinate calculation (#512) ## Description Fix issues in coordinate calculation to solve On-screen keyboard render issue, and potential issues in other UI widgets. See https://github.com/microsoft/mu_plus/issues/518 The SWM_RECT structure defines a standard bounding rectangle by specifying the left, top, right, and bottom coordinates. For any SWM_RECT instance, the width is calculated as `width = right - left + 1`, and the height is determined by `height = bottom - top + 1`. When the origin point of a rectangle is known, along with its width and height, the right coordinate can be derived using `right = left + width - 1`, and the bottom coordinate is given by `bottom = top + height - 1`. Ensuring the correct application of these formulas prevents the On-Screen Keyboard (OSK) boundary from exceeding its defined limits. - [x] Impacts functionality? - **Functionality** - Does the change ultimately impact how firmware functions? - Examples: Add a new library, publish a new PPI, update an algorithm, ... - [ ] Impacts security? - **Security** - Does the change have a direct security impact on an application, flow, or firmware? - Examples: Crypto algorithm change, buffer overflow fix, parameter validation improvement, ... - [ ] Breaking change? - **Breaking change** - Will anyone consuming this change experience a break in build or boot behavior? - Examples: Add a new library class, move a module to a different repo, call a function in a new library class in a pre-existing module, ... - [ ] Includes tests? - **Tests** - Does the change include any explicit test code? - Examples: Unit tests, integration tests, robot tests, ... - [ ] Includes documentation? - **Documentation** - Does the change contain explicit documentation additions outside direct code modifications (and comments)? - Examples: Update readme file, add feature readme file, link to documentation on an a separate Web page, ... ## How This Was Tested Boot to UEFI menu, all UI items rendered correctly and OSK functioned well. ## Integration Instructions N/A --- MsGraphicsPkg/DisplayEngineDxe/FormDisplay.c | 157 ++++++++------- .../Include/Protocol/SimpleWindowManager.h | 28 +++ .../Library/SimpleUIToolKit/Bitmap.c | 19 +- .../Library/SimpleUIToolKit/Button.c | 61 +++--- .../Library/SimpleUIToolKit/Canvas.c | 12 +- .../Library/SimpleUIToolKit/EditBox.c | 58 +++--- MsGraphicsPkg/Library/SimpleUIToolKit/Grid.c | 41 ++-- MsGraphicsPkg/Library/SimpleUIToolKit/Label.c | 11 +- .../Library/SimpleUIToolKit/ListBox.c | 82 +++++--- .../Library/SimpleUIToolKit/ProgressBar.c | 17 +- .../Library/SimpleUIToolKit/ToggleSwitch.c | 23 ++- .../Library/SimpleUIToolKit/Utilities.c | 4 +- .../Library/SwmDialogsLib/MessageBox.c | 143 +++++++------- .../Library/SwmDialogsLib/PasswordDialog.c | 153 +++++++------- .../SwmDialogsLib/SemmUserAuthDialog.c | 187 +++++++++--------- .../SwmDialogsLib/SingleSelectDialog.c | 151 +++++++------- .../OnScreenKeyboardDriver.c | 83 ++++---- .../RenderingEngineDxe/RenderingEngine.c | 50 ++--- 18 files changed, 684 insertions(+), 596 deletions(-) diff --git a/MsGraphicsPkg/DisplayEngineDxe/FormDisplay.c b/MsGraphicsPkg/DisplayEngineDxe/FormDisplay.c index 3c077209d0..73d1bd3ea5 100644 --- a/MsGraphicsPkg/DisplayEngineDxe/FormDisplay.c +++ b/MsGraphicsPkg/DisplayEngineDxe/FormDisplay.c @@ -921,10 +921,13 @@ CreateFormControls ( // Define a canvas bounding rectangle that fills the form window. // - FormRect.Left = mMasterFrameWidth; - FormRect.Top = mTitleBarHeight; - FormRect.Right = mGop->Mode->Info->HorizontalResolution; - FormRect.Bottom = mGop->Mode->Info->VerticalResolution; + SWM_RECT_INIT2 ( + FormRect, + mMasterFrameWidth, + mTitleBarHeight, + mGop->Mode->Info->HorizontalResolution - mMasterFrameWidth, + mGop->Mode->Info->VerticalResolution - mTitleBarHeight + ); // Create a canvas for rendering the HII form. // @@ -947,10 +950,10 @@ CreateFormControls ( // Set a starting position within the canvas for rendering UI controls. // - UINT32 OrigX = (mMasterFrameWidth + ((mMasterFrameWidth * FP_FCANVAS_BORDER_PAD_WIDTH_PERCENT) / 100)); - UINT32 OrigY = (mTitleBarHeight + ((mMasterFrameHeight * FP_FCANVAS_BORDER_PAD_HEIGHT_PERCENT) / 100)); - UINT32 CanvasRightLimit = (mGop->Mode->Info->HorizontalResolution - ((mMasterFrameWidth * FP_FCANVAS_BORDER_PAD_WIDTH_PERCENT) / 100)); - UINT32 CanvasBottomLimit = (mGop->Mode->Info->VerticalResolution - ((mMasterFrameHeight * FP_FCANVAS_BORDER_PAD_HEIGHT_PERCENT) / 100)); + UINT32 OrigX = (FormRect.Left + ((mMasterFrameWidth * FP_FCANVAS_BORDER_PAD_WIDTH_PERCENT) / 100)); + UINT32 OrigY = (FormRect.Top + ((mMasterFrameHeight * FP_FCANVAS_BORDER_PAD_HEIGHT_PERCENT) / 100)); + UINT32 CanvasRightLimit = (FormRect.Right - ((mMasterFrameWidth * FP_FCANVAS_BORDER_PAD_WIDTH_PERCENT) / 100)); + UINT32 CanvasBottomLimit = (FormRect.Bottom - ((mMasterFrameHeight * FP_FCANVAS_BORDER_PAD_HEIGHT_PERCENT) / 100)); // Walk through the list of processed HII opcodes and create custom UI controls for each element. // @@ -1052,10 +1055,13 @@ CreateFormControls ( // Calculate the correct size for the grid. // - GridRect.Left = OrigX; - GridRect.Top = OrigY; - GridRect.Right = CanvasRightLimit; - GridRect.Bottom = OrigY + (MaxRows * GridCellHeight); + SWM_RECT_INIT ( + GridRect, + OrigX, + OrigY, + CanvasRightLimit, + OrigY + (MaxRows * GridCellHeight) - 1 + ); // Create a grid for aligning UI controls. // @@ -1093,7 +1099,7 @@ CreateFormControls ( &ControlRect ); - OrigY += (ControlRect.Bottom - ControlRect.Top); + OrigY += SWM_RECT_HEIGHT (ControlRect); // Indicate that the grid now has scope. Until the Grid End OpCode is encountered, all // controls added from this point forward will be added to the grid. @@ -1226,7 +1232,7 @@ CreateFormControls ( // Move the next control's origin down the page by the height of the current control. // - OrigY += (ControlRect.Bottom - ControlRect.Top); + OrigY += SWM_RECT_HEIGHT (ControlRect); } } @@ -1330,7 +1336,7 @@ CreateFormControls ( // Move the next control's origin down the page by the height of the current control. // - OrigY += (ControlRect.Bottom - ControlRect.Top); + OrigY += SWM_RECT_HEIGHT (ControlRect); } break; @@ -1345,27 +1351,29 @@ CreateFormControls ( UIT_LB_CELLDATA *OptionList; UINT32 Flags = 0; - UINT32 LabelX = (GridScope ? 0 : (UINT32)MenuOption->Col); - UINT32 LabelY = (GridScope ? 0 : (UINT32)MenuOption->Row); - // UINT32 LabelWidth = (GridScope ? : (CanvasRightLimit - LabelX)); - // UINT32 LabelHeight = (GridScope ? : (CanvasBottomLimit - LabelY)); - // TODO - UINT32 LabelWidth = (CanvasRightLimit - LabelX); - UINT32 LabelHeight = (CanvasBottomLimit - LabelY); UINT32 ListWidth; Label *L; EFI_GRAPHICS_OUTPUT_BLT_PIXEL *TextColor = &gMsColorTable.LabelTextNormalColor; + SWM_RECT LabelRect; + + SWM_RECT_INIT ( + LabelRect, + (GridScope ? 0 : (UINT32)MenuOption->Col), + (GridScope ? 0 : (UINT32)MenuOption->Row), + CanvasRightLimit, + CanvasBottomLimit + ); if (MenuOption->GrayOut) { TextColor = &gMsColorTable.LabelTextGrayoutColor; } L = new_Label ( - LabelX, - LabelY, - LabelWidth, - LabelHeight, + LabelRect.Left, + LabelRect.Top, + SWM_RECT_WIDTH (LabelRect), + SWM_RECT_HEIGHT (LabelRect), &FontInfo, TextColor, // Foreground (text) color. &gMsColorTable.LabelTextBackgroundColor, // Background color. @@ -1415,7 +1423,7 @@ CreateFormControls ( // Move the next control's origin down the page by the height of the current control. // - OrigY += (ControlRect.Bottom - ControlRect.Top) + 40; // TODO - appropriate buffer between listbox label and listbox? + OrigY += SWM_RECT_HEIGHT (ControlRect) + 40; // TODO - appropriate buffer between listbox label and listbox? MenuOption->Row = OrigY; } @@ -1550,7 +1558,7 @@ CreateFormControls ( &ControlRect ); - OrigY += (ControlRect.Bottom - ControlRect.Top); + OrigY += SWM_RECT_HEIGHT (ControlRect); } break; @@ -1558,17 +1566,22 @@ CreateFormControls ( case EFI_IFR_STRING_OP: // StringOp { - UINT32 LabelX = (GridScope ? 0 : (UINT32)MenuOption->Col); - UINT32 LabelY = (GridScope ? 0 : (UINT32)MenuOption->Row); - EFI_IFR_STRING *String = (EFI_IFR_STRING *)Statement->OpCode; - UINT32 LabelWidth = (CanvasRightLimit - LabelX); - UINT32 LabelHeight = (CanvasBottomLimit - LabelY); + EFI_IFR_STRING *String = (EFI_IFR_STRING *)Statement->OpCode; + SWM_RECT LabelRect; + + SWM_RECT_INIT ( + LabelRect, + (GridScope ? 0 : (UINT32)MenuOption->Col), + (GridScope ? 0 : (UINT32)MenuOption->Row), + CanvasRightLimit, + CanvasBottomLimit + ); Label *L = new_Label ( - LabelX, - LabelY, - LabelWidth, - LabelHeight, + LabelRect.Left, + LabelRect.Top, + SWM_RECT_WIDTH (LabelRect), + SWM_RECT_HEIGHT (LabelRect), &FontInfo, ((MsUiGetLargeFontHeight () == FontInfo.FontSize) ? &gMsColorTable.LabelTextLargeColor : &gMsColorTable.LabelTextNormalColor), // TODO - Foreground (text) color. &gMsColorTable.LabelTextBackgroundColor, // Background color. @@ -1615,7 +1628,7 @@ CreateFormControls ( &ControlRect ); - OrigY += (ControlRect.Bottom - ControlRect.Top); + OrigY += SWM_RECT_HEIGHT (ControlRect); MenuOption->Row = OrigY; } @@ -1686,7 +1699,7 @@ CreateFormControls ( &ControlRect ); - OrigY += (ControlRect.Bottom - ControlRect.Top); + OrigY += SWM_RECT_HEIGHT (ControlRect); } if (String->Question.Flags & EFI_IFR_FLAG_READ_ONLY) { @@ -1698,15 +1711,16 @@ CreateFormControls ( case EFI_IFR_TEXT_OP: // Text. { - UINT32 LabelX = (GridScope ? 0 : (UINT32)MenuOption->Col); - UINT32 LabelY = (GridScope ? 0 : (UINT32)MenuOption->Row); - // UINT32 LabelWidth = (GridScope ? : (CanvasRightLimit - LabelX)); - // UINT32 LabelHeight = (GridScope ? : (CanvasBottomLimit - LabelY)); - // TODO - UINT32 LabelWidth = (CanvasRightLimit - LabelX); - UINT32 LabelHeight = (CanvasBottomLimit - LabelY); - EFI_GRAPHICS_OUTPUT_BLT_PIXEL *TextColor = &gMsColorTable.LabelTextNormalColor; // DCR (MsUiGetLargeFontHeight () == FontInfo.FontSize ? &gMsColorTable.LabelTextLargeColor : &gMsColorTable.LabelTextNormalColor; + SWM_RECT LabelRect; + + SWM_RECT_INIT ( + LabelRect, + (GridScope ? 0 : (UINT32)MenuOption->Col), + (GridScope ? 0 : (UINT32)MenuOption->Row), + CanvasRightLimit, + CanvasBottomLimit + ); if (0 == StrnCmp (Description, L"\\fc!Red!", 8)) { Description += StrLen (L"\\fc!Red!"); @@ -1718,10 +1732,10 @@ CreateFormControls ( } Label *L = new_Label ( - LabelX, - LabelY, - LabelWidth, - LabelHeight, + LabelRect.Left, + LabelRect.Top, + SWM_RECT_WIDTH (LabelRect), + SWM_RECT_HEIGHT (LabelRect), &FontInfo, TextColor, // TODO - Foreground (text) color. &gMsColorTable.LabelTextBackgroundColor, // Background color. @@ -1770,7 +1784,7 @@ CreateFormControls ( &ControlRect ); - OrigY += (ControlRect.Bottom - ControlRect.Top); + OrigY += SWM_RECT_HEIGHT (ControlRect); } break; @@ -1778,19 +1792,21 @@ CreateFormControls ( case EFI_IFR_CHECKBOX_OP: // Checkbox. { - UINT32 LabelX = (GridScope ? 0 : (UINT32)MenuOption->Col); - UINT32 LabelY = (GridScope ? 0 : (UINT32)MenuOption->Row); - // UINT32 LabelWidth = (GridScope ? : (CanvasRightLimit - LabelX)); - // UINT32 LabelHeight = (GridScope ? : (CanvasBottomLimit - LabelY)); - // TODO - UINT32 LabelWidth = (CanvasRightLimit - LabelX); - UINT32 LabelHeight = (CanvasBottomLimit - LabelY); + SWM_RECT LabelRect; + + SWM_RECT_INIT ( + LabelRect, + (GridScope ? 0 : (UINT32)MenuOption->Col), + (GridScope ? 0 : (UINT32)MenuOption->Row), + CanvasRightLimit, + CanvasBottomLimit + ); Label *L = new_Label ( - LabelX, - LabelY, - LabelWidth, - LabelHeight, + LabelRect.Left, + LabelRect.Top, + SWM_RECT_WIDTH (LabelRect), + SWM_RECT_HEIGHT (LabelRect), &FontInfo, (MsUiGetLargeFontHeight () == FontInfo.FontSize ? &gMsColorTable.LabelTextLargeColor : &gMsColorTable.LabelTextNormalColor), // TODO - Foreground (text) color. &gMsColorTable.LabelTextBackgroundColor, // Background color. @@ -1837,7 +1853,7 @@ CreateFormControls ( &ControlRect ); - OrigY += (ControlRect.Bottom - ControlRect.Top); + OrigY += SWM_RECT_HEIGHT (ControlRect); MenuOption->Row = OrigY; } @@ -1914,7 +1930,7 @@ CreateFormControls ( &ControlRect ); - OrigY += (ControlRect.Bottom - ControlRect.Top); + OrigY += SWM_RECT_HEIGHT (ControlRect); } break; @@ -2912,10 +2928,13 @@ RegisterWithSimpleWindowManager ( // Default to registering full screen support. // - FrameRect.Left = 0; - FrameRect.Top = 0; - FrameRect.Right = (mGop->Mode->Info->HorizontalResolution - 1); - FrameRect.Bottom = (mGop->Mode->Info->VerticalResolution - 1); + SWM_RECT_INIT2 ( + FrameRect, + 0, + 0, + mGop->Mode->Info->HorizontalResolution, + mGop->Mode->Info->VerticalResolution + ); // // Register with the Simple Window Manager. diff --git a/MsGraphicsPkg/Include/Protocol/SimpleWindowManager.h b/MsGraphicsPkg/Include/Protocol/SimpleWindowManager.h index 997780e0e2..19c8fc2325 100644 --- a/MsGraphicsPkg/Include/Protocol/SimpleWindowManager.h +++ b/MsGraphicsPkg/Include/Protocol/SimpleWindowManager.h @@ -58,6 +58,34 @@ typedef struct _SWM_RECT_tag { UINT32 Bottom; } SWM_RECT; +// Initialize the Rect with the coordinates of the top-left and bottom-right corners +// +#define SWM_RECT_INIT(Rect, TopLeftX, TopLeftY, BottomRightX, BottomRightY) \ +do { \ + (Rect).Left = (TopLeftX); \ + (Rect).Top = (TopLeftY); \ + (Rect).Right = (BottomRightX); \ + (Rect).Bottom = (BottomRightY); \ +} while (0) + +// Initialize the Rect with the coordinates of the top-left corner and the dimensions. +// +#define SWM_RECT_INIT2(Rect, TopLeftX, TopLeftY, Width, Height) \ +do { \ + (Rect).Left = (TopLeftX); \ + (Rect).Top = (TopLeftY); \ + (Rect).Right = (TopLeftX) + (Width) - 1; \ + (Rect).Bottom = (TopLeftY) + (Height) - 1; \ +} while (0) + +// Get width of the Rect +// +#define SWM_RECT_WIDTH(Rect) ((Rect).Right - (Rect).Left + 1) + +// Get height of the Rect +// +#define SWM_RECT_HEIGHT(Rect) ((Rect).Bottom - (Rect).Top + 1) + // Supported user input types. // #define SWM_INPUT_TYPE_TOUCH 0x00000001 diff --git a/MsGraphicsPkg/Library/SimpleUIToolKit/Bitmap.c b/MsGraphicsPkg/Library/SimpleUIToolKit/Bitmap.c index 8210a92ed0..cf2bd3865a 100644 --- a/MsGraphicsPkg/Library/SimpleUIToolKit/Bitmap.c +++ b/MsGraphicsPkg/Library/SimpleUIToolKit/Bitmap.c @@ -18,8 +18,8 @@ RenderBitmap ( IN Bitmap *this ) { - UINT32 Width = (this->m_BitmapBounds.Right - this->m_BitmapBounds.Left + 1); - UINT32 Height = (this->m_BitmapBounds.Bottom - this->m_BitmapBounds.Top + 1); + UINT32 Width = SWM_RECT_WIDTH (this->m_BitmapBounds); + UINT32 Height = SWM_RECT_HEIGHT (this->m_BitmapBounds); // Draw the bitmap. // @@ -132,8 +132,8 @@ Ctor ( IN SWM_RECT BitmapBounds ) { - UINT32 Width = (BitmapBounds.Right - BitmapBounds.Left + 1); - UINT32 Height = (BitmapBounds.Bottom - BitmapBounds.Top + 1); + UINT32 Width = SWM_RECT_WIDTH (BitmapBounds); + UINT32 Height = SWM_RECT_HEIGHT (BitmapBounds); UINT32 BitmapSize; // Capture the bounding box of the bitmap. @@ -211,10 +211,13 @@ new_Bitmap ( B->Ctor = &Ctor; B->Base.Dtor = &Dtor; - Rect.Left = OrigX; - Rect.Right = (OrigX + BitmapWidth - 1); - Rect.Top = OrigY; - Rect.Bottom = (OrigY + BitmapHeight - 1); + SWM_RECT_INIT2 ( + Rect, + OrigX, + OrigY, + BitmapWidth, + BitmapHeight + ); B->Ctor ( B, diff --git a/MsGraphicsPkg/Library/SimpleUIToolKit/Button.c b/MsGraphicsPkg/Library/SimpleUIToolKit/Button.c index 099e2557c7..45c0e91136 100644 --- a/MsGraphicsPkg/Library/SimpleUIToolKit/Button.c +++ b/MsGraphicsPkg/Library/SimpleUIToolKit/Button.c @@ -80,8 +80,8 @@ RenderButton ( // Compute button width and height. // - Width = (this->m_pButton->ButtonBounds.Right - this->m_pButton->ButtonBounds.Left + 1); - Height = (this->m_pButton->ButtonBounds.Bottom - this->m_pButton->ButtonBounds.Top) + 1; + Width = SWM_RECT_WIDTH (this->m_pButton->ButtonBounds); + Height = SWM_RECT_HEIGHT (this->m_pButton->ButtonBounds); // Draw the button's - outer rectangle first. // @@ -185,14 +185,18 @@ SetControlBounds ( // Translate (and possibly resize) button text bounding box. // - SWM_RECT *TextRect = &this->m_pButton->ButtonTextBounds; - UINT32 TextWidth = (TextRect->Right - TextRect->Left); - UINT32 TextHeight = (TextRect->Bottom - TextRect->Top); - - Bounds.Left += TextOffsetX; - Bounds.Top += TextOffsetY; - Bounds.Right = ((Bounds.Left + TextWidth) < Bounds.Right ? (Bounds.Right + TextWidth) : Bounds.Right); - Bounds.Bottom = ((Bounds.Top + TextHeight) < Bounds.Bottom ? (Bounds.Top + TextHeight) : Bounds.Bottom); + UINT32 TextWidth = SWM_RECT_WIDTH (this->m_pButton->ButtonTextBounds); + UINT32 TextHeight = SWM_RECT_HEIGHT (this->m_pButton->ButtonTextBounds); + UINT32 ButtonWidth = SWM_RECT_WIDTH (this->m_pButton->ButtonBounds); + UINT32 ButtonHeight = SWM_RECT_HEIGHT (this->m_pButton->ButtonBounds); + + SWM_RECT_INIT2 ( + Bounds, + this->m_pButton->ButtonBounds.Left + TextOffsetX, + this->m_pButton->ButtonBounds.Top + TextOffsetY, + ((TextWidth < (ButtonWidth - TextOffsetX)) ? TextWidth : (ButtonWidth - TextOffsetX)), + ((TextHeight < (ButtonHeight - TextOffsetY)) ? TextHeight : (ButtonHeight - TextOffsetY)) + ); CopyMem (&this->m_pButton->ButtonTextBounds, &Bounds, sizeof (SWM_RECT)); @@ -422,15 +426,15 @@ Ctor ( goto Exit; } - UINT32 ButtonWidth = (this->m_pButton->ButtonBounds.Right - this->m_pButton->ButtonBounds.Left + 1); - UINT32 ButtonHeight = (this->m_pButton->ButtonBounds.Bottom - this->m_pButton->ButtonBounds.Top + 1); - UINT32 StringWidth = (this->m_pButton->ButtonTextBounds.Right - this->m_pButton->ButtonTextBounds.Left + 1); - UINT32 StringHeight = (this->m_pButton->ButtonTextBounds.Bottom - this->m_pButton->ButtonTextBounds.Top + 1); + UINT32 ButtonWidth = SWM_RECT_WIDTH (this->m_pButton->ButtonBounds); + UINT32 ButtonHeight = SWM_RECT_HEIGHT (this->m_pButton->ButtonBounds); + UINT32 StringWidth = SWM_RECT_WIDTH (this->m_pButton->ButtonTextBounds); + UINT32 StringHeight = SWM_RECT_HEIGHT (this->m_pButton->ButtonTextBounds); - this->m_pButton->ButtonTextBounds.Left += ((ButtonWidth / 2) - (StringWidth / 2)); - this->m_pButton->ButtonTextBounds.Right += ((ButtonWidth / 2) - (StringWidth / 2)); - this->m_pButton->ButtonTextBounds.Top += ((ButtonHeight / 2) - ((StringHeight - MaxGlyphDescent) / 2)); - this->m_pButton->ButtonTextBounds.Bottom += ((ButtonHeight / 2) - ((StringHeight - MaxGlyphDescent) / 2)); + this->m_pButton->ButtonTextBounds.Left += ((ButtonWidth - StringWidth) / 2); + this->m_pButton->ButtonTextBounds.Right += ((ButtonWidth - StringWidth) / 2); + this->m_pButton->ButtonTextBounds.Top += ((ButtonHeight - (StringHeight - MaxGlyphDescent)) / 2); + this->m_pButton->ButtonTextBounds.Bottom += ((ButtonHeight - (StringHeight - MaxGlyphDescent)) / 2); // Configure button state. // @@ -516,15 +520,6 @@ new_Button ( B->Ctor = &Ctor; B->Base.Dtor = &Dtor; - // Set origin corners. - Rect.Left = OrigX; - Rect.Top = OrigY; - - // Adjust for width, if provided. - Rect.Right = (ButtonWidth != SUI_BUTTON_AUTO_SIZE) ? (OrigX + ButtonWidth - 1) : OrigX; - // Adjust for height, if provided. - Rect.Bottom = (ButtonHeight != SUI_BUTTON_AUTO_SIZE) ? (OrigY + ButtonHeight - 1) : OrigY; - // If either of the dimensions should be set automatically, // determine the text dimensions. // We have to do this here because the constructor consumes a RECT, not width or height. @@ -547,10 +542,18 @@ new_Button ( return NULL; } - Rect.Right = Rect.Left + (TempRect.Right - TempRect.Left) + SUI_BUTTON_HIGHLIGHT_X_PAD; // Add px to allow space for the "Tab highlight". - Rect.Bottom = Rect.Top + (TempRect.Bottom - TempRect.Top) + SUI_BUTTON_HIGHLIGHT_Y_PAD; // Add px to allow space for the "Tab highlight". + ButtonWidth = SWM_RECT_WIDTH (TempRect) + SUI_BUTTON_HIGHLIGHT_X_PAD; // Add px to allow space for the "Tab highlight". + ButtonHeight = SWM_RECT_HEIGHT (TempRect) + SUI_BUTTON_HIGHLIGHT_Y_PAD; // Add px to allow space for the "Tab highlight". } + SWM_RECT_INIT2 ( + Rect, + OrigX, + OrigY, + ButtonWidth, + ButtonHeight + ); + B->Ctor ( B, Rect, diff --git a/MsGraphicsPkg/Library/SimpleUIToolKit/Canvas.c b/MsGraphicsPkg/Library/SimpleUIToolKit/Canvas.c index 174756fe7d..1ec0d63009 100644 --- a/MsGraphicsPkg/Library/SimpleUIToolKit/Canvas.c +++ b/MsGraphicsPkg/Library/SimpleUIToolKit/Canvas.c @@ -57,16 +57,16 @@ SetControlBounds ( ) { EFI_STATUS Status = EFI_SUCCESS; - UINT32 NewWidth = (Rect.Right - Rect.Left + 1); - UINT32 NewHeight = (Rect.Bottom - Rect.Top + 1); + UINT32 NewWidth = SWM_RECT_WIDTH (Rect); + UINT32 NewHeight = SWM_RECT_HEIGHT (Rect); UIT_CANVAS_CHILD_CONTROL *pChildControl = this->m_pControls; ControlBase *pControlBase; SWM_RECT ControlRect; // We don't support shrinking the canvas - only repositioning. // - if ((NewWidth != (this->m_CanvasBounds.Right - this->m_CanvasBounds.Left + 1)) || - (NewHeight != (this->m_CanvasBounds.Bottom - this->m_CanvasBounds.Top + 1))) + if ((NewWidth != SWM_RECT_WIDTH (this->m_CanvasBounds)) || + (NewHeight != SWM_RECT_HEIGHT (this->m_CanvasBounds))) { DEBUG ((DEBUG_ERROR, "ERROR [SUIT]: Not able to resize canvas.\r\n")); Status = EFI_UNSUPPORTED; @@ -519,8 +519,8 @@ ClearCanvas ( while (NULL != pChildControl) { pChildControlRect = &pChildControl->ChildBounds; - FillWidth = (pChildControlRect->Right - pChildControlRect->Left + 1); - FillHeight = (pChildControlRect->Bottom - pChildControlRect->Top + 1); + FillWidth = SWM_RECT_WIDTH (*pChildControlRect); + FillHeight = SWM_RECT_HEIGHT (*pChildControlRect); mUITSWM->BltWindow ( mUITSWM, diff --git a/MsGraphicsPkg/Library/SimpleUIToolKit/EditBox.c b/MsGraphicsPkg/Library/SimpleUIToolKit/EditBox.c index bcf4c83894..bfe60e8a3b 100644 --- a/MsGraphicsPkg/Library/SimpleUIToolKit/EditBox.c +++ b/MsGraphicsPkg/Library/SimpleUIToolKit/EditBox.c @@ -81,8 +81,8 @@ RenderEditBox ( // Compute editbox width and height. // - Width = (this->m_EditBoxBounds.Right - this->m_EditBoxBounds.Left + 1); - Height = (this->m_EditBoxBounds.Bottom - this->m_EditBoxBounds.Top + 1); + Width = SWM_RECT_WIDTH (this->m_EditBoxBounds); + Height = SWM_RECT_HEIGHT (this->m_EditBoxBounds); // Draw the editbox background first. // @@ -161,8 +161,8 @@ RenderEditBox ( DrawRectangleOutline ( this->m_EditBoxBounds.Left, this->m_EditBoxBounds.Top, - this->m_EditBoxBounds.Right - this->m_EditBoxBounds.Left - 1, - this->m_EditBoxBounds.Bottom - this->m_EditBoxBounds.Top - 1, + SWM_RECT_WIDTH (this->m_EditBoxBounds), + SWM_RECT_HEIGHT (this->m_EditBoxBounds), UIT_E_HIGHLIGHT_RING_WIDTH, &gMsColorTable.EditBoxHighlightBoundColor ); @@ -204,19 +204,23 @@ SetControlBounds ( // Translate (and possibly resize) the editbox text bounding box. // - SWM_RECT *TextRect = &this->m_EditBoxTextBounds; - UINT32 TextWidth = (TextRect->Right - TextRect->Left + 1); - UINT32 TextHeight = (TextRect->Bottom - TextRect->Top + 1); - - Bounds.Left += TextOffsetX; - Bounds.Top += TextOffsetY; - Bounds.Right = ((Bounds.Left + TextWidth) < Bounds.Right ? (Bounds.Right + TextWidth) : Bounds.Right); - Bounds.Bottom = ((Bounds.Top + TextHeight) < Bounds.Bottom ? (Bounds.Top + TextHeight) : Bounds.Bottom); + UINT32 TextWidth = SWM_RECT_WIDTH (this->m_EditBoxTextBounds); + UINT32 TextHeight = SWM_RECT_HEIGHT (this->m_EditBoxTextBounds); + UINT32 EditBoxWidth = SWM_RECT_WIDTH (this->m_EditBoxBounds); + UINT32 EditBoxHeight = SWM_RECT_HEIGHT (this->m_EditBoxBounds); + + SWM_RECT_INIT2 ( + Bounds, + this->m_EditBoxBounds.Left + TextOffsetX, + this->m_EditBoxBounds.Top + TextOffsetY, + ((TextWidth < (EditBoxWidth - TextOffsetX)) ? TextWidth : (EditBoxWidth - TextOffsetX)), + ((TextHeight < (EditBoxHeight - TextOffsetY)) ? TextHeight : (EditBoxHeight - TextOffsetY)) + ); CopyMem (&this->m_EditBoxTextBounds, &Bounds, sizeof (SWM_RECT)); - // MaxDisplay Characters = ((width of the full edibox) + (AvgCharWidth -1 ) - (left and right padding)) / AvgCharWidth - this->m_MaxDisplayChars = (this->m_EditBoxBounds.Right - this->m_EditBoxBounds.Left + 1 + this->m_CharWidth - 1 - (2 * UIT_EDITBOX_HORIZONTAL_PADDING)) / this->m_CharWidth; + // MaxDisplay Characters = ((width of the full edibox) + (AvgCharWidth -1) - (left and right padding)) / AvgCharWidth + this->m_MaxDisplayChars = (EditBoxWidth + (this->m_CharWidth - 1) - (2 * UIT_EDITBOX_HORIZONTAL_PADDING)) / this->m_CharWidth; return Status; } @@ -653,22 +657,28 @@ Ctor ( this->m_EditBoxText[0] = L'\0'; - TextWidth = (TextRect.Right - TextRect.Left + 1); - TextHeight = (TextRect.Bottom - TextRect.Top + 1); + TextWidth = SWM_RECT_WIDTH (TextRect); + TextHeight = SWM_RECT_HEIGHT (TextRect); this->m_CharWidth = TextWidth / MaxDisplayChars; // Average width of one 'W' - this->m_EditBoxBounds.Left = OrigX; - this->m_EditBoxBounds.Top = OrigY; - this->m_EditBoxBounds.Right = (OrigX + TextWidth + (UIT_EDITBOX_HORIZONTAL_PADDING * 2)); // At beginning and end of editbox text. - this->m_EditBoxBounds.Bottom = (OrigY + TextHeight + (UIT_EDITBOX_VERTICAL_PADDING * 2)); // At top and bottom of editbox text. + SWM_RECT_INIT2 ( + this->m_EditBoxBounds, + OrigX, + OrigY, + TextWidth + (UIT_EDITBOX_HORIZONTAL_PADDING * 2), + TextHeight + (UIT_EDITBOX_VERTICAL_PADDING * 2) + ); // Compute EditBox text bounding rectangle (based on max display string length). // - this->m_EditBoxTextBounds.Left = (OrigX + UIT_EDITBOX_HORIZONTAL_PADDING); - this->m_EditBoxTextBounds.Top = (OrigY + UIT_EDITBOX_VERTICAL_PADDING); - this->m_EditBoxTextBounds.Right = (this->m_EditBoxBounds.Right - UIT_EDITBOX_HORIZONTAL_PADDING); - this->m_EditBoxTextBounds.Bottom = (this->m_EditBoxBounds.Bottom - UIT_EDITBOX_VERTICAL_PADDING); + SWM_RECT_INIT2 ( + this->m_EditBoxTextBounds, + OrigX + UIT_EDITBOX_HORIZONTAL_PADDING, + OrigY + UIT_EDITBOX_VERTICAL_PADDING, + TextWidth, + TextHeight + ); // Configure EditBox state. // diff --git a/MsGraphicsPkg/Library/SimpleUIToolKit/Grid.c b/MsGraphicsPkg/Library/SimpleUIToolKit/Grid.c index e33a2bca5c..c845bf051d 100644 --- a/MsGraphicsPkg/Library/SimpleUIToolKit/Grid.c +++ b/MsGraphicsPkg/Library/SimpleUIToolKit/Grid.c @@ -125,13 +125,19 @@ AddControl ( // control's size so it doesn't flow into the neighbors cell. // SWM_RECT NewBounds; - UINT32 CellOrigX = (this->m_GridBounds.Left + (Column * this->m_GridCellWidth)); - UINT32 CellOrigY = (this->m_GridBounds.Top + (Row * this->m_GridCellHeight)); - UINT32 CellEndX = (CellOrigX + this->m_GridCellWidth - 1); - UINT32 CellEndY = (CellOrigY + this->m_GridCellHeight - 1); - UINT32 ControlWidth = (ControlBounds.Right - ControlBounds.Left + 1); - UINT32 ControlHeight = (ControlBounds.Bottom - ControlBounds.Top + 1); + + UINT32 ControlWidth = SWM_RECT_WIDTH (ControlBounds); + UINT32 ControlHeight = SWM_RECT_HEIGHT (ControlBounds); UINT32 VerticalAdjust = (this->m_GridCellHeight - ControlHeight) / 2; + SWM_RECT CellRect; + + SWM_RECT_INIT2 ( + CellRect, + (this->m_GridBounds.Left + (Column * this->m_GridCellWidth)), + (this->m_GridBounds.Top + (Row * this->m_GridCellHeight)), + this->m_GridCellWidth, + this->m_GridCellHeight + ); if (ControlHeight > this->m_GridCellHeight) { DEBUG ((DEBUG_ERROR, "ERROR [Grid]: Found Grid element larger than specified height. GridH=%d,ElemetH=%d.\r\n", this->m_GridCellHeight, ControlHeight)); @@ -139,19 +145,22 @@ AddControl ( this->m_GridCellHeight = ControlHeight; } - NewBounds.Left = (CellOrigX + ControlBounds.Left); - NewBounds.Top = (CellOrigY + ControlBounds.Top + VerticalAdjust); - NewBounds.Right = (0 != ControlWidth ? (NewBounds.Left + ControlWidth - 1) : NewBounds.Left); - NewBounds.Bottom = (0 != ControlHeight ? (NewBounds.Top + ControlHeight - 1) : NewBounds.Top); + SWM_RECT_INIT2 ( + NewBounds, + (CellRect.Left + ControlBounds.Left), + (CellRect.Top + ControlBounds.Top + VerticalAdjust), + ControlWidth, + ControlHeight + ); // If the child control is larger than the grid cell size and the truncate flag is set, limit the size to the cell size. // - if ((NewBounds.Right > CellEndX) && (TRUE == this->m_TruncateControl)) { - NewBounds.Right = CellEndX; + if ((NewBounds.Right > CellRect.Right) && (TRUE == this->m_TruncateControl)) { + NewBounds.Right = CellRect.Right; } - if ((NewBounds.Bottom > CellEndY) && (TRUE == this->m_TruncateControl)) { - NewBounds.Bottom = CellEndY; + if ((NewBounds.Bottom > CellRect.Bottom) && (TRUE == this->m_TruncateControl)) { + NewBounds.Bottom = CellRect.Bottom; } // Reposition the child control by moving it to the grid-specified cell location and offset. @@ -310,8 +319,8 @@ Ctor ( // Compute grid cell size based on overall side and number of rows & columns. // - this->m_GridCellWidth = ((GridBounds.Right - GridBounds.Left + 1) / Columns); - this->m_GridCellHeight = ((GridBounds.Bottom - GridBounds.Top + 1) / Rows); + this->m_GridCellWidth = (SWM_RECT_WIDTH (GridBounds) / Columns); + this->m_GridCellHeight = (SWM_RECT_HEIGHT (GridBounds) / Rows); this->m_GridInitialHeight = this->m_GridCellHeight; // No child controls yet. diff --git a/MsGraphicsPkg/Library/SimpleUIToolKit/Label.c b/MsGraphicsPkg/Library/SimpleUIToolKit/Label.c index e381058825..93a8589d1e 100644 --- a/MsGraphicsPkg/Library/SimpleUIToolKit/Label.c +++ b/MsGraphicsPkg/Library/SimpleUIToolKit/Label.c @@ -334,10 +334,13 @@ new_Label ( L->Ctor = &Ctor; L->Base.Dtor = &Dtor; - Rect.Left = OrigX; - Rect.Right = (OrigX + LabelWidth - 1); - Rect.Top = OrigY; - Rect.Bottom = (OrigY + LabelHeight - 1); + SWM_RECT_INIT2 ( + Rect, + OrigX, + OrigY, + LabelWidth, + LabelHeight + ); L->Ctor ( L, diff --git a/MsGraphicsPkg/Library/SimpleUIToolKit/ListBox.c b/MsGraphicsPkg/Library/SimpleUIToolKit/ListBox.c index 249810a221..fcc42d1a73 100644 --- a/MsGraphicsPkg/Library/SimpleUIToolKit/ListBox.c +++ b/MsGraphicsPkg/Library/SimpleUIToolKit/ListBox.c @@ -208,9 +208,9 @@ RenderCellTrashcan ( pBltBuffer->Image.Screen = mUITGop; Left = this->m_pCells[CellIndex].CellTrashcanBounds.Left + - (this->m_pCells[CellIndex].CellTrashcanBounds.Right - this->m_pCells[CellIndex].CellTrashcanBounds.Left - MsUiGetLargeFontHeight ()) / 2; + (SWM_RECT_WIDTH (this->m_pCells[CellIndex].CellTrashcanBounds) - MsUiGetLargeFontWidth ()) / 2; Top = this->m_pCells[CellIndex].CellTrashcanBounds.Top + - (this->m_pCells[CellIndex].CellTrashcanBounds.Bottom - this->m_pCells[CellIndex].CellTrashcanBounds.Top - MsUiGetLargeFontHeight ()) / 2; + (SWM_RECT_HEIGHT (this->m_pCells[CellIndex].CellTrashcanBounds) - MsUiGetLargeFontHeight ()) / 2; Status = mUITSWM->StringToWindow ( mUITSWM, @@ -337,8 +337,8 @@ RenderCell ( CopyMem (&StringInfo->BackgroundColor, pFillColor, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); // Render cell background. // - UINT32 CellWidth = (pCell->CellBounds.Right - pCell->CellBounds.Left + 1); - UINT32 CellHeight = (pCell->CellBounds.Bottom - pCell->CellBounds.Top + 1); + UINT32 CellWidth = SWM_RECT_WIDTH (pCell->CellBounds); + UINT32 CellHeight = SWM_RECT_HEIGHT (pCell->CellBounds); mUITSWM->BltWindow ( mUITSWM, @@ -359,8 +359,8 @@ RenderCell ( // pCellRingColor = (CellIndex == this->m_HighlightedCell ? &gMsColorTable.ListBoxHighlightBoundColor : pFillColor); - CellWidth = (pCell->CellBounds.Right - pCell->CellBounds.Left -(2 * UIT_LB_OUTER_BORDER_WIDTH)+ 1); - CellHeight = (pCell->CellBounds.Bottom - pCell->CellBounds.Top -(2 * UIT_LB_OUTER_BORDER_WIDTH)+ 1); + CellWidth = (SWM_RECT_WIDTH (pCell->CellBounds) - (2 * UIT_LB_OUTER_BORDER_WIDTH)); + CellHeight = (SWM_RECT_HEIGHT (pCell->CellBounds) - (2 * UIT_LB_OUTER_BORDER_WIDTH)); DrawRectangleOutline ( (pCell->CellBounds.Left + UIT_LB_OUTER_BORDER_WIDTH), @@ -374,11 +374,11 @@ RenderCell ( // If the listbox was created with the checkbox option flag, draw a checkbox. // if ((this->m_Flags & UIT_LISTBOX_FLAGS_CHECKBOX) == UIT_LISTBOX_FLAGS_CHECKBOX) { - UINT32 CheckBoxHitAreaHeight = (pCell->CellCheckBoxBounds.Bottom - pCell->CellCheckBoxBounds.Top + 1); + UINT32 CheckBoxHitAreaHeight = SWM_RECT_HEIGHT (pCell->CellCheckBoxBounds); UINT32 CheckBoxHeight = (CheckBoxHitAreaHeight / 3); // TODO - 1/3 the height of a listbox cell? UINT32 CheckBoxWidth = CheckBoxHeight; - UINT32 CheckBoxOrigY = (pCell->CellCheckBoxBounds.Top + (CheckBoxHitAreaHeight / 2) - (CheckBoxHeight / 2)); - UINT32 CheckBoxOrigX = (pCell->CellCheckBoxBounds.Left + (CheckBoxHitAreaHeight / 2) - (CheckBoxHeight / 2)); + UINT32 CheckBoxOrigY = (pCell->CellCheckBoxBounds.Top + ((CheckBoxHitAreaHeight - CheckBoxHeight) / 2)); + UINT32 CheckBoxOrigX = (pCell->CellCheckBoxBounds.Left + ((CheckBoxHitAreaHeight - CheckBoxHeight) / 2)); RenderCellCheckBox ( this, @@ -928,10 +928,13 @@ Ctor ( for (this->m_NumberOfCells = 0; CellData[this->m_NumberOfCells].CellText != NULL; this->m_NumberOfCells++) { } - this->m_ListBoxBounds.Left = CellBox.Left; - this->m_ListBoxBounds.Top = CellBox.Top; - this->m_ListBoxBounds.Right = CellBox.Right; - this->m_ListBoxBounds.Bottom = (CellBox.Top + ((CellBox.Bottom - CellBox.Top + 1) * this->m_NumberOfCells)); + SWM_RECT_INIT2 ( + this->m_ListBoxBounds, + CellBox.Left, + CellBox.Top, + SWM_RECT_WIDTH (CellBox), + (SWM_RECT_HEIGHT (CellBox) * this->m_NumberOfCells) + ); this->m_pCells = AllocateZeroPool (this->m_NumberOfCells * sizeof (CellDisplayInfo)); ASSERT (NULL != this->m_pCells); @@ -959,10 +962,15 @@ Ctor ( if (UIT_LISTBOX_FLAGS_CHECKBOX == (this->m_Flags & UIT_LISTBOX_FLAGS_CHECKBOX)) { SWM_RECT *CellBounds = &this->m_pCells[Index].CellBounds; - CopyMem (&this->m_pCells[Index].CellCheckBoxBounds, CellBounds, sizeof (SWM_RECT)); + CheckBoxHitAreaWidth = SWM_RECT_HEIGHT (*CellBounds); - CheckBoxHitAreaWidth = (CellBounds->Bottom - CellBounds->Top + 1); - this->m_pCells[Index].CellCheckBoxBounds.Right = (CellBounds->Left + CheckBoxHitAreaWidth); + SWM_RECT_INIT2 ( + this->m_pCells[Index].CellCheckBoxBounds, + CellBounds->Left, + CellBounds->Top, + CheckBoxHitAreaWidth, + SWM_RECT_HEIGHT (*CellBounds) + ); } // If this is a checkbox type ListBox, compute the checkbox bounding rectangle. @@ -970,10 +978,15 @@ Ctor ( if (UIT_LISTBOX_FLAGS_ALLOW_DELETE == (this->m_Flags & UIT_LISTBOX_FLAGS_ALLOW_DELETE)) { SWM_RECT *CellBounds = &this->m_pCells[Index].CellBounds; - CopyMem (&this->m_pCells[Index].CellTrashcanBounds, CellBounds, sizeof (SWM_RECT)); + TrashcanHitAreaWidth = SWM_RECT_HEIGHT (*CellBounds); - TrashcanHitAreaWidth = (CellBounds->Bottom - CellBounds->Top + 1); - this->m_pCells[Index].CellTrashcanBounds.Left = (CellBounds->Right - TrashcanHitAreaWidth); + SWM_RECT_INIT2 ( + this->m_pCells[Index].CellTrashcanBounds, + CellBounds->Left, + CellBounds->Top, + CheckBoxHitAreaWidth, + SWM_RECT_HEIGHT (*CellBounds) + ); } // Calculate cell text bounding rectangle (cell text should be vertically centered in the cell, accounting for the maximum font glyph descent). Also, @@ -997,18 +1010,22 @@ Ctor ( &MaxGlyphDescent ); - UINT32 CellHeight = (this->m_pCells[Index].CellBounds.Bottom - this->m_pCells[Index].CellBounds.Top + 1); - UINT32 StringWidth = (this->m_pCells[Index].CellTextBounds.Right - this->m_pCells[Index].CellTextBounds.Left + 1); - UINT32 StringHeight = (this->m_pCells[Index].CellTextBounds.Bottom - this->m_pCells[Index].CellTextBounds.Top + 1); + UINT32 CellHeight = SWM_RECT_HEIGHT (this->m_pCells[Index].CellBounds); + UINT32 StringWidth = SWM_RECT_WIDTH (this->m_pCells[Index].CellTextBounds); + UINT32 StringHeight = SWM_RECT_HEIGHT (this->m_pCells[Index].CellTextBounds); - this->m_pCells[Index].CellTextBounds.Right = (this->m_pCells[Index].CellTextBounds.Left + StringWidth - 1); - this->m_pCells[Index].CellTextBounds.Top += ((CellHeight / 2) - (StringHeight / 2) + MaxGlyphDescent); - this->m_pCells[Index].CellTextBounds.Bottom = (this->m_pCells[Index].CellTextBounds.Top + StringHeight + MaxGlyphDescent - 1); + SWM_RECT_INIT2 ( + this->m_pCells[Index].CellTextBounds, + this->m_pCells[Index].CellTextBounds.Left, + this->m_pCells[Index].CellTextBounds.Top + (((CellHeight - StringHeight) / 2) + MaxGlyphDescent), + StringWidth, + StringHeight + MaxGlyphDescent + ); // Increment to the next cell position. // - Rect.Top += (CellBox.Bottom - CellBox.Top + 1); - Rect.Bottom += (CellBox.Bottom - CellBox.Top + 1); + Rect.Top += SWM_RECT_HEIGHT (CellBox); + Rect.Bottom += SWM_RECT_HEIGHT (CellBox); } // Member Variables @@ -1098,10 +1115,13 @@ new_ListBox ( LB->Ctor = &Ctor; LB->Base.Dtor = &Dtor; - Rect.Left = OrigX; - Rect.Right = (OrigX + CellWidth - 1); - Rect.Top = OrigY; - Rect.Bottom = (OrigY + CellHeight - 1); + SWM_RECT_INIT2 ( + Rect, + OrigX, + OrigY, + CellWidth, + CellHeight + ); LB->Ctor ( LB, diff --git a/MsGraphicsPkg/Library/SimpleUIToolKit/ProgressBar.c b/MsGraphicsPkg/Library/SimpleUIToolKit/ProgressBar.c index 49e4347583..542aed6f1f 100644 --- a/MsGraphicsPkg/Library/SimpleUIToolKit/ProgressBar.c +++ b/MsGraphicsPkg/Library/SimpleUIToolKit/ProgressBar.c @@ -46,8 +46,8 @@ RenderProgressBar ( // Compute progres bar width and height. // - Width = (this->m_pProgressBar->ProgressBarBoundsCurrent.Right - this->m_pProgressBar->ProgressBarBoundsCurrent.Left + 1); - Height = (this->m_pProgressBar->ProgressBarBoundsCurrent.Bottom - this->m_pProgressBar->ProgressBarBoundsCurrent.Top + 1); + Width = SWM_RECT_WIDTH (this->m_pProgressBar->ProgressBarBoundsCurrent); + Height = SWM_RECT_HEIGHT (this->m_pProgressBar->ProgressBarBoundsCurrent); // Draw the progress bar background first. // @@ -68,7 +68,7 @@ RenderProgressBar ( // Draw the progress bar color next. // - Width = (((this->m_pProgressBar->ProgressBarBoundsCurrent.Right - this->m_pProgressBar->ProgressBarBoundsCurrent.Left + 1) * this->m_BarPercent) / 100); + Width = ((SWM_RECT_WIDTH (this->m_pProgressBar->ProgressBarBoundsCurrent) * this->m_BarPercent) / 100); mUITSWM->BltWindow ( mUITSWM, @@ -261,10 +261,13 @@ new_ProgressBar ( P->Ctor = &Ctor; P->Base.Dtor = &Dtor; - Rect.Left = OrigX; - Rect.Right = (OrigX + ProgressBarWidth - 1); - Rect.Top = OrigY; - Rect.Bottom = (OrigY + ProgressBarHeight - 1); + SWM_RECT_INIT2 ( + Rect, + OrigX, + OrigY, + ProgressBarWidth, + ProgressBarHeight + ); P->Ctor ( P, diff --git a/MsGraphicsPkg/Library/SimpleUIToolKit/ToggleSwitch.c b/MsGraphicsPkg/Library/SimpleUIToolKit/ToggleSwitch.c index c55624afe9..153cf3e0d1 100644 --- a/MsGraphicsPkg/Library/SimpleUIToolKit/ToggleSwitch.c +++ b/MsGraphicsPkg/Library/SimpleUIToolKit/ToggleSwitch.c @@ -114,8 +114,8 @@ DrawElongatedCircle ( Xarc = sqrt_d ((double)((HalfHeight * HalfHeight) - (Step * Step))); // Not sure why '^' doesn't work. Xstart = (OrigX - (UINT32)Xarc); - Xend = (OrigX + Width + (UINT32)Xarc); - Length = (Xend - Xstart); + Xend = (OrigX + Width + (UINT32)Xarc - 1); + Length = (Xend - Xstart + 1); Y1 = (OrigY + HalfHeight - Step); Y2 = (OrigY + HalfHeight + Step); @@ -153,8 +153,8 @@ CreateToggleSwitchBitmaps ( // Calculate the width and height of the bitmaps, leaving room for the keyboard TAB highlight ring. // - Width = (this->m_pToggleSwitch->ToggleSwitchBounds.Right - this->m_pToggleSwitch->ToggleSwitchBounds.Left + 1); - Height = (this->m_pToggleSwitch->ToggleSwitchBounds.Bottom - this->m_pToggleSwitch->ToggleSwitchBounds.Top + 1); + Width = SWM_RECT_WIDTH (this->m_pToggleSwitch->ToggleSwitchBounds); + Height = SWM_RECT_HEIGHT (this->m_pToggleSwitch->ToggleSwitchBounds); BitmapSize = (Width * Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); // Save width and height for later. @@ -480,7 +480,7 @@ RenderToggleSwitch ( } SWM_RECT *pRect = &this->m_pToggleSwitch->ToggleSwitchBounds; - UINTN SwitchOrigY = (pRect->Top + ((pRect->Bottom - pRect->Top + 1) / 2) - ((StringRect.Bottom - StringRect.Top + 1) / 2)); + UINTN SwitchOrigY = (pRect->Top + ((SWM_RECT_HEIGHT (*pRect) - SWM_RECT_HEIGHT (StringRect)) / 2)); mUITSWM->StringToWindow ( mUITSWM, @@ -667,7 +667,7 @@ Draw ( this->m_pToggleSwitch->State = NORMAL; // Indicate not selected at this time. // Calculate whether switch should be turned on or off. // - if (pInputState->State.TouchState.CurrentX < (pRect->Left + ((pRect->Right - pRect->Left) / 2))) { + if (pInputState->State.TouchState.CurrentX < (pRect->Left + (SWM_RECT_WIDTH (*pRect) / 2))) { if (TRUE == this->m_CurrentState) { this->m_pToggleSwitch->State = SELECT; // Mouse button isn't pressed and switch will move On -> Off - select. Context = this->m_pSelectionContext; @@ -845,10 +845,13 @@ new_ToggleSwitch ( S->Ctor = &Ctor; S->Base.Dtor = &Dtor; - Rect.Left = OrigX; - Rect.Right = (OrigX + ToggleSwitchWidth - 1); - Rect.Top = OrigY; - Rect.Bottom = (OrigY + ToggleSwitchHeight - 1); + SWM_RECT_INIT2 ( + Rect, + OrigX, + OrigY, + ToggleSwitchWidth, + ToggleSwitchHeight + ); S->Ctor ( S, diff --git a/MsGraphicsPkg/Library/SimpleUIToolKit/Utilities.c b/MsGraphicsPkg/Library/SimpleUIToolKit/Utilities.c index c233483f84..fd0795dfeb 100644 --- a/MsGraphicsPkg/Library/SimpleUIToolKit/Utilities.c +++ b/MsGraphicsPkg/Library/SimpleUIToolKit/Utilities.c @@ -46,8 +46,8 @@ GetTextStringBitmapSize ( // Calculate maximum width and height allowed by the specified bounding rectangle. // if (TRUE == BoundsLimit) { - Width = (UINT16)(Bounds->Right - Bounds->Left + 1); - Height = (UINT16)(Bounds->Bottom - Bounds->Top + 1); + Width = (UINT16)SWM_RECT_WIDTH (*Bounds); + Height = (UINT16)SWM_RECT_HEIGHT (*Bounds); } else { // Caller hasn't provided any boundary to enforce. Assume we have the whole screen. // diff --git a/MsGraphicsPkg/Library/SwmDialogsLib/MessageBox.c b/MsGraphicsPkg/Library/SwmDialogsLib/MessageBox.c index 7c0af43203..faf5d121b0 100644 --- a/MsGraphicsPkg/Library/SwmDialogsLib/MessageBox.c +++ b/MsGraphicsPkg/Library/SwmDialogsLib/MessageBox.c @@ -68,8 +68,8 @@ CreateDialogControls ( EFI_STATUS Status = EFI_SUCCESS; UINT32 DialogOrigX = DialogBounds.Left; UINT32 DialogOrigY = DialogBounds.Top; - UINT32 DialogWidth = (DialogBounds.Right - DialogBounds.Left + 1); - UINT32 DialogHeight = (DialogBounds.Bottom - DialogBounds.Top + 1); + UINT32 DialogWidth = SWM_RECT_WIDTH (DialogBounds); + UINT32 DialogHeight = SWM_RECT_HEIGHT (DialogBounds); SWM_RECT StringRect; SWM_RECT ControlBounds; UINT32 ControlOrigX, ControlOrigY; @@ -184,6 +184,14 @@ CreateDialogControls ( ControlOrigX = (DialogOrigX + ((DialogWidth * SWM_MB_DIALOG_CAPTION_X_PERCENT) / 100)); ControlOrigY = (DialogOrigY + ((DialogHeight * SWM_MB_DIALOG_CAPTION_Y_PERCENT) / 100)); + SWM_RECT_INIT ( + ControlBounds, + ControlOrigX, + ControlOrigY, + DialogBounds.Right, + DialogBounds.Bottom + ); + // Select an appropriate font and colors for the caption text (larger font than the body). // FontInfo.FontSize = SWM_MB_CUSTOM_FONT_CAPTION_HEIGHT; @@ -195,8 +203,8 @@ CreateDialogControls ( CaptionLabel = new_Label ( ControlOrigX, ControlOrigY, - (DialogBounds.Right - ControlOrigX - ((DialogWidth * SWM_MB_DIALOG_CAPTION_X_PERCENT) / 100)), - (DialogBounds.Bottom - ControlOrigY), // In theory we could take up the entire dialog. + (SWM_RECT_WIDTH (ControlBounds) - ((DialogWidth * SWM_MB_DIALOG_CAPTION_X_PERCENT) / 100)), + SWM_RECT_HEIGHT (ControlBounds), // In theory we could take up the entire dialog. &FontInfo, &gMsColorTable.MessageBoxTextColor, BackgroundColor, @@ -224,7 +232,15 @@ CreateDialogControls ( // Calculate the appropriate place to put the dialog's body text. // - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_MB_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_MB_DIALOG_CONTROL_VERTICAL_PAD_PX); + + SWM_RECT_INIT ( + ControlBounds, + ControlOrigX, + ControlOrigY, + DialogBounds.Right, + DialogBounds.Bottom + ); // Select an appropriate font and colors for the body text. // @@ -236,8 +252,8 @@ CreateDialogControls ( BodyLabel = new_Label ( ControlOrigX, ControlOrigY, - (DialogBounds.Right - ControlOrigX - ((DialogWidth * SWM_MB_DIALOG_RIGHT_PADDING_PERCENT) / 100)), - (DialogBounds.Bottom - ControlOrigY), // In theory we could take up the entire dialog. + (SWM_RECT_WIDTH (ControlBounds) - ((DialogWidth * SWM_MB_DIALOG_RIGHT_PADDING_PERCENT) / 100)), + SWM_RECT_HEIGHT (ControlBounds), // In theory we could take up the entire dialog. &FontInfo, &gMsColorTable.MessageBoxTextColor, BackgroundColor, @@ -287,7 +303,7 @@ CreateDialogControls ( // Calculate the size and shape of the buttons. // - ControlWidth = (StringRect.Right - StringRect.Left + 1) + (SWM_MB_DIALOG_BUTTONTEXT_PADDING_PX * 2); + ControlWidth = SWM_RECT_WIDTH (StringRect) + (SWM_MB_DIALOG_BUTTONTEXT_PADDING_PX * 2); ControlHeight = (ControlWidth / SWM_MB_DIALOG_BUTTON_ASPECT_RATIO); // Calculate the position and size of the first button. @@ -450,64 +466,31 @@ DrawDialogFrame ( EFI_STATUS Status = EFI_SUCCESS; EFI_FONT_DISPLAY_INFO StringInfo; EFI_IMAGE_OUTPUT *pBltBuffer; + SWM_RECT Rect[4]; + INTN Index; // For performance reasons, drawing the frame as four individual (small) rectangles is faster than a single large rectangle. // - this->BltWindow ( - this, // Top - MessageBoxHandle, - &gMsColorTable.MessageBoxDialogFrameColor, - EfiBltVideoFill, - 0, - 0, - FrameRect.Left, - FrameRect.Top, - (FrameRect.Right - FrameRect.Left + 1), - (CanvasRect.Top - FrameRect.Top + 1), - 0 - ); - - this->BltWindow ( - this, // Left - MessageBoxHandle, - &gMsColorTable.MessageBoxDialogFrameColor, - EfiBltVideoFill, - 0, - 0, - FrameRect.Left, - CanvasRect.Top, - (CanvasRect.Left - FrameRect.Left + 1), - (FrameRect.Bottom - CanvasRect.Top + 1), - 0 - ); - - this->BltWindow ( - this, // Right - MessageBoxHandle, - &gMsColorTable.MessageBoxDialogFrameColor, - EfiBltVideoFill, - 0, - 0, - CanvasRect.Right, - CanvasRect.Top, - (FrameRect.Right - CanvasRect.Right + 1), - (FrameRect.Bottom - CanvasRect.Top + 1), - 0 - ); - - this->BltWindow ( - this, // Bottom - MessageBoxHandle, - &gMsColorTable.MessageBoxDialogFrameColor, - EfiBltVideoFill, - 0, - 0, - CanvasRect.Left, - CanvasRect.Bottom, - (CanvasRect.Right - CanvasRect.Left + 1), - (FrameRect.Bottom - CanvasRect.Bottom + 1), - 0 - ); + SWM_RECT_INIT (Rect[0], FrameRect.Left, FrameRect.Top, FrameRect.Right, CanvasRect.Top); // Top + SWM_RECT_INIT (Rect[1], FrameRect.Left, CanvasRect.Top, CanvasRect.Left, CanvasRect.Bottom); // Left + SWM_RECT_INIT (Rect[2], CanvasRect.Right, CanvasRect.Top, FrameRect.Right, CanvasRect.Bottom); // Right + SWM_RECT_INIT (Rect[3], FrameRect.Left, CanvasRect.Bottom, FrameRect.Right, FrameRect.Bottom); // Bottom + + for (Index = 0; Index < 4; Index++) { + this->BltWindow ( + this, + MessageBoxHandle, + &gMsColorTable.MessageBoxDialogFrameColor, + EfiBltVideoFill, + 0, + 0, + Rect[Index].Left, + Rect[Index].Top, + SWM_RECT_WIDTH (Rect[Index]), + SWM_RECT_HEIGHT (Rect[Index]), + 0 + ); + } // For performance reasons, the canvas has been designed not to paint the entire dialog background. Instead it only knows how to clear // current child control bounding rectanges. So we fill in the entire dialog background once, here. @@ -521,8 +504,8 @@ DrawDialogFrame ( 0, CanvasRect.Left, CanvasRect.Top, - (CanvasRect.Right - CanvasRect.Left + 1), - (CanvasRect.Bottom - CanvasRect.Top + 1), + SWM_RECT_WIDTH (CanvasRect), + SWM_RECT_HEIGHT (CanvasRect), 0 ); @@ -572,8 +555,8 @@ DrawDialogFrame ( // Render the string to the screen, vertically centered. // - UINT32 FrameWidth = (FrameRect.Right - FrameRect.Left + 1); - UINT32 TitleBarHeight = (CanvasRect.Top - FrameRect.Top + 1); + UINT32 FrameWidth = SWM_RECT_WIDTH (FrameRect); + UINT32 TitleBarHeight = (CanvasRect.Top - FrameRect.Top); this->StringToWindow ( this, @@ -585,7 +568,7 @@ DrawDialogFrame ( &StringInfo, &pBltBuffer, (FrameRect.Left + ((FrameWidth * SWM_MB_DIALOG_TITLEBAR_TEXT_X_PERCENT) / 100)), - (FrameRect.Top + ((TitleBarHeight / 2) - ((StringRect.Bottom - StringRect.Top + 1) / 2)) + MaxDescent), // Vertically center in the titlebar. + (FrameRect.Top + ((TitleBarHeight - SWM_RECT_HEIGHT (StringRect)) / 2) + MaxDescent), // Vertically center in the titlebar. NULL, NULL, NULL @@ -626,7 +609,7 @@ CreateMessageBoxDialog ( ) { EFI_STATUS Status = EFI_SUCCESS; - UINT32 DialogHeight = (FrameRect.Bottom - FrameRect.Top + 1); + UINT32 DialogHeight = SWM_RECT_HEIGHT (FrameRect); SWM_RECT CanvasRect; EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackgroundColor; @@ -644,10 +627,13 @@ CreateMessageBoxDialog ( // Since we have a dialog titlebar and frame, the actual canvas area of the dialog is smaller. // - CanvasRect.Left = (FrameRect.Left + SWM_MB_DIALOG_FRAME_WIDTH_PX); - CanvasRect.Top = (FrameRect.Top + ((DialogHeight * SWM_MB_DIALOG_TITLEBAR_HEIGHT_PERCENT) / 100)); - CanvasRect.Right = (FrameRect.Right - SWM_MB_DIALOG_FRAME_WIDTH_PX); - CanvasRect.Bottom = (FrameRect.Bottom - SWM_MB_DIALOG_FRAME_WIDTH_PX); + SWM_RECT_INIT ( + CanvasRect, + (FrameRect.Left + SWM_MB_DIALOG_FRAME_WIDTH_PX), + (FrameRect.Top + ((DialogHeight * SWM_MB_DIALOG_TITLEBAR_HEIGHT_PERCENT) / 100)), + (FrameRect.Right - SWM_MB_DIALOG_FRAME_WIDTH_PX), + (FrameRect.Bottom - SWM_MB_DIALOG_FRAME_WIDTH_PX) + ); // Create a canvas and all of the child controls that make up the Single Select Dialog. // @@ -946,10 +932,13 @@ MessageBoxInternal ( // need to share screen real estate and therefore cooperate for pointer event input. When the OSK is displayed, the // dialog will be shifted up vertically to make room. // - FrameRect.Left = DialogOrigX; - FrameRect.Top = DialogOrigY; - FrameRect.Right = (DialogOrigX + DialogWidth - 1); - FrameRect.Bottom = (DialogOrigY + DialogHeight - 1); + SWM_RECT_INIT2 ( + FrameRect, + DialogOrigX, + DialogOrigY, + DialogWidth, + DialogHeight + ); // Register with the Simple Window Manager to get mouse and touch input events. // diff --git a/MsGraphicsPkg/Library/SwmDialogsLib/PasswordDialog.c b/MsGraphicsPkg/Library/SwmDialogsLib/PasswordDialog.c index 3d5df94cd0..ef14a3d543 100644 --- a/MsGraphicsPkg/Library/SwmDialogsLib/PasswordDialog.c +++ b/MsGraphicsPkg/Library/SwmDialogsLib/PasswordDialog.c @@ -152,8 +152,8 @@ CreateDialogControls ( EFI_STATUS Status = EFI_SUCCESS; UINT32 DialogOrigX = DialogBounds.Left; UINT32 DialogOrigY = DialogBounds.Top; - UINT32 DialogWidth = (DialogBounds.Right - DialogBounds.Left + 1); - UINT32 DialogHeight = (DialogBounds.Bottom - DialogBounds.Top + 1); + UINT32 DialogWidth = SWM_RECT_WIDTH (DialogBounds); + UINT32 DialogHeight = SWM_RECT_HEIGHT (DialogBounds); SWM_RECT StringRect; SWM_RECT ControlBounds; UINT32 ControlOrigX, ControlOrigY; @@ -183,6 +183,14 @@ CreateDialogControls ( ControlOrigX = (DialogOrigX + ((DialogWidth * SWM_PWD_DIALOG_CAPTION_X_PERCENT) / 100)); ControlOrigY = (DialogOrigY + ((DialogHeight * SWM_PWD_DIALOG_CAPTION_Y_PERCENT) / 100)); + SWM_RECT_INIT ( + ControlBounds, + ControlOrigX, + ControlOrigY, + DialogBounds.Right, + DialogBounds.Bottom + ); + // Select an appropriate font and colors for the caption text (larger font than the body). // FontInfo.FontSize = SWM_PWD_CUSTOM_FONT_CAPTION_HEIGHT; @@ -194,8 +202,8 @@ CreateDialogControls ( CaptionLabel = new_Label ( ControlOrigX, ControlOrigY, - (DialogBounds.Right - ControlOrigX - ((DialogWidth * SWM_PWD_DIALOG_CAPTION_X_PERCENT) / 100)), - (DialogBounds.Bottom - ControlOrigY), // In theory we could take up the entire dialog. + (SWM_RECT_WIDTH (ControlBounds) - ((DialogWidth * SWM_PWD_DIALOG_CAPTION_X_PERCENT) / 100)), + SWM_RECT_HEIGHT (ControlBounds), // In theory we could take up the entire dialog. &FontInfo, &DialogTheme.DialogTextColor, &DialogTheme.DialogBackGroundColor, @@ -223,7 +231,15 @@ CreateDialogControls ( // Calculate the appropriate place to put the dialog's body text. // - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + + SWM_RECT_INIT ( + ControlBounds, + ControlOrigX, + ControlOrigY, + DialogBounds.Right, + DialogBounds.Bottom + ); // Select an appropriate font and colors for the body text. // @@ -235,8 +251,8 @@ CreateDialogControls ( BodyLabel = new_Label ( ControlOrigX, ControlOrigY, - (DialogBounds.Right - ControlOrigX - ((DialogWidth * SWM_PWD_DIALOG_RIGHT_PADDING_PERCENT) / 100)), - (DialogBounds.Bottom - ControlOrigY), // In theory we could take up the entire dialog. + (SWM_RECT_WIDTH (ControlBounds) - ((DialogWidth * SWM_PWD_DIALOG_RIGHT_PADDING_PERCENT) / 100)), + SWM_RECT_HEIGHT (ControlBounds), // In theory we could take up the entire dialog. &FontInfo, &DialogTheme.DialogTextColor, &DialogTheme.DialogBackGroundColor, @@ -264,7 +280,7 @@ CreateDialogControls ( // Calculate the appropriate place to put the dialog's password editbox. // - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); // Select an appropriate font and colors for the body text. // @@ -312,7 +328,7 @@ CreateDialogControls ( &ControlBounds ); - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); // Create the editbox for new password confirmation input. // @@ -350,7 +366,7 @@ CreateDialogControls ( &ControlBounds ); - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); break; } case SWM_PWD_TYPE_ALERT_PASSWORD: @@ -396,7 +412,7 @@ CreateDialogControls ( &ControlBounds ); - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); break; } } @@ -457,7 +473,7 @@ CreateDialogControls ( // Calculate the position and size of the first button. // - ControlWidth = (StringRect.Right - StringRect.Left + 1) + (SWM_PWD_DIALOG_BUTTONTEXT_PADDING_PX * 2); + ControlWidth = SWM_RECT_WIDTH (StringRect) + (SWM_PWD_DIALOG_BUTTONTEXT_PADDING_PX * 2); ControlHeight = (ControlWidth / SWM_PWD_DIALOG_BUTTON_ASPECT_RATIO); // Calculate the total width of the buttons plus the padding in between them TotalControlWidth = ControlWidth * (200 + SWM_PWD_DIALOG_BUTTON_SPACE_PERCENT) / 100; // the control width is 2 buttons + 30% spacing @@ -592,64 +608,31 @@ DrawDialogFrame ( EFI_STATUS Status = EFI_SUCCESS; EFI_FONT_DISPLAY_INFO StringInfo; EFI_IMAGE_OUTPUT *pBltBuffer; + SWM_RECT Rect[4]; + INTN Index; // For performance reasons, drawing the frame as four individual (small) rectangles is faster than a single large rectangle. // - this->BltWindow ( - this, // Top - gImageHandle, - &DialogTheme.DialogFrameColor, - EfiBltVideoFill, - 0, - 0, - FrameRect.Left, - FrameRect.Top, - (FrameRect.Right - FrameRect.Left + 1), - (CanvasRect.Top - FrameRect.Top + 1), - 0 - ); - - this->BltWindow ( - this, // Left - gImageHandle, - &DialogTheme.DialogFrameColor, - EfiBltVideoFill, - 0, - 0, - FrameRect.Left, - CanvasRect.Top, - (CanvasRect.Left - FrameRect.Left + 1), - (FrameRect.Bottom - CanvasRect.Top + 1), - 0 - ); - - this->BltWindow ( - this, // Right - gImageHandle, - &DialogTheme.DialogFrameColor, - EfiBltVideoFill, - 0, - 0, - CanvasRect.Right, - CanvasRect.Top, - (FrameRect.Right - CanvasRect.Right + 1), - (FrameRect.Bottom - CanvasRect.Top + 1), - 0 - ); - - this->BltWindow ( - this, // Bottom - gImageHandle, - &DialogTheme.DialogFrameColor, - EfiBltVideoFill, - 0, - 0, - CanvasRect.Left, - CanvasRect.Bottom, - (CanvasRect.Right - CanvasRect.Left + 1), - (FrameRect.Bottom - CanvasRect.Bottom + 1), - 0 - ); + SWM_RECT_INIT (Rect[0], FrameRect.Left, FrameRect.Top, FrameRect.Right, CanvasRect.Top); // Top + SWM_RECT_INIT (Rect[1], FrameRect.Left, CanvasRect.Top, CanvasRect.Left, CanvasRect.Bottom); // Left + SWM_RECT_INIT (Rect[2], CanvasRect.Right, CanvasRect.Top, FrameRect.Right, CanvasRect.Bottom); // Right + SWM_RECT_INIT (Rect[3], FrameRect.Left, CanvasRect.Bottom, FrameRect.Right, FrameRect.Bottom); // Bottom + + for (Index = 0; Index < 4; Index++) { + this->BltWindow ( + this, + gImageHandle, + &DialogTheme.DialogFrameColor, + EfiBltVideoFill, + 0, + 0, + Rect[Index].Left, + Rect[Index].Top, + SWM_RECT_WIDTH (Rect[Index]), + SWM_RECT_HEIGHT (Rect[Index]), + 0 + ); + } // For performance reasons, the canvas has been designed not to paint the entire dialog background. Instead it only knows how to clear // current child control bounding rectanges. So we fill in the entire dialog background once, here. @@ -663,8 +646,8 @@ DrawDialogFrame ( 0, CanvasRect.Left, CanvasRect.Top, - (CanvasRect.Right - CanvasRect.Left + 1), - (CanvasRect.Bottom - CanvasRect.Top + 1), + SWM_RECT_WIDTH (CanvasRect), + SWM_RECT_HEIGHT (CanvasRect), 0 ); @@ -714,8 +697,8 @@ DrawDialogFrame ( // Render the string to the screen, vertically centered. // - UINT32 FrameWidth = (FrameRect.Right - FrameRect.Left + 1); - UINT32 TitleBarHeight = (CanvasRect.Top - FrameRect.Top + 1); + UINT32 FrameWidth = SWM_RECT_WIDTH (FrameRect); + UINT32 TitleBarHeight = (CanvasRect.Top - FrameRect.Top); this->StringToWindow ( this, @@ -727,7 +710,7 @@ DrawDialogFrame ( &StringInfo, &pBltBuffer, (FrameRect.Left + ((FrameWidth * SWM_PWD_DIALOG_TITLEBAR_TEXT_X_PERCENT) / 100)), - (FrameRect.Top + ((TitleBarHeight / 2) - ((StringRect.Bottom - StringRect.Top + 1) / 2)) + MaxDescent), // Vertically center in the titlebar. + (FrameRect.Top + ((TitleBarHeight - SWM_RECT_HEIGHT (StringRect)) / 2) + MaxDescent), // Vertically center in the titlebar. NULL, NULL, NULL @@ -772,15 +755,18 @@ CreatePasswordDialog ( ) { EFI_STATUS Status = EFI_SUCCESS; - UINT32 DialogHeight = (FrameRect.Bottom - FrameRect.Top + 1); + UINT32 DialogHeight = SWM_RECT_HEIGHT (FrameRect); SWM_RECT CanvasRect; // Since we have a dialog titlebar and frame, the actual canvas area of the dialog is smaller. // - CanvasRect.Left = (FrameRect.Left + SWM_PWD_DIALOG_FRAME_WIDTH_PX); - CanvasRect.Top = (FrameRect.Top + ((DialogHeight * SWM_PWD_DIALOG_TITLEBAR_HEIGHT_PERCENT) / 100)); - CanvasRect.Right = (FrameRect.Right - SWM_PWD_DIALOG_FRAME_WIDTH_PX); - CanvasRect.Bottom = (FrameRect.Bottom - SWM_PWD_DIALOG_FRAME_WIDTH_PX); + SWM_RECT_INIT ( + CanvasRect, + (FrameRect.Left + SWM_PWD_DIALOG_FRAME_WIDTH_PX), + (FrameRect.Top + ((DialogHeight * SWM_PWD_DIALOG_TITLEBAR_HEIGHT_PERCENT) / 100)), + (FrameRect.Right - SWM_PWD_DIALOG_FRAME_WIDTH_PX), + (FrameRect.Bottom - SWM_PWD_DIALOG_FRAME_WIDTH_PX) + ); // Create a canvas and all of the child controls that make up the Password Dialog. // @@ -902,7 +888,7 @@ ProcessDialogInput ( // Calculate the vertical delta needed to center the dialog between the top of the screen and the OSK, shift everything up by that amount. The OSK // is docked, centered, at the bottom of the screen. // - UINT32 VertOffset = (FrameRect.Top - ((OSKRect.Top / 2) - ((FrameRect.Bottom - FrameRect.Top + 1) / 2))); + UINT32 VertOffset = (FrameRect.Top - ((OSKRect.Top / 2) - (SWM_RECT_HEIGHT (FrameRect) / 2))); FrameRect.Top -= VertOffset; FrameRect.Bottom -= VertOffset; @@ -1239,10 +1225,13 @@ PasswordDialogInternal ( // need to share screen real estate and therefore cooperate for pointer event input. When the OSK is displayed, the // password dialog will be shifted up vertically to make room. // - FrameRect.Left = DialogOrigX; - FrameRect.Top = DialogOrigY; - FrameRect.Right = (DialogOrigX + DialogWidth - 1); - FrameRect.Bottom = (DialogOrigY + DialogHeight - 1); + SWM_RECT_INIT2 ( + FrameRect, + DialogOrigX, + DialogOrigY, + DialogWidth, + DialogHeight + ); // Locate the on-screen keyboard (OSK) protocol. It may be used for input on a touch-only device. // diff --git a/MsGraphicsPkg/Library/SwmDialogsLib/SemmUserAuthDialog.c b/MsGraphicsPkg/Library/SwmDialogsLib/SemmUserAuthDialog.c index 9c8c9cf4c8..0c32e4d1d1 100644 --- a/MsGraphicsPkg/Library/SwmDialogsLib/SemmUserAuthDialog.c +++ b/MsGraphicsPkg/Library/SwmDialogsLib/SemmUserAuthDialog.c @@ -154,8 +154,8 @@ CreateDialogControls ( EFI_STATUS Status = EFI_SUCCESS; UINT32 DialogOrigX = DialogBounds.Left; UINT32 DialogOrigY = DialogBounds.Top; - UINT32 DialogWidth = (DialogBounds.Right - DialogBounds.Left + 1); - UINT32 DialogHeight = (DialogBounds.Bottom - DialogBounds.Top + 1); + UINT32 DialogWidth = SWM_RECT_WIDTH (DialogBounds); + UINT32 DialogHeight = SWM_RECT_HEIGHT (DialogBounds); SWM_RECT StringRect; SWM_RECT ControlBounds; UINT32 ControlOrigX, ControlOrigY, ThmbOrigX, ThmbOrigY; @@ -186,6 +186,14 @@ CreateDialogControls ( ControlOrigX = (DialogOrigX + ((DialogWidth * SWM_PWD_DIALOG_CAPTION_X_PERCENT) / 100)); ControlOrigY = (DialogOrigY + ((DialogHeight * SWM_PWD_DIALOG_CAPTION_Y_PERCENT) / 100)); + SWM_RECT_INIT ( + ControlBounds, + ControlOrigX, + ControlOrigY, + DialogBounds.Right, + DialogBounds.Bottom + ); + // Select an appropriate font and colors for the caption text (larger font than the body). // FontInfo.FontSize = SWM_PWD_CUSTOM_FONT_CAPTION_HEIGHT; @@ -197,8 +205,8 @@ CreateDialogControls ( CaptionLabel = new_Label ( ControlOrigX, ControlOrigY, - (DialogBounds.Right - ControlOrigX - ((DialogWidth * SWM_PWD_DIALOG_CAPTION_X_PERCENT) / 100)), - (DialogBounds.Bottom - ControlOrigY), // In theory we could take up the entire dialog. + (SWM_RECT_WIDTH (ControlBounds) - ((DialogWidth * SWM_PWD_DIALOG_CAPTION_X_PERCENT) / 100)), + SWM_RECT_HEIGHT (ControlBounds), // In theory we could take up the entire dialog. &FontInfo, &DialogTheme.DialogTextColor, &DialogTheme.DialogBackGroundColor, @@ -226,7 +234,15 @@ CreateDialogControls ( // Calculate the appropriate place to put the dialog's body text. // - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + + SWM_RECT_INIT ( + ControlBounds, + ControlOrigX, + ControlOrigY, + DialogBounds.Right, + DialogBounds.Bottom + ); // Select an appropriate font and colors for the body text. // @@ -238,8 +254,8 @@ CreateDialogControls ( BodyLabel = new_Label ( ControlOrigX, ControlOrigY, - (DialogBounds.Right - ControlOrigX - ((DialogWidth * SWM_PWD_DIALOG_RIGHT_PADDING_PERCENT) / 100)), - (DialogBounds.Bottom - ControlOrigY), // In theory we could take up the entire dialog. + (SWM_RECT_WIDTH (ControlBounds) - ((DialogWidth * SWM_PWD_DIALOG_RIGHT_PADDING_PERCENT) / 100)), + SWM_RECT_HEIGHT (ControlBounds), // In theory we could take up the entire dialog. &FontInfo, &DialogTheme.DialogTextColor, &DialogTheme.DialogBackGroundColor, @@ -267,15 +283,23 @@ CreateDialogControls ( // Calculate the appropriate place to put the dialog's password editbox. // - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + + SWM_RECT_INIT ( + ControlBounds, + ControlOrigX, + ControlOrigY, + DialogBounds.Right, + DialogBounds.Bottom + ); // Draw Password Dialog Cert TEXT. // CertLabel = new_Label ( ControlOrigX, ControlOrigY, - (DialogBounds.Right - ControlOrigX - ((DialogWidth * SWM_PWD_DIALOG_RIGHT_PADDING_PERCENT) / 100)), - (DialogBounds.Bottom - ControlOrigY), // In theory we could take up the entire dialog. + (SWM_RECT_WIDTH (ControlBounds) - ((DialogWidth * SWM_PWD_DIALOG_RIGHT_PADDING_PERCENT) / 100)), + SWM_RECT_HEIGHT (ControlBounds), // In theory we could take up the entire dialog. &FontInfo, &DialogTheme.DialogTextColor, &DialogTheme.DialogBackGroundColor, @@ -302,20 +326,28 @@ CreateDialogControls ( ); // Save the end of the certlabel, and calculate the positions for the Thumbprint editbox to show up next to the thumbprint text. - ThmbOrigY = ControlOrigY + (ControlBounds.Bottom - ControlBounds.Top) - (UINT32)(SWM_PWD_CUSTOM_FONT_EDITBOX_HEIGHT * 1.5); - ThmbOrigX = ControlOrigX + (ControlBounds.Right - ControlBounds.Left); + ThmbOrigY = ControlOrigY + SWM_RECT_HEIGHT (ControlBounds) - (UINT32)(SWM_PWD_CUSTOM_FONT_EDITBOX_HEIGHT * 1.5); + ThmbOrigX = ControlOrigX + SWM_RECT_WIDTH (ControlBounds); // Calculate the appropriate place to put the dialog's password editbox. // - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + + SWM_RECT_INIT ( + ControlBounds, + ControlOrigX, + ControlOrigY, + DialogBounds.Right, + DialogBounds.Bottom + ); // Draw Password Dialog Confirm TEXT. // ConfirmLabel = new_Label ( ControlOrigX, ControlOrigY, - (DialogBounds.Right - ControlOrigX - ((DialogWidth * SWM_PWD_DIALOG_RIGHT_PADDING_PERCENT) / 100)), - (DialogBounds.Bottom - ControlOrigY), // In theory we could take up the entire dialog. + (SWM_RECT_WIDTH (ControlBounds) - ((DialogWidth * SWM_PWD_DIALOG_RIGHT_PADDING_PERCENT) / 100)), + SWM_RECT_HEIGHT (ControlBounds), // In theory we could take up the entire dialog. &FontInfo, &DialogTheme.DialogTextColor, &DialogTheme.DialogBackGroundColor, @@ -341,7 +373,7 @@ CreateDialogControls ( &ControlBounds ); - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); switch (Type) { case SWM_THMB_TYPE_ALERT_PASSWORD: @@ -413,7 +445,7 @@ CreateDialogControls ( &ControlBounds ); - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); break; } case SWM_THMB_TYPE_ALERT_THUMBPRINT: @@ -456,7 +488,7 @@ CreateDialogControls ( &ControlBounds ); - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); break; } case SWM_PWD_TYPE_ALERT_PASSWORD: @@ -500,7 +532,7 @@ CreateDialogControls ( &ControlBounds ); - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_PWD_DIALOG_CONTROL_VERTICAL_PAD_PX); break; } } @@ -561,8 +593,8 @@ CreateDialogControls ( // Calculate the position and size of the first button. // - ControlWidth = (StringRect.Right - StringRect.Left + 1); - ControlHeight = (StringRect.Bottom - StringRect.Top + 1); + ControlWidth = SWM_RECT_WIDTH (StringRect); + ControlHeight = SWM_RECT_HEIGHT (StringRect); ControlOrigX = (DialogOrigX + ((DialogWidth * SWM_PWD_DIALOG_FIRST_BUTTON_X_PERCENT) / 100)); ControlOrigY = (DialogOrigY + DialogHeight) - ((DialogHeight * SWM_PWD_DIALOG_FIRST_BUTTON_Y_PERCENT) / 100); @@ -686,64 +718,31 @@ DrawDialogFrame ( EFI_STATUS Status = EFI_SUCCESS; EFI_FONT_DISPLAY_INFO StringInfo; EFI_IMAGE_OUTPUT *pBltBuffer; + SWM_RECT Rect[4]; + INTN Index; // For performance reasons, drawing the frame as four individual (small) rectangles is faster than a single large rectangle. // - this->BltWindow ( - this, // Top - gImageHandle, - &DialogTheme.DialogFrameColor, - EfiBltVideoFill, - 0, - 0, - FrameRect.Left, - FrameRect.Top, - (FrameRect.Right - FrameRect.Left + 1), - (CanvasRect.Top - FrameRect.Top + 1), - 0 - ); - - this->BltWindow ( - this, // Left - gImageHandle, - &DialogTheme.DialogFrameColor, - EfiBltVideoFill, - 0, - 0, - FrameRect.Left, - CanvasRect.Top, - (CanvasRect.Left - FrameRect.Left + 1), - (FrameRect.Bottom - CanvasRect.Top + 1), - 0 - ); - - this->BltWindow ( - this, // Right - gImageHandle, - &DialogTheme.DialogFrameColor, - EfiBltVideoFill, - 0, - 0, - CanvasRect.Right, - CanvasRect.Top, - (FrameRect.Right - CanvasRect.Right + 1), - (FrameRect.Bottom - CanvasRect.Top + 1), - 0 - ); - - this->BltWindow ( - this, // Bottom - gImageHandle, - &DialogTheme.DialogFrameColor, - EfiBltVideoFill, - 0, - 0, - CanvasRect.Left, - CanvasRect.Bottom, - (CanvasRect.Right - CanvasRect.Left + 1), - (FrameRect.Bottom - CanvasRect.Bottom + 1), - 0 - ); + SWM_RECT_INIT (Rect[0], FrameRect.Left, FrameRect.Top, FrameRect.Right, CanvasRect.Top); // Top + SWM_RECT_INIT (Rect[1], FrameRect.Left, CanvasRect.Top, CanvasRect.Left, CanvasRect.Bottom); // Left + SWM_RECT_INIT (Rect[2], CanvasRect.Right, CanvasRect.Top, FrameRect.Right, CanvasRect.Bottom); // Right + SWM_RECT_INIT (Rect[3], FrameRect.Left, CanvasRect.Bottom, FrameRect.Right, FrameRect.Bottom); // Bottom + + for (Index = 0; Index < 4; Index++) { + this->BltWindow ( + this, + gImageHandle, + &DialogTheme.DialogFrameColor, + EfiBltVideoFill, + 0, + 0, + Rect[Index].Left, + Rect[Index].Top, + SWM_RECT_WIDTH (Rect[Index]), + SWM_RECT_HEIGHT (Rect[Index]), + 0 + ); + } // For performance reasons, the canvas has been designed not to paint the entire dialog background. Instead it only knows how to clear // current child control bounding rectanges. So we fill in the entire dialog background once, here. @@ -757,8 +756,8 @@ DrawDialogFrame ( 0, CanvasRect.Left, CanvasRect.Top, - (CanvasRect.Right - CanvasRect.Left + 1), - (CanvasRect.Bottom - CanvasRect.Top + 1), + SWM_RECT_WIDTH (CanvasRect), + SWM_RECT_HEIGHT (CanvasRect), 0 ); @@ -808,8 +807,8 @@ DrawDialogFrame ( // Render the string to the screen, vertically centered. // - UINT32 FrameWidth = (FrameRect.Right - FrameRect.Left + 1); - UINT32 TitleBarHeight = (CanvasRect.Top - FrameRect.Top + 1); + UINT32 FrameWidth = SWM_RECT_WIDTH (FrameRect); + UINT32 TitleBarHeight = (CanvasRect.Top - FrameRect.Top); this->StringToWindow ( this, @@ -821,7 +820,7 @@ DrawDialogFrame ( &StringInfo, &pBltBuffer, (FrameRect.Left + ((FrameWidth * SWM_PWD_DIALOG_TITLEBAR_TEXT_X_PERCENT) / 100)), - (FrameRect.Top + ((TitleBarHeight / 2) - ((StringRect.Bottom - StringRect.Top + 1) / 2)) + MaxDescent), // Vertically center in the titlebar. + (FrameRect.Top + ((TitleBarHeight / 2) - (SWM_RECT_HEIGHT (StringRect) / 2)) + MaxDescent), // Vertically center in the titlebar. NULL, NULL, NULL @@ -868,15 +867,18 @@ CreateSemmAuthDialog ( ) { EFI_STATUS Status = EFI_SUCCESS; - UINT32 DialogHeight = (FrameRect.Bottom - FrameRect.Top + 1); + UINT32 DialogHeight = SWM_RECT_HEIGHT (FrameRect); SWM_RECT CanvasRect; // Since we have a dialog titlebar and frame, the actual canvas area of the dialog is smaller. // - CanvasRect.Left = (FrameRect.Left + SWM_PWD_DIALOG_FRAME_WIDTH_PX); - CanvasRect.Top = (FrameRect.Top + ((DialogHeight * SWM_PWD_DIALOG_TITLEBAR_HEIGHT_PERCENT) / 100)); - CanvasRect.Right = (FrameRect.Right - SWM_PWD_DIALOG_FRAME_WIDTH_PX); - CanvasRect.Bottom = (FrameRect.Bottom - SWM_PWD_DIALOG_FRAME_WIDTH_PX); + SWM_RECT_INIT ( + CanvasRect, + (FrameRect.Left + SWM_PWD_DIALOG_FRAME_WIDTH_PX), + (FrameRect.Top + ((DialogHeight * SWM_PWD_DIALOG_TITLEBAR_HEIGHT_PERCENT) / 100)), + (FrameRect.Right - SWM_PWD_DIALOG_FRAME_WIDTH_PX), + (FrameRect.Bottom - SWM_PWD_DIALOG_FRAME_WIDTH_PX) + ); // Create a canvas and all of the child controls that make up the Password Dialog. // @@ -1002,7 +1004,7 @@ ProcessDialogInput ( // Calculate the vertical delta needed to center the dialog between the top of the screen and the OSK, shift everything up by that amount. The OSK // is docked, centered, at the bottom of the screen. // - UINT32 VertOffset = (FrameRect.Top - ((OSKRect.Top / 2) - ((FrameRect.Bottom - FrameRect.Top + 1) / 2))); + UINT32 VertOffset = (FrameRect.Top - ((OSKRect.Top / 2) - (SWM_RECT_HEIGHT (FrameRect) / 2))); FrameRect.Top -= VertOffset; FrameRect.Bottom -= VertOffset; @@ -1334,10 +1336,13 @@ VerifyThumbprintInternal ( // need to share screen real estate and therefore cooperate for pointer event input. When the OSK is displayed, the // password dialog will be shifted up vertically to make room. // - FrameRect.Left = DialogOrigX; - FrameRect.Top = DialogOrigY; - FrameRect.Right = (DialogOrigX + DialogWidth - 1); - FrameRect.Bottom = (DialogOrigY + DialogHeight - 1); + SWM_RECT_INIT2 ( + FrameRect, + DialogOrigX, + DialogOrigY, + DialogWidth, + DialogHeight + ); // Locate the on-screen keyboard (OSK) protocol. It may be used for input on a touch-only device. // diff --git a/MsGraphicsPkg/Library/SwmDialogsLib/SingleSelectDialog.c b/MsGraphicsPkg/Library/SwmDialogsLib/SingleSelectDialog.c index 6f08854649..6b2d91dbd1 100644 --- a/MsGraphicsPkg/Library/SwmDialogsLib/SingleSelectDialog.c +++ b/MsGraphicsPkg/Library/SwmDialogsLib/SingleSelectDialog.c @@ -88,8 +88,8 @@ CreateDialogControls ( EFI_STATUS Status = EFI_SUCCESS; UINT32 DialogOrigX = DialogBounds.Left; UINT32 DialogOrigY = DialogBounds.Top; - UINT32 DialogWidth = (DialogBounds.Right - DialogBounds.Left + 1); - UINT32 DialogHeight = (DialogBounds.Bottom - DialogBounds.Top + 1); + UINT32 DialogWidth = SWM_RECT_WIDTH (DialogBounds); + UINT32 DialogHeight = SWM_RECT_HEIGHT (DialogBounds); SWM_RECT StringRect; SWM_RECT ControlBounds; UINT32 ControlOrigX, ControlOrigY; @@ -122,6 +122,14 @@ CreateDialogControls ( ControlOrigX = (DialogOrigX + ((DialogWidth * SWM_SS_DIALOG_CAPTION_X_PERCENT) / 100)); ControlOrigY = (DialogOrigY + ((DialogHeight * SWM_SS_DIALOG_CAPTION_Y_PERCENT) / 100)); + SWM_RECT_INIT ( + ControlBounds, + ControlOrigX, + ControlOrigY, + DialogBounds.Right, + DialogBounds.Bottom + ); + // Select an appropriate font and colors for the caption text (larger font than the body). // FontInfo.FontSize = SWM_SS_CUSTOM_FONT_CAPTION_HEIGHT; @@ -133,8 +141,8 @@ CreateDialogControls ( CaptionLabel = new_Label ( ControlOrigX, ControlOrigY, - (DialogBounds.Right - ControlOrigX - ((DialogWidth * SWM_SS_DIALOG_CAPTION_X_PERCENT) / 100)), - (DialogBounds.Bottom - ControlOrigY), // In theory we could take up the entire dialog. + (SWM_RECT_WIDTH (ControlBounds) - ((DialogWidth * SWM_SS_DIALOG_CAPTION_X_PERCENT) / 100)), + SWM_RECT_HEIGHT (ControlBounds), // In theory we could take up the entire dialog. &FontInfo, &gMsColorTable.SingleSelectDialogTextColor, &gMsColorTable.SingleSelectDialogDialogBackGroundColor, @@ -162,7 +170,15 @@ CreateDialogControls ( // Calculate the appropriate place to put the dialog's body text. // - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_SS_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_SS_DIALOG_CONTROL_VERTICAL_PAD_PX); + + SWM_RECT_INIT ( + ControlBounds, + ControlOrigX, + ControlOrigY, + DialogBounds.Right, + DialogBounds.Bottom + ); // Select an appropriate font and colors for the body text. // @@ -174,8 +190,8 @@ CreateDialogControls ( BodyLabel = new_Label ( ControlOrigX, ControlOrigY, - (DialogBounds.Right - ControlOrigX - ((DialogWidth * SWM_SS_DIALOG_RIGHT_PADDING_PERCENT) / 100)), - (DialogBounds.Bottom - ControlOrigY), // In theory we could take up the entire dialog. + (SWM_RECT_WIDTH (ControlBounds) - ((DialogWidth * SWM_SS_DIALOG_RIGHT_PADDING_PERCENT) / 100)), + SWM_RECT_HEIGHT (ControlBounds), // In theory we could take up the entire dialog. &FontInfo, &gMsColorTable.SingleSelectDialogTextColor, &gMsColorTable.SingleSelectDialogDialogBackGroundColor, @@ -203,7 +219,7 @@ CreateDialogControls ( // Calculate the appropriate place to put the dialog's editbox. // - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_SS_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_SS_DIALOG_CONTROL_VERTICAL_PAD_PX); // Allocate space for the option cells. // @@ -236,7 +252,7 @@ CreateDialogControls ( goto Exit; } - TempCellWidth = (StringRect.Right - StringRect.Left + 1); + TempCellWidth = SWM_RECT_WIDTH (StringRect); if (TempCellWidth > MaxCellWidth) { MaxCellWidth = TempCellWidth; } @@ -301,7 +317,7 @@ CreateDialogControls ( &ControlBounds ); - ControlOrigY += ((ControlBounds.Bottom - ControlBounds.Top + 1) + SWM_SS_DIALOG_CONTROL_VERTICAL_PAD_PX); + ControlOrigY += (SWM_RECT_HEIGHT (ControlBounds) + SWM_SS_DIALOG_CONTROL_VERTICAL_PAD_PX); // Select an appropriate font and colors for button text. // @@ -327,8 +343,8 @@ CreateDialogControls ( // Calculate the position and size of the first button. // - ControlWidth = (StringRect.Right - StringRect.Left + 1); - ControlHeight = (StringRect.Bottom - StringRect.Top + 1); + ControlWidth = SWM_RECT_WIDTH (StringRect); + ControlHeight = SWM_RECT_HEIGHT (StringRect); ControlOrigX = (DialogOrigX + ((DialogWidth * SWM_SS_DIALOG_FIRST_BUTTON_X_PERCENT) / 100)); ControlOrigY = (DialogOrigY + DialogHeight) - ((DialogHeight * SWM_SS_DIALOG_FIRST_BUTTON_Y_PERCENT) / 100); @@ -449,64 +465,31 @@ DrawDialogFrame ( EFI_STATUS Status = EFI_SUCCESS; EFI_FONT_DISPLAY_INFO StringInfo; EFI_IMAGE_OUTPUT *pBltBuffer; + SWM_RECT Rect[4]; + INTN Index; // For performance reasons, drawing the frame as four individual (small) rectangles is faster than a single large rectangle. // - this->BltWindow ( - this, // Top - gImageHandle, - &gMsColorTable.SingleSelectDialogDialogFrameColor, - EfiBltVideoFill, - 0, - 0, - FrameRect.Left, - FrameRect.Top, - (FrameRect.Right - FrameRect.Left + 1), - (CanvasRect.Top - FrameRect.Top + 1), - 0 - ); - - this->BltWindow ( - this, // Left - gImageHandle, - &gMsColorTable.SingleSelectDialogDialogFrameColor, - EfiBltVideoFill, - 0, - 0, - FrameRect.Left, - CanvasRect.Top, - (CanvasRect.Left - FrameRect.Left + 1), - (FrameRect.Bottom - CanvasRect.Top + 1), - 0 - ); - - this->BltWindow ( - this, // Right - gImageHandle, - &gMsColorTable.SingleSelectDialogDialogFrameColor, - EfiBltVideoFill, - 0, - 0, - CanvasRect.Right, - CanvasRect.Top, - (FrameRect.Right - CanvasRect.Right + 1), - (FrameRect.Bottom - CanvasRect.Top + 1), - 0 - ); - - this->BltWindow ( - this, // Bottom - gImageHandle, - &gMsColorTable.SingleSelectDialogDialogFrameColor, - EfiBltVideoFill, - 0, - 0, - CanvasRect.Left, - CanvasRect.Bottom, - (CanvasRect.Right - CanvasRect.Left + 1), - (FrameRect.Bottom - CanvasRect.Bottom + 1), - 0 - ); + SWM_RECT_INIT (Rect[0], FrameRect.Left, FrameRect.Top, FrameRect.Right, CanvasRect.Top); // Top + SWM_RECT_INIT (Rect[1], FrameRect.Left, CanvasRect.Top, CanvasRect.Left, CanvasRect.Bottom); // Left + SWM_RECT_INIT (Rect[2], CanvasRect.Right, CanvasRect.Top, FrameRect.Right, CanvasRect.Bottom); // Right + SWM_RECT_INIT (Rect[3], FrameRect.Left, CanvasRect.Bottom, FrameRect.Right, FrameRect.Bottom); // Bottom + + for (Index = 0; Index < 4; Index++) { + this->BltWindow ( + this, + gImageHandle, + &gMsColorTable.SingleSelectDialogDialogFrameColor, + EfiBltVideoFill, + 0, + 0, + Rect[Index].Left, + Rect[Index].Top, + SWM_RECT_WIDTH (Rect[Index]), + SWM_RECT_HEIGHT (Rect[Index]), + 0 + ); + } // For performance reasons, the canvas has been designed not to paint the entire dialog background. Instead it only knows how to clear // current child control bounding rectanges. So we fill in the entire dialog background once, here. @@ -520,8 +503,8 @@ DrawDialogFrame ( 0, CanvasRect.Left, CanvasRect.Top, - (CanvasRect.Right - CanvasRect.Left + 1), - (CanvasRect.Bottom - CanvasRect.Top + 1), + SWM_RECT_WIDTH (CanvasRect), + SWM_RECT_HEIGHT (CanvasRect), 0 ); @@ -571,8 +554,8 @@ DrawDialogFrame ( // Render the string to the screen, vertically centered. // - UINT32 FrameWidth = (FrameRect.Right - FrameRect.Left + 1); - UINT32 TitleBarHeight = (CanvasRect.Top - FrameRect.Top + 1); + UINT32 FrameWidth = SWM_RECT_WIDTH (FrameRect); + UINT32 TitleBarHeight = (CanvasRect.Top - FrameRect.Top); this->StringToWindow ( this, @@ -584,7 +567,7 @@ DrawDialogFrame ( &StringInfo, &pBltBuffer, (FrameRect.Left + ((FrameWidth * SWM_SS_DIALOG_TITLEBAR_TEXT_X_PERCENT) / 100)), - (FrameRect.Top + ((TitleBarHeight / 2) - ((StringRect.Bottom - StringRect.Top + 1) / 2)) + MaxDescent), // Vertically center in the titlebar. + (FrameRect.Top + ((TitleBarHeight / 2) - (SWM_RECT_HEIGHT (StringRect) / 2)) + MaxDescent), // Vertically center in the titlebar. NULL, NULL, NULL @@ -626,15 +609,18 @@ CreateSingleSelectDialog ( ) { EFI_STATUS Status = EFI_SUCCESS; - UINT32 DialogHeight = (FrameRect.Bottom - FrameRect.Top + 1); + UINT32 DialogHeight = SWM_RECT_HEIGHT (FrameRect); SWM_RECT CanvasRect; // Since we have a dialog titlebar and frame, the actual canvas area of the dialog is smaller. // - CanvasRect.Left = (FrameRect.Left + SWM_SS_DIALOG_FRAME_WIDTH_PX); - CanvasRect.Top = (FrameRect.Top + ((DialogHeight * SWM_SS_DIALOG_TITLEBAR_HEIGHT_PERCENT) / 100)); - CanvasRect.Right = (FrameRect.Right - SWM_SS_DIALOG_FRAME_WIDTH_PX); - CanvasRect.Bottom = (FrameRect.Bottom - SWM_SS_DIALOG_FRAME_WIDTH_PX); + SWM_RECT_INIT ( + CanvasRect, + (FrameRect.Left + SWM_SS_DIALOG_FRAME_WIDTH_PX), + (FrameRect.Top + ((DialogHeight * SWM_SS_DIALOG_TITLEBAR_HEIGHT_PERCENT) / 100)), + (FrameRect.Right - SWM_SS_DIALOG_FRAME_WIDTH_PX), + (FrameRect.Bottom - SWM_SS_DIALOG_FRAME_WIDTH_PX) + ); // Create a canvas and all of the child controls that make up the Single Select Dialog. // @@ -931,10 +917,13 @@ SingleSelectDialogInternal ( // need to share screen real estate and therefore cooperate for pointer event input. When the OSK is displayed, the // dialog will be shifted up vertically to make room. // - FrameRect.Left = DialogOrigX; - FrameRect.Top = DialogOrigY; - FrameRect.Right = (DialogOrigX + DialogWidth - 1); - FrameRect.Bottom = (DialogOrigY + DialogHeight - 1); + SWM_RECT_INIT2 ( + FrameRect, + DialogOrigX, + DialogOrigY, + DialogWidth, + DialogHeight + ); // Register with the Simple Window Manager to get mouse and touch input events. // diff --git a/MsGraphicsPkg/OnScreenKeyboardDxe/OnScreenKeyboardDriver.c b/MsGraphicsPkg/OnScreenKeyboardDxe/OnScreenKeyboardDriver.c index a5850c26be..436815d43e 100644 --- a/MsGraphicsPkg/OnScreenKeyboardDxe/OnScreenKeyboardDriver.c +++ b/MsGraphicsPkg/OnScreenKeyboardDxe/OnScreenKeyboardDriver.c @@ -392,7 +392,7 @@ AllocateBackBuffers ( } mOSK.KeyboardMaxWidth = Width; - mOSK.KeyboardMaxHeight = (UINTN)((mOSK.KeyboardRectOriginal.botR.pt.y / mOSK.KeyboardRectOriginal.botR.pt.x) * (float)Width); + mOSK.KeyboardMaxHeight = (UINTN)(((mOSK.KeyboardRectOriginal.botR.pt.y + 1) / (mOSK.KeyboardRectOriginal.botR.pt.x + 1)) * (float)Width); // Allocate back buffer and capture buffer. // @@ -835,18 +835,18 @@ InitializeKeyboardGeometry ( mOSK.KeyRectOriginal[KeyCount].topL.pt.z = 0.0; mOSK.KeyRectOriginal[KeyCount].topL.pt.rsvd = 1.0; - mOSK.KeyRectOriginal[KeyCount].topR.pt.x = (KeyOrigX + KeyWidth); + mOSK.KeyRectOriginal[KeyCount].topR.pt.x = (KeyOrigX + KeyWidth - 1); mOSK.KeyRectOriginal[KeyCount].topR.pt.y = KeyOrigY; mOSK.KeyRectOriginal[KeyCount].topR.pt.z = 0.0; mOSK.KeyRectOriginal[KeyCount].topR.pt.rsvd = 1.0; mOSK.KeyRectOriginal[KeyCount].botL.pt.x = KeyOrigX; - mOSK.KeyRectOriginal[KeyCount].botL.pt.y = (KeyOrigY + KeyHeight); + mOSK.KeyRectOriginal[KeyCount].botL.pt.y = (KeyOrigY + KeyHeight - 1); mOSK.KeyRectOriginal[KeyCount].botL.pt.z = 0.0; mOSK.KeyRectOriginal[KeyCount].botL.pt.rsvd = 1.0; - mOSK.KeyRectOriginal[KeyCount].botR.pt.x = (KeyOrigX + KeyWidth); - mOSK.KeyRectOriginal[KeyCount].botR.pt.y = (KeyOrigY + KeyHeight); + mOSK.KeyRectOriginal[KeyCount].botR.pt.x = (KeyOrigX + KeyWidth - 1); + mOSK.KeyRectOriginal[KeyCount].botR.pt.y = (KeyOrigY + KeyHeight - 1); mOSK.KeyRectOriginal[KeyCount].botR.pt.z = 0.0; mOSK.KeyRectOriginal[KeyCount].botR.pt.rsvd = 1.0; @@ -875,18 +875,18 @@ InitializeKeyboardGeometry ( mOSK.KeyboardRectOriginal.topL.pt.z = 0.0; mOSK.KeyboardRectOriginal.topL.pt.rsvd = 1.0; - mOSK.KeyboardRectOriginal.topR.pt.x = (KeyOrigX - KeySpacing + (RIGHT_SPACING_PERCENT * STANDARD_KEY_WIDTH)); + mOSK.KeyboardRectOriginal.topR.pt.x = (KeyOrigX - KeySpacing + (RIGHT_SPACING_PERCENT * STANDARD_KEY_WIDTH) - 1); mOSK.KeyboardRectOriginal.topR.pt.y = 0.0; mOSK.KeyboardRectOriginal.topR.pt.z = 0.0; mOSK.KeyboardRectOriginal.topR.pt.rsvd = 1.0; mOSK.KeyboardRectOriginal.botL.pt.x = 0.0; - mOSK.KeyboardRectOriginal.botL.pt.y = (KeyOrigY + KeyHeight + KeySpacing); + mOSK.KeyboardRectOriginal.botL.pt.y = (KeyOrigY + KeyHeight + KeySpacing - 1); mOSK.KeyboardRectOriginal.botL.pt.z = 0.0; mOSK.KeyboardRectOriginal.botL.pt.rsvd = 1.0; - mOSK.KeyboardRectOriginal.botR.pt.x = (KeyOrigX - KeySpacing + (RIGHT_SPACING_PERCENT * STANDARD_KEY_WIDTH)); - mOSK.KeyboardRectOriginal.botR.pt.y = (KeyOrigY + KeyHeight + KeySpacing); + mOSK.KeyboardRectOriginal.botR.pt.x = (KeyOrigX - KeySpacing + (RIGHT_SPACING_PERCENT * STANDARD_KEY_WIDTH) - 1); + mOSK.KeyboardRectOriginal.botR.pt.y = (KeyOrigY + KeyHeight + KeySpacing - 1); mOSK.KeyboardRectOriginal.botR.pt.z = 0.0; mOSK.KeyboardRectOriginal.botR.pt.rsvd = 1.0; @@ -1070,10 +1070,13 @@ GetKeyboardIconBoundingRect ( break; } - pRect->Left = IconOrigX; - pRect->Top = IconOrigY; - pRect->Right = (IconOrigX + IconWidth - 1); - pRect->Bottom = (IconOrigY + IconHeight - 1); + SWM_RECT_INIT2 ( + *pRect, + IconOrigX, + IconOrigY, + IconWidth, + IconHeight + ); return; } @@ -1091,10 +1094,13 @@ GetKeyboardBoundingRect ( OUT SWM_RECT *pRect ) { - pRect->Left = (UINT32)mOSK.KeyboardRectXformed.topL.pt.x; - pRect->Top = (UINT32)mOSK.KeyboardRectXformed.topL.pt.y; - pRect->Right = (UINT32)mOSK.KeyboardRectXformed.topR.pt.x; - pRect->Bottom = (UINT32)mOSK.KeyboardRectXformed.botL.pt.y; + SWM_RECT_INIT ( + *pRect, + (UINT32)mOSK.KeyboardRectXformed.topL.pt.x, + (UINT32)mOSK.KeyboardRectXformed.topL.pt.y, + (UINT32)mOSK.KeyboardRectXformed.topR.pt.x, + (UINT32)mOSK.KeyboardRectXformed.botL.pt.y + ); return; } @@ -1136,8 +1142,8 @@ RenderKeyboard ( // Determine the keyboard outer bounding rectangle // GetKeyboardBoundingRect (&Rect); - KeyboardWidth = (Rect.Right - Rect.Left + 1); - KeyboardHeight = (Rect.Bottom - Rect.Top + 1); + KeyboardWidth = SWM_RECT_WIDTH (Rect); + KeyboardHeight = SWM_RECT_HEIGHT (Rect); // If the keyboard hasn't (visually) changed, we can just blt the captured buffer for better performance // @@ -1175,7 +1181,7 @@ RenderKeyboard ( Rect.Left, Rect.Top, KeyboardWidth, - (Rect.Bottom - Rect.Top + 1), + SWM_RECT_HEIGHT (Rect), KeyboardWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) ); @@ -1260,8 +1266,8 @@ RenderKeyboard ( continue; } - KeyWidth = (mOSK.KeyList[Count].KeyDisplayHitRect.Right - mOSK.KeyList[Count].KeyDisplayHitRect.Left); - KeyHeight = (mOSK.KeyList[Count].KeyDisplayHitRect.Bottom - mOSK.KeyList[Count].KeyDisplayHitRect.Top); + KeyWidth = SWM_RECT_WIDTH (mOSK.KeyList[Count].KeyDisplayHitRect); + KeyHeight = SWM_RECT_HEIGHT (mOSK.KeyList[Count].KeyDisplayHitRect); KeyOrigX = mOSK.KeyList[Count].KeyDisplayHitRect.Left; KeyOrigY = mOSK.KeyList[Count].KeyDisplayHitRect.Top; @@ -1431,13 +1437,13 @@ TranslateKeyboardLocation ( GetKeyboardBoundingRect (&Rect); if (((INTN)Rect.Left + (INTN)dx) < 0) { dx = (float)Rect.Left; // Limit at current position - } else if ((UINTN)((INTN)(Rect.Right) + (INTN)dx) >= ScreenWidth) { + } else if ((UINTN)((INTN)(Rect.Right) + (INTN)dx) >= (ScreenWidth - 1)) { dx = (float)((INTN)(ScreenWidth - 1) - (INTN)(Rect.Right)); // Limit at screen width } if (((INTN)Rect.Top + (INTN)dy) < 0) { dy = (float)Rect.Top; // Limit at current position - } else if ((UINTN)((INTN)(Rect.Bottom) + (INTN)dy) >= ScreenHeight) { + } else if ((UINTN)((INTN)(Rect.Bottom) + (INTN)dy) >= (ScreenHeight - 1)) { dy = (float)((INTN)(ScreenHeight - 1) - (INTN)(Rect.Bottom)); // Limit at screen height } @@ -1532,8 +1538,8 @@ SetKeyboardPosition ( // Get current keyboard location and size // GetKeyboardBoundingRect (&Rect); - KeyboardWidth = (Rect.Right - Rect.Left + 1); - KeyboardHeight = (Rect.Bottom - Rect.Top + 1); + KeyboardWidth = SWM_RECT_WIDTH (Rect); + KeyboardHeight = SWM_RECT_HEIGHT (Rect); // Save keyboard position for later use. // @@ -1758,8 +1764,8 @@ SetKeyboardSize ( UINTN ScreenWidth = (UINTN)mGop->Mode->Info->HorizontalResolution; UINTN ScreenHeight = (UINTN)mGop->Mode->Info->VerticalResolution; - UINTN KeyboardWidth = (UINTN)(mOSK.KeyboardRectOriginal.topR.pt.x - mOSK.KeyboardRectOriginal.topL.pt.x); - UINTN KeyboardHeight = (UINTN)(mOSK.KeyboardRectOriginal.botL.pt.y - mOSK.KeyboardRectOriginal.topL.pt.y); + UINTN KeyboardWidth = (UINTN)(mOSK.KeyboardRectOriginal.topR.pt.x - mOSK.KeyboardRectOriginal.topL.pt.x + 1); + UINTN KeyboardHeight = (UINTN)(mOSK.KeyboardRectOriginal.botL.pt.y - mOSK.KeyboardRectOriginal.topL.pt.y + 1); // Compute the maximum keyboard size scale factor based on screen dimensions // @@ -2157,9 +2163,9 @@ CheckForDockingButtonHit ( ) { UINTN ButtonLeft = ((UINTN)mOSK.DockingButtonXformed.pt.x - (mOSK.KeyboardDockButton.Width / 2)); - UINTN ButtonRight = ((UINTN)mOSK.DockingButtonXformed.pt.x + (mOSK.KeyboardDockButton.Width / 2)); + UINTN ButtonRight = ((UINTN)mOSK.DockingButtonXformed.pt.x + (mOSK.KeyboardDockButton.Width / 2) - 1); UINTN ButtonTop = ((UINTN)mOSK.DockingButtonXformed.pt.y - (mOSK.KeyboardDockButton.Height / 2)); - UINTN ButtonBottom = ((UINTN)mOSK.DockingButtonXformed.pt.y + (mOSK.KeyboardDockButton.Height / 2)); + UINTN ButtonBottom = ((UINTN)mOSK.DockingButtonXformed.pt.y + (mOSK.KeyboardDockButton.Height / 2) - 1); // If the button isn't being displayed, it shouldn't be selectable. // @@ -2187,9 +2193,9 @@ CheckForCloseButtonHit ( ) { UINTN ButtonLeft = ((UINTN)mOSK.CloseButtonXformed.pt.x - (mOSK.KeyboardCloseButton.Width / 2)); - UINTN ButtonRight = ((UINTN)mOSK.CloseButtonXformed.pt.x + (mOSK.KeyboardCloseButton.Width / 2)); + UINTN ButtonRight = ((UINTN)mOSK.CloseButtonXformed.pt.x + (mOSK.KeyboardCloseButton.Width / 2) - 1); UINTN ButtonTop = ((UINTN)mOSK.CloseButtonXformed.pt.y - (mOSK.KeyboardCloseButton.Height / 2)); - UINTN ButtonBottom = ((UINTN)mOSK.CloseButtonXformed.pt.y + (mOSK.KeyboardCloseButton.Height / 2)); + UINTN ButtonBottom = ((UINTN)mOSK.CloseButtonXformed.pt.y + (mOSK.KeyboardCloseButton.Height / 2) - 1); // If the button isn't being displayed, it shouldn't be selectable. // @@ -2375,7 +2381,7 @@ RotateKeyboard ( UINTN ScreenWidth = (UINTN)mGop->Mode->Info->HorizontalResolution; UINTN ScreenHeight = (UINTN)mGop->Mode->Info->VerticalResolution; - UINTN KeyboardWidth = (UINTN)(mOSK.KeyboardRectOriginal.topR.pt.x - mOSK.KeyboardRectOriginal.topL.pt.x); + UINTN KeyboardWidth = (UINTN)(mOSK.KeyboardRectOriginal.topR.pt.x - mOSK.KeyboardRectOriginal.topL.pt.x + 1); // Save keyboard angle for later. // @@ -3171,10 +3177,13 @@ OSKDriverInit ( // Full screen. // - FrameRect.Left = 0; - FrameRect.Top = 0; - FrameRect.Right = mGop->Mode->Info->HorizontalResolution; - FrameRect.Bottom = mGop->Mode->Info->VerticalResolution; + SWM_RECT_INIT2 ( + FrameRect, + 0, + 0, + mGop->Mode->Info->HorizontalResolution, + mGop->Mode->Info->VerticalResolution + ); // Register with the Simple Window Manager to get pointer input events. // diff --git a/MsGraphicsPkg/RenderingEngineDxe/RenderingEngine.c b/MsGraphicsPkg/RenderingEngineDxe/RenderingEngine.c index dad247fdd8..a8da39117b 100644 --- a/MsGraphicsPkg/RenderingEngineDxe/RenderingEngine.c +++ b/MsGraphicsPkg/RenderingEngineDxe/RenderingEngine.c @@ -234,10 +234,13 @@ SREBlt ( // Current blit operation bounding rectangle. // - BltRect.Left = (UINT32)(DestinationX); - BltRect.Top = (UINT32)(DestinationY); - BltRect.Right = (UINT32)(DestinationX + Width - 1); - BltRect.Bottom = (UINT32)(DestinationY + Height - 1); + SWM_RECT_INIT2 ( + BltRect, + (UINT32)DestinationX, + (UINT32)DestinationY, + (UINT32)Width, + (UINT32)Height + ); // Raise the TPL to avoid interrupting rendering and framebuffer capture. // @@ -245,10 +248,13 @@ SREBlt ( // Current mouse pointer bounding rectangle. // - PointerRect.Left = (UINT32)(mSRE.MousePointerOrigX); - PointerRect.Top = (UINT32)(mSRE.MousePointerOrigY); - PointerRect.Right = (UINT32)(mSRE.MousePointerOrigX + mSRE.MousePointerWidth - 1); - PointerRect.Bottom = (UINT32)(mSRE.MousePointerOrigY + mSRE.MousePointerHeight - 1); + SWM_RECT_INIT2 ( + PointerRect, + (UINT32)mSRE.MousePointerOrigX, + (UINT32)mSRE.MousePointerOrigY, + (UINT32)mSRE.MousePointerWidth, + (UINT32)mSRE.MousePointerHeight + ); // If the blit intersects with the mouse, we need to temporarily hide the mouse pointer. // @@ -268,8 +274,8 @@ SREBlt ( (FALSE == Surface->BlittingSurface) && ((TRUE == RectsOverlap (Surface->FrameRect, BltRect)) || (Surface->FrameChecksum != CalculateSurfaceFrameChecksum (Surface)))) { - FrameWidth = (Surface->FrameRect.Right - Surface->FrameRect.Left + 1); - FrameHeight = (Surface->FrameRect.Bottom - Surface->FrameRect.Top + 1); + FrameWidth = SWM_RECT_WIDTH (Surface->FrameRect); + FrameHeight = SWM_RECT_HEIGHT (Surface->FrameRect); // Remember that we need to notify the client to redraw. // @@ -334,8 +340,8 @@ SREBlt ( if ((FALSE == Surface->BlittingSurface) && (TRUE == RectsOverlap (Surface->FrameRect, BltRect))) { - FrameWidth = (Surface->FrameRect.Right - Surface->FrameRect.Left + 1); - FrameHeight = (Surface->FrameRect.Bottom - Surface->FrameRect.Top + 1); + FrameWidth = SWM_RECT_WIDTH (Surface->FrameRect); + FrameHeight = SWM_RECT_HEIGHT (Surface->FrameRect); // Save the contents of the framebuffer to this capture buffer. // @@ -618,8 +624,8 @@ CalculateSurfaceFrameChecksum ( IN SRE_SURFACE_LIST *Surface ) { - UINT32 Width = (Surface->FrameRect.Right - Surface->FrameRect.Left + 1); - UINT32 Height = (Surface->FrameRect.Bottom - Surface->FrameRect.Top + 1); + UINT32 Width = SWM_RECT_WIDTH (Surface->FrameRect); + UINT32 Height = SWM_RECT_HEIGHT (Surface->FrameRect); EFI_GRAPHICS_OUTPUT_BLT_PIXEL *SurfaceOrigin; UINT32 Offset; UINT32 Checksum = 0; @@ -739,8 +745,8 @@ SRECreateSurface ( // Allocate storage for the backing buffer. // - UINT32 Width = (FrameRect.Right - FrameRect.Left + 1); - UINT32 Height = (FrameRect.Bottom - FrameRect.Top + 1); + UINT32 Width = SWM_RECT_WIDTH (FrameRect); + UINT32 Height = SWM_RECT_HEIGHT (FrameRect); // Allocate a capture buffer for the surface. // @@ -835,8 +841,8 @@ SREResizeSurface ( // If the surface is active, restore the backing buffer before resizing. // if (TRUE == Surface->Active) { - Width = (Surface->FrameRect.Right - Surface->FrameRect.Left + 1); - Height = (Surface->FrameRect.Bottom - Surface->FrameRect.Top + 1); + Width = SWM_RECT_WIDTH (Surface->FrameRect); + Height = SWM_RECT_HEIGHT (Surface->FrameRect); // Restore the contents to the framebuffer. // @@ -864,8 +870,8 @@ SREResizeSurface ( // Allocate storage for the backing buffer. // - Width = (FrameRect->Right - FrameRect->Left + 1); - Height = (FrameRect->Bottom - FrameRect->Top + 1); + Width = SWM_RECT_WIDTH (*FrameRect); + Height = SWM_RECT_HEIGHT (*FrameRect); Surface->pCaptureBuffer = AllocatePool (Width * Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); ASSERT (NULL != Surface->pCaptureBuffer); @@ -968,8 +974,8 @@ SREActivateSurface ( if (Surface->ImageHandle == ImageHandle) { Surface->Active = MakeActive; - FrameWidth = (Surface->FrameRect.Right - Surface->FrameRect.Left + 1); - FrameHeight = (Surface->FrameRect.Bottom - Surface->FrameRect.Top + 1); + FrameWidth = SWM_RECT_WIDTH (Surface->FrameRect); + FrameHeight = SWM_RECT_HEIGHT (Surface->FrameRect); if (TRUE == MakeActive) { Surface->PreviousActive = ActiveSurface;