]> O.S.I.I.S - jp/crow.git/commitdiff
* XCursor.cs:
authorjpbruyere <jp.bruyere@hotmail.com>
Mon, 7 Sep 2015 06:32:29 +0000 (08:32 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Mon, 7 Sep 2015 06:32:29 +0000 (08:32 +0200)
* 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

23 files changed:
GOLib.csproj
Images/Icons/Cursors/arrow [new file with mode: 0644]
Images/Icons/Cursors/bottom_left_corner [new file with mode: 0644]
Images/Icons/Cursors/bottom_right_corner [new file with mode: 0644]
Images/Icons/Cursors/cross [new file with mode: 0644]
Images/Icons/Cursors/hand [new file with mode: 0644]
Images/Icons/Cursors/help [new file with mode: 0644]
Images/Icons/Cursors/move [new file with mode: 0644]
Images/Icons/Cursors/top_left_corner [new file with mode: 0644]
Images/Icons/Cursors/top_right_corner [new file with mode: 0644]
Templates/Checkbox.goml
Templates/Window.goml
src/GraphicObjects/Checkbox.cs
src/GraphicObjects/Expandable.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/Popper.cs
src/GraphicObjects/PrivateContainer.cs
src/GraphicObjects/RadioButton.cs
src/GraphicObjects/TemplatedControl.cs
src/GraphicObjects/Window.cs
src/OpenTKGameWindow.cs
src/XCursor.cs [new file with mode: 0644]

index 25fa70bcfc594eb2d259c9a735c3378d60786891..70181412072bc0d1891f0784b62e6f1a8740f48c 100644 (file)
     <Compile Include="src\ValueChangeEventArgs.cs" />\r
     <Compile Include="src\LayoutChangeEventArgs.cs" />\r
     <Compile Include="src\ReflexionExtensions.cs" />\r
+    <Compile Include="src\XCursor.cs" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <Reference Include="System" />\r
     <EmbeddedResource Include="Templates\AnalogMeter0.goml" />\r
     <EmbeddedResource Include="Images\meter.svg" />\r
     <EmbeddedResource Include="Images\Icons\member.svg" />\r
+    <EmbeddedResource Include="Images\Icons\Cursors\cross" />\r
+    <EmbeddedResource Include="Images\Icons\Cursors\bottom_left_corner" />\r
+    <EmbeddedResource Include="Images\Icons\Cursors\bottom_right_corner" />\r
+    <EmbeddedResource Include="Images\Icons\Cursors\top_left_corner" />\r
+    <EmbeddedResource Include="Images\Icons\Cursors\top_right_corner" />\r
+    <EmbeddedResource Include="Images\Icons\Cursors\arrow" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <None Include="Images\Icons\Cursors\hand" />\r
+    <None Include="Images\Icons\Cursors\help" />\r
+    <None Include="Images\Icons\Cursors\move" />\r
   </ItemGroup>\r
 </Project>\r
diff --git a/Images/Icons/Cursors/arrow b/Images/Icons/Cursors/arrow
new file mode 100644 (file)
index 0000000..61f968e
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 (file)
index 0000000..e9a41a2
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 (file)
index 0000000..208faf4
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 (file)
index 0000000..4596b48
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 (file)
index 0000000..23939b7
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 (file)
index 0000000..cd7ec27
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 (file)
index 0000000..ab98f6a
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 (file)
index 0000000..3493adc
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 (file)
index 0000000..264cc57
Binary files /dev/null and b/Images/Icons/Cursors/top_right_corner differ
index f9aca19d310465e4789f3cdc9b9156a127783268..c9dbe5b44cd2c8eb474ae03d404806b2831c3274 100755 (executable)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>\r
-<HorizontalStack Margin="0" Spacing="1" Focusable="false">\r
+<HorizontalStack Margin="0" Spacing="1">\r
        <Image Name="Image" Width="16" Height="16" Path="#go.Images.Icons.checkbox.svg"/>\r
        <Label Name="Caption"/>\r
 </HorizontalStack>
\ No newline at end of file
index 97e980c243f26c151aef011c9c59d32c7c6372f0..afc63723bb12480e66bbd2b8304275c185d4b996 100755 (executable)
@@ -1,11 +1,10 @@
 <?xml version="1.0"?>\r
-<Border BorderWidth="1" BorderColor="LightGray"  MouseClick="onMouseClick" Margin="0" Focusable="true">\r
-       <VerticalStack MouseClick="onMouseClick" Height="0" Width="0" Margin="0" Focusable="true">\r
-               <Border BorderWidth="1" BorderColor="LightGray"  Height="-1" Width="0" MouseClick="onMouseClick"  Background="BlueCrayola" Focusable="true"\r
-                       MouseMove="Window_MouseMove">\r
-                       <HorizontalStack Margin="1" Spacing="1" Height="-1" Width="0" Focusable="true" MouseMove="Window_MouseMove">\r
+<Border BorderWidth="1" BorderColor="LightGray" Margin="0">\r
+       <VerticalStack Height="0" Width="0" Margin="0">\r
+               <Border BorderWidth="1" BorderColor="LightGray"  Height="-1" Width="0" Background="BlueCrayola">\r
+                       <HorizontalStack Name="hs" Margin="1" Spacing="1" Height="-1" Width="0" Focusable="false" >\r
                                <Image Name="Image" Margin="1" Width="16" Height="16" Path="#go.Images.Icons.tetra.png"/>\r
-                               <Label Width="0" Focusable="true" Name="Title" MouseMove="Window_MouseMove" Margin="5" />\r
+                               <Label Width="0" Name="Title" Margin="5" />\r
                                <Image Focusable="true" Name="Image" Margin="1" Width="16" Height="16" Path="#go.Images.Icons.exit.svg"\r
                                        MouseEnter="{Background=Red}" MouseLeave="{Background=Transparent}" MouseClick="butQuitPress"/>\r
                        </HorizontalStack>\r
index 930fce1a367e9535205a61834d35a124770fde7d..f6b7bae394abdd526576b97ee5a200d02f17d0b8 100644 (file)
@@ -23,7 +23,7 @@ namespace go
                Image _image;\r
 \r
                public Checkbox() : base()\r
-               {\r
+               {                       \r
                }       \r
 \r
                protected override void loadTemplate(GraphicObject template = null)\r
@@ -64,6 +64,12 @@ namespace go
             }\r
         }\r
 \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
                public override void onMouseClick (object sender, MouseButtonEventArgs e)\r
                {\r
                        IsChecked = !IsChecked;\r
index 8b3f4b1a7be7d6ebf5b506816534c802f72a6a6a..770548974fc809f5bd3b910b7ff2578cdefd1f18 100644 (file)
@@ -58,7 +58,12 @@ namespace go
 //                     this.Collapse += (object sender, EventArgs e) => {};\r
 \r
                }\r
