From: jpbruyere Date: Sat, 30 Jan 2016 08:42:37 +0000 (+0100) Subject: NUnit try, renaming, debugging and uniformizating X-Git-Tag: 0.3~87 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=9fa17cdc9487e3ba92ef467c0c6d5d9941530de1;p=jp%2Fcrow.git NUnit try, renaming, debugging and uniformizating --- diff --git a/Crow.csproj b/Crow.csproj index 10a3514c..b65f3170 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -110,13 +110,11 @@ - - @@ -124,11 +122,13 @@ - - + + + + @@ -172,10 +172,8 @@ - - @@ -187,7 +185,6 @@ - @@ -195,9 +192,6 @@ - - - @@ -213,6 +207,12 @@ + + + + + + diff --git a/Crow.sln b/Crow.sln index c396e5dc..17b8e4a7 100644 --- a/Crow.sln +++ b/Crow.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoDevelop.GOLib", "MonoDe EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoDevelop.Diagram", "..\MonoDevelop.Diagram\MonoDevelop.Diagram.csproj", "{232716B4-D19D-4FD7-B310-94A98FD926F0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTest", "UnitTest\UnitTest.csproj", "{7BAE4448-E8F4-48B3-BB11-FA78E7F4506B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Linux_x86 = Debug|Linux_x86 @@ -21,6 +23,10 @@ Global {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Debug|Linux_x86.Build.0 = Debug|Any CPU {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Release|Linux_x86.ActiveCfg = Release|Any CPU {74289092-9F70-4941-AFCB-DFD7BE2140B6}.Release|Linux_x86.Build.0 = Release|Any CPU + {7BAE4448-E8F4-48B3-BB11-FA78E7F4506B}.Debug|Linux_x86.ActiveCfg = Debug|Any CPU + {7BAE4448-E8F4-48B3-BB11-FA78E7F4506B}.Debug|Linux_x86.Build.0 = Debug|Any CPU + {7BAE4448-E8F4-48B3-BB11-FA78E7F4506B}.Release|Linux_x86.ActiveCfg = Release|Any CPU + {7BAE4448-E8F4-48B3-BB11-FA78E7F4506B}.Release|Linux_x86.Build.0 = Release|Any CPU {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Debug|Linux_x86.ActiveCfg = Debug|Any CPU {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Debug|Linux_x86.Build.0 = Debug|Any CPU {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Release|Linux_x86.ActiveCfg = Release|Any CPU diff --git a/Crow.userprefs b/Crow.userprefs index 21fdf1d4..b554ec85 100644 --- a/Crow.userprefs +++ b/Crow.userprefs @@ -1,23 +1,15 @@  - + - - - - - - - - - - - - - - - - + + + + + + + + diff --git a/Images/Icons/updown.svg b/Images/Icons/updown.svg index a4d5fcb4..ce045245 100644 --- a/Images/Icons/updown.svg +++ b/Images/Icons/updown.svg @@ -14,7 +14,7 @@ version="1.1" inkscape:version="0.91 r13725" sodipodi:docname="updown.svg"> - - - - - - - - - + inkscape:current-layer="svg2" />--> + + + + \ No newline at end of file diff --git a/Templates/Checkbox.goml b/Templates/Checkbox.goml deleted file mode 100755 index 80ec112d..00000000 --- a/Templates/Checkbox.goml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - \ No newline at end of file diff --git a/Templates/ComboBox.goml b/Templates/ComboBox.goml new file mode 100755 index 00000000..f60b1a1a --- /dev/null +++ b/Templates/ComboBox.goml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/Templates/ComboBoxOverlay.goml b/Templates/ComboBoxOverlay.goml new file mode 100755 index 00000000..cab49531 --- /dev/null +++ b/Templates/ComboBoxOverlay.goml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/Templates/Combobox.goml b/Templates/Combobox.goml deleted file mode 100755 index 9abd6361..00000000 --- a/Templates/Combobox.goml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - \ No newline at end of file diff --git a/Templates/ComboboxOverlay.goml b/Templates/ComboboxOverlay.goml deleted file mode 100755 index cab49531..00000000 --- a/Templates/ComboboxOverlay.goml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Templates/Expandable.goml b/Templates/Expandable.goml index 4e9a8540..740200ca 100755 --- a/Templates/Expandable.goml +++ b/Templates/Expandable.goml @@ -4,7 +4,7 @@ - diff --git a/Templates/GroupBox.goml b/Templates/GroupBox.goml new file mode 100755 index 00000000..4f6035aa --- /dev/null +++ b/Templates/GroupBox.goml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/Templates/Groupbox.goml b/Templates/Groupbox.goml deleted file mode 100755 index 789cd60f..00000000 --- a/Templates/Groupbox.goml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Templates/ListBox.goml b/Templates/ListBox.goml new file mode 100755 index 00000000..28241e27 --- /dev/null +++ b/Templates/ListBox.goml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/Templates/Listbox.goml b/Templates/Listbox.goml deleted file mode 100755 index 28241e27..00000000 --- a/Templates/Listbox.goml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/Templates/MessageBox.goml b/Templates/MessageBox.goml index e2eccd71..d6e474c0 100644 --- a/Templates/MessageBox.goml +++ b/Templates/MessageBox.goml @@ -9,19 +9,19 @@ diff --git a/UnitTest/ExpectedOutputs/0.png b/UnitTest/ExpectedOutputs/0.png new file mode 100644 index 00000000..acf96fa6 Binary files /dev/null and b/UnitTest/ExpectedOutputs/0.png differ diff --git a/UnitTest/ExpectedOutputs/1.png b/UnitTest/ExpectedOutputs/1.png new file mode 100644 index 00000000..f792986c Binary files /dev/null and b/UnitTest/ExpectedOutputs/1.png differ diff --git a/UnitTest/Interfaces/0.crow b/UnitTest/Interfaces/0.crow new file mode 100755 index 00000000..64d6db6d --- /dev/null +++ b/UnitTest/Interfaces/0.crow @@ -0,0 +1,2 @@ + + diff --git a/UnitTest/Interfaces/1.crow b/UnitTest/Interfaces/1.crow new file mode 100755 index 00000000..142d0721 --- /dev/null +++ b/UnitTest/Interfaces/1.crow @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/UnitTest/Interfaces/2.crow b/UnitTest/Interfaces/2.crow new file mode 100755 index 00000000..dcccba04 --- /dev/null +++ b/UnitTest/Interfaces/2.crow @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/UnitTest/NUnitCrowWindow.cs b/UnitTest/NUnitCrowWindow.cs new file mode 100644 index 00000000..0c73b8e7 --- /dev/null +++ b/UnitTest/NUnitCrowWindow.cs @@ -0,0 +1,456 @@ +#define MONO_CAIRO_DEBUG_DISPOSE + + +using System; +using System.Runtime.InteropServices; +using OpenTK; +using OpenTK.Graphics.OpenGL; +using OpenTK.Input; + +using System.Diagnostics; + +//using GGL; +using System.Threading; +using System.Collections.Generic; +using System.Linq; +using Cairo; + + +namespace Crow +{ + class NUnitCrowWindow : IValueChange, ILayoutable, IGOLibHost + { + #region IValueChange implementation + public event EventHandler ValueChanged; + public virtual void NotifyValueChanged(string MemberName, object _value) + { + ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value)); + } + #endregion + + public Rectangle ClientRectangle = new Rectangle(0,0,800,600); + public List GraphicObjects = new List(); + public Color Background = Color.Transparent; + + Rectangles _redrawClip = new Rectangles();//should find another way to access it from child + List _gobjsToRedraw = new List(); + + #region IGOLibHost implementation + public Rectangles redrawClip { + get { + return _redrawClip; + } + set { + _redrawClip = value; + } + } + + public List gobjsToRedraw { + get { + return _gobjsToRedraw; + } + set { + _gobjsToRedraw = value; + } + } + public void AddWidget(GraphicObject g) + { + g.Parent = this; + GraphicObjects.Insert (0, g); + + g.RegisterForLayouting ((int)LayoutingType.Sizing); + } + public void DeleteWidget(GraphicObject g) + { + g.Visible = false;//trick to ensure clip is added to refresh zone + g.ClearBinding(); + GraphicObjects.Remove (g); + } + public void PutOnTop(GraphicObject g) + { + if (GraphicObjects.IndexOf(g) > 0) + { + GraphicObjects.Remove(g); + GraphicObjects.Insert(0, g); + g.registerClipRect (); + } + } + public void Quit () + { + } + + #region focus + GraphicObject _activeWidget; //button is pressed on widget + GraphicObject _hoverWidget; //mouse is over + GraphicObject _focusedWidget; //has keyboard (or other perif) focus + + public GraphicObject activeWidget + { + get { return _activeWidget; } + set + { + if (_activeWidget == value) + return; + _activeWidget = value; + } + } + public GraphicObject hoverWidget + { + get { return _hoverWidget; } + set { _hoverWidget = value; } + } + public GraphicObject FocusedWidget { + get { return _focusedWidget; } + set { + if (_focusedWidget == value) + return; + if (_focusedWidget != null) + _focusedWidget.onUnfocused (this, null); + _focusedWidget = value; + if (_focusedWidget != null) + _focusedWidget.onFocused (this, null); + } + } + #endregion + + #endregion + + #region Events + //those events are raised only if mouse isn't in a graphic object + public event EventHandler MouseWheelChanged; + public event EventHandler MouseButtonUp; + public event EventHandler MouseButtonDown; + public event EventHandler MouseClick; + public event EventHandler MouseMove; + #endregion + + #region graphic contexte + Context ctx; + public Surface surf; + string testId; + #endregion + + #region update + public Stopwatch updateTime = new Stopwatch (); + public Stopwatch layoutTime = new Stopwatch (); + public Stopwatch guTime = new Stopwatch (); + public Stopwatch drawingTime = new Stopwatch (); + + public void Update () + { + guTime.Reset (); + updateTime.Restart (); + layoutTime.Restart (); + + ctx = new Context(surf); + + GraphicObject[] invGOList = new GraphicObject[GraphicObjects.Count]; + GraphicObjects.CopyTo (invGOList,0); + invGOList = invGOList.Reverse ().ToArray (); + + //Debug.WriteLine ("======= Layouting queue start ======="); + lock (Interface.LayoutingQueue) { + while (Interface.LayoutingQueue.Count > 0) { + // Stopwatch lqiProcTime = new Stopwatch (); + // lqiProcTime.Start (); + LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue (); + lqi.ProcessLayouting (); + // lqiProcTime.Stop (); + // if (lqiProcTime.ElapsedMilliseconds > 10) { + // Debug.WriteLine("lqi {2}: {0} ticks \t, {1} ms", + // updateTime.ElapsedTicks, + // updateTime.ElapsedMilliseconds, lqi.ToString()); + // } + } + } + + //final redraw clips should be added only when layout is completed among parents, + //that's why it take place in a second pass + GraphicObject[] gotr = new GraphicObject[gobjsToRedraw.Count]; + gobjsToRedraw.CopyTo (gotr); + gobjsToRedraw.Clear (); + foreach (GraphicObject p in gotr) { + p.registerClipRect (); + } + + layoutTime.Stop (); + guTime.Start (); + + lock (redrawClip) { + if (redrawClip.count > 0) { + // #if DEBUG_CLIP_RECTANGLE + // redrawClip.stroke (ctx, new Color(1.0,0,0,0.3)); + // #endif + redrawClip.clearAndClip (ctx);//rajouté après, tester si utile + + //Link.draw (ctx); + foreach (GraphicObject p in invGOList) { + if (p.Visible) { + drawingTime.Start (); + + ctx.Save (); + if (redrawClip.count > 0) { + Rectangles clip = redrawClip.intersectingRects (p.Slot); + + if (clip.count > 0) + p.Paint (ref ctx, clip); + } + ctx.Restore (); + + drawingTime.Stop (); + } + } + ctx.ResetClip (); + // #if DEBUG_CLIP_RECTANGLE + // redrawClip.stroke (ctx, Color.Red.AdjustAlpha(0.1)); + // #endif + redrawClip.Reset (); + } + } + guTime.Stop (); + updateTime.Stop (); + ctx.Dispose (); + Console.WriteLine("{3} => layout:{0,8} t\tdraw:{1,8} t\tupdate:{2,8} t", + layoutTime.ElapsedTicks, + guTime.ElapsedTicks, + updateTime.ElapsedTicks, + testId); +// Console.WriteLine("{3} => layout:{0}ms\tdraw{1}ms\tupdate:{2}ms", +// layoutTime.ElapsedMilliseconds, +// guTime.ElapsedMilliseconds, +// updateTime.ElapsedMilliseconds, +// testId); + surf.WriteToPng (@"ExpectedOutputs/" + testId + ".png"); + surf.WriteToPng (@"tmp.png"); + } + #endregion + + #region loading + public GraphicObject LoadTest (string id) + { + testId = id; + GraphicObject tmp = Interface.Load ("Interfaces/" + testId + ".crow", this); + AddWidget (tmp); + return tmp; + } + /// Remove all Graphic objects from top container + public void ClearInterface() + { + int i = 0; + while (GraphicObjects.Count>0) { + GraphicObject g = GraphicObjects [i]; + g.Visible = false; + g.ClearBinding (); + GraphicObjects.RemoveAt (0); + } + } + #endregion + + public NUnitCrowWindow (int width, int height) + { + ClientRectangle.Width = width; + ClientRectangle.Height = height; + + surf = new ImageSurface(Format.Argb32, ClientRectangle.Width, ClientRectangle.Height); + } + + int frameCpt = 0; + int idx = 0; + + + #region FPS + int _fps = 0; + + public int fps { + get { return _fps; } + set { + if (_fps == value) + return; + + _fps = value; + + if (_fps > fpsMax) { + fpsMax = _fps; + ValueChanged.Raise(this, new ValueChangeEventArgs ("fpsMax", fpsMax)); + } else if (_fps < fpsMin) { + fpsMin = _fps; + ValueChanged.Raise(this, new ValueChangeEventArgs ("fpsMin", fpsMin)); + } + + ValueChanged.Raise(this, new ValueChangeEventArgs ("fps", _fps)); + ValueChanged.Raise (this, new ValueChangeEventArgs ("update", + this.updateTime.ElapsedMilliseconds.ToString () + " ms")); + } + } + + public int fpsMin = int.MaxValue; + public int fpsMax = 0; + + void resetFps () + { + fpsMin = int.MaxValue; + fpsMax = 0; + _fps = 0; + } + //public string update = ""; + #endregion + + + #region Mouse Handling + void Mouse_Move(object sender, MouseMoveEventArgs e) + { + if (_activeWidget != null) { + //first, ensure object is still in the graphic tree + if (_activeWidget.TopContainer == null) { + activeWidget = null; + } else { + + //send move evt even if mouse move outside bounds + _activeWidget.onMouseMove (_activeWidget, e); + return; + } + } + + if (_hoverWidget != null) { + //first, ensure object is still in the graphic tree + if (_hoverWidget.TopContainer == null) { + hoverWidget = null; + } else { + //check topmost graphicobject first + GraphicObject tmp = _hoverWidget; + GraphicObject topc = null; + while (tmp is GraphicObject) { + topc = tmp; + tmp = tmp.Parent as GraphicObject; + } + int idxhw = GraphicObjects.IndexOf (topc); + if (idxhw != 0) { + int i = 0; + while (i < idxhw) { + if (GraphicObjects [i].MouseIsIn (e.Position)) { + _hoverWidget.onMouseLeave (this, e); + GraphicObjects [i].checkHoverWidget (e); + return; + } + i++; + } + } + + + if (_hoverWidget.MouseIsIn (e.Position)) { + _hoverWidget.checkHoverWidget (e); + return; + } else { + _hoverWidget.onMouseLeave (this, e); + //seek upward from last focused graph obj's + while (_hoverWidget.Parent as GraphicObject != null) { + _hoverWidget = _hoverWidget.Parent as GraphicObject; + if (_hoverWidget.MouseIsIn (e.Position)) { + _hoverWidget.checkHoverWidget (e); + return; + } else + _hoverWidget.onMouseLeave (this, e); + } + } + } + } + + //top level graphic obj's parsing + for (int i = 0; i < GraphicObjects.Count; i++) { + GraphicObject g = GraphicObjects[i]; + if (g.MouseIsIn (e.Position)) { + g.checkHoverWidget (e); + PutOnTop (g); + return; + } + } + _hoverWidget = null; + MouseMove.Raise (this, e); + } + void Mouse_ButtonUp(object sender, MouseButtonEventArgs e) + { + if (_activeWidget == null) { + MouseButtonUp.Raise (this, e); + return; + } + + _activeWidget.onMouseButtonUp (this, e); + _activeWidget = null; + } + void Mouse_ButtonDown(object sender, MouseButtonEventArgs e) + { + if (_hoverWidget == null) { + MouseButtonDown.Raise (this, e); + return; + } + + GraphicObject g = _hoverWidget; + while (!g.Focusable) { + g = g.Parent as GraphicObject; + if (g == null) { + return; + } + } + + _activeWidget = g; + _activeWidget.onMouseButtonDown (this, e); + } + + void Mouse_WheelChanged(object sender, MouseWheelEventArgs e) + { + if (_hoverWidget == null) { + MouseWheelChanged.Raise (this, e); + return; + } + _hoverWidget.onMouseWheel (this, e); + } + #endregion + + #region keyboard Handling + void Keyboard_KeyDown(object sender, KeyboardKeyEventArgs e) + { + if (_focusedWidget == null) + return; + _focusedWidget.onKeyDown (sender, e); + } + #endregion + + #region ILayoutable implementation + + public void RegisterForLayouting (int layoutType) { throw new NotImplementedException (); } + public void UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); } + public Rectangle ContextCoordinates (Rectangle r) + { + return r; + } + public Rectangle ScreenCoordinates (Rectangle r) + { + return r; + } + + public ILayoutable Parent { + get { + return null; + } + set { + throw new NotImplementedException (); + } + } + Rectangle ILayoutable.ClientRectangle { + get { return new Size(this.ClientRectangle.Size.Width,this.ClientRectangle.Size.Height); } + } + public IGOLibHost TopContainer { + get { return this; } + } + + public Rectangle getSlot () + { + return ClientRectangle; + } + public Rectangle getBounds ()//redundant but fill ILayoutable implementation + { + return ClientRectangle; + } + #endregion + } +} \ No newline at end of file diff --git a/UnitTest/Test.cs b/UnitTest/Test.cs new file mode 100644 index 00000000..11555696 --- /dev/null +++ b/UnitTest/Test.cs @@ -0,0 +1,64 @@ +// +// Test.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2016 jp +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using NUnit.Framework; +using System; +using Crow; +using System.IO; + +namespace UnitTest +{ + [TestFixture ()] + public class Test + { + NUnitCrowWindow win; + + [SetUp] + public void Init() + { + win = new NUnitCrowWindow (400,400); + } + + [Test ()] + [Category("Alignment")] + public void GraphicObject () + { + string[] tests = new string[] { "0","1" }; + + foreach (string s in tests) { + win.LoadTest (s); + win.Update (); + win.Update (); + byte[] model = File.ReadAllBytes("ExpectedOutputs/" + s + ".png"); + byte[] result = File.ReadAllBytes(@"tmp.png"); + + CollectionAssert.AreEqual (model, result); + + win.ClearInterface (); + } + } + + void testAlignment(GraphicObject g){ + g.HorizontalAlignment = HorizontalAlignment.Left; + + } + } +} + diff --git a/UnitTest/UnitTest.csproj b/UnitTest/UnitTest.csproj new file mode 100644 index 00000000..ddd53b61 --- /dev/null +++ b/UnitTest/UnitTest.csproj @@ -0,0 +1,78 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {7BAE4448-E8F4-48B3-BB11-FA78E7F4506B} + Library + UnitTest + UnitTest + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + full + true + bin\Release + prompt + 4 + false + + + + + + ..\..\opentk\Binaries\OpenTK\Release\OpenTK.dll + + + + + + nunit + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + {C2980F9B-4798-4C05-99E2-E174810F7C7B} + Crow + + + + + + + \ No newline at end of file diff --git a/UnitTest/packages.config b/UnitTest/packages.config new file mode 100644 index 00000000..b183023e --- /dev/null +++ b/UnitTest/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/GraphicObjects/Button.cs b/src/GraphicObjects/Button.cs index c598c3e3..5d3e81ca 100644 --- a/src/GraphicObjects/Button.cs +++ b/src/GraphicObjects/Button.cs @@ -26,12 +26,12 @@ namespace Crow #endregion #region GraphicObject Overrides - [XmlAttributeAttribute()][DefaultValue(60)] + [XmlAttributeAttribute()][DefaultValue(50)] public override int Width { get { return base.Width; } set { base.Width = value; } } - [XmlAttributeAttribute()][DefaultValue(30)] + [XmlAttributeAttribute()][DefaultValue(20)] public override int Height { get { return base.Height; } set { base.Height = value; } diff --git a/src/GraphicObjects/CheckBox.cs b/src/GraphicObjects/CheckBox.cs new file mode 100644 index 00000000..a08f9fdb --- /dev/null +++ b/src/GraphicObjects/CheckBox.cs @@ -0,0 +1,94 @@ +using System; + + +using System.Collections.Generic; +using System.Linq; +using System.Text; +//using OpenTK.Graphics.OpenGL; + +using Cairo; + +using winColors = System.Drawing.Color; +using System.Diagnostics; +using System.Xml.Serialization; +using OpenTK.Input; +using System.ComponentModel; + +namespace Crow +{ + [DefaultTemplate("#Crow.Templates.CheckBox.goml")] + public class CheckBox : TemplatedControl + { + string caption; + string image; + bool isChecked; + + #region CTOR + public CheckBox() : base() + { + } + #endregion + + public event EventHandler Checked; + public event EventHandler Unchecked; + + #region GraphicObject overrides +// [XmlAttributeAttribute()][DefaultValue(-1)] +// public override int Height { +// get { return base.Height; } +// set { base.Height = value; } +// } + [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true + public override bool Focusable + { + get { return base.Focusable; } + set { base.Focusable = value; } + } + #endregion + + [XmlAttributeAttribute()][DefaultValue("Checkbox")] + public string Caption { + get { return caption; } + set { + if (caption == value) + return; + caption = value; + NotifyValueChanged ("Caption", caption); + } + } + [XmlAttributeAttribute()][DefaultValue("#Crow.Images.Icons.checkbox.svg")] + public string Image { + get { return image; } + set { + if (image == value) + return; + image = value; + NotifyValueChanged ("Image", image); + } + } + + [XmlAttributeAttribute()][DefaultValue(false)] + public bool IsChecked + { + get { return isChecked; } + set + { + isChecked = value; + + NotifyValueChanged ("IsChecked", value); + if (isChecked) { + NotifyValueChanged ("SvgSub", "checked"); + Checked.Raise (this, null); + } else { + NotifyValueChanged ("SvgSub", "unchecked"); + Unchecked.Raise (this, null); + } + } + } + public override void onMouseClick (object sender, MouseButtonEventArgs e) + { + IsChecked = !IsChecked; + base.onMouseClick (sender, e); + } + } +} diff --git a/src/GraphicObjects/Checkbox.cs b/src/GraphicObjects/Checkbox.cs deleted file mode 100644 index 36181602..00000000 --- a/src/GraphicObjects/Checkbox.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; - - -using System.Collections.Generic; -using System.Linq; -using System.Text; -//using OpenTK.Graphics.OpenGL; - -using Cairo; - -using winColors = System.Drawing.Color; -using System.Diagnostics; -using System.Xml.Serialization; -using OpenTK.Input; -using System.ComponentModel; - -namespace Crow -{ - [DefaultTemplate("#Crow.Templates.Checkbox.goml")] - public class Checkbox : TemplatedControl - { - string caption; - string image; - bool isChecked; - - #region CTOR - public Checkbox() : base() - { - } - #endregion - - public event EventHandler Checked; - public event EventHandler Unchecked; - - #region GraphicObject overrides -// [XmlAttributeAttribute()][DefaultValue(-1)] -// public override int Height { -// get { return base.Height; } -// set { base.Height = value; } -// } - [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true - public override bool Focusable - { - get { return base.Focusable; } - set { base.Focusable = value; } - } - #endregion - - [XmlAttributeAttribute()][DefaultValue("Checkbox")] - public string Caption { - get { return caption; } - set { - if (caption == value) - return; - caption = value; - NotifyValueChanged ("Caption", caption); - } - } - [XmlAttributeAttribute()][DefaultValue("#Crow.Images.Icons.checkbox.svg")] - public string Image { - get { return image; } - set { - if (image == value) - return; - image = value; - NotifyValueChanged ("Image", image); - } - } - - [XmlAttributeAttribute()][DefaultValue(false)] - public bool IsChecked - { - get { return isChecked; } - set - { - isChecked = value; - - NotifyValueChanged ("IsChecked", value); - if (isChecked) { - NotifyValueChanged ("SvgSub", "checked"); - Checked.Raise (this, null); - } else { - NotifyValueChanged ("SvgSub", "unchecked"); - Unchecked.Raise (this, null); - } - } - } - public override void onMouseClick (object sender, MouseButtonEventArgs e) - { - IsChecked = !IsChecked; - base.onMouseClick (sender, e); - } - } -} diff --git a/src/GraphicObjects/ComboBox.cs b/src/GraphicObjects/ComboBox.cs new file mode 100644 index 00000000..5d9c8e97 --- /dev/null +++ b/src/GraphicObjects/ComboBox.cs @@ -0,0 +1,365 @@ +using System; + + +using System.Collections.Generic; +using System.Linq; +using System.Text; +//using OpenTK.Graphics.OpenGL; + +using Cairo; + +using winColors = System.Drawing.Color; +using System.Diagnostics; +using System.Xml.Serialization; +using OpenTK.Input; +using System.ComponentModel; +using System.Xml; +using System.IO; +using System.Collections; +using System.Threading; + +namespace Crow +{ + [DefaultTemplate("#Crow.Templates.ComboBox.goml")] + [DefaultOverlayTemplate("#Crow.Templates.ComboBoxOverlay.goml")] + public class ComboBox : TemplatedContainer + { + #region CTOR + public ComboBox() : base(){ } + #endregion + + bool _isPopped; + string caption; + GraphicObject _overlay; + Group _list; + IList data; + int _selectedIndex; + object _selectedItem; + string _itemTemplate; + string _overlayTemplate; + + public event EventHandler Pop; + public event EventHandler Unpop; + public event EventHandler SelectedItemChanged; + + #region implemented abstract members of TemplatedControl + protected override void loadTemplate (GraphicObject template) + { + base.loadTemplate (template); + loadOverlayTemplate (null); + } + public override GraphicObject Content { + get { + throw new NotImplementedException (); + } + set { + throw new NotImplementedException (); + } + } + #endregion + + protected virtual void loadOverlayTemplate(GraphicObject overlayTemplate) + { + if (overlayTemplate == null) { + DefaultOverlayTemplate dt = (DefaultOverlayTemplate)this.GetType ().GetCustomAttributes (typeof(DefaultOverlayTemplate), true).FirstOrDefault (); + Overlay = Interface.Load (dt.Path); + Overlay.ResolveBindings (); + } else + Overlay = overlayTemplate; + _list = Overlay.FindByName ("List") as Group; + } + + [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")] + public string ItemTemplate { + get { return _itemTemplate; } + set { + //TODO:reload list with new template? + _itemTemplate = value; + } + } + [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ComboBoxOverlay.goml")] + public string OverlayTemplate { + get { return _overlayTemplate; } + set { + //TODO:reload list with new template? + _overlayTemplate = value; + + Overlay = Interface.Load (_overlayTemplate); + Overlay.ResolveBindings (); + _list = Overlay.FindByName ("List") as Group; + } + } + [XmlAttributeAttribute][DefaultValue(-1)] + public int SelectedIndex{ + get { return _selectedIndex; } + set { + //store value event if data is null, because in xml parsing selindex is always + //before data, so it's impossible without that trick to set a default index in goml + _selectedIndex = value; + + if (data == null) + return; + + if (_selectedIndex > data.Count - 1 || _selectedIndex < 0) + throw new Exception ("Combobox SelectedIndex out of range"); + + + _selectedItem = data [_selectedIndex]; + NotifyValueChanged ("SelectedIndex", SelectedIndex); + SelectedItemChanged.Raise (this, new SelectionChangeEventArgs(_selectedItem)); + + if (SelectedItem == null) + Caption = ""; + else + Caption = _selectedItem.ToString (); + } + } + public object SelectedItem{ + set { + if (_selectedItem == value) + return; + + _selectedItem = value; + _selectedIndex = data.IndexOf (_selectedItem); + NotifyValueChanged ("SelectedIndex", _selectedIndex); + SelectedItemChanged.Raise (this, new SelectionChangeEventArgs(_selectedItem)); + + if (SelectedItem == null) + Caption = ""; + else + Caption = _selectedItem.ToString (); + } + + get { return _selectedItem; } + } + [XmlAttributeAttribute][DefaultValue(null)] + public IList Data { + get { + return data; + } + set { + data = value; + if (_list == null) + return; + + foreach (GraphicObject c in _list.Children) { + c.ClearBinding (); + } + _list.Children.Clear (); + _list.registerForGraphicUpdate (); + if (data == null) + return; + if (SelectedIndex < 0) + return; + + //force raise of changes + SelectedIndex = SelectedIndex; + + pendingChildrenAddition = new Queue (); + threadedLoadingFinished = false; + + Thread t = new Thread (loadingThread); + t.Start (); + t.Join (); + + } + } + public override void UpdateLayout (LayoutingType layoutType) + { + CheckPendingChildrenAddition (); + base.UpdateLayout (layoutType); + } + internal void CheckPendingChildrenAddition() + { + if (pendingChildrenAddition == null) + return; + lock (pendingChildrenAddition) { + if (!threadedLoadingFinished && pendingChildrenAddition.Count < 50) + return; + while (pendingChildrenAddition.Count > 0) { + _list.addChild (pendingChildrenAddition.Dequeue ()); + } + } + } + + volatile Queue pendingChildrenAddition; + volatile bool threadedLoadingFinished = false; + + void loadingThread() + { + #if DEBUG_LOAD_TIME + Stopwatch loadingTime = new Stopwatch (); + loadingTime.Start (); + #endif + + MemoryStream ms = new MemoryStream (); + lock (ItemTemplate) { + using (Stream stream = Interface.GetStreamFromPath (ItemTemplate)) + stream.CopyTo (ms); + } + + Type t = Interface.GetTopContainerOfGOMLStream (ms); + + foreach (var item in data) { + ms.Seek(0,SeekOrigin.Begin); + GraphicObject g = Interface.Load (ms, t); + g.DataSource = item; + g.MouseClick += itemClick; + + lock (pendingChildrenAddition) { + pendingChildrenAddition.Enqueue (g); + } + } + + ms.Dispose (); + + threadedLoadingFinished = true; + + #if DEBUG_LOAD_TIME + loadingTime.Stop (); + Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms", + loadingTime.ElapsedTicks, + loadingTime.ElapsedMilliseconds, this.ToString()); + #endif + } + public GraphicObject Overlay { + get { return _overlay; } + set { + if (_overlay != null) { + _overlay.LayoutChanged -= _overlay_LayoutChanged; + _overlay.MouseLeave -= _overlay_MouseLeave; + _overlay.LogicalParent = null; + } + + _overlay = value; + + if (_overlay == null) + return; + + _overlay.LogicalParent = this; + _overlay.Focusable = true; + _overlay.LayoutChanged += _overlay_LayoutChanged; + _overlay.MouseLeave += _overlay_MouseLeave; + } + } + [XmlAttributeAttribute()][DefaultValue("Combobox")] + public string Caption { + get { return caption; } + set { + if (caption == value) + return; + caption = value; + NotifyValueChanged ("Caption", caption); + } + } + [XmlAttributeAttribute()][DefaultValue(false)] + public bool IsPopped + { + get { return _isPopped; } + set + { + _isPopped = value; + + if (_isPopped) { + onPop (this, null); + NotifyValueChanged ("SvgSub", "expanded"); + return; + } + + onUnpop (this, null); + NotifyValueChanged ("SvgSub", "collapsed"); + } + } + + void itemClick(object sender, OpenTK.Input.MouseButtonEventArgs e){ + object datasource = (sender as GraphicObject).DataSource; + SelectedItem = datasource; + IsPopped = false; + //Debug.WriteLine ((sender as GraphicObject).DataSource); + } + void _overlay_MouseLeave (object sender, MouseMoveEventArgs e) + { + IsPopped = false; + } + void _overlay_LayoutChanged (object sender, LayoutChangeEventArgs e) + { + ILayoutable tc = Overlay.Parent as ILayoutable; + if (tc == null) + return; + Rectangle r = this.ScreenCoordinates (this.Slot); + if (e.LayoutType == LayoutingType.Width) { + if (Overlay.Slot.Width < tc.ClientRectangle.Width) { + if (r.Left + Overlay.Slot.Width > tc.ClientRectangle.Right) + Overlay.Left = tc.ClientRectangle.Right - Overlay.Slot.Width; + else + Overlay.Left = r.Left; + }else + Overlay.Left = 0; + }else if (e.LayoutType == LayoutingType.Height) { + if (Overlay.Slot.Height < tc.ClientRectangle.Height) { + if (r.Bottom + Overlay.Slot.Height > tc.ClientRectangle.Bottom) + Overlay.Top = r.Top - Overlay.Slot.Height; + else + Overlay.Top = r.Bottom; + }else + Overlay.Top = 0; + } + } + + [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true + public override bool Focusable + { + get { return base.Focusable; } + set { base.Focusable = value; } + } + + + public virtual void onPop(object sender, EventArgs e) + { + IGOLibHost tc = TopContainer; + if (tc == null) + return; + if (Overlay != null) { + Overlay.Visible = true; + if (Overlay.Parent == null) + tc.AddWidget (Overlay); + (tc as OpenTKGameWindow).PutOnTop (Overlay); + } + Pop.Raise (this, e); + } + public virtual void onUnpop(object sender, EventArgs e) + { + IGOLibHost tc = TopContainer; + if (tc == null) + return; + Overlay.Visible = false; + Unpop.Raise (this, e); + } + + public override void onMouseClick (object sender, MouseButtonEventArgs e) + { + IsPopped = !IsPopped; + base.onMouseClick (sender, e); + } + + public override void ClearBinding () + { + //ensure popped window is cleared + if (Overlay != null) { + if (Overlay.Parent != null) { + IGOLibHost tc = Overlay.Parent as IGOLibHost; + if (tc != null) + tc.DeleteWidget (Overlay); + } + } + base.ClearBinding (); + + } + public override void ResolveBindings () + { + base.ResolveBindings (); + if (Overlay != null) + Overlay.ResolveBindings (); + } + } +} diff --git a/src/GraphicObjects/Combobox.cs b/src/GraphicObjects/Combobox.cs deleted file mode 100644 index 473c10ff..00000000 --- a/src/GraphicObjects/Combobox.cs +++ /dev/null @@ -1,365 +0,0 @@ -using System; - - -using System.Collections.Generic; -using System.Linq; -using System.Text; -//using OpenTK.Graphics.OpenGL; - -using Cairo; - -using winColors = System.Drawing.Color; -using System.Diagnostics; -using System.Xml.Serialization; -using OpenTK.Input; -using System.ComponentModel; -using System.Xml; -using System.IO; -using System.Collections; -using System.Threading; - -namespace Crow -{ - [DefaultTemplate("#Crow.Templates.Combobox.goml")] - [DefaultOverlayTemplate("#Crow.Templates.ComboboxOverlay.goml")] - public class Combobox : TemplatedContainer - { - #region CTOR - public Combobox() : base(){ } - #endregion - - bool _isPopped; - string text; - GraphicObject _overlay; - Group _list; - IList data; - int _selectedIndex; - object _selectedItem; - string _itemTemplate; - string _overlayTemplate; - - public event EventHandler Pop; - public event EventHandler Unpop; - public event EventHandler SelectedItemChanged; - - #region implemented abstract members of TemplatedControl - protected override void loadTemplate (GraphicObject template) - { - base.loadTemplate (template); - loadOverlayTemplate (null); - } - public override GraphicObject Content { - get { - throw new NotImplementedException (); - } - set { - throw new NotImplementedException (); - } - } - #endregion - - protected virtual void loadOverlayTemplate(GraphicObject overlayTemplate) - { - if (overlayTemplate == null) { - DefaultOverlayTemplate dt = (DefaultOverlayTemplate)this.GetType ().GetCustomAttributes (typeof(DefaultOverlayTemplate), true).FirstOrDefault (); - Overlay = Interface.Load (dt.Path); - Overlay.ResolveBindings (); - } else - Overlay = overlayTemplate; - _list = Overlay.FindByName ("List") as Group; - } - - [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")] - public string ItemTemplate { - get { return _itemTemplate; } - set { - //TODO:reload list with new template? - _itemTemplate = value; - } - } - [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ComboboxOverlay.goml")] - public string OverlayTemplate { - get { return _overlayTemplate; } - set { - //TODO:reload list with new template? - _overlayTemplate = value; - - Overlay = Interface.Load (_overlayTemplate); - Overlay.ResolveBindings (); - _list = Overlay.FindByName ("List") as Group; - } - } - [XmlAttributeAttribute][DefaultValue(-1)] - public int SelectedIndex{ - get { return _selectedIndex; } - set { - //store value event if data is null, because in xml parsing selindex is always - //before data, so it's impossible without that trick to set a default index in goml - _selectedIndex = value; - - if (data == null) - return; - - if (_selectedIndex > data.Count - 1 || _selectedIndex < 0) - throw new Exception ("Combobox SelectedIndex out of range"); - - - _selectedItem = data [_selectedIndex]; - NotifyValueChanged ("SelectedIndex", SelectedIndex); - SelectedItemChanged.Raise (this, new SelectionChangeEventArgs(_selectedItem)); - - if (SelectedItem == null) - Text = ""; - else - Text = _selectedItem.ToString (); - } - } - public object SelectedItem{ - set { - if (_selectedItem == value) - return; - - _selectedItem = value; - _selectedIndex = data.IndexOf (_selectedItem); - NotifyValueChanged ("SelectedIndex", _selectedIndex); - SelectedItemChanged.Raise (this, new SelectionChangeEventArgs(_selectedItem)); - - if (SelectedItem == null) - Text = ""; - else - Text = _selectedItem.ToString (); - } - - get { return _selectedItem; } - } - [XmlAttributeAttribute][DefaultValue(null)] - public IList Data { - get { - return data; - } - set { - data = value; - if (_list == null) - return; - - foreach (GraphicObject c in _list.Children) { - c.ClearBinding (); - } - _list.Children.Clear (); - _list.registerForGraphicUpdate (); - if (data == null) - return; - if (SelectedIndex < 0) - return; - - //force raise of changes - SelectedIndex = SelectedIndex; - - pendingChildrenAddition = new Queue (); - threadedLoadingFinished = false; - - Thread t = new Thread (loadingThread); - t.Start (); - t.Join (); - - } - } - public override void UpdateLayout (LayoutingType layoutType) - { - CheckPendingChildrenAddition (); - base.UpdateLayout (layoutType); - } - internal void CheckPendingChildrenAddition() - { - if (pendingChildrenAddition == null) - return; - lock (pendingChildrenAddition) { - if (!threadedLoadingFinished && pendingChildrenAddition.Count < 50) - return; - while (pendingChildrenAddition.Count > 0) { - _list.addChild (pendingChildrenAddition.Dequeue ()); - } - } - } - - volatile Queue pendingChildrenAddition; - volatile bool threadedLoadingFinished = false; - - void loadingThread() - { - #if DEBUG_LOAD_TIME - Stopwatch loadingTime = new Stopwatch (); - loadingTime.Start (); - #endif - - MemoryStream ms = new MemoryStream (); - lock (ItemTemplate) { - using (Stream stream = Interface.GetStreamFromPath (ItemTemplate)) - stream.CopyTo (ms); - } - - Type t = Interface.GetTopContainerOfGOMLStream (ms); - - foreach (var item in data) { - ms.Seek(0,SeekOrigin.Begin); - GraphicObject g = Interface.Load (ms, t); - g.DataSource = item; - g.MouseClick += itemClick; - - lock (pendingChildrenAddition) { - pendingChildrenAddition.Enqueue (g); - } - } - - ms.Dispose (); - - threadedLoadingFinished = true; - - #if DEBUG_LOAD_TIME - loadingTime.Stop (); - Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms", - loadingTime.ElapsedTicks, - loadingTime.ElapsedMilliseconds, this.ToString()); - #endif - } - public GraphicObject Overlay { - get { return _overlay; } - set { - if (_overlay != null) { - _overlay.LayoutChanged -= _overlay_LayoutChanged; - _overlay.MouseLeave -= _overlay_MouseLeave; - _overlay.LogicalParent = null; - } - - _overlay = value; - - if (_overlay == null) - return; - - _overlay.LogicalParent = this; - _overlay.Focusable = true; - _overlay.LayoutChanged += _overlay_LayoutChanged; - _overlay.MouseLeave += _overlay_MouseLeave; - } - } - [XmlAttributeAttribute()][DefaultValue("Combobox")] - public string Text { - get { return text; } - set { - if (text == value) - return; - text = value; - NotifyValueChanged ("Text", text); - } - } - [XmlAttributeAttribute()][DefaultValue(false)] - public bool IsPopped - { - get { return _isPopped; } - set - { - _isPopped = value; - - if (_isPopped) { - onPop (this, null); - NotifyValueChanged ("SvgSub", "expanded"); - return; - } - - onUnpop (this, null); - NotifyValueChanged ("SvgSub", "collapsed"); - } - } - - void itemClick(object sender, OpenTK.Input.MouseButtonEventArgs e){ - object datasource = (sender as GraphicObject).DataSource; - SelectedItem = datasource; - IsPopped = false; - //Debug.WriteLine ((sender as GraphicObject).DataSource); - } - void _overlay_MouseLeave (object sender, MouseMoveEventArgs e) - { - IsPopped = false; - } - void _overlay_LayoutChanged (object sender, LayoutChangeEventArgs e) - { - ILayoutable tc = Overlay.Parent as ILayoutable; - if (tc == null) - return; - Rectangle r = this.ScreenCoordinates (this.Slot); - if (e.LayoutType == LayoutingType.Width) { - if (Overlay.Slot.Width < tc.ClientRectangle.Width) { - if (r.Left + Overlay.Slot.Width > tc.ClientRectangle.Right) - Overlay.Left = tc.ClientRectangle.Right - Overlay.Slot.Width; - else - Overlay.Left = r.Left; - }else - Overlay.Left = 0; - }else if (e.LayoutType == LayoutingType.Height) { - if (Overlay.Slot.Height < tc.ClientRectangle.Height) { - if (r.Bottom + Overlay.Slot.Height > tc.ClientRectangle.Bottom) - Overlay.Top = r.Top - Overlay.Slot.Height; - else - Overlay.Top = r.Bottom; - }else - Overlay.Top = 0; - } - } - - [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true - public override bool Focusable - { - get { return base.Focusable; } - set { base.Focusable = value; } - } - - - public virtual void onPop(object sender, EventArgs e) - { - IGOLibHost tc = TopContainer; - if (tc == null) - return; - if (Overlay != null) { - Overlay.Visible = true; - if (Overlay.Parent == null) - tc.AddWidget (Overlay); - (tc as OpenTKGameWindow).PutOnTop (Overlay); - } - Pop.Raise (this, e); - } - public virtual void onUnpop(object sender, EventArgs e) - { - IGOLibHost tc = TopContainer; - if (tc == null) - return; - Overlay.Visible = false; - Unpop.Raise (this, e); - } - - public override void onMouseClick (object sender, MouseButtonEventArgs e) - { - IsPopped = !IsPopped; - base.onMouseClick (sender, e); - } - - public override void ClearBinding () - { - //ensure popped window is cleared - if (Overlay != null) { - if (Overlay.Parent != null) { - IGOLibHost tc = Overlay.Parent as IGOLibHost; - if (tc != null) - tc.DeleteWidget (Overlay); - } - } - base.ClearBinding (); - - } - public override void ResolveBindings () - { - base.ResolveBindings (); - if (Overlay != null) - Overlay.ResolveBindings (); - } - } -} diff --git a/src/GraphicObjects/Expandable.cs b/src/GraphicObjects/Expandable.cs index 172406c2..f1e2bdeb 100644 --- a/src/GraphicObjects/Expandable.cs +++ b/src/GraphicObjects/Expandable.cs @@ -22,7 +22,7 @@ namespace Crow public class Expandable : TemplatedContainer { bool _isExpanded; - string title; + string caption; string image; Container _contentContainer; @@ -62,13 +62,13 @@ namespace Crow } [XmlAttributeAttribute()][DefaultValue("Expandable")] - public string Title { - get { return title; } + public string Caption { + get { return caption; } set { - if (title == value) + if (caption == value) return; - title = value; - NotifyValueChanged ("Title", title); + caption = value; + NotifyValueChanged ("Caption", caption); } } [XmlAttributeAttribute()][DefaultValue("#Crow.Images.Icons.expandable.svg")] diff --git a/src/GraphicObjects/GroupBox.cs b/src/GraphicObjects/GroupBox.cs new file mode 100644 index 00000000..81bac117 --- /dev/null +++ b/src/GraphicObjects/GroupBox.cs @@ -0,0 +1,68 @@ +using System; + + +using System.Collections.Generic; +using System.Linq; +using System.Text; +//using OpenTK.Graphics.OpenGL; + +using Cairo; + +using winColors = System.Drawing.Color; +using System.Diagnostics; +using System.Xml.Serialization; +using OpenTK.Input; +using System.ComponentModel; +using System.Xml; +using System.IO; + +namespace Crow +{ + [DefaultTemplate("#Crow.Templates.GroupBox.goml")] + public class GroupBox : TemplatedContainer + { + string caption; + Container _contentContainer; + + #region CTOR + public GroupBox() : base(){} + #endregion + + #region Template overrides + public override GraphicObject Content { + get { + return _contentContainer == null ? null : _contentContainer.Child; + } + set { + _contentContainer.SetChild(value); + } + } + protected override void loadTemplate(GraphicObject template = null) + { + base.loadTemplate (template); + + _contentContainer = this.child.FindByName ("Content") as Container; + } + #endregion + + #region GraphicObject overrides + [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true + public override bool Focusable + { + get { return base.Focusable; } + set { base.Focusable = value; } + } + #endregion + + [XmlAttributeAttribute()][DefaultValue("Groupbox")] + public string Caption { + get { return caption; } + set { + if (caption == value) + return; + caption = value; + NotifyValueChanged ("Caption", caption); + } + } + } +} diff --git a/src/GraphicObjects/Groupbox.cs b/src/GraphicObjects/Groupbox.cs deleted file mode 100644 index e1f33d84..00000000 --- a/src/GraphicObjects/Groupbox.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; - - -using System.Collections.Generic; -using System.Linq; -using System.Text; -//using OpenTK.Graphics.OpenGL; - -using Cairo; - -using winColors = System.Drawing.Color; -using System.Diagnostics; -using System.Xml.Serialization; -using OpenTK.Input; -using System.ComponentModel; -using System.Xml; -using System.IO; - -namespace Crow -{ - [DefaultTemplate("#Crow.Templates.Groupbox.goml")] - public class Groupbox : TemplatedContainer - { - string title; - Container _contentContainer; - - #region CTOR - public Groupbox() : base(){} - #endregion - - #region Template overrides - public override GraphicObject Content { - get { - return _contentContainer == null ? null : _contentContainer.Child; - } - set { - _contentContainer.SetChild(value); - } - } - protected override void loadTemplate(GraphicObject template = null) - { - base.loadTemplate (template); - - _contentContainer = this.child.FindByName ("Content") as Container; - } - #endregion - - #region GraphicObject overrides - [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true - public override bool Focusable - { - get { return base.Focusable; } - set { base.Focusable = value; } - } - #endregion - - [XmlAttributeAttribute()][DefaultValue("Groupbox")] - public string Title { - get { return title; } - set { - if (title == value) - return; - title = value; - NotifyValueChanged ("Title", title); - } - } - } -} diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index 8d9880ad..a0ab540e 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -31,7 +31,7 @@ using System.Threading; namespace Crow { - [DefaultTemplate("#Crow.Templates.Listbox.goml")] + [DefaultTemplate("#Crow.Templates.ListBox.goml")] //[DefaultTemplate("#Crow.Templates.ItemTemplate.goml")] public class ListBox : TemplatedControl//, IXmlSerializable { diff --git a/src/GraphicObjects/MessageBox.cs b/src/GraphicObjects/MessageBox.cs index 40f48e4a..18c4afb3 100644 --- a/src/GraphicObjects/MessageBox.cs +++ b/src/GraphicObjects/MessageBox.cs @@ -54,16 +54,16 @@ namespace Crow } } #region GraphicObject overrides - [XmlAttributeAttribute][DefaultValue(350)] + [XmlAttributeAttribute][DefaultValue(250)] public override int Width { get { return base.Width; } set { base.Width = value; } } - [XmlAttributeAttribute][DefaultValue(150)] - public override int Height { - get { return base.Height; } - set { base.Height = value; } - } +// [XmlAttributeAttribute][DefaultValue(80)] +// public override int Height { +// get { return base.Height; } +// set { base.Height = value; } +// } [XmlAttributeAttribute()][DefaultValue(true)] public override bool Focusable { diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index 5842faf8..15a209ce 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -27,7 +27,7 @@ namespace Crow } #endregion bool _isPopped; - string title; + string caption; string image; GraphicObject _content; @@ -66,15 +66,16 @@ namespace Crow if (tc == null) return; Rectangle r = this.ScreenCoordinates (this.Slot); - if (e.LayoutType == LayoutingType.Width) { + if (((int)e.LayoutType & (int)LayoutingType.Width) > 0) { if (Content.Slot.Width < tc.ClientRectangle.Width) { if (r.Left + Content.Slot.Width > tc.ClientRectangle.Right) Content.Left = tc.ClientRectangle.Right - Content.Slot.Width; else Content.Left = r.Left; - }else + } else Content.Left = 0; - }else if (e.LayoutType == LayoutingType.Height) { + } + if (((int)e.LayoutType & (int)LayoutingType.Height) > 0) { if (Content.Slot.Height < tc.ClientRectangle.Height) { if (r.Bottom + Content.Slot.Height > tc.ClientRectangle.Bottom) Content.Top = r.Top - Content.Slot.Height; @@ -116,13 +117,13 @@ namespace Crow } [XmlAttributeAttribute()][DefaultValue("Popper")] - public string Title { - get { return title; } + public string Caption { + get { return caption; } set { - if (title == value) + if (caption == value) return; - title = value; - NotifyValueChanged ("Title", title); + caption = value; + NotifyValueChanged ("Caption", caption); } } [XmlAttributeAttribute()][DefaultValue("#Crow.Images.Icons.expandable.svg")] @@ -165,6 +166,7 @@ namespace Crow if (Content.Parent == null) tc.AddWidget (Content); tc.PutOnTop (Content); + _content_LayoutChanged (this, new LayoutChangeEventArgs (LayoutingType.Sizing)); } Pop.Raise (this, e); } @@ -182,6 +184,5 @@ namespace Crow IsPopped = !IsPopped; base.onMouseClick (sender, e); } - } } diff --git a/src/GraphicObjects/ScrollBar.cs b/src/GraphicObjects/ScrollBar.cs new file mode 100644 index 00000000..905efc55 --- /dev/null +++ b/src/GraphicObjects/ScrollBar.cs @@ -0,0 +1,101 @@ +using System; + + +using System.Collections.Generic; +using System.Linq; +using System.Text; +//using OpenTK.Graphics.OpenGL; + +using Cairo; + +using winColors = System.Drawing.Color; +using System.Diagnostics; +using System.Xml.Serialization; +using OpenTK.Input; +using System.ComponentModel; + +namespace Crow +{ + [DefaultTemplate("#Crow.Templates.ScrollBar.goml")] + public class ScrollBar : TemplatedControl, IValueChange + { + #region IValueChange implementation + public event EventHandler ValueChanged; + #endregion + + Orientation _orientation; + Slider _slider; + double _maximumScroll; + double _scroll; + + public ScrollBar() : base() + { + } + + protected override void loadTemplate(GraphicObject template = null) + { + base.loadTemplate (template); + _slider = this.child.FindByName ("Slider") as Slider; + } + + [XmlAttributeAttribute()][DefaultValue(0.0)] + public virtual double MaximumScroll + { + get { return _maximumScroll; } + set { + if (_maximumScroll == value) + return; + _maximumScroll = value; + registerForGraphicUpdate (); + ValueChanged.Raise(this, new ValueChangeEventArgs ("MaximumScroll", _maximumScroll)); + } + } + [XmlAttributeAttribute()][DefaultValue(0.0)] + public virtual double Scroll + { + get { return _scroll; } + set { + if (_scroll == value) + return; + _scroll = value; + if (_scroll < 0.0) + _scroll = 0.0; + else if (_scroll > _maximumScroll) + _scroll = _maximumScroll; + registerForGraphicUpdate (); + ValueChanged.Raise(this, new ValueChangeEventArgs ("Scroll", _scroll)); + } + } + [XmlAttributeAttribute()][DefaultValue(Orientation.Vertical)] + public virtual Orientation Orientation + { + get { return _orientation; } + set { + if (_orientation == value) + return; + _orientation = value; + ValueChanged.Raise(this, new ValueChangeEventArgs ("Orientation", _orientation)); + registerForGraphicUpdate (); + } + } + public void onScrollBack (object sender, MouseButtonEventArgs e) + { + Scroll -= _slider.LargeIncrement; + } + public void onScrollForth (object sender, MouseButtonEventArgs e) + { + Scroll += _slider.LargeIncrement; + + } + + public void onSliderValueChange(object sender, ValueChangeEventArgs e){ + Scroll = Convert.ToDouble(e.NewValue); + } + + public override void OnLayoutChanges (LayoutingType layoutType) + { + OpenTKGameWindow.currentWindow.CursorVisible = true; + base.OnLayoutChanges (layoutType); + } + } +} diff --git a/src/GraphicObjects/Scrollbar.cs b/src/GraphicObjects/Scrollbar.cs deleted file mode 100644 index f68bdb77..00000000 --- a/src/GraphicObjects/Scrollbar.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System; - - -using System.Collections.Generic; -using System.Linq; -using System.Text; -//using OpenTK.Graphics.OpenGL; - -using Cairo; - -using winColors = System.Drawing.Color; -using System.Diagnostics; -using System.Xml.Serialization; -using OpenTK.Input; -using System.ComponentModel; - -namespace Crow -{ - [DefaultTemplate("#Crow.Templates.Scrollbar.goml")] - public class Scrollbar : TemplatedControl, IValueChange - { - #region IValueChange implementation - public event EventHandler ValueChanged; - #endregion - - Orientation _orientation; - Slider _slider; - double _maximumScroll; - double _scroll; - - public Scrollbar() : base() - { - } - - protected override void loadTemplate(GraphicObject template = null) - { - base.loadTemplate (template); - _slider = this.child.FindByName ("Slider") as Slider; - } - - [XmlAttributeAttribute()][DefaultValue(0.0)] - public virtual double MaximumScroll - { - get { return _maximumScroll; } - set { - if (_maximumScroll == value) - return; - _maximumScroll = value; - registerForGraphicUpdate (); - ValueChanged.Raise(this, new ValueChangeEventArgs ("MaximumScroll", _maximumScroll)); - } - } - [XmlAttributeAttribute()][DefaultValue(0.0)] - public virtual double Scroll - { - get { return _scroll; } - set { - if (_scroll == value) - return; - _scroll = value; - if (_scroll < 0.0) - _scroll = 0.0; - else if (_scroll > _maximumScroll) - _scroll = _maximumScroll; - registerForGraphicUpdate (); - ValueChanged.Raise(this, new ValueChangeEventArgs ("Scroll", _scroll)); - } - } - [XmlAttributeAttribute()][DefaultValue(Orientation.Vertical)] - public virtual Orientation Orientation - { - get { return _orientation; } - set { - if (_orientation == value) - return; - _orientation = value; - ValueChanged.Raise(this, new ValueChangeEventArgs ("Orientation", _orientation)); - registerForGraphicUpdate (); - } - } - public void onScrollBack (object sender, MouseButtonEventArgs e) - { - Scroll -= _slider.LargeIncrement; - } - public void onScrollForth (object sender, MouseButtonEventArgs e) - { - Scroll += _slider.LargeIncrement; - - } - - public void onSliderValueChange(object sender, ValueChangeEventArgs e){ - Scroll = Convert.ToDouble(e.NewValue); - } - - public override void OnLayoutChanges (LayoutingType layoutType) - { - OpenTKGameWindow.currentWindow.CursorVisible = true; - base.OnLayoutChanges (layoutType); - } - } -} diff --git a/src/GraphicObjects/Slider.cs b/src/GraphicObjects/Slider.cs index 97bc177f..7b44a93e 100644 --- a/src/GraphicObjects/Slider.cs +++ b/src/GraphicObjects/Slider.cs @@ -154,6 +154,7 @@ namespace Crow cursor.TopLeft = new Point ((int)(p1.X - r.Width / 2), r.Top + (int)(Value * unity)); } + cursor.Inflate (-1); } #region mouse handling diff --git a/src/GraphicObjects/TextBox.cs b/src/GraphicObjects/TextBox.cs index 097ecaa1..9fca2fea 100644 --- a/src/GraphicObjects/TextBox.cs +++ b/src/GraphicObjects/TextBox.cs @@ -12,16 +12,16 @@ using System.Runtime.InteropServices; namespace Crow { - public class TextBoxWidget : Label + public class TextBox : Label { #region CTOR - public TextBoxWidget(string _initialValue) + public TextBox(string _initialValue) : base(_initialValue) { } - public TextBoxWidget() + public TextBox() { } #endregion diff --git a/src/Interface.cs b/src/Interface.cs index c1713838..b6e5b3f1 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -112,8 +112,11 @@ namespace Crow if (path.StartsWith ("#")) { string resId = path.Substring (1); - stream = System.Reflection.Assembly.GetEntryAssembly ().GetManifestResourceStream (resId); - if (stream == null)//try to find ressource in golib assembly + //try/catch added to prevent nunit error + try { + stream = System.Reflection.Assembly.GetEntryAssembly ().GetManifestResourceStream (resId); + } catch (Exception ex) {} + if (stream == null)//try to find ressource in Crow assembly stream = System.Reflection.Assembly.GetExecutingAssembly ().GetManifestResourceStream (resId); if (stream == null) throw new Exception ("Resource not found: " + path);