FunctionUi

References
public abstract class FunctionUi : IStorable
Non-generic function UI.

Constructors

FunctionUi

#
protected FunctionUi(Function original, IIcon icon)
Construct the base function.
original (Function)Initial function.
icon (IIcon)Function icon.

FunctionUi

#
protected FunctionUi(IReader reader)
reader (IReader)

Fields

_inner

#
protected Color _inner
Actual state of the inner colour as determined by the SetupDrawing method.

_outer

#
protected Color _outer
Actual state of the outer colour as determined by the SetupDrawing method.

Properties

Arguments

#
public FunctionArguments Arguments { get; }
Gets all the arguments associated with this function. Arguments can be either of type Vector (i.e. 2D grips) or Scalar (i.e. 1D sliders) or referents (i.e. 1D functions).

AssumeContinuous

#
protected virtual bool AssumeContinuous { get; }
Override this property and return false if the underlying function is expected to contain discontinuities.

Function

#
public abstract Function Function { get; }
The function hosted by the UI.

GripsOn

#
public bool GripsOn { get; set; }
Gets or sets whether the grips (and scalars) of this function ought to be drawn.

Icon

#
public IIcon Icon { get; }
Gets the icon associated with this function.

Id

#
public Guid Id { get; }
Gets the identifier of this UI instance.

LatestGraphSegments

#
public IEnumerable<Point2d[]> LatestGraphSegments { get; }
The polyline segments the graph was most recently drawn with, in graph (content) coordinates. Empty when the function hasn't been drawn yet. Populated by DrawGraph(FunctionGraphics) from whatever GraphSegments(FunctionGraphics) yields, so subclasses that override GraphSegments (LinearFunction, ThresholdFunction, etc.) contribute here too. Hit-testing uses these so the click tolerance matches the rendered pixels exactly.

Nomen

#
public Nomen Nomen { get; }
Gets the description of this function.

Rank

#
public Rank Rank { get; set; }
Gets or sets the stature of this function. The stature controls the visual style of the function, as well as its inclusion in any outputted collection.

Selected

#
public bool Selected { get; set; }
Gets or sets the selected state.

Tint

#
public OpenColor.Family Tint { get; set; }
Gets or sets the Open-Color family used to tint this function. A concrete shade is resolved at draw time based on the current background so the function stays legible under any theme. Use TintFor(Color) when a concrete Color is needed.

UserName

#
public string UserName { get; set; }
Gets or sets the user name assigned to this function.

VariableArguments

#
protected virtual bool VariableArguments { get; }
Override this property if your function has a variable number of vector arguments.

Methods

AfterDrawGraphSegments

#
protected virtual void AfterDrawGraphSegments(FunctionGraphics graphics)
Draw any decoration that should appear on top of the graph polyline. Called from DrawGraph(FunctionGraphics) after the polyline has been rendered.
graphics (FunctionGraphics)Graphics object to draw with.

BeforeDrawGraphSegments

#
protected virtual void BeforeDrawGraphSegments(FunctionGraphics graphics)
Draw any decoration that should appear behind the graph polyline. Called from DrawGraph(FunctionGraphics) after GraphSegments(FunctionGraphics) has run, so LatestGraphSegments is populated and available.
graphics (FunctionGraphics)Graphics object to draw with.

CanInsertVector

#
public abstract bool CanInsertVector(Point2d location, out Point2d actualLocation)
Test whether a grip can be inserted at or near a coordinate.
location (Point2d)Initial grip insertion coordinate.
actualLocation (out Point2d)Modified grip insertion coordinate.
True if grip can be inserted at modifiedCoordinate.

CanRemoveVector

#
protected abstract bool CanRemoveVector(VectorArgument vector)
Override this method to specifically okay removal off a specific grip.
vector (VectorArgument)

DrawGraph

#
public void DrawGraph(FunctionGraphics graphics)
Draw this function graph into a graphics context. Non-virtual: subclasses customise the rendering via GraphSegments(FunctionGraphics) (the polyline itself) and the BeforeDrawGraphSegments(FunctionGraphics) / AfterDrawGraphSegments(FunctionGraphics) hooks (any decorations before or after the curve). This keeps pen setup, rank thickness rules, obscure dashing, and segment capture in one place.
graphics (FunctionGraphics)Graphics object to draw with.

DrawGripFlourishes

#
public virtual void DrawGripFlourishes(FunctionGraphics graphics)
Draw all grip flourishes associated with this function.
graphics (FunctionGraphics)Graphics object to draw with.

DrawGripShapes

#
public virtual void DrawGripShapes(FunctionGraphics graphics)
Draw all grips associated with this function.
graphics (FunctionGraphics)Graphics object to draw with.

DrawHints

#
public virtual void DrawHints(FunctionGraphics graphics)
Draw the visual hints such as asymptotes, limits and markers associated with this function.
graphics (FunctionGraphics)Graphics object to draw with.

DrawScalarShapes

#
public virtual void DrawScalarShapes(FunctionGraphics graphics)
Draw all scalars associated with this function.
graphics (FunctionGraphics)Graphics object to draw with.

EstimateDistance

#
public virtual double EstimateDistance(Point2d locus, double radius)
Compute an estimate of the distance from the function to the given point. This estimate is done by sampling the function at small intervals around the point. Note: implementors may choose to override this method and provide analytic distance measurements.
locus (Point2d)Point for distance estimate.
radius (double)Maximum sampling radius. Large numbers result in lots of sampling.
Smallest sampled distance or double.NaN if no sample was within radius.

EstimateProjection

#
public virtual Point2d EstimateProjection(Point2d locus, double radius)
Compute an estimate of the point on the function closest to a search point. This estimate is done by sampling the function at small intervals around the point.
locus (Point2d)Point for closest point estimate.
radius (double)Maximum sampling radius.
Closest point or Point2d.Unset if no sample was within radius.

GraphSegments

#
protected virtual IEnumerable<Point2d[]> GraphSegments(FunctionGraphics graphics)
Override this method if you think you can provide a more performant way to generate a graphics path representing the graph curve.
graphics (FunctionGraphics)Drawing properties.

OnFunctionChanged

#
public void OnFunctionChanged()
Raise the FunctionChanged event.

PopulateMenu

#
public virtual void PopulateMenu(ContextMenu menu, Point2d coordinate, Argument parameter)
Invoked when the context menu for this function is about to be shown.
menu (ContextMenu)Menu to append items to.
coordinate (Point2d)Location from whence the menu was requested.
parameter (Argument)Parameter associated with menu coordinate, if any.

SetupDrawing

#
public virtual void SetupDrawing(FunctionGraphics graphics, bool animate = true)
Must be called prior to any draw method. This will ensure the colours and layout are correct.
graphics (FunctionGraphics)
animate (bool = true)

Store

#
public virtual void Store(IWriter writer)
writer (IWriter)
Store

TintFor

#
public Color TintFor(Color background)
Resolve Tint into a concrete colour that stands out against the supplied background.
background (Color)Background the tint must contrast with.

TryInsertVector

#
public abstract bool TryInsertVector(Point2d location)
Try and insert a grip at a coordinate.
location (Point2d)Grip location.
True if grip was inserted.

TryRemoveVectors

#
public abstract bool TryRemoveVectors(VectorArgument[] vectors)
Try and remove a set of grips.
vectors (VectorArgument[])Vectors whose removal is indicated.
True if the function changed state.

Events

FunctionChanged

#
public event EventHandler FunctionChanged
Raised when the shape of the function changes due to non-grip/scalar events, for example when the function is modified via a custom menu item.