Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stroke Questions

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

    Stroke Questions

    Theses questions are for creating a Drawing Tool using Stroke.

    Question 1
    How can I retrieve the Color of a Stroke when defined by:
    PHP Code:
    State.Defaults
    MyStroke = new Stroke(Brushes.Blue);
    
    Properties
    {Display(ResourceType  = typeof(Custom.Resource), Name =  "NinjaSCriptDrawingToolTextOutLineStroke", GroupName =  "NinjaScriptGeneral", Order = 6)]
    Stroke MyStroke {get; set;} 
    
    Something like Brush myBrush = MyStroke.Brush; This returns "#FF0000FF". I am looking for "Brushes.Blue"

    EDIT:
    Or convert the Hex to RGB so that I can define a Brush using
    PHP Code:
    Brush myBrush = new Brush(Color.FromRgb(number, number, number));
    myBrush.Freeze(); 
    
    Edit 2:
    I found "A" solution. But I have no idea if I am flirting with disaster.
    PHP Code:
    In OnRender
    
    fillBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(myStroke.Brush.ToString()));
    fillBrush.Opacity = fillOpacity / 100d;
    fillBrush,Freeze();
    fillBrushDevice.Brush = null;
    fillBrushDevice.Brush = fillBrush;
    
    RenderTarget.FillRectangle(rect, fillBrushDevice.BrushDX); 
    
    Basically I am taking a Rectangle OutLine Stoke, getting the color of the stroke, then creating a brush to fill the Rectangle. I am using a Rectangle to learn the code instead of confusing the issue with complex Volume Profile calculations and polygons at this point. Is there a better way to get the Stroke Color and then create a Brush.?


    Question 2
    When drawing a NT standard Rectangle, in the Editing Window is it possible to change the display "OutLine" to something else like "My Super Secret Outline"? If so, how? Any sample code, snippet, or other drawing tools that do that?

    Thanks.
    Last edited by TAJTrades; 07-25-2017, 07:03 AM.

    #2
    Hello TAJTrades,

    Thanks for opening the thread.

    Are you using the Stroke for any other reason than to create a Brush to call FillRectangle()?

    If not, I may suggest to create a parameter for the brush that you wish to use rather than creating a parameter for a stroke. The Shapes DrawingTool source code provides an example creating an parameter for the Brush "areaBrush" as well as the sample here: http://ninjatrader.com/support/forum...ead.php?t=4977

    From Shapes DrawingTool:
    Code:
    [XmlIgnore] 
    [Display(ResourceType = typeof(Custom.Resource), Name = "NinjaScriptDrawingToolShapesAreaBrush", GroupName = "NinjaScriptGeneral", Order = 1)]
    public Brush AreaBrush
    {
    	get { return areaBrush; }
    	set
    	{
    		areaBrush = value;
    		if (areaBrush != null)
    		{
    			if (areaBrush.IsFrozen)
    				areaBrush = areaBrush.Clone();
    			areaBrush.Freeze();
    		}
    		areaBrushDevice.Brush = null;
    	}
    }
    
    [Browsable(false)]
    public string AreaBrushSerialize
    {
    	get { return Serialize.BrushToString(AreaBrush); }
    	set { AreaBrush = Serialize.StringToBrush(value); }
    }
    If you want to use the Stroke as a Brush, I may suggest to use the BrushDX property from the Stroke and avoid making the Brush. You can reference this in the Shapes DrawingTool.

    When drawing a NT standard Rectangle, in the Editing Window is it possible to change the display "OutLine" to something else like "My Super Secret Outline"? If so, how? Any sample code, snippet, or other drawing tools that do that?
    On line 94 of the Shapes DrawingTool, you can assign your own name to the property:
    Code:
    [Display(ResourceType = typeof(Custom.Resource), Name = "My Super Secret Outline", GroupName = "NinjaScriptGeneral", Order = 3)]
    Please let me know if I can be of further help.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    597 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    343 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    556 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    555 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X