<Reference Include="System.Data" />\r
<Reference Include="System.Drawing" />\r
<Reference Include="System.Xml" />\r
- <Reference Include="rsvg2-sharp, Version=2.18.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">\r
- <Package>rsvg2-sharp-2.0</Package>\r
- </Reference>\r
<Reference Include="glib-sharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">\r
<Package>glib-sharp-3.0</Package>\r
</Reference>\r
<Reference Include="Microsoft.CSharp" />\r
- <Reference Include="Mono.Cairo" />\r
<Reference Include="OpenTK">\r
<HintPath>..\opentk\Binaries\OpenTK\Release\OpenTK.dll</HintPath>\r
</Reference>\r
+ <Reference Include="Mono.Cairo" />\r
+ <Reference Include="rsvg2-sharp, Version=2.18.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">\r
+ <Package>rsvg2-sharp-2.0</Package>\r
+ </Reference>\r
</ItemGroup>\r
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
{C2980F9B-4798-4C05-99E2-E174810F7C7B}.Release|Linux_x86.ActiveCfg = Release|Any CPU\r
{C2980F9B-4798-4C05-99E2-E174810F7C7B}.Release|Linux_x86.Build.0 = Release|Any CPU\r
{E9E14DB5-3C67-4E01-B5C3-4D90D7E31A2E}.Debug|Linux_x86.ActiveCfg = Debug|Any CPU\r
+ {E9E14DB5-3C67-4E01-B5C3-4D90D7E31A2E}.Debug|Linux_x86.Build.0 = Debug|Any CPU\r
{E9E14DB5-3C67-4E01-B5C3-4D90D7E31A2E}.Release|Linux_x86.ActiveCfg = Release|Any CPU\r
EndGlobalSection\r
GlobalSection(MonoDevelopProperties) = preSolution\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectTypeGuids>{86F6BF2A-E449-4B3E-813B-9ACC37E5545F};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{2FB6DD19-817A-476D-A99D-7750798944A6}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <RootNamespace>GOMLViewer</RootNamespace>
+ <AssemblyName>GOMLViewer</AssemblyName>
+ <MDBinDir>/usr/local/lib/monodevelop/bin</MDBinDir>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG;</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>full</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Properties\AddinInfo.cs" />
+ <Compile Include="src\DisplayBinding.cs" />
+ <Compile Include="src\GOLibGtkHost.cs" />
+ <Compile Include="src\GOLibNodeExtension.cs" />
+ <Compile Include="src\GOLibView.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Properties\Manifest.addin.xml" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <Import Project="..\packages\MonoDevelop.Addins.0.2.3\build\net40\MonoDevelop.Addins.targets" Condition="Exists('..\packages\MonoDevelop.Addins.0.2.3\build\net40\MonoDevelop.Addins.targets')" />
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\GOLib.csproj">
+ <Project>{C2980F9B-4798-4C05-99E2-E174810F7C7B}</Project>
+ <Name>GOLib</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <Reference Include="OpenTK">
+ <HintPath>..\..\opentk\Binaries\OpenTK\Release\OpenTK.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+</Project>
\ No newline at end of file
--- /dev/null
+using System;
+using Mono.Addins;
+using Mono.Addins.Description;
+
+[assembly:Addin (
+ "GOMLViewer",
+ Namespace = "GOMLViewer",
+ Version = "1.0"
+)]
+
+[assembly:AddinName ("GOMLViewer")]
+[assembly:AddinCategory ("IDE extensions")]
+[assembly:AddinDescription ("GOMLViewer")]
+[assembly:AddinAuthor ("Jean-Philippe Bruyère")]
+
--- /dev/null
+//
+// AssemblyInfo.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// 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 <http://www.gnu.org/licenses/>.
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes.
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle ("GOMLViewer")]
+[assembly: AssemblyDescription ("")]
+[assembly: AssemblyConfiguration ("")]
+[assembly: AssemblyCompany ("")]
+[assembly: AssemblyProduct ("")]
+[assembly: AssemblyCopyright ("jp")]
+[assembly: AssemblyTrademark ("")]
+[assembly: AssemblyCulture ("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion ("1.0.*")]
+
+// The following attributes are used to specify the signing key for the assembly,
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ExtensionModel>
+ <Extension path = "/MonoDevelop/Ide/DisplayBindings">
+ <DisplayBinding
+ id = "GOLib designer"
+ insertafter ="AssemblyBrowser"
+ class = "MonoDevelop.GOLib.GOLibDisplayBinding" />
+ </Extension>
+ <Extension path = "/MonoDevelop/Ide/Pads/ProjectPad">
+ <NodeBuilder id = "GOLibNodeExtension" class = "MonoDevelop.GOLib.GOLibNodeExtension"/>
+ </Extension>
+ <Extension path = "/MonoDevelop/Core/MimeTypes">
+ <MimeType id="text/x-goml" _description="GOlib interface definition" icon="md-csharp-file" isText="false">
+ <File pattern="*.goml" />
+ </MimeType>
+ </Extension>
+</ExtensionModel>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<packages>\r
+ <package id="MonoDevelop.Addins" version="0.2.3" targetFramework="net45" />\r
+</packages>
\ No newline at end of file
--- /dev/null
+//
+// DisplayBinding.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+// Copyright (c) 2015 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+//
+// DisplayBinding.cs
+//
+// Author:
+// Mike Krüger <mkrueger@novell.com>
+//
+// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
+//
+// 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.IO;
+using MonoDevelop.Core;
+using MonoDevelop.Ide.Gui;
+using MonoDevelop.Projects;
+using System.Globalization;
+using System.Diagnostics;
+
+namespace MonoDevelop.GOLib
+{
+ class GOLibDisplayBinding : IViewDisplayBinding
+ {
+ bool canHandle = false;
+
+ public string Name {
+ get {
+ return GettextCatalog.GetString ("GOLib designer");
+ }
+ }
+ public bool CanUseAsDefault
+ { get { return canHandle; } }
+
+ public IViewContent CreateContent (FilePath fileName, string mimeType, Project ownerProject)
+ {
+ return new GOLibView ();
+ }
+ public bool CanHandle (FilePath fileName, string mimeType, Project ownerProject)
+ {
+ canHandle = mimeType.StartsWith("text/x-goml");
+ return true;
+ }
+ }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using go;
+using MonoDevelop.Core;
+using MonoDevelop.Ide;
+using MonoDevelop.Projects;
+using System.Diagnostics;
+using OpenTK.Input;
+using MonoDevelop.DesignerSupport;
+
+namespace MonoDevelop.GOLib
+{
+ public class GOLibGtkHost : Gtk.DrawingArea, ILayoutable, IGOLibHost, IPropertyPadProvider
+ {
+ #region IPropertyPadProvider implementation
+
+ public object GetActiveComponent ()
+ {
+ return activeWidget;
+ }
+ public object GetProvider ()
+ {
+ return activeWidget;
+ }
+ public void OnEndEditing (object obj)
+ {
+
+ }
+ public void OnChanged (object obj)
+ {
+
+ }
+ #endregion
+
+ #region Events
+ //those events are raised only if mouse isn't in a graphic object
+ 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;
+ #endregion
+
+ string _path;
+ GraphicObject goWidget;
+
+ public GOLibGtkHost ()
+ {
+ this.Drawn += onExpose;
+ this.ButtonPressEvent += GOLibGtkHost_ButtonPressEvent;
+ this.ButtonReleaseEvent += GOLibGtkHost_ButtonReleaseEvent;
+ this.MotionNotifyEvent += GOLibGtkHost_MotionNotifyEvent;
+
+ this.Events |= Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask |
+ Gdk.EventMask.PointerMotionMask | Gdk.EventMask.PointerMotionHintMask;
+ }
+ static double[] dashed = {2.0};
+
+ void onExpose(object o, Gtk.DrawnArgs args)
+ {
+ Gtk.DrawingArea area = (Gtk.DrawingArea) o;
+
+ Cairo.Context cr = args.Cr;
+ _redrawClip.AddRectangle (this.ClientRectangle);
+ update (cr);
+
+ if (_hoverWidget != null) {
+ cr.Rectangle (_hoverWidget.ScreenCoordinates(_hoverWidget.getSlot ()));
+ cr.LineWidth = 1;
+ cr.SetDash (dashed, 0);
+ cr.Color = go.Color.Yellow;
+ cr.Stroke ();
+ }
+ ((IDisposable) cr.Target).Dispose();
+ ((IDisposable) cr).Dispose();
+ }
+ // TODO: should find a more safer way to link gtk button to otk.
+ void GOLibGtkHost_ButtonPressEvent (object o, Gtk.ButtonPressEventArgs args)
+ {
+ MouseButtonEventArgs e = new MouseButtonEventArgs
+ ((int)args.Event.X, (int)args.Event.Y,
+ gtkButtonIdToOpenTkButton(args.Event.Button), true);
+ activeWidget = hoverWidget;
+ DesignerSupport.DesignerSupport.Service.SetPadContent (this);
+ }
+ void GOLibGtkHost_ButtonReleaseEvent (object o, Gtk.ButtonReleaseEventArgs args)
+ {
+ MouseButtonEventArgs e = new MouseButtonEventArgs
+ ((int)args.Event.X, (int)args.Event.Y,
+ gtkButtonIdToOpenTkButton(args.Event.Button), false);
+ }
+ int lastX,LastY;
+ void GOLibGtkHost_MotionNotifyEvent (object o, Gtk.MotionNotifyEventArgs args)
+ {
+
+ Mouse_Move(this, new MouseMoveEventArgs (
+ (int)args.Event.X,(int)args.Event.Y,
+ (int)args.Event.X-lastX, (int)args.Event.Y-LastY
+ ));
+ lastX = (int)args.Event.X;
+ LastY = (int)args.Event.Y;
+
+ QueueDraw ();
+ }
+
+ MouseButton gtkButtonIdToOpenTkButton(uint gtkMouseButton)
+ {
+ switch (gtkMouseButton) {
+ case 1:
+ return MouseButton.Left;
+ case 2:
+ return MouseButton.Middle;
+ case 3:
+ return MouseButton.Right;
+ case 4:
+ return MouseButton.Button4;
+ case 5:
+ return MouseButton.Button5;
+ }
+ return MouseButton.LastButton;
+ }
+
+
+
+ public void Load(string path)
+ {
+ goWidget = Interface.Load (path);
+ this.AddWidget (goWidget);
+ }
+
+
+
+ public List<GraphicObject> GraphicObjects = new List<GraphicObject>();
+ public Color Background = Color.Transparent;
+
+ 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;
+ }
+ }
+
+ #region focus
+
+ GraphicObject _activeWidget; //button is pressed on widget
+ GraphicObject _hoverWidget; //mouse is over
+ GraphicObject _focusedWidget; //has keyboard (or other perif) focus
+
+ public GraphicObject activeWidget
+ {
+ get { return _activeWidget; }
+ set
+ {
+ if (_activeWidget == value)
+ return;
+
+ _activeWidget = value;
+ }
+ }
+ public GraphicObject hoverWidget
+ {
+ get { return _hoverWidget; }
+ set { _hoverWidget = value; }
+ }
+ public GraphicObject FocusedWidget {
+ get { return _focusedWidget; }
+ set {
+ if (_focusedWidget == value)
+ return;
+ if (_focusedWidget != null)
+ _focusedWidget.onUnfocused (this, null);
+ _focusedWidget = value;
+ _focusedWidget.onFocused (this, null);
+ }
+ }
+
+ #endregion
+
+ Rectangle dirtyZone = Rectangle.Empty;
+
+ #region Chrono's
+ public Stopwatch updateTime = new Stopwatch ();
+ public Stopwatch layoutTime = new Stopwatch ();
+ public Stopwatch guTime = new Stopwatch ();
+ public Stopwatch drawingTime = new Stopwatch ();
+ #endregion
+
+ #region update
+ void update (Cairo.Context ctx)
+ {
+ updateTime.Restart ();
+ layoutTime.Reset ();
+ guTime.Reset ();
+ drawingTime.Reset ();
+
+ GraphicObject[] invGOList = new GraphicObject[GraphicObjects.Count];
+ GraphicObjects.CopyTo (invGOList,0);
+ invGOList = invGOList.Reverse ().ToArray ();
+
+ //Debug.WriteLine ("======= Layouting queue start =======");
+ while (Interface.LayoutingQueue.Count > 0) {
+ LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue ();
+ lqi.ProcessLayouting ();
+ }
+
+ //Debug.WriteLine ("otd:" + gobjsToRedraw.Count.ToString () + "-");
+ //final redraw clips should be added only when layout is completed among parents,
+ //that's why it take place in a second pass
+ GraphicObject[] gotr = new GraphicObject[gobjsToRedraw.Count];
+ gobjsToRedraw.CopyTo (gotr);
+ gobjsToRedraw.Clear ();
+ foreach (GraphicObject p in gotr) {
+ p.registerClipRect ();
+ }
+
+
+ lock (redrawClip) {
+ if (redrawClip.count > 0) {
+ // #if DEBUG_CLIP_RECTANGLE
+ // redrawClip.stroke (ctx, new Color(1.0,0,0,0.3));
+ // #endif
+ redrawClip.clearAndClip (ctx);//rajouté après, tester si utile
+
+ //Link.draw (ctx);
+ foreach (GraphicObject p in invGOList) {
+ if (p.Visible) {
+ drawingTime.Start ();
+
+ ctx.Save ();
+ if (redrawClip.count > 0) {
+ Rectangles clip = redrawClip.intersectingRects (p.Slot);
+
+ if (clip.count > 0)
+ p.Paint (ref ctx, clip);
+ }
+ ctx.Restore ();
+
+ drawingTime.Stop ();
+ }
+ }
+ ctx.ResetClip ();
+ dirtyZone = redrawClip.Bounds;
+ // #if DEBUG_CLIP_RECTANGLE
+ // redrawClip.stroke (ctx, Color.Red.AdjustAlpha(0.1));
+ // #endif
+ redrawClip.Reset ();
+ }
+ }
+ //surf.WriteToPng (@"/mnt/data/test.png");
+
+ // if (ToolTip.isVisible) {
+ // ToolTip.panel.processkLayouting();
+ // if (ToolTip.panel.layoutIsValid)
+ // ToolTip.panel.Paint(ref ctx);
+ // }
+ // Debug.WriteLine("INTERFACE: layouting: {0} ticks \t graphical update {1} ticks \t drawing {2} ticks",
+ // layoutTime.ElapsedTicks,
+ // guTime.ElapsedTicks,
+ // drawingTime.ElapsedTicks);
+ // Debug.WriteLine("INTERFACE: layouting: {0} ms \t graphical update {1} ms \t drawing {2} ms",
+ // layoutTime.ElapsedMilliseconds,
+ // guTime.ElapsedMilliseconds,
+ // drawingTime.ElapsedMilliseconds);
+ updateTime.Stop ();
+ // Debug.WriteLine("UPDATE: {0} ticks \t, {1} ms",
+ // updateTime.ElapsedTicks,
+ // updateTime.ElapsedMilliseconds);
+ }
+ #endregion
+
+
+ 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);
+ }
+
+// public void LoadInterface<T>(string path, out T result)
+// {
+// GraphicObject.Load<T> (path, out result, this);
+// AddWidget (result as GraphicObject);
+// }
+// public T LoadInterface<T> (string Path)
+// {
+// T result;
+// GraphicObject.Load<T> (Path, out result, this);
+// AddWidget (result as GraphicObject);
+// return result;
+// }
+
+
+
+ public void PutOnTop(GraphicObject g)
+ {
+ if (GraphicObjects.IndexOf(g) > 0)
+ {
+ GraphicObjects.Remove(g);
+ GraphicObjects.Insert(0, g);
+ }
+ }
+
+ #region Mouse Handling
+ void Mouse_Move(object sender, MouseMoveEventArgs e)
+ {
+ if (_activeWidget != null) {
+ //send move evt even if mouse move outside bounds
+ _activeWidget.onMouseMove (_activeWidget, e);
+ return;
+ }
+
+ if (_hoverWidget != null) {
+ //check topmost graphicobject first
+ GraphicObject tmp = _hoverWidget;
+ GraphicObject topc = null;
+ while (tmp is GraphicObject) {
+ topc = tmp;
+ tmp = tmp.Parent as GraphicObject;
+ }
+ int idxhw = GraphicObjects.IndexOf (topc);
+ if (idxhw != 0) {
+ int i = 0;
+ while (i < idxhw) {
+ if (GraphicObjects [i].MouseIsIn (e.Position)) {
+ _hoverWidget.onMouseLeave (this, e);
+ GraphicObjects [i].checkHoverWidget (e);
+ return;
+ }
+ i++;
+ }
+ }
+
+
+ if (_hoverWidget.MouseIsIn (e.Position)) {
+ _hoverWidget.checkHoverWidget (e);
+ return;
+ } else {
+ _hoverWidget.onMouseLeave (this, e);
+ //seek upward from last focused graph obj's
+ while (_hoverWidget.Parent as GraphicObject!=null) {
+ _hoverWidget = _hoverWidget.Parent as GraphicObject;
+ if (_hoverWidget.MouseIsIn (e.Position)) {
+ _hoverWidget.checkHoverWidget (e);
+ return;
+ } else
+ _hoverWidget.onMouseLeave (this, e);
+ }
+ }
+ }
+
+ //top level graphic obj's parsing
+ for (int i = 0; i < GraphicObjects.Count; i++) {
+ GraphicObject g = GraphicObjects[i];
+ if (g.MouseIsIn (e.Position)) {
+ g.checkHoverWidget (e);
+ PutOnTop (g);
+ return;
+ }
+ }
+ _hoverWidget = null;
+ MouseMove.Raise (this, e);
+ }
+ void Mouse_ButtonUp(object sender, MouseButtonEventArgs e)
+ {
+ if (_activeWidget == null)
+ return;
+
+ _activeWidget.onMouseButtonUp (this, e);
+ _activeWidget = null;
+ MouseButtonUp.Raise (this, e);
+ }
+ void Mouse_ButtonDown(object sender, MouseButtonEventArgs e)
+ {
+ if (_hoverWidget == null) {
+ MouseButtonDown.Raise (this, e);
+ return;
+ }
+
+ GraphicObject g = _hoverWidget;
+ while (!g.Focusable) {
+ g = g.Parent as GraphicObject;
+ if (g == null) {
+ return;
+ }
+ }
+
+ _activeWidget = g;
+ _activeWidget.onMouseButtonDown (this, e);
+ }
+
+ void Mouse_WheelChanged(object sender, MouseWheelEventArgs e)
+ {
+ if (_hoverWidget == null) {
+ MouseWheelChanged.Raise (this, e);
+ return;
+ }
+ _hoverWidget.onMouseWheel (this, e);
+ }
+ #endregion
+
+ #region keyboard Handling
+ void Keyboard_KeyDown(object sender, KeyboardKeyEventArgs e)
+ {
+ if (_focusedWidget == null)
+ return;
+ _focusedWidget.onKeyDown (sender, e);
+ }
+ #endregion
+
+ public void Quit ()
+ {
+ throw new NotImplementedException ();
+ }
+
+
+ #region ILayoutable implementation
+
+ public Rectangle ContextCoordinates (Rectangle r)
+ {
+ return r;
+ }
+ public Rectangle ScreenCoordinates (Rectangle r)
+ {
+ return r;
+ }
+
+ public ILayoutable Parent {
+ get {
+ return null;
+ }
+ set {
+ throw new NotImplementedException ();
+ }
+ }
+
+ public bool SizeIsValid {
+ get { return true; }
+ set { throw new NotImplementedException (); }
+ }
+
+ public void RegisterForLayouting (int layoutType)
+ {
+ throw new NotImplementedException ();
+ }
+
+
+ public void UpdateLayout (LayoutingType layoutType)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public bool PositionIsValid {
+ get {
+ return true;
+ }
+ set {
+ throw new NotImplementedException ();
+ }
+ }
+ public bool LayoutIsValid {
+ get {
+ return true;//tester tout les enfants a mon avis
+ }
+ set {
+ throw new NotImplementedException ();
+ }
+ }
+
+ public Rectangle ClientRectangle {
+ get {
+ return new go.Size(Allocation.Width,Allocation.Height);
+ }
+ }
+
+ public IGOLibHost TopContainer {
+ get { return this as IGOLibHost; }
+ }
+
+ public Rectangle getSlot ()
+ {
+ return ClientRectangle;
+ }
+ public Rectangle getBounds ()//redundant but fill ILayoutable implementation
+ {
+ return ClientRectangle;
+ }
+
+ public bool WIsValid {
+ get {
+ return true;
+ }
+ set {
+ throw new NotImplementedException ();
+ }
+ }
+ public bool HIsValid {
+ get {
+ return true;
+ }
+ set {
+ throw new NotImplementedException ();
+ }
+ }
+ public bool XIsValid {
+ get {
+ return true;
+ }
+ set {
+ throw new NotImplementedException ();
+ }
+ }
+ public bool YIsValid {
+ get {
+ return true;
+ }
+ set {
+ throw new NotImplementedException ();
+ }
+ }
+
+ public virtual void InvalidateLayout ()
+ {
+ // foreach (GraphicObject g in GraphicObjects) {
+ // g.InvalidateLayout ();
+ // }
+ }
+
+ #endregion
+ }
+}
+
--- /dev/null
+//
+// ImageViewerNodeExtension.cs
+//
+// Author:
+// Mike Krüger <mkrueger@novell.com>
+//
+// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
+//
+// 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 MonoDevelop.Projects;
+using MonoDevelop.Ide.Gui.Components;
+using MonoDevelop.Components;
+using MonoDevelop.Components.Commands;
+using MonoDevelop.Ide;
+
+namespace MonoDevelop.GOLib
+{
+ enum Commands {
+ ShowGOLibViewer
+ }
+
+ class GOLibNodeExtension : NodeBuilderExtension
+ {
+ public override Type CommandHandlerType {
+ get { return typeof(GOLibCommandHandler); }
+ }
+ public override bool CanBuildNode (Type dataType)
+ {
+ return typeof(ProjectFile).IsAssignableFrom (dataType);
+ }
+ public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, NodeInfo nodeInfo)
+ {
+ ProjectFile pf = dataObject as ProjectFile;
+
+// string mimeType = DesktopService.GetMimeTypeForUri (pf.FilePath);
+// if (mimeType.StartsWith ("image/", StringComparison.CurrentCultureIgnoreCase)) {
+// Image i;
+// if (pf != null) {
+// i = Image.FromFile (pf.FilePath);
+// nodeInfo.Icon = i.Scale (16.0 / i.Width, 16.0 / i.Height);
+// }
+// }
+
+ base.BuildNode (treeBuilder, dataObject, nodeInfo);
+ }
+ }
+
+ class GOLibCommandHandler: NodeCommandHandler
+ {
+ [CommandHandler (Commands.ShowGOLibViewer)]
+ protected void OnShowGOLibViewer ()
+ {
+
+ GOLibView view = new GOLibView ();
+
+ ProjectFile file = CurrentNode.DataItem as ProjectFile;
+ if (file != null)
+ view.Load (file.FilePath);
+
+ IdeApp.Workbench.OpenDocument (view, true);
+ }
+ }
+
+}
+
--- /dev/null
+//
+// ImageViewer.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+// Copyright (c) 2015 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+//
+// HexEditorView.cs
+//
+// Author:
+// Mike Krüger <mkrueger@novell.com>
+//
+// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
+//
+// 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.IO;
+using MonoDevelop.Ide.Gui;
+using MonoDevelop.Ide.Gui.Content;
+using MonoDevelop.Ide.Fonts;
+using Mono.Addins;
+using MonoDevelop.Core;
+using MonoDevelop.Ide;
+using go;
+using MonoDevelop.DesignerSupport;
+
+namespace MonoDevelop.GOLib
+{
+ class GOLibView : AbstractViewContent
+ {
+ GOLibGtkHost gtkGoWidgetHost;
+
+
+ double zoom = 1.0;
+
+ public override Gtk.Widget Control {
+ get {
+ return gtkGoWidgetHost;
+ }
+ }
+
+ public GOLibView ()
+ {
+ gtkGoWidgetHost = new GOLibGtkHost ();
+ }
+
+ public override void Load (string fileName)
+ {
+ gtkGoWidgetHost.Load (fileName);
+ ContentName = fileName;
+ this.IsDirty = false;
+ gtkGoWidgetHost.Show ();
+ }
+ public override bool CanReuseView (string fileName)
+ {
+ return base.CanReuseView (fileName);
+ }
+ public override void RedrawContent ()
+ {
+ base.RedrawContent ();
+ }
+ }
+}
<RootNamespace>MonoDevelop.GOLib</RootNamespace>
<AssemblyName>MonoDevelop.GOLib</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <OutputPath>build</OutputPath>
<CustomCommands>
<CustomCommands>
- <Command type="Execute" command="/usr/local/lib/monodevelop/bin/MonoDevelop.exe" workingdir="/usr/local/lib/monodevelop/bin/">
+ <Command type="Execute"
+ command="/usr/local/lib/monodevelop/bin/MonoDevelop.exe --no-redirect"
+ workingdir="/usr/local/lib/monodevelop/bin"
+ >
<EnvironmentVariables>
<Variable name="MONODEVELOP_DEV_ADDINS" value="${TargetDir}" />
+ <Variable name="MONODEVELOP_CONSOLE_LOG_LEVEL" value="UpToDebug" />
+ <Variable name="MONODEVELOP_LOGGING_PAD_LEVEL" value="UpToDebug" />
+ <Variable name="MONODEVELOP_CONSOLE_LOG_USE_COLOUR" value="True"/>
</EnvironmentVariables>
</Command>
</CustomCommands>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
- <OutputPath>build</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
- <CustomCommands>
- <CustomCommands>
- <Command type="Execute" command="/usr/local/lib/monodevelop/bin/MonoDevelop.exe" workingdir="/usr/local/lib/monodevelop/bin/" />
- </CustomCommands>
- </CustomCommands>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>full</DebugType>
+ <DebugType>none</DebugType>
<Optimize>true</Optimize>
- <OutputPath>build</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
- <CustomCommands>
- <CustomCommands>
- <Command type="Execute" command="/usr/local/lib/monodevelop/bin/MonoDevelop.exe" workingdir="/usr/local/lib/monodevelop/bin/" />
- </CustomCommands>
- </CustomCommands>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="ICSharpCode.NRefactory">
- <HintPath>..\..\..\..\..\opt\lib\monodevelop\bin\ICSharpCode.NRefactory.dll</HintPath>
+ <HintPath>\usr\local\lib\monodevelop\bin\ICSharpCode.NRefactory.dll</HintPath>
+ <Private>False</Private>
</Reference>
<Reference Include="Mono.Addins">
<Package>mono-addins</Package>
</Reference>
- <Reference Include="MonoDevelop.Core">
- <HintPath>..\..\..\..\..\opt\lib\monodevelop\bin\MonoDevelop.Core.dll</HintPath>
- </Reference>
<Reference Include="MonoDevelop.Ide">
- <HintPath>..\..\..\..\..\opt\lib\monodevelop\bin\MonoDevelop.Ide.dll</HintPath>
+ <HintPath>\usr\local\lib\monodevelop\bin\MonoDevelop.Ide.dll</HintPath>
+ <Private>False</Private>
</Reference>
<Reference Include="Mono.Cairo" />
<Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
- <Reference Include="OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4">
- <HintPath>..\dependencies\OpenTK.dll</HintPath>
- </Reference>
<Reference Include="System.Drawing" />
<Reference Include="MonoDevelop.DesignerSupport">
- <HintPath>..\..\..\..\..\usr\local\lib\monodevelop\AddIns\MonoDevelop.DesignerSupport\MonoDevelop.DesignerSupport.dll</HintPath>
+ <HintPath>\usr\local\lib\monodevelop\AddIns\MonoDevelop.DesignerSupport\MonoDevelop.DesignerSupport.dll</HintPath>
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="OpenTK">
+ <HintPath>..\..\opentk\Binaries\OpenTK\Release\OpenTK.dll</HintPath>
+ </Reference>
+ <Reference Include="MonoDevelop.Core">
+ <HintPath>..\..\..\..\..\usr\local\lib\monodevelop\bin\MonoDevelop.Core.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
}
}
public bool CanUseAsDefault
- { get { return canHandle; } }
+ { get { return false; }}
public IViewContent CreateContent (FilePath fileName, string mimeType, Project ownerProject)
{
return new GOLibView ();
+
+
}
public bool CanHandle (FilePath fileName, string mimeType, Project ownerProject)
{
canHandle = mimeType.StartsWith("text/x-goml");
- return true;
+ return canHandle;
}
}
}
public object GetActiveComponent ()
{
- return activeWidget;
+ return hoverWidget;
}
public object GetProvider ()
{
- return activeWidget;
+ return hoverWidget;
}
public void OnEndEditing (object obj)
{
}
#endregion
+ #region Events
+ //those events are raised only if mouse isn't in a graphic object
+ 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;
+ #endregion
+
string _path;
GraphicObject goWidget;
Gtk.DrawingArea area = (Gtk.DrawingArea) o;
Cairo.Context cr = Gdk.CairoHelper.Create(area.GdkWindow);
_redrawClip.AddRectangle (this.ClientRectangle);
+
+ LoggingService.LogInfo ("expose event");
+
update (cr);
if (_hoverWidget != null) {
MouseButtonEventArgs e = new MouseButtonEventArgs
((int)args.Event.X, (int)args.Event.Y,
gtkButtonIdToOpenTkButton(args.Event.Button), true);
- activeWidget = hoverWidget;
+ Mouse_ButtonDown (o, e);
DesignerSupport.DesignerSupport.Service.SetPadContent (this);
}
void GOLibGtkHost_ButtonReleaseEvent (object o, Gtk.ButtonReleaseEventArgs args)
{
MouseButtonEventArgs e = new MouseButtonEventArgs
((int)args.Event.X, (int)args.Event.Y,
- gtkButtonIdToOpenTkButton(args.Event.Button), false);
+ gtkButtonIdToOpenTkButton(args.Event.Button), false);
+ Mouse_ButtonUp (o, e);
}
int lastX,LastY;
void GOLibGtkHost_MotionNotifyEvent (object o, Gtk.MotionNotifyEventArgs args)
public void Load(string path)
{
- goWidget = GraphicObject.Load (path);
+ goWidget = Interface.Load (path);
this.AddWidget (goWidget);
}
public Stopwatch drawingTime = new Stopwatch ();
#endregion
+ #region update
void update (Cairo.Context ctx)
{
updateTime.Restart ();
GraphicObjects.CopyTo (invGOList,0);
invGOList = invGOList.Reverse ().ToArray ();
- foreach (GraphicObject p in invGOList) {
- if (p.Visible) {
- layoutTime.Start ();
- while(!p.LayoutIsValid)
- p.UpdateLayout ();
- layoutTime.Stop ();
- }
+ go.Size newSize = this.ClientRectangle.Size;
+ if (lastSize != newSize) {
+ foreach (GraphicObject g in GraphicObjects)
+ g.RegisterForLayouting ((int)LayoutingType.All);
+ lastSize = newSize;
}
- GraphicObject[] gotr = new GraphicObject[_gobjsToRedraw.Count];
- _gobjsToRedraw.CopyTo (gotr);
- _gobjsToRedraw.Clear ();
+ //Debug.WriteLine ("======= Layouting queue start =======");
+ while (Interface.LayoutingQueue.Count > 0) {
+ LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue ();
+ lqi.ProcessLayouting ();
+ }
+
+ //Debug.WriteLine ("otd:" + gobjsToRedraw.Count.ToString () + "-");
+ //final redraw clips should be added only when layout is completed among parents,
+ //that's why it take place in a second pass
+ GraphicObject[] gotr = new GraphicObject[gobjsToRedraw.Count];
+ gobjsToRedraw.CopyTo (gotr);
+ gobjsToRedraw.Clear ();
foreach (GraphicObject p in gotr) {
p.registerClipRect ();
}
- lock (_redrawClip) {
- if (_redrawClip.count > 0) {
+ lock (redrawClip) {
+ if (redrawClip.count > 0) {
// #if DEBUG_CLIP_RECTANGLE
// redrawClip.stroke (ctx, new Color(1.0,0,0,0.3));
// #endif
- _redrawClip.clearAndClip (ctx);//rajouté après, tester si utile
+ redrawClip.clearAndClip (ctx);//rajouté après, tester si utile
+
//Link.draw (ctx);
foreach (GraphicObject p in invGOList) {
if (p.Visible) {
drawingTime.Start ();
ctx.Save ();
- if (_redrawClip.count > 0) {
- Rectangles clip = _redrawClip.intersectingRects (p.ContextCoordinates(p.Slot.Size));
+ if (redrawClip.count > 0) {
+ Rectangles clip = redrawClip.intersectingRects (p.Slot);
if (clip.count > 0)
p.Paint (ref ctx, clip);
}
}
ctx.ResetClip ();
- dirtyZone = _redrawClip.Bounds;
+ dirtyZone = redrawClip.Bounds;
// #if DEBUG_CLIP_RECTANGLE
// redrawClip.stroke (ctx, Color.Red.AdjustAlpha(0.1));
// #endif
- _redrawClip.Reset ();
+ redrawClip.Reset ();
}
}
+ //surf.WriteToPng (@"/mnt/data/test.png");
+
// if (ToolTip.isVisible) {
// ToolTip.panel.processkLayouting();
// if (ToolTip.panel.layoutIsValid)
// Debug.WriteLine("UPDATE: {0} ticks \t, {1} ms",
// updateTime.ElapsedTicks,
// updateTime.ElapsedMilliseconds);
-
}
+ #endregion
+
public void AddWidget(GraphicObject g)
{
g.Parent = this;
- GraphicObjects.Add (g);
+ GraphicObjects.Insert (0, g);
+
+ g.RegisterForLayouting ((int)LayoutingType.Sizing);
}
public void DeleteWidget(GraphicObject g)
{
g.Visible = false;//trick to ensure clip is added to refresh zone
+ g.ClearBinding();
GraphicObjects.Remove (g);
}
- public void LoadInterface<T>(string path, out T result)
- {
- GraphicObject.Load<T> (path, out result, this);
- AddWidget (result as GraphicObject);
- }
- public T LoadInterface<T> (string Path)
- {
- T result;
- GraphicObject.Load<T> (Path, out result, this);
- AddWidget (result as GraphicObject);
- return result;
- }
+// public void LoadInterface<T>(string path, out T result)
+// {
+// GraphicObject.Load<T> (path, out result, this);
+// AddWidget (result as GraphicObject);
+// }
+// public T LoadInterface<T> (string Path)
+// {
+// T result;
+// GraphicObject.Load<T> (Path, out result, this);
+// AddWidget (result as GraphicObject);
+// return result;
+// }
{
if (_activeWidget != null) {
//send move evt even if mouse move outside bounds
- _activeWidget.checkHoverWidget (e);
+ _activeWidget.onMouseMove (_activeWidget, e);
return;
}
if (_hoverWidget != null) {
+ //check topmost graphicobject first
+ GraphicObject tmp = _hoverWidget;
+ GraphicObject topc = null;
+ while (tmp is GraphicObject) {
+ topc = tmp;
+ tmp = tmp.Parent as GraphicObject;
+ }
+ int idxhw = GraphicObjects.IndexOf (topc);
+ if (idxhw != 0) {
+ int i = 0;
+ while (i < idxhw) {
+ if (GraphicObjects [i].MouseIsIn (e.Position)) {
+ _hoverWidget.onMouseLeave (this, e);
+ GraphicObjects [i].checkHoverWidget (e);
+ return;
+ }
+ i++;
+ }
+ }
+
+
if (_hoverWidget.MouseIsIn (e.Position)) {
_hoverWidget.checkHoverWidget (e);
return;
_activeWidget.onMouseButtonUp (this, e);
_activeWidget = null;
+ MouseButtonUp.Raise (this, e);
}
void Mouse_ButtonDown(object sender, MouseButtonEventArgs e)
{
if (_hoverWidget == null) {
+ MouseButtonDown.Raise (this, e);
return;
}
GraphicObject g = _hoverWidget;
- while (!g.Focusable) {
+ while (!g.Focusable) {
g = g.Parent as GraphicObject;
if (g == null) {
return;
_activeWidget = g;
_activeWidget.onMouseButtonDown (this, e);
}
+
void Mouse_WheelChanged(object sender, MouseWheelEventArgs e)
{
if (_hoverWidget == null) {
+ MouseWheelChanged.Raise (this, e);
return;
}
_hoverWidget.onMouseWheel (this, e);
_focusedWidget.onKeyDown (sender, e);
}
#endregion
+
+ public void Quit ()
+ {
+ throw new NotImplementedException ();
+ }
#region ILayoutable implementation
get { return true; }
set { throw new NotImplementedException (); }
}
+
+ public void RegisterForLayouting (int layoutType)
+ {
+ throw new NotImplementedException ();
+ }
+
+
+ public void UpdateLayout (LayoutingType layoutType)
+ {
+ throw new NotImplementedException ();
+ }
+
public bool PositionIsValid {
get {
return true;
throw new NotImplementedException ();
}
}
-
+ Size lastSize;
public Rectangle ClientRectangle {
- get {
- return new go.Size(Allocation.Width,Allocation.Height);
+ get {
+ go.Size newSize = new go.Size (Allocation.Width, Allocation.Height);
+ return newSize;
}
}
using MonoDevelop.Components;
using MonoDevelop.Components.Commands;
using MonoDevelop.Ide;
+using System.Linq;
namespace MonoDevelop.GOLib
{
GOLibView view = new GOLibView ();
ProjectFile file = CurrentNode.DataItem as ProjectFile;
+
if (file != null)
view.Load (file.FilePath);
+
IdeApp.Workbench.OpenDocument (view, true);
+ //IdeApp.Workbench.Documents.Where (d => d.FileName == file.FilePath);
+
}
+ public override void ActivateItem ()
+ {
+// ProjectFile o = this.CurrentNode.DataItem as ProjectFile;
+// Ide.Gui.Document[] doc = IdeApp.Workbench.Documents.Where (d => d.FileName == o.FilePath).ToArray();
+// if (doc [0].ActiveView != null)
+// return;
+ //doc [0].ActiveView.Select();
+ OnShowGOLibViewer ();
+ }
+
}
}
public GOLibView ()
{
gtkGoWidgetHost = new GOLibGtkHost ();
+
}
public override void Load (string fileName)
gtkGoWidgetHost.Load (fileName);
ContentName = fileName;
this.IsDirty = false;
+
gtkGoWidgetHost.Show ();
}
public override bool CanReuseView (string fileName)
{
base.RedrawContent ();
}
+
}
}
\r
public GOLIBTests ()\r
: base(600, 400,"test: press spacebar to toogle test files")\r
- {}\r
+ {\r
+ VSync = VSyncMode.Off;\r
+ }\r
\r
int frameCpt = 0;\r
int idx = 0;\r
string[] testFiles = {\r
- "testCombobox.goml",\r
- "testBorder.goml",\r
+ "test4.goml",\r
"testContainer.goml",\r
+ "testBorder.goml",\r
"testLabel.goml",\r
"testCheckbox.goml",\r
+ "fps.goml",\r
"testRadioButton.goml",\r
"testSpinner.goml",\r
"testPopper.goml",\r
"testExpandable.goml",\r
"testGroupBox.goml",\r
- "test_stack.goml",\r
+ "testCombobox.goml",\r
"testWindow.goml",\r
"testMsgBox.goml",\r
"testGrid.goml",\r
- "fps.goml",\r
+\r
"testMeter.goml",\r
};\r
\r
protected override void OnLoad (EventArgs e)\r
{\r
base.OnLoad (e);\r
- LoadInterface("Interfaces/" + testFiles[idx]);\r
+ this.AddWidget(new test4());\r
+ //LoadInterface("Interfaces/" + testFiles[idx]);\r
}\r
protected override void OnUpdateFrame (FrameEventArgs e)\r
{\r
- base.OnUpdateFrame (e);\r
-\r
+ if (frameCpt % 8 == 0)\r
+ base.OnUpdateFrame (e);\r
+ \r
fps = (int)RenderFrequency;\r
\r
\r
<?xml version="1.0"?>
-<!--<GraphicObject
- Width="100" Height="100"
- Top="200" Left="200"
- Margin="10" Background="Green"/>-->
-
-<Container Width="0" Height="0" Background="Transparent">
- <Group >
+<Container Width="100" Height="100" Background="Red">
+ <Group>
<Border CornerRadius="5" BorderWidth="1" Margin="5"/>
<HorizontalStack Fit="true" Background="Clear"
VerticalAlignment="Top" Left="10">
- <GraphicObject Width="5"/>
+ <GraphicObject Width="3"/>
<Label Text="GroupBox"/>
<GraphicObject Width="5"/>
</HorizontalStack>
Margin="10" Focusable="True" Fit="True" Background="Green">-->\r
<Group Fit="true">\r
<GraphicObject Name="g1" Width="400" Height="40" Background="Blue"/>\r
- <GraphicObject Name="g2" Width="40" Height="40" Background="Red"\r
+ <GraphicObject Name="g2" Width="400" Height="40" Background="Red"\r
HorizontalAlignment="Right"/> \r
</Group>\r
<!--</Container>-->
\ No newline at end of file
--- /dev/null
+// ------------------------------------------------------------------------------
+// <autogenerated>
+// This code was generated by a tool.
+// Mono Runtime Version: 4.0.30319.17020
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </autogenerated>
+// ------------------------------------------------------------------------------
+
+using System;
+
+
+namespace go {
+
+ public partial class testBorder : Border {
+ public testBorder() {
+ this.BorderWidth = 5;
+ this.Width = 200;
+ this.Height = 200;
+ this.CornerRadius = 20;
+ this.Margin = 0;
+ this.Background = go.Color.Mantis;
+ this.SetChild(new go.GraphicObject());
+ this.Child.CornerRadius = 0;
+ this.Child.Background = go.Color.CornflowerBlue;
+ this.Child.Height = 100;
+ this.Child.Width = 100;
+ }
+ }
+}
<?xml version="1.0"?>\r
-<Container Background="Red" Left="100" Top="100" Height="300" Width="300" >\r
+<Container Class="TestContainer1" Background="Red" Left="100" Top="100" Height="300" Width="300" >\r
<Container Left="100" Top="100" Height="100" Width="100" Background="LightGreen" Margin="0">\r
<Label Text="{fps}" Background="DarkRed"/>\r
</Container>\r
<?xml version="1.0"?>\r
<Grid RowCount="2" ColumnCount="2">\r
- <GraphicObject Background="1,0;0,0;0,0;1,0"/>\r
+ <GraphicObject Background="0,0;0,0;0,0;1,0"/>\r
<GraphicObject Background="0,0;0,0;0,5;1,0"/>\r
<GraphicObject Background="0,0;0,5;0,0;1,0"/>\r
<GraphicObject Background="0,5;0,0;0,0;1,0"/>\r
<?xml version="1.0"?>\r
<Groupbox Width="-1" Height="-1" Background="Red">\r
- <VerticalStack Margin="0">\r
- <Checkbox />\r
-\r
- </VerticalStack>\r
+<Label/>\r
</Groupbox>\r
<VerticalStack Background="DarkBlue" Height="300" Width="200">\r
<!-- <Label Text="label11" Width="0" Background="Green"/>\r
<Label Text="label21"/>-->\r
-<!-- <HorizontalStack Width="-1" Height="-1" Margin="5"\r
+ <HorizontalStack Width="-1" Height="-1" Margin="5"\r
Focusable="True" Background="Blue">\r
+\r
<Label Text="label12"/>\r
+ <VerticalStack Background="Red" Fit="true">\r
+ <Label Text="label99"/>\r
+ <Label Text="label999"/>\r
+ </VerticalStack>\r
<Label Text="label22"/>\r
- <Label Text="label32"/>\r
+<!-- <Label Text="label32"/>\r
<Label Text="label42"/>\r
- <Label Text="label52"/>\r
+ <Label Text="label52"/>-->\r
</HorizontalStack>\r
- <Label Text="label33" Background="Green" Width="0"/>-->\r
+<!-- <Label Text="label33" Background="Green" Width="0"/>-->\r
<!-- <Label Text="label43"/>-->\r
- <Border Margin="10">\r
- <Label Text="label53" Background="Red" Height="0" CornerRadius="10"/>\r
- </Border>\r
+<!-- <Border Margin="10">\r
+ <Label Text="label53" Background="Red" Height="0" CornerRadius="10"/>\r
+ </Border>-->\r
<Label Text="label43"/>\r
<Label Text="label43"/>\r
</VerticalStack>\r
<HintPath>..\..\opentk\Binaries\OpenTK\Release\OpenTK.dll</HintPath>
</Reference>
<Reference Include="Mono.Cairo" />
+ <Reference Include="golib">
+ <HintPath>..\bin\Release\golib.dll</HintPath>
+ </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="GOLIBTest_5.cs" />
<Compile Include="GOLIBTest_TypeViewer.cs" />
<Compile Include="GOLIBTest_DirViewer.cs" />
<Compile Include="GOLIBTests.cs" />
+ <Compile Include="Interfaces\testBorder.goml.cs" />
+ <Compile Include="..\bin\Debug\Interfaces\testContainer.goml.cs">
+ <Link>Interfaces\testContainer.goml.cs</Link>
+ </Compile>
+ <Compile Include="..\bin\Debug\Interfaces\test_stack.goml.cs">
+ <Link>Interfaces\test_stack.goml.cs</Link>
+ </Compile>
+ <Compile Include="..\bin\Debug\Interfaces\test4.goml.cs">
+ <Link>Interfaces\test4.goml.cs</Link>
+ </Compile>
</ItemGroup>
<ItemGroup>
<None Include="image\u.svg">
<Folder Include="Interfaces\" />
<Folder Include="image\" />
</ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\GOLib.csproj">
- <Project>{C2980F9B-4798-4C05-99E2-E174810F7C7B}</Project>
- <Name>GOLib</Name>
- </ProjectReference>
- </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="image\tetra.png" />
</ItemGroup>
namespace go
{
+ public enum BindingType
+ {
+ Handler,
+ DynamicHandler,
+ PropertyBinding
+ }
+ public class Binding{
+ public BindingType BindingType;
+ public string MemberName;
+ public string BindingExpression;
+ }
+
+ public static class CompilerServices2
+ {
+ static int dynHandleCpt = 0;
+ /// <summary>
+ /// Compile events expression in GOML attributes
+ /// </summary>
+ /// <param name="es">Event binding details</param>
+ public static void ResolveBinding(DynAttribute es)
+ {
+ Type srcType = es.Source.GetType ();
+
+ #region Retrieve EventHandler parameter type
+ EventInfo ei = srcType.GetEvent (es.MemberName);
+ MethodInfo invoke = ei.EventHandlerType.GetMethod ("Invoke");
+ ParameterInfo[] pars = invoke.GetParameters ();
+
+ Type handlerArgsType = pars [1].ParameterType;
+ #endregion
+
+ Type[] args = {typeof(object), handlerArgsType};
+ DynamicMethod dm = new DynamicMethod("dynHandle_" + dynHandleCpt,
+ typeof(void),
+ args,
+ srcType.Module);
+
+ es.Source.DynamicMethodIds.Add (dynHandleCpt);
+
+ dynHandleCpt++;
+
+ #region IL generation
+ ILGenerator il = dm.GetILGenerator(256);
+
+ string src = es.Value.Trim();
+
+ if (! (src.StartsWith("{") || src.EndsWith ("}")))
+ throw new Exception (string.Format("GOML:Malformed {0} Event handler: {1}", es.MemberName, es.Value));
+
+ src = src.Substring (1, src.Length - 2);
+ string[] srcLines = src.Split (new char[] { ';' });
+
+ foreach (string srcLine in srcLines) {
+ string statement = srcLine.Trim ();
+
+ string[] operandes = statement.Split (new char[] { '=' });
+ if (operandes.Length < 2) //not an affectation
+ {
+ continue;
+ }
+ string lop = operandes [0].Trim ();
+ string rop = operandes [operandes.Length-1].Trim ();
+
+ #region LEFT OPERANDES
+ GraphicObject lopObj = es.Source; //default left operand base object is
+ //the first arg (object sender) of the event handler
+
+ string[] lopParts = lop.Split (new char[] { '.' });
+ if (lopParts.Length == 2) {//should search also for member of es.Source
+ lopObj = es.Source.FindByName (lopParts [0]);
+ if (lopObj==null)
+ throw new Exception (string.Format("GOML:Unknown name: {0}", lopParts[0]));
+ //TODO: should create private member holding ref of lopObj, and emit
+ //a call to FindByName(lopObjName) during #ctor or in a onLoad func or evt handler
+ throw new Exception (string.Format("GOML:obj tree ref not yet implemented", lopParts[0]));
+ }else
+ il.Emit(OpCodes.Ldarg_0); //load sender ref onto the stack
+
+ int i = lopParts.Length -1;
+
+ MemberInfo lopMbi = lopObj.GetType().GetMember (lopParts[i])[0];
+ OpCode lopSetOC;
+ dynamic lopSetMbi;
+ Type lopT = null;
+ switch (lopMbi.MemberType) {
+ case MemberTypes.Property:
+ PropertyInfo lopPi = srcType.GetProperty (lopParts[i]);
+ MethodInfo dstMi = lopPi.GetSetMethod ();
+ lopT = lopPi.PropertyType;
+ lopSetMbi = dstMi;
+ lopSetOC = OpCodes.Callvirt;
+ break;
+ case MemberTypes.Field:
+ FieldInfo dstFi = srcType.GetField(lopParts[i]);
+ lopT = dstFi.FieldType;
+ lopSetMbi = dstFi;
+ lopSetOC = OpCodes.Stfld;
+ break;
+ default:
+ throw new Exception (string.Format("GOML:member type not handle: {0}", lopParts[i]));
+ }
+ #endregion
+
+ #region RIGHT OPERANDES
+ if (rop.StartsWith("\'")){
+ if (!rop.EndsWith("\'"))
+ throw new Exception (string.Format
+ ("GOML:malformed string constant in handler: {0}", rop));
+ string strcst = rop.Substring (1, rop.Length - 2);
+
+ il.Emit(OpCodes.Ldstr,strcst);
+
+ }else{
+ //search for a static field in left operand type named 'rop name'
+ FieldInfo ropFi = lopT.GetField (rop, BindingFlags.Static|BindingFlags.Public);
+ if (ropFi != null)
+ {
+ il.Emit (OpCodes.Ldsfld, ropFi);
+ }else{
+ //search if parsing methods are present
+ MethodInfo lopTryParseMi = lopT.GetMethod("TryParse");
+
+ }
+ }
+
+ #endregion
+
+ //emit left operand assignment
+ il.Emit(lopSetOC, lopSetMbi);
+ }
+
+ il.Emit(OpCodes.Ret);
+
+ #endregion
+
+ Delegate del = dm.CreateDelegate(ei.EventHandlerType);
+ MethodInfo addHandler = ei.GetAddMethod ();
+ addHandler.Invoke(es.Source, new object[] {del});
+ }
+
+ }
public static class CompilerServices
{
static int dynHandleCpt = 0;
+
/// <summary>
/// Compile events expression in GOML attributes
/// </summary>
using System.Xml;\r
\r
namespace go\r
-{\r
+{ \r
public class GraphicObject : IXmlSerializable, ILayoutable, IValueChange\r
{\r
internal List<int> DynamicMethodIds = new List<int> ();\r
\r
#region private fields\r
ILayoutable _parent;\r
- string _name;\r
- Color _background;\r
- Color _foreground;\r
- Font _font;\r
- double _cornerRadius;\r
- int _margin;\r
+ string _name = "unamed";\r
+ Color _background = Color.Transparent;\r
+ Color _foreground = Color.White;\r
+ Font _font = "droid, 10";\r
+ double _cornerRadius = 0;\r
+ int _margin = 0;\r
bool _focusable = false;\r
bool _hasFocus = false;\r
protected bool _isVisible = true;\r
- VerticalAlignment _verticalAlignment;\r
- HorizontalAlignment _horizontalAlignment;\r
- Size _maximumSize;\r
- Size _minimumSize;\r
+ VerticalAlignment _verticalAlignment = VerticalAlignment.Center;\r
+ HorizontalAlignment _horizontalAlignment = HorizontalAlignment.Center;\r
+ Size _maximumSize = "0;0";\r
+ Size _minimumSize = "0;0";\r
\r
Picture _backgroundImage;\r
string _backgroundImagePath;\r
{\r
return Visible ? ScreenCoordinates(Slot).ContainsOrIsEqual (m) : false; \r
}\r
- internal virtual void checkHoverWidget(MouseMoveEventArgs e)\r
+ public virtual void checkHoverWidget(MouseMoveEventArgs e)\r
{\r
IGOLibHost glh = TopContainer;\r
if (glh.hoverWidget != this) {\r
while (reader.MoveToNextAttribute ()) {\r
string attName = reader.Name;\r
string attValue = reader.Value;\r
+\r
+ if (string.IsNullOrEmpty (attValue))\r
+ continue;\r
+ \r
MemberInfo mi = thisType.GetMember (attName).FirstOrDefault();\r
if (mi == null) {\r
Debug.WriteLine (Interface.CurrentGOMLPath + "=>GOML: Unknown attribute in " + thisType.ToString() + " : " + attName);\r
bool isAttribute = false;\r
object defaultValue = null;\r
\r
- foreach (object o in pi.GetCustomAttributes ()) {\r
- XmlAttributeAttribute xaa = o as XmlAttributeAttribute;\r
+ foreach (object attrib in pi.GetCustomAttributes ()) {\r
+ XmlAttributeAttribute xaa = attrib as XmlAttributeAttribute;\r
if (xaa != null) {\r
isAttribute = true;\r
if (!string.IsNullOrEmpty (xaa.AttributeName))\r
attName = xaa.AttributeName;\r
continue;\r
}\r
- if (o is XmlIgnoreAttribute)\r
+ if (attrib is XmlIgnoreAttribute)\r
break;\r
- DefaultValueAttribute dv = o as DefaultValueAttribute;\r
+ DefaultValueAttribute dv = attrib as DefaultValueAttribute;\r
if (dv != null)\r
defaultValue = dv.Value; \r
}\r
if (!isAttribute)\r
continue;\r
- \r
- if (string.IsNullOrEmpty (attValue)) {\r
- //avoid system types automaticaly converted by parser\r
- if (defaultValue != null && !pi.PropertyType.Namespace.StartsWith("System")) {\r
- if (pi.PropertyType != defaultValue.GetType()) {\r
- MethodInfo miParse = pi.PropertyType.GetMethod ("Parse", BindingFlags.Static | BindingFlags.Public);\r
- if (miParse != null) { \r
- pi.SetValue (this, miParse.Invoke (null, new object[]{ defaultValue }), null);\r
- continue;\r
- }\r
- }\r
- }\r
- pi.SetValue (this, defaultValue, null);\r
- } else {\r
-\r
- if (attValue.StartsWith("{")) {\r
- if (Interface.DontResoveGOML)\r
- continue;\r
- //binding\r
- if (!attValue.EndsWith("}"))\r
- throw new Exception (string.Format("GOML:Malformed binding: {0}", attValue));\r
-\r
- string strBinding = attValue.Substring (1, attValue.Length - 2);\r
- Interface.GOMLResolver.Add (new DynAttribute () {\r
- Source = this,\r
- MemberName = attName,\r
- Value = strBinding\r
- });\r
+// {\r
+// //avoid system types automaticaly converted by parser\r
+// if (defaultValue != null && !pi.PropertyType.Namespace.StartsWith("System")) {\r
+// if (pi.PropertyType != defaultValue.GetType()) {\r
+// MethodInfo miParse = pi.PropertyType.GetMethod ("Parse", BindingFlags.Static | BindingFlags.Public);\r
+// if (miParse != null) { \r
+// pi.SetValue (this, miParse.Invoke (null, new object[]{ defaultValue }), null);\r
+// continue;\r
+// }\r
+// }\r
+// }\r
+// pi.SetValue (this, defaultValue, null);\r
+// } else {\r
+\r
+ if (attValue.StartsWith("{")) {\r
+ if (Interface.DontResoveGOML)\r
continue;\r
- }\r
+ //binding\r
+ if (!attValue.EndsWith("}"))\r
+ throw new Exception (string.Format("GOML:Malformed binding: {0}", attValue));\r
+\r
+ string strBinding = attValue.Substring (1, attValue.Length - 2);\r
+ Interface.GOMLResolver.Add (new DynAttribute () {\r
+ Source = this,\r
+ MemberName = attName,\r
+ Value = strBinding\r
+ });\r
+ continue;\r
+ }\r
\r
- if (pi.PropertyType == typeof(string)) {\r
- pi.SetValue (this, attValue, null);\r
- continue;\r
- }\r
+ if (pi.PropertyType == typeof(string)) {\r
+ pi.SetValue (this, attValue, null);\r
+ continue;\r
+ }\r
\r
- object o = null;\r
+ object o = null;\r
\r
- if (pi.PropertyType.IsEnum) {\r
- o = Enum.Parse (pi.PropertyType, attValue);\r
- } else {\r
- MethodInfo me = pi.PropertyType.GetMethod ("Parse", new Type[] { typeof(string) });\r
- o = me.Invoke (null, new string[] { attValue });\r
- }\r
+ if (pi.PropertyType.IsEnum) {\r
+ pi.SetValue (this, Enum.Parse (pi.PropertyType, attValue), null);\r
+ } else {\r
+ MethodInfo me = pi.PropertyType.GetMethod ("Parse", new Type[] { typeof(string) });\r
+ pi.SetValue (this, me.Invoke (null, new string[] { attValue }), null);\r
+ }\r
+\r
+ \r
\r
- pi.SetValue (this, o, null);\r
- } \r
}\r
}\r
reader.MoveToElement();\r
\r
\r
#region Mouse handling\r
- internal override void checkHoverWidget (OpenTK.Input.MouseMoveEventArgs e)\r
+ public override void checkHoverWidget (OpenTK.Input.MouseMoveEventArgs e)\r
{\r
if (TopContainer.hoverWidget != this) {\r
TopContainer.hoverWidget = this;\r
#endregion
#region Mouse handling
- internal override void checkHoverWidget (MouseMoveEventArgs e)
+ public override void checkHoverWidget (MouseMoveEventArgs e)
{
base.checkHoverWidget (e);
if (child != null)
{ \r
return Visible ? base.ScreenCoordinates(Slot).ContainsOrIsEqual (m) : false; \r
}\r
- internal override void checkHoverWidget (MouseMoveEventArgs e)\r
+ public override void checkHoverWidget (MouseMoveEventArgs e)\r
{\r
Point m = e.Position - new Point ((int)ScrollX, (int)ScrollY);\r
base.checkHoverWidget (new MouseMoveEventArgs(m.X,m.Y,e.XDelta,e.YDelta));\r
using System.Collections.Generic;
using System.Xml;
using System.Linq;
+using System.Reflection.Emit;
+using System.CodeDom;
+using Microsoft.CSharp;
+using System.CodeDom.Compiler;
namespace go
{
/// <summary>
/// Graphic objects References use in dynamic delegates for binding
/// </summary>
- public static List<object> References = new List<object>();
- public static Queue<int> FreeRefIndices = new Queue<int>();
- public static void Unreference(Object o)
+ public static List<object> References = new List<object> ();
+ public static Queue<int> FreeRefIndices = new Queue<int> ();
+
+ public static void Unreference (Object o)
{
int idxt = Interface.References.IndexOf (o);
if (idxt < 0)
return;
- References[idxt] = null;
+ References [idxt] = null;
FreeRefIndices.Enqueue (idxt);
}
+
/// <summary> register target object reference in an array for binding CIL </summary>
- public static int Reference(object o)
+ public static int Reference (object o)
{
- int dstIdx = Interface.References.IndexOf(o);
+ int dstIdx = Interface.References.IndexOf (o);
if (dstIdx < 0) {
if (FreeRefIndices.Count == 0) {
- dstIdx = Interface.References.Count();
+ dstIdx = Interface.References.Count ();
Interface.References.Add (o);
} else {
dstIdx = FreeRefIndices.Dequeue ();
}
return dstIdx;
}
- public static LayoutingQueue LayoutingQueue = new LayoutingQueue();
+
+ public static LayoutingQueue LayoutingQueue = new LayoutingQueue ();
#region Load/Save
- internal static Stack<List<DynAttribute>> GOMLResolutionStack = new Stack<List<DynAttribute>>();
- internal static List<DynAttribute> GOMLResolver
- {
- get { return GOMLResolutionStack.Peek ();}
+ internal static Stack<List<DynAttribute>> GOMLResolutionStack = new Stack<List<DynAttribute>> ();
+
+ internal static List<DynAttribute> GOMLResolver {
+ get { return GOMLResolutionStack.Peek (); }
}
//internal static List<DynAttribute> Bindings;
- public static void Save<T>(string file, T graphicObject)
+ public static void Save<T> (string file, T graphicObject)
{
- XmlSerializerNamespaces xn = new XmlSerializerNamespaces();
- xn.Add("", "");
- XmlSerializer xs = new XmlSerializer(typeof(T));
-
- xs = new XmlSerializer(typeof(T));
- using (Stream s = new FileStream(file, FileMode.Create))
- {
- xs.Serialize(s, graphicObject, xn);
+ XmlSerializerNamespaces xn = new XmlSerializerNamespaces ();
+ xn.Add ("", "");
+ XmlSerializer xs = new XmlSerializer (typeof(T));
+
+ xs = new XmlSerializer (typeof(T));
+ using (Stream s = new FileStream (file, FileMode.Create)) {
+ xs.Serialize (s, graphicObject, xn);
}
}
- public static Stream GetStreamFromPath(string path)
+ public static Stream GetStreamFromPath (string path)
{
Stream stream = null;
if (path.StartsWith ("#")) {
string resId = path.Substring (1);
- stream = System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream(resId);
+ stream = System.Reflection.Assembly.GetEntryAssembly ().GetManifestResourceStream (resId);
if (stream == null)//try to find ressource in golib assembly
- stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resId);
+ stream = System.Reflection.Assembly.GetExecutingAssembly ().GetManifestResourceStream (resId);
if (stream == null)
throw new Exception ("Resource not found: " + path);
} else {
}
return stream;
}
+
/// <summary>
/// Pre-read first node to set GraphicObject class for loading
/// and reset stream position to 0
/// </summary>
- public static Type GetTopContainerOfGOMLStream(Stream stream){
+ public static Type GetTopContainerOfGOMLStream (Stream stream)
+ {
string root = "Object";
- stream.Seek(0,SeekOrigin.Begin);
+ string ClassName = "";
+ stream.Seek (0, SeekOrigin.Begin);
using (XmlReader reader = XmlReader.Create (stream)) {
- while (reader.Read()) {
+ while (reader.Read ()) {
// first element is the root element
if (reader.NodeType == XmlNodeType.Element) {
root = reader.Name;
+ ClassName = reader.GetAttribute ("Class");
+ if (!string.IsNullOrEmpty (ClassName))
+ break;
+ if (CurrentGOMLPath.StartsWith ("#"))
+ ClassName = Path.GetFileNameWithoutExtension (CurrentGOMLPath.Substring (1));
+ else
+ ClassName = Path.GetFileNameWithoutExtension (CurrentGOMLPath);
break;
}
}
}
- Type t = Type.GetType("go." + root);
- //var go = Activator.CreateInstance(t);
- stream.Seek(0,SeekOrigin.Begin);
+ Type t = Type.GetType ("go." + root);
+
+ //t = CreateDynamicType (ClassName, t);
+
+ stream.Seek (0, SeekOrigin.Begin);
return t;
}
+
+
+
+
+ static AssemblyBuilder assemblyBuilder;
+ static ModuleBuilder moduleBuilder;
+
+ public static void InitDynamicAssembly ()
+ {
+ AssemblyName an = new AssemblyName ("DynamicGraphicObjects");
+ assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly (an, AssemblyBuilderAccess.RunAndSave);
+ moduleBuilder = assemblyBuilder.DefineDynamicModule ("MainModule");
+ }
+
+ public static void TerminateDynamicAssembly ()
+ {
+ }
+
+ public static CodeCompileUnit CompileUnit;
+ public static CodeTypeDeclaration GOTypeDecl;
+
+ public static CodeTypeDeclaration GenCodeType (string newTypeName, Type baseType)
+ {
+ CompileUnit = new CodeCompileUnit ();
+ CodeNamespace cns = null;
+
+ int idxLastDot = newTypeName.LastIndexOf ('.');
+ string typeName = newTypeName;
+ if (idxLastDot < 0)
+ cns = new CodeNamespace ("go");
+ else {
+ typeName = newTypeName.Substring (idxLastDot + 1);
+ cns = new CodeNamespace (newTypeName.Substring (0, idxLastDot));
+ }
+ CompileUnit.Namespaces.Add (new CodeNamespace ());
+ CompileUnit.Namespaces.Add (cns);
+ CompileUnit.Namespaces [0].Imports.Add (new CodeNamespaceImport ("System"));
+ CodeTypeDeclaration GOTypeDecl = new CodeTypeDeclaration (typeName);
+ GOTypeDecl.IsClass = true;
+ GOTypeDecl.IsPartial = true;
+ GOTypeDecl.TypeAttributes |= TypeAttributes.Public;
+ GOTypeDecl.BaseTypes.Add (baseType.Name);
+ cns.Types.Add (GOTypeDecl);
+ return GOTypeDecl;
+ }
+
+ static void GenNewClassFromGOML (string path)
+ {
+ string root = null;
+ string newClassName = "";
+
+ using (Stream stream = GetStreamFromPath (path)) {
+ using (XmlReader reader = XmlReader.Create (stream)) {
+ CodeTypeDeclaration GOTypeDecl = null;
+ CodeConstructor constructor = null;
+
+ CodeExpression curRef = null;
+ Type curType = null;
+ Stack<CodeExpression> curRefStack = new Stack<CodeExpression> ();
+ Stack<Type> curTypeStack = new Stack<Type> ();
+
+ int arrayIndex = -1;
+ int localVarCpt = 0;
+
+ while (reader.Read ()) {
+ switch (reader.NodeType) {
+ case XmlNodeType.Element:
+ if (string.IsNullOrEmpty (root)) {
+ //create the new base class
+ // first element is the root element
+ root = reader.Name;
+ newClassName = reader.GetAttribute ("Class");
+ if (string.IsNullOrEmpty (newClassName)) {
+ if (path.StartsWith ("#"))
+ newClassName = Path.GetFileNameWithoutExtension (path.Substring (1));
+ else
+ newClassName = Path.GetFileNameWithoutExtension (path);
+ }
+ curType = Type.GetType ("go." + root);
+
+ GOTypeDecl = GenCodeType (newClassName, curType);
+ // Declares a constructor.
+ constructor = new CodeConstructor ();
+ constructor.Attributes = MemberAttributes.Public;
+ GOTypeDecl.Members.Add (constructor);
+
+ curRef = new CodeThisReferenceExpression ();
+ } else if (reader.Name == "Template") {
+ }else{
+ Type childType = Type.GetType ("go." + reader.Name);
+ localVarCpt++;
+ string localVarName = childType.Name + localVarCpt;
+ constructor.Statements.Add (
+ new CodeVariableDeclarationStatement (
+ childType,
+ localVarName,
+ new CodeObjectCreateExpression (childType)
+ )
+ );
+ if (curType == typeof(go.Container) || curType.IsSubclassOf (typeof(go.Container))) {
+ constructor.Statements.Add (
+ new CodeMethodInvokeExpression (
+ curRef,
+ "SetChild",
+ new CodeVariableReferenceExpression (localVarName)
+ )
+ );
+ } else if (curType == typeof(go.Group) || curType.IsSubclassOf (typeof(go.Group))) {
+ constructor.Statements.Add (
+ new CodeMethodInvokeExpression (curRef, "addChild",
+ new CodeVariableReferenceExpression (localVarName)
+ )
+ );
+ }
+ curTypeStack.Push (curType);
+ curRefStack.Push (curRef);
+ curRef = new CodeVariableReferenceExpression (localVarName);
+ curType = childType;
+ }
+ while (reader.MoveToNextAttribute ()) {
+ string attName = reader.Name;
+ string attValue = reader.Value;
+
+ if (string.IsNullOrEmpty (attValue))
+ continue;
+
+ MemberInfo mi = curType.GetMember (attName).FirstOrDefault ();
+ if (mi == null) {
+ Debug.WriteLine (Interface.CurrentGOMLPath + "=>GOML: Unknown attribute in " + curType.ToString () + " : " + attName);
+ continue;
+ }
+ if (mi.MemberType == MemberTypes.Event) {
+ //TODO: handle events
+ continue;
+ }
+ if (mi.MemberType == MemberTypes.Property) {
+ PropertyInfo pi = mi as PropertyInfo;
+
+ if (pi.GetSetMethod () == null) {
+ Debug.WriteLine (Interface.CurrentGOMLPath + "=>GOML: Read only property in " + curType.ToString () + " : " + attName);
+ continue;
+ }
+
+ if (attValue.StartsWith("{")) {
+ if (Interface.DontResoveGOML)
+ continue;
+ //binding
+ if (!attValue.EndsWith("}"))
+ throw new Exception (string.Format("GOML:Malformed binding: {0}", attValue));
+
+ string strBinding = attValue.Substring (1, attValue.Length - 2);
+
+ continue;
+ }
+
+ CodeExpression val = null;
+ if (pi.PropertyType == typeof(string)) {
+ val = new CodePrimitiveExpression (attValue);
+ } else if (pi.PropertyType.IsPrimitive) {
+ MethodInfo me = pi.PropertyType.GetMethod ("Parse", new Type[] { typeof(string) });
+ val = new CodePrimitiveExpression (
+ me.Invoke (null, new string[] { attValue }));
+ } else if (pi.PropertyType.IsEnum || (pi.PropertyType == typeof(go.Color) && Char.IsLetter (attValue [0]))) {
+ val = new CodeFieldReferenceExpression (new CodeTypeReferenceExpression (pi.PropertyType), attValue);
+ }else if (pi.PropertyType == typeof(go.Color) || pi.PropertyType == typeof(go.Font)) {
+ val = new CodeCastExpression(pi.PropertyType,
+ new CodeMethodInvokeExpression (
+ new CodeTypeReferenceExpression (pi.PropertyType),
+ "Parse",
+ new CodePrimitiveExpression (attValue)
+ )
+ );
+ } else {
+ val = new CodeMethodInvokeExpression (new CodeTypeReferenceExpression (pi.PropertyType),
+ "Parse", new CodePrimitiveExpression (attValue));
+
+ }
+ constructor.Statements.Add (
+ new CodeAssignStatement (
+ new CodePropertyReferenceExpression (curRef, attName),
+ val
+ )
+ );
+ }
+ }
+ reader.MoveToElement ();
+ if (reader.IsEmptyElement) {
+ curType = curTypeStack.Pop ();
+ curRef = curRefStack.Pop ();
+ }
+ break;
+ case XmlNodeType.EndElement:
+ if (curTypeStack.Count < 1)//GOML last closing tag
+ break;
+ curType = curTypeStack.Pop ();
+ curRef = curRefStack.Pop ();
+ if (curType.IsSubclassOf (typeof(go.Container)))
+ arrayIndex = -1;
+ break;
+ }
+ }
+ }
+ }
+
+
+
+
+ GenerateCSharpCode (CompileUnit, path + ".cs");
+ }
+
+ static void GenerateCSharpCode (CodeCompileUnit codeBase, string file)
+ {
+ CodeDomProvider codeDomProvider = new CSharpCodeProvider ();
+ //On définit les options de génération de code
+ CodeGeneratorOptions options = new CodeGeneratorOptions ();
+ //On demande a ce que le code généré soit dans le même ordre que le code inséré
+ options.VerbatimOrder = false;
+ //options.BracingStyle = "C";
+ //options.BracingStyle = "C";
+ options.ElseOnClosing = true;
+ options.BlankLinesBetweenMembers = false;
+
+ using (IndentedTextWriter itw = new IndentedTextWriter (new StreamWriter (file, false), "\t")) {
+ //On demande la génération proprement dite
+ codeDomProvider.GenerateCodeFromCompileUnit (codeBase, itw, options);
+ itw.Flush ();
+ }
+ Console.WriteLine ("C# code generated: " + file);
+ }
+
+ public static Type CreateDynamicType (string newTypeName, Type baseType)
+ {
+ if (moduleBuilder == null)
+ InitDynamicAssembly ();
+ TypeBuilder tb = moduleBuilder.DefineType (newTypeName
+ , TypeAttributes.Public |
+ TypeAttributes.Class |
+ TypeAttributes.AutoClass |
+ TypeAttributes.AnsiClass |
+ TypeAttributes.BeforeFieldInit |
+ TypeAttributes.AutoLayout
+ , baseType);
+
+ ConstructorBuilder constructor = tb.DefineDefaultConstructor (MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName);
+
+ ConstructorInfo cn = typeof(XmlRootAttribute).GetConstructor (new Type[] { typeof(string) });
+ CustomAttributeBuilder cab = new CustomAttributeBuilder (cn, new object[] { baseType.Name });
+
+ tb.SetCustomAttribute (cab);
+
+
+
+
+ Type tmp = tb.CreateType ();
+ //assemblyBuilder.Save ("newAssembly.dll",PortableExecutableKinds.ILOnly,ImageFileMachine.I386);
+ return tmp;
+ }
+
public static string CurrentGOMLPath;
- public static GraphicObject Load(string path, object hostClass = null, bool resolveGOML = true)
- {
+
+ public static GraphicObject Load (string path, object hostClass = null, bool resolveGOML = true)
+ {
+// GenNewClassFromGOML (path);
+// return null;
CurrentGOMLPath = path;
using (Stream stream = GetStreamFromPath (path)) {
return Load(stream, GetTopContainerOfGOMLStream(stream), hostClass, resolveGOML);
}
CurrentGOMLPath = "";
}
- public static GraphicObject Load(Stream stream, Type type, object hostClass = null, bool resolve = true)
+
+ public static GraphicObject Load (Stream stream, Type type, object hostClass = null, bool resolve = true)
{
#if DEBUG_LOAD_TIME
Stopwatch loadingTime = new Stopwatch ();
GraphicObject result;
- XmlSerializerNamespaces xn = new XmlSerializerNamespaces();
- xn.Add("", "");
+ XmlSerializerNamespaces xn = new XmlSerializerNamespaces ();
+ xn.Add ("", "");
//prevent unused ref in References created by xmlSerializer
Interface.DontResoveGOML = true;
- XmlSerializer xs = new XmlSerializer(type);
+ XmlSerializer xs = new XmlSerializer (type);
Interface.DontResoveGOML = false;
- GOMLResolutionStack.Push(new List<DynAttribute>());
+ GOMLResolutionStack.Push (new List<DynAttribute> ());
- result = (GraphicObject)xs.Deserialize(stream);
- result.DataSource = hostClass;
+ result = (GraphicObject)xs.Deserialize (stream);
+ //result.DataSource = hostClass;
if (hostClass == null) {
GOMLResolutionStack.Pop ();
#if DEBUG_LOAD_TIME
loadingTime.Stop ();
- Debug.WriteLine("GOML Loading ({2}): {0} ticks \t, {1} ms",
- loadingTime.ElapsedTicks,
- loadingTime.ElapsedMilliseconds,
- CurrentGOMLPath);
+ Debug.WriteLine ("GOML Loading ({2}): {0} ticks \t, {1} ms",
+ loadingTime.ElapsedTicks,
+ loadingTime.ElapsedMilliseconds,
+ CurrentGOMLPath);
#endif
return result;
}
- public static void resolveGOML(object hostClass)
+ public static void resolveGOML (object hostClass)
{
- foreach (DynAttribute es in GOMLResolver)
- {
+ foreach (DynAttribute es in GOMLResolver) {
// if (string.IsNullOrEmpty(es.Value))
// continue;
Type dstType = es.Source.GetType ();
- MemberInfo miTarget = dstType.GetMember (es.MemberName).FirstOrDefault();
+ MemberInfo miTarget = dstType.GetMember (es.MemberName).FirstOrDefault ();
if (miTarget == null) {
Debug.WriteLine ("'{0}' Member not found in '{1}' type.", es.MemberName, dstType.ToString ());
if (mi == null) {
//TODO: hack to have it work, hostClass and dataSource should be clearly separated
mi = OpenTKGameWindow.currentWindow.GetType ().GetMethod (es.Value, BindingFlags.NonPublic | BindingFlags.Public
- | BindingFlags.Instance);
+ | BindingFlags.Instance);
if (mi == null) {
Debug.WriteLine ("Handler Method not found: " + es.Value);
continue;
Delegate del = Delegate.CreateDelegate (ei.EventHandlerType, effectiveHostClass, mi);
- addHandler.Invoke(es.Source, new object[] {del});
+ addHandler.Invoke (es.Source, new object[] { del });
}
} else {
CompilerServices.ResolveBinding (es, hostClass);
}
}
- GOMLResolutionStack.Pop();
+ GOMLResolutionStack.Pop ();
}
+
#endregion
}
}