]> O.S.I.I.S - jp/crow.git/commitdiff
update OpenTKGameWin with shared CrowInterface
authorjpbruyere <jp.bruyere@hotmail.com>
Tue, 1 Mar 2016 03:51:52 +0000 (04:51 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Tue, 1 Mar 2016 04:19:09 +0000 (05:19 +0100)
Crow.sln
GtkCrow/CrowContainer.cs
OTKCrow/OpenTKGameWindow.cs
Tests/GOLIBTests.cs
Tests/GOLIBTestsOTK.cs [new file with mode: 0644]
Tests/Tests.csproj
src/Interface.cs

index 895b825a27e08826f7867452909ea0ed65a57151..ed803ba7f64c4eb9b306d94b202a38564de0660d 100644 (file)
--- a/Crow.sln
+++ b/Crow.sln
@@ -15,8 +15,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OTKCrow", "OTKCrow\OTKCrow.
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GtkCrow", "GtkCrow\GtkCrow.csproj", "{D6F98B08-56B8-405C-9212-F9D26097E35F}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "testGdk", "testGdk\testGdk.csproj", "{AF79108B-C774-4220-8D34-4CC31831E713}"
-EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug|Linux_x86 = Debug|Linux_x86
@@ -36,10 +34,6 @@ Global
                {7BAE4448-E8F4-48B3-BB11-FA78E7F4506B}.Debug|Linux_x86.ActiveCfg = Debug|Any CPU
                {7BAE4448-E8F4-48B3-BB11-FA78E7F4506B}.Debug|Linux_x86.Build.0 = Debug|Any CPU
                {7BAE4448-E8F4-48B3-BB11-FA78E7F4506B}.Release|Linux_x86.ActiveCfg = Release|Any CPU
-               {AF79108B-C774-4220-8D34-4CC31831E713}.Debug|Linux_x86.ActiveCfg = Debug|Linux_x86
-               {AF79108B-C774-4220-8D34-4CC31831E713}.Debug|Linux_x86.Build.0 = Debug|Linux_x86
-               {AF79108B-C774-4220-8D34-4CC31831E713}.Release|Linux_x86.ActiveCfg = Release|Linux_x86
-               {AF79108B-C774-4220-8D34-4CC31831E713}.Release|Linux_x86.Build.0 = Release|Linux_x86
                {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Debug|Linux_x86.ActiveCfg = Debug|Any CPU
                {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Debug|Linux_x86.Build.0 = Debug|Any CPU
                {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Release|Linux_x86.ActiveCfg = Release|Any CPU
index 7ea77d033fd1fce101e32e0182863dcb152f06d7..9fd9a69c40dccb33fbef7a2ad933cf0e4314d84b 100644 (file)
@@ -61,23 +61,20 @@ namespace Crow
 
                        GLib.Idle.Add (new GLib.IdleHandler (idleHandler));
                        GLib.Timeout.Add (10, new GLib.TimeoutHandler (updateHandler));
-                       interval.Start ();
                }
                #endregion
 
 
 
                #region Timers
-               Stopwatch interval = new Stopwatch();
                bool updateHandler(){
                        CrowInterface.Update();
                        return true;
                }
                bool idleHandler(){
-                       if (CrowInterface.IsDirty && interval.ElapsedMilliseconds > 1) {
-                               Debug.WriteLine (interval.ElapsedTicks.ToString ());
+                       if (CrowInterface.IsDirty) {
                                QueueDrawArea (CrowInterface.DirtyRect.X, CrowInterface.DirtyRect.Y, CrowInterface.DirtyRect.Width, CrowInterface.DirtyRect.Height);
-                               interval.Restart ();
+                               return false;
                        }
                        return true;
                }
@@ -243,13 +240,14 @@ namespace Crow
                                }
 
                                CrowInterface.IsDirty = false;
+                               GLib.Idle.Add (new GLib.IdleHandler (idleHandler));
                                return;
                        }
-                       if (CrowInterface.bmp == null)
-                               return;
-                       using (ImageSurface img = new ImageSurface (CrowInterface.bmp, Format.Argb32, CrowInterface.ClientRectangle.Width, CrowInterface.ClientRectangle.Height, 4 * CrowInterface.ClientRectangle.Width)) {
-                               args.Cr.SetSourceSurface (img, CrowInterface.ClientRectangle.X, CrowInterface.ClientRectangle.Y);
-                               args.Cr.Paint();
+                       if (CrowInterface.bmp != null) {
+                               using (ImageSurface img = new ImageSurface (CrowInterface.bmp, Format.Argb32, CrowInterface.ClientRectangle.Width, CrowInterface.ClientRectangle.Height, 4 * CrowInterface.ClientRectangle.Width)) {
+                                       args.Cr.SetSourceSurface (img, CrowInterface.ClientRectangle.X, CrowInterface.ClientRectangle.Y);
+                                       args.Cr.Paint ();
+                               }
                        }
                }
                void Win_DeleteEvent (object o, Gtk.DeleteEventArgs args)
index ae013bd8df73c4e13a9bf8ff09e974184fe7a9da..518c2bc75490fb20c93ee084098ba7ba7d5bdc2c 100644 (file)
@@ -31,157 +31,87 @@ using OpenTK.Graphics.OpenGL;
 
 namespace Crow
 {
-       public class OpenTKGameWindow : GameWindow, ILayoutable, IGOLibHost
+       public class OpenTKGameWindow : GameWindow, IValueChange
     {
-               #region ctor
-//             public OpenTKGameWindow(int _width, int _height, string _title="golib")
-//                     : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 1), _title,
-//                             GameWindowFlags.Fullscreen,
-//                             DisplayDevice.Default,
-//                             3,0,OpenTK.Graphics.GraphicsContextFlags.Default)
-               public OpenTKGameWindow(int _width, int _height, string _title="Crow")
-                       : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 1),
-                               _title,GameWindowFlags.Default,DisplayDevice.GetDisplay(DisplayIndex.Second),
-                               3,3,OpenTK.Graphics.GraphicsContextFlags.Debug)
-//             public OpenTKGameWindow(int _width, int _height, string _title="golib")
-//                     : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), _title)
+               #region IValueChange implementation
+               public event EventHandler<ValueChangeEventArgs> ValueChanged;
+               public virtual void NotifyValueChanged(string MemberName, object _value)
                {
-                       //VSync = VSyncMode.On;
-                       currentWindow = this;
-                       //Load cursors
-                       XCursor.Cross = XCursorFile.Load("#Crow.Images.Icons.Cursors.cross").Cursors[0];
-                       XCursor.Default = XCursorFile.Load("#Crow.Images.Icons.Cursors.arrow").Cursors[0];
-                       XCursor.NW = XCursorFile.Load("#Crow.Images.Icons.Cursors.top_left_corner").Cursors[0];
-                       XCursor.NE = XCursorFile.Load("#Crow.Images.Icons.Cursors.top_right_corner").Cursors[0];
-                       XCursor.SW = XCursorFile.Load("#Crow.Images.Icons.Cursors.bottom_left_corner").Cursors[0];
-                       XCursor.SE = XCursorFile.Load("#Crow.Images.Icons.Cursors.bottom_right_corner").Cursors[0];
-                       XCursor.H = XCursorFile.Load("#Crow.Images.Icons.Cursors.sb_h_double_arrow").Cursors[0];
-                       XCursor.V = XCursorFile.Load("#Crow.Images.Icons.Cursors.sb_v_double_arrow").Cursors[0];
+                       ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value));
                }
                #endregion
 
