示例#1
0
		public Sprite (Stream stream, TextureSettings settings, Vector4 rect, bool relativeRect, Vector4 color, bool flipV = true) {
			var tex = new Texture(stream, settings);
			_material = new SpriteMaterial(new SpriteShader(), tex);
			
			if (rect == Vector4.Zero)
				rect = new Vector4(0, 0, tex.Size.Width, tex.Size.Height);
			else if (relativeRect) {
				rect.X *= tex.Size.Width;
				rect.Y *= tex.Size.Height;
				rect.Z *= tex.Size.Width;
				rect.W *= tex.Size.Height;
			}
			
			_size = new Vector2(rect.Z - rect.X, rect.W - rect.Y);

			_vbuffer = new VertexBuffer(VertexFormat.PositionColorUV);
			_vbuffer.Data = new [] {
				rect.X, rect.Y, 0f, color.X, color.Y, color.Z, color.W, 0f, flipV ? 1f : 0f,
				rect.Z, rect.Y, 0f, color.X, color.Y, color.Z, color.W, 1f, flipV ? 1f : 0f,
				rect.Z, rect.W, 0f, color.X, color.Y, color.Z, color.W, 1f, flipV ? 0f : 1f,
				rect.X, rect.W, 0f, color.X, color.Y, color.Z, color.W, 0f, flipV ? 0f : 1f
			};
			_vbuffer.Commit ();
			
			_ibuffer = new IndexBuffer();
			_ibuffer.Data = new [] { 0, 1, 2, 2, 3, 0 };
			_ibuffer.Commit ();
			
			_ioffset = 0;
			_icount = 6;
			
			_ownResources = true;
		}
示例#2
0
文件: Mesh.cs 项目: jpernst/GameStack
		public Mesh (string name, Material mat, VertexFormat format, float[] vertices, int[] indices, Bone[] bones) {
			_name = name;
			_material = mat;
			_vbuffer = new VertexBuffer(format, vertices);
			_ibuffer = new IndexBuffer(indices, BeginMode.Triangles);
			_bones = bones;
			if(_bones != null)
				_boneTransforms = new Matrix4[_bones.Length];
		}
示例#3
0
		public Sprite (Material material, Vector2 size, VertexBuffer vbuffer = null, IndexBuffer ibuffer = null, int ioffset = 0, int icount = 0, bool ownMaterial = false) {
			_material = material;
			_size = size;
			_vbuffer = vbuffer;
			_ibuffer = ibuffer;
			_ioffset = ioffset;
			_icount = icount;
			_ownResources = ownMaterial;
		}
示例#4
0
文件: Quad.cs 项目: jpernst/GameStack
		public Quad (Material material, Vector4 rect, Vector4 color, bool flipV = false) {
			_material = material;
			_color = color;
			_vbuffer = new VertexBuffer (VertexFormat.PositionColorUV);
			_ibuffer = new IndexBuffer ();

			if (rect == Vector4.Zero)
				rect = new Vector4(-0.5f, -0.5f, 0.5f, 0.5f);

			_vbuffer.Data = new [] {
				rect.X, rect.Y, 0f, _color.X, _color.Y, _color.Z, _color.W, 0f, flipV ? 1f : 0f,
				rect.Z, rect.Y, 0f, _color.X, _color.Y, _color.Z, _color.W, 1f, flipV ? 1f : 0f,
				rect.Z, rect.W, 0f, _color.X, _color.Y, _color.Z, _color.W, 1f, flipV ? 0f : 1f,
				rect.X, rect.W, 0f, _color.X, _color.Y, _color.Z, _color.W, 0f, flipV ? 0f : 1f
			};
			_vbuffer.Commit ();
			_ibuffer.Data = new [] { 0, 1, 2, 2, 3, 0 };
			_ibuffer.Commit ();
		}
示例#5
0
		public void Build () {
			if (!_isDirty || _text == null || _font == null)
				return;

			if (_vbuffer == null)
				_vbuffer = new VertexBuffer(VertexFormat.PositionColorUV);
			if (_ibuffer == null)
				_ibuffer = new IndexBuffer();

			var i = 0;
			TextRun run = null;
			var lines = new List<List<TextRun>>();
			var line = new List<TextRun>();
			//var nestedRuns = new Stack<TextRun>();
			//var nestedTags = new Stack<string>();
			lines.Add(line);
			run = new TextRun(_font, i, _kerning, _color);
			line.Add(run);

			var trim = false;

			while (i < _text.Length) {
				if (char.IsLowSurrogate(_text, i)) {
					i++;
					continue;
				}

				if (trim) {
					if (char.IsWhiteSpace(_text, i)) {
						i++;
						continue;
					} else
						trim = false;
				}

				var c = char.ConvertToUtf32(_text, i++);
				if (c == '\n') {
					run.End = i;
					line = new List<TextRun>();
					lines.Add(line);
					run = new TextRun(run, i);
					line.Add(run);
					continue;
				} else if (c < 32)
					continue;

				var ch = run.Font[c];
				if (ch == null) {
					ch = run.Font['?'];
					if (ch == null) {
						ch = run.Font[' '];
						if (ch == null)
							continue;
					}
				}

				run.Push(ch);
				if (_width > 0f && line.Sum(tr => tr.Width) > _width) {
					int count;
					var back = run.FindBreak(out count);
					if (i - back <= run.Start) {
						if (line.Count > 1) {
							line.RemoveAt(line.Count - 1);
							line = new List<TextRun>();
							lines.Add(line);
							line.Add(run);
							trim = true;
							continue;
						} else
							back = 1;
					}
					i -= back - count;
					run.Pop(back);
					line = new List<TextRun>();
					lines.Add(line);
					run = new TextRun(run, i);
					line.Add(run);
					trim = true;
				}
			}
			run.End = i;

			_actualSize.X = lines.Max(l => l.Sum(tr => tr.Width));
			_actualSize.Y = lines.Sum(l => l.Max(tr => tr.Height) + _leading);

			var vertices = new List<float>();
			var indices = new List<int>();
			var y = 0f;
			for (i = lines.Count - 1; i >= 0; --i) {
				var tl = lines[i];
				var x = 0f;
				if (_halign == HorizontalAlignment.Right)
					x = _width - tl.Sum(tr => tr.Width);
				else if (_halign == HorizontalAlignment.Center)
					x = Mathf.Floor((_width - tl.Sum(tr => tr.Width)) / 2f);

				foreach (var tr in tl) {
					tr.Build(vertices, indices, new Vector3(x, y + (tr.Font.LineHeight - tr.Font.Base), 0f));
					x += tr.Width;
				}
				y += tl.Max(tr => tr.Height) + _leading;
			}

			_vbuffer.Data = vertices.ToArray();
			_vbuffer.Commit();
			_ibuffer.Data = indices.ToArray();
			_ibuffer.Commit();

			_isDirty = false;
		}
示例#6
0
		private SlicedSprite (Material material, Vector2 size) : base(material, size) {
			_vbuffer = new VertexBuffer(VertexFormat.PositionColorUV);
			_ibuffer = new IndexBuffer();
		}