mirror of
https://github.com/Memorix101/UnityXNA/
synced 2024-12-30 15:25:35 +01:00
Added Viewport support
This commit is contained in:
parent
64046bbdfe
commit
602464fbc6
@ -13,6 +13,7 @@ class DrawSpriteCall
|
|||||||
private Vector4 color;
|
private Vector4 color;
|
||||||
private Vector2 origin;
|
private Vector2 origin;
|
||||||
private SpriteEffects spriteEffects;
|
private SpriteEffects spriteEffects;
|
||||||
|
private Viewport viewport;
|
||||||
|
|
||||||
public Texture2D Texture2D {
|
public Texture2D Texture2D {
|
||||||
get {
|
get {
|
||||||
@ -49,8 +50,16 @@ class DrawSpriteCall
|
|||||||
return this.spriteEffects;
|
return this.spriteEffects;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DrawSpriteCall(Texture2D texture2D, Vector2 position, Nullable<Rectangle> source, Vector4 color, Vector2 origin, SpriteEffects spriteEffects)
|
public Viewport Viewport
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return this.viewport;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawSpriteCall(Texture2D texture2D, Vector2 position, Nullable<Rectangle> source, Vector4 color, Vector2 origin, SpriteEffects spriteEffects, Viewport viewport)
|
||||||
{
|
{
|
||||||
// TODO: Complete member initialization
|
// TODO: Complete member initialization
|
||||||
this.texture2D = texture2D;
|
this.texture2D = texture2D;
|
||||||
@ -59,6 +68,7 @@ class DrawSpriteCall
|
|||||||
this.color = color;
|
this.color = color;
|
||||||
this.origin = origin;
|
this.origin = origin;
|
||||||
this.spriteEffects = spriteEffects;
|
this.spriteEffects = spriteEffects;
|
||||||
}
|
this.viewport = viewport;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,10 @@ class DrawStringCall
|
|||||||
private SpriteFont font;
|
private SpriteFont font;
|
||||||
private string value;
|
private string value;
|
||||||
private Vector2 position;
|
private Vector2 position;
|
||||||
private Vector4 color ;
|
private Vector4 color;
|
||||||
|
private Viewport viewport;
|
||||||
|
|
||||||
public SpriteFont Font {
|
public SpriteFont Font {
|
||||||
get {
|
get {
|
||||||
return this.font;
|
return this.font;
|
||||||
}
|
}
|
||||||
@ -35,12 +36,22 @@ class DrawStringCall
|
|||||||
return this.color;
|
return this.color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public DrawStringCall(SpriteFont font, string value, Vector2 position, Vector4 color)
|
|
||||||
|
public Viewport Viewport
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return this.viewport;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawStringCall(SpriteFont font, string value, Vector2 position, Vector4 color, Viewport viewport)
|
||||||
{
|
{
|
||||||
this.font = font;
|
this.font = font;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
this.viewport = viewport;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -44,10 +44,18 @@ namespace Microsoft.Xna.Framework
|
|||||||
{
|
{
|
||||||
content = new ContentManager(null, "");
|
content = new ContentManager(null, "");
|
||||||
|
|
||||||
_components = new GameComponentCollection();
|
_components = new GameComponentCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Initialize()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Update(GameTime gameTime)
|
protected virtual void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void UnloadContent()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,14 +104,14 @@ namespace Microsoft.Xna.Framework
|
|||||||
}
|
}
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
UnloadContent();
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
internal void Begin()
|
internal void Begin()
|
||||||
{
|
{
|
||||||
|
Initialize();
|
||||||
LoadContent();
|
LoadContent();
|
||||||
// XNA's first update call has a zero elapsed time, so do one now.
|
// XNA's first update call has a zero elapsed time, so do one now.
|
||||||
GameTime gameTime = new GameTime(new TimeSpan(0), new TimeSpan(0), new TimeSpan(0, 0, 0, 0, 0), new TimeSpan(0, 0, 0, 0, 0));
|
GameTime gameTime = new GameTime(new TimeSpan(0), new TimeSpan(0), new TimeSpan(0, 0, 0, 0, 0), new TimeSpan(0, 0, 0, 0, 0));
|
||||||
@ -118,8 +126,6 @@ namespace Microsoft.Xna.Framework
|
|||||||
GameTime gameTime = new GameTime(new TimeSpan(0), new TimeSpan(0), new TimeSpan(totalTicks), new TimeSpan(ticks));
|
GameTime gameTime = new GameTime(new TimeSpan(0), new TimeSpan(0), new TimeSpan(totalTicks), new TimeSpan(ticks));
|
||||||
Update(gameTime);
|
Update(gameTime);
|
||||||
Draw(gameTime);
|
Draw(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,9 @@ namespace Microsoft.Xna.Framework
|
|||||||
{
|
{
|
||||||
private Game game;
|
private Game game;
|
||||||
|
|
||||||
|
private int _preferredBackBufferHeight;
|
||||||
|
private int _preferredBackBufferWidth;
|
||||||
|
|
||||||
public GraphicsDevice GraphicsDevice
|
public GraphicsDevice GraphicsDevice
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -23,5 +26,31 @@ namespace Microsoft.Xna.Framework
|
|||||||
// TODO: Complete member initialization
|
// TODO: Complete member initialization
|
||||||
this.game = game;
|
this.game = game;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int PreferredBackBufferWidth
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _preferredBackBufferWidth;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
//_shouldApplyChanges = true;
|
||||||
|
_preferredBackBufferWidth = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int PreferredBackBufferHeight
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _preferredBackBufferHeight;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
//_shouldApplyChanges = true;
|
||||||
|
_preferredBackBufferHeight = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,11 @@ namespace Microsoft.Xna.Framework
|
|||||||
{
|
{
|
||||||
if (!Application.isEditor)
|
if (!Application.isEditor)
|
||||||
{
|
{
|
||||||
return new Rectangle(Screen.mainWindowPosition.x, Screen.mainWindowPosition.y, Screen.height, Screen.width);
|
return new Rectangle(Screen.mainWindowPosition.x, Screen.mainWindowPosition.y, Screen.width, Screen.height);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new Rectangle(0, 0, Screen.height, Screen.width);
|
return new Rectangle(0, 0, Screen.width, Screen.height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,19 +71,19 @@ namespace Microsoft.Xna.Framework.Graphics
|
|||||||
|
|
||||||
internal void Draw(Texture2D texture2D, Vector2 position, Nullable<Rectangle> source, Color color, float p, Vector2 Origin, float p_2, SpriteEffects spriteEffects, float p_3)
|
internal void Draw(Texture2D texture2D, Vector2 position, Nullable<Rectangle> source, Color color, float p, Vector2 Origin, float p_2, SpriteEffects spriteEffects, float p_3)
|
||||||
{
|
{
|
||||||
graphicsDevice.DrawQueue.EnqueueSprite(new DrawSpriteCall(texture2D, position, source, color.ToVector4(), Origin, spriteEffects));
|
graphicsDevice.DrawQueue.EnqueueSprite(new DrawSpriteCall(texture2D, position, source, color.ToVector4(), Origin, spriteEffects, graphicsDevice.Viewport));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Draw stretching
|
//TODO: Draw stretching
|
||||||
internal void Draw(Texture2D texture2D, Nullable<Rectangle> source, Color color)
|
internal void Draw(Texture2D texture2D, Nullable<Rectangle> source, Color color)
|
||||||
{
|
{
|
||||||
graphicsDevice.DrawQueue.EnqueueSprite(new DrawSpriteCall(texture2D, Vector2.Zero, source, color.ToVector4(), Vector2.Zero, SpriteEffects.None));
|
graphicsDevice.DrawQueue.EnqueueSprite(new DrawSpriteCall(texture2D, Vector2.Zero, source, color.ToVector4(), Vector2.Zero, SpriteEffects.None, graphicsDevice.Viewport));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Draw texture section
|
//Draw texture section
|
||||||
internal void Draw(Texture2D texture2D, Vector2 position, Nullable<Rectangle> source, Color color)
|
internal void Draw(Texture2D texture2D, Vector2 position, Nullable<Rectangle> source, Color color)
|
||||||
{
|
{
|
||||||
graphicsDevice.DrawQueue.EnqueueSprite(new DrawSpriteCall(texture2D, position, source, color.ToVector4(), Vector2.Zero, SpriteEffects.None));
|
graphicsDevice.DrawQueue.EnqueueSprite(new DrawSpriteCall(texture2D, position, source, color.ToVector4(), Vector2.Zero, SpriteEffects.None, graphicsDevice.Viewport));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO:
|
//TODO:
|
||||||
@ -115,23 +115,23 @@ namespace Microsoft.Xna.Framework.Graphics
|
|||||||
texCoordTL.X = temp;
|
texCoordTL.X = temp;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
graphicsDevice.DrawQueue.EnqueueSprite(new DrawSpriteCall(texture, Vector2.Zero, source, color.ToVector4(), Vector2.Zero, SpriteEffects.None));
|
graphicsDevice.DrawQueue.EnqueueSprite(new DrawSpriteCall(texture, Vector2.Zero, source, color.ToVector4(), Vector2.Zero, SpriteEffects.None, graphicsDevice.Viewport));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO:
|
//TODO:
|
||||||
internal void Draw (Texture2D texture, Nullable<Rectangle> source, Rectangle? sourceRectangle, Color color)
|
internal void Draw (Texture2D texture, Nullable<Rectangle> source, Rectangle? sourceRectangle, Color color)
|
||||||
{
|
{
|
||||||
graphicsDevice.DrawQueue.EnqueueSprite(new DrawSpriteCall(texture, Vector2.Zero, source, color.ToVector4(), Vector2.Zero, SpriteEffects.None));
|
graphicsDevice.DrawQueue.EnqueueSprite(new DrawSpriteCall(texture, Vector2.Zero, source, color.ToVector4(), Vector2.Zero, SpriteEffects.None, graphicsDevice.Viewport));
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Draw(Texture2D texture2D, Vector2 position, Color color)
|
internal void Draw(Texture2D texture2D, Vector2 position, Color color)
|
||||||
{
|
{
|
||||||
graphicsDevice.DrawQueue.EnqueueSprite(new DrawSpriteCall(texture2D, position, null, color.ToVector4(), Vector2.Zero, SpriteEffects.None));
|
graphicsDevice.DrawQueue.EnqueueSprite(new DrawSpriteCall(texture2D, position, null, color.ToVector4(), Vector2.Zero, SpriteEffects.None, graphicsDevice.Viewport));
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void DrawString(SpriteFont font, string value, Vector2 position, Color color)
|
internal void DrawString(SpriteFont font, string value, Vector2 position, Color color)
|
||||||
{
|
{
|
||||||
graphicsDevice.DrawQueue.EnqueueString(new DrawStringCall(font, value, position, color.ToVector4()));
|
graphicsDevice.DrawQueue.EnqueueString(new DrawStringCall(font, value, position, color.ToVector4(), graphicsDevice.Viewport));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,14 @@ namespace Microsoft.Xna.Framework.Graphics
|
|||||||
get { return unityTexture.height; }
|
get { return unityTexture.height; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Rectangle Bounds
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new Rectangle(0, 0, unityTexture.width, unityTexture.height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ SOFTWARE.
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Microsoft.Xna.Framework.Graphics
|
namespace Microsoft.Xna.Framework.Graphics
|
||||||
{
|
{
|
||||||
@ -106,8 +107,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
|||||||
int x,
|
int x,
|
||||||
int y,
|
int y,
|
||||||
int width,
|
int width,
|
||||||
int height
|
int height)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
@ -117,7 +117,14 @@ namespace Microsoft.Xna.Framework.Graphics
|
|||||||
minDepth = 0;
|
minDepth = 0;
|
||||||
maxDepth = 0;
|
maxDepth = 0;
|
||||||
titleSafeArea = new Rectangle(x, y, width, height);
|
titleSafeArea = new Rectangle(x, y, width, height);
|
||||||
}
|
|
||||||
|
/*GameObject _camGo = new GameObject("Camera");
|
||||||
|
_camGo.transform.position = new UnityEngine.Vector3((float)x, (float)y, 0.0f);
|
||||||
|
var _camera = _camGo.AddComponent<Camera>();
|
||||||
|
_camera.rect = new Rect(x, y, width, height);*/
|
||||||
|
|
||||||
|
//Camera.main.rect = new Rect(x, y, width, height);
|
||||||
|
}
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
|
|
||||||
public Vector3 Project(Vector3 source, Matrix projection, Matrix view, Matrix world)
|
public Vector3 Project(Vector3 source, Matrix projection, Matrix view, Matrix world)
|
||||||
|
@ -95,7 +95,9 @@ public class XNATest : MonoBehaviour {
|
|||||||
sourceRect.height *= -1;
|
sourceRect.height *= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI.DrawTextureWithTexCoords(new Rect(x, y, width * Mathf.Abs(sourceRect.width), height * Mathf.Abs(sourceRect.height)), call.Texture2D.UnityTexture, sourceRect);
|
var viewport = call.Viewport;
|
||||||
|
//Debug.Log("Viewport: " + viewport);
|
||||||
|
GUI.DrawTextureWithTexCoords(new Rect(x + viewport.X, y + viewport.Y, width * Mathf.Abs(sourceRect.width), height * Mathf.Abs(sourceRect.height)), call.Texture2D.UnityTexture, sourceRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw strings from SpriteBatch.DrawString()
|
// Draw strings from SpriteBatch.DrawString()
|
||||||
@ -106,9 +108,7 @@ public class XNATest : MonoBehaviour {
|
|||||||
GUI.color = new Color(call.Color.X, call.Color.Y, call.Color.Z, call.Color.W);
|
GUI.color = new Color(call.Color.X, call.Color.Y, call.Color.Z, call.Color.W);
|
||||||
|
|
||||||
Vector2 size = GUI.skin.label.CalcSize(new GUIContent(call.Value));
|
Vector2 size = GUI.skin.label.CalcSize(new GUIContent(call.Value));
|
||||||
string[] x = call.Font.PathTo.Split('/');
|
Font myFont = (Font)UnityEngine.Resources.Load($"Content/{call.Font.FontName.ToString()}", typeof(Font));
|
||||||
string path = $"{call.Font.PathTo.Remove(call.Font.PathTo.Length - 1 - x[x.Length-1].Length)}/{call.Font.FontName.ToString()}";
|
|
||||||
Font myFont = (Font)UnityEngine.Resources.Load($"{path}", typeof(Font));
|
|
||||||
//GUI.skin.font = myFont;
|
//GUI.skin.font = myFont;
|
||||||
|
|
||||||
GUIStyle myStyle = new GUIStyle();
|
GUIStyle myStyle = new GUIStyle();
|
||||||
@ -116,7 +116,8 @@ public class XNATest : MonoBehaviour {
|
|||||||
myStyle.fontSize = (int)call.Font.Size;
|
myStyle.fontSize = (int)call.Font.Size;
|
||||||
myStyle.normal.textColor = new Color(call.Color.X, call.Color.Y, call.Color.Z, call.Color.W);
|
myStyle.normal.textColor = new Color(call.Color.X, call.Color.Y, call.Color.Z, call.Color.W);
|
||||||
|
|
||||||
GUI.Label(new Rect(call.Position.X, call.Position.Y, size.x, size.y), call.Value, myStyle);
|
var viewport = call.Viewport;
|
||||||
|
GUI.Label(new Rect(call.Position.X + viewport.X, call.Position.Y + viewport.Y, size.x, size.y), call.Value, myStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
//GUIStyle style = new GUIStyle();
|
//GUIStyle style = new GUIStyle();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user