Announcement

Collapse
No announcement yet.

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:





    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

        Comment


          #5
          Ok, thanks, interesting to learn more!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          563 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          329 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          547 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          548 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X