Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Drawing/Misc/ILLineProperties.cs @ 9407

Last change on this file since 9407 was 9102, checked in by gkronber, 12 years ago

#1967: ILNumerics source for experimentation

File size: 8.2 KB
Line 
1///
2///    This file is part of ILNumerics Community Edition.
3///
4///    ILNumerics Community Edition - high performance computing for applications.
5///    Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
6///
7///    ILNumerics Community Edition is free software: you can redistribute it and/or modify
8///    it under the terms of the GNU General Public License version 3 as published by
9///    the Free Software Foundation.
10///
11///    ILNumerics Community Edition is distributed in the hope that it will be useful,
12///    but WITHOUT ANY WARRANTY; without even the implied warranty of
13///    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14///    GNU General Public License for more details.
15///
16///    You should have received a copy of the GNU General Public License
17///    along with ILNumerics Community Edition. See the file License.txt in the root
18///    of your distribution package. If not, see <http://www.gnu.org/licenses/>.
19///
20///    In addition this software uses the following components and/or licenses:
21///
22///    =================================================================================
23///    The Open Toolkit Library License
24///   
25///    Copyright (c) 2006 - 2009 the Open Toolkit library.
26///   
27///    Permission is hereby granted, free of charge, to any person obtaining a copy
28///    of this software and associated documentation files (the "Software"), to deal
29///    in the Software without restriction, including without limitation the rights to
30///    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
31///    the Software, and to permit persons to whom the Software is furnished to do
32///    so, subject to the following conditions:
33///
34///    The above copyright notice and this permission notice shall be included in all
35///    copies or substantial portions of the Software.
36///
37///    =================================================================================
38///   
39
40using System;
41using System.Collections.Generic;
42using System.Text;
43using System.Drawing;
44
45namespace ILNumerics.Drawing {
46    /// <summary>
47    /// properties for line graphs
48    /// </summary>
49    public class ILLineProperties {
50
51        #region event handling
52        /// <summary>
53        /// fires if the properties were changed
54        /// </summary>
55        public event EventHandler Changed;
56        protected void OnChanged() {
57            if (Changed != null) {
58                Changed(this,new EventArgs());
59            }
60        }
61        #endregion
62
63        #region attributes
64        private int m_lineWidth;
65        private LineStyle m_lineStyle;
66        private short m_linePattern;
67        private float m_linePatternScale;
68        private Color m_foreColor;
69        private bool m_visible;
70        private bool m_setAntialiasing = false;
71        private bool m_antialiasing;
72        #endregion
73
74        #region Properties
75        /// <summary>
76        /// line width (default: 1)
77        /// </summary>
78        /// <remarks>if antialiasing is active, it will be disabled
79        /// as long as the width is less than 2 and automatically
80        /// reenabled if the width gets larger than 1 again.</remarks>
81        public int Width {
82            get {
83                return m_lineWidth;
84            }
85            set {
86                // for width = 1, antialiasing will not work and
87                // must get disabled temporarily here
88                if (value <= 1) {
89                    if (m_antialiasing) {
90                        m_antialiasing = false;
91                        m_setAntialiasing = true;
92                    }
93                } else {
94                    if (m_setAntialiasing) {
95                        m_setAntialiasing = false;
96                        m_antialiasing = true;
97                    }
98                }
99                m_lineWidth = value;
100                OnChanged();
101            }
102        }
103        /// <summary>
104        /// line style (default: solid)
105        /// </summary>
106        public LineStyle Style {
107            get {
108                return m_lineStyle;
109            }
110            set {
111                m_lineStyle = value;
112                OnChanged();
113            }
114        }
115        /// <summary>
116        /// user defined line stipple pattern for line style 'UserPattern'
117        /// </summary>
118        /// <remarks>the pattern is defined by corresponding bits
119        /// set in the short value. It may be stretched via the
120        /// LinePatternScale parameter. Default: 15</remarks>
121        public short Pattern {
122            get {
123                return m_linePattern;
124            }
125            set {
126                m_linePattern = value;
127                m_lineStyle = LineStyle.UserPattern;
128                OnChanged();
129            }
130        }
131        /// <summary>
132        /// scaling for line stipple patterns (default: 2.0f)
133        /// </summary>
134        public float PatternScale {
135            get {
136                return m_linePatternScale;
137            }
138            set {
139                m_linePatternScale = value;
140                OnChanged();
141            }
142        }
143        /// <summary>
144        /// Line color (default: DarkOliveGreen)
145        /// </summary>
146        public Color Color {
147            get {
148                return m_foreColor;
149            }
150            set {
151                m_foreColor = value;
152                OnChanged();
153            }
154        }
155        /// <summary>
156        /// get / set if lines are visible (default: true)
157        /// </summary>
158        public bool Visible {
159            get {
160                return m_visible;
161            }
162            set {
163                m_visible = value;
164                OnChanged();
165            }
166        }
167        /// <summary>
168        /// draw lines with smooth antialiasing (if possible and supported)
169        /// </summary>
170        /// <remarks>If the object supports antialiased lines, edges will be drawn
171        /// smoothly. This sometimes comes with the drawback of the lines beeing
172        /// more thick. Not all objects support antialiasing. Default value is 'false'.</remarks>
173        public bool Antialiasing {
174            get {
175                return m_antialiasing;
176            }
177            set {
178                if (m_setAntialiasing && !value) {
179                    m_setAntialiasing = false;
180                }
181                m_antialiasing = value;
182                OnChanged();
183            }
184        }
185        #endregion
186
187        #region public properties
188        public ILLineProperties Clone() {
189            return (ILLineProperties) this.MemberwiseClone();
190        }
191        public void CopyFrom(ILLineProperties props) {
192            if (props != null) {
193                this.Antialiasing = props.Antialiasing;
194                this.Color = props.Color;
195                this.Pattern = props.Pattern;
196                this.PatternScale = props.PatternScale;
197                this.Style = props.Style;
198                this.Visible = props.Visible;
199                this.Width = props.Width;
200            }
201        }
202        #endregion
203
204        #region constructors
205        /// <summary>
206        /// create default properties for graphs
207        /// </summary>
208        public ILLineProperties() {
209            m_lineStyle = LineStyle.Solid;
210            m_foreColor = Color.AntiqueWhite;
211            m_lineWidth = 1;
212            m_linePattern = 15;
213            m_linePatternScale = 2.0f;
214            m_visible = true;
215            m_antialiasing = false;
216        }
217        /// <summary>
218        /// create a new instance of this class based on another instance
219        /// </summary>
220        /// <param name="props">properties to be copied</param>
221        public ILLineProperties(ILLineProperties props) {
222            m_lineStyle = props.Style;
223            m_foreColor = props.Color;
224            m_lineWidth = props.Width;
225            m_linePattern = props.Pattern;
226            m_linePatternScale = props.PatternScale;
227            m_visible = true;
228            m_antialiasing = props.m_antialiasing;
229        }
230        #endregion
231    }
232}
Note: See TracBrowser for help on using the repository browser.