PDA

View Full Version : Sample: Slider Framework


Worm
02-28-2006, 01:39 PM
This is a spin-off of the Splitter Framework and uses the same conventions.

This framework will let you use objects as sliders. There are two object to each slider, the Slider Background (Named: vslider_YourObjectName) or hslider_YourObjectName), and the Knob (Named: vknob_YourObjectName) or hknob_YourObjectName).

There is a custom event that will return the percentage the knob has traveled across the background object. The returned percentage can then be used to set volumes, move objects, set opacity, scroll pictures etc...

How to use:
1. Add these function calls to the following Page Events
On Show Event

--Initialize the sliders
InitSliders();


On Mouse Button

DoSlider_MouseButton(e_Type, e_X, e_Y);


On Mouse Move

DoSlider_MouseMove(e_X, e_Y);


2. Copy this code to your Global Functions

-- Custom event
function On_Slider_Move(sCurrentSlider, nPercent)
-- use this event to make change the values the slider
-- is related to
end


--[[************************************************** ******]]--
--[[ Set up a table to reference the objects in AMS ]]--
--[[************************************************** ******]]--
tbObjectType = {}
tbObjectType[OBJECT_BUTTON] = Button;
tbObjectType[OBJECT_LABEL] = Label;
tbObjectType[OBJECT_PARAGRAPH] = Paragraph;
tbObjectType[OBJECT_IMAGE] = Image;
tbObjectType[OBJECT_FLASH] = Flash;
tbObjectType[OBJECT_VIDEO] = Video;
tbObjectType[OBJECT_WEB] = Web;
tbObjectType[OBJECT_INPUT] = Input;
tbObjectType[OBJECT_HOTSPOT] = Hotspot;
tbObjectType[OBJECT_LISTBOX] = ListBox;
tbObjectType[OBJECT_COMBOBOX] = ComboBox;
tbObjectType[OBJECT_PROGRESS] = Progress;
tbObjectType[OBJECT_TREE] = Tree;
tbObjectType[OBJECT_PLUGIN] = Plugin;


-- Function to initialize the splitters with code to change the cursors
-- also initiates the table that holds the ratios for sizing objects
function InitSliders()
m_tblObjectData = {};
tblObjects = Page.EnumerateObjects();
end

-- Function to tell whether a point is in a given
-- objects rectangle
function IsInRect(m_nX, m_nY, m_tblPos, m_tblSize)
local bReturn = false;
if (m_nX >= m_tblPos.X) and (m_nX <= m_tblPos.X + m_tblSize.Width) then
if (m_nY >= m_tblPos.Y) and (m_nY <= m_tblPos.Y + m_tblSize.Height) then
bReturn = true;
end
end
return bReturn;
end

-- Function to detect when a slider has been selected
function DoSlider_MouseButton(e_Type, e_X, e_Y)
local bReturn = false;
local Object = nil;

if e_Type == LEFT_BUTTON_DOWN then
-- Get the objects on the page
tblObjects = Page.EnumerateObjects();
--if there are objects, and we are not currently moving a slider
if tblObjects and not m_blnMoveSlider then
for index, sObject in tblObjects do
--if the object is a splitter
if (String.Left(sObject, 6) == "vknob_") or (String.Left(sObject, 6) == "hknob_") then
--get the object type
Object = tbObjectType[Page.GetObjectType(sObject)];
--if our mouse pointer is inside of a slider rectangle
if IsInRect(e_X, e_Y, Object.GetPos(sObject), Object.GetSize(sObject)) then
if not m_blnMoveSlider then
--Get the initial Original Positions and Size
m_nOrigX = Object.GetPos(sObject).X;
m_nOrigY = Object.GetPos(sObject).Y;
m_nSplitterHeight = Object.GetSize(sObject).Height;
m_nSplitterWidth = Object.GetSize(sObject).Width;
end
--set the variables to allow the slider to move
m_blnMoveSlider = true;
m_sCurrentSlider = sObject;
m_XOffset = e_X - Object.GetPos(sObject).X;
m_YOffset = e_Y - Object.GetPos(sObject).Y;
break;
end
end
end
end
else
-- we're no longer on a slider, reset the variables that
-- allow the splitter to be moved.
m_blnMoveSlider = false;
end
end

