]> O.S.I.I.S - jp/crow.git/commitdiff
mouse event revamping, fit measure unit change from Pixels to Percent
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 18 Feb 2018 09:53:30 +0000 (10:53 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 18 Feb 2018 09:53:30 +0000 (10:53 +0100)
12 files changed:
Crow.csproj
Templates/Expandable.template
Templates/ScrollBar.template
Templates/Spinner.template
Tests/BasicTests.cs
Tests/Interfaces/Divers/0.crow
src/BubblingMouseButtonEventArgs.cs
src/GraphicObjects/CheckBox.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/RadioButton.cs
src/Interface.cs
src/Measure.cs

index d05f2ae654d7ec04d334ef3e94a4b89ff13df94a..b340d9e408dd1948a0f213ef79c51e6fc6484f84 100644 (file)
@@ -30,7 +30,7 @@
     <DebugSymbols>true</DebugSymbols>
     <DebugType>full</DebugType>
     <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
-    <DefineConstants>DEBUG_UPDATE0;DEBUG_FOCUS;DEBUG_DISPOSE;DEBUG_LAYOUTING0;TRACE0;DEBUG;MEASURE_TIME;DEBUG_LOAD0;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0</DefineConstants>
+    <DefineConstants>DEBUG_UPDATE0;DEBUG_FOCUS0;DEBUG_DISPOSE0;DEBUG_LAYOUTING0;TRACE0;DEBUG;MEASURE_TIME;DEBUG_LOAD0;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0</DefineConstants>
     <Optimize>false</Optimize>
     <OutputPath>$(SolutionDir)build\Debug</OutputPath>
   </PropertyGroup>
index c5dd1d83d6972eb25f44ade5e37a78af4cc486b9..a36958d554a9ad20b58c4db6cdd1b653f68c8360 100755 (executable)
@@ -2,7 +2,7 @@
 <Border Style="ControlBorder" Foreground="{./Foreground}" Background="{./Background}">
        <VerticalStack>
                <HorizontalStack Spacing="1" Height="Fit" MouseDoubleClick="./onClickForExpand">
-                       <Container Margin="1" Width="9" Height="9" Focusable="true" MouseClick="./onClickForExpand"
+                       <Container Margin="1" Width="9" Height="9" Focusable="true" MouseDown="./onClickForExpand"
                                                                                                                MouseEnter="{Background=LightGray}"
                                                                                                                MouseLeave="{Background=Transparent}">
                                <Image
index c2b9a1ba1aaff8afa77563fe2c7c348aaac7b7d3..3c67bfa7b8db26c375f64bfe15785dbeef433a36 100755 (executable)
@@ -1,8 +1,8 @@
 <?xml version="1.0"?>
 <Border BorderWidth="1" Foreground="Jet">
        <GenericStack Orientation="{./Orientation}" Spacing="0">
-               <Shape Style="ArrowBut" MouseClick="./onScrollBack" Path="M 5.5,0.5 L 10.5,10.5 L 0.5,10.5 Z"/>
-               <Slider Name="Slider"
+               <Shape Style="ArrowBut" MouseDown="./onScrollBack" Path="M 5.5,0.5 L 10.5,10.5 L 0.5,10.5 Z"/>
+               <Slider Name="Slider"                   
                        Orientation="{./Orientation}"
                        Value="{²./Value}"
                        Maximum="{./Maximum}"
@@ -13,6 +13,6 @@
                        CursorColor="hgradient|0:Gray|1:Jet"
                        Foreground="Jet"
                        Background="hgradient|0:DimGray|0.1:Gray|0.95:Gray|1:White"/>
-               <Shape Style="ArrowBut" MouseClick="./onScrollForth" Path="M 0.5,0.5 L 10.5,0.5 L 5.5,10.5 Z"/>
+               <Shape Style="ArrowBut" MouseDown="./onScrollForth" Path="M 0.5,0.5 L 10.5,0.5 L 5.5,10.5 Z"/>
        </GenericStack>
 </Border>
\ No newline at end of file
index dd957d2532e45acf90857d023c11fd2b9d2b47b5..60d7ccf9eba299a8fcf6751ef4674cca6f0afb17 100755 (executable)
@@ -6,7 +6,7 @@
                        Text="{²./Value}" TextAlignment="Right" Margin="0"/>
        </Border>
        <VerticalStack MinimumSize="13,13" Width="25%" Height="Stretched" Spacing="0" Margin="0">
-               <Shape Style="ArrowBut" Height="50%" MouseClick="./onUp" Path="M 5.5,0.5 L 10.5,6.5 L 0.5,6.5 Z"/>                      
-               <Shape Style="ArrowBut" Height="50%" MouseClick="./onDown" Path="M 0.5,0.5 L 10.5,0.5 L 5.5,6.5 Z"/>                    
+               <Shape Style="ArrowBut" Height="50%" MouseDown="./onUp" Path="M 5.5,0.5 L 10.5,6.5 L 0.5,6.5 Z"/>                       
+               <Shape Style="ArrowBut" Height="50%" MouseDown="./onDown" Path="M 0.5,0.5 L 10.5,0.5 L 5.5,6.5 Z"/>                     
        </VerticalStack>
 </HorizontalStack>
index 9327a11253059c75e70a3d5dfb3521446f88a570..3bfd16e8ff574fa848c73d16640369366e485200 100644 (file)
@@ -99,10 +99,10 @@ namespace Tests
                        }
                        get { return List2; }
                }
