]> O.S.I.I.S - jp/crow.git/commitdiff
scroller x, ide wip
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 14 Mar 2018 20:42:59 +0000 (21:42 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 14 Mar 2018 20:42:59 +0000 (21:42 +0100)
13 files changed:
Templates/ComboBox.template
Templates/FileDialog.template
Templates/ListBox.template
Templates/ScrollingListBox.template
Templates/TreeView.template
Tests/Interfaces/Divers/clip4.crow
Tests/Interfaces/Divers/welcome.crow
Tests/Interfaces/TemplatedControl/testItemTemplateTag.crow
Tests/Interfaces/Wrapper/2.2.crow
Tests/ui/showcase.crow
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Scroller.cs
src/GraphicObjects/Slider.cs

index aed500aba15220c710b1faa7be4ff5e12c0cc766..7b7e8392a5e3429a56a595a0e042f787090cad56 100755 (executable)
@@ -18,7 +18,7 @@
        </Template>
        <Border Background="DimGray" BorderWidth="1" Margin="1"
                MinimumSize="{../../MinimumPopupSize}" Fit="true">
-               <Scroller Name="scroller1" Margin="2" VerticalScrolling="true"
+               <Scroller Name="scroller1" Margin="2" 
                        MaximumSize="0,200"
                        HorizontalAlignment="Left">
                        <VerticalStack
index e508b3d74d3432e97abf5216419714913a563b32..6fae49c5992cf07cc0a24225910926172845a565 100644 (file)
@@ -32,8 +32,7 @@
                                                        SelectedItemChanged="./onSelectedItemChanged">
                                                        <Template>
                                                                <HorizontalStack>
-                                                                       <Scroller ScrollX="{../scrollbar1.Value}"  Name="scroller1"
-                                                                               VerticalScrolling="true" HorizontalScrolling="false">
+                                                                       <Scroller ScrollX="{../scrollbar1.Value}"  Name="scroller1">
                                                                                <VerticalStack Height="Fit" VerticalAlignment="Top"
                                                                                        Name="ItemsContainer" Margin="0" Spacing="1"/>
                                                                        </Scroller>
index f6d6214db11bfd5b41d1069e33dcef9f2c05041e..a1aea50ff52d703a0386e411ca3411ab6361c9ab 100755 (executable)
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <Border BorderWidth="1" Margin="1" MinimumSize="10,10">
-       <Scroller  Name="scroller1" Margin="1" VerticalScrolling="true">
+       <Scroller  Name="scroller1" Margin="1" >
                <VerticalStack
                        Height="Fit" Name="ItemsContainer" Margin="0" VerticalAlignment="Top"/>
        </Scroller>
index 56b08c037b6d163b04b9076a33d7c7896d866d88..3b098df28c63a30bf653a7cf22113a9647610c65 100644 (file)
@@ -2,7 +2,7 @@
 <Border BorderWidth="1" Background="{./Background}">
        <HorizontalStack Margin="1">
                <Scroller Name="scroller1" 
-                               Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}">
+                               Margin="2" ScrollY="{../scrollbar1.Value}">
                        <VerticalStack Height="Fit" MinimumSize="10,10"
                                Name="ItemsContainer" Margin="0" VerticalAlignment="Top"/>
                </Scroller>
index a1d9bc7237d093463d783599bef2d13cd3c6b015..31514fce05d70cb508a20599da0efff145a5d4b0 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <HorizontalStack>
-       <Scroller  Name="scroller1" Margin="1" VerticalScrolling="true"
+       <Scroller  Name="scroller1" Margin="1"
                Background="{./Background}"
                ScrollY="{../scrollbar1.Value}">
                <VerticalStack