-                       \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
 \r
                [XmlAttributeAttribute()][DefaultValue("Expandable")]\r
                public string Title {\r
index e1e2963b3c5f19708537d01b2392244c4c3f2448..e1972669345d166ecb6b5d41a832ad87ce75b21f 100644 (file)
@@ -659,7 +659,11 @@ namespace go
                #region Mouse handling\r
                public virtual bool MouseIsIn(Point m)\r
                {\r
-                       return Visible & Focusable ? ScreenCoordinates(Slot).ContainsOrIsEqual (m) : false; \r
+                       return Visible ? ScreenCoordinates(Slot).ContainsOrIsEqual (m) : false; \r
+               }\r
+               internal virtual void checkHoverWidget(Point m)\r
+               {\r
+                       \r
                }\r
                public virtual void onMouseMove(object sender, MouseMoveEventArgs e)\r
                {\r
index e7a4b2b68f4def6fbd891661319e93b30a255862..e2d64c89769c92e8352faf291f63f4421274daa4 100644 (file)
@@ -65,12 +65,6 @@ namespace go
                }\r
                        \r
                #region GraphicObject overrides\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]public override bool DrawingIsValid {\r
                        get {\r
                                if (!base.DrawingIsValid)\r
index 0bbe3a527c4deaa8656271f2e33cb3ebbeb4556b..f03a166aacdfa3b1abb3cbb3c66e0b8c73b52672 100644 (file)
@@ -52,7 +52,12 @@ namespace go
                        this.Unpop += (object sender, EventArgs e) => {_image.SvgSub = "collapsed";};\r
 \r
                }\r
-                       \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
 \r
                [XmlAttributeAttribute()][DefaultValue("Popper")]\r
                public string Title {\r
index 025934f9322387a522e7a76fefd4c69462f9311f..f863fae827cea9682bac50623fc54bd98ca1b0a6 100644 (file)
@@ -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)
index 8c8000e28017df5bb87655bdcc93797871944e4d..9d7ef83e7d05f6c8871c72e99599c4836a7353e2 100644 (file)
@@ -35,6 +35,12 @@ namespace go
                        _image.SvgSub = "unchecked";\r
                }\r
                        \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
 \r
                [XmlAttributeAttribute][DefaultValue("RadioButton")]\r
                public string Caption {\r
index d8af0bdf53ffd2579aa25fab47d9b3c881b2b761..37da50cfc5b3097ca350e418e94aafddf35dd414 100644 (file)
@@ -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)
index 0fd2b7808677f0ab578ad8e779fa6241a553f7af..ad3ec5bbaedcf95afc8453f3eda6a56702e9e17c 100644 (file)
@@ -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)
index e9c7db08ce1f8ff344c031b4cf8cf8ecd1167d4e..d7cecd4ecca3cb4b2bcdc6785c10715ea5e74621 100755 (executable)
@@ -32,6 +32,16 @@ namespace go
 //                     : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), _title)\r
                {\r
                        //VSync = VSyncMode.On;\r
+\r
+                       //Load cursors\r
+                       XCursor.Cross = XCursorFile.Load("#go.Images.Icons.Cursors.cross").Cursors[0];\r
+                       XCursor.Default = XCursorFile.Load("#go.Images.Icons.Cursors.arrow").Cursors[0];\r
+                       XCursor.NW = XCursorFile.Load("#go.Images.Icons.Cursors.top_left_corner").Cursors[0];\r
+                       XCursor.NE = XCursorFile.Load("#go.Images.Icons.Cursors.top_right_corner").Cursors[0];\r
+                       XCursor.SW = XCursorFile.Load("#go.Images.Icons.Cursors.bottom_left_corner").Cursors[0];\r
+                       XCursor.SE = XCursorFile.Load("#go.Images.Icons.Cursors.bottom_right_corner").Cursors[0];\r
+\r
+\r
                }        \r
                #endregion\r
 \r
