algorithmic modeling for Rhino
Using the TextRender method, interestingly enough, I ran into a "feature" that renders text onto the actual canvas of Grasshopper! In a way I'm just going to call this a feature because one could get real creative with the use of this (instruction text, error messages, etc etc).
The code snippet to do that:
TextRenderer.DrawText(graphics, "Beware: Monsters out!", SystemFonts.DefaultFont, new Point(10, 10), SystemColors.ControlText);
I am interested in, however, having that text in the relative position of my bitmap render. This is what my component looks like:
Is there a method that determines the relative position of points with-in this image displayed?
Thank you.
Tags:
The Canvas is a typical winforms control which is drawn using a System.Drawing.Graphics object, so you can draw whatever you want wherever you want. (Though not whenever you want, you're only allowed to use the Graphics object during paint events.)
The drawing logic of the Canvas is pretty complicated as there are a lot of layers/channels in which different things are drawn, and Grasshopper itself draws stuff in between channels as well. The (somewhat simplified) logic is thus:
Things like Window-Select rectangles, the Radial menu, the Moses tool etc. are called Interactions and they use the events to draw things as well, but they are not part of the intrinsic painting pipeline.
--
David Rutten
david@mcneel.com
During most of the painting process, the Graphics object which belongs to the Canvas has the zoom+pan transformation applied to it. So if you draw things in regular component coordinates they should appear in the right place.
I do not know if TextRenderer.DrawText ignores the display transform, it would be surprising if it did. When exactly are you calling that method?
--
David Rutten
david@mcneel.com
If you want to draw text to the canvas, I recommend using Graphics.DrawString with the Graphics object that you are given inside the Attribute Render method. DrawString has a fair number of overloads and you can specify wrapping, clipping, trimming and alignment options as well as font and fill properties.
You can use the GH_FontServer class to get access to standard fonts used in Grasshopper. DO NOT DISPOSE these fonts as they are used over and over again by different components.
--
David Rutten
david@mcneel.com
If the text doesn't fit in the rectangle, it may not be drawn at all. 10x10 pixels is pretty small. Also a rectangle starting at 10,10 means the text will be drawn close to the canvas 'page' corner, wherever that is. If your component is not visible when the page corner is, the Render method won't even be called.
--
David Rutten
david@mcneel.com
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by