In an earlier post I mentioned that before, but the problem was slow loading in a list gadget.
Loading an array with data from a file is much faster than a list gadget.
I have to process a text file of thousands of lines of graphic data.These data are just strings with XYZ coordinates.I want to zoom, move and rotate the data on the srceen.
Drawing only 500 rectangles already takes a long time.
I don't understand what I'm doing wrong, when I look at other graphics programs it all goes very quickly
Code: Select all
Enumeration
#main_win: #font
#F1 ;functietoets met add
#canvas
#test_File:#list1
EndEnumeration
;-------------------------------------------------------
Global win_color.l=RGB(115,122,121)
Global x1,y1 ;start line
Global X2,Y2 ;end line
Global line_color.l
Global starttime.q,endtime.q,time.q
Global Dim my_line.s(100)
Global Dim test.s(100001)
;-------------------------------------------------------
Declare sneltoets()
;-------------------------------------------------------
LoadFont(#font,"caladea",18, #PB_Font_Italic|#PB_Font_Bold)
flags=#PB_Window_SystemMenu;| #PB_Window_Maximize;#PB_Window3D_Borderless;|#PB_Window_ScreenCentered
;array with lines
my_line(1)="100,100,200,100"
my_line(2)="200,100,200,200"
my_line(3)="200,200,100,200"
my_line(4)="100,200,100,100"
;-------------------------------------------------------
Procedure make_test_file();make a file with 100000 lines of strings
Define fo
Define n.l
fo = CreateFile(#test_File, "test_file.txt")
For n=0 To 100000
WriteStringN(#test_file,Str(n)+"x100,y100,z100")
Next
EndProcedure
;---------------------------------------------------
Procedure test_array_speed();it takes 55 ms !!
number_lines.l=0
StartTime.q = ElapsedMilliseconds()
If OpenFile( #test_file, "test_file.txt") ; opens an existing file or creates one, if it does not exist yet
ReadFile( #test_file, "test_file.txt") ; if the file could be read, we continue...
While Eof( #test_file) = 0 ; loop as long the 'end of file' isn't reached
test(number_lines)=Str(number_lines)+" "+ReadString(#test_file)
number_lines= number_lines+1
; Debug ReadString(#file) ; display line by line in the debug window
Wend
CloseFile( #test_file)
EndIf
endtime.q= ElapsedMilliseconds()
time=endtime-StartTime
Debug "time_array = "+time
Debug "lines="+number_lines
EndProcedure
;------------------------------------------------------------
Procedure list_speed();it takes 11398 ms
StartTime.q = ElapsedMilliseconds()
number_lines.l=0
If OpenFile( #test_file, "test_file.txt") ; opens an existing file or creates one, if it does not exist yet
ReadFile( #test_file, "test_file.txt") ; if the file could be read, we continue...
While Eof( #test_file) = 0 ; loop as long the 'end of file' isn't reached
AddGadgetItem (#list1, -1, Str(number_lines)+" "+ReadString(#test_file)) ; define listview content
number_lines= number_lines+1
; Debug ReadString(#file) ; display line by line in the debug window
Wend
CloseFile( #test_file);SetActiveGadget(#main_window)
EndIf
endtime.q= ElapsedMilliseconds()
time=endtime-StartTime
Debug "time_list = "+time
Debug "lines="+number_lines
EndProcedure
;-----------------------------------------------------
Procedure tekenlijn(a1,b1,a2,b2)
StartDrawing(CanvasOutput(#canvas))
LineXY(a1,b1,a2,b2,line_color)
StopDrawing()
EndProcedure
;------------------------------------------------------------------------
Procedure draw_box(mx,my) ;draw 500 box
Define u,t,n,e
Define l$
For e=1 To 500 ;number of box
t=Random(400) ;random y position
u=Random(400) ;random x position
For n=1 To 4
l$=my_line(n)
x1= ValD(StringField(l$,1,","))
Y1= ValD(StringField(l$,2,","))
x2= ValD(StringField(l$,3,","))
Y2= ValD(StringField(l$,4,","))
tekenlijn(X1+mx+u,y1+my+t,x2+mx+u,y2+my+t)
Next
Next
EndProcedure
;----------------------------------------------------------
Procedure OnCanvasEvents()
Protected mX, mY, y
mX = GetGadgetAttribute(#canvas, #PB_Canvas_MouseX)
mY = GetGadgetAttribute(#canvas, #PB_Canvas_MouseY)
Select EventType()
Case #PB_EventType_MouseMove, #PB_EventType_LeftClick
If GetGadgetAttribute(#canvas, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton
StartDrawing(CanvasOutput(#canvas))
Box( 0,0,880,600,$F3F3F3) ;clear canvas
line_color=$D1101F
StopDrawing()
draw_box(mx,my)
EndIf
EndSelect
EndProcedure
;-----------------------------------------------------------------------
If OpenWindow (#main_win,0,0,1200,900, "box test" ,flags )
CanvasGadget(#canvas,10,10,880,600)
ListViewGadget(#list1,900,200,200,400)
make_test_file()
list_speed() ;test the time for listview
test_array_speed();test time for fill an array
BindGadgetEvent(#canvas, @OnCanvasEvents(), #PB_All)
sneltoets()
Repeat
Ev = WaitWindowEvent()
Select ev ;
Case #PB_Event_Gadget
Select EventGadget()
Case #F1 ;main
; tekenlijn(x1,y1,x2,y2)
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case #F1
;tekenlijn(x1,y1,x2,y2)
EndSelect
EndSelect
Until ev=#PB_Event_CloseWindow
EndIf
End
;--------------------------------------------------------
Procedure sneltoets() ;sneltoetsen voor keybord events
AddKeyboardShortcut(#main_win, #PB_Shortcut_F1,#F1)
EndProcedure