-               IList<Color> testList = Color.ColorDic.Values.OrderBy(c=>c.Hue)
-                       .ThenBy(c=>c.Value).ThenBy(c=>c.Saturation)
+               List<Color> testList = Color.ColorDic.Values//.OrderBy(c=>c.Hue)
+                       //.ThenBy(c=>c.Value).ThenBy(c=>c.Saturation)
                        .ToList();
-               public IList<Color> TestList {
+               public List<Color> TestList {
                        set{
                                testList = value;
                                NotifyValueChanged ("TestList", testList);
index 4290079279defe33729188c478ca63379521f678..055b037ed555fe99fae5b71a8778f8a72a3c6f31 100755 (executable)
                                        MouseEnter="{Foreground=White}"
                                        MouseLeave="{Foreground=DimGray}"
                                        MouseDown="{Background=DarkRed}"
+                                       MouseClick="{Foreground=Green}"
+                                       MouseDoubleClick="{Foreground=Yellow}"
                                        MouseUp="{Background=Onyx}"/>
                                <Label Text="MouseEvents" Width="50%" Margin="3"
                                        Background="Onyx"
                                        Foreground="DimGray"
                                        TextAlignment="Center"
+                                       MouseClick="{Foreground=Green}"
+                                       MouseDoubleClick="{Foreground=Yellow}"
                                        MouseEnter="{Foreground=White}"
                                        MouseLeave="{Foreground=DimGray}"
                                        MouseDown="{Background=Mantis}"
index 749396209506593d216d7e06c31e2241cdefab8f..e81a6f74d18550c4d906d915466a1c90e4114f3d 100644 (file)
@@ -35,6 +35,9 @@ namespace Crow
        {
                public GraphicObject Focused;
                public BubblingMouseButtonEventArg(MouseButtonEventArgs mbe) : base(mbe){}
+               public BubblingMouseButtonEventArg(int x, int y, MouseButton button, bool pressed)
+                       : base (x,y,button,pressed){}
+
        }
 }
 
index 3a6b2b6ad102dc738bf6abd0dc344d180c3fdd0a..646a857774d6038abb2fe666126147a13d563f32 100644 (file)
@@ -65,10 +65,10 @@ namespace Crow
                        }
                }
 
-               public override void onMouseClick (object sender, MouseButtonEventArgs e)
+               public override void onMouseDown (object sender, MouseButtonEventArgs e)
                {
                        IsChecked = !IsChecked;
-                       base.onMouseClick (sender, e);
+                       base.onMouseDown (sender, e);
                }
        }
 }
index f0e8a04dfff257d45de889729df91438c66dc00b..aca7032e774235f6f56029ac30c6c8db04bd3fde 100644 (file)
@@ -1556,11 +1556,6 @@ namespace Crow
                        #if DEBUG_FOCUS
                        Debug.WriteLine("MOUSE DOWN => " + this.ToString());
                        #endif
