How to make an app - Andromo App Maker

Announcement

Collapse
No announcement yet.

Sample: Slider Framework

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 Files
    Last edited by Brett; 03-01-2006, 09:56 AM.

  • #2
    Worm, you're on fire!! Thanks!
    Regards,

    -Ron

    Music | Video | Pictures

    Comment


    • #3
      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

      Comment


      • #4
        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.

        Comment


        • #5
          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.

          Comment


          • #6
            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

            Comment


            • #7
              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....

              Comment


              • #8
                Great work!
                I can't get how to save slider's position. Can any1 help me?

                Comment


                • #9
                  its a great piece of work man!!

                  Love it!:yes

                  Comment


                  • #10
                    Thanks! Very useful!

                    Comment


                    • #11
                      @ Worm:

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

                      Comment


                      • #12
                        yup, if it slides, it uses the slider framework, i threw the slider plugin in the bin when i found this little gem
                        Embrace change in your life, you never know, it could all work out for the best

                        Comment


                        • #13
                          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, 11:38 AM.

                          Comment


                          • #14
                            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)

                            Comment


                            • #15
                              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?????

                              Comment

                              Working...
                              X