-               public List<GraphicObject> GraphicObjects = new List<GraphicObject>();
-               public Color Background = Color.Transparent;
+               public Interface CrowInterface;
 
-               internal static OpenTKGameWindow currentWindow;
+               #region FPS
+               int frameCpt = 0;
+               int _fps = 0;
 
-               Rectangles _redrawClip = new Rectangles();//should find another way to access it from child
-               List<GraphicObject> _gobjsToRedraw = new List<GraphicObject>();
-
-               #region IGOLibHost implementation
-               public Rectangles clipping {
-                       get { return _redrawClip; }
-                       set { _redrawClip = value; }
-               }
-               public XCursor MouseCursor {
+               public int fps {
+                       get { return _fps; }
                        set {
-                               if (value == null) {
-                                       Cursor = null;
+                               if (_fps == value)
                                        return;
+
+                               _fps = value;
+
+                               if (_fps > fpsMax) {
+                                       fpsMax = _fps;
+                                       ValueChanged.Raise(this, new ValueChangeEventArgs ("fpsMax", fpsMax));
+                               } else if (_fps < fpsMin) {
+                                       fpsMin = _fps;
+                                       ValueChanged.Raise(this, new ValueChangeEventArgs ("fpsMin", fpsMin));
                                }
-                               Cursor = new MouseCursor
-                                       ((int)value.Xhot, (int)value.Yhot, (int)value.Width, (int)value.Height,value.data);; }
-               }
-               public List<GraphicObject> gobjsToRedraw {
-                       get { return _gobjsToRedraw; }
-                       set { _gobjsToRedraw = value; }
-               }
-               public void AddWidget(GraphicObject g)
-               {
-                       g.Parent = this;
-                       GraphicObjects.Insert (0, g);
 
-                       g.RegisterForLayouting (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 PutOnTop(GraphicObject g)
-               {
-                       if (GraphicObjects.IndexOf(g) > 0)
-                       {
-                               GraphicObjects.Remove(g);
-                               GraphicObjects.Insert(0, g);
-                               //g.registerClipRect ();
+                               ValueChanged.Raise(this, new ValueChangeEventArgs ("fps", _fps));
+                               #if MEASURE_TIME
+                               ValueChanged.Raise (this, new ValueChangeEventArgs ("update",
+                                       this.CrowInterface.updateTime.ElapsedTicks.ToString () + " ticks"));
+                               ValueChanged.Raise (this, new ValueChangeEventArgs ("layouting",
+                                       this.CrowInterface.layoutTime.ElapsedTicks.ToString () + " ticks"));
+                               ValueChanged.Raise (this, new ValueChangeEventArgs ("drawing",
+                                       this.CrowInterface.drawingTime.ElapsedTicks.ToString () + " ticks"));
+                               #endif
                        }
                }
-               public void Quit ()
-               {
-                       this.Exit ();
-               }
 
-               #region focus
-               GraphicObject _activeWidget;    //button is pressed on widget
-               GraphicObject _hoverWidget;             //mouse is over
-               GraphicObject _focusedWidget;   //has keyboard (or other perif) focus
+               public int fpsMin = int.MaxValue;
+               public int fpsMax = 0;
 
-               public GraphicObject activeWidget
+               void resetFps ()
                {
-                       get { return _activeWidget; }
-                       set
-                       {
-                               if (_activeWidget == value)
-                                       return;
-
-                               if (_activeWidget != null)
-                                       _activeWidget.IsActive = false;
-
-                               _activeWidget = value;
-
-                               if (_activeWidget != null)
-                                       _activeWidget.IsActive = true;
-                       }
-               }
-               public GraphicObject hoverWidget
-               {
-                       get { return _hoverWidget; }
-                       set {
-                               if (_hoverWidget == value)
-                                       return;
-                               _hoverWidget = value;
-                       }
-               }
-               public GraphicObject FocusedWidget {
-                       get { return _focusedWidget; }
-                       set {
-                               if (_focusedWidget == value)
-                                       return;
-                               if (_focusedWidget != null)
-                                       _focusedWidget.onUnfocused (this, null);
-                               _focusedWidget = value;
-                               if (_focusedWidget != null)
-                                       _focusedWidget.onFocused (this, null);
-                       }
+                       fpsMin = int.MaxValue;
+                       fpsMax = 0;
+                       _fps = 0;
                }
+               public string update = "";
+               public string drawing = "";
+               public string layouting = "";
                #endregion
 
-               #endregion
-
-               /// <summary> Remove all Graphic objects from top container </summary>
-               public void ClearInterface()
+               #region ctor
+//             public OpenTKGameWindow(int _width, int _height, string _title="golib")
+//                     : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 1), _title,
+//                             GameWindowFlags.Fullscreen,
+//                             DisplayDevice.Default,
+//                             3,0,OpenTK.Graphics.GraphicsContextFlags.Default)
+               public OpenTKGameWindow(int _width, int _height, string _title="Crow")
+                       : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 1),
+                               _title,GameWindowFlags.Default,DisplayDevice.GetDisplay(DisplayIndex.Second),
+                               3,3,OpenTK.Graphics.GraphicsContextFlags.Debug)
+//             public OpenTKGameWindow(int _width, int _height, string _title="golib")
+//                     : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), _title)
                {
-                       int i = 0;
-                       while (GraphicObjects.Count>0) {
-                               //TODO:parent is not reset to null because object will be added
-                               //to ObjectToRedraw list, and without parent, it fails
-                               GraphicObject g = GraphicObjects [i];
-                               g.Visible = false;
-                               g.ClearBinding ();
-                               GraphicObjects.RemoveAt (0);
-                       }
+                       CrowInterface = new Interface ();
+                       CrowInterface.Quit += Quit;
                }
-               public GraphicObject FindByName (string nameToFind)
+               #endregion
+
+               public void Quit (object sender, EventArgs e)
                {
-                       foreach (GraphicObject w in GraphicObjects) {
-                               GraphicObject r = w.FindByName (nameToFind);
-                               if (r != null)
-                                       return r;
-                       }
-                       return null;
+                       this.Exit ();
                }
+
                #region Events
                //those events are raised only if mouse isn't in a graphic object
                public event EventHandler<OpenTK.Input.MouseWheelEventArgs> MouseWheelChanged;
@@ -192,39 +122,15 @@ namespace Crow
                public event EventHandler<OpenTK.Input.KeyboardKeyEventArgs> KeyboardKeyDown;
                #endregion
 
-               #region graphic contexte
-               Context ctx;
-               Surface surf;
-               byte[] bmp;
+               #region graphic context
                int texID;
-
-               public QuadVAO uiQuad, uiQuad2;
+               QuadVAO uiQuad;
                Crow.Shader shader;
                int[] viewport = new int[4];
 
                void createContext()
                {
-                       createOpenGLSurface ();
-
-                       if (uiQuad != null)
-                               uiQuad.Dispose ();
-                       uiQuad = new QuadVAO (0, 0, ClientRectangle.Width, ClientRectangle.Height, 0, 1, 1, -1);
-                       uiQuad2 = new QuadVAO (0, 0, ClientRectangle.Width, ClientRectangle.Height, 0, 0, 1, 1);
-
-                       shader.ProjectionMatrix = Matrix4.CreateOrthographicOffCenter
-                               (0, ClientRectangle.Width, ClientRectangle.Height, 0, 0, 1);
-
-                       clipping.AddRectangle (ClientRectangle);
-               }
-               void createOpenGLSurface()
-               {
-                       currentWindow = this;
-
-                       int stride = 4 * ClientRectangle.Width;
-                       int bmpSize = Math.Abs (stride) * ClientRectangle.Height;
-                       bmp = new byte[bmpSize];
-
-                       //create texture
+                       #region Create texture
                        if (GL.IsTexture(texID))
                                GL.DeleteTexture (texID);
                        GL.GenTextures(1, out texID);
@@ -233,7 +139,7 @@ namespace Crow
 
                        GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba,
                                ClientRectangle.Width, ClientRectangle.Height, 0,
-                               OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp);
+                               OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, CrowInterface.bmp);
 
                        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
@@ -241,6 +147,18 @@ namespace Crow
                        GL.BindTexture(TextureTarget.Texture2D, 0);
 
                        shader.Texture = texID;
+                       #endregion
+
+                       #region Update ui quad
+                       if (uiQuad != null)
+                               uiQuad.Dispose ();
+                       uiQuad = new QuadVAO (0, 0, ClientRectangle.Width, ClientRectangle.Height, 0, 1, 1, -1);
+
+                       shader.ProjectionMatrix = Matrix4.CreateOrthographicOffCenter
+                               (0, ClientRectangle.Width, ClientRectangle.Height, 0, 0, 1);
+                       #endregion
+
+                       //TODO:add maybe clientrectangle to clipping here
                }
                void OpenGLDraw()
                {
@@ -249,18 +167,20 @@ namespace Crow
 
                        shader.Enable ();
 
-                       if (isDirty) {
-                               byte[] tmp = new byte[4 * DirtyRect.Width * DirtyRect.Height];
-                               for (int y = 0; y < DirtyRect.Height; y++) {
-                                       Array.Copy(bmp,
-                                               ((DirtyRect.Top + y) * ClientRectangle.Width * 4) + DirtyRect.Left * 4,
-                                               tmp, y * DirtyRect.Width * 4, DirtyRect.Width *4);
+                       if (CrowInterface.IsDirty) {
+                               byte[] tmp = new byte[4 * CrowInterface.DirtyRect.Width * CrowInterface.DirtyRect.Height];
+                               for (int y = 0; y < CrowInterface.DirtyRect.Height; y++) {
+                                       Array.Copy(CrowInterface.bmp,
+                                               ((CrowInterface.DirtyRect.Top + y) * ClientRectangle.Width * 4) + CrowInterface.DirtyRect.Left * 4,
+                                               tmp, y * CrowInterface.DirtyRect.Width * 4, CrowInterface.DirtyRect.Width *4);
                                }
                                GL.TexSubImage2D (TextureTarget.Texture2D, 0,
-                                       DirtyRect.Left, DirtyRect.Top, DirtyRect.Width, DirtyRect.Height,
+                                       CrowInterface.DirtyRect.Left, CrowInterface.DirtyRect.Top,
+                                       CrowInterface.DirtyRect.Width, CrowInterface.DirtyRect.Height,
                                        OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, tmp);
-                               isDirty = false;
+                               CrowInterface.IsDirty = false;
                        }
+
                        uiQuad.Render (PrimitiveType.TriangleStrip);
 
                        GL.BindTexture(TextureTarget.Texture2D, 0);
@@ -270,96 +190,6 @@ namespace Crow
                }
                #endregion
 
-
-               bool isDirty = false;
-               Rectangle DirtyRect;
-
-               #region update
-               void update ()
-               {
-                       if (mouseRepeatCount > 0) {
-                               int mc = mouseRepeatCount;
-                               mouseRepeatCount -= mc;
-                               for (int i = 0; i < mc; i++) {
-                                       FocusedWidget.onMouseClick (this, new MouseButtonEventArgs (Mouse.X, Mouse.Y, MouseButton.Left, true));
-                               }
-                       }
-
-                       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.IsQueuedForRedraw = false;
-                               p.Parent.RegisterClip (p.LastPaintedSlot);
-                               p.Parent.RegisterClip (p.getSlot());
-                       }
-
-                       using (surf = new ImageSurface (bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height, ClientRectangle.Width * 4)) {
-                               using (ctx = new Context (surf)){
-
-
-                                       if (clipping.count > 0) {
-                                               //Link.draw (ctx);
-                                               clipping.clearAndClip(ctx);
-
-                                               foreach (GraphicObject p in invGOList) {
-                                                       if (!p.Visible)
-                                                               continue;
-                                                       if (!clipping.intersect (p.Slot))
-                                                               continue;
-                                                       ctx.Save ();
-
-                                                       p.Paint (ref ctx);
-
-                                                       ctx.Restore ();
-                                               }
-
-                                               #if DEBUG_CLIP_RECTANGLE
-                                               clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5));
-                                               #endif
-
-                                               if (isDirty)
-                                                       DirtyRect += clipping.Bounds;
-                                               else
-                                                       DirtyRect = clipping.Bounds;
-                                               isDirty = true;
-
-                                               DirtyRect.Left = Math.Max (0, DirtyRect.Left);
-                                               DirtyRect.Top = Math.Max (0, DirtyRect.Top);
-                                               DirtyRect.Width = Math.Min (ClientRectangle.Right, DirtyRect.Width);
-                                               DirtyRect.Height = Math.Min (ClientRectangle.Bottom, DirtyRect.Height);
-
-                                               clipping.Reset ();
-                                       }
-                               }
-                       }
-               }                                               
-               #endregion
-
-               #region loading
-               public GraphicObject LoadInterface (string path)
-               {
-                       GraphicObject tmp = Interface.Load (path, this);
-                       AddWidget (tmp);
-                       return tmp;
-               }
-               #endregion
-
                public virtual void OnRender(FrameEventArgs e)
                {
                }
