Click here to Skip to main content
15,893,588 members
Articles / Desktop Programming / WPF

Equation Calculator with Graphing

Rate me:
Please Sign up or sign in to vote.
4.92/5 (69 votes)
25 Nov 2010CPOL9 min read 133.9K   4.2K   158  
Equation Calculator with Graphing
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows;

namespace CommonUtils.GraphicalCanvas
{
	public interface ICanvasItem 
	{
		void Arrange();
	}

	public class CanvasVisualGroup : Visual, ICanvasItem
	{
		public virtual bool IsEnabled {get; set;}
		public Transform RenderTransform
		{
			get
			{
				return (Transform) base.GetValue(UIElement.RenderTransformProperty);
			}
			set
			{
				base.SetValue(UIElement.RenderTransformProperty, value);
			}
		}
		public List<ICanvasItem> Items {get; private set;}
		public CanvasVisualGroup()
		{
			Items = new List<ICanvasItem>();
			IsEnabled = true;
		}
		public void Clear()
		{
			foreach (Visual item in Items)
			{
				if (item is CanvasVisualGroup)
					((CanvasVisualGroup)item).Clear();
				RemoveVisualChild(item);
			}
		}
		protected override int VisualChildrenCount
		{
			get 
			{ 
				if (!IsEnabled)
					return 0;
				return Items.Count; 
			}
		}
		protected override Visual GetVisualChild(int index)
		{
			return Items[index] as Visual;
		}
		public void UpdateChildren()
		{
			foreach (Visual v in Items)
			{
				if (VisualTreeHelper.GetParent(v) != null)
				{
					continue;
					// skip ?
				}
				if (v is CanvasVisualGroup)
					((CanvasVisualGroup)v).UpdateChildren();
				else
					this.AddVisualChild(v);
			}
		}
		public void Arrange()
		{
			foreach (ICanvasItem v in Items)
			{
				if (v is CanvasVisualGroup)
					((CanvasVisualGroup)v).RenderTransform = RenderTransform;
				v.Arrange();
			}
		}
	}
	public class CanvasLayer : CanvasVisualGroup
	{
		public virtual void NotifyOnMouseMove(CanvasSurface surface, Point point)
		{
		}
		public virtual void OnRender(CanvasSurface surface, DrawingContext drawingContext)
		{
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions