]> O.S.I.I.S - jp/crow.git/commitdiff
cairo.region to handle clipping, native pointer leaking...
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 13 Aug 2017 17:11:00 +0000 (19:11 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 13 Aug 2017 17:11:00 +0000 (19:11 +0200)
19 files changed:
Crow.csproj
Crow.sln
Tests/Tests.csproj
src/GraphicObjects/Container.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/Popper.cs
src/GraphicObjects/PrivateContainer.cs
src/GraphicObjects/ScrollBar.cs
src/GraphicObjects/TemplatedContainer.cs
src/GraphicObjects/TemplatedControl.cs
src/GraphicObjects/TemplatedGroup.cs
src/Input/Buttons.cs
src/Input/KeyModifiers.cs
src/Interface.cs
src/PerformanceMeasure.cs
src/Rectangle.cs
src/Rectangles.cs [deleted file]
src/XCursor.cs

index e5395a0623b57b3b01a0243b3f6b5c16cad7a9ed..29bcd8e0462f46307a31407f86fdf50fd1611a80 100644 (file)
@@ -23,6 +23,8 @@
     <OutputPath>$(SolutionDir)build\$(Configuration)</OutputPath>
     <IntermediateOutputPath>$(SolutionDir)build\obj\$(Configuration)</IntermediateOutputPath>
     <AssemblyOriginatorKeyFile>crow.key</AssemblyOriginatorKeyFile>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -39,7 +41,6 @@
     <Compile Include="src\Colors.cs" />
     <Compile Include="src\Point.cs" />
     <Compile Include="src\Rectangle.cs" />
-    <Compile Include="src\Rectangles.cs" />
     <Compile Include="src\Size.cs" />
     <Compile Include="src\GraphicObjects\GraphicObject.cs" />
     <Compile Include="src\GraphicObjects\Container.cs" />
index ba1b6741b6a2d5bc901c956b1837cf9c96a33e1a..83e55eb5e132a7321a844503c009150f823d580e 100644 (file)
--- 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
index 362fb9a648ec9ffc838267256e42dec1e9eb6da4..2adcdb16b88ff81baa386c3c2c99f0d7894d731f 100644 (file)
     <WarningLevel>4</WarningLevel>
     <ConsolePause>false</ConsolePause>
     <DefineConstants>DEBUG;TRACE;MEASURE_TIME</DefineConstants>
+    <IntermediateOutputPath>$(SolutionDir)build\obj\$(Configuration)</IntermediateOutputPath>
+    <OutputPath>$(SolutionDir)build\$(Configuration)</OutputPath>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>none</DebugType>
     <Optimize>true</Optimize>
     <WarningLevel>0</WarningLevel>
     <ConsolePause>false</ConsolePause>
+    <IntermediateOutputPath>$(SolutionDir)build\obj\$(Configuration)</IntermediateOutputPath>
+    <OutputPath>$(SolutionDir)build\$(Configuration)</OutputPath>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
@@ -42,7 +46,6 @@
     <Reference Include="System.Drawing" />
     <Reference Include="OpenTK">
       <HintPath>$(SolutionDir)packages\OpenTK.2.0.0\lib\net20\OpenTK.dll</HintPath>
-      <Package>opentk</Package>
     </Reference>
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
index aac3594607ebe21b2f983bccfaa7bf1204f27cc1..df14b8e213104c99a2340e5ddbfe97aa39b498f5 100644 (file)
@@ -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
        }
 }
 
index 284e4877ff29d90dc2a3fe2ef429dc3363c796d5..41738802701ade171c2351652aedd9b3dc719ceb 100644 (file)
@@ -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 ()
                {
index de6d3e40dc059ddf26eb5763239013d5396c4a70..f3c357d2ecf63e1f4d373c7b12106bc580c41154 100644 (file)
@@ -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
-
        }
 }
index d3f2e7c829d4391235441153164be048aa342dfd..0e5364d6c8ca56809639ce38773c1ebedd596c70 100644 (file)
@@ -27,7 +27,6 @@
 using System;
 using System.Xml.Serialization;
 using System.ComponentModel;