@@ -369,27 +199,9 @@ namespace Crow
                }
 
                #region Game win overrides
-               protected override void OnUpdateFrame(FrameEventArgs e)
-               {
-                       base.OnUpdateFrame(e);
-                       update ();
-               }
-               protected override void OnRenderFrame(FrameEventArgs e)
-               {
-                       GLClear ();
-
-
-                       base.OnRenderFrame(e);
-
-                       OnRender (e);
-                       OpenGLDraw ();
-
-
-                       SwapBuffers ();
-               }
                protected override void OnLoad(EventArgs e)
-       {
-           base.OnLoad(e);
+               {
+                       base.OnLoad(e);
 
                        Keyboard.KeyDown += new EventHandler<OpenTK.Input.KeyboardKeyEventArgs>(Keyboard_KeyDown);
                        Mouse.WheelChanged += new EventHandler<OpenTK.Input.MouseWheelEventArgs>(Mouse_WheelChanged);
@@ -407,13 +219,44 @@ namespace Crow
 
                        shader = new Crow.TexturedShader ();
                }
+               protected override void OnUpdateFrame(FrameEventArgs e)
+               {
+                       base.OnUpdateFrame(e);
+                       fps = (int)RenderFrequency;
+
+
+                       if (frameCpt > 50) {
+                               resetFps ();
+                               frameCpt = 0;
+                               GC.Collect();
+                               GC.WaitForPendingFinalizers();
+                               NotifyValueChanged("memory", GC.GetTotalMemory (false).ToString());
+                       }
+                       frameCpt++;
+                       CrowInterface.Update ();
+               }
+               protected override void OnRenderFrame(FrameEventArgs e)
+               {
+                       GLClear ();
+
+                       base.OnRenderFrame(e);
+
+                       OnRender (e);
+                       OpenGLDraw ();
+
+                       SwapBuffers ();
+               }
 
                protected override void OnResize(EventArgs e)
                {
                        base.OnResize (e);
+                       CrowInterface.ProcessResize(
+                               new Rectangle(
+                               this.ClientRectangle.X,
+                               this.ClientRectangle.Y,
+                               this.ClientRectangle.Width,
+                               this.ClientRectangle.Height));
                        createContext ();
-                       foreach (GraphicObject g in GraphicObjects)
-                               g.RegisterForLayouting (LayoutingType.All);
                }
                #endregion
 
@@ -425,149 +268,21 @@ namespace Crow
                        }
                }
                void Mouse_Move(object sender, OpenTK.Input.MouseMoveEventArgs otk_e)
-       {
-                       MouseMoveEventArgs e = new MouseMoveEventArgs (otk_e.X, otk_e.Y, otk_e.XDelta, otk_e.YDelta);
-                       MouseState ms = e.Mouse;
-                       update_mouseButtonStates (ref ms, otk_e.Mouse);
-                       e.Mouse = ms;
-
-                       if (_activeWidget != null) {
-                               //first, ensure object is still in the graphic tree
-                               if (_activeWidget.HostContainer == null) {
-                                       activeWidget = null;
-                               } else {
-
-                                       //send move evt even if mouse move outside bounds
-                                       _activeWidget.onMouseMove (this, e);
-                                       return;
-                               }
-                       }
-
-                       if (hoverWidget != null) {
-                               //first, ensure object is still in the graphic tree
-                               if (hoverWidget.HostContainer == null) {
-                                       hoverWidget = null;
-                               } else {
-                                       //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, otk_e);
-       }
+        {
+                       CrowInterface.ProcessMouseMove (otk_e.X, otk_e.Y);
+        }
                void Mouse_ButtonUp(object sender, OpenTK.Input.MouseButtonEventArgs otk_e)
-       {
-                       MouseButtonEventArgs e = new MouseButtonEventArgs (otk_e.X, otk_e.Y, (Crow.MouseButton)otk_e.Button, otk_e.IsPressed);
-                       MouseState ms = e.Mouse;
-                       update_mouseButtonStates (ref ms, otk_e.Mouse);
-                       e.Mouse = ms;
-
-                       if (_activeWidget == null) {
-                               MouseButtonUp.Raise (this, otk_e);
-                               return;
-                       }
-
-                       if (mouseRepeatThread != null) {
-                               mouseRepeatOn = false;
-                               mouseRepeatThread.Abort();
-                               mouseRepeatThread.Join ();
-                       }
-
-                       _activeWidget.onMouseUp (this, e);
-                       activeWidget = null;
-       }
+        {
+                       CrowInterface.ProcessMouseButtonUp ((int)otk_e.Button);
+        }
                void Mouse_ButtonDown(object sender, OpenTK.Input.MouseButtonEventArgs otk_e)
                {
-                       MouseButtonEventArgs e = new MouseButtonEventArgs (otk_e.X, otk_e.Y, (Crow.MouseButton)otk_e.Button, otk_e.IsPressed);
-                       MouseState ms = e.Mouse;
-                       update_mouseButtonStates (ref ms, otk_e.Mouse);
-                       e.Mouse = ms;
-
-                       if (hoverWidget == null) {
-                               MouseButtonDown.Raise (this, otk_e);
-                               return;
-                       }
-
-                       hoverWidget.onMouseDown(hoverWidget,new BubblingMouseButtonEventArg(e));
-
-                       if (FocusedWidget == null)
-                               return;
-                       if (!FocusedWidget.MouseRepeat)
-                               return;
-                       mouseRepeatThread = new Thread (mouseRepeatThreadFunc);
-                       mouseRepeatThread.Start ();
-       }
+                       CrowInterface.ProcessMouseButtonDown ((int)otk_e.Button);
+        }
                void Mouse_WheelChanged(object sender, OpenTK.Input.MouseWheelEventArgs otk_e)
-       {
-                       MouseWheelEventArgs e = new MouseWheelEventArgs (otk_e.X, otk_e.Y, otk_e.Value, otk_e.Delta);
-                       MouseState ms = e.Mouse;
-                       update_mouseButtonStates (ref ms, otk_e.Mouse);
-                       e.Mouse = ms;
-
-                       if (hoverWidget == null) {
-                               MouseWheelChanged.Raise (this, otk_e);
-                               return;
-                       }
-                       hoverWidget.onMouseWheel (this, e);
-       }
-
-               volatile bool mouseRepeatOn;
-               volatile int mouseRepeatCount;
-               Thread mouseRepeatThread;
-               void mouseRepeatThreadFunc()
-               {
-                       mouseRepeatOn = true;
-                       Thread.Sleep (Interface.DeviceRepeatDelay);
-                       while (mouseRepeatOn) {
-                               mouseRepeatCount++;
-                               Thread.Sleep (Interface.DeviceRepeatInterval);
-                       }
-                       mouseRepeatCount = 0;
-               }
+        {
+                       CrowInterface.ProcessMouseWheelChanged (otk_e.DeltaPrecise);
+        }
                #endregion
 
        #region keyboard Handling
@@ -580,45 +295,7 @@ namespace Crow
 //                     }
                        Keyboad.SetKeyState ((Crow.Key)otk_e.Key, true);
                        KeyboardKeyEventArgs e = new KeyboardKeyEventArgs((Crow.Key)otk_e.Key, otk_e.IsRepeat,Keyboad);
-                       _focusedWidget.onKeyDown (sender, e);
-       }
-       #endregion
-
-               #region ILayoutable implementation
-               public void RegisterClip(Rectangle r){
-                       clipping.AddRectangle (r);
-               }
-               public bool ArrangeChildren { get { return false; }}
-               public int LayoutingTries {
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
-               }
-               public LayoutingType RegisteredLayoutings {
-                       get { return LayoutingType.None; }
-                       set { throw new NotImplementedException (); }
-               }
-               public void RegisterForLayouting (LayoutingType layoutType) { throw new NotImplementedException (); }
-               public bool UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); }
-               public Rectangle ContextCoordinates (Rectangle r) => r;
-               public Rectangle ScreenCoordinates (Rectangle r) => r;
-
-               public ILayoutable Parent {
-                       get { return null; }
-                       set { throw new NotImplementedException (); }
-               }
-               public ILayoutable LogicalParent {
-                       get { return null; }
-                       set { throw new NotImplementedException (); }
-               }
-
-               Rectangle ILayoutable.ClientRectangle {
-                       get { return new Size(this.ClientRectangle.Size.Width,this.ClientRectangle.Size.Height); }
-               }
-               public IGOLibHost HostContainer {
-                       get { return this; }
-               }
-               public Rectangle getSlot () => ClientRectangle;
-               public Rectangle getBounds () => ClientRectangle;
-               #endregion
+        }
+        #endregion
     }
 }
