From: Jean-Philippe Bruyère Date: Sun, 13 Aug 2017 17:11:00 +0000 (+0200) Subject: cairo.region to handle clipping, native pointer leaking... X-Git-Tag: v0.9.5-beta~209 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=da33782c4ab475d0e8c1216f13ecbff2450ec546;p=jp%2Fcrow.git cairo.region to handle clipping, native pointer leaking... --- diff --git a/Crow.csproj b/Crow.csproj index e5395a06..29bcd8e0 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -23,6 +23,8 @@ $(SolutionDir)build\$(Configuration) $(SolutionDir)build\obj\$(Configuration) crow.key + 8.0.30703 + 2.0 true @@ -39,7 +41,6 @@ - diff --git a/Crow.sln b/Crow.sln index ba1b6741..83e55eb5 100644 --- a/Crow.sln +++ b/Crow.sln @@ -5,8 +5,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crow", "Crow.csproj", "{C29 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{74289092-9F70-4941-AFCB-DFD7BE2140B6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrowIDE", "CrowIDE\CrowIDE.csproj", "{B6D911CD-1D09-42FC-B300-9187190F2AE1}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -17,10 +15,6 @@ Global {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Debug|Any CPU.Build.0 = Debug|Any CPU {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Release|Any CPU.ActiveCfg = Release|Any CPU {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Release|Any CPU.Build.0 = Release|Any CPU - {B6D911CD-1D09-42FC-B300-9187190F2AE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B6D911CD-1D09-42FC-B300-9187190F2AE1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B6D911CD-1D09-42FC-B300-9187190F2AE1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B6D911CD-1D09-42FC-B300-9187190F2AE1}.Release|Any CPU.Build.0 = Release|Any CPU {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Debug|Any CPU.Build.0 = Debug|Any CPU {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 362fb9a6..2adcdb16 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -28,12 +28,16 @@ 4 false DEBUG;TRACE;MEASURE_TIME + $(SolutionDir)build\obj\$(Configuration) + $(SolutionDir)build\$(Configuration) none true 0 false + $(SolutionDir)build\obj\$(Configuration) + $(SolutionDir)build\$(Configuration) @@ -42,7 +46,6 @@ $(SolutionDir)packages\OpenTK.2.0.0\lib\net20\OpenTK.dll - opentk 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 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; /// /// Initialize this Graphic object instance by setting style and default values and loading template if required /// 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 (); } /// Chained painting routine on the parent context of the actual cached version /// of the widget @@ -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 () != null) - continue; - if (pi.Name == "DataSource") - continue; - - pi.SetValue(result, pi.GetValue(this)); - } - return result; - } - #endregion - /// - /// full GraphicTree clone with binding definition - /// 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 (); -// -// 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 (); diff --git a/src/Input/Buttons.cs b/src/Input/Buttons.cs index a80f5040..ebf3bc42 100644 --- a/src/Input/Buttons.cs +++ b/src/Input/Buttons.cs @@ -25,7 +25,7 @@ // THE SOFTWARE. using System; -namespace OpenTK.Input +namespace Crow { /// /// Enumerates available buttons for a GamePad device. diff --git a/src/Input/KeyModifiers.cs b/src/Input/KeyModifiers.cs index 1314e737..885365ca 100644 --- a/src/Input/KeyModifiers.cs +++ b/src/Input/KeyModifiers.cs @@ -39,6 +39,7 @@ namespace Crow [Flags] public enum KeyModifiers : byte { + None = 0, /// /// The alt key modifier (option on Mac). /// @@ -52,6 +53,11 @@ namespace Crow /// /// The shift key modifier. /// - Shift = 1 << 2 + Shift = 1 << 2, + + /// + /// The shift key modifier. + /// + AltGr = 1 << 3 } } diff --git a/src/Interface.cs b/src/Interface.cs index 8439c31e..adcb2830 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -110,6 +110,14 @@ namespace Crow #region Events public event EventHandler MouseCursorChanged; public event EventHandler Quit; + + public event EventHandler MouseWheelChanged; + public event EventHandler MouseButtonUp; + public event EventHandler MouseButtonDown; + public event EventHandler MouseClick; + public event EventHandler MouseMove; + public event EventHandler KeyboardKeyDown; + public event EventHandler KeyboardKeyUp; #endregion #region Public Fields @@ -152,7 +160,7 @@ namespace Crow /// Client rectangle in the host context Rectangle clientRectangle; /// Clipping rectangles on the root context - Rectangles clipping = new Rectangles(); + Region clipping = new Region(); /// Main Cairo context Context ctx; /// Main Cairo surface @@ -387,15 +395,19 @@ namespace Crow if (mouseRepeatCount > 0) { int mc = mouseRepeatCount; mouseRepeatCount -= mc; - for (int i = 0; i < mc; i++) { - FocusedWidget.onMouseClick (this, new MouseButtonEventArgs (Mouse.X, Mouse.Y, MouseButton.Left, true)); + if (_focusedWidget != null) { + for (int i = 0; i < mc; i++) { + _focusedWidget.onMouseClick (this, new MouseButtonEventArgs (Mouse.X, Mouse.Y, MouseButton.Left, true)); + } } } if (keyboardRepeatCount > 0) { int mc = keyboardRepeatCount; keyboardRepeatCount -= mc; - for (int i = 0; i < mc; i++) { - _focusedWidget.onKeyDown (this, lastKeyDownEvt); + if (_focusedWidget != null) { + for (int i = 0; i < mc; i++) { + _focusedWidget.onKeyDown (this, lastKeyDownEvt); + } } } CrowThread[] tmpThreads; @@ -490,20 +502,24 @@ namespace Crow #endif using (surf = new ImageSurface (bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height, ClientRectangle.Width * 4)) { using (ctx = new Context (surf)){ - if (clipping.count > 0) { - //Link.draw (ctx); - clipping.clearAndClip(ctx); + if (!clipping.IsEmpty) { + + for (int i = 0; i < clipping.NumRectangles; i++) + ctx.Rectangle(clipping.GetRectangle(i)); + ctx.ClipPreserve(); + ctx.Operator = Operator.Clear; + ctx.Fill(); + ctx.Operator = Operator.Over; for (int i = GraphicTree.Count -1; i >= 0 ; i--){ GraphicObject p = GraphicTree[i]; if (!p.Visible) continue; - if (!clipping.intersect (p.Slot)) + if (clipping.Contains (p.Slot) == RegionOverlap.Out) continue; - ctx.Save (); + ctx.Save (); p.Paint (ref ctx); - ctx.Restore (); } @@ -511,10 +527,13 @@ namespace Crow clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5)); #endif lock (RenderMutex) { +// Array.Copy (bmp, dirtyBmp, bmp.Length); + + IsDirty = true; if (IsDirty) - DirtyRect += clipping.Bounds; + DirtyRect += clipping.Extents; else - DirtyRect = clipping.Bounds; + DirtyRect = clipping.Extents; DirtyRect.Left = Math.Max (0, DirtyRect.Left); DirtyRect.Top = Math.Max (0, DirtyRect.Top); @@ -530,11 +549,12 @@ namespace Crow ((DirtyRect.Top + y) * ClientRectangle.Width * 4) + DirtyRect.Left * 4, dirtyBmp, y * DirtyRect.Width * 4, DirtyRect.Width * 4); } - IsDirty = true; + } else IsDirty = false; } - clipping.Reset (); + clipping.Dispose (); + clipping = new Region (); } //surf.WriteToPng (@"/mnt/data/test.png"); } @@ -642,15 +662,15 @@ namespace Crow public void ProcessResize(Rectangle bounds){ lock (UpdateMutex) { clientRectangle = bounds; - int stride = 4 * ClientRectangle.Width; int bmpSize = Math.Abs (stride) * ClientRectangle.Height; bmp = new byte[bmpSize]; + dirtyBmp = new byte[bmpSize]; foreach (GraphicObject g in GraphicTree) g.RegisterForLayouting (LayoutingType.All); - clipping.AddRectangle (clientRectangle); + RegisterClip (clientRectangle); } } @@ -859,7 +879,7 @@ namespace Crow #region ILayoutable implementation public void RegisterClip(Rectangle r){ - clipping.AddRectangle (r); + clipping.UnionRectangle (r); } public bool ArrangeChildren { get { return false; }} public int LayoutingTries { diff --git a/src/PerformanceMeasure.cs b/src/PerformanceMeasure.cs index 1db29e30..3c978e8b 100644 --- a/src/PerformanceMeasure.cs +++ b/src/PerformanceMeasure.cs @@ -58,14 +58,16 @@ namespace Crow computeStats (); } public void NotifyChanges(){ - if (cptMeasures == 0) - return; - NotifyValueChanged("minimum", minimum); - NotifyValueChanged("maximum", maximum); - NotifyValueChanged("current", current); - // NotifyValueChanged("total", total); - // NotifyValueChanged("cptMeasures", cptMeasures); - NotifyValueChanged("mean", total / cptMeasures); + lock(this){ + if (cptMeasures == 0) + return; + NotifyValueChanged("minimum", minimum); + NotifyValueChanged("maximum", maximum); + NotifyValueChanged("current", current); + // NotifyValueChanged("total", total); + // NotifyValueChanged("cptMeasures", cptMeasures); + NotifyValueChanged("mean", total / cptMeasures); + } } void computeStats(){ @@ -85,7 +87,8 @@ namespace Crow minimum = long.MaxValue; } void onResetClick(object sender, MouseButtonEventArgs e){ - ResetStats(); + lock(this) + ResetStats(); } } } diff --git a/src/Rectangle.cs b/src/Rectangle.cs index 574dc3c4..8f48d06d 100644 --- a/src/Rectangle.cs +++ b/src/Rectangle.cs @@ -28,73 +28,50 @@ using System; using System.Collections.Generic; using System.Text; using System.Xml.Serialization; +using System.Runtime.InteropServices; namespace Crow -{ +{ + [StructLayout(LayoutKind.Sequential)] public struct Rectangle { internal static Type TRectangle = typeof(Rectangle); - #region private fields - int _x; - int _y; - int _width; - int _height; - #endregion + + public int X; + public int Y; + public int Width; + public int Height; #region ctor - public Rectangle(Point p, Size s) - { - _x = p.X; - _y = p.Y; - _width = s.Width; - _height = s.Height; - } - public Rectangle(Size s) + public Rectangle(Point p, Size s): this (p.X, p.Y, s.Width, s.Height) + { + } + public Rectangle(Size s) : this (0, 0, s.Width, s.Height) { - _x = 0; - _y = 0; - _width = s.Width; - _height = s.Height; } public Rectangle(int x, int y, int width, int height) { - _x = x; - _y = y; - _width = width; - _height = height; + X = x; + Y = y; + Width = width; + Height = height; } #endregion #region PROPERTIES - [XmlIgnore]public int X{ - get { return _x; } - set { _x = value; } - } - [XmlIgnore]public int Y{ - get { return _y; } - set { _y = value; } - } [XmlIgnore]public int Left{ - get { return _x; } - set { _x = value; } + get { return X; } + set { X = value; } } [XmlIgnore]public int Top{ - get { return _y; } - set { _y = value; } + get { return Y; } + set { Y = value; } } [XmlIgnore]public int Right{ - get { return _x + _width; } + get { return X + Width; } } [XmlIgnore]public int Bottom{ - get { return _y + _height; } - } - [XmlIgnore]public int Width{ - get { return _width; } - set { _width = value; } - } - [XmlIgnore]public int Height{ - get { return _height; } - set { _height = value; } + get { return Y + Height; } } [XmlIgnore]public Size Size{ get { return new Size(Width, Height); } @@ -253,10 +230,10 @@ namespace Crow { int hash = 17; // Suitable nullity checks etc, of course :) - hash = hash * 23 + _x.GetHashCode(); - hash = hash * 23 + _y.GetHashCode(); - hash = hash * 23 + _width.GetHashCode(); - hash = hash * 23 + _height.GetHashCode(); + hash = hash * 23 + X.GetHashCode(); + hash = hash * 23 + Y.GetHashCode(); + hash = hash * 23 + Width.GetHashCode(); + hash = hash * 23 + Height.GetHashCode(); return hash; } } diff --git a/src/Rectangles.cs b/src/Rectangles.cs deleted file mode 100644 index 7310290d..00000000 --- a/src/Rectangles.cs +++ /dev/null @@ -1,137 +0,0 @@ -// -// Rectangles.cs -// -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2013-2017 Jean-Philippe Bruyère -// -// 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; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Cairo; -using System.Diagnostics; - -namespace Crow -{ - public class Rectangles - { - public List list = new List(); - public int count - { - get { return list.Count; } - } - - public void AddRectangle(Rectangle r) - { - if (doesNotContain (r)) { - list.Add (r); - boundsUpToDate = false; - } - } - public void Reset() - { - list = new List(); - _bounds = Rectangle.Empty; - boundsUpToDate = true; - } - bool doesNotContain(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 void stroke(Context ctx, Color c) - { - foreach (Rectangle r in list) - ctx.Rectangle(r); - - ctx.SetSourceColor(c); - - ctx.LineWidth = 2; - ctx.Stroke (); - } - public void clearAndClip(Context ctx) - { - if (list.Count == 0) - return; - foreach (Rectangle r in list) - ctx.Rectangle(r); - - ctx.ClipPreserve(); - ctx.Operator = Operator.Clear; - 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) { - if (list.Count > 0) { - _bounds = list [0]; - for (int i = 1; i < list.Count; i++) { - _bounds += list [i]; - } - } else - _bounds = Rectangle.Empty; - boundsUpToDate = true; - } - return _bounds; - } - } - public void clear(Context ctx) - { - foreach (Rectangle r in list) - ctx.Rectangle(r); - ctx.Operator = Operator.Clear; - ctx.Fill(); - ctx.Operator = Operator.Over; - } - public override string ToString () - { - string tmp = ""; - foreach (Rectangle r in list) { - tmp += r.ToString (); - } - return tmp; - } - } -} diff --git a/src/XCursor.cs b/src/XCursor.cs index 0d7c244e..627e2afd 100644 --- a/src/XCursor.cs +++ b/src/XCursor.cs @@ -27,7 +27,6 @@ using System; using System.IO; using System.Diagnostics; -using OpenTK; using System.Collections.Generic; namespace Crow