index 69fc7f12f7130a4a04c056cd30e33f0999793cff..852a4e879391efa431d14f0db0cf4be1c85aa878 100755 (executable)
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <Border Fit="true" BorderWidth="2"  >
-<Scroller CornerRadius="2" VerticalScrolling="true" Height="200" Width="300" Background="DimGray" Margin="2">
+<Scroller CornerRadius="2" Height="200" Width="300" Background="DimGray" Margin="2">
        <VerticalStack Margin="10" VerticalAlignment="Top" Fit="true" Background="vgradient|0:BlueCrayola|1:Black" >
                 <Label MouseEnter="{Background=Gray}" MouseLeave="{Background=hgradient|0:DarkRed|1:Transparent}" Margin="5" Background="hgradient|0:DarkRed|1:Transparent" Font="droid,20" Text="label 1"/>
                 <Label MouseEnter="{Background=Gray}" MouseLeave="{Background=hgradient|0:DarkRed|1:Transparent}" Margin="5" Background="hgradient|0:DarkRed|1:Transparent" Font="droid,20" Text="label 2"/>
index 22dfd7490d5b9074f2aaabbf90aa89bffae3979f..3445ef1c657ac2c536bdf4260176429abed480c0 100644 (file)
@@ -1,21 +1,2 @@
 <?xml version="1.0"?>
-<Border BorderStyle="Sunken" Fit="true" Background="0.7,0.7,0.7,0.5" CornerRadius="10">
-       <VerticalStack Margin="20">
-               <Image Path="#Crow.Images.Icons.crow.svg"/>
-<!--           <Label Font="Times bold, 60" Text="C.R.O.W"/>-->
-               <HorizontalStack Fit="true" DataSource="{CrowVersion}" Spacing="0">
-                       <Label Foreground="Black" Font="mono, 12" Text="version: "/>            
-                       <Label Foreground="Black" Font="mono, 12" Text="{Major}"/>              
-                       <Label Foreground="Black" Font="mono, 12" Text="."/>
-                       <Label Foreground="Black" Font="mono, 12" Text="{Minor}"/>
-                       <Label Foreground="Black" Font="mono, 12" Text="."/>
-                       <Label Foreground="DimGray" Font="mono, 12" Text="{Build}"/>
-               </HorizontalStack>
-               <GraphicObject Height="30"/>
-               <Label Font="20" Text="Press &lt;F2&gt; and &lt;F3&gt; to cycle into the examples"/>
-               <Label Font="20" Text="Those are basic tests used to validate changes,"/>
-               <GraphicObject Height="30"/>
-               <Label Foreground="DimGray" Font="20" Text="&lt;F5&gt; => File dialog example"/>
-               <Label Foreground="DimGray" Font="20" Text="&lt;F6&gt; => Window example"/>
-       </VerticalStack>
-</Border>
\ No newline at end of file
+<GraphicObject Height="30" Width="30" Background="#500000"/>
\ No newline at end of file
index 54ccde153452b802ec4e0b4862d8d1f96b2c9099..90c475a5b518e7ff4cfa41c2e8b15895e5054cb9 100755 (executable)
@@ -7,7 +7,7 @@
                                <Border BorderWidth="1">
                                        <HorizontalStack Margin="1">
                                                <Scroller Name="scroller1" 
-                                                               Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}">
+                                                               Margin="2" ScrollY="{../scrollbar1.Value}">
                                                        <VerticalStack Height="Fit" MinimumSize="10,10"
                                                                Name="ItemsContainer" Margin="0" VerticalAlignment="Top"/>
                                                </Scroller>
index ceeae253df19ec1f9f78727a21085c551b718017..246a937dd73d3d55f3fffb3dccf30f694bfc2c68 100755 (executable)
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <Window Caption="Horizontal Wrapper" Width="50%" Height="50%">
        <VerticalStack Margin="1">
-               <Scroller Name="scroller1" ScrollX="{../scrollbar1.Value}" VerticalScrolling="False" HorizontalScrolling="true" Margin="1" Background="BlueCrayola">
+               <Scroller Name="scroller1" ScrollX="{../scrollbar1.Value}" Margin="1" Background="BlueCrayola">
                        <Wrapper HorizontalAlignment="Left" Orientation="Horizontal" Height="100%" Width="Fit" Margin="0" Background="MediumSeaGreen" Spacing="1" >
                                <GraphicObject Width="50" Height="50" Background="SeaGreen"/>
                                <GraphicObject Width="50" Height="50" Background="SeaGreen"/>