index 8c504a7ba32f57dbeb00e349825350488568e9fe..53f36590b4828e6b00362fc562aa58efede47037 100644 (file)
@@ -66,6 +66,11 @@ namespace test
                        "testPopper.goml",
                        "testTextBox.crow",
                        "testColorList.crow",
+//                     "5.crow",
+//                     "testCombobox.goml",
+//                     "testPopper.goml",
+                       "testTextBox.crow",
+//                     "testColorList.crow",
                        "4.crow",
                        "testSpinner.goml",
                        "testScrollbar.goml",
diff --git a/Tests/GOLIBTestsOTK.cs b/Tests/GOLIBTestsOTK.cs
new file mode 100644 (file)
index 0000000..4256120
--- /dev/null
@@ -0,0 +1,216 @@
+#define MONO_CAIRO_DEBUG_DISPOSE
+
+
+using System;
+using System.Runtime.InteropServices;
+using OpenTK;
+using OpenTK.Graphics.OpenGL;
+
+using System.Diagnostics;
+
+//using GGL;
+using Crow;
+using System.Threading;
+using System.Collections.Generic;
+using System.Linq;
+
+
+namespace testOTK
+{
+       class GOLIBTests : OpenTKGameWindow
+       {
+               public GOLIBTests ()
+                       : base(800, 600,"test: press spacebar to toogle test files")
+               {
+                       VSync = VSyncMode.Off;
+                       Interface.CurrentInterface = CrowInterface;
+               }
+
+               int frameCpt = 0;
+               int idx = 0;
+               string[] testFiles = {
+                       "testColorList.crow",
+                       "testCheckbox.goml",
+                       "testWindow.goml",
+                       "fps.goml",
+                       "testTabView.crow",
+                       "testExpandable.goml",
+                       "0.crow",
+                       "testImage.crow",
+                       "testOutOfClipUpdate.crow",
+//                     "test_Listbox.goml",
+//                     "testTreeView.crow",
+                       "1.crow",
+                       "clip4.crow",
+                       "clip3.crow",
+                       "clip2.crow",
+                       "clip0.crow",
+                       "clip1.crow",
+//                     "5.crow",
+//                     "testCombobox.goml",
+//                     "testPopper.goml",
+                       "testTextBox.crow",
+
+                       "4.crow",
+                       "testSpinner.goml",
+                       "testScrollbar.goml",
+                       "testGroupBox.goml",
+                       "testGrid.goml",
+                       "testButton.crow",
+                       "testBorder.goml",
+//                     "testButton2.crow",
+                       "test2WayBinding.crow",
+                       "test4.goml",
+                       "2.crow",
+                       "test1.goml",
+                       "testWindow2.goml",
+
+                       "testWindow3.goml",
+                       "testLabel.goml",
+                       "testAll.goml",
+//                     "testSpinner.goml",
+//                     "testRadioButton2.goml",
+                       "testContainer.goml",
+                       "testRadioButton.goml",
+                       "testMsgBox.goml",
+//                     "testMeter.goml",
+               };
+
+
+               public int intValue = 25;
+
+               public int IntValue {
+                       get {
+                               return intValue;
+                       }
+                       set {
+                               intValue = value;
+                               NotifyValueChanged ("IntValue", intValue);
+                       }
+               }
+               void onSpinnerValueChange(object sender, ValueChangeEventArgs e){
+                       if (e.MemberName != "Value")
+                               return;
+                       intValue = Convert.ToInt32(e.NewValue);
+               }
+               void change_alignment(object sender, EventArgs e){
+                       RadioButton rb = sender as RadioButton;
+                       if (rb == null)
+                               return;
+                       NotifyValueChanged ("alignment", Enum.Parse(typeof(Alignment), rb.Caption));
+               }
+               public IList<String> List2 = new List<string>(new string[]
+                       {
+                               "string1",
+                               "string2",
+                               "string3",
+                               "string4",
+                               "string5",
+                               "string6",
+                               "string7",
+                               "string8",
+                               "string8",
+                               "string8",
+                               "string8",
+                               "string8",
+                               "string8",
+                               "string9"
+                       }
+               );
+               IList<Color> testList = Color.ColorDic.ToList();
+               public IList<Color> TestList {
+                       set{
+                               testList = value;
+                               NotifyValueChanged ("TestList", testList);
+                       }
+                       get { return testList; }
+               }
+               void OnClear (object sender, MouseButtonEventArgs e) => TestList = null;
+
+               void OnLoadList (object sender, MouseButtonEventArgs e) => TestList = Color.ColorDic.ToList();
+
+               protected override void OnLoad (EventArgs e)
+               {
+                       base.OnLoad (e);
+                       //this.AddWidget(new test4());
+                       KeyboardKeyDown += GOLIBTests_KeyboardKeyDown1;;
+
+                       GraphicObject obj = CrowInterface.LoadInterface("Interfaces/" + testFiles[idx]);
+                       obj.DataSource = this;
+
+               }
+               void GOLIBTests_KeyboardKeyDown1 (object sender, OpenTK.Input.KeyboardKeyEventArgs e)
+               {
+                       if (e.Key == OpenTK.Input.Key.Escape) {
+                               Quit (null, null);
+                               return;
+                       } else if (e.Key == OpenTK.Input.Key.L) {
+                               TestList.Add ("new string");
+                               NotifyValueChanged ("TestList", TestList);
+                               return;
+                       } else if (e.Key == OpenTK.Input.Key.W) {
+                               GraphicObject w = CrowInterface.LoadInterface("Interfaces/testWindow.goml");
+                               w.DataSource = this;
+                               return;
+                       }
+                       CrowInterface.ClearInterface ();
+                       idx++;
+                       if (idx == testFiles.Length)
+                               idx = 0;
+                       this.Title = testFiles [idx];
+                       GraphicObject obj = CrowInterface.LoadInterface("Interfaces/" + testFiles[idx]);
+                       obj.DataSource = this;
+               }
+
+//             protected override void OnUpdateFrame (FrameEventArgs e)
+//             {
+//                     //if (frameCpt % 8 == 0)
+//                             base.OnUpdateFrame (e);
+//
+//                     fps = (int)RenderFrequency;
+//
+//
+//                     if (frameCpt > 50) {
+//                             resetFps ();
+//                             frameCpt = 0;
+//                             GC.Collect();
+//                             GC.WaitForPendingFinalizers();
+//                             NotifyValueChanged("memory", GC.GetTotalMemory (false).ToString());
+//                     }
+//                     frameCpt++;
+//             }
+               void onButClick(object send, MouseButtonEventArgs e)
+               {
+                       Console.WriteLine ("button clicked:" + send.ToString());
+               }
+               void onAddTabButClick(object sender, MouseButtonEventArgs e){
+
+                       TabView tv = CrowInterface.FindByName("tabview1") as TabView;
+                       if (tv == null)
+                               return;
+                       tv.AddChild (new TabItem () { Caption = "NewTab" });
+               }
+               [STAThread]
+               static void Main ()
+               {
+                       Console.WriteLine ("starting example");
+                       GOLIBTests win = new GOLIBTests ();
+                       win.Run (30);
+                       //win.KeyPressEvent += win.Win_KeyPressEvent;
+               }
+
+               void Win_KeyPressEvent (object o, Gtk.KeyPressEventArgs args)
+               {
+                       CrowInterface.ClearInterface ();
+                       idx++;
+                       if (idx == testFiles.Length)
+                               idx = 0;
+                       this.Title = testFiles [idx];
+                       GraphicObject obj = CrowInterface.LoadInterface("Interfaces/" + testFiles[idx]);
+                       obj.DataSource = this;
+               }
+
+
+
+       }
+}
\ No newline at end of file
index ec90518c498b36040ff0c9485cd06cb40df0b22a..1c1bf659dd657e233d73c6ce0bbe9dc95b5252f7 100644 (file)
@@ -8,7 +8,7 @@
     <OutputType>Exe</OutputType>
     <RootNamespace>Tests</RootNamespace>
     <AssemblyName>Tests</AssemblyName>
-    <StartupObject>test.GOLIBTests</StartupObject>
+    <StartupObject>testOTK.GOLIBTests</StartupObject>
     <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
     <OutputPath>..\bin\$(configuration)</OutputPath>
     <IntermediateOutputPath>obj\$(configuration)</IntermediateOutputPath>
@@ -61,7 +61,6 @@
     </Reference>
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="GOLIBTests.cs" />
     <Compile Include="Interfaces\testBorder.goml.cs" />
     <Compile Include="..\bin\Debug\Interfaces\testContainer.goml.cs">
       <Link>Interfaces\testContainer.goml.cs</Link>
@@ -69,6 +68,7 @@
     <Compile Include="..\bin\Debug\Interfaces\test_stack.goml.cs">
       <Link>Interfaces\test_stack.goml.cs</Link>
     </Compile>
+    <Compile Include="GOLIBTestsOTK.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="image\u.svg">
     <None Include="Interfaces\6.crow">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="GOLIBTests.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Interfaces\" />
       <Project>{C2980F9B-4798-4C05-99E2-E174810F7C7B}</Project>
       <Name>Crow</Name>
     </ProjectReference>
-    <ProjectReference Include="..\GtkCrow\GtkCrow.csproj">
-      <Project>{D6F98B08-56B8-405C-9212-F9D26097E35F}</Project>
-      <Name>GtkCrow</Name>
+    <ProjectReference Include="..\OTKCrow\OTKCrow.csproj">
+      <Project>{350D4F49-9901-4998-9903-BCA7D48DA58C}</Project>
+      <Name>OTKCrow</Name>
     </ProjectReference>
   </ItemGroup>
 </Project>
