<ItemGroup>\r
<Compile Include="src\EventSource.cs" />\r
<Compile Include="src\Colors.cs" />\r
- <Compile Include="src\Mouse.cs" />\r
<Compile Include="src\Point.cs" />\r
<Compile Include="Properties\AssemblyInfo.cs" />\r
<Compile Include="src\Rectangle.cs" />\r
<Compile Include="src\GraphicObjects\ILayoutable.cs" />\r
<Compile Include="src\Enums.cs" />\r
<Compile Include="src\GraphicObjects\GenericStack.cs" />\r
+ <Compile Include="src\CompilerServices\CompilerServices.cs" />\r
+ <Compile Include="src\GraphicObjects\AnalogMeter.cs" />\r
+ <Compile Include="src\GraphicObjects\Border.cs" />\r
+ <Compile Include="src\GraphicObjects\Checkbox.cs" />\r
+ <Compile Include="src\Font.cs" />\r
+ <Compile Include="src\TextChangeEventArgs.cs" />\r
</ItemGroup>\r
<ItemGroup>\r
<Reference Include="System" />\r
<Reference Include="OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4">\r
<HintPath>dependencies\OpenTK.dll</HintPath>\r
</Reference>\r
+ <Reference Include="Microsoft.CSharp" />\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
<Folder Include="src\win32\" />\r
<Folder Include="Images\" />\r
<Folder Include="Images\Icons\" />\r
- <Folder Include="src\Shapes\" />\r
+ <Folder Include="src\CompilerServices\" />\r
</ItemGroup>\r
<ItemGroup>\r
<None Include="Images\Icons\icon_alert.gif">\r
foreach (Color col in Color.ColorDic) {\r
HorizontalStack s = colors.addChild (new HorizontalStack ());\r
s.HorizontalAlignment = HorizontalAlignment.Left;\r
- s.addChild (new Button () {\r
- Bounds = new Size(32, 20),\r
- CornerRadius = 5,\r
- Background = col,\r
- }\r
- );\r
+ Border b = new Border () {\r
+ Bounds = new Size (32, 20),\r
+ CornerRadius = 5,\r
+ Background = col,\r
+ BorderWidth = 2,\r
+ BorderColor = Color.Transparent,\r
+ Focusable = true\r
+ };\r
+ b.MouseEnter += delegate(object sender, MouseMoveEventArgs ee) {\r
+ (sender as Border).BorderColor = Color.White;\r
+ };\r
+ b.MouseLeave += delegate(object sender, MouseMoveEventArgs ee) {\r
+ (sender as Border).BorderColor = Color.Transparent;\r
+ };\r
+ s.addChild (b);\r
\r
s.addChild (\r
new Label (col.ToString ()){\r
fps = (int)RenderFrequency;\r
\r
labFps.Text = fps.ToString();\r
- labUpdate.Text = this.updateTime.ElapsedMilliseconds.ToString();\r
+ labUpdate.Text = this.updateTime.ElapsedMilliseconds.ToString() + " ms";\r
if (frameCpt > 200) {\r
labFpsMin.Text = fpsMin.ToString();\r
labFpsMax.Text = fpsMax.ToString();\r
<?xml version="1.0"?>\r
<Group Name="MainGrp" Background="0,5;0,5;0,5;0,5" Foreground="White"\r
- BorderColor="White" BorderWidth="2" Margin="10" Focusable="True" Width="800" Height="500">\r
+ Margin="10" Focusable="True" Width="800" Height="500">\r
<Slider Height="10" Width="300" BorderWidth="1" Background="Transparent"\r
VerticalAlignment="Bottom" />\r
<HorizontalStack WidgetSpacing="10" Name="hs0" VerticalAlignment="Top" Background="0,5;0,5;0,5;0,5">\r
<Button Margin="5" BorderWidth="0" Background="Gray" Width="-1" Height="-1">\r
<Label FontSize="10" Text="This is a test" Margin="5" FontColor="White" Foreground="White" />\r
</Button>\r
- <TextBoxWidget TextAlignment="LeftCenter" \r
+ <TextBoxWidget TextAlignment="LeftCenter" Font="droid,14" \r
Width="300" Height="-1" Margin="2"\r
BorderColor="White" BorderWidth="1"\r
Text="editable text"/>\r
<Label Name="labUpdate" Text="xxxx" FontSize="16" Width="60" TextAlignment="Center" Background="DarkGreen"/>\r
</HorizontalStack>\r
<HorizontalStack>\r
- <Label Text="Fps:" Width = "30" FontColor="White" VerticalAlignment="Center" TextAlignment="LeftCenter"/>\r
- <Label Name="labFps" Text="xxxx" FontSize="16" Width = "40" FontColor="Black" TextAlignment="Center" Background="SpringGreen"/>\r
+ <Label Text="Fps:" Width = "30" VerticalAlignment="Center" TextAlignment="LeftCenter"/>\r
+ <Label Name="labFps" Text="xxxx" Font="droid bold, 14"\r
+ TextAlignment="Center" Background="AoEnglish"/>\r
</HorizontalStack>\r
<HorizontalStack>\r
- <Label Text="Min:" Width = "30" FontColor="White" />\r
- <Label Name="labFpsMin" Text="xxxx" FontSize="16" Width = "40" FontColor="Black" TextAlignment="Center" Background="SpringGreen"/>\r
+ <Label Text="Min:" Width = "30" />\r
+ <Label Name="labFpsMin" Text="xxxx" Font="droid bold, 14"\r
+ TextAlignment="Center" Background="AoEnglish"/>\r
</HorizontalStack>\r
<HorizontalStack>\r
- <Label Text="Max:" Width = "30" FontColor="White" />\r
- <Label Name="labFpsMax" Text="xxxx" FontSize="16" Width = "40" FontColor="Black" TextAlignment="Center" Background="SpringGreen"/>\r
+ <Label Text="Max:" Width = "30"/>\r
+ <Label Name="labFpsMax" Text="xxxx" Font="droid bold, 14"\r
+ TextAlignment="Center" Background="AoEnglish"/>\r
</HorizontalStack>\r
</VerticalStack>\r
\r
<Scroller Background="DimGray" Height="350" Width="300" \r
Margin="5" VerticalScrolling="true">\r
- <VerticalStack Name="colors" BorderColor="Gray" VerticalAlignment="Top"\r
- Background="Transparent" BorderWidth="2" Margin="5">\r
+ <VerticalStack Name="colors" VerticalAlignment="Top" Margin="5">\r
<ProgressBar Name="pbBar2" Width="100" Height="20" Value="50"\r
BorderWidth="2" BorderColor="White" Foreground="BlueCrayola" Background="DarkGray"/>\r
</VerticalStack>\r
{\r
public struct Color : IXmlSerializable\r
{\r
+ #region CTOR\r
+ public Color(double _R, double _G, double _B, double _A)\r
+ {\r
+ A = _A.Clamp(0,1);\r
+ R = _R.Clamp(0,1);\r
+ G = _G.Clamp(0,1);\r
+ B = _B.Clamp(0,1);\r
+ Name = "";\r
+ }\r
+ internal Color(double _R, double _G, double _B, double _A, string _name)\r
+ {\r
+ A = _A;\r
+ R = _R;\r
+ G = _G;\r
+ B = _B;\r
+ Name = _name;\r
+ ColorDic.Add(this);\r
+ } \r
+ #endregion\r
+\r
public static List<Color> ColorDic = new List<Color>();\r
\r
internal string Name; \r
+\r
+ #region public fields\r
public double A;\r
public double R;\r
public double G;\r
public double B; \r
+ #endregion\r
\r
- public Color(double _R, double _G, double _B, double _A)\r
- {\r
- A = _A.Clamp(0,1);\r
- R = _R.Clamp(0,1);\r
- G = _G.Clamp(0,1);\r
- B = _B.Clamp(0,1);\r
- Name = "";\r
- }\r
- internal Color(double _R, double _G, double _B, double _A, string _name)\r
- {\r
- A = _A;\r
- R = _R;\r
- G = _G;\r
- B = _B;\r
- Name = _name;\r
- ColorDic.Add(this);\r
- } \r
- \r
+ #region Operators\r
public static implicit operator string(Color c)\r
{\r
return c.ToString();\r
}\r
+ public static implicit operator Color(string s)\r
+ {\r
+ if (string.IsNullOrEmpty(s))\r
+ return White;\r
+\r
+ string[] c = s.Split(new char[] { ';' });\r
+\r
+ if (c.Length == 1)\r
+ {\r
+ foreach (Color cr in ColorDic)\r
+ {\r
+ if (cr.Name == s)\r
+ return cr;\r
+ }\r
+ }\r
+\r
+ return new Color(\r
+ double.Parse(c[0]),\r
+ double.Parse(c[1]),\r
+ double.Parse(c[2]),\r
+ double.Parse(c[3])); \r
+ }\r
\r
public static implicit operator System.Drawing.Color(Color c)\r
{\r
{\r
return new Cairo.Color(c.R, c.G, c.B, c.A);\r
}\r
- public float[] floatArray\r
+\r
+ public static bool operator ==(Color left, Color right)\r
{\r
- get { return new float[]{ (float)R, (float)G, (float)B, (float)A }; }\r
+ return left.A == right.A &&\r
+ left.R == right.R &&\r
+ left.G == right.G &&\r
+ left.B == right.B ? true : false;\r
}\r
- public Color AdjustAlpha(double _A)\r
+ public static bool operator !=(Color left, Color right)\r
{\r
- return new Color (this.R, this.G, this.B, _A);\r
+ return left.A == right.A &&\r
+ left.R == right.R &&\r
+ left.G == right.G &&\r
+ left.B == right.B ? false : true;\r
+\r
+ }\r
+ public static bool operator ==(Color c, string n)\r
+ {\r
+ return c.Name == n ? true : false;\r
+ }\r
+ public static bool operator !=(Color c, string n)\r
+ {\r
+ return c.Name == n ? false : true;\r
+ }\r
+ public static bool operator ==(string n, Color c)\r
+ {\r
+ return c.Name == n ? true : false;\r
+ }\r
+ public static bool operator !=(string n, Color c)\r
+ {\r
+ return c.Name == n ? false : true;\r
}\r
- public static bool operator ==(Color left, Color right)\r
- {\r
- return left.A == right.A &&\r
- left.R == right.R &&\r
- left.G == right.G &&\r
- left.B == right.B ? true : false;\r
- }\r
- public static bool operator !=(Color left, Color right)\r
- {\r
- return left.A == right.A &&\r
- left.R == right.R &&\r
- left.G == right.G &&\r
- left.B == right.B ? false : true;\r
- \r
- }\r
- public static bool operator ==(Color c, string n)\r
- {\r
- return c.Name == n ? true : false;\r
- }\r
- public static bool operator !=(Color c, string n)\r
- {\r
- return c.Name == n ? false : true;\r
- }\r
- public static bool operator ==(string n, Color c)\r
- {\r
- return c.Name == n ? true : false;\r
- }\r
- public static bool operator !=(string n, Color c)\r
- {\r
- return c.Name == n ? false : true;\r
- }\r
public static Color operator *(Color c, Double f)\r
{\r
return new Color(c.R,c.G,c.B,c.A * f);\r
}\r
public static Color operator +(Color c1, Color c2)\r
{\r
- return new Color(c1.R + c2.R,c1.G+c2.G,c1.B+c2.B,c1.A + c2.A);\r
+ return new Color(c1.R + c2.R,c1.G + c2.G,c1.B + c2.B,c1.A + c2.A);\r
+ }\r
+ public static Color operator -(Color c1, Color c2)\r
+ {\r
+ return new Color(c1.R - c2.R,c1.G - c2.G,c1.B - c2.B,c1.A - c2.A);\r
+ }\r
+ #endregion\r
+\r
+\r
+ public float[] floatArray\r
+ {\r
+ get { return new float[]{ (float)R, (float)G, (float)B, (float)A }; }\r
+ }\r
+ public Color AdjustAlpha(double _A)\r
+ {\r
+ return new Color (this.R, this.G, this.B, _A);\r
}\r
+\r
+ #region Predefined colors\r
public static readonly Color Transparent = new Color(0, 0, 0, 0, "Transparent");\r
public static readonly Color Green = new Color(0, 1.0, 0, 1.0, "Green");\r
public static readonly Color AirForceBlueRaf = new Color(0.364705882352941,0.541176470588235,0.658823529411765,1.0,"AirForceBlueRaf");\r
public static readonly Color YellowRyb = new Color(0.996078431372549,0.996078431372549,0.2,1.0,"YellowRyb");\r
public static readonly Color Zaffre = new Color(0,0.0784313725490196,0.658823529411765,1.0,"Zaffre");\r
public static readonly Color ZinnwalditeBrown = new Color(0.172549019607843,0.0862745098039216,0.0313725490196078,1.0,"ZinnwalditeBrown");\r
-\r
- public override string ToString()\r
- {\r
- if (!string.IsNullOrEmpty(Name))\r
- return Name;\r
-\r
- foreach (Color cr in ColorDic)\r
- {\r
- if (cr == this)\r
- {\r
- Name = cr.Name;\r
- return cr.Name;\r
- }\r
- }\r
-\r
- return string.Format("{0};{1};{2};{3}", R, G, B, A);\r
- }\r
-\r
- public static implicit operator Color(string s)\r
- {\r
- if (string.IsNullOrEmpty(s))\r
- return White;\r
-\r
- string[] c = s.Split(new char[] { ';' });\r
-\r
- if (c.Length == 1)\r
- {\r
- foreach (Color cr in ColorDic)\r
- {\r
- if (cr.Name == s)\r
- return cr;\r
- }\r
- }\r
-\r
- return new Color(\r
- double.Parse(c[0]),\r
- double.Parse(c[1]),\r
- double.Parse(c[2]),\r
- double.Parse(c[3])); \r
- }\r
- public void ReadXml(System.Xml.XmlReader reader)\r
+ #endregion\r
+ \r
+ #region IXmlSerializable\r
+ public void ReadXml(System.Xml.XmlReader reader)\r
{\r
string[] c = reader["Color"].Split(new char[] { ';' });\r
A = double.Parse(c[0]);\r
G = double.Parse(c[2]);\r
B = double.Parse(c[3]);\r
}\r
-\r
public void WriteXml(System.Xml.XmlWriter writer)\r
{\r
-\r
writer.WriteAttributeString("Color", this.ToString());\r
}\r
-\r
public System.Xml.Schema.XmlSchema GetSchema()\r
{\r
return null;\r
}\r
+ #endregion\r
\r
+ public override string ToString()\r
+ {\r
+ if (!string.IsNullOrEmpty(Name))\r
+ return Name;\r
\r
+ foreach (Color cr in ColorDic)\r
+ {\r
+ if (cr == this)\r
+ {\r
+ Name = cr.Name;\r
+ return cr.Name;\r
+ }\r
+ }\r
\r
+ return string.Format("{0};{1};{2};{3}", R, G, B, A);\r
+ }\r
\r
public static object Parse(string s)\r
{\r
--- /dev/null
+using System;
+using System.Reflection.Emit;
+using System.Reflection;
+
+namespace go
+{
+ public static class CompilerServices
+ {
+ public static void createDynHandler(string eventName,
+ object dstObj, Type handlerArgsType, string destProp, string src)
+ {
+ Type dstType = dstObj.GetType ();
+
+ Type[] args = {typeof(object), handlerArgsType};
+ DynamicMethod hello = new DynamicMethod("dynHandle",
+ typeof(void),
+ args,
+ dstType.Module);
+
+ MethodInfo dstMi = dstType.GetProperty (destProp).GetSetMethod ();
+ FieldInfo srcFi = typeof(go.Color).GetField (src, BindingFlags.Static|BindingFlags.Public);
+ ILGenerator il = hello.GetILGenerator(256);
+
+ il.Emit(OpCodes.Ldarg_0);
+ il.Emit (OpCodes.Ldsfld, srcFi);
+ il.Emit(OpCodes.Callvirt, dstMi);
+ il.Emit(OpCodes.Ret);
+ //hello.DefineParameter(1, ParameterAttributes.In, "instance");
+ //hello.DefineParameter(2, ParameterAttributes.In, "value");
+ FieldInfo fi = getEventHandlerField (dstType, eventName);
+ Delegate del = hello.CreateDelegate(fi.FieldType);
+ fi.SetValue(dstObj, del);
+
+ }
+ static int dynHandleCpt = 0;
+ public static void CompileEventSource(EventSource es)
+ {
+ Type srcType = es.Source.GetType ();
+
+ #region Retrieve EventHandler parameter type
+ EventInfo ei = srcType.GetEvent (es.EventName);
+ 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);
+
+ #region IL generation
+ ILGenerator il = dm.GetILGenerator(256);
+
+ string src = es.Handler.Trim();
+
+ if (! (src.StartsWith("{") || src.EndsWith ("}")))
+ throw new Exception (string.Format("GOML:Malformed {0} Event handler: {1}", es.EventName, es.Handler));
+
+ 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
+
+ FieldInfo evtFi = getEventHandlerField (srcType, es.EventName);
+ Delegate del = dm.CreateDelegate(evtFi.FieldType);
+ evtFi.SetValue(es.Source, del);
+ }
+
+ public static FieldInfo getEventHandlerField(Type type, string eventName)
+ {
+ FieldInfo fi;
+ Type ty = type;
+ do {
+ fi = ty.GetField (eventName,
+ BindingFlags.NonPublic |
+ BindingFlags.Instance |
+ BindingFlags.GetField);
+ ty = ty.BaseType;
+ if (ty == null)
+ break;
+ } while(fi == null);
+ return fi;
+ }
+ }
+}
+
\r
namespace go\r
{\r
- internal class EventSource\r
+ public class EventSource\r
{\r
public GraphicObject Source;\r
public string EventName;\r
--- /dev/null
+using System;
+using Cairo;
+
+namespace go
+{
+ public enum FontStyle
+ {
+ Normal,
+ Bold,
+ Italic,
+ Underlined
+ }
+ public class Font
+ {
+ #region CTOR
+ public Font ()
+ {
+ }
+ #endregion
+
+ string _name = "droid";
+ int _size = 12;
+ FontStyle _style = FontStyle.Normal;
+
+ public string Name {
+ get { return _name; }
+ set { _name = value; }
+ }
+ public int Size {
+ get { return _size; }
+ set { _size = value; }
+ }
+ public FontStyle Style {
+ get { return _style; }
+ set { _style = value; }
+ }
+
+ public FontSlant Slant {
+ get{
+ switch (Style) {
+ case FontStyle.Normal:
+ default:
+ return FontSlant.Normal;
+ case FontStyle.Italic:
+ return FontSlant.Italic;
+ }
+ }
+ }
+ public FontWeight Wheight {
+ get{
+ switch (Style) {
+ case FontStyle.Bold:
+ return FontWeight.Bold;
+ case FontStyle.Italic:
+ case FontStyle.Normal:
+ default:
+ return FontWeight.Normal;
+ }
+ }
+ }
+
+ #region Operators
+ public static implicit operator string(Font c)
+ {
+ return c.ToString();
+ }
+ public static implicit operator Font(string s)
+ {
+ Font f = new Font ();
+
+ if (!string.IsNullOrEmpty (s)) {
+ string[] c = s.TrimStart().TrimEnd().Split (new char[] { ',' });
+
+ if (c.Length == 2)
+ f.Size = int.Parse (c [1].TrimStart());
+
+ string[] n = c [0].TrimEnd().Split (new char[] { ' ' });
+
+ f.Name = n [0];
+
+ if (n.Length > 1)
+ f.Style = (FontStyle)Enum.Parse (typeof(FontStyle), n[n.Length-1], true);
+ }
+
+ return f;
+ }
+ #endregion
+
+ public override string ToString()
+ {
+ if (_style == FontStyle.Normal)
+ return string.Format("{0},{1}", _name, _size);
+ else
+ return string.Format("{0} {1},{2}", _name, _style, _size);
+
+ }
+
+ public static object Parse(string s)
+ {
+ return (Font)s;
+ }
+ }
+}
+
--- /dev/null
+using System;
+using System.Xml.Serialization;
+using System.ComponentModel;
+using Cairo;
+
+namespace go
+{
+ public class AnalogMeter : NumericControl
+ {
+ #region CTOR
+ public AnalogMeter() : base()
+ {}
+ public AnalogMeter(double minimum, double maximum, double step)
+ : base(minimum,maximum,step)
+ {
+ }
+ #endregion
+
+ #region GraphicObject Overrides
+ protected override void onDraw (Context gr)
+ {
+ base.onDraw (gr);
+
+ Rectangle r = ClientRectangle;
+ Point m = r.Center;
+
+ double aUnit = Math.PI*2.0 / (Maximum - Minimum);
+ gr.Translate (m.X, m.Y);
+ gr.Rotate (Value * aUnit);
+ gr.Translate (-m.X, -m.Y);
+
+ gr.LineWidth = 2;
+ gr.Color = Foreground;
+ gr.MoveTo (m);
+ gr.LineTo (m.X, 0);
+ gr.Stroke ();
+ }
+ #endregion
+ }
+}
+
--- /dev/null
+using System;
+using System.Xml.Serialization;
+using System.ComponentModel;
+
+namespace go
+{
+ public class Border : Container
+ {
+ #region CTOR
+ public Border () : base(){}
+ #endregion
+
+ #region private fields
+ Color _borderColor;
+ int _borderWidth;
+ #endregion
+
+ #region public properties
+ [XmlAttributeAttribute()][DefaultValue(2)]
+ public virtual int BorderWidth {
+ get { return _borderWidth; }
+ set {
+ _borderWidth = value;
+ registerForGraphicUpdate ();
+ }
+ }
+ [XmlAttributeAttribute()][DefaultValue("White")]
+ public virtual Color BorderColor {
+ get { return _borderColor; }
+ set {
+ _borderColor = value;
+ registerForGraphicUpdate ();
+ }
+ }
+ #endregion
+
+ #region GraphicObject override
+ [XmlIgnore]public override Rectangle ClientRectangle {
+ get {
+ Rectangle cb = base.ClientRectangle;
+ cb.Inflate (- BorderWidth);
+ return cb;
+ }
+ }
+
+ protected override Size measureRawSize ()
+ {
+ Size raw = Bounds.Size;
+
+ if (child != null) {
+ if (Bounds.Width < 0 && child.WIsValid)
+ raw.Width = child.Slot.Width + 2 * (Margin+BorderWidth);
+ if (Bounds.Height < 0 && child.HIsValid)
+ raw.Height = child.Slot.Height + 2 * (Margin+BorderWidth);
+ }
+
+ return raw;
+ }
+ protected override void onDraw (Cairo.Context gr)
+ {
+ Rectangle rBack = new Rectangle (Slot.Size);
+
+ if (BorderWidth > 0)
+ rBack.Inflate (-BorderWidth / 2);
+
+ gr.Color = Background;
+ CairoHelpers.CairoRectangle(gr,rBack,CornerRadius);
+ gr.Fill ();
+
+ if (BorderWidth > 0) {
+
+ gr.LineWidth = BorderWidth;
+ gr.Color = BorderColor;
+ CairoHelpers.CairoRectangle(gr,rBack,CornerRadius);
+ gr.Stroke ();
+ }
+ }
+ #endregion
+ }
+}
+
using System;\r
-\r
-\r
using System.Collections.Generic;\r
using System.Linq;\r
using System.Text;\r
//using OpenTK.Graphics.OpenGL;\r
\r
-using Cairo;\r
-\r
-using winColors = System.Drawing.Color;\r
using System.Diagnostics;\r
+\r
using System.Xml.Serialization;\r
+using Cairo;\r
using OpenTK.Input;\r
+using System.ComponentModel;\r
\r
namespace go\r
{\r
- public delegate void GOEvent(GraphicObject sender);\r
-\r
- public enum ButtonStates\r
- {\r
- normal,\r
- mouseOver,\r
- mouseDown,\r
- Disable\r
- }\r
-\r
public class Button : Container, IXmlSerializable\r
{\r
- public GOEvent Click;\r
-\r
- bool _isCheckable = false;\r
- bool _isChecked = false;\r
- bool _affectMultiSelectState = false;\r
- bool _border3D = false;\r
- Color _checkedColor;\r
- ButtonStates _CurrentState = ButtonStates.normal;\r
-\r
+ #region CTOR\r
public Button() : base()\r
- {}\r
+ {\r
+ MouseEnter += delegate { Background = Color.Lion;};\r
+ MouseLeave += delegate { Background = Color.Gray;};\r
+ MouseButtonDown += delegate { Background = Color.Red;};\r
+ MouseButtonUp += delegate { Background = Color.Gray;};\r
+ }\r
+ #endregion\r
\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(true)]\r
+ #region GraphicObject Overrides\r
+ [XmlAttributeAttribute()][DefaultValue(60)]\r
+ public override int Width {\r
+ get { return base.Width; }\r
+ set { base.Width = value; }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue(30)]\r
+ public override int Height {\r
+ get { return base.Height; }\r
+ set { base.Height = value; }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue("Gray")]\r
+ public virtual Color Background {\r
+ get { return base.Background; }\r
+ set { base.Background = value; }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue(true)]\r
public override bool Focusable\r
{\r
get { return base.Focusable; }\r
set { base.Focusable = value; }\r
- }\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- public Color CheckedColor\r
- {\r
- get { return _checkedColor; }\r
- set\r
- {\r
- _checkedColor = value;\r
- registerForGraphicUpdate();\r
- }\r
- }\r
-\r
- [System.Xml.Serialization.XmlIgnore]\r
- public ButtonStates CurrentState\r
- {\r
- get { return _CurrentState; }\r
- set\r
- {\r
- if (value == _CurrentState)\r
- return;\r
- _CurrentState = value;\r
- registerForRedraw();\r
- }\r
- }\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(false)]\r
- public bool IsChecked\r
- {\r
- get { return _isChecked; }\r
- set\r
- {\r
- if (value == _isChecked)\r
- return;\r
-\r
- _isChecked = value;\r
-\r
- if (Click != null)\r
- Click(this);\r
-\r
- registerForGraphicUpdate();\r
- }\r
- }\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(false)]\r
- public bool IsCheckable\r
- {\r
- get { return _isCheckable; }\r
- set { _isCheckable = value; }\r
- }\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(false)]\r
- public bool AffectMultiSelectState\r
- {\r
- get { return _affectMultiSelectState; }\r
- set { _affectMultiSelectState = value; }\r
- }\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(false)]\r
- public bool Border3d\r
- {\r
- get { return _border3D; }\r
- set { _border3D = value; }\r
- }\r
-\r
- public override void Paint(ref Context ctx, Rectangles clip = null)\r
- {\r
- base.Paint(ref ctx, clip);\r
-\r
- Rectangle r = Parent.ContextCoordinates (Slot);\r
-\r
- ctx.Save();\r
- //ctx.ResetClip();\r
- \r
- if (IsCheckable){\r
- if (IsChecked){\r
- ctx.Color = CheckedColor;\r
- ctx.Rectangle(r);\r
- ctx.Fill();\r
-\r
- if (Border3d)\r
- CairoHelpers.StrokeLoweredRectangle(ctx, r);\r
- }\r
- else{\r
- if (Border3d)\r
- CairoHelpers.StrokeRaisedRectangle(ctx, r);\r
- }\r
- }\r
-\r
- switch (CurrentState){\r
- case ButtonStates.normal:\r
- break;\r
- case ButtonStates.mouseOver:\r
- CairoHelpers.CairoRectangle(ctx,r,CornerRadius);\r
- ctx.Operator = Operator.Add;\r
- ctx.Color = new Color(0.2, 0.2, 0.2, 1.0);\r
- ctx.Fill();\r
- ctx.Operator = Operator.Over;\r
- break;\r
- case ButtonStates.mouseDown: \r
- CairoHelpers.CairoRectangle(ctx,r,CornerRadius);\r
- ctx.Operator = Operator.Add;\r
- ctx.Color = Color.Red;\r
- ctx.Fill();\r
- ctx.Operator = Operator.Over;\r
- break;\r
- case ButtonStates.Disable:\r
- CairoHelpers.CairoRectangle(ctx,r,CornerRadius);\r
- ctx.Color = new Color(0.2, 0.2, 0.2, 0.7);\r
- ctx.Fill();\r
- break;\r
-\r
- }\r
- ctx.Restore();\r
- }\r
+ } \r
\r
+ #endregion\r
\r
- #region mouse handling\r
- public override void onMouseButtonDown (object sender,MouseButtonEventArgs e)\r
- {\r
- if (CurrentState != ButtonStates.Disable)\r
- {\r
- if (IsCheckable)\r
- {\r
- if (IsChecked)\r
- IsChecked = false;\r
- else\r
- {\r
- Group wg = Parent as Group;\r
- if (wg != null)\r
- {\r
- if (AffectMultiSelectState && !wg.MultiSelect)\r
- {\r
- foreach (Button but in wg.Children.OfType<Button>())\r
- {\r
- if (but.IsCheckable)\r
- {\r
- if (but.IsChecked && but.AffectMultiSelectState)\r
- {\r
- but.IsChecked = false;\r
- break;\r
- }\r
- }\r
- }\r
- }\r
- }\r
- IsChecked = true;\r
- }\r
- }\r
- //else if (Click != null)\r
- // Click(this);\r
-\r
- CurrentState = ButtonStates.mouseDown;\r
- }\r
-\r
- base.onMouseButtonDown (sender, e);\r
- }\r
- public override void onMouseButtonUp (object sender, OpenTK.Input.MouseButtonEventArgs e)\r
+ [XmlAttributeAttribute][DefaultValue("Button")]\r
+ public string Text\r
{\r
- if (CurrentState != ButtonStates.Disable) {\r
- if (MouseIsIn (e.Position))\r
- CurrentState = ButtonStates.mouseOver;\r
+ get {\r
+ Label l = child as Label;\r
+ return l == null ? "" : l.Text; \r
+ }\r
+ set\r
+ {\r
+ Label l = child as Label;\r
+ if (l == null)\r
+ this.setChild(new Label (value) \r
+ { \r
+ TextAlignment = Alignment.Center,\r
+ Foreground = Color.Black\r
+ });\r
else\r
- CurrentState = ButtonStates.normal;\r
-\r
+ l.Text = value;\r
}\r
-\r
- base.onMouseButtonUp (sender, e);\r
- }\r
- public override void onMouseEnter (object sender, MouseMoveEventArgs e)\r
- {\r
- if (CurrentState == ButtonStates.normal)\r
- CurrentState = ButtonStates.mouseOver;\r
-\r
- base.onMouseEnter (sender, e);\r
- }\r
- public override void onMouseLeave (object sender, MouseMoveEventArgs e)\r
- {\r
- if (CurrentState == ButtonStates.mouseOver)\r
- CurrentState = ButtonStates.normal;\r
-\r
- base.onMouseLeave (sender, e);\r
- }\r
- #endregion\r
-\r
- #region IXmlSerializable\r
- public override System.Xml.Schema.XmlSchema GetSchema()\r
- {\r
- return null;\r
- }\r
- public override void ReadXml(System.Xml.XmlReader reader)\r
- {\r
- string handler = reader.GetAttribute("OnClick");\r
- GraphicObject.EventsToResolve.Add(new EventSource \r
- { \r
- Source = this, \r
- Handler = handler,\r
- EventName = "OnClick"\r
- });\r
-\r
- //Container c = this as Container;\r
- base.ReadXml(reader);\r
- }\r
- public override void WriteXml(System.Xml.XmlWriter writer)\r
- {\r
- if (Click != null)\r
- {\r
- writer.WriteAttributeString("OnClick", Click.Method.Name);\r
- }\r
-\r
- base.WriteXml(writer);\r
- }\r
- #endregion\r
+ } \r
}\r
}\r
--- /dev/null
+using System;\r
+\r
+\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+//using OpenTK.Graphics.OpenGL;\r
+\r
+using Cairo;\r
+\r
+using winColors = System.Drawing.Color;\r
+using System.Diagnostics;\r
+using System.Xml.Serialization;\r
+using OpenTK.Input;\r
+\r
+namespace go\r
+{\r
+ public delegate void GOEvent(GraphicObject sender);\r
+\r
+ public enum ButtonStates\r
+ {\r
+ normal,\r
+ mouseOver,\r
+ mouseDown,\r
+ Disable\r
+ }\r
+\r
+ public class Checkbox : Container, IXmlSerializable\r
+ {\r
+ public GOEvent Click;\r
+\r
+ bool _isCheckable = false;\r
+ bool _isChecked = false;\r
+ bool _affectMultiSelectState = false;\r
+ bool _border3D = false;\r
+ Color _checkedColor;\r
+ ButtonStates _CurrentState = ButtonStates.normal;\r
+\r
+ public Checkbox() : base()\r
+ {}\r
+\r
+ [System.Xml.Serialization.XmlAttributeAttribute()]\r
+ [System.ComponentModel.DefaultValue(true)]\r
+ public override bool Focusable\r
+ {\r
+ get { return base.Focusable; }\r
+ set { base.Focusable = value; }\r
+ }\r
+\r
+ [System.Xml.Serialization.XmlAttributeAttribute()]\r
+ public Color CheckedColor\r
+ {\r
+ get { return _checkedColor; }\r
+ set\r
+ {\r
+ _checkedColor = value;\r
+ registerForGraphicUpdate();\r
+ }\r
+ }\r
+\r
+ [System.Xml.Serialization.XmlIgnore]\r
+ public ButtonStates CurrentState\r
+ {\r
+ get { return _CurrentState; }\r
+ set\r
+ {\r
+ if (value == _CurrentState)\r
+ return;\r
+ _CurrentState = value;\r
+ registerForRedraw();\r
+ }\r
+ }\r
+\r
+ [System.Xml.Serialization.XmlAttributeAttribute()]\r
+ [System.ComponentModel.DefaultValue(false)]\r
+ public bool IsChecked\r
+ {\r
+ get { return _isChecked; }\r
+ set\r
+ {\r
+ if (value == _isChecked)\r
+ return;\r
+\r
+ _isChecked = value;\r
+\r
+ if (Click != null)\r
+ Click(this);\r
+\r
+ registerForGraphicUpdate();\r
+ }\r
+ }\r
+\r
+ [System.Xml.Serialization.XmlAttributeAttribute()]\r
+ [System.ComponentModel.DefaultValue(false)]\r
+ public bool IsCheckable\r
+ {\r
+ get { return _isCheckable; }\r
+ set { _isCheckable = value; }\r
+ }\r
+\r
+ [System.Xml.Serialization.XmlAttributeAttribute()]\r
+ [System.ComponentModel.DefaultValue(false)]\r
+ public bool AffectMultiSelectState\r
+ {\r
+ get { return _affectMultiSelectState; }\r
+ set { _affectMultiSelectState = value; }\r
+ }\r
+\r
+ [System.Xml.Serialization.XmlAttributeAttribute()]\r
+ [System.ComponentModel.DefaultValue(false)]\r
+ public bool Border3d\r
+ {\r
+ get { return _border3D; }\r
+ set { _border3D = value; }\r
+ }\r
+\r
+ public override void Paint(ref Context ctx, Rectangles clip = null)\r
+ {\r
+ base.Paint(ref ctx, clip);\r
+\r
+ Rectangle r = Parent.ContextCoordinates (Slot);\r
+\r
+ ctx.Save();\r
+ //ctx.ResetClip();\r
+ \r
+ if (IsCheckable){\r
+ if (IsChecked){\r
+ ctx.Color = CheckedColor;\r
+ ctx.Rectangle(r);\r
+ ctx.Fill();\r
+\r
+ if (Border3d)\r
+ CairoHelpers.StrokeLoweredRectangle(ctx, r);\r
+ }\r
+ else{\r
+ if (Border3d)\r
+ CairoHelpers.StrokeRaisedRectangle(ctx, r);\r
+ }\r
+ }\r
+\r
+ switch (CurrentState){\r
+ case ButtonStates.normal:\r
+ break;\r
+ case ButtonStates.mouseOver:\r
+ CairoHelpers.CairoRectangle(ctx,r,CornerRadius);\r
+ ctx.Operator = Operator.Add;\r
+ ctx.Color = new Color(0.2, 0.2, 0.2, 1.0);\r
+ ctx.Fill();\r
+ ctx.Operator = Operator.Over;\r
+ break;\r
+ case ButtonStates.mouseDown: \r
+ CairoHelpers.CairoRectangle(ctx,r,CornerRadius);\r
+ ctx.Operator = Operator.Add;\r
+ ctx.Color = Color.Red;\r
+ ctx.Fill();\r
+ ctx.Operator = Operator.Over;\r
+ break;\r
+ case ButtonStates.Disable:\r
+ CairoHelpers.CairoRectangle(ctx,r,CornerRadius);\r
+ ctx.Color = new Color(0.2, 0.2, 0.2, 0.7);\r
+ ctx.Fill();\r
+ break;\r
+\r
+ }\r
+ ctx.Restore();\r
+ }\r
+\r
+\r
+ #region mouse handling\r
+ public override void onMouseButtonDown (object sender,MouseButtonEventArgs e)\r
+ {\r
+ if (CurrentState != ButtonStates.Disable)\r
+ {\r
+ if (IsCheckable)\r
+ {\r
+ if (IsChecked)\r
+ IsChecked = false;\r
+ else\r
+ {\r
+ Group wg = Parent as Group;\r
+ if (wg != null)\r
+ {\r
+ if (AffectMultiSelectState && !wg.MultiSelect)\r
+ {\r
+ foreach (Checkbox but in wg.Children.OfType<Checkbox>())\r
+ {\r
+ if (but.IsCheckable)\r
+ {\r
+ if (but.IsChecked && but.AffectMultiSelectState)\r
+ {\r
+ but.IsChecked = false;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ IsChecked = true;\r
+ }\r
+ }\r
+ //else if (Click != null)\r
+ // Click(this);\r
+\r
+ CurrentState = ButtonStates.mouseDown;\r
+ }\r
+\r
+ base.onMouseButtonDown (sender, e);\r
+ }\r
+ public override void onMouseButtonUp (object sender, OpenTK.Input.MouseButtonEventArgs e)\r
+ {\r
+ if (CurrentState != ButtonStates.Disable) {\r
+ if (MouseIsIn (e.Position))\r
+ CurrentState = ButtonStates.mouseOver;\r
+ else\r
+ CurrentState = ButtonStates.normal;\r
+\r
+ }\r
+\r
+ base.onMouseButtonUp (sender, e);\r
+ }\r
+ public override void onMouseEnter (object sender, MouseMoveEventArgs e)\r
+ {\r
+ if (CurrentState == ButtonStates.normal)\r
+ CurrentState = ButtonStates.mouseOver;\r
+\r
+ base.onMouseEnter (sender, e);\r
+ }\r
+ public override void onMouseLeave (object sender, MouseMoveEventArgs e)\r
+ {\r
+ if (CurrentState == ButtonStates.mouseOver)\r
+ CurrentState = ButtonStates.normal;\r
+\r
+ base.onMouseLeave (sender, e);\r
+ }\r
+ #endregion\r
+\r
+ #region IXmlSerializable\r
+ public override System.Xml.Schema.XmlSchema GetSchema()\r
+ {\r
+ return null;\r
+ }\r
+ public override void ReadXml(System.Xml.XmlReader reader)\r
+ {\r
+ string handler = reader.GetAttribute("OnClick");\r
+ GraphicObject.EventsToResolve.Add(new EventSource \r
+ { \r
+ Source = this, \r
+ Handler = handler,\r
+ EventName = "OnClick"\r
+ });\r
+\r
+ //Container c = this as Container;\r
+ base.ReadXml(reader);\r
+ }\r
+ public override void WriteXml(System.Xml.XmlWriter writer)\r
+ {\r
+ if (Click != null)\r
+ {\r
+ writer.WriteAttributeString("OnClick", Click.Method.Name);\r
+ }\r
+\r
+ base.WriteXml(writer);\r
+ }\r
+ #endregion\r
+ }\r
+}\r
{\r
public class Container : GraphicObject, IXmlSerializable\r
{\r
- public GraphicObject child;\r
+ #region CTOR\r
+ public Container()\r
+ : base()\r
+ {\r
+ }\r
+ public Container(Rectangle _bounds)\r
+ : base(_bounds)\r
+ {\r
+ }\r
+ #endregion\r
\r
- public Container()\r
- : base()\r
- {\r
- }\r
- public Container(Rectangle _bounds)\r
- : base(_bounds)\r
- {\r
- }\r
+ public GraphicObject child;\r
\r
public T setChild<T>(T _child)\r
{\r
\r
return (T)_child;\r
}\r
+\r
+ #region GraphicObject Overrides\r
+ [XmlIgnore]public override bool LayoutIsValid\r
+ {\r
+ get\r
+ {\r
+ if (!Visible)\r
+ return true;\r
+\r
+ return !base.LayoutIsValid || child == null ?\r
+ base.LayoutIsValid :\r
+ child.LayoutIsValid;\r
+ }\r
+ set { base.LayoutIsValid = value; }\r
+ }\r
+\r
public override GraphicObject FindByName (string nameToFind)\r
{\r
if (Name == nameToFind)\r
if (child != null)\r
child.InvalidateLayout();\r
}\r
- public override bool LayoutIsValid\r
- {\r
- get\r
- {\r
- if (!Visible)\r
- return true;\r
-\r
- return !base.LayoutIsValid || child == null ?\r
- base.LayoutIsValid :\r
- child.LayoutIsValid;\r
- }\r
- set { base.LayoutIsValid = value; }\r
- }\r
- public override Size measureRawSize ()\r
+ protected override Size measureRawSize ()\r
{\r
Size raw = Bounds.Size;\r
\r
if (child != null) {\r
if (Bounds.Width < 0 && child.WIsValid)\r
- raw.Width = child.Width + 2 * (Margin + BorderWidth);\r
+ raw.Width = child.Slot.Width + 2 * (Margin);\r
if (Bounds.Height < 0 && child.HIsValid)\r
- raw.Height = child.Height + 2 * (Margin + BorderWidth);\r
+ raw.Height = child.Slot.Height + 2 * (Margin);\r
}\r
\r
return raw;\r
{\r
if (!child.LayoutIsValid) {\r
child.UpdateLayout ();\r
-\r
- if (!WIsValid) {\r
- if (Width < 0 && child.WIsValid) {\r
- Slot.Width = child.Slot.Width + 2 * Margin + 2 * BorderWidth;\r
- WIsValid = true;\r
- }\r
- }\r
- if (!HIsValid) {\r
- if (Height < 0 && child.HIsValid) {\r
- Slot.Height = child.Slot.Height + 2 * Margin + 2 * BorderWidth;\r
- HIsValid = true;\r
- }\r
- }\r
}\r
}\r
\r
if (LayoutIsValid)\r
registerForRedraw();\r
}\r
-// public override void onDraw (Cairo.Context gr)\r
-// {\r
-// base.onDraw (gr);\r
-//\r
-// if (child == null)\r
-// return;\r
-// if (!child.Visible)\r
-// return;\r
-//\r
-// child.Paint (ref gr);\r
-// }\r
public override Rectangle ContextCoordinates (Rectangle r)\r
{\r
return\r
\r
ctx.Restore(); \r
}\r
+ #endregion\r
\r
#region Mouse handling\r
public override void onMouseMove (object sender, MouseMoveEventArgs e)\r
{\r
public class GenericStack : Group\r
{\r
- int currentXForWidget = 0;\r
- int currentYForWidget = 0;\r
- bool childrenArePositionned = false;\r
- int _widgetSpacing;\r
- Orientation _orientation;\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(-1)]\r
- public override int Width {\r
- get { return base.Width; }\r
- set { base.Width = value; }\r
+ #region CTOR\r
+ public GenericStack()\r
+ : base()\r
+ { \r
}\r
+ #endregion\r
\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(-1)]\r
- public override int Height {\r
- get { return base.Height; }\r
- set { base.Height = value; }\r
- }\r
+ #region Private fields\r
+ bool childrenArePositionned = false;\r
+ int _spacing;\r
+ Orientation _orientation;\r
+ #endregion\r
\r
- [XmlAttributeAttribute()]\r
- [DefaultValue(2)]\r
- public int WidgetSpacing\r
+ #region Public Properties\r
+ [XmlAttributeAttribute()][DefaultValue(2)]\r
+ public int Spacing\r
{\r
- get { return _widgetSpacing; }\r
- set { _widgetSpacing = value; }\r
+ get { return _spacing; }\r
+ set { _spacing = value; }\r
}\r
-\r
- [XmlAttributeAttribute()]\r
- [DefaultValue(Orientation.Horizontal)]\r
+ [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)]\r
public virtual Orientation Orientation\r
{\r
get { return _orientation; }\r
set { _orientation = value; }\r
}\r
+ #endregion\r
\r
- public GenericStack()\r
- : base()\r
- { \r
- }\r
-\r
- public override bool LayoutIsValid {\r
+ #region GraphicObject Overrides\r
+ [XmlAttributeAttribute()][DefaultValue(-1)]\r
+ public override int Width {\r
+ get { return base.Width; }\r
+ set { base.Width = value; }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue(-1)]\r
+ public override int Height {\r
+ get { return base.Height; }\r
+ set { base.Height = value; }\r
+ }\r
+ [XmlIgnore]public override bool LayoutIsValid {\r
get { return childrenArePositionned && base.LayoutIsValid; }\r
set { base.LayoutIsValid = value; }\r
}\r
+\r
public override void InvalidateLayout ()\r
{\r
childrenArePositionned = false;\r
base.InvalidateLayout ();\r
}\r
- public override Size measureRawSize ()\r
+ protected override Size measureRawSize ()\r
{\r
Size raw = Bounds.Size;\r
Size tmp = new Size ();\r
if (raw.Width < 0) {\r
if (c.WIsValid) {\r
if (Orientation == Orientation.Horizontal && c.Bounds.Width != 0)\r
- tmp.Width += c.Slot.Width + WidgetSpacing;\r
+ tmp.Width += c.Slot.Width + Spacing;\r
else\r
tmp.Width = Math.Max (tmp.Width, c.Slot.Right);\r
}else\r
if (raw.Height < 0) {\r
if (c.HIsValid) {\r
if (Orientation == Orientation.Vertical && c.Bounds.Height != 0)\r
- tmp.Height += c.Slot.Height + WidgetSpacing;\r
+ tmp.Height += c.Slot.Height + Spacing;\r
else\r
tmp.Height = Math.Max (tmp.Height, c.Slot.Bottom);\r
}else\r
}\r
\r
if (raw.Width < 0)\r
- tmp.Width += 2*(BorderWidth+Margin);\r
+ tmp.Width += 2*Margin;\r
if (raw.Height < 0)\r
- tmp.Height += 2*(BorderWidth+Margin);\r
+ tmp.Height += 2*Margin;\r
\r
return tmp;\r
}\r
\r
c.Slot.X = d;\r
c.XIsValid = true;\r
- d += c.Slot.Width + WidgetSpacing;\r
+ d += c.Slot.Width + Spacing;\r
}\r
} else {\r
foreach (GraphicObject c in Children) {\r
\r
c.Slot.Y = d;\r
c.YIsValid = true;\r
- d += c.Slot.Height + WidgetSpacing;\r
+ d += c.Slot.Height + Spacing;\r
}\r
}\r
childrenArePositionned = true;\r
if (LayoutIsValid)\r
registerForRedraw();\r
}\r
-//\r
+ #endregion\r
+\r
+ //\r
// bool enoughtSpaceForWidget(GraphicObject w)\r
// {\r
// if (!SizeToContent)\r
// nextYForWidget = nextYForWidget + w.Slot.Height;\r
//\r
//\r
-// if (nextXForWidget > clientBounds.Right )\r
+// if (nextXForWidget > ClientRectangle.Right )\r
// return false;\r
-// if (currentYForWidget > clientBounds.Bottom )\r
+// if (currentYForWidget > ClientRectangle.Bottom )\r
// return false;\r
// }\r
// return true;\r
// currentYForWidget = currentYForWidget + WidgetSpacing + w.Slot.Height;\r
//\r
// }\r
- }\r
+ \r
+ }\r
}\r
namespace go\r
{\r
public class GraduatedSlider : Slider\r
- { \r
+ { \r
+ #region CTOR\r
public GraduatedSlider() : base()\r
{}\r
public GraduatedSlider(double minimum, double maximum, double step)\r
SmallIncrement = step;\r
LargeIncrement = step * 5;\r
}\r
- public override void DrawGraduations(Context gr, PointD pStart, PointD pEnd)\r
+ #endregion\r
+\r
+ protected override void DrawGraduations(Context gr, PointD pStart, PointD pEnd)\r
{\r
- Rectangle r = clientBounds;\r
+ Rectangle r = ClientRectangle;\r
gr.Color = Foreground;\r
\r
gr.LineWidth = 2;\r
{\r
public class GraphicObject : IXmlSerializable, ILayoutable\r
{\r
+ #region CTOR\r
+ public GraphicObject ()\r
+ {\r
+ loadDefaultValues ();\r
+ registerForGraphicUpdate ();\r
+ }\r
+ public GraphicObject (Rectangle _bounds)\r
+ {\r
+ loadDefaultValues ();\r
+ Bounds = _bounds;\r
+ registerForGraphicUpdate ();\r
+ }\r
+ #endregion\r
\r
- #region private properties\r
-\r
+ #region private fields\r
ILayoutable _parent;\r
string _name;\r
Color _background;\r
Color _foreground;\r
- Color _borderColor;\r
- int _borderWidth;\r
double _cornerRadius;\r
int _margin;\r
bool _focusable = false;\r
bool wIsValid = false;\r
bool xIsValid = false;\r
bool yIsValid = false;\r
-\r
#endregion\r
\r
+ #region public fields\r
public Rectangle Bounds;\r
public Rectangle Slot = new Rectangle ();\r
public object Tag;\r
public byte[] bmp;\r
+ #endregion\r
\r
#region ILayoutable\r
-\r
- [System.Xml.Serialization.XmlIgnore]\r
- public ILayoutable Parent { \r
+ [XmlIgnore]public ILayoutable Parent { \r
get { return _parent; }\r
set { _parent = value; }\r
}\r
- [System.Xml.Serialization.XmlIgnore]\r
- public virtual bool SizeIsValid {\r
+ [XmlIgnore]public virtual bool SizeIsValid {\r
get { return hIsValid & wIsValid; }\r
set {\r
hIsValid = value;\r
wIsValid = value;\r
}\r
}\r
- [System.Xml.Serialization.XmlIgnore]\r
- public virtual bool WIsValid {\r
+ [XmlIgnore]public virtual bool WIsValid {\r
get { return wIsValid; }\r
set { wIsValid = value; }\r
}\r
- [System.Xml.Serialization.XmlIgnore]\r
- public virtual bool HIsValid {\r
+ [XmlIgnore]public virtual bool HIsValid {\r
get { return hIsValid; }\r
set { hIsValid = value; }\r
}\r
- [System.Xml.Serialization.XmlIgnore]\r
- public virtual bool XIsValid {\r
+ [XmlIgnore]public virtual bool XIsValid {\r
get { return xIsValid; }\r
set { xIsValid = value; }\r
}\r
- [System.Xml.Serialization.XmlIgnore]\r
- public virtual bool YIsValid {\r
+ [XmlIgnore]public virtual bool YIsValid {\r
get { return yIsValid; }\r
set { yIsValid = value; }\r
}\r
- [System.Xml.Serialization.XmlIgnore]\r
- public virtual bool PositionIsValid {\r
+ [XmlIgnore]public virtual bool PositionIsValid {\r
get { return xIsValid & yIsValid; }\r
set {\r
xIsValid = value;\r
yIsValid = value;\r
}\r
}\r
- [System.Xml.Serialization.XmlIgnore]\r
- public virtual bool LayoutIsValid {\r
+ [XmlIgnore]public virtual bool LayoutIsValid {\r
get { return SizeIsValid & PositionIsValid; }\r
set {\r
if (value == SizeIsValid & PositionIsValid)\r
// Parent.layoutIsValid = false;\r
}\r
}\r
+ [XmlIgnore]public virtual Rectangle ClientRectangle {\r
+ get {\r
+ Rectangle cb = Slot.Size;\r
+ cb.Inflate ( - Margin);\r
+ return cb;\r
+ }\r
+ }\r
\r
public virtual void InvalidateLayout ()\r
{\r
bmp = null;\r
LayoutIsValid = false;\r
}\r
-\r
- [System.Xml.Serialization.XmlIgnore]\r
- public virtual Rectangle ClientRectangle {\r
- get {\r
- Rectangle cb = Slot.Size;\r
- cb.Inflate ( - BorderWidth - Margin);\r
- return cb;\r
- }\r
- }\r
public virtual Rectangle ContextCoordinates(Rectangle r){\r
return\r
Parent.ContextCoordinates (r);// + ClientRectangle.Position;\r
return \r
Parent.ScreenCoordinates(r) + Parent.getSlot().Position + Parent.ClientRectangle.Position;\r
}\r
+ public virtual Rectangle getSlot()\r
+ {\r
+ return Slot;\r
+ }\r
#endregion\r
\r
- #region event handlers\r
-\r
+ #region EVENT HANDLERS\r
public event EventHandler<MouseWheelEventArgs> MouseWheelChanged = delegate { };\r
public event EventHandler<MouseButtonEventArgs> MouseButtonUp = delegate { };\r
public event EventHandler<MouseButtonEventArgs> MouseButtonDown = delegate { };\r
- public event EventHandler<MouseButtonEventArgs> MouseClicked = delegate { };\r
+ public event EventHandler<MouseButtonEventArgs> MouseClick = delegate { };\r
public event EventHandler<MouseMoveEventArgs> MouseMove = delegate { };\r
public event EventHandler<MouseMoveEventArgs> MouseEnter = delegate { };\r
public event EventHandler<MouseMoveEventArgs> MouseLeave = delegate { };\r
public event EventHandler<KeyboardKeyEventArgs> KeyUp = delegate { };\r
public event EventHandler Focused = delegate { };\r
public event EventHandler Unfocused = delegate { };\r
-\r
#endregion\r
\r
#region public properties\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue("unamed")]\r
+ [XmlAttributeAttribute()][DefaultValue("unamed")]\r
public virtual string Name {\r
get { return _name; }\r
set { _name = value; }\r
}\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(VerticalAlignment.Center)]\r
+ [XmlAttributeAttribute()][DefaultValue(VerticalAlignment.Center)]\r
public virtual VerticalAlignment VerticalAlignment {\r
get { return _verticalAlignment; }\r
set { \r
// if (Top > 0)\r
}\r
}\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(HorizontalAlignment.Center)]\r
+ [XmlAttributeAttribute()][DefaultValue(HorizontalAlignment.Center)]\r
public virtual HorizontalAlignment HorizontalAlignment {\r
get { return _horizontalAlignment; }\r
set { _horizontalAlignment = value; }\r
}\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(0)]\r
+ [XmlAttributeAttribute()][DefaultValue(0)]\r
public virtual int Left {\r
get { return Bounds.X; }\r
set {\r
registerForGraphicUpdate ();\r
}\r
}\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(0)]\r
+ [XmlAttributeAttribute()][DefaultValue(0)]\r
public virtual int Top {\r
get { return Bounds.Y; }\r
set {\r
registerForGraphicUpdate ();\r
}\r
}\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(0)]\r
+ [XmlAttributeAttribute()][DefaultValue(0)]\r
public virtual int Width {\r
get { return Bounds.Width; }\r
set {\r
InvalidateLayout ();\r
}\r
}\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(0)]\r
+ [XmlAttributeAttribute()][DefaultValue(0)]\r
public virtual int Height {\r
get { return Bounds.Height; }\r
set {\r
InvalidateLayout ();\r
}\r
}\r
+ [XmlAttributeAttribute()][DefaultValue(false)]\r
+ public virtual bool Fit {\r
+ get { return Bounds.Width < 0 && Bounds.Height < 0 ? true : false; }\r
+ set {\r
+ if (value == Fit)\r
+ return;\r
\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(false)]\r
+ Bounds.Width = Bounds.Height = -1;\r
+ InvalidateLayout ();\r
+ }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue(false)]\r
public virtual bool Focusable {\r
get { return _focusable; }\r
set { _focusable = value; }\r
- }\r
- \r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue("Transparent")]\r
+ } \r
+ [XmlAttributeAttribute()][DefaultValue("Transparent")]\r
public virtual Color Background {\r
get { return _background; }\r
set {\r
registerForGraphicUpdate ();\r
}\r
}\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue("White")]\r
+ [XmlAttributeAttribute()][DefaultValue("White")]\r
public virtual Color Foreground {\r
get { return _foreground; }\r
set {\r
registerForGraphicUpdate ();\r
}\r
}\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue("White")]\r
- public virtual Color BorderColor {\r
- get { return _borderColor; }\r
- set {\r
- _borderColor = value;\r
- registerForGraphicUpdate ();\r
- }\r
- }\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(0)]\r
- public virtual int BorderWidth {\r
- get { return _borderWidth; }\r
- set {\r
- _borderWidth = value;\r
- registerForGraphicUpdate ();\r
- }\r
- }\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(5)]\r
+ [XmlAttributeAttribute()][DefaultValue(5)]\r
public virtual double CornerRadius {\r
get { return _cornerRadius; }\r
set {\r
registerForGraphicUpdate ();\r
}\r
}\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(0)]\r
+ [XmlAttributeAttribute()][DefaultValue(0)]\r
public virtual int Margin {\r
get { return _margin; }\r
set {\r
registerForGraphicUpdate ();\r
}\r
}\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(true)]\r
+ [XmlAttributeAttribute()][DefaultValue(true)]\r
public virtual bool Visible {\r
get { return _isVisible; }\r
set {\r
// registerForRedraw();\r
}\r
}\r
- //should maybe test only focusedWidget in higher container (opentkwin for now)\r
- [System.Xml.Serialization.XmlIgnore]\r
- public virtual bool HasFocus {\r
+ [XmlIgnore]public virtual bool HasFocus {\r
get { return _hasFocus; }\r
set { _hasFocus = value; }\r
}\r
-\r
- [System.Xml.Serialization.XmlIgnore]\r
- public virtual bool isCached {\r
- get { return false; }\r
- }\r
-\r
- [System.Xml.Serialization.XmlIgnore]\r
- public virtual bool cachingInProgress {\r
- get { return false; }\r
- set { return; }\r
- }\r
-\r
- public virtual Rectangle clientBounds {\r
- get {\r
- Rectangle cb = Slot.Size;\r
- cb.Inflate (-(BorderWidth + Margin));\r
- return cb;\r
- }\r
- }\r
-\r
-\r
-\r
-\r
-\r
-\r
- public virtual Rectangle getSlot()\r
- {\r
- return Slot;\r
- }\r
- [XmlIgnore]\r
- public virtual bool DrawingIsValid\r
+ [XmlIgnore]public virtual bool DrawingIsValid\r
{ get { return bmp == null ? \r
false : \r
true; } }\r
#endregion\r
\r
- public GraphicObject ()\r
- {\r
- loadDefaultValues ();\r
- registerForGraphicUpdate ();\r
- }\r
- public GraphicObject (Rectangle _bounds)\r
- {\r
- loadDefaultValues ();\r
- Bounds = _bounds;\r
- registerForGraphicUpdate ();\r
- }\r
/// <summary>\r
/// Loads the default values from XML attributes default\r
/// </summary>\r
if (dv != null) {\r
if (pi.PropertyType == typeof(Color))\r
pi.SetValue (this, Color.Parse ((string)dv.Value), null);\r
+ else if (pi.PropertyType == typeof(Font))\r
+ pi.SetValue (this, Font.Parse ((string)dv.Value), null);\r
else\r
pi.SetValue (this, dv.Value, null);\r
continue;\r
{\r
OpenTKGameWindow.redrawClip.AddRectangle (ScreenCoordinates(Slot));\r
}\r
- public virtual Size measureRawSize ()\r
+ protected virtual Size measureRawSize ()\r
{\r
return Bounds.Size;\r
}\r
\r
- public virtual void ComputeSize()\r
+ protected virtual void ComputeSize()\r
{\r
Size rawSize = measureRawSize ();\r
\r
hIsValid = false; \r
}\r
}\r
- public virtual void ComputePosition()\r
+ protected virtual void ComputePosition()\r
{\r
if (!xIsValid) {\r
xIsValid = true;\r
}\r
public virtual void UpdateLayout ()\r
{\r
-// if (LayoutIsValid)\r
-// return;\r
-//\r
- //should maybe invalidate drawing\r
-\r
- //Rectangle oldRenderBounds = Slot;\r
-\r
if (!SizeIsValid)\r
ComputeSize ();\r
if (!PositionIsValid)\r
registerForRedraw ();\r
\r
}\r
- public virtual void onDraw(Context gr)\r
+ protected virtual void onDraw(Context gr)\r
{\r
Rectangle rBack = new Rectangle (Slot.Size);\r
\r
- if (BorderWidth > 0) \r
- rBack.Inflate (-BorderWidth / 2);\r
-\r
gr.Color = Background;\r
CairoHelpers.CairoRectangle(gr,rBack,_cornerRadius);\r
gr.Fill ();\r
-\r
- if (BorderWidth > 0) {\r
-\r
- gr.LineWidth = BorderWidth;\r
- gr.Color = BorderColor;\r
- CairoHelpers.CairoRectangle(gr,rBack,_cornerRadius);\r
- gr.Stroke ();\r
- }\r
}\r
-\r
- internal virtual void UpdateGraphic ()\r
+ protected virtual void UpdateGraphic ()\r
{\r
int stride = 4 * Slot.Width;\r
\r
draw.Flush ();\r
}\r
}\r
-\r
- //could maybe be internal\r
+ \r
public virtual void Paint (ref Context ctx, Rectangles clip = null)\r
{\r
if (!Visible)\r
#endregion\r
\r
#region Mouse handling\r
-\r
public virtual bool MouseIsIn(Point m)\r
{\r
- return Visible ? ScreenCoordinates(Slot).ContainsOrIsEqual (m) : false; \r
+ return Visible & Focusable ? ScreenCoordinates(Slot).ContainsOrIsEqual (m) : false; \r
}\r
public virtual void onMouseMove(object sender, MouseMoveEventArgs e)\r
{\r
w.hoverWidget = this;\r
onMouseEnter (sender, e);\r
}\r
-\r
- if (MouseMove != null)\r
- MouseMove (sender, e);\r
+ \r
+ MouseMove (this, e);\r
}\r
public virtual void onMouseButtonUp(object sender, MouseButtonEventArgs e){\r
if (MouseIsIn (e.Position))\r
- onMouseClicked (sender, e);\r
- if (MouseButtonUp != null)\r
- MouseButtonUp (sender, e);\r
+ onMouseClick (sender, e);\r
+\r
+ MouseButtonUp (this, e);\r
}\r
public virtual void onMouseButtonDown(object sender, MouseButtonEventArgs e){\r
(sender as OpenTKGameWindow).FocusedWidget = this;\r
- if (MouseButtonDown!=null)\r
- MouseButtonDown (sender, e);\r
+\r
+ MouseButtonDown (this, e);\r
}\r
- public virtual void onMouseClicked(object sender, MouseButtonEventArgs e){ \r
- if (MouseClicked!=null)\r
- MouseClicked(sender,e);\r
+ public virtual void onMouseClick(object sender, MouseButtonEventArgs e){ \r
+ MouseClick(this,e);\r
}\r
public virtual void onMouseWheel(object sender, MouseWheelEventArgs e){\r
GraphicObject p = Parent as GraphicObject;\r
if (p != null)\r
p.onMouseWheel(this,e);\r
-\r
- if (MouseWheelChanged!=null)\r
- MouseWheelChanged (this, e);\r
+ \r
+ MouseWheelChanged (this, e);\r
}\r
public virtual void onFocused(object sender, EventArgs e){\r
- if (Focused!=null)\r
- Focused (sender, e);\r
+ Focused (this, e);\r
this.HasFocus = true;\r
}\r
public virtual void onUnfocused(object sender, EventArgs e){\r
- if (Unfocused!=null)\r
- Unfocused (sender, e);\r
+ Unfocused (this, e);\r
this.HasFocus = false;\r
}\r
public virtual void onMouseEnter(object sender, MouseMoveEventArgs e)\r
{\r
- //Debug.WriteLine ("Mouse Enter: " + this.ToString ());\r
- if (MouseEnter != null)\r
- MouseEnter (this, e);\r
+ Debug.WriteLine ("Mouse enter: " + this.Name);\r
+ MouseEnter (this, e);\r
}\r
public virtual void onMouseLeave(object sender, MouseMoveEventArgs e)\r
{\r
- if (MouseLeave != null)\r
- MouseLeave (this, e);\r
+ Debug.WriteLine ("Mouse leave: " + this.Name);\r
+ MouseLeave (this, e);\r
}\r
#endregion\r
\r
\r
foreach (EventSource es in EventsToResolve)\r
{\r
- if (es.Handler == null)\r
+ if (string.IsNullOrEmpty(es.Handler))\r
continue;\r
- \r
- MethodInfo mi = ClassContainingHandlers.GetType().GetMethod(es.Handler, BindingFlags.NonPublic | BindingFlags.Public\r
- | BindingFlags.Instance);\r
\r
- if (mi == null) {\r
- Debug.WriteLine ("Handler Method not found: " + es.Handler);\r
- continue;\r
- }\r
- FieldInfo fi;\r
- Type ty = es.Source.GetType ();\r
- do {\r
- fi = ty.GetField (es.EventName,\r
- BindingFlags.NonPublic |\r
- BindingFlags.Instance |\r
- BindingFlags.GetField);\r
- ty = ty.BaseType;\r
- if (ty == null)\r
- break;\r
- } while(fi == null);\r
- Delegate del = Delegate.CreateDelegate(fi.FieldType, ClassContainingHandlers, mi);\r
- fi.SetValue(es.Source, del);\r
+ if (es.Handler.StartsWith ("{")) {\r
+ CompilerServices.CompileEventSource (es);\r
+ } else { \r
+ MethodInfo mi = ClassContainingHandlers.GetType ().GetMethod (es.Handler, BindingFlags.NonPublic | BindingFlags.Public\r
+ | BindingFlags.Instance);\r
+\r
+ if (mi == null) {\r
+ Debug.WriteLine ("Handler Method not found: " + es.Handler);\r
+ continue;\r
+ }\r
\r
+ FieldInfo fi = CompilerServices.getEventHandlerField (es.Source.GetType (), es.EventName);\r
+ Delegate del = Delegate.CreateDelegate(fi.FieldType, ClassContainingHandlers, mi);\r
+ fi.SetValue(es.Source, del);\r
+ }\r
}\r
\r
}\r
public override string ToString ()\r
{\r
return Name == "unamed" ? this.GetType ().ToString() : Name;\r
-// string tmp = this.GetType ().ToString ().Split (new char[] { '.' }).Last () + ":-";\r
-// if (!LayoutIsValid)\r
-// tmp += "L-";\r
-// //if (Interface.graphicUpdateList.Contains(this))\r
-// // tmp += "GU-";\r
-// if (OpenTKGameWindow.redrawClip.intersect (this.renderBoundsInBackendSurfaceCoordonate))\r
-// tmp += "D-";\r
-// return tmp + string.Format ("rb:{0}", Slot);\r
}\r
\r
#region IXmlSerializable\r
string handler = reader.GetAttribute(ei.Name);\r
if (string.IsNullOrEmpty (handler))\r
continue;\r
+ \r
GraphicObject.EventsToResolve.Add(new EventSource \r
{ \r
Source = this, \r
//TODO: maybe find another way to convert correctely colors default values\r
if (pi.PropertyType == typeof(Color))\r
pi.SetValue (this, Color.Parse ((string)defaultValue), null);\r
+ else if (pi.PropertyType == typeof(Font))\r
+ pi.SetValue (this, Font.Parse ((string)defaultValue), null);\r
else\r
pi.SetValue (this, defaultValue, null);\r
} else {\r
{\r
public class Group : GraphicObject, IXmlSerializable\r
{\r
+ #region CTOR\r
+ public Group()\r
+ : base()\r
+ { \r
+ }\r
+ #endregion\r
+\r
bool _multiSelect = false;\r
\r
public GraphicObject activeWidget;\r
-\r
public List<GraphicObject> Children = new List<GraphicObject>();\r
\r
- [XmlAttributeAttribute()]\r
- [DefaultValue(false)]\r
+ [XmlAttributeAttribute()][DefaultValue(false)]\r
public bool MultiSelect\r
{\r
get { return _multiSelect; }\r
set { _multiSelect = value; }\r
}\r
\r
-\r
- public Group()\r
- : base()\r
- { \r
- }\r
\r
public virtual T addChild<T>(T child)\r
{\r
child.Parent = null;\r
LayoutIsValid = false;\r
}\r
+ public void putWidgetOnTop(GraphicObject w)\r
+ {\r
+ if (Children.Contains(w))\r
+ {\r
+ Children.Remove(w);\r
+ Children.Add(w);\r
+ }\r
+ }\r
+ public void putWidgetOnBottom(GraphicObject w)\r
+ {\r
+ if (Children.Contains(w))\r
+ {\r
+ Children.Remove(w);\r
+ Children.Insert(0, w);\r
+ }\r
+ }\r
\r
#region GraphicObject overrides\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(true)]//overiden to get default to true\r
+ [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true\r
public override bool Focusable\r
{\r
get { return base.Focusable; }\r
set { base.Focusable = value; }\r
}\r
- [XmlIgnore]\r
- public override bool DrawingIsValid {\r
+ [XmlIgnore]public override bool DrawingIsValid {\r
get {\r
if (!base.DrawingIsValid)\r
return false;\r
return true;\r
}\r
}\r
- [XmlIgnore]\r
- public override bool LayoutIsValid\r
+ [XmlIgnore]public override bool LayoutIsValid\r
{\r
get\r
{\r
foreach (GraphicObject w in Children)\r
w.InvalidateLayout();\r
}\r
- public override Size measureRawSize ()\r
+ protected override Size measureRawSize ()\r
{\r
Size raw = Bounds.Size;\r
Size tmp = new Size ();\r
}\r
\r
if (raw.Width < 0)\r
- tmp.Width += 2*(BorderWidth+Margin);\r
+ tmp.Width += 2*Margin;\r
if (raw.Height < 0)\r
- tmp.Height += 2*(BorderWidth+Margin);\r
+ tmp.Height += 2*Margin;\r
\r
return tmp;\r
}\r
return r + ClientRectangle.Position;\r
} \r
\r
- public override void onDraw (Context gr)\r
+ protected override void onDraw (Context gr)\r
{\r
Rectangle rBack = new Rectangle (Slot.Size);\r
gr.Color = Background;\r
\r
public override void Paint(ref Context ctx, Rectangles clip = null)\r
{\r
- if ( !(Visible & LayoutIsValid) )\r
+ if ( !(Visible&LayoutIsValid) )\r
return;\r
\r
// ctx.Save ();\r
base.onMouseMove (sender, e);\r
}\r
#endregion\r
-\r
- public void putWidgetOnTop(GraphicObject w)\r
- {\r
- if (Children.Contains(w))\r
- {\r
- Children.Remove(w);\r
- Children.Add(w);\r
- }\r
- }\r
- public void putWidgetOnBottom(GraphicObject w)\r
- {\r
- if (Children.Contains(w))\r
- {\r
- Children.Remove(w);\r
- Children.Insert(0, w);\r
- }\r
- }\r
\r
public override string ToString()\r
{\r
using System;\r
using System.Collections.Generic;\r
+using System.ComponentModel;\r
using System.Text;\r
-using Cairo;\r
using System.Xml.Serialization;\r
-using System.ComponentModel;\r
+using Cairo;\r
\r
namespace go\r
{\r
\r
- public class GroupBox : Container\r
+ public class GroupBox : Border\r
{\r
+ #region CTOR\r
+ public GroupBox() : base (){\r
+ }\r
+ public GroupBox(string _title = "GroupBox")\r
+ : base()\r
+ {\r
+ Text = _title; \r
+ }\r
+ #endregion\r
+\r
+ #region private fields\r
string _title;\r
- int _fontSize = 10;\r
+ Font _font;\r
+ #endregion\r
\r
- [XmlAttributeAttribute]\r
- [DefaultValue("GroupBox")]\r
+ #region public properties\r
+ [XmlAttributeAttribute][DefaultValue("GroupBox")]\r
public string Text\r
{\r
get { return _title; }\r
_title = value;\r
registerForGraphicUpdate();\r
}\r
- }\r
- \r
- [XmlAttributeAttribute]\r
- [DefaultValue(10)]\r
- public int fontSize\r
- {\r
- get { return _fontSize; }\r
- set\r
- {\r
- _fontSize = value;\r
- registerForGraphicUpdate();\r
- }\r
- }\r
+ } \r
+ [XmlAttributeAttribute()][DefaultValue("droid,12")]\r
+ public Font Font {\r
+ get { return _font; }\r
+ set { _font = value; }\r
+ }\r
+ #endregion\r
\r
- public Size titleSize()\r
- {\r
+ Size titleSize {\r
+ get {\r
#if _WIN32 || _WIN64\r
byte[] txt = System.Text.UTF8Encoding.UTF8.GetBytes(_title);\r
#endif\r
\r
- Size s;\r
+ Size s;\r
\r
- using (ImageSurface img = new ImageSurface (Format.Argb32, 1, 1)) {\r
- using (Context gr = new Context (img)) {\r
- gr.SetFontSize (fontSize);\r
- TextExtents te;\r
+ using (ImageSurface img = new ImageSurface (Format.Argb32, 1, 1)) {\r
+ using (Context gr = new Context (img)) {\r
+ gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);\r
+ gr.SetFontSize (Font.Size);\r
+ TextExtents te;\r
#if _WIN32 || _WIN64\r
te = gr.TextExtents(txt);\r
#elif __linux__\r
- te = gr.TextExtents (Text);\r
+ te = gr.TextExtents (Text);\r
#endif\r
- FontExtents fe = gr.FontExtents;\r
- s = new Size ((int)Math.Ceiling (te.XAdvance), (int)Math.Ceiling (fe.Height));\r
+ FontExtents fe = gr.FontExtents;\r
+ s = new Size ((int)Math.Ceiling (te.XAdvance), (int)Math.Ceiling (fe.Height));\r
+ }\r
}\r
+ return s;// +borderWidth;\r
}\r
- return s;// +borderWidth;\r
- }\r
-\r
- public GroupBox() : base (){\r
}\r
- public GroupBox(Rectangle _bounds, string _title = "GroupBox")\r
- : base(_bounds)\r
- {\r
- Text = _title;\r
- }\r
- \r
- public GroupBox(string _title = "GroupBox")\r
- : base()\r
- {\r
- Text = _title; \r
- }\r
- \r
- public override Rectangle clientBounds\r
- {\r
- get\r
- {\r
- Size ts = titleSize();\r
-\r
- Rectangle cb = Slot;\r
- cb.X = 0;\r
- cb.Y = ts.Height;\r
- cb.Height -= ts.Height;\r
- cb.Inflate(-BorderWidth - Margin);\r
- \r
- return cb;\r
- }\r
- } \r
\r
- public override void onDraw (Context gr)\r
+ #region GraphicObject overrides\r
+ public override Rectangle ClientRectangle {\r
+ get {\r
+ Size ts = titleSize;\r
+ Rectangle cb = Slot.Size;\r
+ cb.Y = ts.Height;\r
+ cb.Height -= ts.Height;\r
+ cb.Inflate ( - Margin);\r
+ return cb;\r
+ }\r
+ } \r
+ protected override Size measureRawSize ()\r
+ {\r
+ Size raw = base.measureRawSize ();\r
+ return raw > 0 ? raw + titleSize : raw;\r
+ }\r
+ protected override void onDraw (Context gr)\r
{\r
//base.onDraw (gr);\r
\r
byte[] txt = System.Text.UTF8Encoding.UTF8.GetBytes(Text);\r
Rectangle r = new Rectangle(Slot.Size);\r
+ if (BorderWidth > 0) \r
+ r.Inflate (-BorderWidth / 2);\r
+\r
//gr.Rotate(Math.PI);\r
- gr.SetFontSize(fontSize);\r
+ gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);\r
+ gr.SetFontSize (Font.Size);\r
FontExtents fe = gr.FontExtents;\r
TextExtents te = gr.TextExtents(Text);\r
\r
gr.LineWidth = BorderWidth;\r
gr.Color = Background;\r
\r
- CairoHelpers.CairoRectangle (gr, r, CornerRadius);\r
- gr.Fill();\r
+\r
\r
Rectangle rTitle = r;\r
\r
r.Y += th;\r
r.Height -= th;\r
\r
+ CairoHelpers.CairoRectangle (gr, r, CornerRadius);\r
+ gr.Fill();\r
+\r
const int titleGap = 5;\r
\r
if (BorderWidth > 0)\r
{\r
gr.Color = BorderColor;\r
- gr.LineWidth = BorderWidth;\r
-\r
- r.Inflate(-BorderWidth / 2, -BorderWidth / 2);\r
\r
rTitle.X = r.X + titleGap;\r
rTitle.Width = (int)Math.Ceiling(te.XAdvance) + 2 * titleGap;\r
gr.Color = Foreground;\r
gr.Fill();\r
}\r
+ #endregion\r
\r
public override string ToString()\r
{\r
- return this.Text + ":" + base.ToString();\r
+ return base.ToString() + ": " + this.Text;\r
}\r
}\r
}\r
Bitmap = _bitmap;\r
}\r
\r
- public override Size measureRawSize ()\r
+ protected override Size measureRawSize ()\r
{\r
if (image == null)\r
loadImage (@"Images/Icons/icon_alert.gif"); \r
\r
- return imgSize + (BorderWidth + Margin)*2;\r
+ return imgSize + Margin*2;\r
}\r
\r
//load image via System.Drawing.Bitmap, cairo load png only\r
bitmap.UnlockBits (data);\r
//bitmap.Dispose(); \r
}\r
- public override void onDraw (Context gr)\r
+ protected override void onDraw (Context gr)\r
{\r
base.onDraw (gr);\r
float ratio = 1f;\r
- float widthRatio = (float)clientBounds.Width / imgSize.Width;\r
- float heightRatio = (float)clientBounds.Height / imgSize.Height;\r
+ float widthRatio = (float)ClientRectangle.Width / imgSize.Width;\r
+ float heightRatio = (float)ClientRectangle.Height / imgSize.Height;\r
\r
ratio = Math.Min (widthRatio, heightRatio);\r
- Rectangle rImg = clientBounds;\r
+ Rectangle rImg = ClientRectangle;\r
\r
gr.Scale (widthRatio, heightRatio);\r
using (ImageSurface imgSurf = new ImageSurface(image, Format.Argb32, \r
using System.Diagnostics;\r
using Cairo;\r
using System.Text.RegularExpressions;\r
+using System.Xml.Serialization;\r
+using System.ComponentModel;\r
\r
namespace go\r
{\r
[Serializable]\r
public class Label : GraphicObject\r
{\r
+ #region CTOR\r
+ public Label()\r
+ { \r
+\r
+ }\r
+ public Label(string _text)\r
+ : base()\r
+ {\r
+ Text = _text;\r
+ }\r
+ #endregion\r
+\r
//TODO:change protected to private\r
\r
+ #region private and protected fields\r
protected string _text = "label";\r
- Alignment _textAlignment = Alignment.LeftCenter;\r
- int _fontSize = 12;\r
+ Alignment _textAlignment = Alignment.LeftCenter; \r
+ Font _font;\r
bool _multiline = false;\r
\r
protected Rectangle rText;\r
protected float heightRatio = 1f;\r
protected FontExtents fe;\r
protected TextExtents te;\r
+ #endregion\r
\r
//public string FontFace = "MagicMedieval";\r
- public string FontFace = "droid";\r
-\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(-1)]\r
- public override int Width {\r
- get { return base.Width; }\r
- set { base.Width = value; }\r
- }\r
\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(-1)]\r
- public override int Height {\r
- get { return base.Height; }\r
- set { base.Height = value; }\r
- }\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(2)]\r
- public virtual int Margin {\r
- get { return base.Margin; }\r
- set { base.Margin = value; }\r
- }\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(Alignment.LeftCenter)]\r
+ [XmlAttributeAttribute()][DefaultValue(Alignment.LeftCenter)]\r
public Alignment TextAlignment\r
{\r
get { return _textAlignment; }\r
set { _textAlignment = value; }\r
}\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
+ [XmlAttributeAttribute()][DefaultValue("label")]\r
public string Text\r
{\r
get { return _text; }\r
_text = value;\r
}\r
}\r
- \r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(10)]\r
- public int FontSize\r
- {\r
- get { return _fontSize; }\r
- set\r
- {\r
- _fontSize = value;\r
- registerForGraphicUpdate();\r
- }\r
- }\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(false)]\r
+ [XmlAttributeAttribute()][DefaultValue("droid,10")]\r
+ public Font Font {\r
+ get { return _font; }\r
+ set { _font = value; }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue(false)]\r
public bool Multiline\r
{\r
get { return _multiline; }\r
registerForGraphicUpdate();\r
}\r
}\r
-\r
- public Label()\r
- { \r
-\r
- }\r
-\r
- public Label(string _text)\r
- : base()\r
- {\r
- //updateFont();\r
- Text = _text;\r
- }\r
-\r
- void updateFont()\r
- {\r
- //TextFont = new Font(fontFamily, fontSize, fontStyle, GraphicsUnit.Pixel);\r
-\r
- bmp = null;\r
- }\r
- \r
+ \r
string[] getLines {\r
get {\r
return _multiline ?\r
}\r
}\r
\r
- public override Size measureRawSize()\r
+ #region GraphicObject overrides\r
+ [XmlAttributeAttribute()][DefaultValue(-1)]\r
+ public override int Width {\r
+ get { return base.Width; }\r
+ set { base.Width = value; }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue(-1)]\r
+ public override int Height {\r
+ get { return base.Height; }\r
+ set { base.Height = value; }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue(2)]\r
+ public override int Margin {\r
+ get { return base.Margin; }\r
+ set { base.Margin = value; }\r
+ }\r
+\r
+ protected override Size measureRawSize()\r
{\r
Size s;\r
\r
using (ImageSurface img = new ImageSurface (Format.Argb32, 1, 1)) {\r
using (Context gr = new Context (img)) {\r
//Cairo.FontFace cf = gr.GetContextFontFace ();\r
- gr.SelectFontFace (FontFace, FontSlant.Normal, FontWeight.Normal);\r
- gr.SetFontSize (FontSize);\r
+\r
+ gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);\r
+ gr.SetFontSize (Font.Size);\r
\r
te = new TextExtents();\r
\r
te = tmp;\r
}\r
fe = gr.FontExtents;\r
- s = new Size ((int)Math.Ceiling (te.XAdvance) + (BorderWidth + Margin) * 2, (int)Math.Ceiling (fe.Height) * lines.Length + (BorderWidth + Margin) * 2);\r
+ s = new Size ((int)Math.Ceiling (te.XAdvance) + Margin * 2, (int)Math.Ceiling (fe.Height) * lines.Length + Margin*2);\r
}\r
}\r
return s;// +borderWidth;\r
}\r
- public override void onDraw (Context gr)\r
+ protected override void onDraw (Context gr)\r
{\r
base.onDraw (gr);\r
string[] lines = getLines;\r
\r
- gr.SelectFontFace(FontFace, FontSlant.Normal, FontWeight.Normal);\r
+ gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);\r
+ gr.SetFontSize (Font.Size);\r
\r
- gr.LineWidth = BorderWidth;\r
gr.Antialias = Antialias.Subpixel;\r
//gr.FontOptions.Antialias = Antialias.Subpixel;\r
//gr.FontOptions.HintMetrics = HintMetrics.On;\r
- gr.SetFontSize(FontSize);\r
\r
rText = new Rectangle(new Point(0, 0),new Size((int)te.Width,(int)fe.Height * lines.Length));\r
\r
widthRatio = 1f;\r
heightRatio = 1f;\r
\r
- Rectangle cb = clientBounds;\r
+ Rectangle cb = ClientRectangle;\r
\r
//ignore text alignment if size to content = true\r
if (Bounds.Size < 0)\r
\r
gr.Color = Foreground;\r
\r
- gr.FontMatrix = new Matrix(widthRatio * FontSize, 0, 0, heightRatio * FontSize, 0, 0);\r
+ gr.FontMatrix = new Matrix(widthRatio * Font.Size, 0, 0, heightRatio * Font.Size, 0, 0);\r
\r
for (int i = 0; i < lines.Length; i++) {\r
gr.MoveTo(rText.X, rText.Y + fe.Ascent + fe.Height * i);\r
} \r
gr.Fill();\r
}\r
+ #endregion\r
}\r
}\r
using System;
+using System.Xml.Serialization;
+using System.ComponentModel;
namespace go
{
public class NumericControl : GraphicObject
{
+ #region CTOR
public NumericControl () : base()
{
}
_smallStep = step;
_bigStep = step * 5;
}
+ #endregion
#region event handlers
public EventHandler<ValueChangeEventArgs> ValueChanged;
}
#endregion
+ #region private fields
double _actualValue, _minValue, _maxValue, _smallStep, _bigStep;
+ #endregion
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(0)]
+ #region public properties
+ [XmlAttributeAttribute()][DefaultValue(0)]
public virtual double Minimum {
get { return _minValue; }
set {
registerForGraphicUpdate ();
}
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(10.0)]
+ [XmlAttributeAttribute()][DefaultValue(10.0)]
public virtual double Maximum
{
get { return _maxValue; }
registerForGraphicUpdate ();
}
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(0.5)]
+ [XmlAttributeAttribute()][DefaultValue(0.5)]
public virtual double SmallIncrement
{
get { return _smallStep; }
registerForGraphicUpdate ();
}
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(2.0)]
+ [XmlAttributeAttribute()][DefaultValue(2.0)]
public virtual double LargeIncrement
{
get { return _bigStep; }
registerForGraphicUpdate ();
}
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(0)]
+ [XmlAttributeAttribute()][DefaultValue(0)]
public double Value
{
get { return _actualValue; }
registerForGraphicUpdate();
}
}
+ #endregion
+
}
}
using System.Text;\r
using Cairo;\r
using System.Diagnostics;\r
+using System.Xml.Serialization;\r
+using System.ComponentModel;\r
\r
namespace go\r
{\r
[Serializable]\r
- public class ProgressBar : GraphicObject\r
+ public class ProgressBar : Border\r
{\r
+ #region CTOR\r
+ public ProgressBar() : base(){}\r
+ public ProgressBar(int _max) : base()\r
+ {\r
+ Maximum = _max;\r
+ }\r
+ #endregion\r
+\r
+ #region private fields\r
int _currentValue = 0;\r
int _minimum = 0;\r
int _maximum = 100;\r
+ #endregion\r
\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue("Gray")]\r
- public override Color Background {\r
- get { return base.Background; }\r
- set { base.Background = value; }\r
- }\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(0)]\r
- public override int BorderWidth {\r
- get { return base.BorderWidth; }\r
- set { base.BorderWidth = value; }\r
- }\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue("BlueCrayola")]\r
- public virtual Color Foreground {\r
- get { return base.Foreground; }\r
- set { base.Foreground = value; }\r
- }\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(0)]\r
- public int Value\r
- {\r
- get { return _currentValue; }\r
- set\r
- {\r
- if (_currentValue == value)\r
- return;\r
-\r
- _currentValue = value;\r
+ #region public properties\r
+ [XmlAttributeAttribute()][DefaultValue(0)]\r
+ public int Value\r
+ {\r
+ get { return _currentValue; }\r
+ set\r
+ {\r
+ if (_currentValue == value)\r
+ return;\r
\r
- if (_currentValue > Maximum)\r
- _currentValue = Maximum;\r
+ _currentValue = value;\r
\r
- registerForGraphicUpdate();\r
- }\r
- }\r
+ if (_currentValue > Maximum)\r
+ _currentValue = Maximum;\r
\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(0)]\r
+ registerForGraphicUpdate();\r
+ }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue(0)]\r
public int Minimum {\r
get {return _minimum;}\r
set {\r
registerForGraphicUpdate ();\r
}\r
}\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(100)]\r
+ [XmlAttributeAttribute()][DefaultValue(100)]\r
public int Maximum {\r
get {return _maximum;}\r
set {\r
registerForGraphicUpdate();\r
}\r
}\r
- \r
- public ProgressBar() : base(){}\r
+ #endregion\r
\r
- public ProgressBar(int _max) : base()\r
- {\r
- Maximum = _max;\r
- }\r
+ #region GraphicObject overrides\r
+ [XmlAttributeAttribute()][DefaultValue("Gray")]\r
+ public override Color Background {\r
+ get { return base.Background; }\r
+ set { base.Background = value; }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue(0)]\r
+ public override int BorderWidth {\r
+ get { return base.BorderWidth; }\r
+ set { base.BorderWidth = value; }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue("BlueCrayola")]\r
+ public virtual Color Foreground {\r
+ get { return base.Foreground; }\r
+ set { base.Foreground = value; }\r
+ }\r
\r
- public override void onDraw (Context gr)\r
+ protected override void onDraw (Context gr)\r
{\r
base.onDraw (gr);\r
\r
CairoHelpers.CairoRectangle(gr,rBack,CornerRadius);\r
gr.Fill();\r
}\r
- public override void Paint (ref Context ctx, Rectangles clip)\r
- {\r
- base.Paint (ref ctx, clip);\r
-// if (clip != null)\r
-// clip.stroke (ctx, Color.Amethyst);\r
- }\r
+ #endregion\r
}\r
}\r
\r
if (scrollY > 0)\r
scrollY = 0;\r
- else if (scrollY < -child.Slot.Height + clientBounds.Height)\r
- scrollY = -child.Slot.Height + clientBounds.Height;\r
+ else if (scrollY < -child.Slot.Height + ClientRectangle.Height)\r
+ scrollY = -child.Slot.Height + ClientRectangle.Height;\r
\r
}\r
if (HorizontalScrolling )\r
\r
if (scrollX > 0)\r
scrollX = 0;\r
- else if (scrollX < -child.Slot.Width + clientBounds.Width)\r
- scrollX = -child.Slot.Width + clientBounds.Width;\r
+ else if (scrollX < -child.Slot.Width + ClientRectangle.Width)\r
+ scrollX = -child.Slot.Width + ClientRectangle.Width;\r
}\r
\r
\r
using System.Text;\r
using Cairo;\r
using System.Xml.Serialization;\r
+using System.ComponentModel;\r
\r
namespace go\r
{\r
public class Slider : NumericControl\r
{\r
+ #region CTOR\r
+ public Slider() : base()\r
+ {}\r
+ public Slider(double minimum, double maximum, double step)\r
+ : base(minimum,maximum,step)\r
+ {\r
+ }\r
+ #endregion\r
+\r
+ #region private fields\r
Rectangle cursor;\r
int _cursorWidth;\r
Color _cursorColor;\r
- //Point mouseDownPos;\r
- bool holdCursor = false;//may use maybe active go equality\r
+ bool holdCursor = false;\r
+ #endregion\r
\r
protected double unity;\r
\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue("Gray")]\r
- public override Color Background {\r
- get { return base.Background; }\r
- set { base.Background = value; }\r
- }\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(2)]\r
- public override int BorderWidth {\r
- get { return base.BorderWidth; }\r
- set { base.BorderWidth = value; }\r
- }\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue("BlueGray")]\r
+ #region Public properties\r
+ [XmlAttributeAttribute()][DefaultValue("BlueGray")]\r
public virtual Color CursorColor {\r
get { return _cursorColor; }\r
set {\r
registerForGraphicUpdate ();\r
}\r
}\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(20)]\r
+ [XmlAttributeAttribute()][DefaultValue(20)]\r
public virtual int CursorWidth {\r
get { return _cursorWidth; }\r
set {\r
registerForGraphicUpdate ();\r
}\r
}\r
+ #endregion\r
\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(true)]\r
+ #region GraphicObject Overrides\r
+ [XmlAttributeAttribute()][DefaultValue("Gray")]\r
+ public override Color Background {\r
+ get { return base.Background; }\r
+ set { base.Background = value; }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue(true)]\r
public override bool Focusable\r
{\r
get { return base.Focusable; }\r
set { base.Focusable = value; }\r
}\r
+ protected override void UpdateGraphic ()\r
+ {\r
+ computeCursorPosition();\r
+ base.UpdateGraphic ();\r
+ }\r
\r
+ protected override void onDraw (Context gr)\r
+ {\r
+ base.onDraw (gr);\r
\r
- \r
- public Slider() : base()\r
- {}\r
- public Slider(double minimum, double maximum, double step)\r
- : base(minimum,maximum,step)\r
- {\r
- }\r
+ Rectangle r = ClientRectangle;\r
+ PointD pStart = r.TopLeft + new Point(cursor.Width/2, r.Height / 2);\r
+ PointD pEnd = r.TopRight + new Point(-cursor.Width/2, r.Height / 2);\r
+\r
+ DrawGraduations (gr, pStart,pEnd);\r
+\r
+ DrawCursor (gr, cursor);\r
+ }\r
+ #endregion\r
+\r
+ protected virtual void DrawGraduations(Context gr, PointD pStart, PointD pEnd)\r
+ {\r
+ gr.Color = Foreground;\r
+\r
+ gr.LineWidth = 1;\r
+ gr.MoveTo(pStart);\r
+ gr.LineTo(pEnd);\r
+\r
+ gr.Stroke();\r
+\r
+ }\r
+ protected virtual void DrawCursor(Context gr, Rectangle _cursor)\r
+ {\r
+ gr.Color = CursorColor;\r
+ CairoHelpers.CairoRectangle (gr, _cursor, CornerRadius);\r
+ gr.FillPreserve();\r
+ }\r
\r
void computeCursorPosition()\r
{ \r
- Rectangle r = clientBounds;\r
+ Rectangle r = ClientRectangle;\r
\r
cursor = new Rectangle(new Size(_cursorWidth,(int) (r.Height)));\r
\r
\r
}\r
#endregion\r
-\r
- internal override void UpdateGraphic ()\r
- {\r
- computeCursorPosition();\r
- base.UpdateGraphic ();\r
- }\r
-\r
- public override void onDraw (Context gr)\r
- {\r
- base.onDraw (gr);\r
-\r
- Rectangle r = clientBounds;\r
- PointD pStart = r.TopLeft + new Point(cursor.Width/2, r.Height / 2);\r
- PointD pEnd = r.TopRight + new Point(-cursor.Width/2, r.Height / 2);\r
-\r
- DrawGraduations (gr, pStart,pEnd);\r
-\r
- DrawCursor (gr, cursor);\r
- }\r
-\r
- public virtual void DrawGraduations(Context gr, PointD pStart, PointD pEnd)\r
- {\r
- gr.Color = Foreground;\r
-\r
- gr.LineWidth = 1;\r
- gr.MoveTo(pStart);\r
- gr.LineTo(pEnd);\r
-\r
- gr.Stroke();\r
-\r
- }\r
- public virtual void DrawCursor(Context gr, Rectangle _cursor)\r
- {\r
- gr.Color = CursorColor;\r
- CairoHelpers.CairoRectangle (gr, _cursor, CornerRadius);\r
- gr.FillPreserve();\r
- gr.Color = BorderColor;\r
- gr.Stroke ();\r
- }\r
}\r
}\r
using System.Diagnostics;\r
using System.Xml.Serialization;\r
using System.Globalization;\r
+using System.ComponentModel;\r
\r
namespace go\r
{\r
public class TextBoxWidget : Label\r
{\r
- public static KeyboardDevice Keyboard;\r
- public static char decimalSeparator = '.';//????? should follow locale policy\r
+ #region CTOR\r
+ public TextBoxWidget(string _initialValue, GOEvent _onTextChanged = null)\r
+ : base(_initialValue)\r
+ {\r
+\r
+ }\r
+\r
+ public TextBoxWidget()\r
+ { }\r
+ #endregion\r
+\r
static bool _capitalOn = false; //????????????????\r
- public static bool capitalOn\r
+ [XmlIgnore]public static bool capitalOn\r
{\r
get\r
{\r
set { _capitalOn = value; }\r
}\r
\r
- Color selColor = Color.BlueBell;\r
- Color selFontColor = Color.WhiteSmoke;\r
+ #region private fields\r
+ Color selColor;\r
+ Color selFontColor;\r
Point mouseLocalPos; //mouse coord in widget space, filled only when clicked \r
int _currentPos; //0 based cursor position in string\r
double textCursorPos; //cursor position in cairo units in widget client coord.\r
double SelStartCursorPos = -1;\r
double SelEndCursorPos = -1;\r
bool SelectionInProgress = false;\r
+ #endregion\r
+\r
+ [XmlAttributeAttribute()][DefaultValue("SkyBlue")]\r
+ public virtual Color SelectionBackground {\r
+ get { return selColor; }\r
+ set {\r
+ selColor = value;\r
+ registerForGraphicUpdate ();\r
+ }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue("Black")]\r
+ public virtual Color SelectionForeground {\r
+ get { return selFontColor; }\r
+ set {\r
+ selFontColor = value;\r
+ registerForGraphicUpdate ();\r
+ }\r
+ }\r
\r
- [XmlIgnore]\r
- public override bool HasFocus //trigger update when lost focus to errase text beam\r
+ #region GraphicObject overrides\r
+ [XmlIgnore]public override bool HasFocus //trigger update when lost focus to errase text beam\r
{\r
get\r
{\r
registerForGraphicUpdate();\r
}\r
}\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- [System.ComponentModel.DefaultValue(true)]\r
+ [XmlAttributeAttribute()][DefaultValue(true)]\r
public override bool Focusable\r
{\r
get { return base.Focusable; }\r
set { base.Focusable = value; }\r
}\r
+ [XmlAttributeAttribute()][DefaultValue("White")]\r
+ public virtual Color Background {\r
+ get { return base.Background; }\r
+ set { base.Background = value; }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue("Black")]\r
+ public virtual Color Foreground {\r
+ get { return base.Foreground; }\r
+ set { base.Foreground = value; }\r
+ }\r
\r
- [XmlIgnore]\r
- public GOEvent onTextChanged;\r
-\r
- [XmlIgnore]\r
- public int currentPos\r
- {\r
- get { return _currentPos; }\r
- set { _currentPos = value; }\r
- }\r
-\r
- [XmlIgnore]\r
- public int selBeginPos;\r
- [XmlIgnore]\r
- public int selReleasePos;\r
- [XmlIgnore]\r
- public int selectionStart //ordered selection start and end positions\r
- {\r
- get { return selReleasePos < 0 ? selBeginPos : Math.Min(selBeginPos, selReleasePos); }\r
- }\r
- [XmlIgnore]\r
- public int selectionEnd\r
- { get { return selReleasePos < 0 ? selReleasePos : Math.Max(selBeginPos, selReleasePos); } }\r
- [XmlIgnore]\r
- public string selectedText\r
- { get { return selectionEnd < 0 ? null : Text.Substring(selectionStart, selectionEnd - selectionStart); } }\r
- [XmlIgnore]\r
- public bool selectionIsEmpty\r
- { get { return string.IsNullOrEmpty(selectedText); } }\r
-\r
- public TextBoxWidget(string _initialValue, GOEvent _onTextChanged = null)\r
- : base(_initialValue)\r
- {\r
- onTextChanged = _onTextChanged;\r
- Focusable = true;\r
- selColor = Color.SkyBlue;\r
- selFontColor = Color.Black;\r
- Foreground = Color.Black;\r
- Background = Color.White;\r
- TextAlignment = Alignment.LeftCenter;\r
- }\r
-\r
- public TextBoxWidget()\r
- { }\r
-\r
- public override void onDraw (Context gr)\r
+ protected override void onDraw (Context gr)\r
{\r
base.onDraw (gr);\r
-// gr.FontOptions.Antialias = Antialias.Subpixel;\r
-// gr.FontOptions.HintMetrics = HintMetrics.On;\r
- gr.SetFontSize(FontSize);\r
+ // gr.FontOptions.Antialias = Antialias.Subpixel;\r
+ // gr.FontOptions.HintMetrics = HintMetrics.On;\r
+ gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);\r
+ gr.SetFontSize (Font.Size);\r
+\r
FontExtents fe = gr.FontExtents;\r
\r
#region draw text cursor\r
if (HasFocus)\r
{\r
//TODO:\r
- gr.Color = Color.White;\r
+ gr.Color = Foreground;\r
gr.LineWidth = 2;\r
gr.MoveTo(new PointD(textCursorPos + rText.X, rText.Y ));\r
gr.LineTo(new PointD(textCursorPos + rText.X, rText.Y + fe.Height));\r
gr.Fill();\r
\r
}\r
+ #endregion\r
+\r
+ public event EventHandler<TextChangeEventArgs> TextChanged = delegate { };\r
+\r
+ public virtual void onTextChanged(Object sender, TextChangeEventArgs e)\r
+ {\r
+ TextChanged (this, e);\r
+ }\r
+\r
+\r
+ [XmlIgnore]public int currentPos{\r
+ get { return _currentPos; }\r
+ set { _currentPos = value; }\r
+ }\r
+ [XmlIgnore]public int selBeginPos;\r
+ [XmlIgnore]public int selReleasePos;\r
+ [XmlIgnore]public int selectionStart //ordered selection start and end positions\r
+ {\r
+ get { return selReleasePos < 0 ? selBeginPos : Math.Min(selBeginPos, selReleasePos); }\r
+ }\r
+ [XmlIgnore]public int selectionEnd\r
+ { get { return selReleasePos < 0 ? selReleasePos : Math.Max(selBeginPos, selReleasePos); } }\r
+ [XmlIgnore]public string selectedText\r
+ { get { return selectionEnd < 0 ? null : Text.Substring(selectionStart, selectionEnd - selectionStart); } }\r
+ [XmlIgnore]public bool selectionIsEmpty\r
+ { get { return string.IsNullOrEmpty(selectedText); } }\r
+\r
+\r
\r
#region Keyboard handling\r
public override void onKeyDown (object sender, KeyboardKeyEventArgs e)\r
break;\r
case Key.Enter:\r
case Key.KeypadEnter:\r
- if (onTextChanged != null)\r
- onTextChanged(this);\r
+ onTextChanged(this,new TextChangeEventArgs(Text));\r
break;\r
case Key.Escape:\r
Text = "";\r
public override void onMouseButtonDown (object sender, MouseButtonEventArgs e)\r
{\r
if (this.HasFocus){\r
- mouseLocalPos = Mouse.Position - ScreenCoordinates(rText).TopLeft - rText.TopLeft;\r
+ mouseLocalPos = e.Position - ScreenCoordinates(rText).TopLeft - rText.TopLeft;\r
selBeginPos = -1;\r
selReleasePos = -1;\r
}else{\r
+++ /dev/null
-using System;\r
-using System.Collections.Generic;\r
-using System.Linq;\r
-using System.Text;\r
-\r
-namespace go\r
-{\r
- public enum MouseButtonStates\r
- {\r
- Released,\r
- Pressed\r
- }\r
-\r
- public static class Mouse\r
- {\r
- static Point _position;\r
- static Point _lastPosition;\r
- static Point _delta;\r
- static int _wheelDelta;\r
-\r
- public static Point Position\r
- {\r
- get { return _position; }\r
- set\r
- {\r
- _lastPosition = _position;\r
- _position = value;\r
- _delta = new Point(_lastPosition.X - _position.X, _lastPosition.Y - _position.Y);\r
- }\r
- }\r
- public static Point LastPosition\r
- {\r
- get { return _lastPosition; }\r
- }\r
- public static Point Delta\r
- {\r
- get { return _delta; }\r
- }\r
- public static int WheelDelta {\r
- get { return _wheelDelta; }\r
- set { _wheelDelta = value; }\r
- }\r
-\r
- public static int X\r
- {\r
- get { return _position.X; } \r
- }\r
- public static int Y\r
- {\r
- get { return _position.Y; }\r
- }\r
-\r
- public static MouseButtonStates LeftButton = MouseButtonStates.Released;\r
- public static MouseButtonStates RightButton = MouseButtonStates.Released;\r
- public static MouseButtonStates MiddleButton = MouseButtonStates.Released;\r
-\r
- }\r
-}\r
// DisplayDevice.Default,\r
// 3,0,OpenTK.Graphics.GraphicsContextFlags.Default)\r
public OpenTKGameWindow(int _width, int _height, string _title="golib")\r
- : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 1), _title)\r
+ : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), _title)\r
{\r
VSync = VSyncMode.On;\r
} \r
int stride = 4 * ClientRectangle.Width;\r
int bmpSize = Math.Abs (stride) * ClientRectangle.Height;\r
bmp = new byte[bmpSize];\r
+ //bmp = Enumerable.Repeat((byte)0, bmpSize).ToArray();\r
\r
if (dispList > 0)\r
GL.DeleteLists (dispList, 1);\r
\r
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, \r
ClientRectangle.Width, ClientRectangle.Height, 0,\r
- OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero);\r
+ OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp);\r
\r
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);\r
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);\r
}\r
}\r
\r
- Debug.WriteLine ("otd:" + gobjsToRedraw.Count.ToString () + "-");\r
+ //Debug.WriteLine ("otd:" + gobjsToRedraw.Count.ToString () + "-");\r
//redraw clip should be added when layout is complete among parents,\r
//that's why it take place in a second pass\r
foreach (GraphicObject p in gobjsToRedraw) {\r
#region Mouse Handling\r
void Mouse_Move(object sender, MouseMoveEventArgs e)\r
{\r
-\r
- go.Mouse.Position = e.Position;\r
-\r
if (_activeWidget != null) {\r
//send move evt even if mouse move outside bounds\r
_activeWidget.onMouseMove (this, e);\r
using System;\r
using System.Collections.Generic;\r
using System.Text;\r
+using System.Xml.Serialization;\r
\r
namespace go\r
{ \r
#endregion\r
\r
#region PROPERTIES\r
- [System.Xml.Serialization.XmlIgnore()]\r
- public int X\r
- {\r
+ [XmlIgnore]public int X{\r
get { return _x; }\r
set { _x = value; }\r
}\r
- [System.Xml.Serialization.XmlIgnore()]\r
- public int Y\r
- {\r
+ [XmlIgnore]public int Y{\r
get { return _y; }\r
set { _y = value; }\r
}\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- public int Left\r
- {\r
+ [XmlIgnore]public int Left{\r
get { return _x; }\r
set { _x = value; }\r
}\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- public int Top\r
- {\r
+ [XmlIgnore]public int Top{\r
get { return _y; }\r
set { _y = value; }\r
}\r
-\r
- [System.Xml.Serialization.XmlIgnore()]\r
- public int Right\r
- {\r
+ [XmlIgnore]public int Right{\r
get { return _x + _width; }\r
}\r
- [System.Xml.Serialization.XmlIgnore()]\r
- public int Bottom\r
- {\r
+ [XmlIgnore]public int Bottom{\r
get { return _y + _height; }\r
}\r
-\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- public int Width\r
- {\r
+ [XmlIgnore]public int Width{\r
get { return _width; }\r
set { _width = value; }\r
}\r
- [System.Xml.Serialization.XmlAttributeAttribute()]\r
- public int Height\r
- {\r
+ [XmlIgnore]public int Height{\r
get { return _height; }\r
set { _height = value; }\r
}\r
- [System.Xml.Serialization.XmlIgnore()]\r
- public Size Size\r
- {\r
+ [XmlIgnore]public Size Size{\r
get { return new Size(Width, Height); }\r
set\r
{\r
Height = value.Height;\r
}\r
}\r
- [System.Xml.Serialization.XmlIgnore()]\r
- public Point Position\r
- {\r
+ [XmlIgnore]public Point Position{\r
get { return new Point(X, Y); }\r
set\r
{\r
Y = value.Y;\r
}\r
}\r
- [System.Xml.Serialization.XmlIgnore()]\r
- public Point TopLeft\r
- {\r
+ [XmlIgnore]public Point TopLeft{\r
set\r
{\r
X = value.X;\r
}\r
get { return new Point(X, Y); }\r
}\r
- [System.Xml.Serialization.XmlIgnore()]\r
- public Point TopRight\r
- {\r
+ [XmlIgnore]public Point TopRight{\r
get { return new Point(Right, Y); }\r
}\r
- [System.Xml.Serialization.XmlIgnore()]\r
- public Point BottomLeft\r
- {\r
+ [XmlIgnore]public Point BottomLeft{\r
get { return new Point(X, Bottom); }\r
}\r
- [System.Xml.Serialization.XmlIgnore()]\r
- public Point BottomRight\r
- {\r
+ [XmlIgnore]public Point BottomRight{\r
get { return new Point(Right, Bottom); }\r
}\r
- [System.Xml.Serialization.XmlIgnore()]\r
- public Point Center\r
+ [XmlIgnore]public Point Center\r
{\r
get { return new Point(Left + Width / 2, Top + Height / 2); }\r
}\r
return false;\r
else\r
return true;\r
- }\r
+ }\r
+ public static Size operator +(Size s1, Size s2)\r
+ {\r
+ return new Size(s1.Width + s2.Width, s1.Height + s2.Height);\r
+ }\r
public static Size operator +(Size s, int i)\r
{\r
return new Size(s.Width + i, s.Height + i);\r
--- /dev/null
+using System;
+
+namespace go
+{
+ public class ValueChangeEventArgs: EventArgs
+ {
+ public Decimal OldValue;
+ public Decimal NewValue;
+
+ public ValueChangeEventArgs (Decimal _oldValue, Decimal _newValue) : base()
+ {
+ OldValue = _oldValue;
+ NewValue = _newValue;
+ }
+ }
+}
+
namespace go
{
- public class ValueChangeEventArgs: EventArgs
+ public class TextChangeEventArgs: EventArgs
{
- public Decimal OldValue;
- public Decimal NewValue;
+ public String Text;
- public ValueChangeEventArgs (Decimal _oldValue, Decimal _newValue) : base()
+ public TextChangeEventArgs (string _newValue) : base()
{
- OldValue = _oldValue;
- NewValue = _newValue;
+ Text = _newValue;
}
}
}
+++ /dev/null
-using System;\r
-\r
-namespace go\r
-{\r
- public static class directories\r
- {\r
-#if _WIN32 || _WIN64\r
- public const string rootDir = @"d:/";\r
-#elif __linux__\r
- public const string rootDir = @"/mnt/data/";\r
-#endif\r
- \r
- }\r
-}\r
-\r