j'essaie de porter un ancien programme Lazarus et Qt réalisé quand j'étais enseignant : un petit traceur de courbes en coordonnées cartésiennes.
J'en suis au traçage du repère (la 1ère étape).
Code : Tout sélectionner
EnableExplicit
Enumeration Windows
#WdwMain
#CvsGrid
#BarStatus
EndEnumeration
Enumeration FontID
#CvsFont
EndEnumeration
Global WdwLargeur.i = 800 ; La Largeur de la fenêtre.
Global WdwHauteur.i = 600 ; La Hauteur de la fenêtre.
Global WdwOptions.i = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered
Global uX.i ; Espace entre 2 lignes verticales.
Global uY.i ; Espace entre 2 lignes horizontales.
Global CvsGridWidth.i = WdwLargeur.i ; La Largeur de la grille.
Global CvsGridHeight.i = WdwHauteur.i - 22 ; La Hauteur de la grille (-22 pour la barre de status).
Global CvsGridLineColor.i = RGBA(88,88,88,255) ; La couleur des lignes (un gris).
Global CvsGridBgColor.i = RGB(255, 255, 255) ; La couleur d'arrière plan de la grille.
Declare Exit()
Declare Paint()
Procedure WdwMain()
; Ouverture de la fenêtre.
OpenWindow(#WdwMain, 0, 0, WdwLargeur, WdwHauteur, "Représentation graphique", WdwOptions.i)
; Création du canvas.
CanvasGadget(#CvsGrid, 0, 0, CvsGridWidth.i, CvsGridHeight.i)
; Création de la barre de status.
CreateStatusBar(#BarStatus, WindowID(#WdwMain))
AddStatusBarField(#PB_Ignore)
Paint()
; On place un Callback pour la fernmeture de la fenêtre.
BindEvent(#PB_Event_CloseWindow, @Exit(), #WdwMain)
; On place un Callback pour le repaint de la fenêtre.
BindEvent(#PB_Event_SizeWindow, @Paint(), #WdwMain)
EndProcedure
Procedure Exit()
End
EndProcedure
Procedure Paint()
uX.i = Int(WindowWidth(EventWindow())/10)
uY.i = Int(WindowHeight(EventWindow())/10)
LoadFont(#CvsFont, "Verdana", Int(Sqr(WindowWidth(EventWindow())* WindowHeight(EventWindow()))/48), #PB_Font_Bold)
ResizeGadget(#CvsGrid, #PB_Ignore, #PB_Ignore, WindowWidth(EventWindow()), WindowHeight(EventWindow())-22)
StartDrawing(CanvasOutput(#CvsGrid))
Box(0, 0, WindowWidth(EventWindow()), WindowHeight(EventWindow()) , CvsGridBgColor.i)
StopDrawing()
StartVectorDrawing(CanvasVectorOutput(#CvsGrid))
VectorSourceColor(CvsGridLineColor)
Define Index.i
For Index.i = 1 To 10
AddPathSegments( "M " +Str(Index.i*uX.i) +" 0" +" L " +Str(Index.i*uX.i) +" " +Str(WindowHeight(EventWindow())) )
AddPathSegments( "M 0 " +Str(Index.i*uY.i) +" L " +Str(WindowWidth(EventWindow())) +" " +Str(Index.i*uY.i) )
If Index.i = 5
StrokePath(3, #PB_Path_RoundCorner)
Else
StrokePath(1, #PB_Path_Default)
EndIf
Next
VectorFont(FontID(#CvsFont))
Define Text$
Text$ = "0"
MovePathCursor(5*uX.i -VectorTextWidth(Text$, #PB_VectorText_Visible) -Int(uX.i/10), 5*uY.i +Int(uY.i/10))
DrawVectorText(Text$)
Text$ = "1"
MovePathCursor(6*uX.i -VectorTextWidth(Text$, #PB_VectorText_Visible) -Int(uX.i/10), 5*uY.i +Int(uY.i/10))
DrawVectorText(Text$)
MovePathCursor(5*uX.i -VectorTextWidth(Text$, #PB_VectorText_Visible) -Int(uX.i/10), 4*uY.i +Int(uY.i/10))
DrawVectorText(Text$)
Text$ = "x"
MovePathCursor(10*uX.i -VectorTextWidth(Text$, #PB_VectorText_Visible) -Int(uX.i/10), 5*uY.i +Int(uY.i/20))
DrawVectorText(Text$)
Text$ = "y"
MovePathCursor(5*uX.i -VectorTextWidth(Text$, #PB_VectorText_Visible) -Int(uX.i/10), Int(uY.i/20))
DrawVectorText(Text$)
StopVectorDrawing()
EndProcedure
; Ouverture de la fenêtre.
WdwMain()
Repeat
WaitWindowEvent(1)
ForEver
1. Y a-t-il un moyen d'effacer l'écran en VectorDrawing ? J'utilise
Code : Tout sélectionner
StartDrawing(CanvasOutput(#CvsGrid))
Box(0, 0, WindowWidth(EventWindow()), WindowHeight(EventWindow()) , CvsGridBgColor.i)
StopDrawing()
2. Y a-t-il un moyen de dessiner un axe terminé par une flèche ? (Justement pour les axes du repère). J'ai bien trouvé
Code : Tout sélectionner
StrokePath(3, #PB_Path_RoundCorner)
3. En Qt, j'ai réussi à porter mon programme sur tablette. Régulièrement j'évalue les capacités de Qt en mobile. Je l'avais fait en Delpi FMX et en Windev Mobile mais pas en Qt. C'est possible maintenant. Donc est-ce que SpiderBasic serait capable d'utiliser un code quasi-identique (je ne parle pas du redimensionnement de la fenêtre mais d'une approche identique (CanvasOutput et CanvasVectorOutput)
Merci. Cordialement. Gilles
PS : je travaille sous macOS 10.13.2 - Code portable sous Windows mais je n'ai pas encore vérifié sa portabilité sur Linux

Question subsidiaire : pourquoi ce genre d'appellations : #PB_Path_RoundCorner, AddPathSegments, StrokePath.. Que vient faire le "path" là-dedans ?