-- Function to move the slider
function DoSlider_MouseMove(e_X, e_Y)
local z;

if not System.IsKeyDown(1) then
m_blnMoveSlider = false;
end

m_nDiff = 0;

if m_blnMoveSlider then
-- get the current slider's object type
local SliderObject = tbObjectType[Page.GetObjectType(m_sCurrentSlider)];

m_blnAllowMove = true;
if String.Left(m_sCurrentSlider, 6) == "hknob_" then
-- it's a vertical slider
if m_blnAllowMove then
m_sVolObjectName = String.Replace(m_sCurrentSlider, "hknob_", "hslider_", true);
local VolObject = tbObjectType[Page.GetObjectType(m_sVolObjectName)];
m_MaxX = (VolObject.GetPos(m_sVolObjectName).X + VolObject.GetSize(m_sVolObjectName).Width) - SliderObject.GetSize(m_sCurrentSlider).Width
m_MinX = VolObject.GetPos(m_sVolObjectName).X
if (e_X - m_XOffset) >= m_MaxX then
SliderObject.SetPos(m_sCurrentSlider, m_MaxX, SliderObject.GetPos(m_sCurrentSlider).Y);
elseif (e_X - m_XOffset) <= m_MinX then
SliderObject.SetPos(m_sCurrentSlider, m_MinX, SliderObject.GetPos(m_sCurrentSlider).Y);
else
-- Set the slider position
SliderObject.SetPos(m_sCurrentSlider, e_X - m_XOffset, SliderObject.GetPos(m_sCurrentSlider).Y);
end

-- get the value of pixels the slider was moved
m_nDiff = e_X - (m_nOrigX + m_XOffset);

-- set our sliders original position to the new position
m_nOrigX = m_nOrigX + m_nDiff;
end
m_Percent = Math.Floor(((SliderObject.GetPos(m_sCurrentSlider) .X - m_MinX) / (m_MaxX - m_MinX)) * 100)
elseif String.Left(m_sCurrentSlider, 6) == "vknob_" then
-- it's a Horizontal Slider
if m_blnAllowMove then
m_sVolObjectName = String.Replace(m_sCurrentSlider, "vknob_", "vslider_", true);
local VolObject = tbObjectType[Page.GetObjectType(m_sVolObjectName)];
m_MaxY = (VolObject.GetPos(m_sVolObjectName).Y + VolObject.GetSize(m_sVolObjectName).Height) - SliderObject.GetSize(m_sCurrentSlider).Height
m_MinY = VolObject.GetPos(m_sVolObjectName).Y
if (e_Y - m_YOffset) >= m_MaxY then
SliderObject.SetPos(m_sCurrentSlider, SliderObject.GetPos(m_sCurrentSlider).X ,m_MaxY);
elseif (e_Y - m_YOffset) <= m_MinY then
SliderObject.SetPos(m_sCurrentSlider, SliderObject.GetPos(m_sCurrentSlider).X, m_MinY );
else
-- Set the slider position
SliderObject.SetPos(m_sCurrentSlider, SliderObject.GetPos(m_sCurrentSlider).X, e_Y - m_YOffset);
end

-- get the value of pixels the slider was moved
m_nDiff = e_Y - (m_nOrigY + m_YOffset);
-- set our splitters original position to the new position
m_nOrigY = m_nOrigY + m_nDiff;
end
m_Percent = 100 - Math.Floor(((SliderObject.GetPos(m_sCurrentSlider) .Y - m_MinY) / (m_MaxY - m_MinY)) * 100)
end


-- fire event our own event
On_Slider_Move(m_sCurrentSlider, m_Percent);
end
end


3. Place your objects and name them accordingly

