diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2015-04-04 15:48:33 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2015-04-04 15:48:33 +0200 |
| commit | 7249a058b2e41a33b7b72c57fb63d716326cc01f (patch) | |
| tree | 9673532aff58cc4e93919b897e153688aaaef970 /src/GraphicObjects | |
| parent | 30baf7a73449a5a0b5c6ea7f3952d4d614ec741f (diff) | |
* MyClass.cs:
* Key.cs:
* GOLibView.cs:
* GOLibGtkHost.cs:
* Buttons.cs:
* DisplayBinding.cs:
* MouseState.cs:
* AddinInfo.cs:
* MonoDevelop.GOLib.csproj:
* GOLibNodeExtension.cs:
* AssemblyInfo.cs:
* MouseEventArgs.cs:
* MonoDevelop.GOLib.addin.xml:
* KeyboardKeyEventArgs.cs: Monodevelop GOLib Addin
* Tests.csproj:
* test4.xml:
* test3.xml:
* test1.xml:
* test0.xml:
* test5.xml:
* test5.goml:
* test4.goml:
* test3.goml:
* test1.goml:
* test0.goml: change xml to goml extension
* GOLibHost.cs: Generalization for GOLib host application
* OpenTKGameWindow.cs:
* Button.cs:
* Scroller.cs:
* IGOLibHost.cs:
* ILayoutable.cs:
* GraphicObject.cs: Top container + IGOLibHost interface for multiple
application container implementation
* GOLib.sln:
* GOLib.csproj: MD GOLib addin
Diffstat (limited to 'src/GraphicObjects')
| -rwxr-xr-x | src/GraphicObjects/Button.cs | 2 | ||||
| -rwxr-xr-x | src/GraphicObjects/GraphicObject.cs | 86 | ||||
| -rw-r--r-- | src/GraphicObjects/IGOLibHost.cs | 17 | ||||
| -rw-r--r-- | src/GraphicObjects/ILayoutable.cs | 2 | ||||
| -rw-r--r-- | src/GraphicObjects/Scroller.cs | 2 |
5 files changed, 94 insertions, 15 deletions
diff --git a/src/GraphicObjects/Button.cs b/src/GraphicObjects/Button.cs index c0c12565..e4987fda 100755 --- a/src/GraphicObjects/Button.cs +++ b/src/GraphicObjects/Button.cs @@ -13,7 +13,7 @@ using System.ComponentModel; namespace go
{
- public class Button : Container
+ public class Button : Container, IXmlSerializable
{
#region CTOR
public Button() : base()
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 935729f2..86cb3009 100755 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -14,6 +14,8 @@ using System.Xml.Serialization; using System.Reflection;
using System.ComponentModel;
using System.IO;
+//using System.Xml;
+using System.Xml;
namespace go
{
@@ -52,6 +54,8 @@ namespace go bool yIsValid = false;
#endregion
+ public static bool DesignerMode = false;
+
#region public fields
public Rectangle Bounds;
public Rectangle Slot = new Rectangle ();
@@ -114,7 +118,7 @@ namespace go return cb;
}
}
- [XmlIgnore]public virtual OpenTKGameWindow TopContainer {
+ [XmlIgnore]public virtual IGOLibHost TopContainer {
get { return Parent.TopContainer; }
}
public virtual void InvalidateLayout ()
@@ -242,7 +246,7 @@ namespace go }
[XmlAttributeAttribute()][DefaultValue(false)]
public virtual bool Focusable {
- get { return _focusable; }
+ get { return _focusable | DesignerMode; }
set { _focusable = value; }
}
[XmlAttributeAttribute()][DefaultValue("Transparent")]
@@ -287,11 +291,11 @@ namespace go _isVisible = value;
//add slot to clipping to redraw
- OpenTKGameWindow.gobjsToRedraw.Add (this);
+ TopContainer.gobjsToRedraw.Add (this);
//ensure main win doesn't keep hidden childrens ref
- if (this.Contains (OpenTKGameWindow.currentWindow.hoverWidget))
- OpenTKGameWindow.currentWindow.hoverWidget = null;
+ if (this.Contains (TopContainer.hoverWidget))
+ TopContainer.hoverWidget = null;
// if (Parent != null)
// Parent.InvalidateLayout ();
//else
@@ -380,11 +384,11 @@ namespace go public virtual void registerForRedraw ()
{
if (LayoutIsValid && Visible)
- OpenTKGameWindow.gobjsToRedraw.Add (this);
+ TopContainer.gobjsToRedraw.Add (this);
}
public virtual void registerClipRect()
{
- OpenTKGameWindow.redrawClip.AddRectangle (ScreenCoordinates(Slot));
+ TopContainer.redrawClip.AddRectangle (ScreenCoordinates(Slot));
}
protected virtual Size measureRawSize ()
{
@@ -536,10 +540,10 @@ namespace go }
public virtual void onMouseMove(object sender, MouseMoveEventArgs e)
{
- OpenTKGameWindow w = sender as OpenTKGameWindow;
+ //ILayoutable w = sender as ILayoutable;
- if (w.hoverWidget != this) {
- w.hoverWidget = this;
+ if (TopContainer.hoverWidget != this) {
+ TopContainer.hoverWidget = this;
onMouseEnter (sender, e);
}
@@ -552,7 +556,7 @@ namespace go MouseButtonUp (this, e);
}
public virtual void onMouseButtonDown(object sender, MouseButtonEventArgs e){
- (sender as OpenTKGameWindow).FocusedWidget = this;
+ TopContainer.FocusedWidget = this;
MouseButtonDown (this, e);
}
@@ -601,7 +605,25 @@ namespace go {
xs.Serialize(s, graphicObject, xn);
}
- }
+ }
+ public static GraphicObject Load(string path)
+ {
+ string root = "Object";
+ using (Stream s = new FileStream (path, FileMode.Open)) {
+ using (XmlReader reader = XmlReader.Create (s)) {
+ while (reader.Read()) {
+ // first element is the root element
+ if (reader.NodeType == XmlNodeType.Element) {
+ root = reader.Name;
+ break;
+ }
+ }
+ }
+ }
+ Type t = Type.GetType("go." + root);
+ var go = Activator.CreateInstance(t);
+ return Load(path, t);
+ }
public static void Load<T>(string file, out T result, object ClassContainingHandlers = null)
{
EventsToResolve = new List<EventSource>();
@@ -639,7 +661,47 @@ namespace go fi.SetValue(es.Source, del);
}
}
+ }
+
+ public static GraphicObject Load(string file, Type type, object ClassContainingHandlers = null)
+ {
+ GraphicObject result;
+ EventsToResolve = new List<EventSource>();
+
+ XmlSerializerNamespaces xn = new XmlSerializerNamespaces();
+ xn.Add("", "");
+ XmlSerializer xs = new XmlSerializer(type);
+
+ using (Stream s = new FileStream(file, FileMode.Open))
+ {
+ result = (GraphicObject)xs.Deserialize(s);
+ }
+
+ if (ClassContainingHandlers == null)
+ return result;
+
+ foreach (EventSource es in EventsToResolve)
+ {
+ if (string.IsNullOrEmpty(es.Handler))
+ continue;
+
+ if (es.Handler.StartsWith ("{")) {
+ CompilerServices.CompileEventSource (es);
+ } else {
+ MethodInfo mi = ClassContainingHandlers.GetType ().GetMethod (es.Handler, BindingFlags.NonPublic | BindingFlags.Public
+ | BindingFlags.Instance);
+ if (mi == null) {
+ Debug.WriteLine ("Handler Method not found: " + es.Handler);
+ continue;
+ }
+
+ FieldInfo fi = CompilerServices.getEventHandlerField (es.Source.GetType (), es.EventName);
+ Delegate del = Delegate.CreateDelegate(fi.FieldType, ClassContainingHandlers, mi);
+ fi.SetValue(es.Source, del);
+ }
+ }
+ return result;
}
#endregion
diff --git a/src/GraphicObjects/IGOLibHost.cs b/src/GraphicObjects/IGOLibHost.cs new file mode 100644 index 00000000..7a422877 --- /dev/null +++ b/src/GraphicObjects/IGOLibHost.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; + +namespace go +{ + public interface IGOLibHost + { + Rectangles redrawClip { get; set; } + List<GraphicObject> gobjsToRedraw { get; } + GraphicObject activeWidget { get; set; } + GraphicObject hoverWidget { get; set; } + GraphicObject FocusedWidget { get; set; } + void AddWidget (GraphicObject g); + void DeleteWidget(GraphicObject g); + } +} + diff --git a/src/GraphicObjects/ILayoutable.cs b/src/GraphicObjects/ILayoutable.cs index 579fe2b0..1107f825 100644 --- a/src/GraphicObjects/ILayoutable.cs +++ b/src/GraphicObjects/ILayoutable.cs @@ -18,7 +18,7 @@ namespace go Rectangle getSlot(); Rectangle getBounds(); - OpenTKGameWindow TopContainer { get; } + IGOLibHost TopContainer { get; } void InvalidateLayout (); diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs index b24eb784..3d952fd0 100644 --- a/src/GraphicObjects/Scroller.cs +++ b/src/GraphicObjects/Scroller.cs @@ -115,7 +115,7 @@ namespace go public override void registerClipRect ()
{
- OpenTKGameWindow.redrawClip.AddRectangle (base.ScreenCoordinates(Slot));
+ TopContainer.redrawClip.AddRectangle (base.ScreenCoordinates(Slot));
}
public override void UpdateLayout ()
{
|