@@ -288,7 +298,10 @@ namespace go
 //                     Debug.WriteLine("UPDATE: {0} ticks \t, {1} ms",\r
 //                             updateTime.ElapsedTicks,\r
 //                             updateTime.ElapsedMilliseconds);\r
-\r
+                       //update Mouse cursor\r
+                       if (_hoverWidget is Window) {\r
+                               \r
+                       }\r
                }                                               \r
                #endregion\r
                        \r
@@ -423,7 +436,7 @@ namespace go
                        }\r
 \r
                        GraphicObject g = _hoverWidget;\r
-                       while (!g.Focusable) {\r
+                       while (!g.Focusable) {                          \r
                                g = g.Parent as GraphicObject;\r
                                if (g == null) {                                        \r
                                        return;\r
@@ -433,6 +446,7 @@ namespace go
                        _activeWidget = g;\r
                        _activeWidget.onMouseButtonDown (this, e);\r
         }\r
+\r
         void Mouse_WheelChanged(object sender, MouseWheelEventArgs e)\r
         {\r
                        if (_hoverWidget == null) {\r
diff --git a/src/XCursor.cs b/src/XCursor.cs
new file mode 100644 (file)
index 0000000..a186fcf
--- /dev/null
@@ -0,0 +1,173 @@
+//
+//  XCursor.cs
+//
+//  Author:
+//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+//  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 <http://www.gnu.org/licenses/>.
+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<XCursor> Cursors = new List<XCursor>();
+
+               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<toc> tocList = new List<toc> ();
+                       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);
+               }
+       }
+}
+