4. Use the custom event in the Global Functions to get the slider's position

rhosk
02-28-2006, 04:08 PM
Worm, you're on fire!! Thanks!

Intrigued
02-28-2006, 05:55 PM
When it comes to apples and oranges... man... this has nothing to do with them!

;)

But, this is swanky'ly'tifically'schwang'fine!

Nice one, again, Worm'inator.

:D

Worm
02-28-2006, 09:49 PM
Oops, just noticed I missed one of the Global Functions.

There is another that allows you to set the position by code. I'll post that tomorrow when I get back to my other PC.

Corey
02-28-2006, 09:51 PM
The other PC... Hmmm. Someone should do a short film about a guy who's work computer gets jealous of his home computer and sets about to eliminate it. T'would be good wotchin' methinks forsooth. :cool

Worm
03-02-2006, 02:07 PM
My work machine was so jealous, it made me "actually" have to work yesterday.

Throw this in your Global Functions. Use the knob_ object as the SliderName.


function SetSliderPos(sSliderName, nPercent)
local m_bReturn = false;
local SliderObject = tbObjectType[Page.GetObjectType(sSliderName)];

if String.Left(sSliderName, 6) == "hknob_" then
m_sVolObjectName = String.Replace(sSliderName, "hknob_", "hslider_", true);
local VolObject = tbObjectType[Page.GetObjectType(m_sVolObjectName)];
if VolObject then
m_nPos = Math.Floor((VolObject.GetSize(m_sVolObjectName).Wi dth - SliderObject.GetSize(sSliderName).Width) * (nPercent/100));
m_nPos = VolObject.GetPos(m_sVolObjectName).X + VolObject.GetSize(m_sVolObjectName).Width - m_nPos;
SliderObject.SetPos(sSliderName, m_nPos, SliderObject.GetPos(sSliderName).Y);
-- fire event our own event
On_Slider_Move(sSliderName, nPercent);
m_bReturn = true;
end
else
m_sVolObjectName = String.Replace(sSliderName, "vknob_", "vslider_", true);
local VolObject = tbObjectType[Page.GetObjectType(m_sVolObjectName)];
if VolObject then
m_nPos = Math.Floor((VolObject.GetSize(m_sVolObjectName).He ight - SliderObject.GetSize(sSliderName).Height) * (nPercent/100))
m_nPos = (VolObject.GetPos(m_sVolObjectName).Y + (VolObject.GetSize(m_sVolObjectName).Height - SliderObject.GetSize(sSliderName).Height)) - m_nPos
SliderObject.SetPos(sSliderName, SliderObject.GetPos(sSliderName).X, m_nPos);
-- fire event our own event
On_Slider_Move(sSliderName, nPercent);
m_bReturn = true;
end
end
return m_bReturn;
end

medina07
04-19-2006, 03:56 AM
it is possible to synchronize the SliderFrameWork with the Time Length in the Media Player Plugin?
If it is possible please you tell me how....

a3uk
06-03-2006, 03:49 AM
Great work!
I can't get how to save slider's position. Can any1 help me?:huh

SiNisTer
03-30-2007, 06:37 AM
its a great piece of work man!!

Love it!:yes

FoxLeader
04-05-2007, 05:05 PM
Thanks! Very useful!

CyberRBT
04-24-2007, 11:57 PM
@ Worm:

This is an EXCELLENT concept program. :yes :yes :yes

RizlaUK
04-28-2007, 08:56 AM
yup, if it slides, it uses the slider framework, i threw the slider plugin in the bin when i found this little gem ;)

crz
07-29-2007, 12:32 PM
hi there i'm a new member
and i got a question about a slider in my project.
i've seen the codes from worm
and there are very usefull.
but can i also use the slider to slide trugh; labels,buttons etc.
in other words can islide trugh my page as it is.
i got a project with: width = 1014 and height = 3000

but what i see is that i can't see the whole page
so what i'm tryng 2 do is scroll down 2 the bottem of
my page