index bfb234ad6148c627db302dfa22ef26b0232084d6..61df4443bd8aeb0d9c521a317be9c8737107a268 100755 (executable)
@@ -7,7 +7,7 @@
                <Splitter/>
                <HorizontalStack>
                        <Scroller Name="scroller1" Background="White"
-                                       Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}"
+                                       Margin="2" ScrollY="{../scrollbar1.Value}"
                                        ValueChanged="./_scroller_ValueChanged">
                                <TextBox VerticalAlignment="Top" TextChanged="Tb_TextChanged"
                                        Text="{source}" Multiline="true" TextAlignment="TopLeft"
index 2ca07975b0c4373dd700c40471c77f0a7b6cc9d2..2533fb1b74d0fe34d4b57335d9c3468da1d21041 100644 (file)
@@ -1020,13 +1020,16 @@ namespace Crow
                        if (!string.IsNullOrEmpty (Style)) {
                                if (IFace.DefaultValuesLoader.ContainsKey (Style)) {
                                        IFace.DefaultValuesLoader [Style] (this);
+                                       onInitialized (this, null);
                                        return;
                                }
                        } else if (IFace.DefaultValuesLoader.ContainsKey (thisType.FullName)) {
                                IFace.DefaultValuesLoader [thisType.FullName] (this);
+                               onInitialized (this, null);
                                return;
                        } else  if (IFace.DefaultValuesLoader.ContainsKey (thisType.Name)) {
                                IFace.DefaultValuesLoader [thisType.Name] (this);
+                               onInitialized (this, null);
                                return;
                        }
 
index 397d7de03a9d27d9e20d9ada30fdb8c6deb9afed..30dd14800c2d4a05e15d2ae4760c5bba90611c3e 100644 (file)
@@ -42,160 +42,159 @@ namespace Crow
                public Scroller (Interface iface) : base(iface){}
                #endregion
 
-               bool _verticalScrolling;
-               bool _horizontalScrolling;
-               bool _scrollbarVisible;
-               int _scrollX = 0;
-               int _scrollY = 0;
-               int scrollSpeed;
-
                public event EventHandler<ScrollingEventArgs> Scrolled;
 
+               int scrollX, scrollY, maxScrollX, maxScrollY, scrollSpeed;
+
+               /// <summary>
+               /// if true, key stroke are handled in derrived class
+               /// </summary>
+               protected bool KeyEventsOverrides = false;
+
                #region public properties
