00001 namespace Grendel.Example {
00002 using System;
00003 using Grendel.Base;
00004 using Grendel.Extra;
00005
00009 public class InteractiveGreekCross : GreekCross, IInteractiveShape {
00010 public InteractiveGreekCross(Canvas canvas, double size) :base(canvas, size){}
00011
00012 private bool active = true;
00013
00014 public Position LeftTopCorner {
00015 get { return new Position(-Size/2, - Size/2); }
00016 }
00017
00018 public Position RightBottomCorner {
00019 get { return new Position(Size/2, Size/2); }
00020 }
00021
00022 public void Interaction (MouseButtons button, Position location) {
00023 new TemporaryMarker(Canvas, this, 3);
00024 if(button.IsPressedLeft)
00025 new Inspector(Canvas, this).PropertyDialog();
00026 if(button.IsPressedRight)
00027 new Inspector(Canvas, this).MethodLauncher();
00028 }
00029
00030 public bool IsActive {
00031 get {return active;}
00032 set {active = value;}
00033 }
00034
00035 }
00036
00041 public class Star : BaseInteractiveShape, ICanvasCloneable {
00042 int n;
00043 private double ip;
00044 private double p;
00045 private bool maltesianEfect;
00046 private Color outlineColor;
00047
00048 public Star(Canvas canvas, int corners, double radius,
00049 double internalRadius, Color outlineColor) : base(canvas){
00050 this.n = corners;
00051 this.p = radius;
00052 this.ip = internalRadius;
00053 this.outlineColor = outlineColor;
00054 }
00055
00056 public Star(Canvas canvas)
00057 : this(canvas, 8, 80.0, 50.0, Color.Black){}
00058
00059 public ICanvasObject Clone () {
00060 Star clone = new Star(Canvas, Corners, Radius, InternalRadius, OutlineColor);
00061 clone.InheritGroupsFrom(this);
00062 clone.Location = Location;
00063 clone.LocalTransformation = LocalTransformation;
00064
00065 clone.Layer = Layer;
00066 clone.BaseColor = BaseColor;
00067 clone.MaltesianEfect = MaltesianEfect;
00068 return clone;
00069 }
00070
00071 public void CloneLeft() {
00072 Clone();
00073 MoveLeft();
00074 }
00075
00076 public void MoveLeft() {
00077 Position newPos = Location + new Vector(2*p, 0);
00078 new Shifter(Canvas, this, newPos, 33.0);
00079 }
00080
00081
00085 public double Radius {
00086 get {
00087 return p;
00088 }
00089 set {
00090 p = value;
00091 }
00092 }
00093
00097 public int Corners {
00098 get {
00099 return n;
00100 }
00101 set {
00102 n = value;
00103 }
00104 }
00105
00109 public double InternalRadius {
00110 get {
00111 return ip;
00112 }
00113 set {
00114 ip = value;
00115 }
00116 }
00117
00122 public bool MaltesianEfect {
00123 get {
00124 return maltesianEfect;
00125 }
00126 set {
00127 maltesianEfect = value;
00128 }
00129 }
00130
00131 public override Position LeftTopCorner {
00132 get { return new Position(-p, -p); }
00133 }
00134
00135 public override Position RightBottomCorner {
00136 get { return new Position(p, p); }
00137 }
00138
00142 public Color OutlineColor {
00143 get {
00144 return outlineColor;
00145 }
00146 set {
00147 outlineColor = value;
00148 }
00149 }
00150
00151 public override void Painting () {
00152 double krok = 2*Math.PI / n;
00153 for(int i=0; i<n; i++) {
00154 double puhel = krok * i;
00155 double iuhel = puhel + krok/2;
00156 double kuhel = puhel + krok;
00157 Position b1 = new Position(p*Math.Cos(puhel), p*Math.Sin(puhel));
00158 Position b2 = new Position(ip*Math.Cos(iuhel), ip*Math.Sin(iuhel));
00159 Position b3 = new Position(p*Math.Cos(kuhel), p*Math.Sin(kuhel));
00160 Canvas.DrawFilledTriangle(this, b1, Position.Origin, b2, BaseColor);
00161 if (!maltesianEfect)
00162 Canvas.DrawFilledTriangle(this, b2, Position.Origin, b3, BaseColor);
00163 Canvas.DrawLine(this, b1, b2, 1, OutlineColor);
00164 Canvas.DrawLine(this, b2, b3 , 1, OutlineColor);
00165 }
00166 }
00167
00168 public override void Interaction (MouseButtons button, Position location) {
00169 new TemporaryMarker(Canvas, this, 3.0);
00170 if(button.IsPressedLeft)
00171 new Inspector(Canvas, this).PropertyDialog();
00172 if(button.IsPressedRight)
00173 new Inspector(Canvas, this).MethodLauncher();
00174 }
00175
00176 }
00177
00182 public class FrameCounter : Text, IDynamicObject {
00183 public FrameCounter(Canvas canvas) : base(canvas, "") {
00184 CurrentText = Canvas.Frame.ToString();
00185 }
00186
00187 public bool IsActive {
00188 get { return true; }
00189 set { }
00190 }
00191
00192 public bool AnimationStep (int frame) {
00193 CurrentText = frame.ToString();
00194 return true;
00195 }
00196
00197 }
00198 }