can someone tell me how please ?


Greetings 2 all the programmers (keep doing what your doing)

crz
07-29-2007, 12:37 PM
hi there i'm a new member
and i got a question about a slider in my project.
i've seen the codes from worm
and there are very usefull.
but can i also use the slider to slide trugh; labels,buttons etc.
in other words can islide trugh my page as it is.
i got a project with: width = 1014 and height = 3000

but what i see is that i can't see the whole page
so what i'm tryng 2 do is scroll down 2 the bottem of
my page

can someone tell me how please ?


Greetings 2 all the programmers (keep doing what your doing)

JDog
09-02-2007, 06:35 PM
Hey Worm, thank you very much for your skills and patience with me... I'm still a little confused on how to get the slider with the picture to work with audio, can you guide me a little more??

Also where in the global function do I put the second part of the code you posted?????:eek:

JDog
09-03-2007, 12:36 PM
Hey worm I tried to post this befor but i havn't seen it. Here it is. I tried to follow your help but without any luck. I'm confused about how to make it work with audio.
Did I forget somthing? I can do the play, load, etc.. But I wanted it to slide before I went further.

Thanks Again,

JDog:)

Worm
09-03-2007, 06:54 PM
First things first. You need to be sure to name your images properly. If they are horizontal sliders, they need to start with hknob_ and hslider_, vertical sliders need to be vknob_ and vslider_. You had the knob as hknob, and the slider image as vslider_.

Also, use the custom event to set the get the perentage the slider has been moved. If you start throwing code into the framework, it could get ugly. Its kinda delicate :) There isn't a need to change the framework to work with your images, it will automatically work with any images named properly.

Last thing is the knob will trave the full length of the v/hslider_ image. So you want to make that image only the size/length you want the slider knob to move.

I've fixed up your apz to show you how, less the audio part. Once you get your slider working, then we can deal with that.

JDog
09-03-2007, 08:48 PM
Hey Worm!! Thank you so much for your help. I will start working on this tonight!! I'm realy glad all the people here are willing to help others learn something worth wild.

Well off to work on it.

THANKS AGAIN!

JDog :D:D:D:D

Intrigued
09-03-2007, 08:54 PM
As long as Worm can afford these high prices at the gas pump.... he goes the extra mile.

;-) @Worm

rexzooly
09-04-2007, 04:03 AM
i can't what to see this project and yet worm and alot of others do go that mile that is needed to help others.

In the next month or so i am going to be setting up a AMS and SUF site with free programs and the amz's for please to change them to there liking.

these last 4 weeks i have been able do alot more thanks to Worm and Derat.
there are others that have helped but these 2 have really opened my mind to
the possablitys to what ams can do thanks fellers.

i looked at you project looks kool :yes

If you need hosting for it just say.
i have hosting till may and if you want to host it just say.
when i get my home server up then i will then be redoing
my ams hosting site for people to have a homeplage and there downloads
i do have a limited amout of BW but i have over 160gig for this server
there for there should be no problem in hosting anyones projects.

JDog
09-04-2007, 08:46 PM
AWESOME Rexzooly!!! Thanks alot. Yea this is going to be a cool project if I can figure out a little code. I never tried it before so I'm kinda confused allot. BUT I guess this is how to learn..

I want this project to be an audio mixer and a D.J. mixer. Somthing like cakewalk, bla,bla.. Lol :lol BUT all original designs.

Thanks for the interest in it!!

JDog

rexzooly
09-05-2007, 09:19 AM
AWESOME Rexzooly!!! Thanks alot. Yea this is going to be a cool project if I can figure out a little code. I never tried it before so I'm kinda confused allot. BUT I guess this is how to learn..

I want this project to be an audio mixer and a D.J. mixer. Somthing like cakewalk, bla,bla.. Lol :lol BUT all original designs.

Thanks for the interest in it!!

JDog

well just pm me if you do need hosting.
should be getting new hosting pack soon as i am selling my main pc
jolly:yes

