public override void Render() { var transform = Matrix32.Scaling(Size); PrepareRenderState(); Shape.Draw(transform, Color); }
public void DrawCustomShape(Color4 areaColor, Color4 lineColor, Matrix32 transform) { for (int i = 0; i < cachedShapeTriangles.Count; i += 3) { Vertex[] v = new Vertex[3]; for (int j = 0; j < 3; ++j) { v[j].Color = areaColor; v[j].Pos = cachedShapePoints[cachedShapeTriangles[i + j]] * transform; } Renderer.DrawTriangleStrip(v, v.Length); } var spacing = new Vector2(3, 2); if (cachedShapePoints.Count < 3) { return; } for (int i = 0; i < cachedShapePoints.Count - 1; ++i) { Renderer.DrawDashedLine( cachedShapePoints[i] * transform, cachedShapePoints[i + 1] * transform, lineColor, spacing ); } Renderer.DrawDashedLine( cachedShapePoints.Last() * transform, cachedShapePoints.First() * transform, lineColor, spacing ); }
protected internal override Lime.RenderObject GetRenderObject() { if (Parent.AsWidget == null) { return(null); } IImageCombinerArg arg1, arg2; if (!GetArgs(out arg1, out arg2)) { return(null); } if (!arg1.GloballyVisible || !arg2.GloballyVisible) { return(null); } var texture1 = arg1.GetTexture(); var texture2 = arg2.GetTexture(); if (texture1 == null || texture2 == null) { return(null); } var ro = RenderObjectPool <RenderObject> .Acquire(); ro.Arg12CommonMaterial = CustomMaterial; ro.Arg1Material = CustomMaterial; if (ro.Arg1Material == null) { var shader = Shader == ShaderId.Inherited ? Parent.AsWidget.GlobalShader : Shader; if (arg2.Shader == ShaderId.Silhuette) { shader = ShaderId.Silhuette; } else if (arg1.Shader == ShaderId.Silhuette) { shader = ShaderId.Silhuette; Toolbox.Swap(ref arg1, ref arg2); Toolbox.Swap(ref texture1, ref texture2); } var blending = Blending == Blending.Inherited ? Parent.AsWidget.GlobalBlending : Blending; ro.Arg1Material = WidgetMaterial.GetInstance(blending, shader, WidgetMaterial.GetNumTextures(texture1, null)); ro.Arg12CommonMaterial = WidgetMaterial.GetInstance( blending, shader, WidgetMaterial.GetNumTextures(texture1, texture2), Operation == ImageCombinerOperation.Multiply ? TextureBlending.Multiply : TextureBlending.CutOut); } ro.Arg1Texture = texture1; ro.Arg2Texture = texture2; ro.Operation = Operation; ro.Arg1Transform = Matrix32.Scaling(arg1.Size) * arg1.CalcLocalToParentTransform(); ro.Arg2Transform = Matrix32.Scaling(arg2.Size) * arg2.CalcLocalToParentTransform(); ro.Arg1UVTransform = arg1.UVTransform; ro.Arg2UVTransform = arg2.UVTransform; ro.LocalToWorldTransform = Parent.AsWidget.LocalToWorldTransform; ro.Color = arg1.Color * arg2.Color * Parent.AsWidget.GlobalColor; return(ro); }
public Quadrangle Transform(Matrix32 matrix) { return(new Quadrangle { V1 = matrix.TransformVector(V1), V2 = matrix.TransformVector(V2), V3 = matrix.TransformVector(V3), V4 = matrix.TransformVector(V4) }); }
public override void Render(Node node) { var widget = node.AsWidget; widget.PrepareRendererState(); var transform = Matrix32.Scaling(widget.Size); Shape.Draw(transform, color); }
public Matrix32 CalcWeightedRelativeTransform(SkinningWeights weights) { Matrix32 skinningMatrix = new Matrix32(); skinningMatrix.T = ApplySkinningToVector(Vector2.Zero, weights); skinningMatrix.U = ApplySkinningToVector(Vector2.Right, weights) - skinningMatrix.T; skinningMatrix.V = ApplySkinningToVector(Vector2.Down, weights) - skinningMatrix.T; return(skinningMatrix); }
public override void Render() { PrepareRenderState(); Renderer.DrawVerticalGradientRect(Vector2.Zero, Size, Gradient); Renderer.DrawRectOutline(Vector2.Zero, Size, BorderColor); var transform = Matrix32.Scaling(IconWidth, Size.Y) * Matrix32.Translation(Size.X - IconWidth, 0); separator.Draw(transform); icon.Draw(transform, IconColor); }
public void Draw(Matrix32 transform, Color4 tint) { Renderer.PushState(RenderState.Transform1); Renderer.MultiplyTransform1(transform); foreach (var i in this) { i.Draw(tint); } Renderer.PopState(); }
public void Draw(Matrix32 transform, Color4 tint) { var t = Renderer.Transform1; Renderer.Transform1 = transform * t; foreach (var i in this) { i.Draw(tint); } Renderer.Transform1 = t; }
public override void Render(Node node) { var widget = node.AsWidget; widget.PrepareRendererState(); Renderer.DrawVerticalGradientRect(Vector2.Zero, widget.Size, Theme.Colors.ButtonDefault); Renderer.DrawRectOutline(Vector2.Zero, widget.Size, Theme.Colors.ControlBorder); var transform = Matrix32.Scaling(IconWidth, widget.Height) * Matrix32.Translation(widget.Width - IconWidth, 0); separator.Draw(transform); icon.Draw(transform, list.Items.Count > 0 ? Theme.Colors.BlackText : Theme.Colors.GrayText); }
public static Matrix44 MakeProjection( float width, float height, Matrix32 transform, Matrix44 cameraProjection, Matrix44 orthoProjection) { orthoProjection.M33 = 1; // Discard Z normalization, since it comes from the camera projection matrix orthoProjection.M43 = 0; return(cameraProjection * // Transform from <-1, 1> normalized coordinates to the widget space Matrix44.CreateScale(width / 2, -height / 2, 1) * Matrix44.CreateTranslation(width / 2, height / 2, 0) * (Matrix44)transform * orthoProjection); }
public bool HitTest(Matrix32 worldTransform, Vector2 point, out int tag) { point = worldTransform.CalcInversed().TransformVector(point); foreach (var s in items) { if (s.HitTest(point, out tag)) { return(true); } } tag = -1; return(false); }
public override void Render(Node node) { var widget = node.AsWidget; widget.PrepareRendererState(); Renderer.DrawRect(Vector2.Zero, widget.Size, Theme.Colors.WhiteBackground); Renderer.DrawRectOutline(Vector2.Zero, widget.Size, Theme.Colors.ControlBorder); if (checkBox.Checked) { var transform = Matrix32.Scaling(Theme.Metrics.CheckBoxSize); icon.Draw(transform); } }
private void SetValueFromCurrentMousePosition(bool draggingJustBegun) { if (Rail == null) { return; } float railLength = Rail.CalcPolylineLength(); if (railLength <= 0) { return; } Matrix32 transform = Rail.LocalToWorldTransform.CalcInversed(); Vector2 p = transform.TransformVector(Input.MousePosition); float offset = Rail.CalcSplineLengthToNearestPoint(p) / railLength; if (RangeMax <= RangeMin) { return; } float v = offset * (RangeMax - RangeMin) + RangeMin; if (draggingJustBegun) { dragInitialDelta = Value - v; dragInitialOffset = offset; return; } float prevValue = Value; if (offset > dragInitialOffset && dragInitialOffset < 1) { Value = v + dragInitialDelta * (1 - (offset - dragInitialOffset) / (1 - dragInitialOffset)); } else if (offset < dragInitialOffset && dragInitialOffset > 0) { Value = v + dragInitialDelta * (1 - (dragInitialOffset - offset) / dragInitialOffset); } else { Value = v + dragInitialDelta; } if (Step > 0) { Value = (float)Math.Round(Value / Step) * Step; } if (Value != prevValue) { RaiseChanged(); } }
public static void BeginFrame() { PlatformRenderer.BeginFrame(); DrawCalls = 0; PolyCount3d = 0; Blending = Blending.None; Shader = ShaderId.None; CullMode = CullMode.None; Transform1 = Matrix32.Identity; Transform2 = Matrix32.Identity; World = Matrix44.Identity; View = Matrix44.Identity; CurrentRenderList = MainRenderList; RenderCycle++; }
public override void Render() { PrepareRenderState(); Renderer.DrawRect(Vector2.Zero, Size, BackgroundColor); Renderer.DrawRectOutline(Vector2.Zero, Size, BorderColor); if (State == CheckBoxState.Checked) { var transform = Matrix32.Scaling(Theme.Metrics.CheckBoxSize); checkedIcon.Draw(transform); } else if (State == CheckBoxState.Indeterminate) { var transform = Matrix32.Scaling(Theme.Metrics.CheckBoxSize); indeterminateIcon.Draw(transform); } }
private void RenderHelper(IImageCombinerArg arg1, IImageCombinerArg arg2, IMaterial material, ITexture texture1, ITexture texture2) { Matrix32 transform1 = Matrix32.Scaling(arg1.Size) * arg1.CalcLocalToParentTransform(); Matrix32 transform2 = Matrix32.Scaling(arg2.Size) * arg2.CalcLocalToParentTransform(); // source rectangle int numCoords = 4; for (int i = 0; i < 4; i++) { coords[i] = rect[i] * transform1; } for (int i = 0; i < 4; i++) { stencil[i] = rect[i] * transform2; } bool clockwiseOrder = AreVectorsClockwiseOrdered(stencil[0], stencil[1], stencil[2]); // clip invisible parts for (int i = 0; i < 4; i++) { int j = (i < 3) ? i + 1 : 0; Vector2 v1 = clockwiseOrder ? stencil[j] : stencil[i]; Vector2 v2 = clockwiseOrder ? stencil[i] : stencil[j]; ClipPolygonByLine(coords, ref numCoords, v1, v2); } if (numCoords < 3) { return; } // Эти матрицы переводят координаты вершин изображения в текстурные координаты. Matrix32 uvTransform1 = transform1.CalcInversed(); Matrix32 uvTransform2 = transform2.CalcInversed(); Color4 color = arg1.Color * arg2.Color * Parent.AsWidget.GlobalColor; for (int i = 0; i < numCoords; i++) { vertices[i].Pos = coords[i]; vertices[i].Color = color; var uv1 = coords[i] * uvTransform1 * arg1.UVTransform; var uv2 = coords[i] * uvTransform2 * arg2.UVTransform; texture1?.TransformUVCoordinatesToAtlasSpace(ref uv1); texture2?.TransformUVCoordinatesToAtlasSpace(ref uv2); vertices[i].UV1 = uv1; vertices[i].UV2 = uv2; } Renderer.DrawTriangleFan(material, vertices, numCoords); }
public override void Render(Node node) { var widget = node.AsWidget; widget.PrepareRendererState(); Matrix32 transform; if (type == SpinButtonType.Additive) { transform = Matrix32.Scaling(ButtonWidth, widget.Height - 2) * Matrix32.Translation(1, 1); } else { transform = Matrix32.Scaling(-ButtonWidth, widget.Height - 2) * Matrix32.Translation(ButtonWidth + 1, 1); } buttonShape.Draw(transform); }
private void RenderParticle(Particle p, Matrix32 matrix, Color4 color) { if (p.ColorCurrent.A <= 0) { return; } float angle = p.Angle; if (AlongPathOrientation) { angle += p.FullDirection; } ITexture texture = p.Modifier.GetTexture((int)p.TextureIndex - 1); Renderer.Transform1 = p.Transform * matrix; Renderer.DrawSprite(texture, p.ColorCurrent * color, -Vector2.Half, Vector2.One, Vector2.Zero, Vector2.One); }
private void CalcInitialColorAndTransform(out Color4 color, out Matrix32 transform) { color = Color; transform = CalcLocalToParentTransform(); Widget basicWidget = GetBasicWidget(); if (basicWidget != null) { for (Node node = Parent; node != null && node != basicWidget; node = node.Parent) { if (node.AsWidget != null) { transform *= node.AsWidget.CalcLocalToParentTransform(); color *= node.AsWidget.Color; } } } }
public override void Render() { Matrix32 matrix = Matrix32.Identity; Color4 color = Color4.White; Widget basicWidget = GetBasicWidget(); if (basicWidget != null) { matrix = basicWidget.LocalToWorldTransform; color = basicWidget.GlobalColor; } Renderer.Blending = GlobalBlending; Renderer.Shader = GlobalShader; foreach (var particle in particles) { RenderParticle(particle, matrix, color); } Renderer.Transform1 = basicWidget.LocalToWorldTransform; }
public override void Update(float delta) { base.Update(delta); if (Index > 0 && Parent != null) { BoneArray.Entry e; e.Joint = Position; e.Rotation = Rotation; e.Length = Length; if (BaseIndex > 0) { // Tie the bone to the parent bone. BoneArray.Entry b = Parent.AsWidget.BoneArray[BaseIndex]; float l = ClipAboutZero(b.Length); Vector2 u = b.Tip - b.Joint; Vector2 v = new Vector2(-u.Y / l, u.X / l); e.Joint = b.Tip + u * Position.X + v * Position.Y; e.Rotation += b.Rotation; } // Get position of bone's tip. e.Tip = Vector2.RotateDegRough(new Vector2(e.Length, 0), e.Rotation) + e.Joint; if (RefLength != 0) { float relativeScaling = Length / ClipAboutZero(RefLength); // Calculating the matrix of relative transformation. Matrix32 m1, m2; m1 = Matrix32.TransformationRough(Vector2.Zero, Vector2.One, RefRotation * Mathf.DegToRad, RefPosition); m2 = Matrix32.TransformationRough(Vector2.Zero, new Vector2(relativeScaling, 1), e.Rotation * Mathf.DegToRad, e.Joint); e.RelativeTransform = m1.CalcInversed() * m2; } else { e.RelativeTransform = Matrix32.Identity; } Parent.AsWidget.BoneArray[Index] = e; Parent.PropagateDirtyFlags(DirtyFlags.GlobalTransform); for (var child = Parent.FirstChild; child != null; child = child.NextSibling) { child.DirtyMask |= DirtyFlags.LocalTransform | DirtyFlags.ParentBoundingRect; } } }
private static Rectangle CalcLocalScissorAABB(Matrix32 transform) { // Get the scissor rectangle in 0,0 - 1,1 coordinate space var vp = new Rectangle { A = new Vector2(viewport.X, viewport.Y), B = new Vector2(viewport.X + viewport.Width, viewport.Y + viewport.Height) }; var r = (Rectangle)(IntRectangle)scissorState.Bounds; var scissorRect = new Rectangle { A = (r.A - vp.A) / vp.Size, B = (r.B - vp.A) / vp.Size }; // Transform it to the normalized OpenGL space scissorRect.A = scissorRect.A * 2 - Vector2.One; scissorRect.B = scissorRect.B * 2 - Vector2.One; // Get the unprojected coordinates var invProjection = FixupWVP(Projection).CalcInverted(); var v0 = invProjection.ProjectVector(scissorRect.A); var v1 = invProjection.ProjectVector(new Vector2(scissorRect.B.X, scissorRect.A.Y)); var v2 = invProjection.ProjectVector(scissorRect.B); var v3 = invProjection.ProjectVector(new Vector2(scissorRect.A.X, scissorRect.B.Y)); // Get coordinates in the widget space var invTransform = transform.CalcInversed(); v0 = invTransform.TransformVector(v0); v1 = invTransform.TransformVector(v1); v2 = invTransform.TransformVector(v2); v3 = invTransform.TransformVector(v3); var aabb = new Rectangle { A = v0, B = v0 }. IncludingPoint(v1). IncludingPoint(v2). IncludingPoint(v3); return(aabb); }
void EnumerateMagnets() { numMagnets = 0; if (Parent == null) { return; } foreach (Node node in Parent.Nodes) { ParticlesMagnet magnet = node as ParticlesMagnet; if (magnet != null) { if (numMagnets >= MaxMagnets) { break; } Matrix32 transform = magnet.CalcLocalToParentTransform(); Widget basicWidget = GetBasicWidget(); if (basicWidget != null) { for (Node n = Parent; n != basicWidget; n = n.Parent) { if (n.AsWidget != null) { transform *= n.AsWidget.CalcLocalToParentTransform(); } } } magnets[numMagnets++] = new MagnetData { Magnet = magnet, PrecalcTransitionMatrix = transform.CalcInversed(), PrecalcInvTransitionMatrix = transform }; } } }
/// <summary> /// Applies the transformation matrix to this <see cref="Rectangle"/>. /// </summary> public Rectangle Transform(Matrix32 value) { return(new Rectangle(A * value, B * value)); }
public static void MultiplyTransform1(Matrix32 transform) { Transform1 = transform * Transform1; }
public static void MultiplyTransform2(Matrix32 transform) { Transform2 = transform * Transform2; }
public void CaptureRenderState(Widget widget) { LocalToWorldTransform = widget.LocalToWorldTransform; Blending = widget.GlobalBlending; Shader = widget.GlobalShader; }
public void Draw(Matrix32 transform) { Draw(transform, Color4.White); }