New topic: mouseUP detection on a slider control
<http://forums.realsoftware.com/viewtopic.php?t=34205> Page 1 of 1 [ 3 posts ] Previous topic | Next topic Author Message Barrie Post subject: mouseUP detection on a slider controlPosted: Wed Jun 09, 2010 6:46 pm Joined: Wed Nov 07, 2007 4:18 pm Posts: 27 Location: Ottawa, Canada When using the slider control, the mouseUp event only fires if mouseDown returns true. However, when mouseDown returns true, the slider cannot be moved. I want to move the slider and also detect when I stop sliding the slider (the mouseUp event). How can this be achieved? About a year ago, someone asked this same question on this forum which was answered by Karen who suggested the use of a timer. This sounds a bit complicated. Is this still the best solution? If so, please post the code. Thanks Barrie _________________ >From Barrie Jones Mac OSX 10.5.8: RS 2010 r1: Top wbgookin Post subject: Re: mouseUP detection on a slider controlPosted: Wed Jun 09, 2010 8:03 pm Joined: Sat Aug 22, 2009 9:44 am Posts: 105 Put "return true" in the mousedown event. In mousedrag, put: me.Value = (me.Maximum - me.Minimum) * x / me.Width Then your slider will move when you drag it, and your mouseup will fire too. Note, this seems to be close but not quite correct...as I slide from left to right the slider doesn't QUITE track with the pointer. Perhaps me.width isn't the right value (are there borders or something?). Anyway, it's hopefully a start. Bill Top Karen Post subject: Re: mouseUP detection on a slider controlPosted: Wed Jun 09, 2010 9:36 pm Joined: Fri Sep 30, 2005 8:53 am Posts: 773 http://mysite.verizon.net/vzezdg8x/sitebuildercontent/sitebuilderfiles/UltimateSlider2_RBP.zip -------------------------------------------------------------------- Ultimate Slider 2.0 -------------------------------------------------------------------- This Slider Subclass is a re-write of code I wrote and released almost 7 years ago when I was new to RB. It's main purpose was to provide an event that signaled the end of moving the thumb during LiveScroll, something the RB slider does not support. This useful when you wish to give the user some live numeric or visual feedback of the slider's current value but performing a final action that takes too long to perform while the user is actually moving the slider. Way back 7 years ago then were no ContainerControls and so that old subclass does not play nice with them. It also used old style constructors as well as having a few obscure bugs too ... Also back then I had never had a PC on my desk at work (always a Mac) and had Macs at home... So I never even though about handling changing slider values with the arrow keys and RB did not have support for MouseWheels back then either IIRC. So needing the class myself, I dusted it off, redesigned the code, added some features and fixed some bugs. So here is the UltimateSlider 2.0! It's Ultimate ONLY in the sense that I could not think of any more features that were easy to add! This version provides a ChangeFinished event that is called when the Mouse button is released after dragging the thumb. This event should not break any existing code as for a "dead" scroll (LiveScrollChangeFinshed = false), the ValueChanged event is still called normally, and then the ChangedFinished event immediately afterwards. That event order ensures the same code would work for both live and "dead" scrolls. This class also supports using the MouseWheel to change the slider value on all platforms (it's not normally supported on the Mac in the RB Framework). Also now holding the shiftkey down when the arrow key are pressed when the slider has the focus results in PageSteps instead of LineSteps for the delta. The Big change with mousewheel support is that the ChangeFinished event will also fire when user stop moving the MouseWheel for a set time period, unless you turn it off. For the keyboard as i mentioned above, this also supports using the arrow keys to change the slider value on all platforms as normal if it has the focus (theoretically with full keyboard access turned on, a slider should be able to get the focus on a Mac). The new feature here is that the ChangeFinished event will fire when the stops hitting an arrow key for a specified time period as for the MouseWheel. Also holding th shiftkey down when the arrow keys are pressed results in PageSteps instead of LineSteps. The ChangeFinished event is fired from a timer subclass (mode 2, period 200 for dragging the thumb) which is passed a delegate (instead of an interface type) that is defined in the slider subclass. That routine checks if the mouse is still down. If not it fires the ChangeFinished event and shuts the timer down. For MouseWheel and Arrow Keys each time that event is called the timer is reset to prevent it from triggering. Both the ChangedFinished and ValueChanged Events include an initial value parameter (the value when the change was initiated). This allows an easy way to deal with deltas, or undoing the change. The ChangeFinished event also includes a boolean parameter to allow us to know if the mouse was released inside the control or not. It also includes a parameter to allow you to know if the value was set from a linked Display/entry control (see below), or by dragging the thumb, or using the MouseWheel or arrow keys, or just setting Slider.Value directly. Often time one has either a StaticText or editfield/textfield that displays the current numeric value of a the slider, and in the case of an editfield/textfield, allows the user to set the slider value numerically . It is also not unusual for displayed end user entered values to be in different units from the actual slider values, as Slider values must be integers and the end user units may be a real number. To deal with this the subclass has: 1) a method for setting the slider value using user units is supplied. This calls a new slider event to do the unit transform 2) A separate event from ValueChanged is supplied for updating the displaying of the current slider value in such linked value entry controls. A separate event from ValueChanged is provided to help keep code better organized and keep that logic separate from the action logic. In addition there is a setter method that ONLY fires the event to update the displayed value and not ValueChanged or ChangedFinished. Finally it provides a boolean property which when set allows the user to abort the change and have the slider value return to it's pre-change value by letting the MouseButton up outside of the control.AFAIK this type of functionality is normally only supported on OS X for LiveScroll = False (though buggy on RB2009R3) but maybe useful in all situations, thus this setting works for both live and "dead" scrolling for all platforms. One caveat however. For a LiveScroll on a Mac and all types on other platforms (at least XP), there is no visual indication of when the mouse is out of the acceptable drop area while dragging the thumb. The Drop area is defined as in the control or within 100 pixels of the control horizontally and within 20 pixels of the top and bottom of the rectControl vertically. For OS X (at least on 10.4) for a "Dead" scroll the thumb disappears when dragged out of the drop zone. -------------------------------------------------------------------- Ultimate Slider 2.0 -------------------------------------------------------------------- Requires REALBasic 2008R3 or later -------------------------------------------------------------------- Introduction -------------------------------------------------------------------- For live scrolling, this Slider allows you to execute a final action at the end of the "slide" when the mousebutton is released in it's ChangeFinished event. It will also (optionally) execute that event at the end of repeated pressing the arrow keys when the slider has the focus, or at the end of changing the slider value using the MouseWheel. For both the arrow keys and MouseWheel, holding down the shift key results in PageSteps instead of Linesteps . Incidentally it ensures mousewheel support on all platforms ( the RB slider control does not provide "automatic" support for that on the Mac - you need to add code to the mousewheel event) It also allows you to separately update linked value controls (see below) and UI Controls during a LiveScroll using the UpdateDisplayedValue and ValueChanged Events. This is useful when you wish to give the user live numerical feedback of the slider's position and perhaps show a simplified example while dragging, but the final action would take too long to perform while the user is moving the slider It also provides a mechanism where, if the linked numerical feedback control is an editfield/TextField or some other interactive control, the user can enter a numeric value into that control in user units, and have the slider update. This slider supports the concept of user units, and provides a defined mechanism for when the values displayed and/or entered by a user are different form those the slider uses internally (such as numbers with decimal places) It also supports the user aborting a drag if the user releases the mouse button sufficiently far enough out of the slider. -------------------------------------------------------------------- New/Modified Events: -------------------------------------------------------------------- ValueChanged(InitialValue as Integer, Source as Integer) Event fires whenever Slider value is changed EXCEPT when using the Set method InitialValue: Slider Value in slider (integer) units: Note: Value in User units obtained from DisplayValueInitial computed property Source: What caused the Change. Constants: SourceValueProperty (0): the slider value property was directly set SourceSlider (1): The user tried to change value by moving slider thumb SourceUserEntry (2): Changed by SetByUser method SourceMouseWheel (3): Changed By MouseWheel SourceKeyBoard (4): Changed by pressing arrow keys when has focus ------------- UserValueTransform(ByRef theValue as Double, ToUserValue as Boolean) Event Fires wherever translation is needed between user and slider units: the DisplayValue properties, SetByUser method, for UpdateDisplayedValue event theValue: value to be transformed ToUserValue: If True need to transform theValue from Slider units to user units If False need to transform thevalue from user units to slider units ------------- UpdateDisplayedValue(UserValue as Double) Event Fires when slider value changes. Meant for updating slider numeric display controls (such as a StaticText) and/or numeric slider value entry controls (such as an editfield/testfield) to display current slider value in user units. UserValue: Current slider value in user units ------------- ChangeFinished(InitialValue as integer, OutofBounds as Boolean, Source as integer) Fires when the process of changing the slider value is complete however it is done, except when using the Set method. InitialValue: Slider Value in slider (integer) units: Note: Value in User units obtained from DisplayValueInitial computed property OutofBounds: Dragging of slider thumb ends with mouse outside of the drop area The Drop area is defined as in the control bounds or within 100 pixels of the right and left sides and within 20 pixels of the top and bottom edges. Source: What caused the Change. Constants: SourceValueProperty (0): the slider value property was directly set SourceSlider (1): The user tried to change value by moving slider thumb SourceUserEntry (2): Changed by SetByUser method SourceMouseWheel (3): Changed By MouseWheel SourceKeyBoard (4): Changed by pressing arrow keys when has focus -------------------------------------------------------------------- New Public Methods -------------------------------------------------------------------- Set(Value as integer) Sets slider value without firing the ValueChanged or ChangedFinished Events The UpdateDisplayedValue is fired. Uses Slider units. ------------- SetByUser(value as Double) Allows you to set the value of the slider from a "linked" control. Meant for use with controls for the slider value is entered as number by the user in user units. It does not call the ValueChanged event to prevent an infinite loop but does call the MouseUp event which is always called after a LiveScroll is finished or when a value is changed with LiveScroll = False. Sets the property isLinkedUpdate to true so you know why MouseUp is being called -------------------------------------------------------------------- Public Properties: -------------------------------------------------------------------- AllowAbort as Boolean User Settable If true and while dragging the thumb, the user releases it outside the control, the slider is set to it's original value at mousedown. AFAIK this type of functionality is normally only supported on OS X for LiveScroll = False but maybe useful in all situations On Abort the ChangedFinshed and Update Events are always called. If LiveScroll = True then the ValueChanged is also called. For a LiveScroll on a Mac and Both types on Windows (at least XP) there is no visual indication of when the mouse is out of the acceptable drop area. The Drop area is defined as in the control or within 100 pixels of the control horizontally and within 20 pixels of the top and bottom of the rectControl vertically. For OS X (at least on 10.4) for a "Dead" scroll the thumb disappears when dragged out of the drop zone. As mentioned above, on OSX at least, in theory, using this property only makes sense only for a LiveScroll as the slider control is supposed to take care of this itself, hence the disapearing thumb. However as of RB009r3 there is a bug that causes it not to return to the correct initial value, so using this feature with LiveUpdate = false may be useful. ------------- EntryTimeOut As Integer Settable Sets the time in milliseconds between the last arrow key press or MouseWheel move and when the ChangeFinished event will fire. Default 650. A value <= 0 prevents the ChangeFinished event from firing for Arrow Keys and mousewheel changes only ------------- DisplayValue as Double Read only Returns the current slider value in user units ------------- DisplayValueInitial as Double Read only Returns the initial slider value in user units, unless in the ValueChanged or ChangeFinished will return Same value as DisplayValue Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 3 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