index 352f2a1a2d594961fc1a4bdc6fe9cafe65f14c11..53417ee456b09368b07505d73e2a298757e90649 100644 (file)
@@ -304,9 +304,13 @@ namespace Crow
                        gobjsToRedraw.CopyTo (gotr);
                        gobjsToRedraw.Clear ();
                        foreach (GraphicObject p in gotr) {
-                               p.IsQueuedForRedraw = false;
-                               p.Parent.RegisterClip (p.LastPaintedSlot);
-                               p.Parent.RegisterClip (p.getSlot());
+                               try {
+                                       p.IsQueuedForRedraw = false;
+                                       p.Parent.RegisterClip (p.LastPaintedSlot);
+                                       p.Parent.RegisterClip (p.getSlot());
+                               } catch (Exception ex) {
+                                       Debug.WriteLine ("Error Register Clip: " + ex.ToString ());
+                               }
                        }
 
                        #if MEASURE_TIME
@@ -561,14 +565,19 @@ namespace Crow
                        mouseRepeatThread.Start ();
                        return true;
                }
-//             public bool ProcessMouseWheelChanged(int delta)
-//             {
-//                     if (hoverWidget == null)
-//                             return false;
-//                     hoverWidget.onMouseWheel (this, e);
-//                     return true;
-//             }
+               public bool ProcessMouseWheelChanged(float delta)
+               {
+                       Mouse.SetScrollRelative (0, delta);
+                       MouseWheelEventArgs e = new MouseWheelEventArgs () { Mouse = Mouse, DeltaPrecise = delta };
 
+                       if (hoverWidget == null)
+                               return false;
+                       hoverWidget.onMouseWheel (this, e);
+                       return true;
+               }
+//             public bool ProcessKeyDown(int Key){
+//
+//             }
                volatile bool mouseRepeatOn;
                volatile int mouseRepeatCount;
                Thread mouseRepeatThread;