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 | |
| 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')
| -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 | ||||
| -rwxr-xr-x | src/OpenTKGameWindow.cs | 136 |
6 files changed, 167 insertions, 78 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 ()
{
diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index 1e937545..1e5b5d86 100755 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -17,12 +17,14 @@ using System.Threading; using System.Drawing.Imaging;
//using System.Xml.Serialization;
//using System.Reflection;
+using System.Xml;
+using System.IO;
namespace go
{
- public class OpenTKGameWindow : GameWindow, ILayoutable
+ public class OpenTKGameWindow : GameWindow, ILayoutable, IGOLibHost
{
#region ctor
// public OpenTKGameWindow(int _width, int _height, string _title="golib")
@@ -50,10 +52,39 @@ namespace go public List<GraphicObject> GraphicObjects = new List<GraphicObject>();
public Color Background = Color.Transparent;
- public static Rectangles redrawClip = new Rectangles();//should find another way to access it from child
- public static List<GraphicObject> gobjsToRedraw = new List<GraphicObject>();
internal static OpenTKGameWindow currentWindow;
+ Rectangles _redrawClip = new Rectangles();//should find another way to access it from child
+ List<GraphicObject> _gobjsToRedraw = new List<GraphicObject>();
+
+ public Rectangles redrawClip {
+ get {
+ return _redrawClip;
+ }
+ set {
+ _redrawClip = value;
+ }
+ }
+
+ public List<GraphicObject> gobjsToRedraw {
+ get {
+ return _gobjsToRedraw;
+ }
+ set {
+ _gobjsToRedraw = value;
+ }
+ }
+ public void AddWidget(GraphicObject g)
+ {
+ g.Parent = this;
+ GraphicObjects.Add (g);
+ }
+ public void DeleteWidget(GraphicObject g)
+ {
+ g.Visible = false;//trick to ensure clip is added to refresh zone
+ GraphicObjects.Remove (g);
+ }
+
#region Events
//those events are raised only if mouse isn't in a graphic object
public event EventHandler<MouseWheelEventArgs> MouseWheelChanged = delegate { };
@@ -266,17 +297,7 @@ namespace go // updateTime.ElapsedMilliseconds);
}
-
- public void AddWidget(GraphicObject g)
- {
- g.Parent = this;
- GraphicObjects.Add (g);
- }
- public void DeleteWidget(GraphicObject g)
- {
- g.Visible = false;//ensure clip is added to refresh zone
- GraphicObjects.Remove (g);
- }
+
public void LoadInterface<T>(string path, out T result)
{
GraphicObject.Load<T> (path, out result, this);
@@ -289,7 +310,7 @@ namespace go AddWidget (result as GraphicObject);
return result;
}
-
+
#region Game win overrides
protected override void OnUpdateFrame(FrameEventArgs e)
{
@@ -434,14 +455,12 @@ namespace go }
#endregion
-
#region ILayoutable implementation
public Rectangle ContextCoordinates (Rectangle r)
{
return r;
}
-
public Rectangle ScreenCoordinates (Rectangle r)
{
return r;
@@ -460,7 +479,6 @@ namespace go get { return true; }
set { throw new NotImplementedException (); }
}
-
public bool PositionIsValid {
get {
return true;
@@ -469,7 +487,6 @@ namespace go throw new NotImplementedException ();
}
}
-
public bool LayoutIsValid {
get {
return true;//tester tout les enfants a mon avis
@@ -483,7 +500,7 @@ namespace go get { return new Size(this.ClientRectangle.Size.Width,this.ClientRectangle.Size.Height); }
}
- public OpenTKGameWindow TopContainer {
+ public IGOLibHost TopContainer {
get { return this; }
}
@@ -495,6 +512,7 @@ namespace go {
return ClientRectangle;
}
+
public bool WIsValid {
get {
return true;
@@ -503,7 +521,6 @@ namespace go throw new NotImplementedException ();
}
}
-
public bool HIsValid {
get {
return true;
@@ -512,7 +529,6 @@ namespace go throw new NotImplementedException ();
}
}
-
public bool XIsValid {
get {
return true;
@@ -521,7 +537,6 @@ namespace go throw new NotImplementedException ();
}
}
-
public bool YIsValid {
get {
return true;
@@ -530,52 +545,47 @@ namespace go throw new NotImplementedException ();
}
}
+
public virtual void InvalidateLayout ()
{
// foreach (GraphicObject g in GraphicObjects) {
// g.InvalidateLayout ();
// }
}
- public Rectangle rectInScreenCoord (Rectangle r)
- {
- throw new NotImplementedException ();
- }
-
- public Rectangle renderBoundsInContextCoordonate {
- get { return ClientRectangle; }
- }
-
- public Rectangle ClientBoundsInContextCoordonate {
- get {
- throw new NotImplementedException ();
- }
- }
-
- public Rectangle renderBoundsInBackendSurfaceCoordonate {
- get { return ClientRectangle; }
- }
-
- public Rectangle ClientBoundsInBackendSurfaceCoordonate {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
-
- public Rectangle ScreenCoordBounds {
- get { return ClientRectangle; }
- }
-
- public Rectangle ScreenCoordClientBounds {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
+// public Rectangle rectInScreenCoord (Rectangle r)
+// {
+// throw new NotImplementedException ();
+// }
+// public Rectangle renderBoundsInContextCoordonate {
+// get { return ClientRectangle; }
+// }
+// public Rectangle ClientBoundsInContextCoordonate {
+// get {
+// throw new NotImplementedException ();
+// }
+// }
+// public Rectangle renderBoundsInBackendSurfaceCoordonate {
+// get { return ClientRectangle; }
+// }
+// public Rectangle ClientBoundsInBackendSurfaceCoordonate {
+// get {
+// throw new NotImplementedException ();
+// }
+// set {
+// throw new NotImplementedException ();
+// }
+// }
+// public Rectangle ScreenCoordBounds {
+// get { return ClientRectangle; }
+// }
+// public Rectangle ScreenCoordClientBounds {
+// get {
+// throw new NotImplementedException ();
+// }
+// set {
+// throw new NotImplementedException ();
+// }
+// }
#endregion
}
}
\ No newline at end of file |