diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-02-18 10:53:30 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-02-18 10:53:30 +0100 |
| commit | 2fe8a2c781c270279e7bf579b76fddc3d7fc8cbe (patch) | |
| tree | 1a3c2b62e5df15445333ea5eb0c1d2f94d75a5b5 | |
| parent | 632bd63db115383da4216ee31ff0e9d39081e87b (diff) | |
mouse event revamping, fit measure unit change from Pixels to Percent
| -rw-r--r-- | Crow.csproj | 2 | ||||
| -rwxr-xr-x | Templates/Expandable.template | 2 | ||||
| -rwxr-xr-x | Templates/ScrollBar.template | 6 | ||||
| -rwxr-xr-x | Templates/Spinner.template | 4 | ||||
| -rw-r--r-- | Tests/BasicTests.cs | 6 | ||||
| -rwxr-xr-x | Tests/Interfaces/Divers/0.crow | 4 | ||||
| -rw-r--r-- | src/BubblingMouseButtonEventArgs.cs | 3 | ||||
| -rw-r--r-- | src/GraphicObjects/CheckBox.cs | 4 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 11 | ||||
| -rw-r--r-- | src/GraphicObjects/RadioButton.cs | 4 | ||||
| -rw-r--r-- | src/Interface.cs | 59 | ||||
| -rw-r--r-- | src/Measure.cs | 6 |
12 files changed, 74 insertions, 37 deletions
diff --git a/Crow.csproj b/Crow.csproj index d05f2ae6..b340d9e4 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -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> diff --git a/Templates/Expandable.template b/Templates/Expandable.template index c5dd1d83..a36958d5 100755 --- a/Templates/Expandable.template +++ b/Templates/Expandable.template @@ -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 diff --git a/Templates/ScrollBar.template b/Templates/ScrollBar.template index c2b9a1ba..3c67bfa7 100755 --- a/Templates/ScrollBar.template +++ b/Templates/ScrollBar.template @@ -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 diff --git a/Templates/Spinner.template b/Templates/Spinner.template index dd957d25..60d7ccf9 100755 --- a/Templates/Spinner.template +++ b/Templates/Spinner.template @@ -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> diff --git a/Tests/BasicTests.cs b/Tests/BasicTests.cs index 9327a112..3bfd16e8 100644 --- a/Tests/BasicTests.cs +++ b/Tests/BasicTests.cs @@ -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); diff --git a/Tests/Interfaces/Divers/0.crow b/Tests/Interfaces/Divers/0.crow index 42900792..055b037e 100755 --- a/Tests/Interfaces/Divers/0.crow +++ b/Tests/Interfaces/Divers/0.crow @@ -58,11 +58,15 @@ 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}" diff --git a/src/BubblingMouseButtonEventArgs.cs b/src/BubblingMouseButtonEventArgs.cs index 74939620..e81a6f74 100644 --- a/src/BubblingMouseButtonEventArgs.cs +++ b/src/BubblingMouseButtonEventArgs.cs @@ -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){} + } } diff --git a/src/GraphicObjects/CheckBox.cs b/src/GraphicObjects/CheckBox.cs index 3a6b2b6a..646a8577 100644 --- a/src/GraphicObjects/CheckBox.cs +++ b/src/GraphicObjects/CheckBox.cs @@ -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); } } } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index f0e8a04d..aca7032e 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -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 diff --git a/src/GraphicObjects/RadioButton.cs b/src/GraphicObjects/RadioButton.cs index ead332ea..4c553481 100644 --- a/src/GraphicObjects/RadioButton.cs +++ b/src/GraphicObjects/RadioButton.cs @@ -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 diff --git a/src/Interface.cs b/src/Interface.cs index 0142f96a..e1bd7533 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -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++; diff --git a/src/Measure.cs b/src/Measure.cs index 352ce8ff..c88038c6 100644 --- a/src/Measure.cs +++ b/src/Measure.cs @@ -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; |