diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2017-08-13 19:11:00 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2017-08-13 19:11:00 +0200 |
| commit | 5f68cf21b47b88e4e1de7fed7bd9b8b56b5dfa3d (patch) | |
| tree | 5571df47d1e938e51d204372a7fa874b343313a9 /src/GraphicObjects | |
| parent | 8776ccb3ca259053c2b93b0a068b76a9bf8032f3 (diff) | |
cairo.region to handle clipping, native pointer leaking...
Diffstat (limited to 'src/GraphicObjects')
| -rw-r--r-- | src/GraphicObjects/Container.cs | 55 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 208 | ||||
| -rw-r--r-- | src/GraphicObjects/Group.cs | 83 | ||||
| -rw-r--r-- | src/GraphicObjects/Popper.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/PrivateContainer.cs | 12 | ||||
| -rw-r--r-- | src/GraphicObjects/ScrollBar.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/TemplatedContainer.cs | 66 | ||||
| -rw-r--r-- | src/GraphicObjects/TemplatedControl.cs | 96 | ||||
| -rw-r--r-- | src/GraphicObjects/TemplatedGroup.cs | 59 |
9 files changed, 40 insertions, 541 deletions
diff --git a/src/GraphicObjects/Container.cs b/src/GraphicObjects/Container.cs index aac35946..df14b8e2 100644 --- a/src/GraphicObjects/Container.cs +++ b/src/GraphicObjects/Container.cs @@ -33,7 +33,7 @@ using System.Threading; namespace Crow { - public class Container : PrivateContainer, IXmlSerializable + public class Container : PrivateContainer { #region CTOR public Container() @@ -51,59 +51,6 @@ namespace Crow { base.SetChild (_child); } - - #region IXmlSerializable - - public override System.Xml.Schema.XmlSchema GetSchema() - { - return null; - } - public override void ReadXml(System.Xml.XmlReader reader) - { - //only read attributes in GraphicObject IXmlReader implementation - base.ReadXml(reader); - - - using (System.Xml.XmlReader subTree = reader.ReadSubtree()) - { - subTree.Read(); //skip current node - subTree.Read(); //read first child - - if (!subTree.IsStartElement()) - return; - - Type t = Type.GetType("Crow." + subTree.Name); - if (t == null) { - Assembly a = Assembly.GetEntryAssembly (); - foreach (Type expT in a.GetExportedTypes ()) { - if (expT.Name == subTree.Name) { - t = expT; - break; - } - } - } - GraphicObject go = (GraphicObject)Activator.CreateInstance(t); - - (go as IXmlSerializable).ReadXml(subTree); - - SetChild(go); - - subTree.Read();//closing tag - } - } - public override void WriteXml(System.Xml.XmlWriter writer) - { - base.WriteXml(writer); - - if (Child == null) - return; - - writer.WriteStartElement(Child.GetType().Name); - (Child as IXmlSerializable).WriteXml(writer); - writer.WriteEndElement(); - } - - #endregion } } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 284e4877..41738802 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -38,7 +38,7 @@ using System.IO; namespace Crow { - public class GraphicObject : IXmlSerializable, ILayoutable, IValueChange, ICloneable + public class GraphicObject : ILayoutable, IValueChange { internal static ulong currentUid = 0; internal ulong uid = 0; @@ -58,8 +58,7 @@ namespace Crow } } - Rectangles clipping = new Rectangles(); - public Rectangles Clipping { get { return clipping; }} + public Region Clipping; #region IValueChange implementation public event EventHandler<ValueChangeEventArgs> ValueChanged; @@ -73,20 +72,22 @@ namespace Crow #region CTOR public GraphicObject () { + Clipping = new Region (); #if DEBUG uid = currentUid; currentUid++; #endif } #endregion - + internal bool initialized = false; /// <summary> /// Initialize this Graphic object instance by setting style and default values and loading template if required /// </summary> public virtual void Initialize(){ if (currentInterface == null) - currentInterface = Interface.CurrentInterface; + currentInterface = Interface.CurrentInterface; loadDefaultValues (); + initialized = true; } #region private fields LayoutingType registeredLayoutings = LayoutingType.All; @@ -844,7 +845,7 @@ namespace Crow public virtual void RegisterClip(Rectangle clip){ Rectangle r = clip + ClientRectangle.Position; if (CacheEnabled && !IsDirty) - Clipping.AddRectangle (r); + Clipping.UnionRectangle (r); if (Parent == null) return; GraphicObject p = Parent as GraphicObject; @@ -1107,7 +1108,7 @@ namespace Crow Rectangle rBack = new Rectangle (Slot.Size); Background.SetAsSource (gr, rBack); - CairoHelpers.CairoRectangle(gr,rBack,cornerRadius); + CairoHelpers.CairoRectangle (gr, rBack, cornerRadius); gr.Fill (); } @@ -1137,8 +1138,8 @@ namespace Crow } ctx.SetSourceSurface (bmp, rb.X, rb.Y); ctx.Paint (); - //Clipping.clearAndClip (ctx); - Clipping.Reset(); + Clipping.Dispose (); + Clipping = new Region (); } /// <summary> Chained painting routine on the parent context of the actual cached version /// of the widget </summary> @@ -1332,195 +1333,6 @@ namespace Crow protected virtual void onLogicalParentChanged(object sender, DataSourceChangeEventArgs e) { LogicalParentChanged.Raise (this, e); } - #region IXmlSerializable - public virtual System.Xml.Schema.XmlSchema GetSchema () - { - return null; - } -// void affectMember(string name, string value){ -// Type thisType = this.GetType (); -// -// if (string.IsNullOrEmpty (value)) -// return; -// -// MemberInfo mi = thisType.GetMember (name).FirstOrDefault(); -// if (mi == null) { -// Debug.WriteLine ("XML: Unknown attribute in " + thisType.ToString() + " : " + name); -// return; -// } -// if (mi.MemberType == MemberTypes.Event) { -// this.Bindings.Add (new Binding (new MemberReference(this, mi), value)); -// return; -// } -// if (mi.MemberType == MemberTypes.Property) { -// PropertyInfo pi = mi as PropertyInfo; -// -// if (pi.GetSetMethod () == null) { -// Debug.WriteLine ("XML: Read only property in " + thisType.ToString() + " : " + name); -// return; -// } -// -// XmlAttributeAttribute xaa = (XmlAttributeAttribute)pi.GetCustomAttribute (typeof(XmlAttributeAttribute)); -// if (xaa != null) { -// if (!string.IsNullOrEmpty (xaa.AttributeName)) -// name = xaa.AttributeName; -// } -// if (value.StartsWith("{",StringComparison.Ordinal)) { -// //binding -// if (!value.EndsWith("}", StringComparison.Ordinal)) -// throw new Exception (string.Format("XML:Malformed binding: {0}", value)); -// -// this.Bindings.Add (new Binding (new MemberReference(this, pi), value.Substring (1, value.Length - 2))); -// return; -// } -// if (pi.GetCustomAttribute (typeof(XmlIgnoreAttribute)) != null) -// return; -// if (xaa == null)//not define as xmlAttribute -// return; -// -// if (pi.PropertyType == typeof(string)) { -// pi.SetValue (this, value, null); -// return; -// } -// -// if (pi.PropertyType.IsEnum) { -// pi.SetValue (this, Enum.Parse (pi.PropertyType, value), null); -// } else { -// MethodInfo me = pi.PropertyType.GetMethod ("Parse", new Type[] { typeof(string) }); -// pi.SetValue (this, me.Invoke (null, new string[] { value }), null); -// } -// } -// } - public virtual void ReadXml (System.Xml.XmlReader reader) - { - if (reader.HasAttributes) { - - style = reader.GetAttribute ("Style"); - - loadDefaultValues (); - - while (reader.MoveToNextAttribute ()) { - if (reader.Name == "Style") - continue; - - //affectMember (reader.Name, reader.Value); - } - reader.MoveToElement (); - }else - loadDefaultValues (); - } - public virtual void WriteXml (System.Xml.XmlWriter writer) - { - foreach (PropertyInfo pi in this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { - if (pi.GetSetMethod () == null) - continue; - - bool isAttribute = false; - bool hasDefaultValue = false; - bool ignore = false; - string name = ""; - object value = null; - Type valueType = null; - - - MemberInfo mi = pi.GetGetMethod (); - - if (mi == null) - continue; - - value = pi.GetValue (this, null); - valueType = pi.PropertyType; - name = pi.Name; - - - - object[] att = pi.GetCustomAttributes (false); - - foreach (object o in att) { - XmlAttributeAttribute xaa = o as XmlAttributeAttribute; - if (xaa != null) { - isAttribute = true; - if (string.IsNullOrEmpty (xaa.AttributeName)) - name = pi.Name; - else - name = xaa.AttributeName; - continue; - } - - XmlIgnoreAttribute xia = o as XmlIgnoreAttribute; - if (xia != null) { - ignore = true; - continue; - } - - DefaultValueAttribute dv = o as DefaultValueAttribute; - if (dv != null) { - if (dv.Value.Equals (value)) - hasDefaultValue = true; - if (dv.Value.ToString () == value.ToString ()) - hasDefaultValue = true; - - continue; - } - - - } - - if (hasDefaultValue || ignore || value==null) - continue; - - if (isAttribute) - writer.WriteAttributeString (name, value.ToString ()); - else { - if (valueType.GetInterface ("IXmlSerializable") == null) - continue; - - (pi.GetValue (this, null) as IXmlSerializable).WriteXml (writer); - } - } - foreach (EventInfo ei in this.GetType().GetEvents()) { - FieldInfo fi = this.GetType().GetField(ei.Name, - BindingFlags.NonPublic | - BindingFlags.Instance | - BindingFlags.GetField); - - Delegate dg = (System.Delegate)fi.GetValue (this); - - if (dg == null) - continue; - - foreach (Delegate d in dg.GetInvocationList()) { - if (!d.Method.Name.StartsWith ("<"))//Skipping empty handler, not clear it's trikky - writer.WriteAttributeString (ei.Name, d.Method.Name); - } - } - } - #endregion - - #region ICloneable implementation - public object Clone () - { - Type type = this.GetType (); - GraphicObject result = (GraphicObject)Activator.CreateInstance (type); - result.CurrentInterface = CurrentInterface; - - foreach (PropertyInfo pi in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { - if (pi.GetSetMethod () == null) - continue; - - if (pi.GetCustomAttribute<XmlIgnoreAttribute> () != null) - continue; - if (pi.Name == "DataSource") - continue; - - pi.SetValue(result, pi.GetValue(this)); - } - return result; - } - #endregion - /// <summary> - /// full GraphicTree clone with binding definition - /// </summary> public override string ToString () { diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index de6d3e40..f3c357d2 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -29,14 +29,13 @@ using System.Collections.Generic; using System.ComponentModel; using System.Xml.Serialization; using Cairo; -using OpenTK.Input; using System.Diagnostics; using System.Reflection; namespace Crow { - public class Group : GraphicObject, IXmlSerializable + public class Group : GraphicObject { #region CTOR public Group() @@ -238,20 +237,28 @@ namespace Crow Context gr = new Context (bmp); - if (Clipping.count > 0) { - Clipping.clearAndClip (gr); + if (!Clipping.IsEmpty) { + for (int i = 0; i < Clipping.NumRectangles; i++) + gr.Rectangle(Clipping.GetRectangle(i)); + gr.ClipPreserve(); + gr.Operator = Operator.Clear; + gr.Fill(); + gr.Operator = Operator.Over; + base.onDraw (gr); - //clip to client zone - CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); - gr.Clip (); + if (ClipToClientRect) { + CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); + gr.Clip (); + } lock (Children) { foreach (GraphicObject c in Children) { if (!c.Visible) continue; - if (Clipping.intersect (c.Slot + ClientRectangle.Position)) - c.Paint (ref gr); + if (Clipping.Contains (c.Slot + ClientRectangle.Position) == RegionOverlap.Out) + continue; + c.Paint (ref gr); } } @@ -264,7 +271,8 @@ namespace Crow ctx.SetSourceSurface (bmp, rb.X, rb.Y); ctx.Paint (); - Clipping.Reset(); + Clipping.Dispose(); + Clipping = new Region (); } #endregion @@ -356,60 +364,5 @@ namespace Crow base.checkHoverWidget (e); } #endregion - - - #region IXmlSerializable - - public override System.Xml.Schema.XmlSchema GetSchema() - { - return null; - } - public override void ReadXml(System.Xml.XmlReader reader) - { - base.ReadXml(reader); - - using (System.Xml.XmlReader subTree = reader.ReadSubtree()) - { - subTree.Read(); - - while (!subTree.EOF) - { - subTree.Read(); - - if (!subTree.IsStartElement()) - break; - - Type t = Type.GetType("Crow." + subTree.Name); - if (t == null) { - Assembly a = Assembly.GetEntryAssembly (); - foreach (Type expT in a.GetExportedTypes ()) { - if (expT.Name == subTree.Name) { - t = expT; - break; - } - } - } - if (t == null) - throw new Exception (subTree.Name + " type not found"); - GraphicObject go = (GraphicObject)Activator.CreateInstance(t); - (go as IXmlSerializable).ReadXml(subTree); - AddChild(go); - } - } - } - public override void WriteXml(System.Xml.XmlWriter writer) - { - base.WriteXml(writer); - - foreach (GraphicObject go in Children) - { - writer.WriteStartElement(go.GetType().Name); - (go as IXmlSerializable).WriteXml(writer); - writer.WriteEndElement(); - } - } - - #endregion - } } diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index d3f2e7c8..0e5364d6 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -27,7 +27,6 @@ using System; using System.Xml.Serialization; using System.ComponentModel; -using OpenTK.Input; namespace Crow { diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index d018bd77..02e251be 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -179,10 +179,16 @@ namespace Crow { Rectangle rb = Slot + Parent.ClientRectangle.Position; + Context gr = new Context (bmp); - if (Clipping.count > 0) { - Clipping.clearAndClip (gr); + if (!Clipping.IsEmpty) { + for (int i = 0; i < Clipping.NumRectangles; i++) + gr.Rectangle(Clipping.GetRectangle(i)); + gr.ClipPreserve(); + gr.Operator = Operator.Clear; + gr.Fill(); + gr.Operator = Operator.Over; onDraw (gr); } @@ -191,6 +197,8 @@ namespace Crow ctx.SetSourceSurface (bmp, rb.X, rb.Y); ctx.Paint (); + Clipping.Dispose(); + Clipping = new Region (); } #endregion diff --git a/src/GraphicObjects/ScrollBar.cs b/src/GraphicObjects/ScrollBar.cs index 91ce50ef..ca258aae 100644 --- a/src/GraphicObjects/ScrollBar.cs +++ b/src/GraphicObjects/ScrollBar.cs @@ -27,7 +27,6 @@ using System; using System.Xml.Serialization; using System.ComponentModel; -using OpenTK.Input; namespace Crow { diff --git a/src/GraphicObjects/TemplatedContainer.cs b/src/GraphicObjects/TemplatedContainer.cs index 1ab8cf7d..b8a32167 100644 --- a/src/GraphicObjects/TemplatedContainer.cs +++ b/src/GraphicObjects/TemplatedContainer.cs @@ -57,72 +57,6 @@ namespace Crow return Content.Contains (goToFind); } #endregion - - #region IXmlSerialisation Overrides - public override void ReadXml(System.Xml.XmlReader reader) - { - using (System.Xml.XmlReader subTree = reader.ReadSubtree ()) { - subTree.Read (); - string tmp = subTree.ReadOuterXml (); - - //seek for template tag - using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) { - xr.Read (); - base.ReadXml (xr); - } - //process content - using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) { - xr.Read (); //skip current node - - while (!xr.EOF) { - xr.Read (); //read first child - - if (!xr.IsStartElement ()) - continue; - - if (xr.Name == "Template"){ - xr.Skip (); - if (!xr.IsStartElement ()) - continue; - } - - Type t = Type.GetType ("Crow." + xr.Name); - if (t == null) { - Assembly a = Assembly.GetEntryAssembly (); - foreach (Type expT in a.GetExportedTypes ()) { - if (expT.Name == xr.Name) { - t = expT; - break; - } - } - } - if (t == null) - throw new Exception (xr.Name + " type not found"); - - GraphicObject go = (GraphicObject)Activator.CreateInstance (t); - - (go as IXmlSerializable).ReadXml (xr); - - Content = go; - - xr.Read (); //closing tag - } - - } - } - } - public override void WriteXml(System.Xml.XmlWriter writer) - { - base.WriteXml(writer); - - if (Content == null) - return; - //TODO: if template is not the default one, we have to save it - writer.WriteStartElement(Content.GetType().Name); - (Content as IXmlSerializable).WriteXml(writer); - writer.WriteEndElement(); - } - #endregion } } diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index 082d0426..0461a8ee 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -37,7 +37,7 @@ using System.Reflection; namespace Crow { - public abstract class TemplatedControl : PrivateContainer, IXmlSerializable + public abstract class TemplatedControl : PrivateContainer { #region CTOR public TemplatedControl () : base() @@ -111,100 +111,6 @@ namespace Crow }else this.SetChild (template); } - - //TODO:IXmlSerializable is not used anymore - #region IXmlSerializable - public override System.Xml.Schema.XmlSchema GetSchema(){ return null; } - public override void ReadXml(System.Xml.XmlReader reader) - { - //Template could be either an attribute containing path or expressed inlined - //as a Template Element - using (System.Xml.XmlReader subTree = reader.ReadSubtree()) - { - subTree.Read (); - - string template = reader.GetAttribute ("Template"); - string tmp = subTree.ReadOuterXml (); - - //Load template from path set as attribute in templated control - if (string.IsNullOrEmpty (template)) { - //seek for template tag first - using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) { - //load template first if inlined - - xr.Read (); //read first child - xr.Read (); //skip root node - - while (!xr.EOF) { - if (!xr.IsStartElement ()) { - xr.Read (); - continue; - } - if (xr.Name == "ItemTemplate") { - string dataType = "default", datas = "", itemTmp; - while (xr.MoveToNextAttribute ()) { - if (xr.Name == "DataType") - dataType = xr.Value; - else if (xr.Name == "Data") - datas = xr.Value; - } - xr.MoveToElement (); - itemTmp = xr.ReadInnerXml (); - -// if (ItemTemplates == null) -// ItemTemplates = new Dictionary<string, ItemTemplate> (); -// -// using (IMLReader iTmp = new IMLReader (null, itemTmp)) { -// ItemTemplates [dataType] = -// new ItemTemplate (iTmp.RootType, iTmp.GetLoader (), dataType, datas); -// } -// if (!string.IsNullOrEmpty (datas)) -// ItemTemplates [dataType].CreateExpandDelegate(this); - - continue; - } - if (xr.Name == "Template") { - xr.Read (); - - Type t = Type.GetType ("Crow." + xr.Name); - if (t == null) { - Assembly a = Assembly.GetEntryAssembly (); - foreach (Type expT in a.GetExportedTypes ()) { - if (expT.Name == xr.Name) { - t = expT; - break; - } - } - } - GraphicObject go = (GraphicObject)Activator.CreateInstance (t); - (go as IXmlSerializable).ReadXml (xr); - - loadTemplate (go); - continue; - } - xr.ReadInnerXml (); - } - } - } else - loadTemplate (CurrentInterface.Load (template)); - - //if no template found, load default one - if (this.child == null) - loadTemplate (); - - //normal xml read - using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) { - xr.Read (); - base.ReadXml(xr); - } - } - } - public override void WriteXml(System.Xml.XmlWriter writer) - { - //TODO: - throw new NotImplementedException(); - } - #endregion } } diff --git a/src/GraphicObjects/TemplatedGroup.cs b/src/GraphicObjects/TemplatedGroup.cs index e4447168..eea3a184 100644 --- a/src/GraphicObjects/TemplatedGroup.cs +++ b/src/GraphicObjects/TemplatedGroup.cs @@ -267,65 +267,6 @@ namespace Crow // } #endregion - #region IXmlSerialisation Overrides - public override void ReadXml(System.Xml.XmlReader reader) - { - using (System.Xml.XmlReader subTree = reader.ReadSubtree ()) { - subTree.Read (); - string tmp = subTree.ReadOuterXml (); - - //seek for template tag - using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) { - xr.Read (); - base.ReadXml (xr); - } - //process content - using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) { - xr.Read (); //skip current node - - while (!xr.EOF) { - xr.Read (); //read first child - - if (!xr.IsStartElement ()) - continue; - - if (xr.Name == "Template" || Name == "ItemTemplate"){ - xr.Skip (); - if (!xr.IsStartElement ()) - continue; - } - - Type t = Type.GetType ("Crow." + xr.Name); - if (t == null) { - Assembly a = Assembly.GetEntryAssembly (); - foreach (Type expT in a.GetExportedTypes ()) { - if (expT.Name == xr.Name) { - t = expT; - break; - } - } - } - if (t == null) - throw new Exception (xr.Name + " type not found"); - - GraphicObject go = (GraphicObject)Activator.CreateInstance (t); - - (go as IXmlSerializable).ReadXml (xr); - - AddItem (go); - - xr.Read (); //closing tag - } - - } - } - } - public override void WriteXml(System.Xml.XmlWriter writer) - { - throw new NotImplementedException (); - } - #endregion - void loading(){ if (ItemTemplates == null) ItemTemplates = new Dictionary<string, ItemTemplate> (); |