Indigo Rose Software
  #1  
Old 02-28-2006
Worm Worm is offline
Indigo Rose Customer
 
Join Date: Jul 2002
Location: USA
Posts: 3,937
Thumbs up Sample: Slider Framework

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
Code:
--Initialize the sliders
InitSliders();
On Mouse Button
Code:
DoSlider_MouseButton(e_Type, e_X, e_Y);
On Mouse Move
Code:
DoSlider_MouseMove(e_X, e_Y);
2. Copy this code to your Global Functions
Code:
-- 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
Attached Images
File Type: jpg SliderFrameWork.jpg (22.4 KB, 821 views)
Attached Files
File Type: apz SliderFrameWork.apz (93.9 KB, 1184 views)

Last edited by Brett; 03-01-2006 at 09:56 AM.
Reply With Quote
  #2  
Old 02-28-2006
rhosk's Avatar
rhosk rhosk is offline
Indigo Rose Customer
 
Join Date: Aug 2003
Location: Maine, USA
Posts: 1,692
Worm, you're on fire!! Thanks!
__________________
Regards,

-Ron

Music | Video | Pictures
Reply With Quote
  #3  
Old 02-28-2006
Intrigued's Avatar
Intrigued Intrigued is offline
Indigo Rose Customer
 
Join Date: Dec 2003
Location: Location! Location!
Posts: 6,059
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.

__________________
Intrigued
www.amsuser.com
Reply With Quote
  #4  
Old 02-28-2006
Worm Worm is offline
Indigo Rose Customer
 
Join Date: Jul 2002
Location: USA
Posts: 3,937
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.
Reply With Quote
  #5  
Old 02-28-2006
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
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.
Reply With Quote
  #6  
Old 03-02-2006
Worm Worm is offline
Indigo Rose Customer
 
Join Date: Jul 2002
Location: USA
Posts: 3,937
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.

Code:
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).Width - 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).Height - 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
Reply With Quote
  #7  
Old 04-19-2006
medina07's Avatar
medina07 medina07 is offline
Forum Member
 
Join Date: Feb 2006
Location: Japan
Posts: 66
Talking

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....
Reply With Quote
  #8  
Old 06-03-2006
a3uk's Avatar
a3uk a3uk is offline
Forum Member
 
Join Date: Jul 2005
Posts: 11
Great work!
I can't get how to save slider's position. Can any1 help me?
Reply With Quote
  #9  
Old 03-30-2007
SiNisTer's Avatar
SiNisTer SiNisTer is offline
Forum Member
 
Join Date: Mar 2007
Posts: 186
its a great piece of work man!!

Love it!
Reply With Quote
  #10  
Old 04-05-2007
FoxLeader's Avatar
FoxLeader FoxLeader is offline
Forum Member
 
Join Date: Nov 2006
Location: Quebec, Canada.
Posts: 432
Thanks! Very useful!
Reply With Quote
  #11  
Old 04-24-2007
CyberRBT's Avatar
CyberRBT CyberRBT is offline
Forum Member
 
Join Date: Nov 2003
Location: Myrtle Beach, SC
Posts: 155
@ Worm:

This is an EXCELLENT concept program.
Reply With Quote
  #12  
Old 04-28-2007
RizlaUK's Avatar
RizlaUK RizlaUK is offline
Forum Member
 
Join Date: May 2006
Location: London UK
Posts: 3,129
yup, if it slides, it uses the slider framework, i threw the slider plugin in the bin when i found this little gem
Reply With Quote
  #13  
Old 07-29-2007
crz crz is offline
Forum Member
 
Join Date: Jul 2007
Posts: 5
Huh? qoute

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)

Last edited by crz; 07-29-2007 at 12:38 PM.
Reply With Quote
  #14  
Old 07-29-2007
crz crz is offline
Forum Member
 
Join Date: Jul 2007
Posts: 5
Huh? qoute

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)
Reply With Quote
  #15  
Old 09-02-2007
JDog's Avatar
JDog JDog is offline
Forum Member
 
Join Date: Sep 2007
Location: PA
Posts: 10
Talking Confused

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?????
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dependency Module: Microsoft .NET Framework 2.0 Adam Setup Factory 8.0 Examples 30 1 Day Ago 09:27 PM
Sample: Splitter Framework Worm AutoPlay Media Studio 7.5 Examples 37 01-17-2009 09:45 PM
Dependency Module: Microsoft .NET Framework 1.1 Darryl Setup Factory 8.0 Examples 12 06-10-2008 03:26 AM
Sample Project : User can Re-Size and save images using slider Corey AutoPlay Media Studio 5.0 7 08-17-2007 01:27 PM
Volume Slider markstaylor AutoPlay Media Studio 5.0 5 08-13-2004 11:32 AM


All times are GMT -6. The time now is 07:53 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software