From: jpbruyere Date: Thu, 3 Sep 2015 10:48:04 +0000 (+0200) Subject: * GOLib.sln: X-Git-Tag: 0.2~66 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=6fd66d56dd5789eae345a517dc42f3488cf7aca6;p=jp%2Fcrow.git * GOLib.sln: * GOLib.csproj: * GOLIBTest_0.cs: * GOLIBTest_fps.cs: * ReflexionExtensions.cs: * Label.cs: * test4.goml: * GenericStack.cs: * PrivateContainer.cs: * CompilerServices.cs: * Tests.csproj: * member.svg: * GOLIBTest_TypeViewer.cs: * tmpMembers.goml: * testTypeViewer.goml: Type viewer * Group.cs: * Window.cs: * GraphicObject.cs: set OnLayoutChanges to public * Point.cs: Implement length --- diff --git a/GOLib.csproj b/GOLib.csproj index 101fa57f..60f6c606 100644 --- a/GOLib.csproj +++ b/GOLib.csproj @@ -114,6 +114,7 @@ + @@ -180,5 +181,6 @@ + diff --git a/GOLib.sln b/GOLib.sln index 98b5962c..3bd7afc3 100644 --- a/GOLib.sln +++ b/GOLib.sln @@ -56,4 +56,10 @@ Global {E9E14DB5-3C67-4E01-B5C3-4D90D7E31A2E}.Nsis|Any CPU.Build.0 = Debug|Any CPU {E9E14DB5-3C67-4E01-B5C3-4D90D7E31A2E}.Release|Linux_x86.ActiveCfg = Release|Any CPU EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + Policies = $0 + $0.StandardHeader = $1 + $1.Text = @ \n ${FileName}\n \n Author:\n ${AuthorName} <${AuthorEmail}>\n\n Copyright (c) ${Year} ${CopyrightHolder}\n\n This program is free software: you can redistribute it and/or modify\n it under the terms of the GNU General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU General Public License for more details.\n\n You should have received a copy of the GNU General Public License\n along with this program. If not, see . + $1.IncludeInNewFiles = True + EndGlobalSection EndGlobal diff --git a/Images/Icons/member.svg b/Images/Icons/member.svg new file mode 100644 index 00000000..af654a94 --- /dev/null +++ b/Images/Icons/member.svg @@ -0,0 +1,93 @@ + + + + + + + + + # + + + + + + + + + + + + diff --git a/Tests/GOLIBTest_0.cs b/Tests/GOLIBTest_0.cs index d8d2a913..7ec0de99 100644 --- a/Tests/GOLIBTest_0.cs +++ b/Tests/GOLIBTest_0.cs @@ -14,7 +14,7 @@ using go; using System.Threading; -namespace test +namespace test6 { class GOLIBTest_0 : OpenTKGameWindow { diff --git a/Tests/GOLIBTest_TypeViewer.cs b/Tests/GOLIBTest_TypeViewer.cs index 347e06dc..1980f582 100644 --- a/Tests/GOLIBTest_TypeViewer.cs +++ b/Tests/GOLIBTest_TypeViewer.cs @@ -13,6 +13,7 @@ using System.Diagnostics; using go; using System.Threading; using System.Reflection; +using System.Linq; namespace test @@ -43,6 +44,7 @@ namespace test MemberInfo mi; + } [STAThread] @@ -65,7 +67,18 @@ namespace test get { return Type.Name; } } public MemberInfo[] Members { - get { return Type.GetProperties (BindingFlags.Public | BindingFlags.Instance); } + get { + MemberInfo[] mi = Properties.Cast ().Concat (Methods.Cast ()).ToArray(); + return mi; + } + } + public MethodInfo[] Methods { + get { return Type.GetMethods (BindingFlags.Public | BindingFlags.Instance).Where (m => !m.IsSpecialName).ToArray(); } } + public PropertyInfo[] Properties { + get { return Type.GetProperties (); } + } + } + } \ No newline at end of file diff --git a/Tests/GOLIBTest_fps.cs b/Tests/GOLIBTest_fps.cs index fd7ccf53..12fdf444 100644 --- a/Tests/GOLIBTest_fps.cs +++ b/Tests/GOLIBTest_fps.cs @@ -41,16 +41,6 @@ namespace test ValueChanged.Raise(this, new ValueChangeEventArgs ("fps", _fps)); } } - string name = "testName"; - - public string Name { - get { - return name; - } - set { - name = value; - } - } public int fpsMin = int.MaxValue; public int fpsMax = 0; @@ -63,6 +53,17 @@ namespace test } #endregion + string name = "testName"; + + public string Name { + get { + return name; + } + set { + name = value; + } + } + public GOLIBTest_fps () : base(600, 400,"test") {} diff --git a/Tests/Interfaces/test4.goml b/Tests/Interfaces/test4.goml index ec4251fe..0cdc2545 100755 --- a/Tests/Interfaces/test4.goml +++ b/Tests/Interfaces/test4.goml @@ -133,7 +133,7 @@ TextAlignment="Center" Background="AoEnglish"/> - + diff --git a/Tests/Interfaces/testTypeViewer.goml b/Tests/Interfaces/testTypeViewer.goml index 7cec7286..eacf4959 100755 --- a/Tests/Interfaces/testTypeViewer.goml +++ b/Tests/Interfaces/testTypeViewer.goml @@ -1,16 +1,20 @@  - + - + diff --git a/Tests/Interfaces/tmpMembers.goml b/Tests/Interfaces/tmpMembers.goml index c86f1574..9b24ae33 100755 --- a/Tests/Interfaces/tmpMembers.goml +++ b/Tests/Interfaces/tmpMembers.goml @@ -2,7 +2,8 @@ - diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 6e2973a4..1b029972 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -8,7 +8,7 @@ Exe Tests Tests - test.GOLIBTest_4 + test.GOLIBTest_Window v4.5 ..\bin\$(configuration) obj\$(configuration) diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index b1b08d5e..1aaeac99 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -4,6 +4,8 @@ using System.Reflection; using System.Collections; using System.Diagnostics; using System.Linq; +using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace go @@ -37,6 +39,10 @@ namespace go } static int dynHandleCpt = 0; + /// + /// Compile events expression in GOML attributes + /// + /// Event binding details public static void CompileEventSource(DynAttribute es) { Type srcType = es.Source.GetType (); @@ -154,6 +160,11 @@ namespace go evtFi.SetValue(es.Source, del); } + /// + /// Resolves GOML property bindings afler loading + /// + /// Binding details + /// Data source for binding public static void ResolveBinding(DynAttribute binding, object _source) { object srcGO = null; @@ -185,14 +196,28 @@ namespace go throw new Exception ("Syntax error in binding, expected 'go dot member'"); } + if (srcGO == null) { + Debug.WriteLine ("Invalid Binding Source: " + binding.Value); + return; + } Type srcType = srcGO.GetType (); Type dstType = binding.Source.GetType (); MemberInfo miSrc = srcType.GetMember (statement).FirstOrDefault (); MemberInfo miDst = dstType.GetMember (binding.MemberName).FirstOrDefault (); + object srcVal = null; //value in source member + + #region search for extensions methods if member not found in type + if (miSrc == null && !string.IsNullOrEmpty(statement)) + { + Assembly a = Assembly.GetExecutingAssembly(); + miSrc = CompilerServices.GetExtensionMethods(a, srcType).FirstOrDefault(); + } + #endregion + #region initialize target with actual value - object srcVal = null; + if (miSrc == null) srcVal = srcGO;//if no member is provided for binding, source raw value is taken else { @@ -200,7 +225,13 @@ namespace go srcVal = (miSrc as PropertyInfo).GetGetMethod ().Invoke (srcGO, null); else if (miSrc.MemberType == MemberTypes.Field) srcVal = (miSrc as FieldInfo).GetValue (srcGO); - else + else if (miSrc.MemberType == MemberTypes.Method){ + MethodInfo mthSrc = miSrc as MethodInfo; + if (mthSrc.IsDefined(typeof(ExtensionAttribute), false)) + srcVal = mthSrc.Invoke(null, new object[] {srcGO}); + else + srcVal = mthSrc.Invoke(srcGO, null); + }else throw new Exception ("unandled source member type for binding"); } if (miDst.MemberType == MemberTypes.Property) { @@ -363,6 +394,36 @@ namespace go } while(fi == null); return fi; } + + /// + /// Gets extension methods defined in assembley for extendedType + /// + /// Extension methods enumerable + /// Assembly + /// Extended type to search for + public static IEnumerable GetExtensionMethods(Assembly assembly, + Type extendedType) + { + IEnumerable query = null; + Type curType = extendedType; + + do { + query = from type in assembly.GetTypes () + where type.IsSealed && !type.IsGenericType && !type.IsNested + from method in type.GetMethods (BindingFlags.Static + | BindingFlags.Public | BindingFlags.NonPublic) + where method.IsDefined (typeof(ExtensionAttribute), false) + where method.GetParameters () [0].ParameterType == curType + select method; + + if (query.Count() > 0) + break; + + curType = curType.BaseType; + } while (curType != null); + + return query; + } } } diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 3b96d548..20130576 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -125,13 +125,13 @@ namespace go else if (gobjs.Length == 1) { int sz = Children.Where(ch=>ch.Visible).Except (gobjs).Sum (g => g.Slot.Width); if (sz < Slot.Width) { - gobjs [0].Slot.Width = Slot.Width - sz - Spacing; + gobjs [0].Slot.Width = Slot.Width - sz - (Children.Count+1) * Spacing; int idx = Children.IndexOf (gobjs [0]); if (idx > 0 && idx < Children.Count - 1) gobjs [0].Slot.Width -= Spacing; - if (gobjs [0].LastSlots.Width != gobjs [0].Slot.Width) { gobjs [0].bmp = null; + //gobjs [0].OnLayoutChanges (LayoutingType.Width); gobjs [0].LastSlots.Width = gobjs [0].Slot.Width; } } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 457a6016..e1e2963b 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -456,7 +456,7 @@ namespace go } /// trigger dependant sizing component update - protected virtual void OnLayoutChanges(LayoutingType layoutType) + public virtual void OnLayoutChanges(LayoutingType layoutType) { if (Parent==null) return; diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index aac566db..e7a4b2b6 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -120,7 +120,7 @@ namespace go return tmp; } - protected override void OnLayoutChanges (LayoutingType layoutType) + public override void OnLayoutChanges (LayoutingType layoutType) { base.OnLayoutChanges (layoutType); diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index e9951862..c0bfe47e 100755 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -202,7 +202,9 @@ namespace go lines [selectionEnd.Y].Substring (selectionEnd.X, lines [selectionEnd.Y].Length - selectionEnd.X); l++; for (int c = 0; c < linesToRemove-1; c++) - lines.RemoveAt (l); + lines.RemoveAt (l); + currentCol = selectionStart.X; + currentLine = selectionStart.Y; } else lines [l] = lines [l].Remove (selectionStart.X, selectionEnd.X - selectionStart.X); currentCol = selectionStart.X; diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index cd234d62..025934f9 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -92,7 +92,7 @@ namespace go return child == null ? Bounds.Size : new Size(child.Slot.Width + 2 * Margin, child.Slot.Height + 2 * (Margin)); } - protected override void OnLayoutChanges (LayoutingType layoutType) + public override void OnLayoutChanges (LayoutingType layoutType) { switch (layoutType) { case LayoutingType.Width: diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index 7eb910cc..0fd2b780 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -36,8 +36,19 @@ namespace go void Window_MouseMove (object sender, OpenTK.Input.MouseMoveEventArgs e) { + +// if ((e.Position - this.Slot.TopLeft).Length < 3) +// System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.SizeNWSE; +// else +// System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; + if (!e.Mouse.IsButtonDown (MouseButton.Left)) return; + + // + + System.Windows.Forms.Cursor.Show();// = System.Windows.Forms.Cursors.SizeAll; + this.TopContainer.redrawClip.AddRectangle (this.ScreenCoordinates(this.Slot)); this.Left += e.XDelta; this.Top += e.YDelta; diff --git a/src/Point.cs b/src/Point.cs index db06a05b..58305f00 100755 --- a/src/Point.cs +++ b/src/Point.cs @@ -26,6 +26,9 @@ namespace go _y = y; } + public int Length { + get { return (int)Math.Sqrt (Math.Pow (_x, 2) + Math.Pow (_y, 2)); } + } public static implicit operator Cairo.Point(Point p) { return new Cairo.Point(p.X, p.Y); diff --git a/src/ReflexionExtensions.cs b/src/ReflexionExtensions.cs new file mode 100644 index 00000000..fc16c9d4 --- /dev/null +++ b/src/ReflexionExtensions.cs @@ -0,0 +1,56 @@ +// +// ReflexionExtensions.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2015 jp +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using System.Reflection; + +namespace go +{ + public static class ReflexionExtensions + { + public static string GetIcon(this MemberInfo mi) + { + switch (mi.MemberType) { + case MemberTypes.Constructor: + return "ctor"; + case MemberTypes.Event: + return "event"; + case MemberTypes.Field: + return "field"; + case MemberTypes.Method: + return "method"; + case MemberTypes.Property: + return "property"; + case MemberTypes.TypeInfo: + break; + case MemberTypes.Custom: + break; + case MemberTypes.NestedType: + break; + case MemberTypes.All: + break; + default: + return "pubfld"; + } + return "notset"; + } + } +} +