-               [XmlAttributeAttribute][DefaultValue(true)]
-               public bool VerticalScrolling {
-                       get { return _verticalScrolling; }
-                       set { _verticalScrolling = value; }
-               }
+               /// <summary> Horizontal Scrolling Position </summary>
+               [XmlAttributeAttribute][DefaultValue(0)]
+               public virtual int ScrollX {
+                       get { return scrollX; }
+                       set {
+                               if (scrollX == value)
+                                       return;
 
-               [XmlAttributeAttribute][DefaultValue(false)]
-        public bool HorizontalScrolling {
-                       get { return _horizontalScrolling; }
-                       set { _horizontalScrolling = value; }
-               }
-               [XmlAttributeAttribute][DefaultValue(true)]
-               public bool ScrollbarVisible {
-                       get { return _scrollbarVisible; }
-                       set { _scrollbarVisible = value; }
+                               int newS = value;
+                               if (newS < 0)
+                                       newS = 0;
+                               else if (newS > maxScrollX)
+                                       newS = maxScrollX;
+
+                               if (newS == scrollX)
+                                       return;
+
+                               scrollX = value;
+
+                               NotifyValueChanged ("ScrollX", scrollX);
+                               RegisterForGraphicUpdate ();
+                       }
                }
+               /// <summary> Vertical Scrolling Position </summary>
                [XmlAttributeAttribute][DefaultValue(0)]
-               public int ScrollX {
-                       get {
-                               return _scrollX;
-                       }
+               public virtual int ScrollY {
+                       get { return scrollY; }
                        set {
-                               if (_scrollX == value)
+                               if (scrollY == value)
                                        return;
-                               if (value < 0)
-                                       _scrollX = 0;
-                               else if (value > Child.Slot.Width - ClientRectangle.Width)
-                                       _scrollX = Math.Max(0, Child.Slot.Width - ClientRectangle.Width);
-                               else
-                                       _scrollX = value;
-                               NotifyValueChanged("ScrollX", _scrollX);
-                               RegisterForRedraw ();
-                               Scrolled.Raise (this, new ScrollingEventArgs (Orientation.Horizontal));
+
+                               int newS = value;
+                               if (newS < 0)
+                                       newS = 0;
+                               else if (newS > maxScrollY)
+                                       newS = maxScrollY;
+
+                               if (newS == scrollY)
+                                       return;
+
+                               scrollY = value;
+
+                               NotifyValueChanged ("ScrollY", scrollY);
+                               RegisterForGraphicUpdate ();
                        }
                }
+               /// <summary> Horizontal Scrolling maximum value </summary>
                [XmlAttributeAttribute][DefaultValue(0)]
-               public int ScrollY {
-                       get {
-                               return _scrollY;
-                       }
+               public virtual int MaxScrollX {
+                       get { return maxScrollX; }
                        set {
-                               if (_scrollY == value)
+                               if (maxScrollX == value)
                                        return;
-                               if (value < 0)
-                                       _scrollY = 0;
-                               else if (value > Child.Slot.Height - ClientRectangle.Height)
-                                       _scrollY = Math.Max(0,Child.Slot.Height - ClientRectangle.Height);
-                               else
-                                       _scrollY = value;
-                               NotifyValueChanged("ScrollY", _scrollY);
-                               RegisterForRedraw ();
-                               Scrolled.Raise (this, new ScrollingEventArgs (Orientation.Vertical));
+
+                               maxScrollX = value;
+
+                               if (scrollX > maxScrollX)
+                                       ScrollX = maxScrollX;
+
+                               NotifyValueChanged ("MaxScrollX", maxScrollX);
+                               RegisterForGraphicUpdate ();
                        }
                }
+               /// <summary> Vertical Scrolling maximum value </summary>
+               [XmlAttributeAttribute][DefaultValue(0)]
+               public virtual int MaxScrollY {
+                       get { return maxScrollY; }
+                       set {
+                               if (maxScrollY == value)
+                                       return;
+
+                               maxScrollY = value;
+
+                               if (scrollY > maxScrollY)
+                                       ScrollY = maxScrollY;
 
-               [XmlIgnore]
-               public int MaximumScroll {
-                       get {
-                               try {
-                                       return VerticalScrolling ?
-                                               Math.Max(Child.Slot.Height - ClientRectangle.Height,0) :
-                                               Math.Max(Child.Slot.Width - ClientRectangle.Width,0);
-                               } catch {
-                                       return 0;
-                               }
+                               NotifyValueChanged ("MaxScrollY", maxScrollY);
+                               RegisterForGraphicUpdate ();
                        }
                }
-
-               [XmlAttributeAttribute][DefaultValue(30)]
-               public int ScrollSpeed {
+               /// <summary> Mouse Wheel Scrolling multiplier </summary>
+               [XmlAttributeAttribute][DefaultValue(50)]
+               public virtual int ScrollSpeed {
                        get { return scrollSpeed; }
                        set {
+                               if (scrollSpeed == value)
+                                       return;
+
                                scrollSpeed = value;
-                               NotifyValueChanged("ScrollSpeed", scrollSpeed);
+
+                               NotifyValueChanged ("ScrollSpeed", scrollSpeed);
                        }
                }
                #endregion
 
-               #region GraphicObject Overrides
-               public override void OnLayoutChanges (LayoutingType layoutType)
+               public override void SetChild (GraphicObject _child)
                {
-                       base.OnLayoutChanges (layoutType);
+                       Group g = child as Group;
+                       if (g != null)
+                               g.ChildrenCleared -= onChildListCleared;
+                       
+                       base.SetChild (_child);
 
-                       NotifyValueChanged("MaximumScroll", MaximumScroll);
-                       if (layoutType == LayoutingType.Height) {
-                               NotifyValueChanged ("PageHeight", Slot.Height);
-                               if (child?.Slot.Height > 0)
-                                       NotifyValueChanged ("ChildHeightRatio", Slot.Height * Slot.Height / child.Slot.Height);
-                       } else {
-                               NotifyValueChanged ("PageWidth", Slot.Width);
-                               if (child?.Slot.Width > 0)
-                                       NotifyValueChanged ("ChildWidthRatio", Slot.Width * Slot.Width / child.Slot.Width);
-                       }
+                       g = _child as Group;
+                       if (g != null)
+                               g.ChildrenCleared += onChildListCleared;                        
                }
-               void OnChildLayoutChanges (object sender, LayoutingEventArgs arg)
+               public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg)
                {
-                       //Debug.WriteLine ("scroller childLayoutChanges");
-                       int maxScroll = MaximumScroll;
-                       //Debug.WriteLine ("maxscroll={0}", maxScroll);
-                       if (_verticalScrolling) {
-                               if (arg.LayoutType == LayoutingType.Height) {
-                                       if (maxScroll < ScrollY) {
-                                               //Debug.WriteLine ("scrolly={0} maxscroll={1}", ScrollY, maxScroll);
-                                               ScrollY = maxScroll;
-                                       }
-                                       NotifyValueChanged("MaximumScroll", maxScroll);
-                                       if (child?.Slot.Height > 0)
-                                               NotifyValueChanged ("ChildHeightRatio", Slot.Height * Slot.Height / child.Slot.Height);
-                               }
-                       } else if (arg.LayoutType == LayoutingType.Width) {
-                               if (maxScroll < ScrollX) {
-                                       //Debug.WriteLine ("scrolly={0} maxscroll={1}", ScrollY, maxScroll);
-                                       ScrollX = maxScroll;
-                               }
-                               NotifyValueChanged("MaximumScroll", maxScroll);
-                               if (child?.Slot.Width > 0)
-                                       NotifyValueChanged ("ChildWidthRatio", Slot.Width * Slot.Width / child.Slot.Width);
-                       }
+                       base.OnChildLayoutChanges (sender, arg);
+                       updateMaxScroll (arg.LayoutType);
                }
-               void onChildListCleared(object sender, EventArgs e){
-                       ScrollY = 0;
-                       ScrollX = 0;
+
+
+               #region GraphicObject Overrides
+               public override Rectangle ScreenCoordinates (Rectangle r)
+               {
+                       return base.ScreenCoordinates (r) - new Point((int)ScrollX,(int)ScrollY);
                }
-               public override void SetChild (GraphicObject _child)
+               public override bool PointIsIn (ref Point m)
                {
-                       GraphicObject c = child as GraphicObject;
-                       Group g = child as Group;
-                       if (c != null) {
-                               c.LayoutChanged -= OnChildLayoutChanges;
-                               if (g != null)
-                                       g.ChildrenCleared -= onChildListCleared;
-                       }
-                       c = _child as GraphicObject;
-                       g = _child as Group;
-                       if (c != null) {
-                               c.LayoutChanged += OnChildLayoutChanges;
-                               if (g != null)
-                                       g.ChildrenCleared += onChildListCleared;
-                       }
-                       base.SetChild (_child);
+                       if (!base.PointIsIn(ref m))
+                               return false;
+                       if (!Slot.ContainsOrIsEqual (m) || child==null)
+                               return false;
+                       m += new Point (ScrollX, ScrollY);
+                       return true;
                }
-               public override Rectangle ScreenCoordinates (Rectangle r)
+               public override void RegisterClip (Rectangle clip)
                {
-                       return base.ScreenCoordinates (r) - new Point((int)ScrollX,(int)ScrollY);
+                       base.RegisterClip (clip - new Point(ScrollX,ScrollY));
+               }
+               public override void OnLayoutChanges (LayoutingType layoutType)
+               {
+                       base.OnLayoutChanges (layoutType);
+
+                       if (layoutType == LayoutingType.Height)
+                               NotifyValueChanged ("PageHeight", Slot.Height);
+                       else if (layoutType == LayoutingType.Width)
+                               NotifyValueChanged ("PageWidth", Slot.Width);
+                       else
+                               return;
+                       updateMaxScroll(layoutType);
                }
                protected override void onDraw (Context gr)
                {
@@ -218,50 +217,75 @@ namespace Crow
                        gr.Restore ();
                }
 
-               #region Mouse handling
-               //internal Point savedMousePos;
-
-               public override bool PointIsIn (ref Point m)
-               {
-                       if (!base.PointIsIn(ref m))
-                               return false;
-                       if (!Slot.ContainsOrIsEqual (m) || child==null)
-                               return false;
-                       m += new Point (ScrollX, ScrollY);
-                       return true;
-               }
-//             public override bool MouseIsIn (Point m)
-//             {
-//                     return Visible ? base.ScreenCoordinates(Slot).ContainsOrIsEqual (m) : false;
-//             }
-//             public override void checkHoverWidget (MouseMoveEventArgs e)
-//             {
-//                     savedMousePos = e.Position;
-//                     Point m = e.Position - new Point (ScrollX, ScrollY);
-//                     base.checkHoverWidget (new MouseMoveEventArgs(m.X,m.Y,e.XDelta,e.YDelta));
-//             }
+               #region Mouse & Keyboard
+               /// <summary> Process scrolling vertically, or if shift is down, vertically </summary>
                public override void onMouseWheel (object sender, MouseWheelEventArgs e)
                {
-                       if (Child == null)
-                               return;
-
-                       if (VerticalScrolling )
+                       base.onMouseWheel (sender, e);
+                       if (IFace.Keyboard.IsKeyDown (Key.ShiftLeft))
+                               ScrollX += e.Delta * ScrollSpeed;
+                       else
                                ScrollY -= e.Delta * ScrollSpeed;
-                       if (HorizontalScrolling )
-                               ScrollX -= e.Delta * ScrollSpeed;
                }
-//             public override void onMouseMove (object sender, MouseMoveEventArgs e)
-//             {
-//                     savedMousePos.X += e.XDelta;
-//                     savedMousePos.Y += e.YDelta;
-//                     base.onMouseMove (sender, new MouseMoveEventArgs(savedMousePos.X,savedMousePos.Y,e.XDelta,e.YDelta));
-//             }
-               public override void RegisterClip (Rectangle clip)
+               /// <summary> Process scrolling with arrow keys, home and end keys. </summary>
+               public override void onKeyDown (object sender, KeyboardKeyEventArgs e)
                {
-                       base.RegisterClip (clip - new Point(ScrollX,ScrollY));
+                       base.onKeyDown (sender, e);
+
+                       if (KeyEventsOverrides)
+                               return;
+
+                       switch (e.Key) {
+                       case Key.Up:
+                               ScrollY--;
+                               break;
+                       case Key.Down:
+                               ScrollY++;
+                               break;
+                       case Key.Left:
+                               ScrollX--;
+                               break;
+                       case Key.Right:
+                               ScrollX++;
+                               break;
+                       case Key.Home:
+                               ScrollX = 0;
+                               ScrollY = 0;
+                               break;
+                       case Key.End:
+                               ScrollX = MaxScrollX;
+                               ScrollY = MaxScrollY;
+                               break;
+                       }
                }
                #endregion
 
                #endregion
+
+               void updateMaxScroll (LayoutingType lt){
+                       if (Child == null) {
+                               MaxScrollX = 0;
+                               MaxScrollY = 0;
+                               return;
+                       }
+
+                       Rectangle cb = ClientRectangle;
+
+                       if (lt == LayoutingType.Height) {
+                               MaxScrollY = child.Slot.Height - cb.Height;
+                               if (child.Slot.Height > 0)
+                                       NotifyValueChanged ("ChildHeightRatio", Slot.Height * Slot.Height / child.Slot.Height);                 
+                       } else if (lt == LayoutingType.Width) {
+                               MaxScrollX = child.Slot.Width - cb.Width;
+                               if (child.Slot.Width > 0)
+                                       NotifyValueChanged ("ChildWidthRatio", Slot.Width * Slot.Width / child.Slot.Width);
+                       }
+               }
+               void onChildListCleared(object sender, EventArgs e){
+                       ScrollY = 0;
+                       ScrollX = 0;
+               }
+
+
     }
 }
index 4492c40676e50d2b64f6783eeef6f0d310423760..2bdd5b8ab0c2c8e5693ea39f30384152e19464e8 100644 (file)
@@ -186,16 +186,24 @@ namespace Crow
                        }
                        cursor.Inflate (-1);
         }
-        
+               Point mouseDownInit;
+               double mouseDownInitValue;
+
                #region mouse handling
                public override void onMouseDown (object sender, MouseButtonEventArgs e)
                {
                        base.onMouseDown (sender, e);
-
+                       mouseDownInit = ScreenPointToLocal (e.Position);
+                       mouseDownInitValue = Value;
                        Rectangle cursInScreenCoord = ScreenCoordinates (cursor + Slot.Position);
-                       if (cursInScreenCoord.ContainsOrIsEqual (e.Position))
+                       if (cursInScreenCoord.ContainsOrIsEqual (e.Position)){
+//                             Rectangle r = ClientRectangle;
+//                             if (r.Width - _cursorSize > 0) {
+//                                     double unit = (Maximum - Minimum) / (double)(r.Width - _cursorSize);
+//                                     mouseDownInit += new Point ((int)(Value / unit), (int)(Value / unit));
+//                             }
                                holdCursor = true;
-                       else if (_orientation == Orientation.Horizontal) {
+                       }else if (_orientation == Orientation.Horizontal) {
                                if (e.Position.X < cursInScreenCoord.Left)
                                        Value -= LargeIncrement;
                                else
@@ -216,26 +224,24 @@ namespace Crow
                public override void onMouseMove (object sender, MouseMoveEventArgs e)
                {
                        if (holdCursor) {                               
-                               Point m = ScreenPointToLocal (e.Position);
+                               Point m = ScreenPointToLocal (e.Position) - mouseDownInit;
                                Rectangle r = ClientRectangle;
 
                                if (_orientation == Orientation.Horizontal) {
                                        if (r.Width - _cursorSize == 0)
                                                return;                                 
                                        double unit = (Maximum - Minimum) / (double)(r.Width - _cursorSize);
-                                       double tmp = (double)m.X * unit;
+                                       double tmp = mouseDownInitValue + (double)m.X * unit;
                                        tmp -= tmp % SmallIncrement;
                                        Value = tmp;
                                } else {
                                        if (r.Height - _cursorSize == 0)
                                                return;                                 
                                        double unit = (Maximum - Minimum) / (double)(r.Height - _cursorSize);
-                                       double tmp = (double)m.Y * unit;
+                                       double tmp = mouseDownInitValue + (double)m.Y * unit;
                                        tmp -= tmp % SmallIncrement;
                                        Value = tmp;
                                }
-
-
                        }
                        
                        base.onMouseMove (sender, e);