rexzooly
01-06-2008, 10:12 AM
JDog hows the mixer coming ?

Hope you have it all working now :)

Give me a PM sometime to tell me how its going.

TimeSurfer
02-11-2008, 03:31 PM
Ok I've implemented the slider framework into my project, now my question is this how can i retrieve the position of the slider. I need to retrieve in the on page show so that i may set the volume accordingly.

RizlaUK
03-28-2008, 05:33 PM
Ok I've implemented the slider framework into my project, now my question is this how can i retrieve the position of the slider. I need to retrieve in the on page show so that i may set the volume accordingly.


in your slider function that sets the volume, set a var for that slider myVar=nPercent, and use myVar to get the volume



@WORM, there appears to be a bug in the SetSliderPos function, only when setting hknob, its setting the slider to far forward so the hslider and hknob lose there alignment, vknob is fine tho

im trying to fix it but not getting any closer....any suggestions

RizlaUK
03-28-2008, 06:14 PM
Nevermind, i got it

this line:
m_nPos = VolObject.GetPos(m_sVolObjectName).X + VolObject.GetSize(m_sVolObjectName).Width - m_nPos;

should be:
m_nPos = VolObject.GetPos(m_sVolObjectName).X + m_nPos;

it was adding the width of the vknob image to the slider amount

heres the whole function
function SetSliderPos(sSliderName, nPercent)
local m_bReturn = false;
local SliderObject = tbObjectType[Page.GetObjectType(sSliderName)];

if String.Left(sSliderName, 6) == "hknob_" then
m_sVolObjectName = String.Replace(sSliderName, "hknob_", "hslider_", true);
local VolObject = tbObjectType[Page.GetObjectType(m_sVolObjectName)];
if VolObject then
m_nPos = Math.Floor((VolObject.GetSize(m_sVolObjectName).Wi dth - SliderObject.GetSize(sSliderName).Width) * (nPercent/100));
m_nPos = VolObject.GetPos(m_sVolObjectName).X + m_nPos;
SliderObject.SetPos(sSliderName, m_nPos, SliderObject.GetPos(sSliderName).Y);
-- fire event our own event
--On_Slider_Move(sSliderName, nPercent);
m_bReturn = true;
end
else
m_sVolObjectName = String.Replace(sSliderName, "vknob_", "vslider_", true);
local VolObject = tbObjectType[Page.GetObjectType(m_sVolObjectName)];
if VolObject then
m_nPos = Math.Floor((VolObject.GetSize(m_sVolObjectName).He ight - SliderObject.GetSize(sSliderName).Height) * (nPercent/100))
m_nPos = (VolObject.GetPos(m_sVolObjectName).Y + (VolObject.GetSize(m_sVolObjectName).Height - SliderObject.GetSize(sSliderName).Height)) - m_nPos
SliderObject.SetPos(sSliderName, SliderObject.GetPos(sSliderName).X, m_nPos);
-- fire event our own event
--On_Slider_Move(sSliderName, nPercent);
m_bReturn = true;
end
end
return m_bReturn;
end

also, i made a few edits so it can run as a script, call "Application.RunScriptFile("AutoPlay\\Scripts\\SliderSetup.lua");" from page preload to setup sliders for that page....thats it

Worm
03-28-2008, 10:23 PM
Thanks for cleaning up my sloppiness :yes

Sorry I wasn't around to help out, my two oldest daughters were in the musical Oliver tonight. It was awesome!

RizlaUK
03-29-2008, 12:53 AM
that must be a proud moment, cant wait till mine are doing stuff like that, but thats a few yeas away yet, still up to our ears in bottles and dirty nappies, lol

Thanks for cleaning up my sloppiness

lol, np, i'm supprized no-one else picked up on it to be honest, first time iv used that function (as i dident know it was there!!)

Worm
03-29-2008, 07:29 AM
Mine are still fairly young 10 and under... they were work house boys, but still it was a very cool thing.

Have a great weekend.

