aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/Rectangles.cs
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2014-12-18 22:41:10 +0100
committerjpbruyere <jp.bruyere@hotmail.com>2014-12-18 22:41:10 +0100
commitd5a5d9516969d7a0fb665a72be7269e7bd51ad58 (patch)
tree64807d55e1994b3c700e9628ac7a6ba602a4426f /src/Rectangles.cs
parent02fed0f59e37aa66381023ec1543cca9a54ac118 (diff)
misa a jour
Diffstat (limited to 'src/Rectangles.cs')
-rw-r--r--src/Rectangles.cs368
1 files changed, 204 insertions, 164 deletions
diff --git a/src/Rectangles.cs b/src/Rectangles.cs
index 8129fc83..71ebf477 100644
--- a/src/Rectangles.cs
+++ b/src/Rectangles.cs
@@ -1,164 +1,204 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Cairo;
-using System.Diagnostics;
-
-namespace go
-{
- public class Rectangles
- {
- public List<Rectangle> list = new List<Rectangle>();
- public int count
- {
- get { return list.Count; }
- }
-
- public void AddRectangle(Rectangle r)
- {
- //if (r.Left == 0)
- // Debugger.Break();
- if (addRect(r))
- list.Add(r);
- }
- public void Reset()
- {
- list = new List<Rectangle>();
- }
- bool addRect(Rectangle r)
- {
- foreach (Rectangle rInList in list)
- if (rInList.Contains(r))
- return false;
- return true;
- }
-
- public bool intersect(Rectangle r)
- {
- foreach (Rectangle rInList in list)
- if (rInList.Intersect(r))
- return true;
- return false;
- }
-
- public Rectangles intersectingRects(Rectangle r)
- {
- Rectangles tmp = new Rectangles();
-
- foreach (Rectangle rInList in list)
- if (rInList.Intersect(r))
- tmp.list.Add(rInList.Clone);//on bypass le test déjà fait a l'ajout intial du rect dans la liste
-
- return tmp;
- }
- public Rectangles SmallerContainedRects(Rectangle r)
- {
- Rectangles tmp = new Rectangles();
-
- foreach (Rectangle rInList in list)
- if (r.Contains(rInList) && rInList.Size < r.Size)
- tmp.list.Add(rInList.Clone);
-
- return tmp;
- }
- public Rectangles SmallerRects(Rectangle r)
- {
- Rectangles tmp = new Rectangles();
-
- foreach (Rectangle rInList in list)
- if (rInList.Size < r.Size)
- tmp.list.Add(rInList.Clone);
-
- return tmp;
- }
- public Rectangles containedRects(Rectangle r)
- {
- Rectangles tmp = new Rectangles();
-
- foreach (Rectangle rInList in list)
- if (r.Contains(rInList) && rInList.Size <= r.Size)
- tmp.list.Add(rInList.Clone);
-
- return tmp;
- }
- public void Rebase(GraphicObject w)
- {
- Rectangle r = w.renderBounds;
- List<Rectangle> newList = new List<Rectangle>();
-
- foreach (Rectangle rInList in list)
- {
- Rectangle rebasedR = rInList.Clone;
- rebasedR.TopLeft-= r.TopLeft;
-
- ScrollingWidget sw = w as ScrollingWidget;
- if (sw != null)
- {
- if (sw.VerticalScrolling)
- rebasedR.Top -= sw.scrollY;
- if (sw.HorizontalScrolling)
- rebasedR.Left -= sw.scrollX;
- }
- newList.Add(rebasedR);
- }
- list = newList;
- }
- public void clearAndClip(Context ctx)
- {
- //ctx.Save();
-
- foreach (Rectangle r in list)
- {
- ctx.Rectangle(r);
- }
-
- ctx.ClipPreserve();
- ctx.Operator = Operator.Clear;
- ctx.Fill();
- ctx.Operator = Operator.Over;
- //ctx.Restore();
- }
- public void clip(Context ctx)
- {
- foreach (Rectangle r in list)
- {
- ctx.Rectangle(r);
- }
-
- ctx.Clip();
- }
- public void clear(Context ctx)
- {
- //ctx.Save();
-
- foreach (Rectangle r in list)
- {
- ctx.Rectangle(r);
- }
- ctx.Operator = Operator.Clear;
- ctx.Fill();
- ctx.Operator = Operator.Over;
- //ctx.Restore();
- }
- //public RectanglesRelations test(Rectangle r)
- //{
- // foreach (Rectangle rInList in list)
- // {
- // switch (rInList.test(r))
- // {
- // case RectanglesRelations.NoRelation:
- // break;
- // case RectanglesRelations.Intersect:
- // break;
- // case RectanglesRelations.Contains:
- // break;
- // case RectanglesRelations.Equal:
- // break;
- // default:
- // break;
- // }
- // }
- //}
- }
-}
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Cairo;
+using System.Diagnostics;
+
+namespace go
+{
+ public class Rectangles
+ {
+ public List<Rectangle> list = new List<Rectangle>();
+ public int count
+ {
+ get { return list.Count; }
+ }
+
+ public void AddRectangle(Rectangle r)
+ {
+ if (rectIsNotContainedInRectangles (r)) {
+ list.Add (r);
+ boundsUpToDate = false;
+ }
+ }
+ public void Reset()
+ {
+ list = new List<Rectangle>();
+ _bounds = Rectangle.Empty;
+ boundsUpToDate = true;
+ }
+ bool rectIsNotContainedInRectangles(Rectangle r)
+ {
+ foreach (Rectangle rInList in list)
+ if (rInList.ContainsOrIsEqual(r))
+ return false;
+ return true;
+ }
+
+ public bool intersect(Rectangle r)
+ {
+ foreach (Rectangle rInList in list)
+ if (rInList.Intersect(r))
+ return true;
+ return false;
+ }
+
+ public Rectangles intersectingRects(Rectangle r)
+ {
+ Rectangles tmp = new Rectangles();
+
+ foreach (Rectangle rInList in list)
+ if (rInList.Intersect(r))
+ tmp.list.Add(rInList);//on bypass le test déjà fait a l'ajout intial du rect dans la liste
+
+ return tmp;
+ }
+ public Rectangles SmallerContainedRects(Rectangle r)
+ {
+ Rectangles tmp = new Rectangles();
+
+ foreach (Rectangle rInList in list)
+ if (r.ContainsOrIsEqual(rInList) && rInList.Size < r.Size)
+ tmp.list.Add(rInList);
+
+ return tmp;
+ }
+ /// <summary>
+ /// Return rectangles with size smaller than r.size
+ /// </summary>
+ public Rectangles SmallerRects(Rectangle r)
+ {
+ Rectangles tmp = new Rectangles();
+
+ foreach (Rectangle rInList in list)
+ if (rInList.Size < r.Size)
+ tmp.list.Add(rInList);
+
+ return tmp;
+ }
+ public Rectangles containedOrEqualRects(Rectangle r)
+ {
+ Rectangles tmp = new Rectangles();
+
+ foreach (Rectangle rInList in list)
+ if (r.ContainsOrIsEqual(rInList))// && rInList.Size <= r.Size)
+ tmp.list.Add(rInList);
+
+ return tmp;
+ }
+ public void Srcoll(GraphicObject w)
+ {
+ Scroller sw = w as Scroller;
+ if (sw == null)
+ return;
+
+ List<Rectangle> newList = new List<Rectangle>();
+
+ foreach (Rectangle rInList in list)
+ {
+ Rectangle r = rInList;
+
+ if (sw.VerticalScrolling)
+ r.Top -= sw.scrollY;
+ if (sw.HorizontalScrolling)
+ r.Left -= sw.scrollX;
+
+ newList.Add(r);
+ }
+ list = newList;
+ }
+ public void Rebase(GraphicObject w)
+ {
+ Rectangle r = w.Parent.ContextCoordinates(w.Slot);
+ List<Rectangle> newList = new List<Rectangle>();
+
+ foreach (Rectangle rInList in list)
+ {
+ Rectangle rebasedR = rInList;
+ rebasedR.TopLeft-= r.TopLeft;
+
+ Scroller sw = w as Scroller;
+ if (sw != null)
+ {
+ if (sw.VerticalScrolling) {
+ rebasedR.Top -= sw.scrollY;
+// if (sw.scrollY < 0)
+// Debug.WriteLine ("..");
+ }if (sw.HorizontalScrolling)
+ rebasedR.Left -= sw.scrollX;
+ }
+
+ newList.Add(rebasedR);
+ }
+ list = newList;
+ }
+ public void stroke(Context ctx, Color c)
+ {
+ foreach (Rectangle r in list)
+ {
+ ctx.Rectangle(r);
+ }
+
+ ctx.Color = c;
+
+ ctx.LineWidth = 2;
+ ctx.Stroke ();
+ }
+ public void clearAndClip(Context ctx)
+ {
+ foreach (Rectangle r in list)
+ {
+ ctx.Rectangle(r);
+ }
+
+ ctx.ClipPreserve();
+
+ //if (Interface.Background == Color.Transparent) {
+ ctx.Operator = Operator.Clear;
+ //} else {
+ // ctx.Color = Interface.Background;
+ //}
+
+ ctx.Fill();
+ ctx.Operator = Operator.Over;
+ }
+
+ public void clip(Context ctx)
+ {
+ foreach (Rectangle r in list)
+ {
+ ctx.Rectangle(r);
+ }
+
+ ctx.Clip();
+ }
+
+ Rectangle _bounds;
+ bool boundsUpToDate = true;
+ public Rectangle Bounds {
+ get {
+ if (!boundsUpToDate) {
+ _bounds = Rectangle.Empty;
+ foreach (Rectangle rInList in list)
+ _bounds += rInList;
+ boundsUpToDate = true;
+ }
+ return _bounds;
+ }
+ }
+ public void clear(Context ctx)
+ {
+ //ctx.Save();
+
+ foreach (Rectangle r in list)
+ {
+ ctx.Rectangle(r);
+ }
+ ctx.Operator = Operator.Clear;
+ ctx.Fill();
+ ctx.Operator = Operator.Over;
+ //ctx.Restore();
+ }
+ }
+}