-                       if (CurrentInterface.eligibleForDoubleClick == this && CurrentInterface.clickTimer.ElapsedMilliseconds < Interface.DoubleClick)
-                               onMouseDoubleClick (this, e);
-                       else
-                               CurrentInterface.clickTimer.Restart();
-                       CurrentInterface.eligibleForDoubleClick = null;
 
                        if (CurrentInterface.ActiveWidget == null)
                                CurrentInterface.ActiveWidget = this;
@@ -1603,12 +1598,6 @@ namespace Crow
                                p.onMouseUp(sender,e);
 
                        MouseUp.Raise (this, e);
-
-                       if (MouseIsIn (e.Position) && IsActive) {
-                               if (CurrentInterface.clickTimer.ElapsedMilliseconds < Interface.DoubleClick)
-                                       CurrentInterface.eligibleForDoubleClick = this;
-                               onMouseClick (this, e);
-                       }
                }
                public virtual void onMouseClick(object sender, MouseButtonEventArgs e){
                        #if DEBUG_FOCUS
index ead332ea9bffdb86c877189c90ab998f579762c0..4c553481bc89acba2f392767c01d06d725b9ee80 100644 (file)
@@ -43,7 +43,7 @@ namespace Crow
                public event EventHandler Unchecked;
 
                #region GraphicObject overrides
-               public override void onMouseClick (object sender, MouseButtonEventArgs e)
+               public override void onMouseDown (object sender, MouseButtonEventArgs e)
                {                                               
                        Group pg = Parent as Group;
                        if (pg != null) {
@@ -56,7 +56,7 @@ namespace Crow
                        } else
                                IsChecked = !IsChecked;
 
-                       base.onMouseClick (sender, e);
+                       base.onMouseDown (sender, e);
                }
                #endregion
 
index 0142f96a8befb56a62591318f9cfa293844097c7..e1bd7533b82147a58168cb8f79114bc97d798732 100644 (file)
@@ -114,7 +114,7 @@ namespace Crow
                /// <summary> delay before tooltip appear </summary>
                public static int ToolTipDelay = 500;
                /// <summary>Double click threshold in milisecond</summary>
-               public static int DoubleClick = 200;//max duration between two mouse_down evt for a dbl clk in milisec.
+               public static int DoubleClick = 250;//max duration between two mouse_down evt for a dbl clk in milisec.
                /// <summary> Time to wait in millisecond before starting repeat loop</summary>
                public static int DeviceRepeatDelay = 700;
                /// <summary> Time interval in millisecond between device event repeat</summary>
@@ -143,7 +143,20 @@ namespace Crow
                /// </summary>
                protected static Interface CurrentInterface;
                internal Stopwatch clickTimer = new Stopwatch();
-               internal GraphicObject eligibleForDoubleClick = null;
+               GraphicObject armedClickSender = null;
+               MouseButtonEventArgs armedClickEvtArgs = null;
+//             internal GraphicObject EligibleForDoubleClick {
+//                     get { return eligibleForDoubleClick; }
+//                     set {
+//                             eligibleForDoubleClick = value;
+//                             clickTimer.Restart ();
+//                     }
+//             }
+               internal void armeClick (GraphicObject sender, MouseButtonEventArgs e){
+                       armedClickSender = sender;
+                       armedClickEvtArgs = e;
+                       clickTimer.Restart ();
+               }
                #endregion
 
                #region Events
@@ -476,12 +489,18 @@ namespace Crow
                /// Result: the Interface bitmap is drawn in memory (byte[] bmp) and a dirtyRect and bitmap are available
                /// </summary>
                public void Update(){
+                       if (armedClickSender != null && clickTimer.ElapsedMilliseconds >= Interface.DoubleClick) {
+                               armedClickSender.onMouseClick (armedClickSender, armedClickEvtArgs);                            
+                               armedClickSender = null;
+                       }
+
                        if (mouseRepeatCount > 0) {
                                int mc = mouseRepeatCount;
                                mouseRepeatCount -= mc;
                                if (_focusedWidget != null) {
+                                       mouseRepeatTriggeredAtLeastOnce = true;
                                        for (int i = 0; i < mc; i++) {
-                                               _focusedWidget.onMouseClick (this, new MouseButtonEventArgs (Mouse.X, Mouse.Y, MouseButton.Left, true));
+                                               _focusedWidget.onMouseDown (this, new BubblingMouseButtonEventArg(Mouse.X, Mouse.Y, MouseButton.Left, true));
                                        }
                                }
                        }
@@ -794,6 +813,10 @@ namespace Crow
                /// <returns>true if mouse is in the interface</returns>
                public virtual bool ProcessMouseMove(int x, int y)
                {
+                       if (armedClickSender != null) {
+                               armedClickSender.onMouseClick (armedClickSender, armedClickEvtArgs);
+                               armedClickSender = null;
+                       }
                        int deltaX = x - Mouse.X;
                        int deltaY = y - Mouse.Y;
                        Mouse.X = x;
@@ -890,13 +913,18 @@ namespace Crow
                                mouseRepeatThread.Abort();
                                mouseRepeatThread.Join ();
                        }
-
+                       if (!mouseRepeatTriggeredAtLeastOnce) {
+                               if (_activeWidget.MouseIsIn (e.Position))
+                                       armeClick (_activeWidget, e);                           
+                       }
+                       mouseRepeatTriggeredAtLeastOnce = false;
                        _activeWidget.onMouseUp (_activeWidget, e);
-                       GraphicObject lastActive = _activeWidget;
+
+//                     GraphicObject lastActive = _activeWidget;
                        ActiveWidget = null;
-                       if (!lastActive.MouseIsIn (Mouse.Position)) {
-                               ProcessMouseMove (Mouse.X, Mouse.Y);
-                       }
+//                     if (!lastActive.MouseIsIn (Mouse.Position)) {
+//                             ProcessMouseMove (Mouse.X, Mouse.Y);
+//                     }
                        return true;
                }
                /// <summary>
@@ -912,6 +940,18 @@ namespace Crow
                        if (HoverWidget == null)
                                return false;
 
+                       if (HoverWidget == armedClickSender) {
+                               if (clickTimer.ElapsedMilliseconds < Interface.DoubleClick) {
+                                       armedClickSender.onMouseDoubleClick (armedClickSender, e);
+                                       armedClickSender = null;
+                                       return true;
+                               }
+                                       
+                       }
+                       if (armedClickSender!=null)
+                               armedClickSender.onMouseClick (armedClickSender, armedClickEvtArgs);                            
+                       armedClickSender = null;
+
                        HoverWidget.onMouseDown(HoverWidget,new BubblingMouseButtonEventArg(e));
 
                        if (FocusedWidget == null)
@@ -1062,13 +1102,14 @@ namespace Crow
                #endregion
 
                #region Device Repeat Events
-               volatile bool mouseRepeatOn, keyboardRepeatOn;
+               volatile bool mouseRepeatOn, keyboardRepeatOn, mouseRepeatTriggeredAtLeastOnce = false;
                volatile int mouseRepeatCount, keyboardRepeatCount;
                Thread mouseRepeatThread, keyboardRepeatThread;
                KeyboardKeyEventArgs lastKeyDownEvt;
                void mouseRepeatThreadFunc()
                {
                        mouseRepeatOn = true;
+                       mouseRepeatTriggeredAtLeastOnce = false;
                        Thread.Sleep (Interface.DeviceRepeatDelay);
                        while (mouseRepeatOn) {
                                mouseRepeatCount++;
index 352ce8ff0041d380e17a78dad9a025a3c4ccd208..c88038c6f33e6a2b81928dfeba6aa494c24c2f4e 100644 (file)
@@ -49,7 +49,7 @@ namespace Crow
                /// <summary>
                /// Fit on content, this special measure is defined as a fixed integer set to -1 pixel
                /// </summary>
-               public static Measure Fit = new Measure(-1);
+               public static Measure Fit = new Measure(-1,Unit.Percent);
                /// <summary>
                /// Stretched into parent client area. This special measure is defined as a proportional cote
                /// set to 100 Percents
@@ -67,8 +67,8 @@ namespace Crow
                /// <summary>
                /// True is size is fixed in pixels, this means not proportional, stretched nor fit.
                /// </summary>
-               public bool IsFixed { get { return Value > 0 && Units == Unit.Pixel; }}
-               public bool IsFit { get { return Value == -1 && Units == Unit.Pixel; }}
+               public bool IsFixed { get { return Units == Unit.Pixel; }}
+               public bool IsFit { get { return Value == -1 && Units == Unit.Percent; }}
                #region Operators
                public static implicit operator int(Measure m){
                        return m.Value;