Skip to content

Commit

Permalink
added resizable middle part
Browse files Browse the repository at this point in the history
  • Loading branch information
arakis committed Jun 8, 2014
1 parent be863cc commit e08ec0b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/DrawGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,21 @@ public class TCaliperGroup : TDrawGroup
public TCaliperPart1 part1;
public TCaliperPart2 part2;
public TCaliperPart3 part3;
public TCaliperPart4 part4;

public TCaliperGroup ()
{
parts.Add (part1 = new TCaliperPart1 ());
parts.Add (part2 = new TCaliperPart2 ());
parts.Add (part3 = new TCaliperPart3 ());
parts.Add (part4 = new TCaliperPart4 ());

//part2.rect.Y = 20;
part2.rect.X = 100;
distance = 100;
part4.rect.X = 52;
part4.rect.Y = 47;

setContrastColor( contrastColor);
setContrastColor (contrastColor);

var color1 = new MenuItem ("Color");
menu.Insert (color1, 0);
Expand All @@ -99,14 +103,13 @@ public TCaliperGroup ()
chooser.Style = originalStyle;
if (chooser.Run () == (int)ResponseType.Ok) {
setContrastColor( new TColor (chooser.ColorSelection.CurrentColor));
setContrastColor (new TColor (chooser.ColorSelection.CurrentColor));
}
chooser.Hide ();
}
}
};
}

// *** configuration ***
public POINT rotationCenterImage = new POINT (20, 65);
public POINT displayCenterOffset = new POINT (45, 68);
Expand All @@ -116,14 +119,14 @@ public TCaliperGroup ()
private TColor contrastColor = new TColor (150, 0, 0);
double angle = 0.0174532925 * 0;
// ***

double tmpAngle = 0;
public RECT unrotatedRect;
public RECT rotatedRect;
public POINT rotationCenterRoot = new POINT (1920 + 1920 / 2, 1200 / 2);
public POINT rotationCenterZero = new POINT (0, 0);

public void setContrastColor(TColor color){
public void setContrastColor (TColor color)
{
contrastColor = color;
foreach (var part in parts) {
part.applyContrast (color);
Expand Down Expand Up @@ -158,17 +161,7 @@ public void generateImage ()
if (part.rotate) {
//Draw image

var r = part.rect;

using (var pat = new SurfacePattern (part.image)) {
pat.Matrix = new Matrix (){ X0 = -r.X, Y0 = -r.Y };
//pat.Matrix = pat.Matrix;

cr.SetSource (pat);
cr.Rectangle (new Cairo.Rectangle (r.X, r.Y, r.Width, r.Height));
cr.Fill ();

}
part.draw (cr);
}
}

Expand Down Expand Up @@ -281,6 +274,7 @@ public int distance {
}
set {
part2.rect.X = value + minX;
updatePart4 ();
}
}

Expand Down Expand Up @@ -324,7 +318,7 @@ public int getDistanceToRotationCenter (POINT rootPos)
int x, y;
GetPosition (out x, out y);

var p=AbsPosToUnrotatedPos (new POINT (rootPos.X-x, rootPos.Y-y));
var p = AbsPosToUnrotatedPos (new POINT (rootPos.X - x, rootPos.Y - y));
return p.X - rotationCenterImage.X;
}

Expand All @@ -349,6 +343,7 @@ protected override bool OnMotionNotifyEvent (EventMotion evnt)
part2.rect.X = getDistanceToRotationCenter (rootMousePos);
part2.rect.X -= moveMouseXOffset;
part2.rect.X = Math.Max (part2.rect.X, minX);
updatePart4 ();

if (distance > minDistanceForRotation) {
tmpAngle = funcs.GetAngleOfLineBetweenTwoPoints (rotationCenterRoot, rootMousePos);
Expand Down Expand Up @@ -378,6 +373,10 @@ protected override bool OnMotionNotifyEvent (EventMotion evnt)
return base.OnMotionNotifyEvent (evnt);
}

private void updatePart4(){
part4.rect.Width = distance;
}

protected override bool OnButtonPressEvent (EventButton evnt)
{
mousePos = new POINT ((int)evnt.X, (int)evnt.Y);
Expand Down
26 changes: 26 additions & 0 deletions src/lib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,21 @@ public virtual void applyContrast (TColor c)
//public double rotationAngle;
public System.Drawing.Rectangle rect;
//public System.Drawing.Rectangle rotatedRect;

public virtual void draw(Context cr){
var r = rect;
using (var pat = new SurfacePattern (image)) {
pat.Matrix = new Matrix (){ X0 = -r.X, Y0 = -r.Y };
pat.Extend = Extend.Repeat;
//pat.Matrix = pat.Matrix;

cr.SetSource (pat);
cr.Rectangle (new Cairo.Rectangle (r.X, r.Y, r.Width, r.Height));
cr.Fill ();

}
}

}

public class TImagePart : TPart
Expand Down Expand Up @@ -325,6 +340,17 @@ public TCaliperPart3 () : base ("../../template/caliper/3.png")
//drawNonrotated = true;
}
}

public class TCaliperPart4 : TImagePart
{
public TCaliperPart4 () : base ("../../template/caliper/4.png")
{
rotate = true;
//drawNonrotated = true;
}

}

}


Binary file added src/template/caliper/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/template/caliper/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e08ec0b

Please sign in to comment.