-using OpenTK.Input;
 
 namespace Crow
 {
index d018bd77b1c58ed50e068ee1f8e80278f5925984..02e251bea1bbdecb4bfbd0ca776cfdec310d1dd4 100644 (file)
@@ -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
 
index 91ce50efbca214155c64d6d2924d8b8ced6ce355..ca258aaed821cf2627a0d4124331fe4f24a5cc6c 100644 (file)
@@ -27,7 +27,6 @@
 using System;
 using System.Xml.Serialization;
 using System.ComponentModel;
-using OpenTK.Input;
 
 namespace Crow
 {
index 1ab8cf7db158aa3741589350d915d73c3da2cd66..b8a321670c75bb07171d9dac561bdd3543f1c67d 100644 (file)
@@ -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
        }
 }
 
index 082d04269ae2f320de23b7157193790533c68ca4..0461a8eedf8a5bcb69cecca65a6d8946fd392073 100644 (file)
@@ -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
        }
 }
 
index e444716870bcd5a257bcc490fc417804765f92f3..eea3a18477393d31ae20eb6fbb36b3054bb65d61 100644 (file)
@@ -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> ();
index a80f5040b3093b30988c0740468247634eb7c251..ebf3bc42f4ef0654e109daeace5bbafd4de80a96 100644 (file)
@@ -25,7 +25,7 @@
 // THE SOFTWARE.
 using System;
 
-namespace OpenTK.Input
+namespace Crow
 {
     /// <summary>
     /// Enumerates available buttons for a <c>GamePad</c> device.
index 1314e7374c3fa640a9868788dd52c759d46397ce..885365ca91a20ebc405e189c366425235f63006b 100644 (file)
@@ -39,6 +39,7 @@ namespace Crow
     [Flags]
     public enum KeyModifiers : byte
     {
+       None = 0,
        /// <summary>
        /// The alt key modifier (option on Mac).
        /// </summary>
@@ -52,6 +53,11 @@ namespace Crow
        /// <summary>
        /// The shift key modifier.
        /// </summary>
-       Shift = 1 << 2
+       Shift = 1 << 2,
+
+       /// <summary>
+       /// The shift key modifier.
+       /// </summary>
+       AltGr = 1 << 3
     }
 }
index 8439c31ea64f0caa04ad901ba74bb334f94de447..adcb283095acb695be13207dd1427b9c7488fcb5 100644 (file)
@@ -110,6 +110,14 @@ namespace Crow
                #region Events
                public event EventHandler<MouseCursorChangedEventArgs> MouseCursorChanged;
                public event EventHandler Quit;
+
+               public event EventHandler<MouseWheelEventArgs> MouseWheelChanged;
+               public event EventHandler<MouseButtonEventArgs> MouseButtonUp;
+               public event EventHandler<MouseButtonEventArgs> MouseButtonDown;
+               public event EventHandler<MouseButtonEventArgs> MouseClick;
+               public event EventHandler<MouseMoveEventArgs> MouseMove;
+               public event EventHandler<KeyboardKeyEventArgs> KeyboardKeyDown;
+               public event EventHandler<KeyboardKeyEventArgs> KeyboardKeyUp;
                #endregion
 
                #region Public Fields
@@ -152,7 +160,7 @@ namespace Crow
                /// <summary>Client rectangle in the host context</summary>
                Rectangle clientRectangle;
                /// <summary>Clipping rectangles on the root context</summary>
-               Rectangles clipping = new Rectangles();
+               Region clipping = new Region();
                /// <summary>Main Cairo context</summary>
                Context ctx;
                /// <summary>Main Cairo surface</summary>
@@ -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 {
index 1db29e30484630a9e0f9fd2519fbb76259cc7e29..3c978e8b473e379353b63c7aee19e80300eca9f1 100644 (file)
@@ -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();
                }
        }
 }
index 574dc3c4ea08f566448eaa22cbf97b40dd982ee0..8f48d06d81c9fabc2bcd301760387d55ae51da31 100644 (file)
@@ -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 (file)
index 7310290..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-//
-// Rectangles.cs
-//
-// Author:
-//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// 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<Rectangle> list = new List<Rectangle>();
-        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<Rectangle>();
-                       _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;
-               }
-    }
-}
index 0d7c244eca6f2986fd07a8027a9621e237f5096c..627e2afdd473aa1cd70bc0580537b3a99fc3672c 100644 (file)
@@ -27,7 +27,6 @@
 using System;
 using System.IO;
 using System.Diagnostics;
-using OpenTK;
 using System.Collections.Generic;
 
 namespace Crow