Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

DrawLine with interactive line width

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    DrawLine with interactive line width

    Hi,

    I want to draw some lines with a DrawingTool.
    Then, selcting this line, I want to change a parameter in this line properties.
    Depending on this parameter, I would like to change the colour, width, etc

    Example:

    This is how I usually draw a line within OnRender:

    Point pto1= new Point(fx, fy);
    SharpDX.Vector2 vector1=pto1.ToVector2();
    Point pto2= new Point(fx2, fy2);
    SharpDX.Vector2 vector2=pto2.ToVector2();

    RenderTarget.DrawLine(vector1, vector2, outlineStroke.BrushDX, espesorStroke.Width, outlineStroke.StrokeStyle);

    I would like to have something like:
    RenderTarget.DrawLine(vector1, vector2, colour-variable, width-variable, outlineStroke.StrokeStyle);

    without having to define so many "strokes" as combinations I need.


    Thanks

    #2
    Hi artson, thanks for writing in.

    The overload to use will be:
    RenderTarget.DrawLine(Vector2 point0, Vector2 point1, Brush brush, float strokeWidth, StrokeStyle strokeStyle)

    The strokeWidth property can be a simple float public property:

    Code:
    [NinjaScriptProperty]
    [Range(1, float.MaxValue)]
    [Display(Name="MyFloat", Order=1, GroupName="Parameters")]
    public float MyFloat
    { get; set; }
    The Brush will need to be a C# style brush e.g.

    Code:
    [XmlIgnore]
    public Brush MyBrush { get; set; }
    
    [Browsable(false)]
    public string MyBrushSerialize
    {
      get { return Serialize.BrushToString(MyBrush); }
      set { MyBrush = Serialize.StringToBrush(value);  }
    }
    Then convert it to a SharpDX brush:

    Code:
    SharpDX.Direct2D1.Brush dxBrush = MyBrush .ToDxBrush(RenderTarget); //this can be used in RenderTarget.DrawLine
    See also OnRenderTargetChanged to make sure you dispose the brush properly.


    Here is the documentation where I found this information:





    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks!

      I'm not an esxpert here, so I have some more questions.

      How can I go from
      Code:
      [NinjaScriptProperty]
      [Range(1, float.MaxValue)]
      [Display(Name="MyFloat", Order=1, GroupName="Parameters")]
      public float [B]MyFloat[/B]
      { get; set; }

      to

      RenderTarget.DrawLine(Vector2 point0, Vector2 point1, Brush brush, float strokeWidth, StrokeStyle strokeStyle)


      If I put it:

      RenderTarget.DrawLine(Vector2 point0, Vector2 point1, Brush brush, MyFloat, StrokeStyle strokeStyle)

      I get an error:
      not possible to convert from "float" to NinjaTrader.Gui.Stroke.......

      Comment


        #4
        Hi artson, I attached an example for you to try out. Please let me know if you have questions on it.
        Attached Files
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Ok, thanks, interesting to learn more!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Barry Milan, Yesterday, 10:35 PM
          5 responses
          16 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by DanielSanMartin, Yesterday, 02:37 PM
          2 responses
          13 views
          0 likes
          Last Post DanielSanMartin  
          Started by DJ888, 04-16-2024, 06:09 PM
          4 responses
          12 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by terofs, Today, 04:18 PM
          0 responses
          11 views
          0 likes
          Last Post terofs
          by terofs
           
          Started by nandhumca, Today, 03:41 PM
          0 responses
          8 views
          0 likes
          Last Post nandhumca  
          Working...
          X