Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
* Model/AbstractHandle.cs: Added Inner and ElementBounds
Browse files Browse the repository at this point in the history
* Model/LineHandleGroup.cs: Cosmetic
* Model/TransformHandle.cs: Renamed some Methods
* Model/RotateHandleGroup.cs, Model/BottomRightRotateHandle.cs: Added
* Model/Draw/ShapeCreationTool.cs: Renamed some methods
* Model/RotateHandle.cs: Added GetXaml(), Update(). Improved MouseStep
* Controller/StandardSelection.cs: Added support for RotateHandleGroup

svn path=/trunk/lunareclipse/; revision=105675
  • Loading branch information
Manuel Cerón committed Jun 12, 2008
1 parent 33f33ee commit 537da89
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 12 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2008-06-12 Manuel Cerón <ceronman@unicauca.edu.co>



2008-06-08 Manuel Cerón <ceronman@unicauca.edu.co>


Expand Down
4 changes: 4 additions & 0 deletions Controller/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2008-06-12 Manuel Cerón <ceronman@unicauca.edu.co>

* StandardSelection.cs: Added support for RotateHandleGroup

2008-06-08 Manuel Cerón <ceronman@unicauca.edu.co>

* StandardSelection.cs: Addes support for PathHandleGroup in
Expand Down
2 changes: 2 additions & 0 deletions Controller/StandardSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ private IHandleGroup FindHandleGroup(UIElement element)
return new LineHandleGroup(Controller, element as Line);
if (element is Path)
return new PathHandleGroup(Controller, element as Path);
if (element is Rectangle)
return new RotateHandleGroup(Controller, element as Rectangle);
return null;
}

Expand Down
2 changes: 2 additions & 0 deletions LunarEclipse.mdp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
<File name="Model/StartPointHandle.cs" subtype="Code" buildaction="Compile" />
<File name="Model/RotateHandle.cs" subtype="Code" buildaction="Compile" />
<File name="Model/TransformHandle.cs" subtype="Code" buildaction="Compile" />
<File name="Model/BottomRightRotateHandle.cs" subtype="Code" buildaction="Compile" />
<File name="Model/RotateHandleGroup.cs" subtype="Code" buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="False" refto="atk-sharp, Version=2.8.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
Expand Down
20 changes: 18 additions & 2 deletions Model/AbstractHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,24 @@ protected Rect CalculateElementBounds()

protected virtual string GetXaml()
{
return "<Rectangle />";
return "<Rectangle Fill=\"#00FFFFFF\" Stroke=\"#FF000000\"/>";
}

