Code : Tout sélectionner
EnableExplicit
UseSQLiteDatabase()
#MainForm=0
#MainArea=0
#MainCanvas=1
Structure item
id.i
X.i
Y.i
EndStructure
Global NewList myItem.item()
Global WF,HF,W=10,gMouseX,gMouseY,Db
Procedure Exit()
End
EndProcedure
Procedure WhereIsMouse()
Protected CurrentTime,TimeElapsed,query.s
CurrentTime=ElapsedMilliseconds()
; Recherche de l'item depuis la Db
query="SELECT id FROM item WHERE (X1<="+Str(gMouseX)
query+" AND X2>="+Str(gMouseX)+") AND ("
query+"Y1<="+Str(gMouseY)+" AND Y2>="+Str(gMouseY)+")"
If DatabaseQuery(Db,query)=0
MessageRequester("Erreur",DatabaseError())
End
EndIf
If FirstDatabaseRow(Db)<>0
SelectElement(myItem(),GetDatabaseLong(Db,0))
FinishDatabaseQuery(Db)
TimeElapsed=ElapsedMilliseconds()-CurrentTime
SetGadgetAttribute(#MainCanvas,#PB_Canvas_Cursor,#PB_Cursor_Hand)
Debug "Vous êtes sur l'item "+Str(myItem()\id)+" le temps nécessaire est de "+Str(TimeElapsed)+" milisecondes"
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
Procedure EventCanvas()
Select EventType()
Case #PB_EventType_MouseMove
gMouseX=GetGadgetAttribute(#MainCanvas,#PB_Canvas_MouseX)
gMouseY=GetGadgetAttribute(#MainCanvas,#PB_Canvas_MouseY)
If WhereIsMouse():ProcedureReturn :EndIf
SetGadgetAttribute(#MainCanvas,#PB_Canvas_Cursor,#PB_Cursor_Default)
EndSelect
EndProcedure
Procedure MakeMemorisDb()
Protected query.s
Db=OpenDatabase(#PB_Any,":memory:","","")
query="CREATE TABLE item ("
query+"id INTEGER,"
query+"X1 INTEGER,"
query+"X2 INTEGER,"
query+"Y1 INTEGER,"
query+"Y2 INTEGER)"
If DatabaseUpdate(Db,query)=0
MessageRequester("Erreur",DatabaseError())
End
EndIf
EndProcedure
Procedure AddItemToMemoris(X,Y)
Protected query.s
query="INSERT INTO item ("
query+"id,X1,Y1,X2,Y2) VALUES ("
query+Str(ListIndex(myItem()))+","+Str(X)+","+Str(Y)+","+Str(X+W)+","+Str(Y+W)+")"
If DatabaseUpdate(Db,query)=0
MessageRequester("Erreur",DatabaseError())
End
EndIf
EndProcedure
Procedure DrawSample()
Protected X,Y,N
; Dessine des carrés sur le canvas
StartDrawing(CanvasOutput(#MainCanvas))
For X=W To 3000-W Step 0
Y=W
For Y=W To 3000-W Step 0
N+1
Box(X,Y,W,W,$00FC7C)
; Ajout de l'item à la liste
AddElement(myItem())
With myItem()
\id=N
\X=X
\Y=Y
AddItemToMemoris(\X,\Y)
EndWith
Y+(W*2)
Next
X+(W*2)
Next
StopDrawing()
EndProcedure
Procedure OpenMainForm()
Protected flag=#PB_Window_SystemMenu|#PB_Window_Maximize
MakeMemorisDb()
OpenWindow(#MainForm,0,0,800,600,"teste",flag)
WF=WindowWidth(#MainForm)
HF=WindowHeight(#MainForm)
ScrollAreaGadget(#MainArea,0,0,WF,HF,3000,3000)
CanvasGadget(#MainCanvas,0,0,3000,3000)
CloseGadgetList()
DrawSample()
SetGadgetAttribute(#MainArea,#PB_ScrollArea_X,3000)
SetGadgetAttribute(#MainArea,#PB_ScrollArea_Y,3000)
BindEvent(#PB_Event_CloseWindow,@Exit(),#MainForm)
BindGadgetEvent(#MainCanvas,@EventCanvas())
EndProcedure
OpenMainForm()
Repeat:WaitWindowEvent():ForEver