// Project: Scrollbox example with MouseWheel / Touch functionality // Created: 2020-11-20 // show all errors SetErrorMode(2) // set window properties SetWindowTitle("Scrollbox Example") SetWindowSize( 1024, 720, 0 ) SetWindowAllowResize( 1 ) // allow the user to resize the window // set display properties SetVirtualResolution( 1024, 720 ) // doesn't have to match the window SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts lorem$ = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Non consectetur a erat nam. Tempus iaculis urna id volutpat. In hac habitasse platea dictumst. Euismod nisi porta lorem mollis aliquam ut porttitor leo a. At urna condimentum mattis pellentesque id nibh tortor id. Ut tellus elementum sagittis vitae et. Ultrices tincidunt arcu non sodales neque sodales ut. In pellentesque massa placerat duis ultricies lacus sed turpis tincidunt. Tellus in metus vulputate eu. Diam vel quam elementum pulvinar. Tellus orci ac auctor augue mauris augue neque. Sagittis nisl rhoncus mattis rhoncus." //next paragraph. CHR(10) = Line Feed lorem$ = lorem$ + CHR(10) + CHR(10) + "Orci dapibus ultrices in iaculis. Aliquam malesuada bibendum arcu vitae elementum. Morbi non arcu risus quis varius quam quisque id diam. Curabitur gravida arcu ac tortor dignissim convallis aenean et. Mattis rhoncus urna neque viverra. Congue quisque egestas diam in arcu cursus. Magna eget est lorem ipsum dolor sit amet. Eget nullam non nisi est sit amet facilisis magna etiam. Facilisi morbi tempus iaculis urna id volutpat lacus. In vitae turpis massa sed elementum. Egestas sed tempus urna et pharetra pharetra massa massa ultricies. Leo duis ut diam quam nulla porttitor massa. At elementum eu facilisis sed odio morbi quis commodo odio. <end>" ThisBox = Scrollbox(lorem$, 300,200,24,600.0,120.0 ) `FUNCTION SYNTAX: Scrollbox(ThisText$,X#,Y#,TextSize, BoxWidth#, BoxHeight#) Back = CreateSprite(0) : SetSpriteSize(Back,600+8,120+8) : SetSpritePosition(Back,300-4,200-4) `only a visual to show pointer over scrollbox/active. do If GetTextHitTest( ThisBox, GetPointerX(), GetPointerY() ) SetSpriteColor(Back,64,64,64,255) If GetRawTouchCount(1) = 1 `if Touch MWD# = (GetRawTouchCurrentY(1) - GetRawTouchLastY(1)) *0.1 `set your own sensitivity Else MWD# = -GetRawMouseWheelDelta() `Else Wheel If MWD# <> 0.0 then MWD# = MWD#/ABS(MWD#) `same here. i just want -1/1 Endif If MWD# <> 0.0 then SetTextY(ThisBox, GetTextY(ThisBox) - MWD#*GetTextSize(ThisBox)) //keep top/bottom lines visible. we originally set the y position to 200 with a boxheight of 120 If GetTextY(ThisBox) > 200 then SetTextY(ThisBox,200) If GetTextY(ThisBox) < 200 - GetTextTotalHeight( ThisBox ) + 120 then SetTextY(ThisBox, 200-GetTextTotalHeight( ThisBox )+120) Else SetSpriteColor(Back,0,0,0,255) Endif Print( "Hover over/Touch Text to check for Scroll." + CHR(10)+ "MouseWheel/Drag to Scroll" ) Sync() loop Function Scrollbox(ThisText$,OX#,OY#,TextSize#, BoxWidth#, BoxHeight#) ThisBox = CreateText(ThisText$) : SetTextPosition(ThisBox,OX#,OY#) SetTextSize(ThisBox,TextSize#) SetTextMaxWidth( ThisBox, BoxWidth# ) SetTextScissor(ThisBox,OX#,OY#,OX#+BoxWidth#,OY#+BoxHeight#) `sets the Scrollbox area EndFunction ThisBox