<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>
<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" />
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
{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
<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" />
<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" />
namespace Crow
{
- public class Container : PrivateContainer, IXmlSerializable
+ public class Container : PrivateContainer
{
#region CTOR
public Container()
{
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
}
}
namespace Crow
{
- public class GraphicObject : IXmlSerializable, ILayoutable, IValueChange, ICloneable
+ public class GraphicObject : ILayoutable, IValueChange
{
internal static ulong currentUid = 0;
internal ulong uid = 0;
}
}
- Rectangles clipping = new Rectangles();
- public Rectangles Clipping { get { return clipping; }}
+ public Region Clipping;
#region IValueChange implementation
public event EventHandler<ValueChangeEventArgs> ValueChanged;
#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;
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;
Rectangle rBack = new Rectangle (Slot.Size);
Background.SetAsSource (gr, rBack);
- CairoHelpers.CairoRectangle(gr,rBack,cornerRadius);
+ CairoHelpers.CairoRectangle (gr, rBack, cornerRadius);
gr.Fill ();
}
}
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>
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 ()
{
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()
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);
}
}
ctx.SetSourceSurface (bmp, rb.X, rb.Y);
ctx.Paint ();
- Clipping.Reset();
+ Clipping.Dispose();
+ Clipping = new Region ();
}
#endregion
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
-
}
}
using System;
using System.Xml.Serialization;
using System.ComponentModel;
-using OpenTK.Input;
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);
}
ctx.SetSourceSurface (bmp, rb.X, rb.Y);
ctx.Paint ();
+ Clipping.Dispose();
+ Clipping = new Region ();
}
#endregion
using System;
using System.Xml.Serialization;
using System.ComponentModel;
-using OpenTK.Input;
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
}
}
namespace Crow
{
- public abstract class TemplatedControl : PrivateContainer, IXmlSerializable
+ public abstract class TemplatedControl : PrivateContainer
{
#region CTOR
public TemplatedControl () : base()
}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
}
}
// }
#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> ();
// THE SOFTWARE.
using System;
-namespace OpenTK.Input
+namespace Crow
{
/// <summary>
/// Enumerates available buttons for a <c>GamePad</c> device.
[Flags]
public enum KeyModifiers : byte
{
+ None = 0,
/// <summary>
/// The alt key modifier (option on Mac).
/// </summary>
/// <summary>
/// The shift key modifier.
/// </summary>
- Shift = 1 << 2
+ Shift = 1 << 2,
+
+ /// <summary>
+ /// The shift key modifier.
+ /// </summary>
+ AltGr = 1 << 3
}
}
#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
/// <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>
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;
#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 ();
}
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);
((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");
}
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);
}
}
#region ILayoutable implementation
public void RegisterClip(Rectangle r){
- clipping.AddRectangle (r);
+ clipping.UnionRectangle (r);
}
public bool ArrangeChildren { get { return false; }}
public int LayoutingTries {
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(){
minimum = long.MaxValue;
}
void onResetClick(object sender, MouseButtonEventArgs e){
- ResetStats();
+ lock(this)
+ ResetStats();
}
}
}
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); }
{
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;
}
}
+++ /dev/null
-//
-// 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;
- }
- }
-}
using System;
using System.IO;
using System.Diagnostics;
-using OpenTK;
using System.Collections.Generic;
namespace Crow