Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Icon from Geometry Path

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

    Custom Icon from Geometry Path

    I am trying to figure out the way to create custom icon from Geometry Path as it is mentioned possible here: http://ninjatrader.com/support/helpG...stom_icons.htm

    Only can't figure out what object should be returned as icon object in that case.
    Do you have any sample with this case?

    #2
    Hello,

    The most efficient way that I have found to accomplish this is to use the XamlReader class to define and assign a xaml Path in your C# script, and then use that Path as the Content of your Button, like the example below:
    Code:
                        Cncl = new System.Windows.Controls.Button();
    
                        System.Windows.Shapes.Path myPath = (System.Windows.Shapes.Path)System.Windows.Markup.XamlReader.Parse(@"<Path xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Data='F1M0,0.5102L0,7.9782L8,7.9782L8,2.4232L4.797,4.5292L4.797,2.4472L1.738,4.1962L1.738,0.0212000000000002z' Fill='#FF343433' Height='7.957' Stretch='Fill' Width='50'/>");
    
                        Cncl.Content = myPath;
    There are other options laid out in the article below, as well:

    https://social.msdn.microsoft.com/forums/vstudio/en-US/7c48bb44-ff0c-4d87-a85b-8f07010fae6e/representing-xaml-paths-in-c
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Thanks Dave for your reply but my problem is not in how to generate geometry path, but how to render the path as an icon, ie:
      Code:
      [FONT=Consolas][COLOR=#0000ff]public [/COLOR][COLOR=#0000ff]override [/COLOR][COLOR=#0000ff]object [/COLOR]Icon[/FONT]
      {
      [COLOR=#0000ff] get[/COLOR]
        {   
              [FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]SharpDX.Direct2D1.[/SIZE][/FONT][/SIZE][/FONT]PathGeometry myPath = ... [COLOR=#008000]// here I define SharpDX path[/COLOR]
      [COLOR=#0000ff]       return [/COLOR]myPath;
        }
      }
      The above obviously won't work so my question is how to render SharpDX path as an object and what type of object should it be? I need it for ChartStyle so there are no buttons involved. Or should they be only System.Windows objects that can be used as an icons)?

      Comment


        #4
        I believe you would need to "apply" the path to an object which can be rendered, rather than rendering it directly. Can you share a bit more about the end goal of where and how you would like to see the path on the chart?
        Dave I.NinjaTrader Product Management

        Comment


          #5
          I believe you would need to "apply" the path to an object which can be rendered
          Yes, and that's exactly the problem I am looking for resolution - what type of object can I render SharpDX path to - I can't do RenderTarget.Draw.... I don't see Canvas or Grid in SharpDX namespace, etc. that's why I asked if you have any sample with that case.
          I have a new ChartStyle and I need an icon to be enclosed in the cs file as opposed to provide path to eg. .bmp.

          I don't need to see the path on the chart - just render the icon for the chart style (just like there are different icons for candlestick, ohlc, etc.

          Comment


            #6
            You can add a Path directly onto the Canvas that you will return in the overridden Icon property, like so:

            Code:
            using System.Windows.Shapes;
            
                    public override object Icon
                    {
                        get
                        {
                            var canvas = new Canvas();
                            System.Windows.Shapes.Path p = new System.Windows.Shapes.Path();
                            p.Fill = Brushes.Red;
                            p.Data = System.Windows.Media.Geometry.Parse("M 0 0 L 5 0 L 5 -5 L 10 -5 L 10 0 L 15 0 L 15 5 L 10 5 L 10 10 L 5 10 L 5 5 L 0 5 Z");
            
                            canvas.Children.Add(p);
                            return canvas;
                        }
                    }
            Dave I.NinjaTrader Product Management

            Comment


              #7
              Thanks Dave for coming back.
              I initially wanted to use SharpDX objects (to reuse methods already written for the rest of the ChartStyle). But it seems I should use System.Windows.Media objects instead. So thanks for providing the sample - I won't be wasting any more time on trying to square peg in the round hole!

              If I may advise, unless SharpDX rendering of the icon is still easily doable the help page should specify it is Geometry Path in System.Windows.Media and not SharpDX that should be used. Your sample (although not tested yet) would also be a nice addition there.

              Comment


                #8
                Those are both good points. I'm going to go ahead and make those changes to refine that section a bit.
                Dave I.NinjaTrader Product Management

                Comment


                  #9
                  If anyone is looking for path syntax, here are some nice references:

                  Comment


                    #10
                    Update

                    I've just noticed updated help guide with an example of geometry path:


                    Great, the example is using Grid instead of Canvas as canvas drawing would be misaligned in the icon box.

                    One suggestion though, the path in the example:
                    Code:
                    myPath.Data = System.Windows.Media.Geometry.Parse("M 0 0 L 5 0 L 5 -5 L 10 -5 L 10 0 L 15 0 L 15 5 L 10 5 L 10 10 L 5 10 L 5 5 L 0 5 Z");
                    should be changed to non-negative:
                    Code:
                    myPath.Data = System.Windows.Media.Geometry.Parse("M 0 5 L 5 5 L 5 0 L 10 0 L 10 5 L 15 5 L 15 10 L 10 10 L 10 15 L 5 15 L 5 10 L 0 10 Z");
                    Otherwise the negative parts of drawing will be cut-off from the Grid.

                    Comment


                      #11
                      Thank you, good catch. I'll fix that now, and the update should be live the next time we publish a new version of the Help Guide.
                      Dave I.NinjaTrader Product Management

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by 00nevest, Today, 02:27 PM
                      0 responses
                      0 views
                      0 likes
                      Last Post 00nevest  
                      Started by Jonafare, 12-06-2012, 03:48 PM
                      5 responses
                      3,986 views
                      0 likes
                      Last Post rene69851  
                      Started by Fitspressorest, Today, 01:38 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post Fitspressorest  
                      Started by Jonker, Today, 01:19 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post Jonker
                      by Jonker
                       
                      Started by futtrader, Today, 01:16 PM
                      0 responses
                      9 views
                      0 likes
                      Last Post futtrader  
                      Working...
                      X