[futurebasic] SlideRange

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 2001 : Group Archive : Group : All Groups

From: SVANVOORST@...
Date: Sun, 25 Nov 2001 10:35:19 EST
For those interested, the following code allows selection of a range of 
values by utilizing two slider controls:

'---------- Start FB^3 Code -----------
Include "Tlbx Appearance.Incl"

dim wndPtr as pointer
dim loSliderH as handle
dim hiSliderH as handle
dim hiSliderValue% as int
dim loSliderValue% as int
dim boxRect as rect
dim sliderRect as rect
end globals

local
dim err
LOCAL FN buildWnd
WINDOW#-1,"SlideRange.demo",(0,0)-(410,150),_docNoGrow
wndPtr = window(_wndPointer)
text _sysFont, 12, 0
edit field#1,,(300,17)-(325,32),_statFramed,_centerJust
edit field#2,,(300,70)-(325,85),_statFramed,_centerJust
err = FN 
SetThemeWindowBackground(wndPtr,_kThemeActiveDialogBackgroundBrush,_true)
edit field#3,"Hi Range",(330,17)-(395,32),_statNoFramed,_leftJust
edit field#4,"Lo Range",(330,70)-(395,85),_statNoFramed,_leftJust
setrect(sliderRect,18,20,283,45)'Adjust slider length to box length
hiSliderH = fn 
newcontrol(wndPtr,sliderRect,"",_true,25,0,24,_kControlSliderProc+2,65536*30)
offsetrect(sliderRect,0,38)
loSliderH = fn 
newcontrol(wndPtr,sliderRect,"",_true,25,0,24,_kControlSliderProc+6,65536*31)
button#35,_activeBtn,"Quit",(320,110)-(380,130),_shadow
setctlvalue(hiSliderH,hiSliderValue%)
setctlvalue(loSliderH,loSliderValue%)
edit$(1) = str$(hiSliderValue%)
edit$(2) = str$(loSliderValue%)
window#1
END FN

local
dim factor% as int
dim offset% as int
local fn fillBox
pen ,,,,0
color _zRed
eraseRect(boxRect)'Erase old range
factor% = (sliderRect.right%-sliderRect.left%)/25'Slider length/#tick marks
offset% = sliderRect.left%+12
setrect(boxRect,loSliderValue%*factor%+offset%,45,hiSliderValue%*factor%+offse

t%+2,58)
paintrect(boxRect)'Draw new range
color _zBlack
end fn

local
dim evnt%
dim id%
dim err
LOCAL FN doDialog
evnt% = DIALOG(0)
id% = DIALOG(evnt)
SELECT evnt%
case _wndRefresh
fn fillBox
for id% = 1 to 2
err = fn drawthemeedittextframe(#[tehandle(id%)],_true)
next
case _btnClick
select id%
case 30'hiSlider btn
hiSliderValue% = fn getctlvalue(hiSliderH)
long if hiSliderValue% => loSliderValue%
fn fillBox
edit$(1) = str$(hiSliderValue%)
end if
case 31'loSlider btn
loSliderValue% = fn getctlvalue(loSliderH)
long if loSliderValue% <= hiSliderValue%
fn fillBox
edit$(2) = str$(loSliderValue%)
end if
case 35
end
end select
CASE _wndClose
END
END SELECT
END FN

hiSliderValue% = 15
loSliderValue% = 10
FN buildWnd
ON DIALOG FN doDialog
DO
HANDLEEVENTS
UNTIL 0

'-------- End of Code --------

Toolboxes require "CALL" should not be checked (Edit/Preferences/Compiler).

Steve Van Voorst