public void RefreshOutline(ImageRegionSelectionControl control, ref LineRectangle textureOutlineRectangle) { var shouldShowOutline = control.CurrentTexture != null; if (shouldShowOutline) { if (textureOutlineRectangle == null) { textureOutlineRectangle = new LineRectangle(control.SystemManagers); textureOutlineRectangle.IsDotted = false; textureOutlineRectangle.Color = new Microsoft.Xna.Framework.Color(255, 255, 255, 128); control.SystemManagers.ShapeManager.Add(textureOutlineRectangle); } textureOutlineRectangle.Width = control.CurrentTexture.Width; textureOutlineRectangle.Height = control.CurrentTexture.Height; textureOutlineRectangle.Visible = true; } else { if (textureOutlineRectangle != null) { textureOutlineRectangle.Visible = false; } } }
internal static bool TryHandleAsBaseType(string baseType, SystemManagers systemManagers, out IRenderable containedObject) { bool handledAsBaseType = true; containedObject = null; switch (baseType) { case "Container": LineRectangle lineRectangle = new LineRectangle(systemManagers); containedObject = lineRectangle; break; case "Rectangle": LineRectangle rectangle = new LineRectangle(); rectangle.IsDotted = false; containedObject = rectangle; break; case "Circle": LineCircle circle = new LineCircle(); circle.CircleOrigin = CircleOrigin.TopLeft; containedObject = circle; break; case "ColoredRectangle": SolidRectangle solidRectangle = new SolidRectangle(); containedObject = solidRectangle; break; case "Sprite": Texture2D texture = null; Sprite sprite = new Sprite(texture); containedObject = sprite; break; case "NineSlice": { NineSlice nineSlice = new NineSlice(); containedObject = nineSlice; } break; case "Text": { Text text = new Text(systemManagers, ""); containedObject = text; } break; default: handledAsBaseType = false; break; } return(handledAsBaseType); }
public void Render(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, SystemManagers managers) { if (AbsoluteVisible) { // Moved this out of here - it's manually called by the TextManager // This is required because we can't update in the draw call now that // we're using RenderTargets //if (mNeedsBitmapFontRefresh) //{ // UpdateTextureToRender(); //} if (RenderBoundary) { LineRectangle.RenderLinePrimitive(mBounds, spriteBatch, this, managers, false); } if (mTextureToRender == null) { RenderUsingSpriteFont(spriteBatch); } else { RenderUsingBitmapFont(spriteBatch, managers); } } }
public void Render(SpriteRenderer spriteRenderer, SystemManagers managers) { if (AbsoluteVisible) { // Moved this out of here - it's manually called by the TextManager // This is required because we can't update in the draw call now that // we're using RenderTargets //if (mNeedsBitmapFontRefresh) //{ // UpdateTextureToRender(); //} if (RenderBoundary) { LineRectangle.RenderLinePrimitive(mBounds, spriteRenderer, this, managers, false); } if (TextRenderingMode == TextRenderingMode.CharacterByCharacter) { RenderCharacterByCharacter(spriteRenderer); } else // RenderTarget { if (mTextureToRender == null) { RenderUsingSpriteFont(spriteRenderer); } else { RenderUsingBitmapFont(spriteRenderer, managers); } } } }
private void SetLineRectangleAroundIpso(LineRectangle rectangle, IPositionedSizedObject pso) { float adjustedSelectionBorder = SelectionBorder / Renderer.Self.Camera.Zoom; rectangle.Visible = true; rectangle.X = pso.GetAbsoluteX() - adjustedSelectionBorder; rectangle.Y = pso.GetAbsoluteY() - adjustedSelectionBorder; rectangle.Width = pso.Width + adjustedSelectionBorder * 2; rectangle.Height = pso.Height + adjustedSelectionBorder * 2; }
public void UpdateGuides() { ClearGuideRectangles(); if (ObjectFinder.Self.GumProjectSave != null) { for (int i = 0; i < ObjectFinder.Self.GumProjectSave.Guides.Count; i++) { GuideRectangle guideRectangle = ObjectFinder.Self.GumProjectSave.Guides[i]; LineRectangle rectangle = new LineRectangle(); float absoluteX; float absoluteY; UnitConverter.Self.ConvertToPixelCoordinates( guideRectangle.X, guideRectangle.Y, guideRectangle.XUnitType, guideRectangle.YUnitType, ObjectFinder.Self.GumProjectSave.DefaultCanvasWidth, ObjectFinder.Self.GumProjectSave.DefaultCanvasHeight, 0, 0, out absoluteX, out absoluteY); rectangle.X = absoluteX; rectangle.Y = absoluteY; float absoluteWidth; float absoluteHeight; UnitConverter.Self.ConvertToPixelCoordinates( guideRectangle.Width, guideRectangle.Height, guideRectangle.WidthUnitType, guideRectangle.HeightUnitType, ObjectFinder.Self.GumProjectSave.DefaultCanvasWidth, ObjectFinder.Self.GumProjectSave.DefaultCanvasHeight, 0, 0, out absoluteWidth, out absoluteHeight); rectangle.Width = absoluteWidth; rectangle.Height = absoluteHeight; rectangle.Name = guideRectangle.Name; rectangle.Color = new Microsoft.Xna.Framework.Color(1.0f, 1.0f, 1.0f, .5f); mGuideRectangles.Add(rectangle); ShapeManager.Self.Add(rectangle); } } }
public void Initialize(WireframeEditControl wireframeEditControl, Panel wireframeParentPanel) { try { mWireframeEditControl = wireframeEditControl; mWireframeEditControl.ZoomChanged += HandleZoomChanged; SystemManagers.Default = new SystemManagers(); SystemManagers.Default.Initialize(GraphicsDevice); Renderer.Self.SamplerState = SamplerState.PointWrap; LoaderManager.Self.ContentLoader = new ContentLoader(); LoaderManager.Self.Initialize(null, "content/TestFont.fnt", Services, null); CameraController.Self.Initialize(Camera, mWireframeEditControl, Width, Height); CameraController.Self.CameraChanged += () => CameraChanged?.Invoke(); InputLibrary.Cursor.Self.Initialize(this); InputLibrary.Keyboard.Self.Initialize(this); mScreenBounds = new LineRectangle(); mScreenBounds.Name = "Gum Screen Bounds"; mScreenBounds.Width = 800; mScreenBounds.Height = 600; mScreenBounds.Color = ScreenBoundsColor; ShapeManager.Self.Add(mScreenBounds, SelectionManager.Self.UiLayer); this.KeyDown += OnKeyDown; this.KeyPress += OnKeyPress; this.MouseDown += CameraController.Self.HandleMouseDown; this.MouseMove += CameraController.Self.HandleMouseMove; this.MouseWheel += CameraController.Self.HandleMouseWheel; this.mTopRuler = new Ruler(this, null, InputLibrary.Cursor.Self); mLeftRuler = new Ruler(this, null, InputLibrary.Cursor.Self); mLeftRuler.RulerSide = RulerSide.Left; if (AfterXnaInitialize != null) { AfterXnaInitialize(this, null); } UpdateToProject(); mHasInitialized = true; } catch (Exception exception) { MessageBox.Show("Error initializing the wireframe control\n\n" + exception); } }
private void RenderUsingBitmapFont(SpriteRenderer spriteRenderer, SystemManagers managers) { if (mTempForRendering == null) { mTempForRendering = new LineRectangle(managers); } mTempForRendering.X = this.X; mTempForRendering.Y = this.Y; mTempForRendering.Width = this.mTextureToRender.Width * mFontScale; mTempForRendering.Height = this.mTextureToRender.Height * mFontScale; //mTempForRendering.Parent = this.Parent; float widthDifference = this.EffectiveWidth - mTempForRendering.Width; if (this.HorizontalAlignment == Graphics.HorizontalAlignment.Center) { mTempForRendering.X += widthDifference / 2.0f; } else if (this.HorizontalAlignment == Graphics.HorizontalAlignment.Right) { mTempForRendering.X += widthDifference; } if (this.VerticalAlignment == Graphics.VerticalAlignment.Center) { mTempForRendering.Y += (this.EffectiveHeight - mTempForRendering.Height) / 2.0f; } else if (this.VerticalAlignment == Graphics.VerticalAlignment.Bottom) { mTempForRendering.Y += this.EffectiveHeight - mTempForRendering.Height; } if (this.Parent != null) { mTempForRendering.X += Parent.GetAbsoluteX(); mTempForRendering.Y += Parent.GetAbsoluteY(); } if (mBitmapFont?.AtlasedTexture != null) { mBitmapFont.RenderAtlasedTextureToScreen(mWrappedText, this.HorizontalAlignment, mTextureToRender.Height, new Color(mRed, mGreen, mBlue, mAlpha), Rotation, mFontScale, managers, spriteRenderer, this); } else { Sprite.Render(managers, spriteRenderer, mTempForRendering, mTextureToRender, new Color(mRed, mGreen, mBlue, mAlpha), null, false, false, Rotation, treat0AsFullDimensions: false, objectCausingRenering: this); } }
public void Initialize(ImageRegionSelectionControl control, SystemManagers managers, WireframeEditControls wireframeControl, WireframeEditControlsViewModel wireframeEditControlsViewModel) { addCursor = new System.Windows.Forms.Cursor(this.GetType(), "Content.AddCursor.cur"); mManagers = managers; mManagers.Renderer.SamplerState = SamplerState.PointClamp; mControl = control; keyboard = new Keyboard(); keyboard.Initialize(control); mManagers.Renderer.Camera.CameraCenterOnScreen = CameraCenterOnScreen.TopLeft; mWireframeControl = wireframeControl; mControl.RegionChanged += new EventHandler(HandleRegionChanged); mControl.MouseWheelZoom += new EventHandler(HandleMouseWheelZoom); mControl.AvailableZoomLevels = mWireframeControl.AvailableZoomLevels; mControl.XnaUpdate += new Action(HandleXnaUpdate); mControl.Panning += HandlePanning; mSpriteOutline = new LineRectangle(managers); managers.ShapeManager.Add(mSpriteOutline); mSpriteOutline.Visible = false; mSpriteOutline.Color = OutlineColor; selectionPreviewRectangle = new LineRectangle(managers); managers.ShapeManager.Add(selectionPreviewRectangle); selectionPreviewRectangle.Visible = false; selectionPreviewRectangle.Color = MagicWandPreviewColor; // Move them up one Z to put them above the sprites: selectionPreviewRectangle.Z = 1; mLineGrid = new LineGrid(managers); managers.ShapeManager.Add(mLineGrid); mLineGrid.Visible = false; mLineGrid.Color = OutlineColor; mControl.Click += new EventHandler(HandleClick); mStatusText = new StatusTextController(managers); mControl_XnaInitialize(); WireframeEditControlsViewModel = wireframeEditControlsViewModel; WireframeEditControlsViewModel.PropertyChanged += HandleWireframePropertyChanged; }
private void UpdateHighlightElements() { SetLineRectangleAroundIpso(GetOrMakeRectangleAtIndex(0), mHighlightedIpso); if (mHighlightedIpso.Component is NineSlice) { NineSlice nineSlice = mHighlightedIpso.Component as NineSlice; float topHeight = 0; float centerHeight = 0; float bottomHeight = 0; float leftWidth = 0; float rightWidth = 0; float centerWidth = 0; if (nineSlice.TopTexture != null && nineSlice.BottomTexture != null && nineSlice.LeftTexture != null && nineSlice.RightTexture != null) { topHeight = nineSlice.OutsideSpriteHeight; bottomHeight = nineSlice.OutsideSpriteHeight; leftWidth = nineSlice.OutsideSpriteWidth; rightWidth = nineSlice.OutsideSpriteWidth; centerHeight = nineSlice.Height - (topHeight + bottomHeight); centerWidth = nineSlice.Width - (leftWidth + rightWidth); LineRectangle tallRectangle = GetOrMakeRectangleAtIndex(1); tallRectangle.Color = Color.Red; tallRectangle.X = nineSlice.GetAbsoluteX() + leftWidth; tallRectangle.Y = nineSlice.GetAbsoluteY(); tallRectangle.Width = centerWidth; tallRectangle.Height = nineSlice.Height; LineRectangle wideRectangle = GetOrMakeRectangleAtIndex(2); wideRectangle.Color = Color.Red; wideRectangle.X = nineSlice.GetAbsoluteX(); wideRectangle.Y = nineSlice.GetAbsoluteY() + topHeight; wideRectangle.Width = nineSlice.Width; wideRectangle.Height = centerHeight; } } }
public void HandleRegionDoubleClicked(ImageRegionSelectionControl control, ref LineRectangle textureOutlineRectangle) { var state = SelectedState.Self.SelectedStateSave; var instancePrefix = SelectedState.Self.SelectedInstance?.Name; var graphicalUiElement = SelectedState.Self.SelectedIpso as GraphicalUiElement; if (!string.IsNullOrEmpty(instancePrefix)) { instancePrefix += "."; } if (state != null && graphicalUiElement != null) { graphicalUiElement.TextureAddress = TextureAddress.Custom; var cursorX = (int)control.XnaCursor.GetWorldX(control.SystemManagers); var cursorY = (int)control.XnaCursor.GetWorldY(control.SystemManagers); int left = Math.Max(0, cursorX - 32); int top = Math.Max(0, cursorY - 32); int right = left + 64; int bottom = top + 64; int width = right - left; int height = bottom - top; graphicalUiElement.TextureLeft = MathFunctions.RoundToInt(left); graphicalUiElement.TextureTop = MathFunctions.RoundToInt(top); graphicalUiElement.TextureWidth = MathFunctions.RoundToInt(width); graphicalUiElement.TextureHeight = MathFunctions.RoundToInt(height); state.SetValue($"{instancePrefix}Texture Left", left, "int"); state.SetValue($"{instancePrefix}Texture Top", top, "int"); state.SetValue($"{instancePrefix}Texture Width", width, "int"); state.SetValue($"{instancePrefix}Texture Height", height, "int"); state.SetValue($"{instancePrefix}Texture Address", Gum.Managers.TextureAddress.Custom, nameof(TextureAddress)); RefreshOutline(control, ref textureOutlineRectangle); RefreshSelector(control, RefreshType.Force); } }
public RectangleSelector(SystemManagers managers) { HandleSize = 4; ResetsCursorIfNotOver = true; mShowHandles = true; mHandles = new List <LineCircle>(); mLineRectangle = new LineRectangle(managers); for (int i = 0; i < 8; i++) { LineCircle lineCircle = new LineCircle(managers); lineCircle.Radius = HandleSize; mHandles.Add(lineCircle); } Width = 34; Height = 34; }
LineRectangle GetOrMakeRectangleAtIndex(int i) { if (i < mHighlightRectangles.Count) { mHighlightRectangles[i].Visible = true; return(mHighlightRectangles[i]); } else { LineRectangle newRect = new LineRectangle(); newRect.Color = Color.Yellow; newRect.Visible = true; mHighlightRectangles.Add(newRect); ShapeManager.Self.Add(newRect, mUiLayer); return(newRect); } }
void HandleXnaInitialize() { mManagers = new SystemManagers(); mManagers.Initialize(mControl.GraphicsDevice); mManagers.Renderer.SamplerState = SamplerState.PointClamp; mManagers.Name = "Preview Window Managers"; ShapeManager shapeManager = mManagers.ShapeManager; mSprite = new RenderingLibrary.Graphics.Sprite(null); mSprite.Name = "Animation PreviewManager Main Sprite"; mRectangle = new LineRectangle(mManagers); mManagers.ShapeManager.Add(mRectangle); // Move it in front of the Sprite mRectangle.Z = 1; mManagers.SpriteManager.Add(mSprite); mControl.Resize += new EventHandler(HandleResize); mControl.XnaUpdate += new Action(HandleXnaUpdate); MoveCameraToProperLocation(); // We'll use Cursor.Self which is initialized and updated elsewhere // Actually looks like that's not the case. We'll make a new one. mCursor = new Cursor(); mCursor.Initialize(mControl); mKeyboard = new Keyboard(); mKeyboard.Initialize(mControl); mLeftRuler = new Ruler(mControl, mManagers, mCursor); mLeftRuler.RulerSide = RulerSide.Left; mTopRuler = new Ruler(mControl, mManagers, mCursor); mTopRuler.RulerSide = RulerSide.Top; mManagers.Renderer.Camera.CameraCenterOnScreen = CameraCenterOnScreen.TopLeft; mManagers.Renderer.Camera.X = -50; mManagers.Renderer.Camera.Y = -50; cameraController = new CameraController(Camera, mManagers, mCursor, mControl, mTopRuler, mLeftRuler); }
public RectangleSelector(SystemManagers managers) { this.managers = managers; HandleSize = 12; ResetsCursorIfNotOver = true; mShowHandles = true; mHandles = new List <LineRectangle>(); mLineRectangle = new LineRectangle(managers); for (int i = 0; i < 8; i++) { var lineRectangle = new LineRectangle(managers); lineRectangle.IsDotted = false; lineRectangle.Width = HandleSize; lineRectangle.Height = HandleSize; mHandles.Add(lineRectangle); } Width = 34; Height = 34; }
public PolygonWireframeEditor(Layer layer) { if (addPointTexture == null) { var gumExePath = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location).ToLower().Replace("/", "\\") + "\\"; ContentLoader loader = new ContentLoader(); var loaderManager = new LoaderManager(); loaderManager.ContentLoader = loader; var fileName = gumExePath + "Content/AddPoint.png"; //addPointTexture = loaderManager.LoadContent(fileName); using (var stream = FileManager.GetStreamForFile(fileName)) { addPointTexture = Texture2D.FromStream(SystemManagers.Default.Renderer.GraphicsDevice, stream); addPointTexture.Name = fileName; } //addPointTexture = LoaderManager.Self.LoadContent<Texture2D>(gumExePath + "Content/AddPoint.png"); } this.layer = layer; addPointSprite = new Sprite(addPointTexture); addPointSprite.Name = "Add point sprite"; SpriteManager.Self.Add(addPointSprite, layer); selectedPointLineRectangle = new LineRectangle(); ShapeManager.Self.Add(selectedPointLineRectangle, layer); selectedPointLineRectangle.Color = Color.Magenta; selectedPointLineRectangle.IsDotted = false; selectedPointLineRectangle.LinePixelWidth = 3; originDisplay = new OriginDisplay(layer); }
public void Initialize(ImageRegionSelectionControl control, SystemManagers managers, WireframeEditControls wireframeControl) { mManagers = managers; mManagers.Renderer.SamplerState = SamplerState.PointClamp; mControl = control; keyboard = new Keyboard(); keyboard.Initialize(control); mManagers.Renderer.Camera.CameraCenterOnScreen = CameraCenterOnScreen.TopLeft; mWireframeControl = wireframeControl; mWireframeControl.WandSelectionChanged += ReactToMagicWandChange; mControl.RegionChanged += new EventHandler(HandleRegionChanged); mControl.MouseWheelZoom += new EventHandler(HandleMouseWheelZoom); mControl.AvailableZoomLevels = mWireframeControl.AvailableZoomLevels; mControl.XnaUpdate += new Action(HandleXnaUpdate); mControl.Panning += HandlePanning; mSpriteOutline = new LineRectangle(managers); managers.ShapeManager.Add(mSpriteOutline); mSpriteOutline.Visible = false; mSpriteOutline.Color = OutlineColor; mLineGrid = new LineGrid(managers); managers.ShapeManager.Add(mLineGrid); mLineGrid.Visible = false; mLineGrid.Color = OutlineColor; mControl.Click += new EventHandler(HandleClick); mStatusText = new StatusTextController(managers); mControl_XnaInitialize(); }
public ResizeHandles(Layer layer) { for (int i = 0; i < mHandles.Length; i++) { mHandles[i] = new LineRectangle(); mHandles[i].IsDotted = false; mHandles[i].Width = WidthAtNoZoom; mHandles[i].Height = WidthAtNoZoom; ShapeManager.Self.Add(mHandles[i], layer); mInnerHandles[i] = new LineRectangle(); mInnerHandles[i].IsDotted = false; mInnerHandles[i].Width = WidthAtNoZoom - 2; mInnerHandles[i].Height = WidthAtNoZoom - 2; mInnerHandles[i].Color = Color.Black; ShapeManager.Self.Add(mInnerHandles[i], layer); } originDisplay = new OriginDisplay(layer); Visible = true; UpdateToProperties(); }
private void RenderUsingBitmapFont(SpriteBatch spriteBatch, SystemManagers managers) { if (mTempForRendering == null) { mTempForRendering = new LineRectangle(managers); } mTempForRendering.X = this.X; mTempForRendering.Y = this.Y; mTempForRendering.Width = this.mTextureToRender.Width * mFontScale; mTempForRendering.Height = this.mTextureToRender.Height * mFontScale; mTempForRendering.Parent = this.Parent; float widthDifference = this.EffectiveWidth - mTempForRendering.Width; if (this.HorizontalAlignment == Graphics.HorizontalAlignment.Center) { mTempForRendering.X += widthDifference / 2.0f; } else if (this.HorizontalAlignment == Graphics.HorizontalAlignment.Right) { mTempForRendering.X += widthDifference; } if (this.VerticalAlignment == Graphics.VerticalAlignment.Center) { mTempForRendering.Y += (this.EffectiveHeight - mTextureToRender.Height) / 2.0f; } else if (this.VerticalAlignment == Graphics.VerticalAlignment.Bottom) { mTempForRendering.Y += this.EffectiveHeight - mTempForRendering.Height; } Sprite.Render(managers, spriteBatch, mTempForRendering, mTextureToRender, new Color(mRed, mGreen, mBlue, mAlpha), null, false, false, Rotation, treat0AsFullDimensions: false); }
internal static bool TryHandleAsBaseType(string baseType, SystemManagers systemManagers, out IRenderable containedObject) { bool handledAsBaseType = true; containedObject = null; switch (baseType) { case "Container": LineRectangle lineRectangle = new LineRectangle(systemManagers); containedObject = lineRectangle; break; case "ColoredRectangle": SolidRectangle solidRectangle = new SolidRectangle(); containedObject = solidRectangle; break; case "Sprite": Texture2D texture = null; Sprite sprite = new Sprite(texture); containedObject = sprite; break; case "NineSlice": { NineSlice nineSlice = new NineSlice(); containedObject = nineSlice; } break; case "Text": { Text text = new Text(systemManagers, ""); //BitmapFont font = null; //if (rvf.GetValue<bool>("UseCustomFont")) //{ // string customFontFile = rvf.GetValue<string>("CustomFontFile"); // if (!string.IsNullOrEmpty(customFontFile)) // { // font = new BitmapFont(customFontFile, systemManagers); // } //} //else //{ // string fontName = rvf.GetValue<string>("Font"); // int fontSize = rvf.GetValue<int>("FontSize"); // verify these var names // fontName = "FontCache/Font" + fontSize.ToString() + fontName + ".fnt"; // font = new BitmapFont(fontName, systemManagers); //} containedObject = text; //Do Text specific alignment. //SetAlignmentValues(text, rvf); } break; default: handledAsBaseType = false; break; } return(handledAsBaseType); }
private void CreateNineSliceSplitLines() { NineSlice nineSlice = mHighlightedIpso.Component as NineSlice; float topHeight = 0; float centerHeight = 0; float bottomHeight = 0; float leftWidth = 0; float rightWidth = 0; float centerWidth = 0; if (nineSlice.TopTexture != null && nineSlice.BottomTexture != null && nineSlice.LeftTexture != null && nineSlice.RightTexture != null) { topHeight = nineSlice.OutsideSpriteHeight; bottomHeight = nineSlice.OutsideSpriteHeight; leftWidth = nineSlice.OutsideSpriteWidth; rightWidth = nineSlice.OutsideSpriteWidth; centerHeight = nineSlice.Height - (topHeight + bottomHeight); centerWidth = nineSlice.Width - (leftWidth + rightWidth); float offsetX = leftWidth; float offsetY = 0; //Vector3 right; //Vector3 up; //if (nineSlice.Rotation == 0) //{ // right = Vector3.Right; // up = Vector3.Up; //} //else //{ // var matrix = Matrix.CreateRotationZ(-MathHelper.ToRadians(nineSlice.Rotation)); // right = matrix.Right; // up = matrix.Up; //} LineRectangle tallRectangle = GetOrMakeRectangleAtIndex(1); tallRectangle.Color = Color.Red; tallRectangle.X = nineSlice.GetAbsoluteX() + offsetX; tallRectangle.Y = nineSlice.GetAbsoluteY(); tallRectangle.Width = centerWidth; tallRectangle.Height = nineSlice.Height; tallRectangle.Rotation = nineSlice.GetAbsoluteRotation(); offsetX = 0; offsetY = topHeight; LineRectangle wideRectangle = GetOrMakeRectangleAtIndex(2); wideRectangle.Color = Color.Red; wideRectangle.X = nineSlice.GetAbsoluteX(); wideRectangle.Y = nineSlice.GetAbsoluteY() + offsetY; wideRectangle.Width = nineSlice.Width; wideRectangle.Height = centerHeight; wideRectangle.Rotation = nineSlice.GetAbsoluteRotation(); } }
internal static bool TryHandleAsBaseType(string baseType, SystemManagers systemManagers, out IRenderable containedObject) { bool handledAsBaseType = true; containedObject = null; #if MONOGAME switch (baseType) { case "Container": case "Component": // this should never be set in Gum, but there could be XML errors or someone could have used an old Gum... if (GraphicalUiElement.ShowLineRectangles) { LineRectangle lineRectangle = new LineRectangle(systemManagers); containedObject = lineRectangle; } else { containedObject = new InvisibleRenderable(); } break; case "Rectangle": LineRectangle rectangle = new LineRectangle(systemManagers); rectangle.IsDotted = false; containedObject = rectangle; break; case "Circle": LineCircle circle = new LineCircle(systemManagers); circle.CircleOrigin = CircleOrigin.TopLeft; containedObject = circle; break; case "Polygon": LinePolygon polygon = new LinePolygon(systemManagers); containedObject = polygon; break; case "ColoredRectangle": SolidRectangle solidRectangle = new SolidRectangle(); containedObject = solidRectangle; break; case "Sprite": Texture2D texture = null; Sprite sprite = new Sprite(texture); containedObject = sprite; break; case "NineSlice": { NineSlice nineSlice = new NineSlice(); containedObject = nineSlice; } break; case "Text": { Text text = new Text(systemManagers, ""); containedObject = text; } break; default: handledAsBaseType = false; break; } #endif return(handledAsBaseType); }
void UpdateLinePrimitive() { LineRectangle.UpdateLinePrimitive(mBounds, this); }
/// <summary> /// Used for rendering directly to screen with an atlased texture. /// </summary> public void RenderAtlasedTextureToScreen(List <string> lines, HorizontalAlignment horizontalAlignment, float textureToRenderHeight, Color color, float rotation, float fontScale, SystemManagers managers, SpriteRenderer spriteRenderer, object objectRequestingChange) { var textObject = (Text)objectRequestingChange; var point = new Point(); int requiredWidth; int requiredHeight; List <int> widths = new List <int>(); GetRequiredWidthAndHeight(lines, out requiredWidth, out requiredHeight, widths); int lineNumber = 0; if (mCharRect == null) { mCharRect = new LineRectangle(managers); } var yoffset = 0f; if (textObject.VerticalAlignment == Graphics.VerticalAlignment.Center) { yoffset = (textObject.EffectiveHeight - textureToRenderHeight) / 2.0f; } else if (textObject.VerticalAlignment == Graphics.VerticalAlignment.Bottom) { yoffset = textObject.EffectiveHeight - textureToRenderHeight * fontScale; } foreach (string line in lines) { // scoot over to leave room for the outline point.X = mOutlineThickness; if (horizontalAlignment == HorizontalAlignment.Right) { point.X = (int)(textObject.Width - widths[lineNumber] * fontScale); } else if (horizontalAlignment == HorizontalAlignment.Center) { point.X = (int)(textObject.Width - widths[lineNumber] * fontScale) / 2; } foreach (char c in line) { Rectangle destRect; int pageIndex; var sourceRect = GetCharacterRect(c, lineNumber, ref point, out destRect, out pageIndex, textObject.FontScale); var origin = new Point((int)textObject.X, (int)(textObject.Y + yoffset)); var rotate = (float)-(textObject.Rotation * System.Math.PI / 180f); var rotatingPoint = new Point(origin.X + destRect.X, origin.Y + destRect.Y); MathFunctions.RotatePointAroundPoint(new Point(origin.X, origin.Y), ref rotatingPoint, rotate); mCharRect.X = rotatingPoint.X; mCharRect.Y = rotatingPoint.Y; mCharRect.Width = destRect.Width; mCharRect.Height = destRect.Height; if (textObject.Parent != null) { mCharRect.X += textObject.Parent.GetAbsoluteX(); mCharRect.Y += textObject.Parent.GetAbsoluteY(); } Sprite.Render(managers, spriteRenderer, mCharRect, mTextures[0], color, sourceRect, false, false, rotation, treat0AsFullDimensions: false, objectCausingRenering: objectRequestingChange); } point.X = 0; lineNumber++; } }