本文整理汇总了C#中VRageMath.Rectangle类的典型用法代码示例。如果您正苦于以下问题:C# Rectangle类的具体用法?C# Rectangle怎么用?C# Rectangle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rectangle类属于VRageMath命名空间,在下文中一共展示了Rectangle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
internal void Draw(Rectangle rect, Color color, MyVideoRectangleFitMode fitMode)
{
int w = 0, h = 0;
byte [] data = m_wrapper.GetTextureData(ref w, ref h);
process_frame(data, w, h);
Rectangle dst = rect;
Rectangle src = new Rectangle(0, 0, w, h);
var videoSize = new Vector2(w, h);
float videoAspect = videoSize.X / videoSize.Y;
float rectAspect = (float)rect.Width / (float)rect.Height;
// Automatic decision based on ratios.
if (fitMode == MyVideoRectangleFitMode.AutoFit)
fitMode = (videoAspect > rectAspect) ? MyVideoRectangleFitMode.FitHeight : MyVideoRectangleFitMode.FitWidth;
float scaleRatio = 0.0f;
switch (fitMode)
{
case MyVideoRectangleFitMode.None:
break;
case MyVideoRectangleFitMode.FitWidth:
scaleRatio = (float)dst.Width / videoSize.X;
dst.Height = (int)(scaleRatio * videoSize.Y);
if (dst.Height > rect.Height)
{
var diff = dst.Height - rect.Height;
dst.Height = rect.Height;
diff = (int)(diff / scaleRatio);
src.Y += (int)(diff * 0.5f);
src.Height -= diff;
}
break;
case MyVideoRectangleFitMode.FitHeight:
scaleRatio = (float)dst.Height / videoSize.Y;
dst.Width = (int)(scaleRatio * videoSize.X);
if (dst.Width > rect.Width)
{
var diff = dst.Width - rect.Width;
dst.Width = rect.Width;
diff = (int)(diff / scaleRatio);
src.X += (int)(diff * 0.5f);
src.Width -= diff;
}
break;
}
dst.X = rect.Left + (rect.Width - dst.Width) / 2;
dst.Y = rect.Top + (rect.Height - dst.Height) / 2;
VRageMath.RectangleF destination = new VRageMath.RectangleF(dst.X, dst.Y, dst.Width, -dst.Height);
VRageMath.Rectangle? source = src;
Vector2 origin = new Vector2(src.Width / 2 * 0, src.Height);
MySpritesRenderer.AddSingleSprite(m_texture, videoSize, color, origin, Vector2.UnitX, source, destination);
}
示例2: DrawSprite
public static void DrawSprite(string texture, ref RectangleF destination, bool scaleDestination, ref Rectangle? sourceRectangle, Color color, float rotation, Vector2 rightVector, ref Vector2 origin, SpriteEffects effects, float depth, bool waitTillLoaded = true, string targetTexture = null)
{
var message = MessagePool.Get<MyRenderMessageDrawSprite>(MyRenderMessageEnum.DrawSprite);
message.Texture = texture;
message.DestinationRectangle = destination;
message.SourceRectangle = sourceRectangle;
message.Color = color;
message.Rotation = rotation;
message.RightVector = rightVector;
message.Depth = depth;
message.Effects = effects;
message.Origin = origin;
message.ScaleDestination = scaleDestination;
message.WaitTillLoaded = waitTillLoaded;
message.TargetTexture = targetTexture;
EnqueueMessage(message);
}
示例3: DrawVideo
static void DrawVideo(uint id, Rectangle rect, Color color, MyVideoRectangleFitMode fitMode)
{
MyVideoPlayerDx9 video;
if (m_videos.TryGetValue(id, out video))
{
Rectangle dst = rect;
Rectangle src = new Rectangle(0, 0, video.VideoWidth, video.VideoHeight);
var videoSize = new Vector2(video.VideoWidth, video.VideoHeight);
float videoAspect = videoSize.X / videoSize.Y;
float rectAspect = (float)rect.Width / (float)rect.Height;
// Automatic decision based on ratios.
if (fitMode == MyVideoRectangleFitMode.AutoFit)
fitMode = (videoAspect > rectAspect) ? MyVideoRectangleFitMode.FitHeight : MyVideoRectangleFitMode.FitWidth;
float scaleRatio = 0.0f;
switch (fitMode)
{
case MyVideoRectangleFitMode.None:
break;
case MyVideoRectangleFitMode.FitWidth:
scaleRatio = (float)dst.Width / videoSize.X;
dst.Height = (int)(scaleRatio * videoSize.Y);
if (dst.Height > rect.Height)
{
var diff = dst.Height - rect.Height;
dst.Height = rect.Height;
diff = (int)(diff / scaleRatio);
src.Y += (int)(diff * 0.5f);
src.Height -= diff;
}
break;
case MyVideoRectangleFitMode.FitHeight:
scaleRatio = (float)dst.Height / videoSize.Y;
dst.Width = (int)(scaleRatio * videoSize.X);
if (dst.Width > rect.Width)
{
var diff = dst.Width - rect.Width;
dst.Width = rect.Width;
diff = (int)(diff / scaleRatio);
src.X += (int)(diff * 0.5f);
src.Width -= diff;
}
break;
}
dst.X = rect.Left + (rect.Width - dst.Width) / 2;
dst.Y = rect.Top + (rect.Height - dst.Height) / 2;
Texture texture = video.OutputFrame;
// Draw upside down
VRageMath.RectangleF destination = new VRageMath.RectangleF(dst.X, dst.Y, dst.Width, -dst.Height);
VRageMath.Rectangle? source = src;
Vector2 origin = new Vector2(src.Width / 2 * 0, src.Height);
MyRender.DrawSprite(texture, null, ref destination, false, ref source, color, Vector2.UnitX, ref origin, VRageRender.Graphics.SpriteEffects.None, 0f);
}
}
示例4: SpriteScissorPush
public static void SpriteScissorPush(Rectangle screenRectangle)
{
var message = MessagePool.Get<MyRenderMessageSpriteScissorPush>(MyRenderMessageEnum.SpriteScissorPush);
message.ScreenRectangle = screenRectangle;
EnqueueMessage(message);
}
示例5: UsingScissorRectangle
public static SpriteScissorToken UsingScissorRectangle(ref RectangleF normalizedRectangle)
{
Vector2 screenSize = GetScreenSizeFromNormalizedSize(normalizedRectangle.Size);
Vector2 screenPosition = GetScreenCoordinateFromNormalizedCoordinate(normalizedRectangle.Position);
var screenRectangle = new Rectangle((int)Math.Round(screenPosition.X, MidpointRounding.AwayFromZero),
(int)Math.Round(screenPosition.Y, MidpointRounding.AwayFromZero),
(int)Math.Round(screenSize.X, MidpointRounding.AwayFromZero),
(int)Math.Round(screenSize.Y, MidpointRounding.AwayFromZero));
VRageRender.MyRenderProxy.SpriteScissorPush(screenRectangle);
return new SpriteScissorToken();
}
示例6: GetSafeAspectRatioPictureSize
// Return picture size that is safe for displaying in bounding area and doesn't distort the aspect ratio of original picture or bounding area.
// Example: picture of video frame is scaled to size of screen, so it fits it as much as possible, but still maintains aspect ration of
// original video frame or screen. So if screen's heigh is not enouch, video frame is scaled down to fit height, but also width is scaled
// according to original video frame.
// It's used whenever we need to scale picture/texture to some area, usually to screen size.
// Also this method calculated left/top coordinates, so it's always centered.
static void GetSafeAspectRatioPictureSize(Vector2I originalSize, Rectangle boundingArea, out Rectangle outRect)
{
outRect.Width = boundingArea.Width;
outRect.Height = (int)(((float)outRect.Width / (float)originalSize.X) * originalSize.Y);
if (outRect.Height > boundingArea.Height)
{
outRect.Height = boundingArea.Height;
outRect.Width = (int)(outRect.Height * ((float)originalSize.X / (float)originalSize.Y));
}
outRect.X = boundingArea.Left + (boundingArea.Width - outRect.Width) / 2;
outRect.Y = boundingArea.Top + (boundingArea.Height - outRect.Height) / 2;
}
示例7: GetSafeAspectRatioFullScreenPictureSize
public static void GetSafeAspectRatioFullScreenPictureSize(Vector2I originalSize, out Rectangle outRect)
{
GetSafeAspectRatioPictureSize(originalSize, m_safeFullscreenRectangle, out outRect);
}
示例8: DrawSpriteBatch
/// <summary>Draws sprite batch at specified position</summary>
/// <param name="normalizedCoord">X and Y are within interval [0,1]</param>
/// <param name="normalizedSize">size of destination rectangle (normalized).
/// Don't forget that it may be distorted by aspect ration, so rectangle size
/// [1,1] can make larger wide than height on your screen.</param>
/// <param name="useFullClientArea">True uses full client rectangle. False limits to GUI rectangle</param>
public static void DrawSpriteBatch(string texture, Vector2 normalizedCoord, Vector2 normalizedSize, Color color, MyGuiDrawAlignEnum drawAlign, bool useFullClientArea = false, bool waitTillLoaded = true)
{
if (string.IsNullOrEmpty(texture))
return;
Vector2 screenCoord = GetScreenCoordinateFromNormalizedCoordinate(normalizedCoord, useFullClientArea);
Vector2 screenSize = GetScreenSizeFromNormalizedSize(normalizedSize, useFullClientArea);
screenCoord = MyUtils.GetCoordAligned(screenCoord, screenSize, drawAlign);
var rect = new Rectangle((int)screenCoord.X, (int)screenCoord.Y, (int)screenSize.X, (int)screenSize.Y);
DrawSprite(texture, rect, color, waitTillLoaded);
}
示例9: DrawSprite
static void DrawSprite(string texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, float scale, VRageRender.Graphics.SpriteEffects effects, float layerDepth)
{
var destination = new RectangleF(position.X, position.Y, scale, scale);
DrawSprite(texture, ref destination, true, ref sourceRectangle, color, rotation, ref origin, effects, layerDepth);
}
示例10: DrawSpriteBatch
// Draws sprite batch at specified SCREEN position (in screen coordinates, not normalized coordinates).
public static void DrawSpriteBatch(string texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, float scale, VRageRender.Graphics.SpriteEffects effects, float layerDepth)
{
DrawSprite(texture, position, sourceRectangle, color, rotation, origin, scale, effects, layerDepth);
}
示例11: DrawVideo
static void DrawVideo(uint id, Rectangle rect, Color color, MyVideoRectangleFitMode fitMode)
{
Debug.Assert(false);
}
示例12: DrawSprite
static void DrawSprite(string texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth, bool waitTillLoaded = true)
{
var destination = new RectangleF(position.X, position.Y, scale, scale);
DrawSprite(texture, ref destination, true, ref sourceRectangle, color, rotation, ref origin, effects, layerDepth, waitTillLoaded);
}
示例13: ProcessDrawMessage
private static void ProcessDrawMessage(MyRenderMessageBase drawMessage)
{
switch (drawMessage.MessageType)
{
case MyRenderMessageEnum.SpriteScissorPush:
{
var msg = drawMessage as MyRenderMessageSpriteScissorPush;
MySpritesRenderer.ScissorStackPush(msg.ScreenRectangle);
break;
}
case MyRenderMessageEnum.SpriteScissorPop:
{
MySpritesRenderer.ScissorStackPop();
break;
}
case MyRenderMessageEnum.DrawSprite:
{
MyRenderMessageDrawSprite sprite = (MyRenderMessageDrawSprite)drawMessage;
MyFileTextureManager texManager = MyManagers.FileTextures;
MySpritesRenderer.AddSingleSprite(texManager.GetTexture(sprite.Texture, MyFileTextureEnum.GUI, waitTillLoaded: sprite.WaitTillLoaded), sprite.Color, sprite.Origin, sprite.RightVector, sprite.SourceRectangle, sprite.DestinationRectangle);
break;
}
case MyRenderMessageEnum.DrawSpriteNormalized:
{
MyRenderMessageDrawSpriteNormalized sprite = (MyRenderMessageDrawSpriteNormalized)drawMessage;
var rotation = sprite.Rotation;
if (sprite.RotationSpeed != 0)
{
rotation += sprite.RotationSpeed * (float)(MyRender11.CurrentDrawTime - MyRender11.CurrentUpdateTime).Seconds;
}
Vector2 rightVector = rotation != 0f ? new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) : sprite.RightVector;
int safeGuiSizeY = MyRender11.ResolutionI.Y;
int safeGuiSizeX = (int)(safeGuiSizeY * 1.3333f); // This will mantain same aspect ratio for GUI elements
var safeGuiRectangle = new VRageMath.Rectangle(MyRender11.ResolutionI.X / 2 - safeGuiSizeX / 2, 0, safeGuiSizeX, safeGuiSizeY);
var safeScreenScale = (float)safeGuiSizeY / MyRenderGuiConstants.REFERENCE_SCREEN_HEIGHT;
float fixedScale = sprite.Scale * safeScreenScale;
var tex = MyManagers.FileTextures.GetTexture(sprite.Texture, MyFileTextureEnum.GUI, true);
var normalizedCoord = sprite.NormalizedCoord;
var screenCoord = new Vector2(safeGuiRectangle.Left + safeGuiRectangle.Width * normalizedCoord.X,
safeGuiRectangle.Top + safeGuiRectangle.Height * normalizedCoord.Y);
Vector2 sizeInPixels = tex.Size;
var sizeInPixelsScaled = sizeInPixels * fixedScale;
Vector2 alignedScreenCoord = screenCoord;
var drawAlign = sprite.DrawAlign;
if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP)
{
// Nothing to do as position is already at this point
}
else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER)
{
// Move position to the texture center
alignedScreenCoord -= sizeInPixelsScaled / 2.0f;
}
else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP)
{
alignedScreenCoord.X -= sizeInPixelsScaled.X / 2.0f;
}
else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM)
{
alignedScreenCoord.X -= sizeInPixelsScaled.X / 2.0f;
alignedScreenCoord.Y -= sizeInPixelsScaled.Y;
}
else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM)
{
alignedScreenCoord -= sizeInPixelsScaled;
}
else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER)
{
alignedScreenCoord.Y -= sizeInPixelsScaled.Y / 2.0f;
}
else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER)
{
alignedScreenCoord.X -= sizeInPixelsScaled.X;
alignedScreenCoord.Y -= sizeInPixelsScaled.Y / 2.0f;
}
else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM)
{
alignedScreenCoord.Y -= sizeInPixelsScaled.Y;// *0.75f;
}
else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP)
{
alignedScreenCoord.X -= sizeInPixelsScaled.X;
//.........这里部分代码省略.........
示例14: DrawVideo
public static void DrawVideo(uint id, Rectangle rect, Color color)
{
DrawVideo(id, rect, color, MyVideoRectangleFitMode.None);
}
示例15: GetSafeHeightPictureSize
// This method scales picture to bounding area according to bounding area's height. We don't care about width, so sometimes if picture has wide
// aspect ratio, borders of image may be outisde of the bounding area. This method is used when we want to have picture covering whole screen
// and don't care if part of picture is invisible. Also, aspect ration is unchanged too.
static void GetSafeHeightPictureSize(Vector2I originalSize, Rectangle boundingArea, out Rectangle outRect)
{
outRect.Height = boundingArea.Height;
outRect.Width = (int)(((float)outRect.Height / (float)originalSize.Y) * originalSize.X);
outRect.X = boundingArea.Left + (boundingArea.Width - outRect.Width) / 2;
outRect.Y = boundingArea.Top + (boundingArea.Height - outRect.Height) / 2;
}