Scrolling text effect

Post

Posted
Rating:
Item has a rating of 5 (Liked by Gianluigi)
#1 (In Topic #1939)
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’

with ScrollView

Hi Folks,

I would like to share a topic: vertical ticker text

and at the same time ask what could be improved.

In Gambas at the beginning, there is ‘About’, which features vertical ticker text with images
using a gridview. I looked at the source code and couldn't quite figure it out.

So I programmed a simpler version based on a ‘Scrollview’ and a ‘Textlabel’ object used
in a modul.

Here is the result and if you know a simple and better way to mix Text and Images,
let me know. Magic word "simple" 🙂

Code (gambas)

  1. Public Sub btnAbout_Click()
  2. s = File.Load("./loremIpsum.txt")
  3. LFAbout.ShowAbout("Linux/Ubuntu/Gambas", s, 500, 300)

The sub takes the window title
a string to be shown
and optional arguments width and heigth of the window

It creates a new window with a scrollview and a textlabel object and a "OK" button.
Usage if the windows is shown (it is modal)

Mouse over the Scrolling Text:
Left Mouse Down … Scroll faster forward
Right Mouse Down … Scroll faster backward
ESC key or OK Button => quit

No special "bells and whistles", formatting the text you can use the HTML subset for a textlabel.

Image

Bildschirmfoto vom 2025-12-05 06-10-51.png

Bildschirmfoto vom 2025-12-05 06-10-51.png

Image

Bildschirmfoto vom 2025-12-05 06-11-04.png

Bildschirmfoto vom 2025-12-05 06-11-04.png
Attachment

LFScrollAbout-0.0.1.tar.gz


Regards,
Yogi
Online now: No Back to the top

Post

Posted
Rating:
Item has a rating of 5 (Liked by Gianluigi)
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
cogier is in the usergroup ‘GambOS Contributor’

Yogi said

Magic word "simple" 🙂

Ok, this version does not scroll past the top and therefore is not endless, but is very simple :thumbs: . You will need to add your "loremIpsum.txt" file to the program.

Code (gambas)

  1. Private TextLabelDisplay As TextLabel
  2. Private aSpring As Spring
  3.  
  4. Public Sub Form_Open()
  5.  
  6.   With Me
  7.     .Padding = 5
  8.     .Arrangement = Arrange.Vertical
  9.     .H = 700
  10.     .W = 415
  11.     .Y = 50
  12.  
  13.   aSpring = New Spring(Me)
  14.  
  15.   TextLabelDisplay = New TextLabel(Me) As "TextLabelDisplay"
  16.   TextLabelDisplay.Text = File.Load(Application.Path &/ "loremIpsum.txt")
  17.  
  18.   Timer1 = New Timer As "Timer1"
  19.   Timer1.Delay = 25
  20.   Timer1.Start
  21.  
  22.  
  23. Public Sub Timer1_Timer()
  24.  
  25.   Inc TextLabelDisplay.H
  26.  


Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’

cogier said


Ok, this version does not scroll past the top and therefore is not endless, but is very simple :thumbs: . You will need to add your "loremIpsum.txt" file to the program.

Code (gambas)

  1. Private TextLabelDisplay As TextLabel
  2. Private aSpring As Spring
  3.  
  4. Public Sub Form_Open()
  5.  
  6.   With Me
  7.     .Padding = 5
  8.     .Arrangement = Arrange.Vertical
  9.     .H = 700
  10.     .W = 415
  11.     .Y = 50
  12.  
  13.   aSpring = New Spring(Me)
  14.  
  15.   TextLabelDisplay = New TextLabel(Me) As "TextLabelDisplay"
  16.   TextLabelDisplay.Text = File.Load(Application.Path &/ "loremIpsum.txt")
  17.  
  18.   Timer1 = New Timer As "Timer1"
  19.   Timer1.Delay = 25
  20.   Timer1.Start
  21.  
  22.  
  23. Public Sub Timer1_Timer()
  24.  
  25.   Inc TextLabelDisplay.H
  26.  




Hi cogier ,

Wow, a really short one.
Thanks for sharing 👍


Regards,
Yogi
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’
It wouldn't leave me alone, so I played around with the FAbout class from the Gambas source code.