soldatstein
04-08-2008, 03:52 AM
how i make sound level bar

Worm
04-08-2008, 06:56 AM
I'd move straight over to the SliderEx plugin from Reteset. Much more functional (IMO)

http://www.indigorose.com/forums/showthread.php?t=23291

RizlaUK
04-08-2008, 10:39 AM
im using a combination of both :)


how i make sound level bar

use the SliderEX plugin, the slider frame work requires that you know some AMS code to customize, SliderEX is just like any other AMS object

Worm
04-08-2008, 11:32 AM
Don't get me wrong. SliderFrameWork has a special place with me. I developed it for a project I had, and its certainly has served its time in other projects of mine. The SliderEx plugin is, as you said, more simple, and quite configurable now too, thanks to Reteset.

RizlaUK
04-08-2008, 02:01 PM
SliderFrameWork is great for true custom slider when the image really matters, for a quick clean easy to use slider then its the plugin, as i say im useing both in a project, a dj mixing type thing, volume and crossfader with slider plugin and eq,pitch,tempo,tone etc with the framework.....it looks great

btw, worm, did you ever code a GetSliderPos function for SliderFrameWork, its the only drawback of useing it

Worm
04-08-2008, 02:47 PM
Sure nuff


function GetSliderPos(sSliderName)
local m_nReturn;
local SliderObject = tbObjectType[Page.GetObjectType(sSliderName)];

if String.Left(sSliderName, 6) == "hknob_" then
m_sVolObjectName = String.Replace(sSliderName, "hknob_", "hslider_", true);
local VolObject = tbObjectType[Page.GetObjectType(m_sVolObjectName)];
if VolObject then
m_nReturn = Math.Floor((SliderObject.GetPos(sSliderName).X - VolObject.GetPos(m_sVolObjectName).X) / (VolObject.GetSize(m_sVolObjectName).Width - SliderObject.GetSize(sSliderName).Width) * 100)
end
else
m_sVolObjectName = String.Replace(sSliderName, "vknob_", "vslider_", true);
local VolObject = tbObjectType[Page.GetObjectType(m_sVolObjectName)];
if VolObject then
m_nReturn = 100 - Math.Floor((SliderObject.GetPos(sSliderName).Y - VolObject.GetPos(m_sVolObjectName).Y) / (VolObject.GetSize(m_sVolObjectName).Height - SliderObject.GetSize(sSliderName).Height) * 100)
end
end
return m_nReturn;
end

RizlaUK
04-08-2008, 05:43 PM
Perfect

Thanks worm :yes

domin
11-20-2008, 03:10 AM
Thanks! Very good prog :yes

Worm
02-17-2009, 09:47 PM
Late addition:

Allows you to reset all objects back to the origninal positions in the event you navigate away from the page and come back.


-- Function to initialize the sliders
function InitSliders()
m_tblObjectData = {};
tblObjects = Page.EnumerateObjects();
--get the original positions if they are not already defined
if tblOrigPositions == nil then
tblOrigPositions={}
for index, sObject in tblObjects do
tblOrigPositions[sObject] = {}
Object = tbObjectType[Page.GetObjectType(sObject)];
tblOrigPositions[sObject].X=Object.GetPos(sObject).X
tblOrigPositions[sObject].Y=Object.GetPos(sObject).Y
end
end
end

--set object back to their original x,y coordinates
function ResetObjects()
Application.SetRedraw(false)
tblObjects = Page.EnumerateObjects();
for index, sObject in tblObjects do
Object = tbObjectType[Page.GetObjectType(sObject)];
Object.SetPos(sObject, tblOrigPositions[sObject].X, tblOrigPositions[sObject].Y)
end
Application.SetRedraw(true)
end

S0mbre
02-20-2009, 05:01 AM
Late addition:

Allows you to reset all objects back to the origninal positions in the event you navigate away from the page and come back.



That's what I've been missing! Thank you!

Chahra
08-01-2009, 05:11 AM
nice thnk you