02-19-2025, 07:06 AM
And here's an example of how to do this, and only update/change the screen as necessary:
Notice here that the vast majority of the time we're not even using _DISPLAY to update the screen. We print what we want on it, draw the buttons over it... and then basically forget about it until we have to update the screen again. We're still doing the input checking and the processing and everything else, but we're doing absolutely *nothing* with images. We're not putting anything on the screen, or making copies of anything, or freeing anything... We're just leaving the screen as it was until we need to do something to change it.
My CPU usage here? 0.1%... and I think that might be because it never seems to be 0.0% on an active program.
Code: (Select All)
Dim buttons(1) 'just two simple buttons for the demo
button(0) = MakeButton("Hello World")
button(1) = MakeButton("STEVE!")
x = 100 'just for moveable button
Cls , 4 'a red screen for a background
screenChange = _TRUE 'we start by drawing the screen once
Do
k = _KeyHit
Select Case k 'left/right arrow to move that button
Case 19200
x = x - 3
If x < 0 Then x = 0
screenChange = _TRUE
Case 19712
x = x + 3
If x > _Width * _FontWidth - 100 Then x = _Width * _FontWidth - 100
screenChange = _TRUE
Case Is > 0: System 'any other key to end
End Select
If screenChange Then 'only update the screen when it changes
_PutImage (x, 100), button(0)
_PutImage (200, 200), button(1)
_Display
screenChange = _FALSE
End If
_Limit 30
Loop
Function MakeButton (caption$)
d = _Dest
temp = _NewImage(_FontWidth * Len(caption$) + 4, _FontHeight + 4, 32)
_Dest temp
Color &HFFFFFFFF&&, 0 ' bright white text with no background
Cls , &HFF0000FF&& 'dark blue background for this button
Line (0, 0)-(_Width - 1, _Height - 1), &HFFFFFFFF, B 'white trim around the edges
Line (1, 1)-(_Width - 2, _Height - 2), &HFFFFFFFF, B '2 pixel trim
_PrintString (3, 3), caption$ 'print the caption
MakeButton = _CopyImage(temp, 33) 'make the hardware button
_Dest d 'restore the destination
_FreeImage temp 'free the temp image
End Function
Notice here that the vast majority of the time we're not even using _DISPLAY to update the screen. We print what we want on it, draw the buttons over it... and then basically forget about it until we have to update the screen again. We're still doing the input checking and the processing and everything else, but we're doing absolutely *nothing* with images. We're not putting anything on the screen, or making copies of anything, or freeing anything... We're just leaving the screen as it was until we need to do something to change it.
My CPU usage here? 0.1%... and I think that might be because it never seems to be 0.0% on an active program.