Spoiler: I still don't have a clear understanding of what exactly is going on there.

I tried to gain a little more clarity by changing the background colour of the objects used
and lo and behold, there is a small visual error that is almost imperceptible.

But see for yourself, I simply added to and expanded the source code, removed the original
Authors and replaced with "LoremIpsum":

Code (gambas)

  1. ' Gambas class file
  2.  
  3. Private $aCache As Image[]
  4. Private $bPressed As Boolean
  5. Private $bLeftMouse As Boolean
  6. Private $iGap As Short = 2
  7.  
  8.  
  9.   FAbout.ShowModal
  10.  
  11.  
  12. Public Sub _new()
  13.  
  14.   Me.Background = Color.Opacity(Color.Background, 1)
  15.   gvwAbout.NoAnimation = True
  16.  
  17.  
  18.  
  19. Public Sub Form_Open()
  20.  
  21.  
  22.  
  23.  
  24. Public Sub btnClose_Click()
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. Private Sub FillAbout()
  32.  
  33.  
  34.   Dim sText, sFont As String
  35.   Dim aAuthor As New String[]
  36.   Dim aText As String[]
  37.  
  38.   sText = Replace(File.Load("./loremIpsum.txt"), "<br>", gb.NewLine)
  39.   aText = Split(sText, gb.NewLine)
  40.   For I = 0 To aText.Count - 1
  41.     aAuthor.Add(aText[I])
  42.   Next
  43.  
  44.   gvwAbout.Columns.Count = 1
  45.   N = 6
  46.  
  47.   gvwAbout.Rows.Count = aAuthor.Count + N + 2
  48.   gvwAbout.Columns[0].Width = Me.ClientWidth - Desktop.Scale * 6
  49.   gvwAbout.Padding = 0
  50.  
  51.   ' Space
  52.   gvwAbout.Rows[0].H = dwgAbout.H / 2
  53.   ' Gambas
  54.   gvwAbout[1, 0].RichText = "<b>G</b>ambas <b>A</b>lmost<br><b>M</b>eans <b>BAS</b>ic !"
  55.   gvwAbout[1, 0].Font = Font["+10,Spacing=2"]
  56.   gvwAbout[1, 0].Alignment = Align.Top
  57.   'gvwAbout[1, 0].WordWrap = True
  58.   ' Logo
  59.   gvwAbout[2, 0].Picture = Picture["icon:/128/gambas"]
  60.   gvwAbout[2, 0].Alignment = Align.Top
  61.  
  62.   For I = 1 To 5
  63.     gvwAbout.Rows[I].H = -1
  64.   Next
  65.   gvwAbout.Rows[4].H += Desktop.Scale * 2
  66.  
  67.  
  68.  
  69.   For I = 0 To aAuthor.Max
  70.  
  71.     sText = aAuthor[I]
  72.     gvwAbout[N, 0].WordWrap = True
  73.     gvwAbout[N, 0].RichText = sText
  74.     gvwAbout[N, 0].Padding = Desktop.Scale
  75.     gvwAbout[N, 0].Alignment = Align.Center
  76.    
  77.     If I > 7 Then
  78.       sFont = "12"
  79.     Else
  80.       sFont = "+" & Str(i)
  81.     Endif
  82.    
  83.     gvwAbout[N, 0].Font = Font[sFont]
  84.     gvwAbout.Rows[N].Height = -1
  85.     Inc N
  86.  
  87.   Next
  88.  
  89.   Inc N
  90.  
  91.   gvwAbout[N, 0].Picture = Picture["./ende.jpg"]
  92.   gvwAbout[N, 0].Alignment = Align.Top
  93.   gvwAbout.Rows[N].Height = -1
  94.  
  95.   Inc N
  96.  
  97.  
  98.   gvwAbout.Rows[N].H = dwgAbout.H
  99.  
  100.  
  101. Private Sub ScrollText(D As Integer)
  102.  
  103.   Dim hImage As Image
  104.  
  105.   If $bLeftMouse = True And $bPressed Then
  106.     D = -D
  107.  
  108.   $Y += D
  109.  
  110.   If D > 0 Then
  111.    
  112.     While $Y >= dwgAbout.H
  113.      
  114.       $Y -= dwgAbout.H
  115.      
  116.       hImage = $aCache[0]
  117.       $aCache[0] = $aCache[1]
  118.       $aCache[1] = $aCache[2]
  119.       $aCache[2] = hImage
  120.      
  121.       Inc $YP
  122.       If ($YP * dwgAbout.H) >= (gvwAbout.ScrollH - dwgAbout.H) Then $YP = 0
  123.  
  124.       PaintAbout($aCache[2], $YP)
  125.      
  126.     Wend
  127.  
  128.   Else If D < 0 Then
  129.    
  130.     While $Y < 0
  131.  
  132.       If $YP = 2 Then
  133.         $Y = 0
  134.         Break
  135.       Endif
  136.      
  137.       $Y += dwgAbout.H - 5
  138.      
  139.       hImage = $aCache[2]
  140.       $aCache[2] = $aCache[1]
  141.       $aCache[1] = $aCache[0]
  142.       $aCache[0] = hImage
  143.      
  144.       Dec $YP
  145.       If $YP < 0 Then $YP = gvwAbout.ScrollH \ dwgAbout.H - 1
  146.       PaintAbout($aCache[0], $YP - 2)
  147.      
  148.     Wend
  149.  
  150.  
  151.   dwgAbout.Refresh
  152.  
  153.  
  154. Public Sub timAbout_Timer()
  155.  
  156.   ScrollText(If($bPressed, 16, 1))
  157.  
  158.  
  159. Public Sub dwgAbout_Draw()
  160.  
  161.   Paint.DrawImage($aCache[0], 0, -$Y)
  162.   If $Y > 0 Then Paint.DrawImage($aCache[1], 0, dwgAbout.H - $Y)
  163.  
  164.  
  165. Public Sub Form_KeyPress()
  166.  
  167.   If Key.Code = Key.Escape Then Me.Close
  168.  
  169.  
  170. Private Sub PaintAbout(hImage As Image, iPos As Integer)
  171.  
  172.   gvwAbout.Move(Me.ClientW, 0, dwgAbout.W + $iGap, dwgAbout.H + $iGap) 'changed to +2, if not there is a visible gap
  173.   If iPos < 0 Then iPos += gvwAbout.ScrollH \ dwgAbout.H
  174.   gvwAbout.Scroll(0, iPos * dwgAbout.H)
  175.   hImage.Fill(Color.Transparent)
  176.   Paint.Begin(hImage)
  177.   Paint.ClipRect = Rect(0, 0, dwgAbout.W, dwgAbout.H)
  178.   gvwAbout.ScrollArea_Draw
  179.   Paint.End
  180.  
  181.  
  182. Public Sub Form_Arrange()
  183.  
  184.  
  185.   FillAbout
  186.  
  187.   $aCache = New Image[3]
  188.  
  189.   For I = 0 To $aCache.Max
  190.     $aCache[I] = New Image(dwgAbout.W, dwgAbout.H)
  191.     PaintAbout($aCache[I], I)
  192.   Next
  193.   $YP = 2
  194.  
  195.  
  196. Public Sub dwgAbout_MouseDown()
  197.  
  198.   $bPressed = True
  199.   If Mouse.State = 4 Then
  200.     $bLeftMouse = True
  201.   Else
  202.     $bLeftMouse = False
  203.  
  204. Public Sub dwgAbout_MouseUp()
  205.  
  206.   $bPressed = False
  207.  
  208.  
  209. Public Sub dwgAbout_MouseWheel()
  210.  
  211.  
  212.   For I = 1 To 32
  213.     ScrollText(If(Mouse.Forward, -2, 2))
  214.     Wait
  215.   Next
  216.  
  217.  
  218. Public Sub ToggleButton1_Click()
  219.  
  220.   If ToggleButton1.Value Then
  221.     ToggleButton1.Text = "Remove Gap"
  222.     $iGap = 0
  223.   Else
  224.     ToggleButton1.Text = "Show Gap"
  225.     $iGap = 2
  226.   Form_Arrange()
  227.   dwgAbout.Refresh
  228.  
  229.  

Attachment

welcomeabout-0.0.1.tar.gz

Online now: No Back to the top
1 guest and 0 members have just viewed this.