00001
00002
00003
00004
00005
00006
00007 namespace Grendel.Extra {
00008
00009 using System;
00010 using Grendel.Base;
00011 using System.IO;
00012 using System.Resources;
00013 using System.Reflection;
00014
00018 public abstract class LinearShape : BaseShape {
00019 private double lineWidth = 1.0;
00020
00021 public LinearShape(Canvas canvas) : base(canvas) {}
00022
00026 public double LineWidth {
00027 get {
00028 return lineWidth;
00029 }
00030 set {
00031 lineWidth = value;
00032 }
00033 }
00034 }
00035
00039 public class UnitCircle : LinearShape {
00040 public UnitCircle(Canvas canvas) : base(canvas) {}
00041
00042 public override void Painting () {
00043 double kappa = 0.5522847498;
00044 Canvas.DrawBezierCurve(this, new Position(-1.0, 0.0),
00045 new Position(-1.0, -kappa),
00046 new Position(-kappa, -1.0),
00047 new Position(0.0, -1.0), LineWidth, BaseColor);
00048 Canvas.DrawBezierCurve(this, new Position(0.0, -1.0),
00049 new Position(kappa, -1.0),
00050 new Position(1.0, -kappa),
00051 new Position(1.0, 0.0), LineWidth, BaseColor);
00052 Canvas.DrawBezierCurve(this, new Position(1.0, 0.0),
00053 new Position(1.0, kappa),
00054 new Position(kappa, 1.0),
00055 new Position(0.0, 1.0), LineWidth, BaseColor);
00056 Canvas.DrawBezierCurve(this, new Position(0.0, 1.0),
00057 new Position(-kappa, 1.0),
00058 new Position(-1.0, kappa),
00059 new Position(-1.0, 0.0), LineWidth, BaseColor);
00060 }
00061 }
00062
00066 public class UnitHorizontalLine : LinearShape {
00067 public UnitHorizontalLine(Canvas canvas) : base(canvas) {}
00068
00069 public override void Painting () {
00070 Canvas.DrawLine(this, Position.Origin, new Position(1.0, 0.0), LineWidth, BaseColor);
00071 }
00072 }
00073
00077 public class GreekCross : LinearShape {
00078 private double size;
00079
00080
00084 public double Size {
00085 get {
00086 return size;
00087 }
00088 set {
00089 size = value;
00090 }
00091 }
00092
00093 public GreekCross(Canvas canvas, double size) : base(canvas) {
00094 this.size = size;
00095 }
00096
00097
00098 public override void Painting () {
00099 Canvas.DrawLine(this, new Position(-size/2,0), new Position(size/2, 0), LineWidth, BaseColor);
00100 Canvas.DrawLine(this, new Position(0, -size/2), new Position(0, size/2), LineWidth, BaseColor);
00101 }
00102
00103 }
00104
00108 public class StaticBitmap : BaseShape {
00109 private string filename;
00110 private IBitmap bitmap = null;
00111
00112 public StaticBitmap(Canvas canvas, string fileName) : base(canvas) {
00113 FileName = fileName;
00114 }
00115
00120 public string FileName {
00121 get {
00122 return filename;
00123 }
00124 set {
00125 filename = value;
00126 if(bitmap != null)
00127 bitmap.Dispose();
00128 Stream s = File.OpenRead(value);
00129 bitmap = Canvas.LoadBitmap(s);
00130 }
00131 }
00132
00133 public override void Painting () {
00134 Canvas.DrawBitmap(this, Position.Origin, bitmap);
00135 }
00136 }
00137
00141 public class ResourceBitmap : BaseShape {
00142 IBitmap b = null;
00143
00144 public ResourceBitmap(Canvas canvas, string resourceID) : base(canvas) {
00145 Assembly assembly = Assembly.GetAssembly(typeof(Canvas));
00146 Stream s = assembly.GetManifestResourceStream(resourceID);
00147 b = Canvas.LoadBitmap(s);
00148 }
00149
00150 public override void Painting () {
00151 Canvas.DrawBitmap(this, Position.Origin, b);
00152 }
00153
00154 }
00155
00160 public class Text : BaseShape {
00161 private string text;
00162
00163
00167 public string CurrentText {
00168 get {
00169 return text;
00170 }
00171 set {
00172 text = value;
00173 }
00174 }
00175
00176 public Text(Canvas canvas, string text) : base(canvas){
00177 this.text = text;
00178 }
00179
00180 public override void Painting () {
00181 Canvas.DrawText(this, Position.Origin, CurrentText, Font.Monospace, BaseColor);
00182 }
00183 }
00184
00189 public class TextWithFont : Text {
00190 private Font font;
00191
00192 public TextWithFont(Canvas canvas, string text, Font font)
00193 : base(canvas, text){
00194 this.Font = font;
00195 }
00196
00200 public Font Font {
00201 get {
00202 return font;
00203 }
00204 set {
00205 font = value;
00206 }
00207 }
00208
00209 public override void Painting () {
00210 Canvas.DrawText(this, Position.Origin, CurrentText, Font, BaseColor);
00211 }
00212 }
00213
00217 public class BezierCurve : LinearShape {
00218 private Position start;
00219 private Vector startVector;
00220 private Position finish;
00221 private Vector finishVector;
00222
00238 public BezierCurve(Canvas canvas, Position startPoint, Vector startVector,
00239 Position finishPoint, Vector finishVector)
00240 : base(canvas) {
00241 this.start = startPoint;
00242 this.startVector = startVector;
00243 this.finish = finishPoint;
00244 this.finishVector = finishVector;
00245 }
00249 public BezierCurve(Canvas canvas, Position p0, Position p1, Position p2,
00250 Position p3) : base(canvas) {
00251 this.start = p0;
00252 this.startVector = p1 - p0;
00253 this.finish = p3;
00254 this.finishVector = p3 - p2;
00255 }
00256
00257 public override void Painting ()
00258 {
00259 Position p0 = start;
00260 Position p1 = start + startVector;
00261 Position p2 = finish + (-1.0 * finishVector);
00262 Position p3 = finish;
00263 Canvas.DrawBezierCurve(this, p0, p1, p2, p3, LineWidth, BaseColor);
00264 }
00265
00266 }
00267
00268 }