} // end of UIGrid2DCheckboxElement Render() #endregion #region Internal /// <summary> /// If the state of the element has changed, we may need to re-create the texture. /// </summary> private void RefreshTexture() { if (dirty) { InGame.SetRenderTarget(diffuse); InGame.Clear(Color.Transparent); int width = diffuse.Width; int height = diffuse.Height; ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); // Render the checkbox. int margin = 2; Vector2 position = new Vector2(margin, margin); Vector2 size = new Vector2(height - 2.0f * margin, height - 2.0f * margin); Vector4 lightGrey = new Vector4(0.7f, 0.7f, 0.7f, 1.0f); quad.Render(checkbox, lightGrey, position, size, @"TexturedRegularAlpha"); // Render the checkmark. if (check) { quad.Render(checkmark, position, size, @"TexturedRegularAlpha"); } // Render the label text into the texture. margin += (int)size.X + 16; int x = 0; int y = (int)((height - Font().LineSpacing) / 2.0f) - 2; int textWidth = (int)Font().MeasureString(label).X; x = TextHelper.CalcJustificationOffset(margin, width, textWidth, justify); SpriteBatch batch = UI2D.Shared.SpriteBatch; batch.Begin(); TextHelper.DrawStringWithShadow(Font, batch, x, y, label, textColor, dropShadowColor, invertDropShadow); batch.End(); // Restore backbuffer. InGame.RestoreRenderTarget(); dirty = false; } } // end of UIGrid2DCheckboxElement Render()
private void CreateRenderTargets(GraphicsDevice device) { const int dpi = 128; int w = (int)(dpi * width); int h = (int)(dpi * height); // Create the diffuse texture. Leave it null if we have no text to render. int originalWidth = w; int originalHeight = h; if (BokuGame.RequiresPowerOf2) { w = MyMath.GetNextPowerOfTwo(w); h = MyMath.GetNextPowerOfTwo(h); } // Create the diffuse texture. Leave it null if we have no text to render. diffuse = new RenderTarget2D(device, w, h, false, SurfaceFormat.Color, DepthFormat.None, 1, RenderTargetUsage.PlatformContents); InGame.GetRT("UIGrid2DTextElement", diffuse); InGame.SetRenderTarget(diffuse); InGame.Clear(Color.Transparent); if (label != null && label.Length > 0) { // Render the label text into the texture. int margin = 24; int x = 0; int y = (int)((originalHeight - Font().LineSpacing) / 2.0f) - 2; int textWidth = (int)(Font().MeasureString(label).X); x = TextHelper.CalcJustificationOffset(margin, originalWidth, textWidth, justify); SpriteBatch batch = UI2D.Shared.SpriteBatch; batch.Begin(); TextHelper.DrawStringWithShadow(Font, batch, x, y, label, textColor, dropShadowColor, invertDropShadow); batch.End(); } // Restore backbuffer. InGame.RestoreRenderTarget(); }
} // end of UIGridModularRadioBoxElement Update() public void RefreshTexture() { if (dirty || diffuse.IsContentLost) { InGame.SetRenderTarget(diffuse); InGame.Clear(Color.White); int w = diffuse.Width; int h = diffuse.Height; ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); // Render the white background. Vector2 position = Vector2.Zero; Vector2 size = new Vector2(w, radioWhite.Height); quad.Render(radioWhite, position, size, "TexturedNoAlpha"); // And the black parts. position.Y = 70; size.Y = h - 70; quad.Render(middleBlack, position, size, "TexturedRegularAlpha"); position.Y = 64; size.Y = radioBlack.Height; quad.Render(radioBlack, position, size, "TexturedRegularAlpha"); // Disable writing to alpha channel. // This prevents transparent fringing around the text. GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; device.BlendState = UI2D.Shared.BlendStateColorWriteRGB; // Render the label and value text into the texture. int margin = 0; position.X = 0; position.Y = (int)((64 - Font().LineSpacing) / 2.0f); int textWidth = (int)(Font().MeasureString(label).X); justify = Justification.Center; position.X = TextHelper.CalcJustificationOffset(margin, w, textWidth, justify); Color labelColor = new Color(127, 127, 127); Color valueColor = new Color(140, 200, 63); Color shadowColor = new Color(0, 0, 0, 20); Vector2 shadowOffset = new Vector2(0, 6); Color entryColor = new Color(200, 200, 200); Color selectedColor = new Color(0, 255, 12); SpriteBatch batch = UI2D.Shared.SpriteBatch; batch.Begin(); // Title. TextHelper.DrawString(Font, label, position + shadowOffset, shadowColor); TextHelper.DrawString(Font, label, position, labelColor); // Entries. UI2D.Shared.GetFont entryFont = UI2D.Shared.GetGameFont18Bold; if (numColumns == 1) { position.Y = 70; Vector2 min = Vector2.Zero; Vector2 max = Vector2.One; for (int i = 0; i < list.Count; i++) { position.X = (512 - entryFont().MeasureString(list[i].Text).X) / 2; TextHelper.DrawString(entryFont, list[i].Text, position, curIndex == i ? selectedColor : entryColor); if (showIndicators) { int vert = 5; if (curIndex == i) { quad.Render(indicatorLit, new Vector2(30, position.Y + vert), new Vector2(indicatorLit.Width, indicatorLit.Height), "TexturedRegularAlpha"); quad.Render(indicatorLit, new Vector2(512 - 30 - indicatorLit.Width, position.Y + vert), new Vector2(indicatorLit.Width, indicatorLit.Height), "TexturedRegularAlpha"); } else { quad.Render(indicatorUnlit, new Vector2(30, position.Y + vert), new Vector2(indicatorUnlit.Width, indicatorUnlit.Height), "TexturedRegularAlpha"); quad.Render(indicatorUnlit, new Vector2(512 - 30 - indicatorLit.Width, position.Y + vert), new Vector2(indicatorUnlit.Width, indicatorUnlit.Height), "TexturedRegularAlpha"); } } min.Y = position.Y / h; position.Y += entryFont().LineSpacing + 4; max.Y = position.Y / h; if (list[i].Box == null) { list[i].Box = new AABB2D(min, max); } else { list[i].Box.Set(min, max); } } } else if (numColumns == 2) { // Probably not as general as we'd like but I think this only // get used for the language options so just do what we need // to get all the languages to fit. // For column 0, left justify. // For column 1, right justify. for (int column = 0; column < numColumns; column++) { position.Y = 70; int width = 512 / numColumns; int center = width / 2 + column * width; int itemsPerColumn = (list.Count + (numColumns - 1)) / numColumns; int minIndex = column * itemsPerColumn; int maxIndex = Math.Min(list.Count, (column + 1) * itemsPerColumn); // Min/max values ine 0..1 range across rt. Vector2 min = new Vector2((center - width / 2.0f) / w, 0); Vector2 max = new Vector2((center + width / 2.0f) / w, 1); for (int i = minIndex; i < maxIndex; i++) { position.X = (int)(center - (entryFont().MeasureString(list[i].Text).X) / 2); int edgeMargin = 8; if (column == 0) { position.X = edgeMargin; } else { position.X = (int)(512 - edgeMargin - entryFont().MeasureString(list[i].Text).X); } TextHelper.DrawString(entryFont, list[i].Text, position, curIndex == i ? selectedColor : entryColor); min.Y = position.Y / h; position.Y += entryFont().LineSpacing + 4; max.Y = position.Y / h; if (list[i].Box == null) { list[i].Box = new AABB2D(min, max); } else { list[i].Box.Set(min, max); } } } } else { Debug.Assert(false, "numColumns must be 1 or 2, nothing else is supported."); } batch.End(); // Restore default blend state. device.BlendState = BlendState.AlphaBlend; // Restore backbuffer. InGame.RestoreRenderTarget(); dirty = false; } } // end of UIGridModularRadioBoxElement RefreshTexture()
} // end of UIGridModularCheckboxElement Render() /// <summary> /// If the state of the element has changed, we may need to re-create the texture. /// </summary> public void RefreshTexture() { if (dirty || diffuse.IsContentLost) { InGame.SetRenderTarget(diffuse); InGame.Clear(Color.White); int w = diffuse.Width; int h = diffuse.Height; ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); // Render the white background. Vector2 position = Vector2.Zero; Vector2 size = new Vector2(w, nextLevelWhite.Height); quad.Render(nextLevelWhite, position, size, "TexturedNoAlpha"); // And the black parts. position.Y = 70; size.Y = h - 70; quad.Render(nextLevelMiddleBlack, position, size, "TexturedRegularAlpha"); position.Y = 64; size.Y = nextLevelBlack.Height; quad.Render(nextLevelBlack, position, size, "TexturedRegularAlpha"); // Render the image. position.X = 6; position.Y = 70; size.X = size.Y = h - position.Y - 6; if (nextLevel != null) { //render the thumbnail when "on" quad.Render(nextLevel.Thumbnail.Texture, position, size, "TexturedRegularAlpha"); } else { quad.Render(nextLevelNone, position, size, "TexturedRegularAlpha"); } // Disable writing to alpha channel. // This prevents transparent fringing around the text. GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; device.BlendState = UI2D.Shared.BlendStateColorWriteRGB; // Render the label text into the texture. int margin = 16; position.X = (int)size.X + margin; position.Y = (int)((128 - Font().LineSpacing) / 2.0f); TextBlob blob = null; if (nextLevel != null) { blob = new TextBlob(Font, nextLevel.Name, w - (int)position.X - margin); } else { blob = new TextBlob(Font, Strings.Localize("editWorldParams.noLevelSelected"), w - (int)position.X - margin); } position.Y = (int)((h - blob.TotalSpacing) / 2.0f) - 2; Color fontColor = new Color(127, 127, 127); Color shadowColor = new Color(0, 0, 0, 20); Vector2 shadowOffset = new Vector2(0, 6); //render the main label string label = Strings.Localize("editWorldParams.nextLevel"); // prepare the label position int labelWidth = (int)(Font().MeasureString(label).X); Vector2 labelPosition = Vector2.Zero; labelPosition.X = TextHelper.CalcJustificationOffset(0, w, labelWidth, Justification.Center); labelPosition.Y = (int)((64 - Font().LineSpacing) / 2.0f); SpriteBatch batch = UI2D.Shared.SpriteBatch; batch.Begin(); //render the main label TextHelper.DrawString(Font, label, labelPosition + shadowOffset, shadowColor); TextHelper.DrawString(Font, label, labelPosition, fontColor); batch.End(); //render the world name blob.RenderWithButtons(position, fontColor, shadowColor, shadowOffset, maxLines: 3); //only render X button if we have a level if (nextLevel != null) { float clearLabelLength = Font().MeasureString(Strings.Localize("editWorldParams.clearNextLevel")).X; //render the X button position.X = w - 54; position.Y = h - 54; size = new Vector2(64, 64); quad.Render(ButtonTextures.XButton, position, size, "TexturedRegularAlpha"); //prepare position for "clear" label position.X -= 10 + (int)clearLabelLength; float hitBoxU = (float)(w - clearLabelLength - 64) / (float)w; float hitBoxV = (float)(h - 64) / (float)h; //update the hit box for "clear" - basically bottom right corner clearHitBox.Set(new Vector2(hitBoxU, hitBoxV), new Vector2(1.0f, 1.0f)); //render the clear button text batch.Begin(); TextHelper.DrawString(Font, Strings.Localize("editWorldParams.clearNextLevel"), position + shadowOffset, shadowColor); TextHelper.DrawString(Font, Strings.Localize("editWorldParams.clearNextLevel"), position, fontColor); batch.End(); } else { //no clear hit box if it's not being rendered clearHitBox.Set(Vector2.Zero, Vector2.Zero); } // Restore write channels device.BlendState = BlendState.AlphaBlend; // Restore backbuffer. InGame.RestoreRenderTarget(); dirty = false; } } // end of UIGridModularCheckboxElement Render()
} // end of UIGridModularMenu Update() public void RefreshTexture() { if (dirty || diffuse.IsContentLost) { int w, h; GetWH(out w, out h); // If the number of elements has changed, we need a new rendertarget. InitDeviceResources(BokuGame.bokuGame.GraphicsDevice); GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; InGame.SetRenderTarget(diffuse); InGame.Clear(Color.Transparent); // The thin margin around the highlight where the normal color shows through. int highlightMargin = 5; ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); // Render the white background. Alpha on normal map is used to round corners. Vector2 position = Vector2.Zero; Vector2 size = new Vector2(w, h); if (title != null) { quad.Render(Vector4.One, position, size); position.Y = 70; } // And the black parts. size.Y = whiteTop.Height; quad.Render(whiteTop, new Vector4(0, 0, 0, 1), position, size, "TexturedRegularAlpha"); position.Y += 16; size.Y = h - position.Y; quad.Render(new Vector4(0, 0, 0, 1), position, size); // Disable writing to alpha channel. // This prevents transparent fringing around the text. device.BlendState = UI2D.Shared.BlendStateColorWriteRGB; // Add the highlight/shadow onto the white region. if (title != null) { position.Y = 25; size.Y = 48; quad.Render(whiteHighlight, new Vector4(0.6f, 1.0f, 0.8f, 0.2f), position + new Vector2(highlightMargin, 0), size + new Vector2(-2 * highlightMargin, -highlightMargin), "TexturedRegularAlpha"); } // Render the label and value text into the texture. SpriteBatch batch = UI2D.Shared.SpriteBatch; batch.Begin(); // Title. UI2D.Shared.GetFont Font = UI2D.Shared.GetGameFont24Bold; if (title != null) { position.X = TextHelper.CalcJustificationOffset(margin.X, w, (int)Font().MeasureString(title).X, justify); position.Y = (int)((64 - Font().LineSpacing) / 2.0f) + 4; TextHelper.DrawString(Font, title, position + shadowOffset, shadowColor); TextHelper.DrawString(Font, title, position, titleTextColor); } // Entries. Font = UI2D.Shared.GetGameFont18Bold; position.Y = 8 + (title != null ? 70 : 0); Vector2 min = Vector2.Zero; Vector2 max = Vector2.One; for (int i = 0; i < itemList.Count; i++) { // Render bar. Vector4 barColor = active ? new Vector4(1, 1, 1, itemList[i].BarAlpha) : new Vector4(1, 0.5f, 1, itemList[i].BarAlpha); quad.Render(greenBar, barColor, new Vector2(8, position.Y - additionalLineSpacing / 3), new Vector2(w - 16, Font().LineSpacing + additionalLineSpacing), "TexturedRegularAlpha"); // Render text. position.X = TextHelper.CalcJustificationOffset(margin.X, w, (int)Font().MeasureString(itemList[i].Text).X, justify); TextHelper.DrawString(Font, itemList[i].Text, position, itemList[i].TextColor); min.Y = position.Y / h; position.Y += Font().LineSpacing + additionalLineSpacing; max.Y = position.Y / h; itemList[i].UVBoundingBox.Set(min, max); } batch.End(); // Add the highlight to the black region. position = new Vector2(highlightMargin, 1 + (title != null ? 70 : 0)); size.X = w - 2 * highlightMargin; size.Y = 60; quad.Render(blackHighlight, new Vector4(1, 1, 1, 0.2f), position, size, "AdditiveBlendWithAlpha"); // Restore write channels. device.BlendState = BlendState.NonPremultiplied; // Restore backbuffer. InGame.RestoreRenderTarget(); dirty = false; } } // end of UIGridModularMenu RefreshTexture()
} // end of Render() #endregion #region Internal /// <summary> /// If the text being displayed has changed, we need to refresh the texture. /// Note this requires changing the rendertarget so this should no be called /// during the normal rendering loop. /// </summary> private void RefreshTexture() { if (dirty) { GraphicsDevice device = BokuGame.Graphics.GraphicsDevice; LoadContent(true); diffuse = UI2D.Shared.RenderTarget512_302; if (diffuse == null) { /// Not ready yet, remain dirty. return; } SpriteBatch batch = UI2D.Shared.SpriteBatch; SpriteFont font20 = UI2D.Shared.GameFont20; SpriteFont font24 = UI2D.Shared.GameFont24; InGame.SetRenderTarget(diffuse); InGame.Clear(Color.Transparent); // Render the backdrop. ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance(); ssquad.Render(background, Vector2.Zero, new Vector2(512, 512), @"TexturedPreMultAlpha"); // // Render the text message. // List <string> lineList = new List <string>(); TextHelper.SplitMessage(Text, (int)(width - margin * 2), font24, false, lineList); // Calc center of display. int y = (int)((height - 1.5f * font24.LineSpacing) / 2.0f); int dy = font24.LineSpacing; // Offset based on number of lines. y -= (int)(dy * (lineList.Count - 1) / 2.0f); batch.Begin(); for (int i = 0; i < lineList.Count; i++) { string line = lineList[i]; // Render the label text into the texture. int x = 0; Vector2 textSize = font24.MeasureString(line); x = TextHelper.CalcJustificationOffset(margin, (int)width, (int)textSize.X, Justification); if (UseDropShadow) { TextHelper.DrawStringWithShadow(font24, batch, x, y, line, TextColor, DropShadowColor, InvertDropShadow); } else { batch.DrawString(font24, line, new Vector2(x, y), TextColor); } y += dy; } // end of i loop over lines in list. // // Render any active buttons and the text that goes with them. // // We need to cal the width of each active button and it's label // so we can center the whole set at the bottom of the dialog. // TODO Set this up so we can also right/left justify? Vector2 position = Vector2.Zero; position.X = width / 2.0f; position.Y = height - margin - 40.0f; Vector2 buttonSize = new Vector2(64, 64); // Size for rendering. int buttonWidth = 40; // Size for spacing. int gap = 8; // Space between sets. float totalWidth = 0; if (handlerA != null) { totalWidth += buttonWidth; totalWidth += font20.MeasureString(labelA).X; } if (handlerB != null) { if (totalWidth != 0) { totalWidth += gap; } totalWidth += buttonWidth; totalWidth += font20.MeasureString(labelB).X; } if (handlerX != null) { if (totalWidth != 0) { totalWidth += gap; } totalWidth += buttonWidth; totalWidth += font20.MeasureString(labelX).X; } if (handlerY != null) { if (totalWidth != 0) { totalWidth += gap; } totalWidth += buttonWidth; totalWidth += font20.MeasureString(labelY).X; } position.X -= (int)totalWidth / 2; // // Render each button/label pair if needed. // ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); if (handlerA != null) { quad.Render(ButtonTextures.AButton, new Vector2(position.X, position.Y - 2), buttonSize, @"TexturedRegularAlpha"); position.X += buttonWidth; //TextHelper.DrawStringWithShadow(font20, batch, position.X, position.Y, labelA, TextColor, DropShadowColor, InvertDropShadow); batch.DrawString(font20, labelA, position, TextColor); position.X += (int)font20.MeasureString(labelA).X + gap; } if (handlerB != null) { quad.Render(ButtonTextures.BButton, new Vector2(position.X, position.Y - 2), buttonSize, @"TexturedRegularAlpha"); position.X += buttonWidth; //TextHelper.DrawStringWithShadow(font20, batch, position.X, position.Y, labelB, TextColor, DropShadowColor, InvertDropShadow); batch.DrawString(font20, labelB, position, TextColor); position.X += (int)font20.MeasureString(labelB).X + gap; } if (handlerX != null) { quad.Render(ButtonTextures.XButton, new Vector2(position.X, position.Y - 2), buttonSize, @"TexturedRegularAlpha"); position.X += buttonWidth; //TextHelper.DrawStringWithShadow(font20, batch, position.X, position.Y, labelX, TextColor, DropShadowColor, InvertDropShadow); batch.DrawString(font20, labelX, position, TextColor); position.X += (int)font20.MeasureString(labelX).X + gap; } if (handlerY != null) { quad.Render(ButtonTextures.YButton, new Vector2(position.X, position.Y - 2), buttonSize, @"TexturedRegularAlpha"); position.X += buttonWidth; //TextHelper.DrawStringWithShadow(font20, batch, position.X, position.Y, labelY, TextColor, DropShadowColor, InvertDropShadow); batch.DrawString(font20, labelY, position, TextColor); position.X += (int)font20.MeasureString(labelY).X + gap; } batch.End(); // Restore backbuffer. InGame.RestoreRenderTarget(); dirty = false; } } // end of MessageDialog RefreshTexture()
private void CreateRenderTargets(GraphicsDeviceManager graphics) { GraphicsDevice device = graphics.GraphicsDevice; const int margin = 24; int w = (int)width; int h = (int)height; int backgroundWidth = w; int backgroundHeight = h; // Create the diffuse texture. if (BokuGame.RequiresPowerOf2) { w = MyMath.GetNextPowerOfTwo(w); h = MyMath.GetNextPowerOfTwo(h); } diffuse = new RenderTarget2D( device, w, h, 1, SurfaceFormat.Color, MultiSampleType.None, 0, RenderTargetUsage.PlatformContents); InGame.GetRT("MessageBoxElement", diffuse); // Save off the current depth buffer. InGame.SetRenderTarget(diffuse); InGame.Clear(Color.Transparent); // Render the backdrop. ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance(); ssquad.Render(background, Vector2.Zero, new Vector2(512, 512), @"TexturedPreMultAlpha"); SpriteFont font = Font(); List <string> lineList = new List <string>(); TextHelper.SplitMessage(label, backgroundWidth - margin * 2, font, false, lineList); // Calc center of display. int y = (int)((backgroundHeight - font.LineSpacing) / 2.0f) - 2; int dy = font.LineSpacing; // Offset based on number of lines. y -= (int)(dy * (lineList.Count - 1) / 2.0f); SpriteBatch batch = UI2D.Shared.SpriteBatch; batch.Begin(); for (int i = 0; i < lineList.Count; i++) { string line = lineList[i]; // Render the label text into the texture. int x = 0; Vector2 textSize = font.MeasureString(line); x = TextHelper.CalcJustificationOffset(margin, backgroundWidth, (int)textSize.X, justify); if (useDropShadow) { TextHelper.DrawStringWithShadow(font, batch, x, y, line, textColor, dropShadowColor, invertDropShadow); } else { batch.DrawString(font, line, new Vector2(x, y), textColor); } y += dy; } // end of i loop over lines in list. // Load button textures. Texture BButton = ButtonTextures.BButton; // Render the 'B' button. Vector2 size = new Vector2(56.0f, 56.0f); Vector2 position = new Vector2(w - 150, h - 40 - margin); // Hack for X600 compat. if (BokuGame.RequiresPowerOf2) { position = new Vector2(backgroundWidth - 350, backgroundHeight - size.Y - margin); } ssquad.Render(BButton, position, size, @"TexturedRegularAlpha"); // And the text with it. { int x = (int)(position.X + 40); y = (int)(position.Y); String buttonLabel = @"Back"; if (useDropShadow) { TextHelper.DrawStringWithShadow(font, batch, x, y, buttonLabel, textColor, dropShadowColor, false); } else { batch.DrawString(font, buttonLabel, new Vector2(x, y), textColor); } } batch.End(); // Restore backbuffer and depth buffer. InGame.RestoreRenderTarget(); }
} // end of UIGridPictureListElement RecalPositions(). /// <summary> /// If the state of the element has changed, we may need to re-create the texture. /// </summary> private void RefreshTexture() { if (!dirty) { // Check if any of the owned pictures are dirty. for (int i = 0; i < pictures.Count; i++) { if (pictures[i].dirty) { dirty = true; pictures[i].dirty = false; } } } if (dirty) { InGame.SetRenderTarget(diffuse); InGame.Clear(Color.Transparent); int width = backgroundWidth; int height = backgroundHeight; ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); // Render the label text into the texture in the upper left-hand corner. int margin = 32; int x = 0; int y = 12; string fancyLabel = label; if (pictures[curIndex].label != null) { fancyLabel = fancyLabel + " : " + pictures[curIndex].label; } int textWidth = (int)(Font().MeasureString(fancyLabel).X); x = TextHelper.CalcJustificationOffset(margin, width, textWidth, justify); SpriteBatch batch = UI2D.Shared.SpriteBatch; batch.Begin(); TextHelper.DrawStringWithShadow(Font, batch, x, y, fancyLabel, textColor, dropShadowColor, invertDropShadow); batch.End(); // Render the arrows. if (showLeftArrow) { quad.Render(leftArrow, leftArrowPosition, arrowSize, @"TexturedRegularAlpha"); } if (showRightArrow) { quad.Render(rightArrow, rightArrowPosition, arrowSize, @"TexturedRegularAlpha"); } // Render the PictureList. for (int i = 0; i < pictures.Count; i++) { if (pictures[i].alpha > 0.0f) { quad.Render(pictures[i].Texture, pictures[i].position, pictures[i].scale * arrowSize, @"TexturedRegularAlpha"); } } // Render help button. if (ShowHelpButton) { x = width - 54; y = height - 54; Vector2 pos = new Vector2(x, y); Vector2 size = new Vector2(64, 64); quad.Render(ButtonTextures.YButton, pos, size, "TexturedRegularAlpha"); x -= 10 + (int)Font().MeasureString(Strings.Localize("editObjectParams.help")).X; batch.Begin(); TextHelper.DrawStringWithShadow(Font, batch, x, y, Strings.Localize("editObjectParams.help"), textColor, dropShadowColor, invertDropShadow); batch.End(); if (xButtonText != null) { x = width - 54; y = height - 54 - Font().LineSpacing - 6; pos = new Vector2(x, y); size = new Vector2(64, 64); quad.Render(ButtonTextures.XButton, pos, size, "TexturedRegularAlpha"); x -= 10 + (int)Font().MeasureString(Strings.Localize("editWorldParams.setCamera")).X; batch.Begin(); TextHelper.DrawStringWithShadow(Font, batch, x, y, Strings.Localize("editWorldParams.setCamera"), textColor, dropShadowColor, invertDropShadow); batch.End(); } } // Restore backbuffer. InGame.RestoreRenderTarget(); dirty = false; } } // end of UIGridPictureListElement RefreshTexture()
} // end of TwitchPick() /// <summary> /// If the state of the element has changed, we may need to re-create the texture. /// </summary> private void RefreshTexture() { if (dirty || diffuse.IsContentLost) { InGame.SetRenderTarget(diffuse); InGame.Clear(Color.White); int w = diffuse.Width; int h = diffuse.Height; ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); // Render the white background. Vector2 position = Vector2.Zero; Vector2 size = new Vector2(w, white.Height); quad.Render(white, position, size, "TexturedNoAlpha"); // And the black parts. position.Y = 70; size.Y = h - 70; quad.Render(middleBlack, position, size, "TexturedRegularAlpha"); position.Y = 64; size.Y = black.Height; quad.Render(black, position, size, "TexturedRegularAlpha"); // The arrows. position.X = 20; position.Y = 90; size = new Vector2(arrow.Width, arrow.Height); quad.Render(arrow, position, size, "TexturedRegularAlpha"); position.X = w - position.X; size.X = -size.X; quad.Render(arrow, position, size, "TexturedRegularAlpha"); // The indicator. size = new Vector2(indicatorLit.Width, indicatorLit.Height); position = new Vector2(512 / 2 - size.X / 2, 140); quad.Render(indicatorLit, position, size, "TexturedRegularAlpha"); // The pictures. Render them from the outside-in so that they // ovelap correctly. Vector2 border = new Vector2(3, 3); int index; for (int i = limit; i > 0; i--) { index = (CurIndex + i) % pics.Count; size = new Vector2(pics[index].size); position = pics[index].position - 0.5f * size; quad.Render(new Vector4(0, 0, 0, 1), position, size); quad.Render(pics[index].texture, position + border, size - 2.0f * border, "TexturedRegularAlpha"); index = (CurIndex - i + pics.Count) % pics.Count; size = new Vector2(pics[index].size); position = pics[index].position - 0.5f * size; quad.Render(new Vector4(0, 0, 0, 1), position, size); quad.Render(pics[index].texture, position + border, size - 2.0f * border, "TexturedRegularAlpha"); } index = CurIndex; size = new Vector2(pics[index].size); position = pics[index].position - 0.5f * size; quad.Render(new Vector4(0, 0, 0, 1), position, size); quad.Render(pics[index].texture, position + border, size - 2.0f * border, "TexturedRegularAlpha"); // Disable writing to alpha channel. // This prevents transparent fringing around the text. GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; device.BlendState = UI2D.Shared.BlendStateColorWriteRGB; // Render the label and value text into the texture. string title = label + " : " + pics[CurIndex].label; int margin = 0; position.X = 0; position.Y = (int)((64 - Font().LineSpacing) / 2.0f); int textWidth = (int)(Font().MeasureString(title).X); justify = Justification.Center; position.X = TextHelper.CalcJustificationOffset(margin, w, textWidth, justify); Color labelColor = new Color(127, 127, 127); Color valueColor = new Color(140, 200, 63); Color shadowColor = new Color(0, 0, 0, 20); Vector2 shadowOffset = new Vector2(0, 6); SpriteBatch batch = UI2D.Shared.SpriteBatch; batch.Begin(); // Title. TextHelper.DrawString(Font, title, position + shadowOffset, shadowColor); TextHelper.DrawString(Font, title, position, labelColor); batch.End(); // Restore default blend state. device.BlendState = BlendState.AlphaBlend; // Restore backbuffer. InGame.RestoreRenderTarget(); dirty = false; } } // end of UIGridModularPictureListElement Render()
} // end of UIGridModularCameraModeElement Render() /// <summary> /// If the state of the element has changed, we may need to re-create the texture. /// </summary> public void RefreshTexture() { if (dirty || diffuse.IsContentLost) { InGame.SetRenderTarget(diffuse); InGame.Clear(Color.White); int w = diffuse.Width; int h = diffuse.Height; ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); // Render the white background. Vector2 position = Vector2.Zero; Vector2 size = new Vector2(w, white.Height); quad.Render(white, position, size, "TexturedNoAlpha"); // And the black parts. position.Y = 70; size.Y = h - 70; quad.Render(middleBlack, position, size, "TexturedRegularAlpha"); position.Y = 64; size.Y = black.Height; quad.Render(black, position, size, "TexturedRegularAlpha"); // The icons. position.X = (512 - icons.Width) / 2; position.Y = 80; size = new Vector2(icons.Width, icons.Height); quad.Render(icons, position, size, "TexturedRegularAlpha"); // Bounding box Vector2 min = new Vector2(position.X / w, position.Y / h); Vector2 max = new Vector2((position.X + size.X) / w, (140 + 2.0f * indicatorLit.Height) / h); iconButtonBox.Set(min, max); // The indicators. size = new Vector2(indicatorLit.Width, indicatorLit.Height); position = new Vector2(105, 140); quad.Render(CurIndex == 0 ? indicatorLit : indicatorUnlit, position, size, "TexturedRegularAlpha"); position = new Vector2(512 / 2 - size.X / 2, 140); quad.Render(CurIndex == 1 ? indicatorLit : indicatorUnlit, position, size, "TexturedRegularAlpha"); position = new Vector2(512 - 105 - size.X, 140); quad.Render(CurIndex == 2 ? indicatorLit : indicatorUnlit, position, size, "TexturedRegularAlpha"); // Disable writing to alpha channel. // This prevents transparent fringing around the text. GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; device.BlendState = UI2D.Shared.BlendStateColorWriteRGB; // Render the label and value text into the texture. string title = label + " : "; switch (CurIndex) { case 0: title += Strings.Localize("editWorldParams.cameraModeFixedPosition"); break; case 1: title += Strings.Localize("editWorldParams.cameraModeFixedOffset"); break; case 2: title += Strings.Localize("editWorldParams.cameraModeFree"); break; } int margin = 0; position.X = 0; position.Y = (int)((64 - Font().LineSpacing) / 2.0f); int textWidth = (int)(Font().MeasureString(title).X); justify = Justification.Center; position.X = TextHelper.CalcJustificationOffset(margin, w, textWidth, justify); Color labelColor = new Color(127, 127, 127); Color valueColor = new Color(140, 200, 63); Color shadowColor = new Color(0, 0, 0, 20); Vector2 shadowOffset = new Vector2(0, 6); SpriteBatch batch = UI2D.Shared.SpriteBatch; batch.Begin(); // Title. TextHelper.DrawString(Font, title, position + shadowOffset, shadowColor); TextHelper.DrawString(Font, title, position, labelColor); batch.End(); if (xButtonText != null) { UI2D.Shared.GetFont ButtonFont = UI2D.Shared.GetGameFont18Bold; position.X = w - 44; position.Y = h - 44; size = new Vector2(48, 48); quad.Render(ButtonTextures.XButton, position, size, "TexturedRegularAlpha"); max.X = (position.X + 44) / w; min.Y = position.Y / h; position.X -= 10 + (int)ButtonFont().MeasureString(Strings.Localize("editWorldParams.setCamera")).X; batch.Begin(); TextHelper.DrawString(ButtonFont, Strings.Localize("editWorldParams.setCamera"), position + shadowOffset, shadowColor); TextHelper.DrawString(ButtonFont, Strings.Localize("editWorldParams.setCamera"), position, labelColor); batch.End(); min.X = position.X / w; max.Y = min.Y + (float)ButtonFont().LineSpacing / h; xButtonBox.Set(min, max); } // Restore default blend state. device.BlendState = BlendState.AlphaBlend; // Restore backbuffer. InGame.RestoreRenderTarget(); dirty = false; } } // end of UIGridModularCameraModeElement Render()
} // end of UIGridBaseSliderElement Render() /// <summary> /// If the state of the element has changed, we may need to re-create the texture. /// </summary> public void RefreshTexture() { if (dirty) { InGame.SetRenderTarget(diffuse); InGame.Clear(Color.Transparent); int width = diffuse.Width; int height = diffuse.Height; ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); // Render the slide under the box. int margin = 36; float aspectRatio = 5.25f; // Based on art, should be more flexible. Vector4 sliderColor = Color.Red.ToVector4(); Vector2 position = new Vector2(margin, margin); Vector2 size = new Vector2(aspectRatio * (height - 2.0f * margin), height - 2.0f * margin); // Scale size based on current value and ranges. size.X *= GetSliderPercentage(); quad.Render(sliderColor, position, size); // Calc position of text overlay. int x = (int)(position.X + aspectRatio * (height - 2.0f * margin) / 2.0f); int y = (height - Font().LineSpacing) / 2; // Render the slider box over the slider itself. margin = 24; aspectRatio = 4.0f; // Based on art, should be more flexible. position = new Vector2(margin, margin); size = new Vector2(aspectRatio * (height - 2.0f * margin), height - 2.0f * margin); Vector4 lightGrey = new Vector4(0.7f, 0.7f, 0.7f, 1.0f); quad.Render(sliderBox, lightGrey, position, size, @"TexturedRegularAlpha"); // Render the current slider value in the center of the slider area. string valueString = GetFormattedValue(); x -= (int)(Font().MeasureString(valueString).X) / 2; SpriteBatch batch = UI2D.Shared.SpriteBatch; batch.Begin(); if (useDropShadow) { TextHelper.DrawStringWithShadow(Font, batch, x, y, valueString, textColor, dropShadowColor, false); } else { TextHelper.DrawString(Font, valueString, new Vector2(x, y), textColor); } batch.End(); // Render the label text into the texture. margin += (int)size.X + 16; x = 0; y = (int)((height - Font().LineSpacing) / 2.0f) - 2; int textWidth = (int)(Font().MeasureString(label).X); x = TextHelper.CalcJustificationOffset(margin, width, textWidth, justify); batch.Begin(); TextHelper.DrawStringWithShadow(Font, batch, x, y, label, textColor, dropShadowColor, invertDropShadow); batch.End(); // Render help button. if (ShowHelpButton) { x = width - 54; y = height - 54; position = new Vector2(x, y); size = new Vector2(64, 64); quad.Render(ButtonTextures.YButton, position, size, "TexturedRegularAlpha"); x -= 10 + (int)Font().MeasureString(Strings.Localize("editObjectParams.help")).X; batch.Begin(); TextHelper.DrawStringWithShadow(Font, batch, x, y, Strings.Localize("editObjectParams.help"), textColor, dropShadowColor, invertDropShadow); batch.End(); } // Restore backbuffer. InGame.RestoreRenderTarget(); dirty = false; } } // end of UIGridIntegerSliderElement RefreshTexture()
} // end of UIGridBaseModularSliderElement Render() /// <summary> /// If the state of the element has changed, we may need to re-create the texture. /// </summary> public void RefreshTexture() { if (dirty || diffuse.IsContentLost) { InGame.SetRenderTarget(diffuse); InGame.Clear(Color.White); int w = diffuse.Width; int h = diffuse.Height; ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); // Render the white background. Vector2 position = Vector2.Zero; Vector2 size = new Vector2(w, h); quad.Render(sliderWhite, position, size, "TexturedNoAlpha"); // And the black part. int blackHeight = 70; // From Photoshop... position.Y = h - blackHeight; size.Y = blackHeight; quad.Render(sliderBlack, position, size, "TexturedRegularAlpha"); // Disable writing to alpha channel. // This prevents transparent fringing around the text. GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; device.BlendState = UI2D.Shared.BlendStateColorWriteRGB; // Render the label and value text into the texture. int margin = 0; position.X = 0; position.Y = (int)(((h - blackHeight) - Font().LineSpacing) / 2.0f) - 2; int textWidth = (int)(Font().MeasureString(label).X); justify = Justification.Center; position.X = TextHelper.CalcJustificationOffset(margin, w, textWidth, justify); Color labelColor = new Color(127, 127, 127); Color valueColor = new Color(140, 200, 63); Color shadowColor = new Color(0, 0, 0, 20); Vector2 shadowOffset = new Vector2(0, 6); SpriteBatch batch = UI2D.Shared.SpriteBatch; batch.Begin(); TextHelper.DrawString(Font, label, position + shadowOffset, shadowColor); TextHelper.DrawString(Font, label, position, labelColor); string valueString = GetFormattedValue(); margin = 48; position.X = w - margin - (int)Font().MeasureString(valueString).X; TextHelper.DrawString(Font, valueString, position, valueColor); batch.End(); // Render the value bead. int left = 22; int top = 93; int right = w - left; int verticalRadius = 8; int horizontalRadius = 6; float percent = GetSliderPercentage(); int len = right - left - horizontalRadius * 2; len = (int)(len * percent); len = Math.Max(len, 7); right = len + left + horizontalRadius * 2 - 2; quad.Render(sliderBeadEnd, new Vector2(left, top), new Vector2(horizontalRadius, verticalRadius * 2), "TexturedRegularAlpha"); quad.Render(sliderBeadEnd, new Vector2(right, top), new Vector2(-horizontalRadius, verticalRadius * 2), "TexturedRegularAlpha"); quad.Render(sliderBeadMiddle, new Vector2(left + horizontalRadius, top), new Vector2(len - 2, verticalRadius * 2), "TexturedRegularAlpha"); /* * // Render help button. * if (ShowHelpButton) * { * position.X = w - 54; * position.Y = h - 54; * size = new Vector2(64, 64); * quad.Render(ButtonTextures.YButton, position, size, "TexturedRegularAlpha"); * position.X -= 10 + (int)Font().MeasureString(Strings.Localize("editObjectParams.help")).X; * batch.Begin(); * TextHelper.DrawString(Font, Strings.Localize("editObjectParams.help"), position + shadowOffset, shadowColor); * TextHelper.DrawString(Font, Strings.Localize("editObjectParams.help"), position, fontColor); * batch.End(); * } */ // Restore default blend state. device.BlendState = BlendState.AlphaBlend; // Restore backbuffer. InGame.RestoreRenderTarget(); dirty = false; } } // end of UIGridIntegerSliderElement RefreshTexture()
} // end of UIGridCheckboxElement Render() /// <summary> /// If the state of the element has changed, we may need to re-create the texture. /// </summary> public void RefreshTexture() { if (dirty) { InGame.SetRenderTarget(diffuse); InGame.Clear(Color.Transparent); int width = diffuse.Width; int height = diffuse.Height; ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); // Render the checkbox. int margin = 24; Vector2 position = new Vector2(margin, margin); Vector2 size = new Vector2(height - 2.0f * margin, height - 2.0f * margin); Vector4 lightGrey = new Vector4(0.7f, 0.7f, 0.7f, 1.0f); quad.Render(checkbox, lightGrey, position, size, @"TexturedRegularAlpha"); // Render the checkmark. if (check) { quad.Render(checkmark, position, size, @"TexturedRegularAlpha"); } // Render the label text into the texture. margin += (int)size.X + 16; int x = 0; int y = (int)((height - Font().LineSpacing) / 2.0f) - 2; int textWidth = (int)(Font().MeasureString(label).X); x = TextHelper.CalcJustificationOffset(margin, width, textWidth, justify); SpriteBatch batch = UI2D.Shared.SpriteBatch; batch.Begin(); TextHelper.DrawStringWithShadow(Font, batch, x, y, label, textColor, dropShadowColor, invertDropShadow); batch.End(); // Render help button. if (ShowHelpButton) { x = width - 54; y = height - 54; position = new Vector2(x, y); size = new Vector2(64, 64); quad.Render(ButtonTextures.YButton, position, size, "TexturedRegularAlpha"); x -= 10 + (int)Font().MeasureString(Strings.Localize("editObjectParams.help")).X; batch.Begin(); TextHelper.DrawStringWithShadow(Font, batch, x, y, Strings.Localize("editObjectParams.help"), textColor, dropShadowColor, invertDropShadow); batch.End(); if (xButtonText != null) { x = width - 54; y = height - 54 - Font().LineSpacing - 6; position = new Vector2(x, y); size = new Vector2(64, 64); quad.Render(ButtonTextures.XButton, position, size, "TexturedRegularAlpha"); x -= 10 + (int)Font().MeasureString(Strings.Localize("editWorldParams.setCamera")).X; batch.Begin(); TextHelper.DrawStringWithShadow(Font, batch, x, y, Strings.Localize("editWorldParams.setCamera"), textColor, dropShadowColor, invertDropShadow); batch.End(); } } // Restore backbuffer. InGame.RestoreRenderTarget(); dirty = false; } } // end of UIGridCheckboxElement Render()