///
/// This file is part of ILNumerics Community Edition.
///
/// ILNumerics Community Edition - high performance computing for applications.
/// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
///
/// ILNumerics Community Edition is free software: you can redistribute it and/or modify
/// it under the terms of the GNU General Public License version 3 as published by
/// the Free Software Foundation.
///
/// ILNumerics Community Edition is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with ILNumerics Community Edition. See the file License.txt in the root
/// of your distribution package. If not, see .
///
/// In addition this software uses the following components and/or licenses:
///
/// =================================================================================
/// The Open Toolkit Library License
///
/// Copyright (c) 2006 - 2009 the Open Toolkit library.
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights to
/// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
/// the Software, and to permit persons to whom the Software is furnished to do
/// so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all
/// copies or substantial portions of the Software.
///
/// =================================================================================
///
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace ILNumerics.Drawing {
///
/// properties for line graphs
///
public class ILLineProperties {
#region event handling
///
/// fires if the properties were changed
///
public event EventHandler Changed;
protected void OnChanged() {
if (Changed != null) {
Changed(this,new EventArgs());
}
}
#endregion
#region attributes
private int m_lineWidth;
private LineStyle m_lineStyle;
private short m_linePattern;
private float m_linePatternScale;
private Color m_foreColor;
private bool m_visible;
private bool m_setAntialiasing = false;
private bool m_antialiasing;
#endregion
#region Properties
///
/// line width (default: 1)
///
/// if antialiasing is active, it will be disabled
/// as long as the width is less than 2 and automatically
/// reenabled if the width gets larger than 1 again.
public int Width {
get {
return m_lineWidth;
}
set {
// for width = 1, antialiasing will not work and
// must get disabled temporarily here
if (value <= 1) {
if (m_antialiasing) {
m_antialiasing = false;
m_setAntialiasing = true;
}
} else {
if (m_setAntialiasing) {
m_setAntialiasing = false;
m_antialiasing = true;
}
}
m_lineWidth = value;
OnChanged();
}
}
///
/// line style (default: solid)
///
public LineStyle Style {
get {
return m_lineStyle;
}
set {
m_lineStyle = value;
OnChanged();
}
}
///
/// user defined line stipple pattern for line style 'UserPattern'
///
/// the pattern is defined by corresponding bits
/// set in the short value. It may be stretched via the
/// LinePatternScale parameter. Default: 15
public short Pattern {
get {
return m_linePattern;
}
set {
m_linePattern = value;
m_lineStyle = LineStyle.UserPattern;
OnChanged();
}
}
///
/// scaling for line stipple patterns (default: 2.0f)
///
public float PatternScale {
get {
return m_linePatternScale;
}
set {
m_linePatternScale = value;
OnChanged();
}
}
///
/// Line color (default: DarkOliveGreen)
///
public Color Color {
get {
return m_foreColor;
}
set {
m_foreColor = value;
OnChanged();
}
}
///
/// get / set if lines are visible (default: true)
///
public bool Visible {
get {
return m_visible;
}
set {
m_visible = value;
OnChanged();
}
}
///
/// draw lines with smooth antialiasing (if possible and supported)
///
/// If the object supports antialiased lines, edges will be drawn
/// smoothly. This sometimes comes with the drawback of the lines beeing
/// more thick. Not all objects support antialiasing. Default value is 'false'.
public bool Antialiasing {
get {
return m_antialiasing;
}
set {
if (m_setAntialiasing && !value) {
m_setAntialiasing = false;
}
m_antialiasing = value;
OnChanged();
}
}
#endregion
#region public properties
public ILLineProperties Clone() {
return (ILLineProperties) this.MemberwiseClone();
}
public void CopyFrom(ILLineProperties props) {
if (props != null) {
this.Antialiasing = props.Antialiasing;
this.Color = props.Color;
this.Pattern = props.Pattern;
this.PatternScale = props.PatternScale;
this.Style = props.Style;
this.Visible = props.Visible;
this.Width = props.Width;
}
}
#endregion
#region constructors
///
/// create default properties for graphs
///
public ILLineProperties() {
m_lineStyle = LineStyle.Solid;
m_foreColor = Color.AntiqueWhite;
m_lineWidth = 1;
m_linePattern = 15;
m_linePatternScale = 2.0f;
m_visible = true;
m_antialiasing = false;
}
///
/// create a new instance of this class based on another instance
///
/// properties to be copied
public ILLineProperties(ILLineProperties props) {
m_lineStyle = props.Style;
m_foreColor = props.Color;
m_lineWidth = props.Width;
m_linePattern = props.Pattern;
m_linePatternScale = props.PatternScale;
m_visible = true;
m_antialiasing = props.m_antialiasing;
}
#endregion
}
}