How to smoothly scroll an Editor Gadget?

Windows specific forum
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

How to smoothly scroll an Editor Gadget?

Post by IdeasVacuum »

This code scrolls the text in an EditorGadget:

Code: Select all

iPause.i = 900
 iLine.i = 0
iTotal.i = CountGadgetItems(#EditorGdgt)

While (iLine < iTotal)
                Delay(iPause)
         SendMessage_(GadgetID(#EditorGdgt),#EM_LINESCROLL,0,1)
         iLine = iLine + 1
Wend
.... efficient, but not smooth. I suspect it is possible to get smoother scrolling by moving the scroll bar programmatically?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
pstryk
New User
New User
Posts: 5
Joined: Tue Dec 03, 2013 7:50 pm
Contact:

Re: How to smoothly scroll an Editor Gadget?

Post by pstryk »

With WinApi:

Code: Select all

OpenWindow(0,60,60,500,500,"Scroll")
EditorGadget(0,0,0,500,500)
 position.POINT
For x=0 To 500
  AddGadgetItem(0, x, "Line: "+Str(x))
Next x
GetScrollRange_(GadgetID(0), #SB_VERT, @minpos, @maxpos)
While event<>#PB_Event_CloseWindow And maxpos>position\y
  If time+10<ElapsedMilliseconds()
  SendMessage_(GadgetID(0), #EM_GETSCROLLPOS, 0, position.POINT)
  position\y+1
  SendMessage_(GadgetID(0), #EM_SETSCROLLPOS, 0, position)
  time=ElapsedMilliseconds()
  EndIf
  event=WindowEvent()
Wend  
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: How to smoothly scroll an Editor Gadget?

Post by IdeasVacuum »

Thanks for the code snippet pstryk - but the performance is similar to my code if run more slowly.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: How to smoothly scroll an Editor Gadget?

Post by IdeasVacuum »

...in fact pstryk, your snippet runs similarly to my code but if I incorporate the method into my app code, it does actually scroll nicely, much smoother! Strange thing is, it only works when the font size is less than 26. My app will often be using much larger font sizes (80 to 120), variable on-the-fly.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply