From: jpbruyere Date: Fri, 21 Aug 2015 11:31:52 +0000 (+0200) Subject: Documentation, analog meter tests X-Git-Tag: 0.2~71 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=24c01f34ad393be4da4af6b25a37e434cbc9cd44;p=jp%2Fcrow.git Documentation, analog meter tests --- diff --git a/GOLib.csproj b/GOLib.csproj index 341b5257..101fa57f 100644 --- a/GOLib.csproj +++ b/GOLib.csproj @@ -178,5 +178,7 @@ + + diff --git a/Images/meter.svg b/Images/meter.svg new file mode 100755 index 00000000..cc3d4e90 --- /dev/null +++ b/Images/meter.svg @@ -0,0 +1,584 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MonoDevelop.GOLib/MonoDevelop.GOLib.csproj b/MonoDevelop.GOLib/MonoDevelop.GOLib.csproj index b780e2d7..845ec7d7 100644 --- a/MonoDevelop.GOLib/MonoDevelop.GOLib.csproj +++ b/MonoDevelop.GOLib/MonoDevelop.GOLib.csproj @@ -86,37 +86,16 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - + diff --git a/Templates/AnalogMeter0.goml b/Templates/AnalogMeter0.goml new file mode 100755 index 00000000..e3259f6d --- /dev/null +++ b/Templates/AnalogMeter0.goml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Tests/GOLIBTest_4.cs b/Tests/GOLIBTest_4.cs index 3fb79fff..24cffc98 100644 --- a/Tests/GOLIBTest_4.cs +++ b/Tests/GOLIBTest_4.cs @@ -135,8 +135,8 @@ namespace test } ); i++; -// if (i > 150) -// break; + if (i > 150) + break; } ValueChanged.Raise(this, new ValueChangeEventArgs ("TestList", TestList)); } diff --git a/Tests/GOLIBTest_TypeViewer.cs b/Tests/GOLIBTest_TypeViewer.cs new file mode 100644 index 00000000..26f8c7cf --- /dev/null +++ b/Tests/GOLIBTest_TypeViewer.cs @@ -0,0 +1,54 @@ +#define MONO_CAIRO_DEBUG_DISPOSE + + +using System; +using System.Runtime.InteropServices; +using OpenTK; +using OpenTK.Graphics.OpenGL; +using OpenTK.Input; + +using System.Diagnostics; + +//using GGL; +using go; +using System.Threading; + + +namespace test +{ + class GOLIBTest_TypeViewer : OpenTKGameWindow + { + public GOLIBTest_TypeViewer () + : base(1024, 600,"test") + {} + + Border g; + Type type; + + protected override void OnLoad (EventArgs e) + { + base.OnLoad (e); + type = typeof (GraphicObject); + + this.AddWidget(Interface.Load ("Interfaces/testTypeViewer.goml", type)); + //LoadInterface("Interfaces/testTypeViewer.goml", out g); + } + + protected override void OnRenderFrame (FrameEventArgs e) + { + GL.Clear (ClearBufferMask.ColorBufferBit); + base.OnRenderFrame (e); + SwapBuffers (); + } + + [STAThread] + static void Main () + { + Console.WriteLine ("starting example"); + + using (GOLIBTest_TypeViewer win = new GOLIBTest_TypeViewer( )) { + win.Run (30.0); + } + } + } +} \ No newline at end of file diff --git a/Tests/GOLIBTest_fps.cs b/Tests/GOLIBTest_fps.cs index e2bf3ef7..fd7ccf53 100644 --- a/Tests/GOLIBTest_fps.cs +++ b/Tests/GOLIBTest_fps.cs @@ -123,7 +123,7 @@ namespace test Console.WriteLine ("starting example"); using (GOLIBTest_fps win = new GOLIBTest_fps( )) { - win.Run (30.0); + win.Run (60.0); } } } diff --git a/Tests/GOLIBTest_meter.cs b/Tests/GOLIBTest_meter.cs new file mode 100644 index 00000000..33669d7e --- /dev/null +++ b/Tests/GOLIBTest_meter.cs @@ -0,0 +1,110 @@ +#define MONO_CAIRO_DEBUG_DISPOSE + + +using System; +using System.Runtime.InteropServices; +using OpenTK; +using OpenTK.Graphics.OpenGL; +using OpenTK.Input; + +using System.Diagnostics; + +//using GGL; +using go; +using System.Threading; + + +namespace test +{ + class GOLIBTest_meter : OpenTKGameWindow, IValueChange + { + public GOLIBTest_meter () + : base(1024, 600,"test") + {} + + #region IValueChange implementation + public event EventHandler ValueChanged; + #endregion + + #region FPS + int _fps = 0; + + public int fps { + get { return _fps; } + set { + 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)); + } + + if (ValueChanged != null) + ValueChanged.Raise(this, new ValueChangeEventArgs ("fps", _fps)); + } + } + string name = "testName"; + + public string Name { + get { + return name; + } + set { + name = value; + } + } + + public int fpsMin = int.MaxValue; + public int fpsMax = 0; + + void resetFps () + { + fpsMin = int.MaxValue; + fpsMax = 0; + _fps = 0; + } + #endregion + AnalogMeter g; + + protected override void OnLoad (EventArgs e) + { + base.OnLoad (e); + LoadInterface("Interfaces/testMeter.goml", out g); + } + + protected override void OnRenderFrame (FrameEventArgs e) + { + GL.Clear (ClearBufferMask.ColorBufferBit); + base.OnRenderFrame (e); + SwapBuffers (); + } + private int frameCpt = 0; + protected override void OnUpdateFrame (FrameEventArgs e) + { + base.OnUpdateFrame (e); + + fps = (int)RenderFrequency; + + if (frameCpt > 200) { + resetFps (); + frameCpt = 0; + } + frameCpt++; + } + [STAThread] + static void Main () + { + Console.WriteLine ("starting example"); + + using (GOLIBTest_meter win = new GOLIBTest_meter( )) { + win.Run (30.0); + } + } + } +} \ No newline at end of file diff --git a/Tests/Interfaces/testMeter.goml b/Tests/Interfaces/testMeter.goml new file mode 100755 index 00000000..1260e764 --- /dev/null +++ b/Tests/Interfaces/testMeter.goml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/Tests/Interfaces/testTypeViewer.goml b/Tests/Interfaces/testTypeViewer.goml new file mode 100755 index 00000000..c4438c48 --- /dev/null +++ b/Tests/Interfaces/testTypeViewer.goml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index b232c4e3..17d12993 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -8,7 +8,7 @@ Exe Tests Tests - test.GOLIBTest_4 + test.GOLIBTest_TypeViewer v4.5 ..\bin\$(configuration) obj\$(configuration) @@ -45,7 +45,6 @@ - @@ -61,6 +60,9 @@ + + + @@ -123,6 +125,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + diff --git a/src/GraphicObjects/AnalogMeter.cs b/src/GraphicObjects/AnalogMeter.cs index dd248cee..bf7f1c24 100644 --- a/src/GraphicObjects/AnalogMeter.cs +++ b/src/GraphicObjects/AnalogMeter.cs @@ -5,6 +5,7 @@ using Cairo; namespace go { + [DefaultTemplate("#go.Templates.AnalogMeter0.goml")] public class AnalogMeter : NumericControl { #region CTOR @@ -20,29 +21,34 @@ namespace go protected override void loadTemplate (GraphicObject template = null) { - throw new NotImplementedException (); + base.loadTemplate (template); } #endregion #region GraphicObject Overrides protected override void onDraw (Context gr) - { + { base.onDraw (gr); Rectangle r = ClientRectangle; Point m = r.Center; + gr.Save (); + + double aUnit = Math.PI*2.0 / (Maximum - Minimum); - gr.Translate (m.X, m.Y); - gr.Rotate (Value * aUnit); + gr.Translate (m.X, r.Height *1.1); + gr.Rotate (Value/4.0 * aUnit - Math.PI/4.0); gr.Translate (-m.X, -m.Y); gr.LineWidth = 2; gr.Color = Foreground; - gr.MoveTo (m); - gr.LineTo (m.X, 0); + gr.MoveTo (m.X,0.0); + gr.LineTo (m.X, -m.Y*0.5); gr.Stroke (); + + gr.Restore (); } #endregion } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index cb26bca8..4e13b34d 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -130,7 +130,7 @@ namespace go NotifyValueChanged("Name", _verticalAlignment); } } - [XmlAttributeAttribute()][DefaultValue(VerticalAlignment.Center)] + [XmlAttributeAttribute ()][DefaultValue(VerticalAlignment.Center)] public virtual VerticalAlignment VerticalAlignment { get { return _verticalAlignment; } set { @@ -275,6 +275,7 @@ namespace go get { return _hasFocus; } set { _hasFocus = value; } } + //TODO: only used in group, should be removed from base go object [XmlIgnore]public virtual bool DrawingIsValid { get { return bmp == null ? false : @@ -299,6 +300,10 @@ namespace go } #endregion + /// + /// allow selection of svg subobject to draw in goml, should be improved + /// ex: allow access to backgroundImage.subimg from goml + /// public string BackImgSub = null; /// @@ -368,32 +373,42 @@ namespace go bmp = null; if (TopContainer != null) TopContainer.gobjsToRedraw.Add (this); - //RegisterForLayouting (); - //registerForRedraw (); - //Interface.registerForGraphicUpdate(this); } /// /// Add clipping region in redraw list of interface, dont update cached object content /// public virtual void RegisterForRedraw () { - bmp = null; TopContainer.gobjsToRedraw.Add (this); } + /// + /// keep last slot components for each layouting pass to track + /// changes and trigger update of other component accordingly + /// public Rectangle LastSlots; + /// + /// keep last slot painted on screen to clear traces if moved or resized + /// TODO: we should ensure the whole parsed widget tree is the last painted + /// version to clear effective oldslot if parents have been moved or resized. + /// IDEA is to add a ScreenCoordinates function that use only lastPaintedSlots + /// public Rectangle LastPaintedSlot; public virtual void registerClipRect() { TopContainer.redrawClip.AddRectangle (ScreenCoordinates(Slot)); + //this clipping should take only last painted slots in ancestor tree which + //is not the case for now. TopContainer.redrawClip.AddRectangle (ScreenCoordinates(LastPaintedSlot)); } + /// return size of content + margins protected virtual Size measureRawSize () { return Bounds.Size; } - + /// clear current layoutingQueue items for object and + /// trigger a new layouting pass for a layoutType public virtual void RegisterForLayouting(int layoutType) { if (Parent == null) @@ -439,6 +454,7 @@ namespace go } + /// trigger dependant sizing component update protected virtual void OnLayoutChanges(LayoutingType layoutType) { switch (layoutType) { @@ -465,6 +481,8 @@ namespace go } LayoutChanged.Raise (this, new LayoutChangeEventArgs (layoutType)); } + /// Update layout component, this is where the computation of alignement + /// and size take place public virtual void UpdateLayout (LayoutingType layoutType) { switch (layoutType) { @@ -572,6 +590,7 @@ namespace go this.RegisterForRedraw (); } + /// This is the common overridable drawing routine to create new widget protected virtual void onDraw(Context gr) { Rectangle rBack = new Rectangle (Slot.Size); @@ -586,6 +605,9 @@ namespace go BackgroundImage.Paint (gr, rBack, BackImgSub); } + /// + /// Interfal drawing context creation on a chached surface limited to slot size + /// this trigger the effective drawing routine protected virtual void UpdateGraphic () { LastPaintedSlot = Slot; @@ -605,7 +627,8 @@ namespace go //draw.WriteToPng ("/mnt/data/test.png"); } } - + /// Chained painting routine on the parent context of the actual cached version + /// of the widget public virtual void Paint (ref Context ctx, Rectangles clip = null) { if (!Visible) diff --git a/src/GraphicObjects/NumericControl.cs b/src/GraphicObjects/NumericControl.cs index d989f668..d22180be 100644 --- a/src/GraphicObjects/NumericControl.cs +++ b/src/GraphicObjects/NumericControl.cs @@ -20,8 +20,6 @@ namespace go } #endregion - - #region private fields double _actualValue, minValue, maxValue, smallStep, bigStep; #endregion @@ -38,7 +36,7 @@ namespace go } } - [XmlAttributeAttribute()][DefaultValue(10.0)] + [XmlAttributeAttribute()][DefaultValue(100.0)] public virtual double Maximum { get { return maxValue; } @@ -50,7 +48,7 @@ namespace go } } - [XmlAttributeAttribute()][DefaultValue(0.5)] + [XmlAttributeAttribute()][DefaultValue(1.0)] public virtual double SmallIncrement { get { return smallStep; } @@ -62,7 +60,7 @@ namespace go } } - [XmlAttributeAttribute()][DefaultValue(2.0)] + [XmlAttributeAttribute()][DefaultValue(5.0)] public virtual double LargeIncrement { get { return bigStep; } diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs index b19c93ca..a413da94 100644 --- a/src/GraphicObjects/Scroller.cs +++ b/src/GraphicObjects/Scroller.cs @@ -76,8 +76,8 @@ namespace go [XmlIgnore] public int MaximumScroll { get { - return VerticalScrolling ? - Child.Slot.Height - ClientRectangle.Height : + return VerticalScrolling ? + child == null ? 0 : Child.Slot.Height - ClientRectangle.Height : Child.Slot.Width - ClientRectangle.Width; } } @@ -134,9 +134,6 @@ namespace go if (VerticalScrolling ) { - //add redraw call with old bounds to errase old position - RegisterForRedraw(); - ScrollY -= e.Delta * ScrollSpeed; if (ScrollY < 0.0) @@ -147,9 +144,6 @@ namespace go } if (HorizontalScrolling ) { - //add redraw call with old bounds to errase old position - RegisterForRedraw(); - ScrollX -= e.Delta * ScrollSpeed; if (ScrollX < 0.0) @@ -157,11 +151,6 @@ namespace go else if (ScrollX > Child.Slot.Width - ClientRectangle.Width) ScrollX = Child.Slot.Width - ClientRectangle.Width; } - - - //renderBounds.Y = -scrollY; - //RegisterForRedraw(); - //Parent.registerForGraphicUpdate (); } #endregion diff --git a/src/GraphicObjects/Slider.cs b/src/GraphicObjects/Slider.cs index cc9f2b05..0f5ba5d0 100644 --- a/src/GraphicObjects/Slider.cs +++ b/src/GraphicObjects/Slider.cs @@ -87,6 +87,8 @@ namespace go get { return base.Focusable; } set { base.Focusable = value; } } + //TODO:seems strange to trigger layout computation in an + //overriding of updateGraphic protected override void UpdateGraphic () { if (Maximum > 0) diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index aae75a54..7eb910cc 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -54,7 +54,7 @@ namespace go void butQuitPress (object sender, MouseButtonEventArgs e) { - TopContainer.Quit (); + TopContainer.DeleteWidget (this); } diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index 81fea59d..e9c7db08 100755 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -1,22 +1,16 @@ // Released to the public domain. Use, modify and relicense at will. using System; - -using OpenTK; -using OpenTK.Graphics.OpenGL; -using OpenTK.Input; -using System.Diagnostics; using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing.Imaging; +using System.IO; using System.Linq; -//using System.IO; -//using GLU = OpenTK.Graphics.Glu; -using Cairo; using System.Threading; - -using System.Drawing.Imaging; -//using System.Xml.Serialization; -//using System.Reflection; using System.Xml; -using System.IO; +using Cairo; +using OpenTK; +using OpenTK.Graphics.OpenGL; +using OpenTK.Input; @@ -37,7 +31,7 @@ namespace go // public OpenTKGameWindow(int _width, int _height, string _title="golib") // : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), _title) { - VSync = VSyncMode.On; + //VSync = VSyncMode.On; } #endregion @@ -111,10 +105,7 @@ namespace go { if (_activeWidget == value) return; - _activeWidget = value; - - } } public GraphicObject hoverWidget @@ -133,7 +124,6 @@ namespace go _focusedWidget.onFocused (this, null); } } - #endregion #region graphic contexte @@ -209,6 +199,7 @@ namespace go #endregion + #region update public Stopwatch updateTime = new Stopwatch (); public Stopwatch layoutTime = new Stopwatch (); public Stopwatch guTime = new Stopwatch (); @@ -235,7 +226,7 @@ namespace go } //Debug.WriteLine ("otd:" + gobjsToRedraw.Count.ToString () + "-"); - //redraw clip should be added when layout is complete among parents, + //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); @@ -299,7 +290,9 @@ namespace go // updateTime.ElapsedMilliseconds); } + #endregion + #region loading public void LoadInterface(string path, out T result) { Interface.Load (path, out result, this); @@ -312,6 +305,7 @@ namespace go AddWidget (result as GraphicObject); return result; } + #endregion #region Game win overrides protected override void OnUpdateFrame(FrameEventArgs e) @@ -322,8 +316,6 @@ namespace go protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); -// if (recreateContext) -// createContext (); OpenGLDraw (); } protected override void OnLoad(EventArgs e) @@ -353,8 +345,6 @@ namespace go { if (texID > 0) GL.DeleteTexture (texID); - //ctx.Dispose (); - //surf.Dispose (); } protected override void OnResize(EventArgs e) @@ -464,16 +454,8 @@ namespace go #region ILayoutable implementation - public void RegisterForLayouting (int layoutType) - { - throw new NotImplementedException (); - } - - public void UpdateLayout (LayoutingType layoutType) - { - throw new NotImplementedException (); - } - + public void RegisterForLayouting (int layoutType) { throw new NotImplementedException (); } + public void UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); } public Rectangle ContextCoordinates (Rectangle r) { return r; @@ -491,32 +473,9 @@ namespace go throw new NotImplementedException (); } } - - public bool SizeIsValid { - get { return true; } - set { 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 (); - } - } - Rectangle ILayoutable.ClientRectangle { get { return new Size(this.ClientRectangle.Size.Width,this.ClientRectangle.Size.Height); } } - public IGOLibHost TopContainer { get { return this; } } @@ -528,9 +487,7 @@ namespace go public Rectangle getBounds ()//redundant but fill ILayoutable implementation { return ClientRectangle; - } - - + } #endregion } } \ No newline at end of file