From: jpbruyere Date: Mon, 7 Sep 2015 06:32:29 +0000 (+0200) Subject: * XCursor.cs: X-Git-Tag: 0.2~62 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=bacf29e47409c20292b6861e6ef40bfc2119eb7b;p=jp%2Fcrow.git * XCursor.cs: * move: * help: * hand: * cross: * arrow: * top_left_corner: * top_right_corner: * bottom_left_corner: * bottom_right_corner: Mouse xCursors * Window.goml: * Checkbox.goml: * Group.cs: * Popper.cs: * Checkbox.cs: * Expandable.cs: * RadioButton.cs: * GraphicObject.cs: * PrivateContainer.cs: * TemplatedControl.cs: Focus handling improvment * GOLib.csproj: * OpenTKGameWindow.cs: * Window.cs: cursors --- diff --git a/GOLib.csproj b/GOLib.csproj index 25fa70bc..70181412 100644 --- a/GOLib.csproj +++ b/GOLib.csproj @@ -115,6 +115,7 @@ + @@ -182,5 +183,16 @@ + + + + + + + + + + + diff --git a/Images/Icons/Cursors/arrow b/Images/Icons/Cursors/arrow new file mode 100644 index 00000000..61f968ef Binary files /dev/null and b/Images/Icons/Cursors/arrow differ diff --git a/Images/Icons/Cursors/bottom_left_corner b/Images/Icons/Cursors/bottom_left_corner new file mode 100644 index 00000000..e9a41a20 Binary files /dev/null and b/Images/Icons/Cursors/bottom_left_corner differ diff --git a/Images/Icons/Cursors/bottom_right_corner b/Images/Icons/Cursors/bottom_right_corner new file mode 100644 index 00000000..208faf48 Binary files /dev/null and b/Images/Icons/Cursors/bottom_right_corner differ diff --git a/Images/Icons/Cursors/cross b/Images/Icons/Cursors/cross new file mode 100644 index 00000000..4596b480 Binary files /dev/null and b/Images/Icons/Cursors/cross differ diff --git a/Images/Icons/Cursors/hand b/Images/Icons/Cursors/hand new file mode 100644 index 00000000..23939b74 Binary files /dev/null and b/Images/Icons/Cursors/hand differ diff --git a/Images/Icons/Cursors/help b/Images/Icons/Cursors/help new file mode 100644 index 00000000..cd7ec277 Binary files /dev/null and b/Images/Icons/Cursors/help differ diff --git a/Images/Icons/Cursors/move b/Images/Icons/Cursors/move new file mode 100644 index 00000000..ab98f6a3 Binary files /dev/null and b/Images/Icons/Cursors/move differ diff --git a/Images/Icons/Cursors/top_left_corner b/Images/Icons/Cursors/top_left_corner new file mode 100644 index 00000000..3493adc6 Binary files /dev/null and b/Images/Icons/Cursors/top_left_corner differ diff --git a/Images/Icons/Cursors/top_right_corner b/Images/Icons/Cursors/top_right_corner new file mode 100644 index 00000000..264cc577 Binary files /dev/null and b/Images/Icons/Cursors/top_right_corner differ diff --git a/Templates/Checkbox.goml b/Templates/Checkbox.goml index f9aca19d..c9dbe5b4 100755 --- a/Templates/Checkbox.goml +++ b/Templates/Checkbox.goml @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/Templates/Window.goml b/Templates/Window.goml index 97e980c2..afc63723 100755 --- a/Templates/Window.goml +++ b/Templates/Window.goml @@ -1,11 +1,10 @@  - - - - + + + + - diff --git a/src/GraphicObjects/Checkbox.cs b/src/GraphicObjects/Checkbox.cs index 930fce1a..f6b7bae3 100644 --- a/src/GraphicObjects/Checkbox.cs +++ b/src/GraphicObjects/Checkbox.cs @@ -23,7 +23,7 @@ namespace go Image _image; public Checkbox() : base() - { + { } protected override void loadTemplate(GraphicObject template = null) @@ -64,6 +64,12 @@ namespace go } } + [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true + public override bool Focusable + { + get { return base.Focusable; } + set { base.Focusable = value; } + } public override void onMouseClick (object sender, MouseButtonEventArgs e) { IsChecked = !IsChecked; diff --git a/src/GraphicObjects/Expandable.cs b/src/GraphicObjects/Expandable.cs index 8b3f4b1a..77054897 100644 --- a/src/GraphicObjects/Expandable.cs +++ b/src/GraphicObjects/Expandable.cs @@ -58,7 +58,12 @@ namespace go // this.Collapse += (object sender, EventArgs e) => {}; } - + [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true + public override bool Focusable + { + get { return base.Focusable; } + set { base.Focusable = value; } + } [XmlAttributeAttribute()][DefaultValue("Expandable")] public string Title { diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index e1e2963b..e1972669 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -659,7 +659,11 @@ namespace go #region Mouse handling public virtual bool MouseIsIn(Point m) { - return Visible & Focusable ? ScreenCoordinates(Slot).ContainsOrIsEqual (m) : false; + return Visible ? ScreenCoordinates(Slot).ContainsOrIsEqual (m) : false; + } + internal virtual void checkHoverWidget(Point m) + { + } public virtual void onMouseMove(object sender, MouseMoveEventArgs e) { diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index e7a4b2b6..e2d64c89 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -65,12 +65,6 @@ namespace go } #region GraphicObject overrides - [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true - public override bool Focusable - { - get { return base.Focusable; } - set { base.Focusable = value; } - } [XmlIgnore]public override bool DrawingIsValid { get { if (!base.DrawingIsValid) diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index 0bbe3a52..f03a166a 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -52,7 +52,12 @@ namespace go this.Unpop += (object sender, EventArgs e) => {_image.SvgSub = "collapsed";}; } - + [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true + public override bool Focusable + { + get { return base.Focusable; } + set { base.Focusable = value; } + } [XmlAttributeAttribute()][DefaultValue("Popper")] public string Title { diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index 025934f9..f863fae8 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -67,14 +67,6 @@ namespace go } #region GraphicObject Overrides - //check if not causing problems - [XmlAttributeAttribute()][DefaultValue(true)] - public override bool Focusable - { - get { return base.Focusable; } - set { base.Focusable = value; } - } - public override GraphicObject FindByName (string nameToFind) { if (Name == nameToFind) diff --git a/src/GraphicObjects/RadioButton.cs b/src/GraphicObjects/RadioButton.cs index 8c8000e2..9d7ef83e 100644 --- a/src/GraphicObjects/RadioButton.cs +++ b/src/GraphicObjects/RadioButton.cs @@ -35,6 +35,12 @@ namespace go _image.SvgSub = "unchecked"; } + [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true + public override bool Focusable + { + get { return base.Focusable; } + set { base.Focusable = value; } + } [XmlAttributeAttribute][DefaultValue("RadioButton")] public string Caption { diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index d8af0bdf..37da50cf 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -75,7 +75,6 @@ namespace go if (child == null)//trigger loading of default template if child is empty loadTemplate (); base.loadDefaultValues (); - this.Focusable = true; } public override GraphicObject FindByName (string nameToFind) diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index 0fd2b780..ad3ec5bb 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -36,23 +36,37 @@ namespace go void Window_MouseMove (object sender, OpenTK.Input.MouseMoveEventArgs e) { - -// if ((e.Position - this.Slot.TopLeft).Length < 3) -// System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.SizeNWSE; -// else -// System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; - - if (!e.Mouse.IsButtonDown (MouseButton.Left)) - return; - - // - System.Windows.Forms.Cursor.Show();// = System.Windows.Forms.Cursors.SizeAll; + } + public override void onMouseMove (object sender, MouseMoveEventArgs e) + { + base.onMouseMove (sender, e); + + + OpenTKGameWindow otkgw = TopContainer as OpenTKGameWindow; + + if ((e.Position - this.Slot.TopLeft).Length < 5) + otkgw.Cursor = XCursor.NW; + else + otkgw.Cursor = XCursor.Cross; + + + if (TopContainer.activeWidget != this) + return; + this.TopContainer.redrawClip.AddRectangle (this.ScreenCoordinates(this.Slot)); this.Left += e.XDelta; this.Top += e.YDelta; this.registerForGraphicUpdate (); + + + } + public override void onMouseLeave (object sender, MouseMoveEventArgs e) + { + base.onMouseLeave (sender, e); + OpenTKGameWindow otkgw = TopContainer as OpenTKGameWindow; + otkgw.Cursor = XCursor.Default; } protected override void loadTemplate(GraphicObject template = null) diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index e9c7db08..d7cecd4e 100755 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -32,6 +32,16 @@ namespace go // : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), _title) { //VSync = VSyncMode.On; + + //Load cursors + XCursor.Cross = XCursorFile.Load("#go.Images.Icons.Cursors.cross").Cursors[0]; + XCursor.Default = XCursorFile.Load("#go.Images.Icons.Cursors.arrow").Cursors[0]; + XCursor.NW = XCursorFile.Load("#go.Images.Icons.Cursors.top_left_corner").Cursors[0]; + XCursor.NE = XCursorFile.Load("#go.Images.Icons.Cursors.top_right_corner").Cursors[0]; + XCursor.SW = XCursorFile.Load("#go.Images.Icons.Cursors.bottom_left_corner").Cursors[0]; + XCursor.SE = XCursorFile.Load("#go.Images.Icons.Cursors.bottom_right_corner").Cursors[0]; + + } #endregion @@ -288,7 +298,10 @@ namespace go // Debug.WriteLine("UPDATE: {0} ticks \t, {1} ms", // updateTime.ElapsedTicks, // updateTime.ElapsedMilliseconds); - + //update Mouse cursor + if (_hoverWidget is Window) { + + } } #endregion @@ -423,7 +436,7 @@ namespace go } GraphicObject g = _hoverWidget; - while (!g.Focusable) { + while (!g.Focusable) { g = g.Parent as GraphicObject; if (g == null) { return; @@ -433,6 +446,7 @@ namespace go _activeWidget = g; _activeWidget.onMouseButtonDown (this, e); } + void Mouse_WheelChanged(object sender, MouseWheelEventArgs e) { if (_hoverWidget == null) { diff --git a/src/XCursor.cs b/src/XCursor.cs new file mode 100644 index 00000000..a186fcfe --- /dev/null +++ b/src/XCursor.cs @@ -0,0 +1,173 @@ +// +// XCursor.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2015 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 System; +using System.IO; +using System.Diagnostics; +using OpenTK; +using System.Collections.Generic; + +namespace go +{ + public class XCursorFile + { + const uint XC_TYPE_IMG = 0xfffd0002; + + class toc + { + public uint type; + public uint subtype; + public uint pos; + + public toc(BinaryReader sr) + { + type = sr.ReadUInt32(); + subtype = sr.ReadUInt32(); + pos = sr.ReadUInt32(); + } + } + + public List Cursors = new List(); + + static XCursorFile loadFromRessource (string resId) + { + Stream stream = null; + + //first, search for ressource in main executable assembly + stream = System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream(resId); + if (stream == null)//try to find ressource in golib assembly + stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resId); + if (stream == null) { + Debug.WriteLine ("Ressource not found: " + resId); + return null; + } + + using (MemoryStream ms = new MemoryStream ()) { + stream.CopyTo (ms); + ms.Seek (0, SeekOrigin.Begin); + return loadFromStream (ms); + } + } + static XCursorFile loadFromFile (string path) + { + using (Stream s = new FileStream (path, + FileMode.Open, FileAccess.Read)) { + return loadFromStream (s); + } + } + static XCursorFile loadFromStream(Stream s) + { + List tocList = new List (); + XCursorFile tmp = new XCursorFile (); + + using (BinaryReader sr = new BinaryReader (s)) { + byte[] data; + //magic: CARD32 ’Xcur’ (0x58, 0x63, 0x75, 0x72) + if (new string (sr.ReadChars (4)) != "Xcur") { + Debug.WriteLine ("XCursor Load error: Wrong magic"); + return null; + } + //header: CARD32 bytes in this header + uint headerLength = sr.ReadUInt32 (); + //version: CARD32 file version number + uint version = sr.ReadUInt32 (); + //ntoc: CARD32 number of toc entries + uint nbToc = sr.ReadUInt32 (); + //toc: LISTofTOC table of contents + for (uint i = 0; i < nbToc; i++) { + tocList.Add (new toc (sr)); + } + + foreach (toc t in tocList) { + if (t.type != XC_TYPE_IMG) + continue; + + sr.BaseStream.Seek (t.pos, SeekOrigin.Begin); + tmp.Cursors.Add(imageLoad (sr)); + } + } + return tmp; + } + + public static XCursorFile Load(string path) + { + if (path.StartsWith ("#")) + return loadFromRessource (path.Substring(1)); + else + return loadFromFile (path); + } + + static XCursor imageLoad(BinaryReader sr) + { + XCursor tmp = new XCursor(); + // header: 36 Image headers are 36 bytes + uint header = sr.ReadUInt32(); + // type: 0xfffd0002 Image type is 0xfffd0002 + uint type = sr.ReadUInt32(); + // subtype: CARD32 Image subtype is the nominal size + uint subtype = sr.ReadUInt32(); + // version: 1 + uint version = sr.ReadUInt32(); + // width: CARD32 Must be less than or equal to 0x7fff + tmp.Width = sr.ReadUInt32(); + // height: CARD32 Must be less than or equal to 0x7fff + tmp.Height = sr.ReadUInt32(); + // xhot: CARD32 Must be less than or equal to width + tmp.Xhot = sr.ReadUInt32(); + // yhot: CARD32 Must be less than or equal to height + tmp.Yhot = sr.ReadUInt32(); + // delay: CARD32 Delay between animation frames in milliseconds + tmp.Delay = sr.ReadUInt32(); + // pixels: LISTofCARD32 Packed ARGB format pixels + tmp.data = sr.ReadBytes((int)(tmp.Width * tmp.Height * 4)); + return tmp; + } + } + public class XCursor + { + public static XCursor Default; + public static XCursor Cross; + public static XCursor Arrow; + public static XCursor SW; + public static XCursor SE; + public static XCursor NW; + public static XCursor NE; + public static XCursor N; + public static XCursor S; + + + + public uint Width; + public uint Height; + public uint Xhot; + public uint Yhot; + public uint Delay; + public byte[] data; + + public XCursor () + { + } + public static implicit operator MouseCursor(XCursor xc) + { + return new MouseCursor((int)xc.Xhot, (int)xc.Yhot, (int)xc.Width, (int)xc.Height,xc.data); + } + } +} +