I have written some test code so I can learn about 2D drawing. In the case below I am simulating a person at a fuel station entering their PIN. I display asterisks in response to keystrokes. I have removed the keyboard for simplicity so I can just see what happens on the display. As you can see FlipBuffers() is required after I display the Welcome message but is not needed thereafter. I would like to understand why FlipBuffers() is not needed in the Repeat Loop.
I am running PB 5.72 on Linux OpenSuse 15.1. The attached display resolution is 800 x 480.
Code: Select all
;
; dCFusnFSC_Scn.pb - Commands to draw on the screen
;
#dCTestMode = 0
#dCScrnWidth = 800
#dCScrnHeight = 480
#dCScnForeColor = $00FF00
#dCScnBackColor = $000000
#dCScnFontName = "DejaVu Sans Mono"
#dCScnFontSize = 18
#dCScnNo = 5
#dCImageNo = 6
#ScnBottom = -1
#ScnTop = -2
#dCLogFile = "dcFusnFSC.log"
;XIncludeFile "dCSettings.pb"
;XIncludeFile "dC_Wait.pb"
;XIncludeFile "dC_CloseFile.pb"
;XIncludeFile "dC_Logging.pb"
Structure Scrn
ID.i
Font_Name.s
Font_Size.a
Font_B.a
Font_I.a
Font_U.a
Font_ID.i
Position_X.i
Position_X1.i
Position_Y.i
Position_Y1.i
Std_X.i
Std_Y.i
EndStructure
Global goScn.scrn
Procedure Scn_LineA(*toScn.scrn,tnColor.i=0,tnY1.i=-1,tnX1.i=-1,tnWidth.i=-1,tnHeight.i=-1)
If tnY1 = -1.0
tnY1 = *toScn\Position_Y + *toScn\Std_Y
tnX1 = 0
tnWidth = #dCScrnWidth
tnHeight = 1
EndIf
StartDrawing(WindowOutput(#dCScnNo))
Line(tnX1,tnY1, tnWidth,tnHeight ,tnColor)
StopDrawing()
EndProcedure
Procedure Scn_Write(*toScn.scrn,tnY.i=0,tnX.i=0,tcText.s="",tnForeColor.i=#dCScnForeColor,tnBackColor.i=#dCScnBackColor)
*toScn\Position_X = *toScn\Std_X * tnX
*toScn\Position_Y = *toScn\Std_Y * tnY
StartDrawing(WindowOutput(#dCScnNo))
DrawingFont(*toScn\Font_ID)
DrawText(*toScn\Position_X,*toScn\Position_Y,tcText,tnForeColor,tnBackColor)
*toScn\Position_X = *toScn\Position_X + TextWidth(tcText)
StopDrawing()
EndProcedure
Procedure Scn_Append(*toScn.scrn,tcText.s,tnForeColor.i=#dCScnForeColor,tnBackColor.i=#dCScnBackColor)
StartDrawing(WindowOutput(#dCScnNo))
GrabDrawingImage(0,0,0,#dCScrnWidth,#dCScrnHeight)
DrawingFont(*toScn\Font_ID)
DrawImage(ImageID(0),0,0,#dCScrnWidth,#dCScrnHeight)
DrawText(*toScn\Position_X,*toScn\Position_Y,tcText,tnForeColor,tnBackColor)
*toScn\Position_X = *toScn\Position_X + TextWidth(tcText)
StopDrawing()
EndProcedure
Procedure Scn_BSpace(*toScn.scrn)
*toScn\Position_X = *toScn\Position_X - *toScn\Std_X
StartDrawing(WindowOutput(#dCScnNo))
GrabDrawingImage(0,0,0,#dCScrnWidth,#dCScrnHeight)
DrawingFont(*toScn\Font_ID)
DrawImage(ImageID(0),0,0,#dCScrnWidth,#dCScrnHeight)
DrawText(*toScn\Position_X,*toScn\Position_Y," ",tnForeColor,tnBackColor)
StopDrawing()
EndProcedure
Procedure Scn_WriteC(*toScn.scrn,tnY.i=0,tnX.i=0,tcText.s="",tnForeColor.i=#dCScnForeColor,tnBackColor.i=#dCScnBackColor)
*toScn\Position_X = (#dCScrnWidth - TextWidth(tcText))/2
*toScn\Position_Y = *toScn\Std_Y * tnY
StartDrawing(WindowOutput(#dCScnNo))
DrawingFont(*toScn\Font_ID)
DrawText(*toScn\Position_X,*toScn\Position_Y,tcText,tnForeColor,tnBackColor)
*toScn\Position_X = *toScn\Position_X + TextWidth(tcText)
StopDrawing()
EndProcedure
Procedure Scn_WriteR(*toScn.scrn,tnY.i=0,tnX.i=0,tcText.s="",tnForeColor.i=#dCScnForeColor,tnBackColor.i=#dCScnBackColor)
*toScn\Position_X = #dCScrnWidth - TextWidth(tcText)
*toScn\Position_Y = *toScn\Std_Y * tnY
StartDrawing(WindowOutput(#dCScnNo))
DrawingFont(*toScn\Font_ID)
DrawText(*toScn\Position_X,*toScn\Position_Y,tcText,tnForeColor,tnBackColor)
*toScn\Position_X = #dCScrnWidth
StopDrawing()
EndProcedure
Procedure Scn_Picture(*toScn.scrn,tcImg.s,tnY1.i,tnX1.i,tnScale_Y = 1.0,tnScale_X.d = 1.0)
If LoadImage(#dCImageNo,tcImg)
*toScn\Position_X = *toScn\Std_X * tnX1
*toScn\Position_Y = *toScn\Std_Y * tnY1
If tnScale_Y <> 1.0 Or tnScale_X <> 1.0
ResizeImage(#dCImageNo,ImageWidth(#dCImageNo) * tnScale_X,ImageHeight(#dCImageNo) * tnScale_Y)
EndIf
StartDrawing(WindowOutput(#dCScnNo))
DrawImage(ImageID(#dCImageNo),*toScn\Position_X,*toScn\Position_Y,ImageWidth(#dCImageNo),ImageHeight(#dCImageNo))
*toScn\Position_X = *toScn\Position_X + ImageWidth(#dCImageNo)
*toScn\Position_Y = *toScn\Position_Y + ImageHeight(#dCImageNo)
StopDrawing()
EndIf
EndProcedure
Procedure Scn_PictureA(*toScn.scrn,tcImg.s,tnY1.i,tnX1.i,tnScale_Y = 1.0,tnScale_X.d = 1.0)
If LoadImage(#dCImageNo,tcImg)
If tnScale_Y <> 1.0 Or tnScale_X <> 1.0
ResizeImage(#dCImageNo,ImageWidth(#dCImageNo) * tnScale_X,ImageHeight(#dCImageNo) * tnScale_Y)
EndIf
StartDrawing(WindowOutput(#dCScnNo))
DrawImage(ImageID(#dCImageNo),tnX1,tnY1,ImageWidth(#dCImageNo),ImageHeight(#dCImageNo))
*toScn\Position_X = tnX1 + ImageWidth(#dCImageNo)
*toScn\Position_Y = tnY1 + ImageHeight(#dCImageNo)
StopDrawing()
EndIf
EndProcedure
Procedure Scn_WriteA(*toScn.scrn,tnY.i=0,tnX.i=0,tcText.s="",tnForeColor.i=#dCScnForeColor,tnBackColor.i=#dCScnBackColor)
*toScn\Position_X = tnX
*toScn\Position_Y = tnY
StartDrawing(WindowOutput(#dCScnNo))
DrawText(*toScn\Position_X,*toScn\Position_Y,tcText,tnForeColor,tnBackColor)
*toScn\Position_X = *toScn\Position_X + TextWidth(tcText)
StopDrawing()
EndProcedure
Procedure.i Scn_GetPosition_X(*toScn.scrn)
ProcedureReturn *toScn\Position_X
EndProcedure
Procedure.i Scn_GetPosition_Y(*toScn.scrn)
ProcedureReturn *toScn\Position_Y
EndProcedure
Procedure.i Scn_GetStd_Y(*toScn.scrn)
ProcedureReturn *toScn\Std_Y
EndProcedure
Procedure Scn_IncPosition_Y(*toScn.scrn,tnInc.i)
*toScn\Position_Y + tnInc
EndProcedure
Procedure Scn_IncPosition_X(*toScn.scrn,tnInc.i)
*toScn\Position_X + tnInc
EndProcedure
Procedure Scn_PushPosition(*toScn.scrn)
*toScn\Position_X1 = *toScn\Position_X
*toScn\Position_Y1 = *toScn\Position_Y
EndProcedure
Procedure Scn_PopPosition(*toScn.scrn)
*toScn\Position_X = *toScn\Position_X1
*toScn\Position_Y = *toScn\Position_Y1
EndProcedure
Procedure.i Scn_GetTxt_Y(*toScn.scrn,tcText.s)
ProcedureReturn TextHeight(tcText)
EndProcedure
Procedure.i ScnGetTxt_X(*toScn.scrn,tcText.s)
ProcedureReturn TextWidth(tcText)
EndProcedure
Procedure.i Scn_Clear(*toScn.scrn)
StartDrawing(WindowOutput(#dCScnNo))
Box(0,0,#dCScrnWidth,#dCScrnHeight,#dCScnBackColor)
StopDrawing()
FlipBuffers()
*toScn\Position_X = 0
*toScn\Position_Y = 0
EndProcedure
Procedure Scn_SetFont(*toScn.scrn,tcFont.s=#dCScnFontName,tnSize.a=#dCScnFontSize,tlB.a=0,tlI.a=0,tlU.a=0)
Define lnFlag.i
If tcFont <> ""
*toScn\Font_Name = tcFont
EndIf
*toScn\Font_Size = tnSize
*toScn\Font_B = tlB
*toScn\Font_I = tlI
*toScn\Font_U = tlU
If tlB
lnFlag | #PB_Font_Bold
EndIf
If tlI
lnFlag | #PB_Font_Italic
EndIf
If tlU
lnFlag | #PB_Font_Underline
EndIf
*toScn\Font_ID = FontID(LoadFont(#PB_Any,*toScn\Font_Name,*toScn\Font_Size,lnFlag))
If *toScn\Font_ID
StartDrawing(WindowOutput(#dCScnNo))
DrawingFont(*toScn\Font_ID)
*toScn\Std_X = TextWidth("X")
*toScn\Std_Y = TextHeight("X")
StopDrawing()
Else
; WriteToLog("Screen Font "+*toScn\Font_Name+" "+Str(*toScn\Font_Size)+"pt did not load")
EndIf
EndProcedure
Procedure.i Scn_Init(*toScn.scrn)
If Not InitSprite()
; WriteTolog("Scn_Init() - InitSprite failed")
ElseIf Not OpenWindow(#dCScnNo,0,0,#dCScrnWidth,#dCScrnHeight,"MultiPass Lite",#PB_Window_TitleBar)
; WriteTolog("Scn_Init() - OpenWindow failed")
ElseIf Not OpenWindowedScreen(WindowID(#dCScnNo),0,0,#dCScrnWidth,#dCScrnHeight)
; WriteTolog("Scn_Init() - OpenWindowedScreen failed")
Else
Scn_SetFont(*toScn)
Scn_Clear(*toScn)
ProcedureReturn 1
EndIf
ProcedureReturn 0
EndProcedure
If Scn_Init(@goScn)
Scn_Write(@goScn,1,1,"Welcome to KardTech Fuels")
;Scn_Picture(@goScn,"doc/CompanyLogo.bmp",3,0)
FlipBuffers() ; Why is FlipBuffers() need here?
Delay(5000)
Scn_Clear(@goScn)
Scn_Write(@goScn,1,0,"Enter PIN:")
Scn_Append(@goScn,"1")
lnSec=ElapsedMilliseconds()
Repeat
Scn_Append(@goScn,"*") ;Why is FlipBuffers() not needed here?
Delay(500)
Until ElapsedMilliseconds() - lnSec > 5000
EndIf