SharpDX.Direct2D1.SolidColorBrush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.DodgerBlue);
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!
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
NinjaTrader
Setting SharpDX colors from the UI
Collapse
X
-
Setting SharpDX colors from the UI
I have added the following to an OnRender() block to set a color:
Code:Tags: None
-
Hello swcooke,
Thank you for the post.
To make this into an input, you would need to replace the SharpDX.Color.DodgerBlue with a user Input so that it is variable.
For this question, I would suggest reviewing the indicator "SampleCustomRender" that comes with NinjaTrader. That indicator has a few color inputs already which you could just copy and paste into your script if needed. This also explains how to use those inputs with rendering so it would be a good sample for this concept specifically.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
-
In the Sample Custom Render the comments advise against using ToDxBrush() but the code still seems to demonstrate drawing using it. Since the comments and the doc's advise against using ToDxBrush() but the examples do, can you give me an example of replacing the SharpDX.Color.DodgerBlue with a user Input so that it is variable as you have suggested?
Comment
-
Hello swcooke,
I had only used your syntax as a description of what needs to be modified, I would suggest using the syntax the sample shows.
The helpguide just suggests against using this when it is not needed, the examples show static colors which do not change so recreating the brush over and over would not be useful there. For a variable input, you would need to create the brush so I would suggest using the same syntax as the sample shows.
You can also use the OnRenderTargetChanged override to create brushes efficiently if you have a lot that needs to be created.
Please let me know if I may be of further assistance.JesseNinjaTrader Customer Service
Comment
-
Not sure what it is you are doing but here is a snippet you can use to set up your user input brushes:
In you global variables:
Code:private Brush areaBrush; private SharpDX.Direct2D1.Brush areaBrushDx; private int areaOpacity;
Code:AreaColor = Brushes.Blue; AreaOpacity = 50;
Code:public override void OnRenderTargetChanged() { if (areaBrushDx != null) areaBrushDx.Dispose(); if (RenderTarget != null) { try { areaBrushDx = areaBrush.ToDxBrush(RenderTarget); } catch (Exception e) { } } }
Code:[XmlIgnore] [Display(Name = "NinjaScript Text Brush", GroupName = "NinjaScriptGeneral", Order = 0)] public Brush AreaColor { get { return areaBrush; } set { areaBrush = value; if (areaBrush != null) { if (areaBrush.IsFrozen) areaBrush = areaBrush.Clone(); areaBrush.Opacity = areaOpacity / 100d; areaBrush.Freeze(); } } } [Browsable(false)] public string AreaColorSerialize { get { return Serialize.BrushToString(AreaColor); } set { AreaColor = Serialize.StringToBrush(value); } } [Range(0, 100)] [Display(Name = "NinjaScriptDrawingToolAreaOpacity", GroupName = "NinjaScriptGeneral", Order = 1)] public int AreaOpacity { get { return areaOpacity; } set { areaOpacity = Math.Max(0, Math.Min(100, value)); if (areaBrush != null) { if (areaBrush.IsFrozen) areaBrush = areaBrush.Clone(); areaBrush.Opacity = areaOpacity / 100d; areaBrush.Freeze(); } } }
Comment
-
Originally posted by swcooke View PostThank you so much. That explains a lot. One follow up question, in the case of this line:
Code:[Display(Name = "CoolName", GroupName = "NinjaScriptGeneral", Order = 1)]
Code:[Display(Name = "[COLOR=Red]Cool Name[/COLOR]", GroupName = "NinjaScriptGeneral", Order = 1)]
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by kujista, Today, 05:44 AM
|
0 responses
5 views
0 likes
|
Last Post
by kujista
Today, 05:44 AM
|
||
Started by ZenCortexCLICK, Today, 04:58 AM
|
0 responses
5 views
0 likes
|
Last Post Today, 04:58 AM | ||
Started by sidlercom80, 10-28-2023, 08:49 AM
|
172 responses
2,281 views
0 likes
|
Last Post
by sidlercom80
Today, 04:40 AM
|
||
Started by Irukandji, Yesterday, 02:53 AM
|
2 responses
18 views
0 likes
|
Last Post
by Irukandji
Today, 03:55 AM
|
||
Started by adeelshahzad, Today, 03:54 AM
|
0 responses
8 views
0 likes
|
Last Post
by adeelshahzad
Today, 03:54 AM
|
Comment