public override void Render(float elapsedms, GraphicsDevice g, SpriteBatch sb, InputManager input, float dx, float dy) { Rectangle oldrect = RenderTargetScope.Open(sb, (int)Math.Floor(dx + x), (int)Math.Floor(dy + y), Width, Height); { Lastdx = dx; Lastdy = dy; int mx = input.State.MousePos.X; int my = input.State.MousePos.Y; if (HasScrolling) { InnerX = BaseInnerX - ScrollCurrentX; InnerY = BaseInnerY - ScrollCurrentY; } BaseRender(elapsedms, g, sb, input, dx, dy); // draw scrollbars if needed if (HasScrolling) { int scw = ScrollSize + (BorderWidth * 2); if (ScrollWidth > Width) { float sfx = dx + x + BorderWidth + 2; float sfy = dy + y + Height - scw - 2 - BorderWidth; int sfw = Width - (BorderWidth * 2) - 4; int sfh = scw; Draw.DrawRectangleHandle(sb, (int)sfx, (int)sfy, sfw, sfh, TitleBackgroundColor); Draw.DrawRectangleHandleOutline(sb, (int)sfx, (int)sfy, sfw, sfh, BorderColor, BorderWidth); int sbarw = GetSliderBarWidth(false); float sliderratio = ((float)(ScrollCurrentX) / (float)((ScrollWidth - Width))); float sliderx = sfx + (sliderratio * (sfw - sbarw)); Draw.DrawRectangleHandleOutline(sb, (int)sliderx, (int)(sfy + BorderWidth), GetSliderBarWidth(false), ScrollSize, TitleFontSettings.Color, BorderWidth); if (mx > sfx && mx < sfx + sfw && my > sfy && my < sfy + sfh) { input.Cursor.TrySet(eCursorState.CLICKABLE); } } if (ScrollHeight > Height) { int hmod = BorderWidth * 2; int hstart = BorderWidth + 2; if (HasTitle) { hmod += GetTitleHeight() + 2; hstart += GetTitleHeight() + 2; } if (ScrollWidth > Width) { hmod += scw + 6; } else { hmod += 4; } float sfx = dx + x + Width - scw - 2 - BorderWidth; float sfy = dy + y + hstart; int sfw = scw; int sfh = Height - hmod; Draw.DrawRectangleHandle(sb, (int)sfx, (int)sfy, sfw, sfh, TitleBackgroundColor); Draw.DrawRectangleHandleOutline(sb, (int)sfx, (int)sfy, sfw, sfh, BorderColor, BorderWidth); int sbarw = GetSliderBarWidth(true); float sliderratio = ((float)(ScrollCurrentY) / (float)((GetScrollYMax()))); float slidery = sfy + (sliderratio * (sfh - sbarw)); Draw.DrawRectangleHandleOutline(sb, (int)(sfx + BorderWidth), (int)slidery, ScrollSize, sbarw, TitleFontSettings.Color, BorderWidth); if (mx > sfx && mx < sfx + sfw && my > sfy && my < sfy + sfh) { input.Cursor.TrySet(eCursorState.CLICKABLE); } } } RenderTargetScope.Close(sb, oldrect); // draw the border last so that it is on top of child elements if (HasBorder) { Draw.DrawRectangleHandleOutline(sb, (int)(dx + x), (int)(dy + y), Width, Height, BorderColor, BorderWidth); } if (HasTitle) { int titleHeight = GetTitleHeight(); Draw.DrawRectangleHandle(sb, (int)(dx + x + BorderWidth), (int)(dy + y + BorderWidth), Width - (BorderWidth * 2), titleHeight + TitleMargin, Color); Draw.DrawRectangleHandle(sb, (int)(dx + x + TitleMargin + BorderWidth), (int)(dy + y + TitleMargin + BorderWidth), Width - (TitleMargin * 2) - (BorderWidth * 2), titleHeight, TitleBackgroundColor); int diff = (titleHeight - TitleSFont.LineSpacing) / 2; Draw.DrawText(g, sb, TitleSFont, dx + x + (TitleMargin * 2) + 2 + BorderWidth, dy + y + diff + BorderWidth + TitleMargin, Title, TitleFontSettings); } if (HasCloseButton) { CloseButton.Render(elapsedms, g, sb, input, dx + x + BaseInnerX, dy + y + BaseInnerY); } } }
public override void Render(float elapsedms, GraphicsDevice g, SpriteBatch sb, InputManager input, float dx, float dy) { // note: this component overwrites the base render logic Rectangle oldrect = RenderTargetScope.Open(sb, (int)Math.Floor(dx + x), (int)Math.Floor(dy + y), Width, Height); { dx += x; dy += y; SelfRender(elapsedms, g, sb, input, dx, dy); if (ComponentsVisible) { int count = 0; int totalw = 0; int totalh = 0; for (int i = StartingIndex; i < Components.Count && (MaxIndex == -1 || i <= MaxIndex) && (MaxCount == -1 || count < MaxCount); i++) { UIComponent u = Components[i]; if (u.Visible) { int uw = 0; int uh = 0; if (AutoOrientation == eUIOrientation.HORIZONTAL) { u.y = MarginY; uh = Height - MarginY * 2; if (FixedWidthPerIndex > 0) { u.x = MarginX + count * (MarginX * 2 + FixedWidthPerIndex); uw = FixedWidthPerIndex; } else { u.x = MarginX + totalw; totalw += u.GetWidth() + MarginX * 2; uw = u.GetWidth(); } } else { u.x = MarginX; uw = Width - MarginX * 2; if (FixedHeightPerIndex > 0) { u.y = MarginY + count * (MarginY * 2 + FixedHeightPerIndex); uh = FixedHeightPerIndex; } else { u.y = MarginY + totalh; totalh += u.GetHeight() + MarginY * 2; uh = u.GetHeight(); } } if (AlternateBackgrounds && count % 2 == 0) { Draw.DrawRectangleHandle(sb, (int)(dx + u.x - MarginX), (int)(dy + u.y - MarginY), uw + MarginX * 2, uh + MarginY * 2, BackgroundColor2); } Rectangle inneroldrect = RenderTargetScope.Open(sb, (int)Math.Floor(dx + u.x), (int)Math.Floor(dy + u.y), uw, uh); { u.Render(elapsedms, g, sb, input, dx + InnerX, dy + InnerY); } RenderTargetScope.Close(sb, inneroldrect); // draw border if (HasBorder) { Draw.DrawRectangleHandleOutline(sb, (int)(dx + u.x - MarginX), (int)(dy + u.y - MarginY), uw + MarginX * 2, uh + MarginY * 2, BorderColor, BorderWidth); } } count++; } } if (HasOuterBorder) { Draw.DrawRectangleHandleOutline(sb, (int)dx, (int)dy, Width, Height, OuterBorderColor, OuterBorderWidth); } } RenderTargetScope.Close(sb, oldrect); }