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.
    https://ninjatrader.com/support/help...getchanged.htm

    Here is the documentation where I found this information:
    https://ninjatrader.com/support/help..._todxbrush.htm
    https://ninjatrader.com/support/help...th_brushes.htm
    https://ninjatrader.com/support/help...t_drawline.htm


    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 AtApi, Today, 08:17 PM
          0 responses
          2 views
          0 likes
          Last Post AtApi
          by AtApi
           
          Started by Kicks.Spin, Today, 05:16 PM
          0 responses
          7 views
          0 likes
          Last Post Kicks.Spin  
          Started by MrBrunotte, Today, 12:52 PM
          0 responses
          20 views
          0 likes
          Last Post MrBrunotte  
          Started by AndyM, Today, 12:22 PM
          0 responses
          21 views
          0 likes
          Last Post AndyM
          by AndyM
           
          Started by Carter, Today, 12:07 PM
          0 responses
          7 views
          0 likes
          Last Post Carter
          by Carter
           
          Working...
          X