protected Visual Element {
protected UIElement Element {
get { return Group.Child; }
}

protected Rect ElementBounds {
get {
double top = (double) Element.GetValue(Canvas.TopProperty);
double left = (double) Element.GetValue(Canvas.LeftProperty);
double width = (double) Element.GetValue(Canvas.WidthProperty);
double height = (double) Element.GetValue(Canvas.HeightProperty);

return new Rect(left, top, width, height);
}
}

protected Point LastClick {
get { return last_click; }
set { last_click = value; }
Expand All @@ -144,6 +155,11 @@ protected bool Dragging {
get { return dragging; }
set { dragging = value; }
}

protected FrameworkElement Inner {
get { return inner; }
set { inner = value; }
}

protected Point CalculateOffset(Point current)
{
Expand Down
50 changes: 50 additions & 0 deletions Model/BottomRightRotateHandle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// BottomRightRotateHandle.cs
//
// Author:
// Manuel Cerón <ceronman@unicauca.edu.co>
//
// Copyright (c) 2008 Manuel Cerón.
//
// 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.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//

using System.Windows;
using LunarEclipse.Controller;

namespace LunarEclipse.Model {

public class BottomRightRotateHandle: RotateHandle{

public BottomRightRotateHandle(MoonlightController controller, IHandleGroup group):
base(controller, group)
{
}

public override Point Location {
get {
Rect r = ElementBounds;
return new Point(r.X + r.Width,
r.Y + r.Height);
}
set {}
}

}
}
8 changes: 8 additions & 0 deletions Model/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2008-06-12 Manuel Cerón <ceronman@unicauca.edu.co>

* AbstractHandle.cs: Added Inner and ElementBounds
* LineHandleGroup.cs: Cosmetic
* TransformHandle.cs: Renamed some Methods
* RotateHandleGroup.cs, BottomRightRotateHandle.cs: Added
* RotateHandle.cs: Added GetXaml(), Update(). Improved MouseStep

2008-06-08 Manuel Cerón <ceronman@unicauca.edu.co>

* AbstractHandle.cs, LineHandle.cs: Update() removed
Expand Down
4 changes: 4 additions & 0 deletions Model/Draw/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2008-06-12 Manuel Cerón <ceronman@unicauca.edu.co>

* ShapeCreationTool.cs: Renamed some methods

2008-06-08 Manuel Cerón <ceronman@unicauca.edu.co>


Expand Down
1 change: 1 addition & 0 deletions Model/Draw/ShapeCreationTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ protected virtual void SetupShapeProperties()
CreatedShape.SetValue(Shape.StrokeProperty, new SolidColorBrush(Colors.Black));
CreatedShape.SetValue(Visual.NameProperty,
NameGenerator.GetName(Controller.Canvas, CreatedShape));
CreatedShape.SetValue(UIElement.RenderTransformOriginProperty, new Point(0.5, 0.5));
}

protected Shape CreatedShape {
Expand Down
3 changes: 0 additions & 3 deletions Model/LineHandleGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public class LineHandleGroup: AbstractHandleGroup {
public LineHandleGroup(MoonlightController controller, Line child):
base(controller, child)
{
if (!(child is Line)) {
throw new ArgumentException("Child must be Line");
}
AddHandle(new StartLineHandle(Controller, this));
AddHandle(new EndLineHandle(Controller, this));

Expand Down
53 changes: 50 additions & 3 deletions Model/RotateHandle.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RotateHandle.cs
//
// Author:
// Alan McGovern <alan.mcgovern@gmail.com>
// Manuel Cerón <ceronman@unicauca.edu.co>
//
// Copyright (c) 2008 Manuel Cerón.
Expand All @@ -22,10 +23,11 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//


using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Input;
using LunarEclipse.Controller;

Expand All @@ -36,6 +38,10 @@ public abstract class RotateHandle: TransformHandle {
public RotateHandle(MoonlightController controller, IHandleGroup group):
base(controller, group)
{
TransformGroup transforms = new TransformGroup();
Inner.SetValue(RenderTransformProperty, transforms);
rotation = new RotateTransform();
transforms.Children.Add(rotation);
}

public override void MouseStep (object sender, MouseEventArgs args)
Expand All @@ -45,8 +51,49 @@ public override void MouseStep (object sender, MouseEventArgs args)
if (!Dragging)
return;

Point center = TransformOrigin;
Point center = ElementTransformCenter;
Point position = args.GetPosition(null);

// TODO: Explain this.
double alpha = Math.Atan2(position.Y - center.Y, position.X - center.X);
double beta = Math.Atan2(LastClick.Y - center.Y, LastClick.X - center.X);

double difference = alpha - beta;

if (Double.IsNaN(difference)) {
difference = 0.0;
System.Console.WriteLine("IS NaN");
System.Console.WriteLine(LastClick.X - center.X);
System.Console.WriteLine(position.X - center.X);
// double supererror = 1.0 / 0.0;
}

ElementRotation.Angle += Toolbox.RadiansToDegrees(difference);
Update();

LastClick = position;
}

public override void Update ()
{
base.Update ();

Point center = ElementTransformCenter;
Rect allocation = CanvasAllocation;
rotation.CenterX = center.X - allocation.X;
rotation.CenterY = center.Y - allocation.Y;

rotation.Angle = ElementRotation.Angle;

System.Console.WriteLine("----- {2}, {0}, {1}", rotation.CenterX, rotation.CenterY, rotation.Angle);
}


protected override string GetXaml ()
{
return "<Rectangle Fill=\"#99FFFF00\" Stroke=\"#FF000000\"/>";
}

private RotateTransform rotation;
}
}
44 changes: 44 additions & 0 deletions Model/RotateHandleGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// RotateHandleGroup.cs
//
// Author:
// Manuel Cerón <ceronman@unicauca.edu.co>
//
// Copyright (c) 2008 Manuel Cerón.
//
// 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.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//

using System.Windows;
using System.Windows.Shapes;
using LunarEclipse.Controller;

namespace LunarEclipse.Model {

public class RotateHandleGroup: AbstractHandleGroup {

public RotateHandleGroup(MoonlightController controller, UIElement child):
base(controller, child)
{
AddHandle(new BottomRightRotateHandle(controller, this) );

UpdateHandles();
}
}
}
17 changes: 13 additions & 4 deletions Model/TransformHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,26 @@ public TransformHandle(MoonlightController controller, IHandleGroup group):
{
}

protected Point TransformOrigin {
protected Point ElementTransformOrigin {
get {
return (Point) Element.GetValue(RenderTransformOriginProperty);
}
}

protected RotateTransform Rotation {
get { return (RotateTransform) Transformations.Children[(int) Transform.Rotate]; }
protected Point ElementTransformCenter {
get {
Rect bounds = ElementBounds;
Point origin = ElementTransformOrigin;
return new Point(bounds.X + bounds.Width * origin.X,
bounds.Y + bounds.Height * origin.Y);
}
}

protected RotateTransform ElementRotation {
get { return (RotateTransform) ElementTransformGroup.Children[(int) Transform.Rotate]; }
}

protected TransformGroup Transformations {
protected TransformGroup ElementTransformGroup {
get {
TransformGroup group = (TransformGroup) Element.GetValue(RenderTransformProperty);

Expand Down

0 comments on commit 537da89

Please sign in to comment.