internal AxisAlignedBox computePosition(AxisAlignedBox area, Vector2 size) { var sizeOver2 = size / 2; var positionSizeOver2 = area.Size / 2; var position = area.minVector; switch (alignment) { case GUIAnchor.MiddleLeft: position.Y = area.Y0 + positionSizeOver2.Y - sizeOver2.Y; break; case GUIAnchor.LowerLeft: position.Y = area.Y1 - size.Y; break; case GUIAnchor.UpperCenter: position.X = area.X0 + positionSizeOver2.X - sizeOver2.X; break; case GUIAnchor.MiddleCenter: position.X = area.X0 + positionSizeOver2.X - sizeOver2.X; goto case GUIAnchor.MiddleLeft; case GUIAnchor.LowerCenter: position.X = area.X0 + positionSizeOver2.X - sizeOver2.X; goto case GUIAnchor.LowerLeft; case GUIAnchor.UpperRight: position.X = area.X1 - size.X; break; case GUIAnchor.MiddleRight: position.X = area.X1 - size.X; goto case GUIAnchor.MiddleLeft; case GUIAnchor.LowerRight: position.X = area.X1 - size.X; goto case GUIAnchor.LowerLeft; } return(AxisAlignedBox.FromRect(position + contentOffset, size)); }
//private void init() //{ // _transform = this.gameObject.transform2(); //} private void render() { if (frame >= frames.Count || frame < 0) { return; } var src = AxisAlignedBox.FromRect(frames[frame].point * size, frames[frame].size); Root.instance.graphics.Draw(renderQuere, material, gameObject.transform.DerivedPosition + offset, src, color, gameObject.transform.DerivedOrientation + rotation, Vector2.Zero,//origin, size * gameObject.transform.DerivedScale, spriteEffect, gameObject.transform.DerivedDepth); //var end = ProjectPointFromCenterRotation(100); //Root.instance.graphics.DrawLine(renderQuere, material, _transform.DerivedPosition, end, color); }
internal void Draw(RenderManager graphics, GUIContent content, GUIDrawArguments drawArgs) { var size = drawArgs.position.Size; if (fixedWidth > 0f) { size.X = fixedWidth; } if (fixedHeight > 0f) { size.Y = fixedHeight; } drawArgs.content = AxisAlignedBox.FromRect(drawArgs.position.minVector + padding.min, size - padding.max - padding.min); var textSize = Vector2.Zero; if (!string.IsNullOrEmpty(content.text)) { if (wordWrap) { textSize = font.MeasureString(content.text, drawArgs.content.Size); } else { textSize = font.MeasureString(content.text); } } var remainingWidth = drawArgs.content.Width - textSize.X; var remainingHeight = drawArgs.content.Height - textSize.Y; var drawIcon = content.icon != null; var drawText = !string.IsNullOrEmpty(content.text); var state = getState(drawArgs); if (remainingWidth <= 0 && imagePosition == ImagePosition.ImageLeft) { textSize.X = drawArgs.content.Width; drawIcon = false; } else if (remainingHeight <= 0 && imagePosition == ImagePosition.ImageAbove) { textSize.Y = drawArgs.content.Height; drawIcon = false; } var material = state.material;// Root.instance.resources.createMaterialFromTexture("content/textures/gui/box.png") if (material != null) { if (border.min == Vector2.Zero && border.max == Vector2.Zero) { graphics.Draw(material, drawArgs.position, state.backgroundColor); } else { var src = AxisAlignedBox.FromRect(Vector2.Zero, material.textureSize); var dstRects = drawArgs.position.fromRectOffset(border); var srcRects = src.fromRectOffset(border); for (var i = 0; i < dstRects.Length; i++) { if (dstRects[i].Width > 0 && dstRects[i].Height > 0) { graphics.Draw(material, dstRects[i], srcRects[i], state.backgroundColor); } } } } if (drawIcon && imagePosition == ImagePosition.ImageLeft) { AxisAlignedBox icon, text; computeTextAndIconLeft(content, drawArgs.content, textSize, remainingWidth, out icon, out text); graphics.Draw(content.icon, icon, Color.White); font.DrawText(graphics.currentRenderQueue, text.minVector, this.fontSize, content.text, state.textColor, 0f, text.Width); } else if (drawIcon && imagePosition == ImagePosition.ImageAbove) { AxisAlignedBox icon, text; computeTextAndIconAbove(content, drawArgs.content, textSize, remainingHeight, out icon, out text); graphics.Draw(content.icon, icon, Color.White); if (wordWrap) { font.DrawWrappedOnWordText(graphics.currentRenderQueue, text.minVector, this.fontSize, content.text, state.textColor, 0f, text.Size); } else { font.DrawText(graphics.currentRenderQueue, text.minVector, this.fontSize, content.text, state.textColor, 0f, text.Width); } } else if (drawText && imagePosition != ImagePosition.ImageOnly) { var position = computePosition(drawArgs.content, textSize); if (wordWrap) { font.DrawWrappedOnWordText(graphics.currentRenderQueue, position.minVector, this.fontSize, content.text, state.textColor, 0f, position.Size); } else { font.DrawText(graphics.currentRenderQueue, position.minVector, this.fontSize, content.text, state.textColor, 0f, position.Width); } } else if (drawIcon && imagePosition != ImagePosition.TextOnly) { var position = computePosition(drawArgs.content, content.icon.textureSize); graphics.Draw(content.icon, position, Color.White); graphics.DrawRect(position, Color.Blue); } }
internal void computeTextAndIconAbove(GUIContent content, AxisAlignedBox area, Vector2 textSize, float remainingHeight, out AxisAlignedBox icon, out AxisAlignedBox text) { var textSizeOver2 = textSize / 2; var positionSizeOver2 = area.Size / 2; var drawPosition = area.minVector; var scaleSize = Vector2.One * Utility.Min(remainingHeight, area.Height); var iconSize = Utility.ScaleToSize(content.icon.textureSize, scaleSize); var iconSizeOver2 = iconSize / 2; var iconPosition = area.minVector; switch (alignment) { case GUIAnchor.UpperLeft: drawPosition.Y += iconSize.Y; break; case GUIAnchor.MiddleLeft: { var size = (area.Height - (iconSize.Y + textSize.Y)) / 2; iconPosition.Y += size; drawPosition.Y = iconPosition.Y + iconSize.Y; } break; case GUIAnchor.LowerLeft: drawPosition.Y = area.Y1 - textSize.Y; iconPosition.Y = drawPosition.Y - iconSize.Y; break; case GUIAnchor.UpperRight: drawPosition.X = area.X1 - textSize.X; drawPosition.Y += iconSize.Y; iconPosition.X += area.Width - iconSize.X; break; case GUIAnchor.MiddleRight: { var sizeH = (area.Height - (iconSize.Y + textSize.Y)) / 2; drawPosition.X = area.X1 - textSize.X; iconPosition.X = area.X1 - iconSize.X; iconPosition.Y += sizeH; drawPosition.Y = iconPosition.Y + iconSize.Y; } break; case GUIAnchor.LowerRight: drawPosition.Y = area.Y1 - textSize.Y; drawPosition.X = area.X1 - textSize.X; iconPosition.X = area.X1 - iconSize.X; iconPosition.Y = drawPosition.Y - iconSize.Y; break; case GUIAnchor.UpperCenter: drawPosition.X = area.X0 + positionSizeOver2.X - textSizeOver2.X; iconPosition.X += positionSizeOver2.X - iconSizeOver2.X; drawPosition.Y += iconSize.Y; break; case GUIAnchor.MiddleCenter: { var sizeH = (area.Height - (iconSize.Y + textSize.Y)) / 2; iconPosition.X += positionSizeOver2.X - iconSizeOver2.X; iconPosition.Y += sizeH; drawPosition.X = area.X0 + positionSizeOver2.X - textSizeOver2.X; drawPosition.Y = iconPosition.Y + iconSize.Y; break; } case GUIAnchor.LowerCenter: drawPosition.Y = area.Y1 - textSize.Y; drawPosition.X = area.X0 + positionSizeOver2.X - textSizeOver2.X; iconPosition.X += positionSizeOver2.X - iconSizeOver2.X; iconPosition.Y = drawPosition.Y - iconSize.Y; break; } switch (alignment) { case GUIAnchor.LowerLeft: case GUIAnchor.MiddleLeft: case GUIAnchor.UpperLeft: if (textSize.X > iconSize.X) { iconPosition.X += textSizeOver2.X - iconSizeOver2.X; } else { drawPosition.X += iconSizeOver2.X - textSizeOver2.X; } break; case GUIAnchor.LowerRight: case GUIAnchor.MiddleRight: case GUIAnchor.UpperRight: if (textSize.X > iconSize.X) { iconPosition.X -= textSizeOver2.X - iconSizeOver2.X; } else { drawPosition.X -= iconSizeOver2.X - textSizeOver2.X; } break; } icon = AxisAlignedBox.FromRect(iconPosition + contentOffset, iconSize); text = AxisAlignedBox.FromRect(drawPosition + contentOffset, textSize); }