aboutsummaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2015-08-21 13:31:52 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2015-08-21 13:31:52 +0200
commit24c01f34ad393be4da4af6b25a37e434cbc9cd44 (patch)
tree384be6cd3d44efa8e6feb4769fce972e7ed4b705 /src
parent61aeb72522c4ad315fed13d8ddd3d73f7a21bc2a (diff)
Documentation, analog meter tests
Diffstat (limited to 'src')
-rw-r--r--src/GraphicObjects/AnalogMeter.cs18
-rw-r--r--src/GraphicObjects/GraphicObject.cs37
-rw-r--r--src/GraphicObjects/NumericControl.cs8
-rw-r--r--src/GraphicObjects/Scroller.cs15
-rw-r--r--src/GraphicObjects/Slider.cs2
-rw-r--r--src/GraphicObjects/Window.cs2
-rwxr-xr-xsrc/OpenTKGameWindow.cs75
7 files changed, 66 insertions, 91 deletions
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
+ /// <summary>
+ /// allow selection of svg subobject to draw in goml, should be improved
+ /// ex: allow access to backgroundImage.subimg from goml
+ /// </summary>
public string BackImgSub = null;
/// <summary>
@@ -368,32 +373,42 @@ namespace go
bmp = null;
if (TopContainer != null)
TopContainer.gobjsToRedraw.Add (this);
- //RegisterForLayouting ();
- //registerForRedraw ();
- //Interface.registerForGraphicUpdate(this);
}
/// <summary>
/// Add clipping region in redraw list of interface, dont update cached object content
/// </summary>
public virtual void RegisterForRedraw ()
{
- bmp = null;
TopContainer.gobjsToRedraw.Add (this);
}
+ /// <summary>
+ /// keep last slot components for each layouting pass to track
+ /// changes and trigger update of other component accordingly
+ /// </summary>
public Rectangle LastSlots;
+ /// <summary>
+ /// 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
+ /// </summary>
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));
}
+ /// <summary> return size of content + margins </summary>
protected virtual Size measureRawSize ()
{
return Bounds.Size;
}
-
+ /// <summary> clear current layoutingQueue items for object and
+ /// trigger a new layouting pass for a layoutType </summary>
public virtual void RegisterForLayouting(int layoutType)
{
if (Parent == null)
@@ -439,6 +454,7 @@ namespace go
}
+ /// <summary> trigger dependant sizing component update </summary>
protected virtual void OnLayoutChanges(LayoutingType layoutType)
{
switch (layoutType) {
@@ -465,6 +481,8 @@ namespace go
}
LayoutChanged.Raise (this, new LayoutChangeEventArgs (layoutType));
}
+ /// <summary> Update layout component, this is where the computation of alignement
+ /// and size take place </summary>
public virtual void UpdateLayout (LayoutingType layoutType)
{
switch (layoutType) {
@@ -572,6 +590,7 @@ namespace go
this.RegisterForRedraw ();
}
+ /// <summary> This is the common overridable drawing routine to create new widget </summary>
protected virtual void onDraw(Context gr)
{
Rectangle rBack = new Rectangle (Slot.Size);
@@ -586,6 +605,9 @@ namespace go
BackgroundImage.Paint (gr, rBack, BackImgSub);
}
+ /// <summary>
+ /// Interfal drawing context creation on a chached surface limited to slot size
+ /// this trigger the effective drawing routine </summary>
protected virtual void UpdateGraphic ()
{
LastPaintedSlot = Slot;
@@ -605,7 +627,8 @@ namespace go
//draw.WriteToPng ("/mnt/data/test.png");
}
}
-
+ /// <summary> Chained painting routine on the parent context of the actual cached version
+ /// of the widget </summary>
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<T>(string path, out T result)
{
Interface.Load<T> (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