slow drawing
slow drawing
i am trying to make a gcodesender for the arduino.
gcode file is a textfile that commands the machine.
I save the file in a list gadget and decode the gcode, I draw the result on the canvas, but that is very slow.
When I go to similar programs, there you have zoom ,rotate and move very fast, why is PB so slow or what am I doing wrong?
gcode file is a textfile that commands the machine.
I save the file in a list gadget and decode the gcode, I draw the result on the canvas, but that is very slow.
When I go to similar programs, there you have zoom ,rotate and move very fast, why is PB so slow or what am I doing wrong?
Re: slow drawing
It could be any number of things. Without a code sample and sample data it is not really possible to narrow it down much.ludoke wrote:i am trying to make a gcodesender for the arduino.
gcode file is a textfile that commands the machine.
I save the file in a list gadget and decode the gcode, I draw the result on the canvas, but that is very slow.
When I go to similar programs, there you have zoom ,rotate and move very fast, why is PB so slow or what am I doing wrong?
Re: slow drawing
I have had to remove a lot of code because of the 60000 character limit.
Code: Select all
EnableExplicit
CompilerIf #PB_Compiler_Thread = 0
CompilerError "Use Option Threadsafe!"
CompilerEndIf
#COMMaxPorts = 30
Enumeration #PB_Event_FirstCustomValue
#ComThread_Started
#ComThread_ByteReceived
#ComThread_LineReceived
#ComThread_Finished
EndEnumeration
Enumeration
#ComText
#Combo
#btn_connect
#SendText
#SendString
#SendButton
#ReceiveText
#ReceiveEdit
#status
EndEnumeration
Structure ThreadParameterStructure
Thread.i
Semaphore.i
Com$
Com.i
Receive$
Exit.i
EndStructure
Global NewList COMUsablePorts.s()
Global ThreadParameter.ThreadParameterStructure
Procedure COMGetAvailablePorts()
Protected NewList COMPortNameList.s()
Protected i.i, Directory.i, Com.i
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
For i = 1 To #COMMaxPorts
AddElement(COMPortNameList())
COMPortNameList() = "COM" + Str(i)
Next i
CompilerEndIf
ForEach COMPortNameList()
Com = OpenSerialPort(#PB_Any, COMPortNameList(), 115200, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1, 1)
If Com
AddElement(COMUsablePorts())
COMUsablePorts() = COMPortNameList()
CloseSerialPort(Com)
EndIf
Next
FreeList(COMPortNameList())
EndProcedure
;----------------------------------------------------
Procedure ComThread(*Parameter.ThreadParameterStructure)
Protected Byte.a, ReceivedBytes.i
PostEvent(#ComThread_Started)
*Parameter\Com = OpenSerialPort(#PB_Any, *Parameter\Com$, 115200, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
If *Parameter\Com
WriteSerialPortString(*Parameter\Com, #CR$ + #CR$ + #CR$)
Repeat
If AvailableSerialPortInput(*Parameter\Com)
If ReadSerialPortData(*Parameter\Com, @Byte, 1) = 1
ReceivedBytes + 1
PostEvent(#ComThread_ByteReceived, 0, 0, 0, ReceivedBytes)
If Byte = #CR
PostEvent(#ComThread_LineReceived)
WaitSemaphore(*Parameter\Semaphore)
Else
*Parameter\Receive$ + Chr(Byte)
; Debug *Parameter\Receive$
EndIf
EndIf
Else
Delay(10)
EndIf
Until *Parameter\Exit
CloseSerialPort(*Parameter\Com)
EndIf
PostEvent(#ComThread_Finished)
EndProcedure
;-----------------enumerrations ---------------------------------------------
Enumeration
;----------------- main window ----------------------------
#main_window
#menu
#M_open:#M_edit:#M_save:#M_save_as:#M_close:#M_notepad:#M_exit:#M_setup:#M_about
#M_CSS:#M_help
#file_info:#btn_redraw
#list1
;------ homing ---------------------------
#cont_home
#btn_homeX:#btn_homeY:#btn_homeZ:#btn_homeA
#txt_home:#txt_homeX:#txt_homeY:#txt_homeZ:#txt_homeA
#txt_homeX_LED:#txt_homeY_LED:#txt_homeZ_LED:#txt_homeA_LED
;------ port ---------------------------
#cont_port
#txt_com
#txt_status
;----------- zeroing ----------------------------------
#cont_zero
#txt_zero:#txt_X:#txt_Z
#str_zeroX:#str_zeroZ
;----------- auto ----------------------
#cont_auto:
#btn_start:#btn_stop:#btn_rewind:#btn_single: #btn_pauze
#txt_auto:#txt_pauze_led:#txt_single_led: #txt_go:#txt_stop_led:#txt_run_led
#str_go
;--------- stepsize ---------------------------
#cont_stepsize
#txt_size:#txt_size1
#stepsize
#jog_x_plus :#jog_x_min:#jog_y_plus:#jog_y_min:#jog_Z_min:#jog_Z_plus:#jog_A_min:#jog_A_plus
;--------- spindel --------------
#scroll_spindel
#cont_spindel
#txt_spindel
#txt_spindel_on_LED
#txt_riem
#txt_rpm
#btn_spindel_on:#btn_spindel_off
;------------ DRO ------------------
#btn_coord
#cont_DRO
#txt_dro:#txt_dro_x: #txt_dro_xw:#str_dro_xw
#txt_dro_Y: #txt_dro_yw:#str_dro_yw
#txt_dro_z: #txt_dro_zw:#str_dro_zw
#txt_dro_a: #txt_dro_aw:#str_dro_aw
;----------- Machine DRO ---------------------------
#cont_mDRO
#txt_mdro
#txt_mdro_x:#txt_mdro_xm
#txt_mdro_y:#txt_mdro_ym
#txt_mdro_z:#txt_mdro_zm
#txt_mdro_a:#txt_mdro_am
;------ voeding --------------------------------
#cont_feed:#btn_reset_feed
#cont_feed_toer
#txt_feed_toer:#txt_feed_toer1:#txt_feed:#txt_feed1
#scroll_feed_toer:#scroll_feed
;------ MDI ------------
#edit_mdi:#cont_mdi
#txt_mdi
#str_mdi
#btn_mdi_preview
#btn_mdi_go
#btn_mdi_clear
;--------------- screen move zoom ------------------------
#btn_zoom_plus:#btn_zoom_min
#cont_screen
#btn_left:#btn_right:#btn_up:#btn_down
;------------ allerlei toetsen ----------------------------
#F1
#setting_file
#canvas:#canvas1:#canvas_work
#file:#dummy
EndEnumeration
; -------------end enumerations ------------------
Global x_step_mm.d=800 ,Z_step_mm.d=800
Global X_accel=2000,X_Deccel=50, Z_accel=2000,Z_deccel=50
Global X_spel.d=0.01 , Z_spel.d=0.01
Global X_min.d=0, X_MAx.d=400
Global Z_min.d =0,Z_max.d=300
Global y_min.d=0,y_max.d=300
Global xw_new.d,yw_new.d,zw_new.d,aw_new.d
Global Xw_old.d,yw_old.d,zw_old.d,aw_old.d
Global xm_new.d,ym_new.d,zm_new.d,am_new.d
Global xm_old.d,ym_old.d,zm_old.d,am_old.d
Global xrad_old.d,xrad_new.d
Global Dim Stap.d(4)
Global metric.d=1
Global x_steps,z_steps
Global n,teller
Global enter=0
Global lijn$
Global temp$
Global mm_inch$="mm"
Global temp,teller
;-------------------------------------------------------
Global Flags = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
Global win_color.l=$3B2B22
Global win_setup_color.l=$8F807E
Global Con_color=$513B2F
Global text_vgcol=$B5F8F5
Global text_agcol= $77EDE90
Global cont_backcolor=$513B2F
Global off_color=$72975E
Global on_color=$031BF6
Global work_zone_color=0
Global font6,font8,font10,font12,font18,font24,font34
Global result_x,result_Y
Global xa,xextra,yextra
Global coord=1
;-----------------------------------------
Global aantal_lijnen
Global lengte, kar_positie=0, einde_lijn=0
Global k$="",g_code$=""
Global mode=0
Global redraw=0
Global tool$,m_code$,opmerking$
Global appquit=0
Global file$
Global voeding=50
Global V_max.i,ijlgang,voeding
Global voeding$,feed$,I_mm$,V_max$,feed
Global rpm_max,rpm
Global stepsize.d=0.01
Global spindle_Status=0
Global single_line=0
Global start=0
Global i_code$,J_code$,K_code$,x_new$,y_new$,z_new$,a_new$,code$,waarde$
Global i_code.d,j_code.d,k_code.d
Global temp$
Global gcode_bepaald=0 ;
Global mdi_preview=0,mdi_go=0
Global preview=0
Global straal.d
Global angle.d
Global starthoek.d,eindhoek.d
#Epsilon=0.0001
#Draw100=$FF000000
;---------------screen canvas --------------------------------
Global x_canvas.d=800 ,y_canvas.d=400
Global x_off.d=400,y_off.D=200
Global zoom.d=1
Global g_color.q=$ffFFFAFF
Global G0_color.q=$ff7E7E80
Global G1_color.q=$ff60EAE9
Global G2_color.q=$ffFF31FF
Global G3_color.q=$ff00EAE1
Global x_canvas_old.d,X_canvas_new.d,y_canvas_old.d,y_canvas_new.d
Global redraw=0
Global ma.d,mb.d,wa.d,wb.d,xcenter.d,ycenter.d,i2.d,j2.d,oops.d
Global i.d,k.d,j.d
Declare auto()
Declare checkFloatInput(gadget, bNegativeOK.b = #True, bNegativeIntegers.b = #False)
Declare css_window()
Declare clear_canvas()
Declare do_arc_move()
Declare do_move()
Declare draw_arc()
Declare draw_grid()
Declare dro();
Declare file_frame()
Declare feed_setting()
Declare gcode_uitvoeren()
Declare home()
Declare init_vars()
Declare load_data()
Declare load_file()
Declare load_fonts()
Declare main_window()
Declare mdi_input()
Declare M_DRO()
Declare menu()
Declare opmerking()
Declare opmerking1()
Declare OnGadgetEvent()
;Declare onchangeevent()
Declare ontrafel()
Declare ontrafel_old()
Declare onwindowEvent()
Declare port()
Declare redraw()
Declare setup_button();
Declare save_data()
Declare save_file()
Declare save_as_file()
Declare save_tooltabel()
Declare SetButtonColor(Id, text$,text_color, back_color)
Declare set_machine_coord_active()
Declare set_work_coord_active()
Declare screen_pos()
Declare spindel()
Declare spindel_ON_OFF()
Declare sneltoets()
Declare stapgrootte()
Declare stepsize()
Declare test_limieten()
Declare tool_setup_window()
Declare uncheck_rpm()
Declare update_canvas()
;Declare update_draw_arc()
Declare update_DRO_X()
Declare update_DRO_Z()
Declare update_positie()
Declare update_screen()
Declare vind_waarde()
Declare voeding()
Declare zero()
COMGetAvailablePorts()
main_window()
sneltoets()
BindEvent(#PB_Event_Gadget, @OnGadgetEvent())
init_vars()
#MenuEvent_ReturnKey = 1000
;---------------------------------------------------------------
Procedure DoEventGadgetType()
Protected gadget = EventGadget()
If IsGadget(gadget)
Select GadgetType(gadget)
Case #PB_GadgetType_String
Select EventType()
Case #PB_EventType_Focus
SetGadgetText(gadget,"0.0") ;set predefined text
AddKeyboardShortcut(#main_window, #PB_Shortcut_Return, #MenuEvent_ReturnKey)
SetGadgetColor(gadget, #PB_Gadget_BackColor,$E0E292);set color blue
Case #PB_EventType_LostFocus
RemoveKeyboardShortcut(#main_window, #PB_Shortcut_Return)
SetGadgetColor(gadget, #PB_Gadget_BackColor, $C7F5F6 );reset to color
EndSelect
EndSelect
EndIf
EndProcedure
;----------------------------------------------------------------------------------------------
Procedure DoEventReturnKey()
PostEvent(#PB_Event_Gadget, GetActiveWindow(), GetActiveGadget(), #PB_EventType_ReturnKey)
EndProcedure
;----------------------------------------------------------------
Define event
Repeat
Event = WaitWindowEvent()
Select EventWindow()
Case #main_Window
Select Event
Case #ComThread_Started
SetGadgetText(#btn_Connect, "DISCONNECT")
DisableGadget(#Combo, #True)
SetGadgetText(#txt_status,"CONNECTED"):SetGadgetColor(#txt_status,#PB_Gadget_BackColor,$49F31E)
Case #ComThread_LineReceived
; AddGadgetItem(#ReceiveEdit, -1, ThreadParameter\Receive$)
; Debug ThreadParameter\Receive$
ThreadParameter\Receive$ = ""
SignalSemaphore(ThreadParameter\Semaphore)
Case #ComThread_Finished
SetGadgetText(#btn_Connect, "CONNECT")
DisableGadget(#Combo, #False)
SetGadgetText(#txt_status,"DISCONNECTED"):SetGadgetColor(#txt_status,#PB_Gadget_BackColor,$491EF3)
Case #PB_Event_CloseWindow
appquit=1
Case #PB_Event_Gadget
Select EventGadget()
Case #btn_reset_feed
SetGadgetState(#scroll_feed,100) : feed_setting()
Case #scroll_feed
feed_setting()
Case #btn_redraw
zoom=1:
redraw()
update_screen()
Case #btn_zoom_plus
zoom=zoom*2
redraw():update_screen()
Case #btn_zoom_min
zoom=zoom/2
redraw():update_screen()
Case #btn_left
x_off=x_off-50
redraw():update_screen()
Case #btn_right
x_off=x_off+50
redraw():update_screen()
Case #btn_down
y_off=y_off+50
redraw():update_screen()
Case #btn_up
y_off=y_off-50
redraw():update_screen()
Case #str_dro_xw
If coord=1
Select EventType()
Case #PB_EventType_ReturnKey
SetActiveGadget(#dummy)
EndSelect
EndIf
Case #str_dro_yw
If coord=1
Select EventType()
Case #PB_EventType_ReturnKey
SetActiveGadget(#dummy)
EndSelect
EndIf
Case #str_dro_zw
Select EventType()
Case #PB_EventType_ReturnKey
SetActiveGadget(#dummy)
EndSelect
Case #str_dro_aw
If coord=1
Select EventType()
Case #PB_EventType_ReturnKey
SetActiveGadget(#dummy)
EndSelect
EndIf
Case #btn_spindel_on
spindel_ON_OFF()
Case #btn_Connect
If GetGadgetText(#btn_Connect) = "CONNECT"
ThreadParameter\Com$ = GetGadgetText(#Combo)
ThreadParameter\Exit = #False
ThreadParameter\Thread = CreateThread(@ComThread(), @ThreadParameter)
Else
ThreadParameter\Exit = #True
EndIf
Case #btn_homeX
SetGadgetColor(#txt_homex_led, #PB_Gadget_BackColor,($0CFD00))
xM_new=x_min: update_screen()
Case #btn_homey
SetGadgetColor(#txt_homey_led, #PB_Gadget_BackColor,($0CFD00))
xm_new=y_min: update_screen()
Case #btn_homeZ
SetGadgetColor(#txt_homeZ_led, #PB_Gadget_BackColor,($0CFD00))
zM_new=z_max: update_screen()
EndSelect
;*****************************************
Case #PB_Event_Menu
Select EventMenu()
Case #btn_left
x_off=x_off-20:update_screen()
Case #btn_right
x_off=x_off+20:update_screen()
Case #jog_x_plus
xw_new=xw_old+stepsize : xM_new=xm_old+stepsize
mode=1:update_screen()
Case #jog_x_min
xw_new=xw_old-stepsize : xM_new=xm_old-stepsize
mode=1:update_screen()
Case #jog_y_plus
yw_new=yw_old+stepsize : yM_new=ym_old+stepsize
mode=1:update_screen()
Case #jog_y_min
yw_new=yw_old-stepsize : yM_new=xm_old-stepsize
mode=1:update_screen()
Case #jog_Z_min
zw_new=zw_old-stepsize : zM_new=zm_old-stepsize
mode=1:update_screen()
Case #jog_Z_plus
zw_new=zw_old+stepsize : zM_new=zm_old+stepsize
mode=1:update_screen()
Case #jog_a_min
aw_new=aw_old-stepsize : aM_new=am_old-stepsize
mode=1:update_screen()
Case #jog_a_plus
aw_new=aw_old+stepsize : aM_new=am_old+stepsize
mode=1:update_screen()
Case #M_open
load_file()
Case #M_edit
Case #M_save
save_file()
Case #M_save_as
save_as_file()
Case #M_close
If ReadFile(#file, file$) :CloseFile(#file)
file$="":SetGadgetText(#file_info,file$)
ClearGadgetItems(#list1)
redraw() :EndIf
Case #M_exit ;einde
appquit=1
Case #M_notepad ;open notepad
RunProgram("notepad.exe")
Case #stepsize
stapgrootte()
EndSelect
EndSelect
EndSelect
Until appquit=1
;--------------------------------------------------------
If IsThread(ThreadParameter\Thread)
ThreadParameter\Exit = #True
If WaitThread(ThreadParameter\Thread, 3000) = 0
KillThread(ThreadParameter\Thread)
EndIf
EndIf
FreeSemaphore(ThreadParameter\Semaphore)
End
;-----------------------schermopbouw --------------------------------------------
Procedure main_window()
result_x=1366:result_y=768
load_fonts()
OpenWindow (#main_window,0,0,result_x,result_y, "LUDO CNC" ,flags )
SetWindowColor(#main_window,win_color):SetGadgetFont(#PB_Any,FontID(font10))
If CreateMenu(#menu, WindowID(#main_window))
MenuTitle("FILE")
MenuItem(#M_open, "OPEN" )
MenuItem(#M_edit, "EDIT")
MenuItem(#M_close,"CLOSE")
MenuItem(#M_save,"SAVE")
MenuItem(#M_save_as,"SAVE AS")
MenuItem(#M_exit, "EXIT" )
MenuItem(#M_notepad,"NOTEPAD")
MenuItem(#M_about,"ABOUT")
MenuTitle("SETUP")
EndIf
menu()
TextGadget(#file_info,950,440,400,20,"GEEN FILE")
ListViewGadget(#list1,950,460,400,120)
TextGadget(#dummy,0,600,1,1,"")
ButtonGadget(#btn_coord,850,180,170,25,"WORK / MACH") :coord=1
CanvasGadget(#canvas,20,20,800,400)
clear_canvas()
init_vars()
port()
home()
dro():m_dro(): HideGadget(#cont_mDRO, 1)
auto()
screen_pos()
spindel()
stepsize()
voeding()
mdi_input()
CreateMenu(#main_window, WindowID(#main_window))
BindEvent(#PB_Event_Gadget, @DoEventGadgetType())
BindMenuEvent(#main_window, #MenuEvent_ReturnKey, @DoEventReturnKey())
EndProcedure
;---------------------------------------------------------------------
Procedure mdi_input()
ContainerGadget(#cont_mdi,950,590,400,150,#PB_Container_Raised ): SetGadgetColor(#cont_home, #PB_Gadget_BackColor, Con_color)
SetGadgetFont(#PB_Default, FontID(font10))
TextGadget(#txt_mdi,5,5,80,15,"MDI INPUT")
ButtonGadget(#btn_mdi_preview,300,25,90,30,"PREVIEW")
ButtonGadget(#btn_mdi_go,300,65,90,30,"RUN MDI")
ButtonGadget(#btn_mdi_clear,300,105,90,30,"MDI CLEAR")
EditorGadget(#edit_mdi, 1, 25, 285, 115)
EndProcedure
;------------------------------------------------------------------------
Procedure auto()
Define xk.i=10 ,yk.i=40
Define xb.i=100 , yh=30,yt=50 ,xt=120
ContainerGadget(#cont_auto,185,530,265,210,#PB_Container_Raised)
SetGadgetColor(#cont_auto, #PB_Gadget_BackColor, Con_color )
SetGadgetFont(#PB_Default, FontID(font12))
TextGadget(#txt_auto,40,10,190,20,"AUTO (ctrl+key)")
SetGadgetColor(#txt_auto, #PB_Gadget_FrontColor,text_vgcol):SetGadgetColor(#txt_auto, #PB_Gadget_BackColor, Con_color )
ButtonGadget(#btn_start,xk,yk,90,yh ,"RUN",#PB_Button_Toggle )
TextGadget(#txt_run_led,105,yk,15,yh," "):SetGadgetColor(#txt_run_led, #PB_Gadget_BackColor, off_color)
ButtonGadget(#btn_pauze,xk+xt,yk,xb,yh ,"(P)AUZE",#PB_Button_Toggle )
TextGadget(#txt_pauze_led,xk+xt+xb+5,yk,15,yh," "):SetGadgetColor(#txt_pauze_led, #PB_Gadget_BackColor, off_color)
ButtonGadget(#btn_rewind,xk,yk+yt,xb,yh ,"RE(W)IND")
ButtonGadget(#btn_single,xk+xt,yk+yt,xb,yh,"SING(L)E",#PB_Button_Toggle )
TextGadget(#txt_single_led,xk+xt+xb+5,yk+yt,15,yh," "):SetGadgetColor(#txt_single_led, #PB_Gadget_BackColor, $6565A6)
TextGadget(#txt_go,xk,yk+2*yt,xb,20,"GO(T)O LINE", #PB_Text_Center )
StringGadget(#str_go,xk+xt,yk+2*yt,xb,yh ,"")
CloseGadgetList()
EndProcedure
;-------------------------------------------------------------------------------------
Procedure DRO()
ContainerGadget(#cont_DRO,850,20,170,150, #PB_Container_Raised )
SetGadgetColor(#cont_DRO, #PB_Gadget_BackColor, Con_color )
TextGadget(#txt_dro,15,5,190,20,"WORK COORDINATE "+ mm_inch$)
SetGadgetFont(#txt_dro, FontID(font8))
SetGadgetColor(#txt_dro, #PB_Gadget_BackColor,0):SetGadgetColor(#txt_dro, #PB_Gadget_FrontColor, $C7F5F6)
SetGadgetFont(#PB_Default, FontID(font18))
TextGadget(#txt_dro_x,10,25,36,26," X "):SetGadgetColor(#txt_dro_X, #PB_Gadget_BackColor, $C7F5F6 )
StringGadget(#str_dro_xw,55,25,100,26,"0.00") :SetGadgetColor(#str_dro_xw, #PB_Gadget_BackColor, $C7F5F6 )
TextGadget(#txt_dro_y,10,55,36,26," Y "):SetGadgetColor(#txt_dro_y, #PB_Gadget_BackColor, $C7F5F6 )
StringGadget(#str_dro_yw,55,55,100,26,"0.00") :SetGadgetColor(#str_dro_yw, #PB_Gadget_BackColor, $C7F5F6)
TextGadget(#txt_dro_z,10,85,36,26," Z ") :SetGadgetColor(#txt_dro_z, #PB_Gadget_BackColor, $C7F5F6)
StringGadget(#str_dro_zw,55,85,100,26,"0.00") :SetGadgetColor(#str_dro_zw, #PB_Gadget_BackColor, $C7F5F6 )
TextGadget(#txt_dro_a,10,115,36,26," A ") :SetGadgetColor(#txt_dro_a, #PB_Gadget_BackColor, $C7F5F6)
StringGadget(#str_dro_aw,55,115,100,26,"0.00") :SetGadgetColor(#str_dro_aw, #PB_Gadget_BackColor, $C7F5F6 )
CloseGadgetList()
EndProcedure
;---------------------------------------------------------------------
Procedure M_DRO()
coord=0
ContainerGadget(#cont_mDRO,850,20,170,150, #PB_Container_Double )
SetGadgetColor(#cont_mDRO, #PB_Gadget_BackColor, Con_color )
TextGadget(#txt_mdro,15,5,190,20,"MACH COORDINATE "+ mm_inch$)
SetGadgetFont(#txt_mdro, FontID(font8))
SetGadgetColor(#txt_mdro, #PB_Gadget_BackColor,0):SetGadgetColor(#txt_mdro, #PB_Gadget_FrontColor, $E2EA00)
SetGadgetFont(#PB_Default, FontID(font18))
TextGadget(#txt_mdro_x,10,25,36,26," X "):SetGadgetColor(#txt_mdro_X, #PB_Gadget_BackColor, $E2EA00 )
TextGadget(#txt_mdro_xm,55,25,100,26,"0.00") :SetGadgetColor(#txt_mdro_xm, #PB_Gadget_BackColor, $E2EA00 )
TextGadget(#txt_mdro_y,10,55,36,26," Y "):SetGadgetColor(#txt_mdro_y, #PB_Gadget_BackColor, $E2EA00 )
TextGadget(#txt_mdro_ym,55,55,100,26,"0.00") :SetGadgetColor(#txt_mdro_ym, #PB_Gadget_BackColor, $E2EA00)
TextGadget(#txt_mdro_z,10,85,36,26," Z ") :SetGadgetColor(#txt_mdro_z, #PB_Gadget_BackColor, $E2EA00)
TextGadget(#txt_mdro_zm,55,85,100,26,"0.00") :SetGadgetColor(#txt_mdro_zm, #PB_Gadget_BackColor, $E2EA00 )
TextGadget(#txt_mdro_a,10,115,36,26," A ") :SetGadgetColor(#txt_mdro_a, #PB_Gadget_BackColor, $E2EA00)
TextGadget(#txt_mdro_am,55,115,100,26,"0.00") :SetGadgetColor(#txt_mdro_am, #PB_Gadget_BackColor, $E2EA00 )
CloseGadgetList()
EndProcedure
;---------------------------------------------------------------------
Procedure menu()
If CreateMenu(#menu, WindowID(#main_window))
MenuTitle("FILE")
MenuItem(#M_open, "OPEN" )
MenuItem(#M_edit, "EDIT")
MenuItem(#M_save,"SAVE")
MenuItem(#M_save_as,"SAVE AS")
MenuItem(#M_exit, "EXIT" )
MenuItem(#m_close,"CLOSE FILE")
MenuItem(#M_notepad,"NOTEPAD")
MenuItem(#M_about,"ABOUT")
MenuTitle("SETUP")
MenuItem( #M_setup, "SETUP")
EndIf
EndProcedure
;----------------------------------------------------------------
Procedure home()
Define xk.i=35 ,yk.i=40
Define cx.i=20,cy.i=530,cb.i=150,ch.i=210
Define xb.i=100 , yh.i=30,yt.i=40
ContainerGadget(#cont_home,cx,cy,cb,ch,#PB_Container_Raised )
SetGadgetColor(#cont_home, #PB_Gadget_BackColor, Con_color)
SetGadgetFont(#PB_Default, FontID(font12))
TextGadget(#txt_home,15,5,120,15,"HOME ctrl+axis")
SetGadgetColor(#txt_home, #PB_Gadget_FrontColor,text_vgcol)
SetGadgetColor(#txt_home, #PB_Gadget_BackColor,Con_color)
; SetGadgetFont(#txt_home_titel,FontID(1))
SetGadgetFont(#PB_Default, FontID(font12))
ButtonGadget(#btn_homeX,xk,yk, xb,yh," HOME X")
ButtonGadget(#btn_homey,xk,(yk+yt), xb,yh," HOME Y")
ButtonGadget(#btn_homeZ,xk,(yk+(2*yt)), xb,yh, " HOME Z")
ButtonGadget(#btn_homeA,xk,(yk+(3*yt)), xb,yh," HOME A", #PB_Button_Left )
TextGadget(#txt_homeX_LED,10,yk,20,yh,"") : SetGadgetColor(#txt_homeX_LED, #PB_Gadget_BackColor,$0000FD )
TextGadget(#txt_homeY_LED,10,(yk +yt),20,yh,"") : SetGadgetColor(#txt_homeY_LED, #PB_Gadget_BackColor,$0000FD )
TextGadget(#txt_homeZ_LED,10,(yk+(2*yt)),20,yh,"") : SetGadgetColor(#txt_homeZ_LED, #PB_Gadget_BackColor,$0000FD )
TextGadget(#txt_homeA_LED,10,(yk+(3*yt)),20,yh,""):SetGadgetColor(#txt_homeA_LED, #PB_Gadget_BackColor,$0000FD)
; SetGadgetFont(#PB_Default, FontID(font18))
CloseGadgetList()
EndProcedure
;-----------------------------------------------------------------------------------------
Procedure port()
ContainerGadget(#cont_port,20,480,320,40, #PB_Container_Double )
SetGadgetColor(#cont_port, #PB_Gadget_BackColor, Con_color )
SetGadgetFont(#PB_Default, FontID(font10))
ComboBoxGadget(#Combo, 110, 6, 70, 22)
ForEach COMUsablePorts()
AddGadgetItem(#COMbo, -1, COMUsablePorts())
Next
SetGadgetState(#Combo, 0)
ThreadParameter\Semaphore = CreateSemaphore()
ButtonGadget(#btn_connect, 5, 4, 95, 25, "CONNECT")
TextGadget(#txt_status,190,8,110,20,"DISCONNECTED", #PB_Text_Center ):SetGadgetColor(#txt_status,#PB_Gadget_BackColor,$491EF3)
CloseGadgetList()
EndProcedure
;---------------------------------------------------------------------------
Procedure spindel()
Define xk.i=10 ,yk.i=40 ;positie knop
Define xb.i=100 , yh=30,yt=50 ,xt=120
ContainerGadget(#cont_spindel,465,530,170,210,#PB_Container_Raised )
SetGadgetColor(#cont_spindel, #PB_Gadget_BackColor,Con_color )
SetGadgetFont(#PB_Default, FontID(font12))
TextGadget (#txt_spindel,25,10,150,20," SPINDLE ")
SetGadgetColor(#txt_spindel, #PB_Gadget_FrontColor,text_vgcol):SetGadgetColor(#txt_spindel, #PB_Gadget_BackColor,Con_color )
ButtonGadget( #btn_spindel_on,xk,yk,95,yh,"OFF " ,#PB_Button_Toggle)
TextGadget(#txt_spindel_on_led,xk+100,yk,15,30," "):SetGadgetColor(#txt_spindel_on_led, #PB_Gadget_BackColor,off_color)
ScrollBarGadget(#scroll_spindel,xt+10,yk,15,150, 0,rpm_max/4, 1,#PB_ScrollBar_Vertical)
SetGadgetState(#scroll_spindel,0)
TextGadget(#txt_riem,xk,yk+YT,xb,yh+10," MAX RPM = "+Str(rpm_max))
TextGadget(#txt_rpm,xk,yk+2*yt,xb,yh," RPM "+Str(rpm), #PB_Text_Center)
CloseGadgetList()
EndProcedure
;----------------------------------------------------------
Procedure stepsize()
Define xk.i=10 ,yk.i=30
Define xb.i=100 , yh=30,yt=50 ,xt=120
stap(0)=0.001:stap(1)=0.01:stap(2)=0.1:stap(3)=1:stap(4)=10
stepsize=Stap(2)
ContainerGadget(#cont_stepsize,785,530,115,70,#PB_Container_Raised )
SetGadgetColor(#cont_stepsize, #PB_Gadget_BackColor, Con_color )
SetGadgetFont(#PB_Default, FontID(font12))
TextGadget (#txt_size,5,7,110,15,"V=STEPSIZE")
SetGadgetColor(#txt_size, #PB_Gadget_BackColor, Con_color ) : SetGadgetColor(#txt_size, #PB_Gadget_FrontColor,text_vgcol)
SetGadgetFont(#PB_Default, FontID(font12))
TextGadget (#txt_size1,30,30,50,20,StrD(stap(1)), #PB_Text_Center)
CloseGadgetList()
EndProcedure
;----------------------------------------------------------
Procedure screen_pos()
ContainerGadget(#cont_screen,360,445,350,75,#PB_Container_Raised )
ButtonGadget(#btn_redraw,5,7,80,20,"REDRAW")
ButtonGadget (#btn_up,95,7,70,20,"(U)p")
ButtonGadget(#btn_down,95,40,70,20,"(D)own")
ButtonGadget(#btn_left,180,7,70,20,"(L)eft")
ButtonGadget(#btn_right,180,40,70,20,"(R)ight")
ButtonGadget(#btn_zoom_min,265,7,70,20,"ZOOM(-)")
ButtonGadget(#btn_zoom_plus,265,40,70,20,"ZOOM(+)")
SetGadgetColor(#cont_screen, #PB_Gadget_BackColor, Con_color)
CloseGadgetList()
EndProcedure
;--------------------------------------------------------------------------------
Procedure zero()
Define xs.i=44 ,ys.i=40
Define xb.i=100,yh=30,yt=50
ContainerGadget(#cont_zero,185,550,165,130,#PB_Container_Raised )
SetGadgetColor(#cont_zero, #PB_Gadget_BackColor, Con_color )
SetGadgetFont(#PB_Default, FontID(font12))
TextGadget(#txt_zero,5,10,180,15,"SET WORK alt+axis")
SetGadgetColor(#txt_zero, #PB_Gadget_FrontColor,text_vgcol): SetGadgetColor(#txt_zero, #PB_Gadget_BackColor, Con_color )
SetGadgetFont(#PB_Default, FontID(font18))
StringGadget(#str_zeroZ,xs,ys,xb,yh,"0")
StringGadget(#str_zeroX,xs,ys+yt,xb,yh,"0")
TextGadget(#txt_z,10,ys,25,30,"Z", #PB_Text_Center )
SetGadgetColor(#txt_Z, #PB_Gadget_BackColor, $8AF392 )
TextGadget(#txt_x,10,ys+yt,25,30,"X", #PB_Text_Center ) : SetGadgetColor(#txt_x, #PB_Gadget_BackColor, $8AF392 )
CloseGadgetList()
EndProcedure
;---------------------------------------------------------------------
Procedure checkFloatInput(gadget, bNegativeOK.b = #True, bNegativeIntegers.b = #False)
Protected start, count, pointcount, new$
SendMessage_(GadgetID(gadget), #EM_GETSEL, @start, 0)
Protected txt$ = GetGadgetText(gadget)
Protected *p.Character = @txt$
While *p\c ; <> 0
If *p\c = '.'
pointcount+1
If pointcount < 2 And Not bNegativeIntegers
new$ + Chr(*p\c)
Else
If start>count : start-1 : EndIf
EndIf
ElseIf count = 0 And *p\c = '-' And bNegativeOK
new$ + Chr('-')
ElseIf *p\c >= '0' And *p\c <= '9'
new$ + Chr(*p\c)
Else
start - 1
EndIf
*p + SizeOf(Character)
count + 1
Wend
If bNegativeIntegers
If Len(new$) = 0 Or new$ = "-" Or ValD(new$) >= 0
new$ = "-1"
EndIf
EndIf
SetGadgetText(gadget, new$)
SendMessage_(GadgetID(gadget), #EM_SETSEL, start, start)
EndProcedure
;------------------------------------------------------------------------
Procedure clear_canvas()
StartDrawing(CanvasOutput(#canvas))
Box( 0,0,800,400,$0)
StopDrawing()
draw_grid()
EndProcedure
;------------------------------------------------------------
Procedure do_move()
xw_new=ValD(x_new$):zw_new=ValD(Z_new$)
x_steps=xw_old-xw_new:z_steps=zw_old-zw_new
update_screen()
xw_old=xw_new:zw_old=zw_new
EndProcedure
;-------------------------------------------------------------------------------
Procedure do_arc_move()
EndProcedure
;--------------------------------------------------------
Procedure draw_grid()
Define text$
StartVectorDrawing(CanvasVectorOutput(#canvas))
VectorSourceColor($60ffffff)
MovePathCursor(400,10)
AddPathLine(400,390)
MovePathCursor(10,200)
AddPathLine(790,200)
AddPathBox(5,5,790,390)
StrokePath(1)
AddPathBox(8,350,80,40)
VectorSourceColor(RGBA(148,164,193, 50))
FillPath()
VectorFont(FontID(font18), 25)
VectorSourceColor(RGBA(255, 255, 0, 250))
Text$ = "TEST"
MovePathCursor(10,360)
DrawVectorText(Text$)
StopVectorDrawing()
EndProcedure
;---------------------------------------------------------------------------
Procedure feed_setting()
Define percent
percent=GetGadgetState(#scroll_feed)
feed$=Str(feed*percent/100)
SetGadgetText (#txt_feed,"FEED "+mm_inch$+ " /min ")
SetGadgetText(#txt_feed1,feed$)
EndProcedure
;------------------------------------------------------------------------
Procedure gcode_uitvoeren()
Select g_code$
Case "0","00"
feed=v_max:feed_setting():mode=0
Case "1","01"
feed=voeding:feed_setting():mode=1
Case "2","02"
feed=voeding:feed_setting():mode=2
Case "3","03"
feed=voeding:feed_setting():mode=3
Case "4"
Case "17"
Case "18"
Case "19"
Case "20"
mm_inch$="inch"
SetGadgetText(#txt_dro,"WORK COORDINATE "+ mm_inch$ )
SetGadgetText (#txt_feed,"FEED "+mm_inch$+ " /min ")
metric=0
Case "21"
mm_inch$="mm": SetGadgetText(#txt_dro,"WORK COORDINATE "+ mm_inch$)
SetGadgetText (#txt_feed,"FEED "+mm_inch$+ " /min ")
metric=1
Case "28"
Case "30"
Case "G40" ,"G41"
Case "43"
Case "49"
Case "54"
Case "64"
Case "G80"
Case "81"
Case "82"
Case "83"
Case "84";
Case "89"
Case "90"
Case "91"
Case "G92"
Case "92.1";
EndSelect
EndProcedure
;----------------------------------------------------------------------
Procedure init_vars()
load_data()
mm_inch$="mm"
metric=1
feed=50:feed$=Str(feed):v_max=1500
x_min=-20:x_max=400
y_min=-20:y_max=200
z_min=0:z_max=300
xw_new=0:xw_old=0:yw_new=0:yw_old=0:zw_old=0:zw_new=0:aw_old=0:aw_new=0
coord=1
EndProcedure
;--------------------------------------------------------
Procedure load_data()
If ReadFile(#setting_file, "settings.dat")
While Eof( #setting_file) = 0
X_step_mm=ValD(ReadString(#setting_file))
Z_step_mm=ValD(ReadString(#setting_file))
X_accel=Val(ReadString(#setting_file))
X_deccel=Val(ReadString(#setting_file))
Z_accel=Val(ReadString(#setting_file))
z_deccel=Val(ReadString(#setting_file))
X_spel=ValD(ReadString(#setting_file))
Z_spel=ValD(ReadString(#setting_file))
X_min=ValD(ReadString(#setting_file))
X_max=ValD(ReadString(#setting_file))
Z_min=ValD(ReadString(#setting_file))
Z_max=ValD(ReadString(#setting_file))
Wend
CloseFile( #setting_file)
Else
MessageRequester("","Settings not found ,use default!")
EndIf
EndProcedure
;--------------------------------------------------------------
Procedure load_file()
Define StandardFile$,keuze
Define Pattern$
Define Pattern
Define length.l,*MemoryID , bytes
aantal_lijnen=1
StandardFile$ = "C:\*.*"
Pattern$ ="All files (*.*)|*.*;file(*.tap)|*.cnc"
Pattern = 0
File$ = OpenFileRequester("Please choose file to load", StandardFile$, Pattern$, Pattern)
ClearGadgetItems(#list1)
If ReadFile(#file, file$)
length = Lof(#file)
*MemoryID = AllocateMemory(length)
If *MemoryID
bytes = ReadData(#file, *MemoryID, length)
EndIf
CloseFile(#file)
EndIf
If File$
If OpenFile( #file, file$)
ReadFile( #file, file$)
While Eof( #file) = 0
AddGadgetItem (#list1, -1, Str(aantal_lijnen)+" "+ReadString(#file))
aantal_lijnen=aantal_lijnen+1
Wend
CloseFile( #file)
EndIf
aantal_lijnen=aantal_lijnen-1
Else
MessageRequester("Information", "FILE OPEN was canceled.", 0)
EndIf
keuze=0;
SetGadgetText(#file_info,file$)
redraw()
EndProcedure
;----------------------------------------------------------------------------------------
Procedure load_fonts()
font6=LoadFont(#PB_Any,"arial",6, #PB_Font_Italic|#PB_Font_Bold)
font8=LoadFont(#PB_Any,"arial",8, #PB_Font_Italic|#PB_Font_Bold)
font10=LoadFont(#PB_Any,"arial",10, #PB_Font_Italic|#PB_Font_Bold)
font12=LoadFont(#PB_Any,"arial",12, #PB_Font_Italic|#PB_Font_Bold)
font18=LoadFont(#PB_Any,"arial",18, #PB_Font_Italic|#PB_Font_Bold)
font24=LoadFont(#PB_Any,"arial",24, #PB_Font_Italic|#PB_Font_Bold)
font34=LoadFont(#PB_Any,"arial",34, #PB_Font_Italic|#PB_Font_Bold)
EndProcedure
;----------------------------------------------------------------------------------------
Procedure OnGadgetEvent()
Select EventGadget()
Case #str_dro_xw
If EventType() = #PB_EventType_LostFocus
checkFloatInput(EventGadget(), #True)
x_new$=GetGadgetText(#str_dro_Xw) : xw_new =ValD(x_new$)
mode=1:update_screen():update_DRO_X()
xw_old=xw_new
EndIf
Case #str_dro_zw
If EventType() = #PB_EventType_LostFocus
checkFloatInput(EventGadget(), #True)
zw_new=ValD(GetGadgetText(#str_dro_zw))
mode=1: update_screen():update_DRO_Z()
zw_old=zw_new
EndIf
Case #btn_mdi_preview
mdi_preview=1
n= CountGadgetItems(#edit_mdi)
For teller=0 To n
lijn$ = GetGadgetItemText(#edit_mdi, teller)
ontrafel()
update_screen()
Next
mdi_preview=0
Case #btn_mdi_go
mdi_go=1
Case #btn_mdi_clear
ClearGadgetItems(#edit_mdi)
ontrafel() :update_screen()
Case #scroll_spindel
rpm=GetGadgetState(#scroll_spindel)
rpm=rpm*4
SetGadgetText(#txt_rpm,"RPM="+Str(rpm))
Case #btn_single
If single_line=1
single_line=0
SetGadgetColor(#txt_single_led, #PB_Gadget_BackColor,off_color)
Else
single_line=1
SetGadgetColor(#txt_single_led, #PB_Gadget_BackColor,on_color)
EndIf
Case #btn_start
If start=1
start=0
SetGadgetColor(#txt_run_led, #PB_Gadget_BackColor,off_color)
Else
start=1
SetGadgetColor(#txt_run_led, #PB_Gadget_BackColor, on_color)
SetGadgetColor(#txt_pauze_led, #PB_Gadget_BackColor,off_color)
EndIf
Case #btn_pauze
If start=1
start=0
SetGadgetColor(#txt_run_led, #PB_Gadget_BackColor,off_color)
SetGadgetColor(#txt_pauze_led, #PB_Gadget_BackColor,on_color)
EndIf
Case #btn_coord
If coord=1: coord=0 :set_machine_coord_active()
Else
coord=1:set_work_coord_active()
EndIf
EndSelect
EndProcedure
;--------------------------------------------------------------
Procedure opmerking()
k$="":opmerking$="("
Repeat
If kar_positie<lengte
kar_positie= kar_positie+1
k$= Mid(lijn$, kar_positie ,1)
opmerking$=opmerking$+k$ :k$=""
Else
k$="q"
EndIf
Until k$= "q"
EndProcedure
;----------------------------------------------------------------------------------------
Procedure ontrafel()
lengte=Len(lijn$)
kar_positie=1:k$="":g_code$="": einde_lijn=0
While kar_positie<lengte
k$= Mid(lijn$, kar_positie ,1) :code$=""
If k$ > "A" And k$ < "{"
Select k$
Case "G","g"
vind_waarde():g_code$=waarde$:gcode_uitvoeren()
Case "T"
vind_waarde():tool$=waarde$
If redraw=1: MessageRequester("TOOLCHANGE","TOOL :"+tool$):EndIf
Case "M"
vind_waarde():m_code$=waarde$
Case "X","x"
vind_waarde():x_new$=waarde$:xw_new=ValD(x_new$)
Case "Y","y"
vind_waarde():y_new$=waarde$:yw_new=ValD(y_new$)
Case "Z","z"
vind_waarde():z_new$=waarde$:zw_new=ValD(z_new$)
Case "A","a"
vind_waarde():a_new$=waarde$:aw_new=ValD(a_new$)
Case "F","f"
vind_waarde():voeding$=waarde$: feed=Val(voeding$):feed_setting()
Case "I","i"
vind_Waarde():i_code$=waarde$
Case "J","j"
vind_Waarde():j_code$=waarde$
Case "K","k"
vind_Waarde():k_code$=waarde$
EndSelect
EndIf
kar_positie = kar_positie+1
Wend
EndProcedure
;----------------------------------------------------------------
Procedure save_file()
Define fo,tmp$
If file$=""
MessageRequester("INFO","GEEN FILENAAM")
Else
fo = OpenFile(#file,File$)
If fo
For n=0 To CountGadgetItems(#list1)
tmp$ = GetGadgetItemText(#list1,n)
WriteStringN(#file, tmp$)
Next
CloseFile(#file)
MessageRequester("","File created successfully.")
Else
MessageRequester("","Cannot create file.",#MB_ICONERROR)
EndIf
EndIf
EndProcedure
;----------------------------------------------------------------------
Procedure save_as_file()
Define pattern$,tmp$
Define pattern,kk,ii
Pattern$ = "Text (*.nc)"
Pattern = 0
File$ = SaveFileRequester("Please choose file name", "", Pattern$, Pattern)
If File$
If ReadFile(#file,File$)
CloseFile(#file)
i=MessageRequester("Warning","File already exists. Overwrite ?",#PB_MessageRequester_YesNo)
If i= #PB_MessageRequester_No
ProcedureReturn
EndIf
EndIf
If GetExtensionPart(File$) = ""
File$ + ".nc"
EndIf
ii = OpenFile(#file,File$)
If ii
For kk=0 To CountGadgetItems(#list1)
tmp$ = GetGadgetItemText(#list1,i)
WriteStringN(#file, tmp$)
Next
CloseFile(#file)
MessageRequester("","File created successfully.")
Else
MessageRequester("","Cannot create file.",#MB_ICONERROR)
EndIf
EndIf
EndProcedure
;------------------------------------------------------------------------------------------
Procedure set_machine_coord_active()
HideGadget(#cont_DRO,1)
HideGadget(#cont_mDRO, 0)
SetGadgetText(#txt_dro,"MACH COORDINATE "+ mm_inch$)
SetGadgetColor(#txt_dro, #PB_Gadget_FrontColor, $E2EA00)
update_screen()
EndProcedure
;--------------------------------------------------------------
Procedure set_work_coord_active()
HideGadget(#cont_DRO,0)
HideGadget(#cont_mDRO, 1)
SetGadgetText(#txt_dro,"WORK COORDINATE "+ mm_inch$)
SetGadgetColor(#txt_dro, #PB_Gadget_FrontColor, $C7F5F6)
update_screen()
EndProcedure
Procedure spindel_on_off()
If spindle_Status =1
spindle_status=0
SetGadgetText( #btn_spindel_on,"OFF")
SetGadgetColor(#txt_spindel_on_LED, #PB_Gadget_BackColor,off_color)
Else
spindle_Status=1
SetGadgetText( #btn_spindel_on,"ON")
SetGadgetColor(#txt_spindel_on_LED, #PB_Gadget_BackColor,on_color)
EndIf
EndProcedure
;----------------------------------------------------------
Procedure sneltoets() ;sneltoetsen voor keybord events
AddKeyboardShortcut(#main_window, #PB_Shortcut_F1,#F1)
AddKeyboardShortcut(#main_window, #PB_Shortcut_V,#stepsize);stepsize
AddKeyboardShortcut(#main_window,#PB_Shortcut_Left,#jog_x_MIN)
AddKeyboardShortcut(#main_window,#PB_Shortcut_Right,#jog_x_plus)
AddKeyboardShortcut(#main_window,#PB_Shortcut_Up,#jog_y_plus)
AddKeyboardShortcut(#main_window,#PB_Shortcut_Down,#jog_y_min)
AddKeyboardShortcut(#main_window,#PB_Shortcut_PageDown,#jog_Z_MIN)
AddKeyboardShortcut(#main_window,#PB_Shortcut_PageUp,#jog_Z_plus)
AddKeyboardShortcut(#main_window,#PB_Shortcut_End,#jog_a_MIN)
AddKeyboardShortcut(#main_window,#PB_Shortcut_Home,#jog_a_plus)
EndProcedure
;--------------------------------------------------------------------
Procedure stapgrootte()
stepsize=stepsize*10
If stepsize>10
stepsize=0.01
EndIf
SetGadgetText(#txt_size1,StrD(stepsize))
EndProcedure
;-----------------------------------------------------------------------
Procedure redraw()
clear_canvas()
For n=0 To aantal_lijnen
lijn$=GetGadgetItemText (#list1,n)
ontrafel()
update_screen()
Next
EndProcedure
;------------------------------------------------------------------------------
Procedure update_DRO_X() ;
Static w$
If coord=1
w$=FormatNumber(xw_new.d,3,".","")
SetGadgetText(#str_dro_xw,w$)
Else
w$=FormatNumber(xm_new.d,2,".","")
SetGadgetText(#txt_mdro_xm,w$)
EndIf
EndProcedure
;----------------------------------------------------------
Procedure update_DRO_y()
Static w$
If coord=1
w$=FormatNumber(yw_new.d,3,".","") ;work
SetGadgetText(#str_dro_yw,w$)
Else
w$=FormatNumber(ym_new.d,2,".","");machine
SetGadgetText(#txt_mdro_ym,w$)
EndIf
EndProcedure
;--------------------------------------------------------
Procedure update_DRO_Z()
Static w$
If coord=1
w$=FormatNumber(zw_new.d,3,".","") ;work
SetGadgetText(#str_dro_zw,w$)
Else
w$=FormatNumber(zm_new.d,2,".","");machine
SetGadgetText(#txt_mdro_zm,w$)
EndIf
EndProcedure
;--------------------------------------------------------
Procedure update_DRO_a()
Static w$
If coord=1
w$=FormatNumber(aw_new.d,3,".","") ;work
SetGadgetText(#str_dro_aw,w$)
Else
w$=FormatNumber(am_new.d,2,".","");machine
SetGadgetText(#txt_mdro_am,w$)
EndIf
EndProcedure
;--------------------------------------------------------
Procedure update_screen()
If mode=2:g_color=G2_color: draw_arc():EndIf
If mode=3:g_color=G3_color: draw_arc():EndIf
StartVectorDrawing(CanvasVectorOutput(#canvas))
FlipCoordinatesY(y_off)
ScaleCoordinates(zoom,zoom)
If mode=0 :g_color=G0_color : VectorSourceColor(g_color)
MovePathCursor(x_off+xw_old,y_off+yw_old)
AddPathLine(x_off+xw_new,y_off+yw_new)
StrokePath(1)
EndIf
If mode=1:g_color=g1_color
VectorSourceColor(g_color)
MovePathCursor(x_off+xw_old,y_off+yw_old)
AddPathLine(x_off+xw_new,y_off+yw_new)
StrokePath(1) :EndIf
VectorSourceColor(g_color)
If mode=2
TranslateCoordinates(x_off,y_off)
AddPathCircle(xcenter,ycenter,ma,wb,wa) : StrokePath(1)
EndIf
If mode=3
TranslateCoordinates(x_off,y_off)
AddPathCircle(xcenter,ycenter,ma,wa,wb): StrokePath(1)
EndIf
StopVectorDrawing()
update_positie()
EndProcedure
;------------------------------------------------------------------------------
Procedure update_positie()
update_DRO_X():update_DRO_y():update_DRO_Z():update_DRO_A()
xw_old=xw_new :xm_old=xm_new
yw_old=yw_new :ym_old=ym_new
zw_old=zw_new: zm_old=zm_new
aw_old=aw_new :am_old=am_new
EndProcedure
;------------------------------------------------------------------------------
Procedure draw_Arc()
i=ValD(i_code$):j=ValD(J_code$)
i=-i:j=-j
ma=Sqr(Pow(i,2)+Pow(j,2))
xcenter=xw_old-i
ycenter=yw_old-j
i2=xw_new-xcenter
j2=yw_new-ycenter
mb=Sqr(Pow(i2,2)+Pow(j2,2))
If Abs(ma-mb)>#Epsilon
EndIf
wa=ATan2(i,j)
wa=Degree(wa)
wb=ATan2(i2,j2)
wb=Degree(wb)
EndProcedure
;----------------------------------------------------------
Procedure vind_waarde()
Define eind=0
waarde$=""
kar_positie = kar_positie+1
Repeat
k$= Mid(lijn$, kar_positie ,1)
; Debug "k$="+k$
Select k$
Case "0" ,"1","2","3","4","5","6","7","8","9","." ,"-"
waarde$=waarde$+k$
kar_positie= kar_positie+1
Default
eind=1
EndSelect
Until eind=1
EndProcedure
;----------------------------------------------------------
Procedure voeding()
Define xk.i=10 ,yk.i=40
Define xb.i=120 , yh=30,yt=50 ,xt=120
ContainerGadget(#cont_feed,645,530,130,210,#PB_Container_Raised )
SetGadgetColor(#cont_feed, #PB_Gadget_BackColor, Con_color )
SetGadgetFont(#PB_Default, FontID(font12))
TextGadget (#txt_feed,5,10,180,20,"FEED "+mm_inch$+ " /min ")
SetGadgetColor(#txt_feed, #PB_Gadget_BackColor, Con_color ) : SetGadgetColor(#txt_feed, #PB_Gadget_FrontColor,text_vgcol):
ScrollBarGadget(#scroll_feed,100,40,15,150,25,300, 1,#PB_ScrollBar_Vertical) ;2
SetGadgetState(#scroll_feed,100)
ButtonGadget(#btn_reset_feed,10,40,80,30,"RESET")
feed$=Str(voeding)
TextGadget (#txt_feed1,10,90,60,20,feed$)
CloseGadgetList()
HideGadget(#cont_feed,0)
EndProcedure
Re: slow drawing
U dont do much drawing - i only found this:
But that cant be the issue...
Code: Select all
Procedure draw_grid()
Define text$
StartVectorDrawing(CanvasVectorOutput(#canvas))
VectorSourceColor($60ffffff)
MovePathCursor(400,10)
AddPathLine(400,390)
MovePathCursor(10,200)
AddPathLine(790,200)
AddPathBox(5,5,790,390)
StrokePath(1)
AddPathBox(8,350,80,40)
VectorSourceColor(RGBA(148,164,193, 50))
FillPath()
VectorFont(FontID(font18), 25)
VectorSourceColor(RGBA(255, 255, 0, 250))
Text$ = "TEST"
MovePathCursor(10,360)
DrawVectorText(Text$)
StopVectorDrawing()
EndProcedure
...
Procedure update_screen()
If mode=2:g_color=G2_color: draw_arc():EndIf
If mode=3:g_color=G3_color: draw_arc():EndIf
StartVectorDrawing(CanvasVectorOutput(#canvas))
FlipCoordinatesY(y_off)
ScaleCoordinates(zoom,zoom)
If mode=0 :g_color=G0_color : VectorSourceColor(g_color)
MovePathCursor(x_off+xw_old,y_off+yw_old)
AddPathLine(x_off+xw_new,y_off+yw_new)
StrokePath(1)
EndIf
If mode=1:g_color=g1_color
VectorSourceColor(g_color)
MovePathCursor(x_off+xw_old,y_off+yw_old)
AddPathLine(x_off+xw_new,y_off+yw_new)
StrokePath(1) :EndIf
VectorSourceColor(g_color)
If mode=2
TranslateCoordinates(x_off,y_off)
AddPathCircle(xcenter,ycenter,ma,wb,wa) : StrokePath(1)
EndIf
If mode=3
TranslateCoordinates(x_off,y_off)
AddPathCircle(xcenter,ycenter,ma,wa,wb): StrokePath(1)
EndIf
StopVectorDrawing()
update_positie()
EndProcedure
Re: slow drawing
Every time you call StartVectorDrawing() , PureBasic makes a copy of the entire canvas, starts drawing onto that copy and when you call StopVectorDrawing() the result of all drawing operations between StartVectorDrawing() and StopVectorDrawing() is presented.
You are calling StartVectorDrawing() and StopVectorDrawing() for almost everything (when you clear the canvas, after every line you process).
This makes things slow.
If you would only call them once and do all drawing operations between them it would be much faster.
You are calling StartVectorDrawing() and StopVectorDrawing() for almost everything (when you clear the canvas, after every line you process).
This makes things slow.
If you would only call them once and do all drawing operations between them it would be much faster.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: slow drawing
thanks Wilbert,
I try it.But i am thinking ,can I path thousends of lines.
I try it.But i am thinking ,can I path thousends of lines.
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: slow drawing
I'm going to say yes.ludoke wrote:But i am thinking ,can I path thousends of lines.
Code: Select all
OpenWindow(0,0,0,800,600,"")
CanvasGadget(0, 0,0,800,600)
start.q = ElapsedMilliseconds()
StartVectorDrawing(CanvasVectorOutput(0))
For i=1 To 25*1000
x.d = Random(700)
y.d = Random(500)
a.d = x+Random(99)
b.d = y+Random(99)
MovePathCursor(x,y)
AddPathLine(a,b)
VectorSourceColor(RGBA(Random(255),Random(255),Random(255),255))
StrokePath(2)
Next
StopVectorDrawing()
finish.q = ElapsedMilliseconds()
MessageRequester("Time Taken for 25K lines drawn:", Str(finish-start))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
BERESHEIT
Re: slow drawing
@netmaestro
250ms on a fast machine
Upscaled 225% = 484ms
It looks like an incorrect implementation
Best Regards Saki
250ms on a fast machine
Upscaled 225% = 484ms
It looks like an incorrect implementation
Best Regards Saki
地球上の平和
Re: slow drawing
Time: 156 ms on Mac Mini Late 2018, Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: slow drawing
just for curiosity...
Code with 250K
4077ms
108ms
It seems, Vectordrawing is a little bit slower
Code with 250K
Code: Select all
OpenWindow(0,0,0,800,600,"")
CanvasGadget(0, 0,0,800,600)
start.q = ElapsedMilliseconds()
StartVectorDrawing(CanvasVectorOutput(0))
For i=1 To 250000
x.d = Random(700)
y.d = Random(500)
a.d = x+Random(99)
b.d = y+Random(99)
MovePathCursor(x,y)
AddPathLine(a,b)
VectorSourceColor(RGBA(Random(255),Random(255),Random(255),255))
StrokePath(2)
Next
StopVectorDrawing()
finish.q = ElapsedMilliseconds()
MessageRequester("Time Taken for 25K lines drawn:", Str(finish-start))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
Code: Select all
OpenWindow(0,0,0,800,600,"")
CanvasGadget(0, 0,0,800,600)
start.q = ElapsedMilliseconds()
StartDrawing(CanvasOutput(0))
For i=1 To 250000
x.d = Random(700)
y.d = Random(500)
a.d = x+Random(99)
b.d = y+Random(99)
LineXY(x,y,a,b,RGBA(Random(255),Random(255),Random(255),255))
Next
StopDrawing()
finish.q = ElapsedMilliseconds()
MessageRequester("Time Taken for 25K lines drawn:", Str(finish-start))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
It seems, Vectordrawing is a little bit slower
Re: slow drawing
Interesting that the Mac is so fast, it can't be the machine.
That VectorDrawing is slower was to be expected.
But it is still surprisingly fast, even though it is so complex.
It is also not completely bug free, maybe it should get an update.
But overall it is a fascinating tool
That VectorDrawing is slower was to be expected.
But it is still surprisingly fast, even though it is so complex.
It is also not completely bug free, maybe it should get an update.
But overall it is a fascinating tool
地球上の平和
Re: slow drawing
can I use openGL for this ?
Re: slow drawing
I find this ,it is very fast,maybe can I use this to view the gcode file
; by Danilo, July 2011
;
; big thanks to all helpers in the german forum!
;
; Version 0.85 beta 2
;
the gDrawing.pbi is to big to show.
; by Danilo, July 2011
;
; big thanks to all helpers in the german forum!
;
; Version 0.85 beta 2
;
the gDrawing.pbi is to big to show.
Code: Select all
EnableExplicit
XIncludeFile "gDrawing.pbi"
Global img
Global mainWin, imgWin, modeWin
Global i.l, j.l, k.l
Global pbLogo, bufferedPbLogo, pbBackground, pbAlphaChannel
Global Background, bufferedBackground, welcomeLogo.i
Global penRotation.f=0, penScale.f=1.0
Global penOriginX.f=0, penOriginY.f=0
Global globalRotation.f = 0.0, globalScale.f = 1.0, globalShearX.f, globalShearY.f
Global Dim colors.l(100)
Prototype demoProc()
Dim demoProcedures.i(20)
Procedure initpicture()
gSetPenImage(bufferedPbLogo,#WrapModeTile)
gSetPenTransform(penOriginX+400,penOriginY+400,penRotation,penScale,penScale)
gBox(0,0,800,800)
gDrawImage(welcomeLogo,100,50)
gSetPenCaps(#LineCapRound, #LineCapArrowAnchor)
gSetPen($80000000,5)
gLineXY(185,310,05,150)
gSetPenColor($DDFFFF00)
gLineXY(190,300,10,140)
gSetPenColor($80000000)
gLineXY(565,340,795,130)
gSetPenColor($DDFF00FF)
gLineXY(560,330,790,120)
EndProcedure
Procedure demo_gPlot()
gSetPenColor(RGBA($00,$00,$00,$FF))
gDrawText(5,5,"plot points at different sizes",$FF000000)
j=0
For i = 1 To 30
j + i + 5
gSetPenSize(i)
gPlot(j,45)
Next i
j=0
gDrawText(5,65,"...with different colors",$FF000000)
For i = 1 To 30
j + i + 5
gSetPen(colors(i),i)
gPlot(j,105)
Next i
j=0
gDrawText(5,125,"...with patterns",$FF000000)
For i = 1 To 30
j + i + 5
gSetPenSize(i)
gSetPenPattern(i,$FFFFFFFF,$FF000000)
gPlot(j,165)
Next i
j=0
gSetPenImage(bufferedBackground)
gDrawText(5,185,"...with image texture",$FF000000)
For i = 1 To 30
j + i + 5
gSetPenSize(i)
gPlot(j,225)
Next i
RandomSeed(0)
For i = 0 To 100
j = Random(800)
k = Random(250)
gSetPenSize(1+Random(20))
gSetPenTransform(penOriginX+j,penOriginY+k+345,penRotation,penScale,penScale)
gPlot(j,k+345)
gResetPenTransform()
Next i
EndProcedure
Procedure demo_gBox()
;gStartRotationAround(0,0,globalRotation)
gSetPenColor(RGBA($00,$00,$00,$FF))
gDrawText(5,5,"draw boxes at different sizes",$FF000000)
j=0
For i = 1 To 30
j + i + 5
gBox(j,45-i*0.5,i,i)
Next i
j=0
gDrawText(5,65,"...with different colors",$FF000000)
For i = 1 To 30
j + i + 5
gSetPenColor(colors(i))
gBox(j,105-i*0.5,i,i)
Next i
j=0
gDrawText(5,125,"...with patterns",$FF000000)
For i = 1 To 30
j + i + 5
gSetPenPattern(i,$FFFFFFFF,$FF000000)
gBox(j,165-i*0.5,i,i)
Next i
j=0
gSetPenImage(bufferedBackground)
gDrawText(5,185,"...with image texture",$FF000000)
For i = 1 To 30
j + i + 5
gSetPenOrigin(j,225)
gBox(j,225-i*0.5,i,i)
gResetPenTransform()
Next i
j=0
gDrawText(5,245,"...outlined",$FF000000)
gDrawingMode(#PB_2DDrawing_Outlined)
gSetPenSize(2)
For i = 1 To 30
j + i + 5
gSetPenColor(colors(i))
gBox(j,285-i*0.5,i,i)
Next i
j=0
gDrawingMode(#PB_2DDrawing_Default)
gDrawText(5,305,"...rotated",$FF000000)
gDrawingMode(#PB_2DDrawing_Outlined)
gSetPenSize(2)
gStartTransform()
For i = 1 To 30
j + i + 5
gSetPenColor(colors(i))
gSetOrigin(j+i*0.5,345)
gRotate(i*12)
gBox(-i*0.5,-i*0.5,i,i)
gResetTransform()
Next i
gStopTransform()
gSetPenColor($FF000000)
gStartTransform()
For i = 0 To 2
gBox(200,420,70,70)
gRotateAt(200,420,20)
Next i
gStopTransform()
gStartTransform()
For i = 0 To 2
gBox(400,420,70,70)
gRotateAt(435,455,20)
Next i
gStopTransform()
gDrawingMode(#PB_2DDrawing_Default)
;gDrawingMode(#PB_2DDrawing_Outlined)
;gSetPenSize(40)
gSetPenImage(bufferedPbLogo,#WrapModeTileFlipXY)
gSetPenTransform(penOriginX+400,penOriginY+545+(800-565)*0.5,penRotation,penScale,penScale)
gBox(20,545,760,800-565)
;gStopRotation()
EndProcedure
Procedure demo_gEllipse()
gSetPenColor(RGBA($00,$00,$00,$FF))
gDrawText(5,5,"draw ellipses at different sizes",$FF000000)
j=0
For i = 1 To 30
j + i + 5
gEllipse(j,45,i*0.5,i)
Next i
j=0
gDrawText(5,65,"...with different colors",$FF000000)
For i = 1 To 30
j + i + 5
gSetPenColor(colors(i))
gEllipse(j,105,i*0.5,i)
Next i
j=0
gDrawText(5,125,"...with patterns",$FF000000)
For i = 1 To 30
j + i + 5
gSetPenPattern(i,$FFFFFFFF,$FF000000)
gEllipse(j,165,i*0.5,i)
Next i
j=0
gSetPenImage(bufferedBackground)
gDrawText(5,185,"...with image texture",$FF000000)
For i = 1 To 30
j + i + 5
gEllipse(j,225,i*0.5,i)
Next i
j=0
gDrawText(5,245,"...outlined",$FF000000)
gDrawingMode(#PB_2DDrawing_Outlined)
For i = 1 To 30
j + i + 5
gSetPenColor(colors(i))
gEllipse(j,285,i*0.5,i)
Next i
j=0
gDrawingMode(#PB_2DDrawing_Default)
gDrawText(5,305,"...rotated",$FF000000)
gDrawingMode(#PB_2DDrawing_Outlined)
gStartTransform()
For i = 1 To 30
j + i + 5
gSetPenColor(colors(i))
gRotateAt(j,345,i*12)
gEllipse(j,345,i*0.5,i)
gResetTransform()
Next i
gStopTransform()
gSetPenImage(bufferedBackground)
gDrawingMode(#PB_2DDrawing_Default)
gSetPenTransform(penOriginX+200,penOriginY+470,penRotation,penScale,penScale)
gEllipse(200,470,100,50)
gResetPenTransform()
gDrawingMode(#PB_2DDrawing_Outlined)
gSetPenSize(10)
gSetPenTransform(penOriginX+450,penOriginY+470,penRotation,penScale,penScale)
gEllipse(450,470,75,25)
gResetPenTransform()
gSetPen($FF000000,2)
gStartTransform()
For i = 1 To 30
gRotateAt(200,670,i*12)
gEllipse(200,670,100,50)
gResetTransform()
Next i
gStopTransform()
gStartTransform()
For i = 1 To 3
gRotateAt(450,670,i*20)
gEllipse(450,670,100,50)
gResetTransform()
Next i
gStopTransform()
gStartTransform()
For i = 1 To 3
gRotateAt(700,670,i*20)
gEllipse(700,670,100,50)
Next i
gStopTransform()
EndProcedure
Procedure demo_gCircle()
gSetPenColor(RGBA($00,$00,$00,$FF))
gDrawText(5,5,"draw circles at different sizes",$FF000000)
j=0
For i = 1 To 30
j + i + 5
gCircle(j,45,i*0.5)
Next i
j=0
gDrawText(5,65,"...with different colors",$FF000000)
For i = 1 To 30
j + i + 5
gSetPenColor(colors(i))
gCircle(j,105,i*0.5)
Next i
j=0
gDrawText(5,125,"...with patterns",$FF000000)
For i = 1 To 30
j + i + 5
gSetPenPattern(i,$FFFFFFFF,$FF000000)
gCircle(j,165,i*0.5)
Next i
j=0
gSetPenImage(bufferedBackground)
gDrawText(5,185,"...with image texture",$FF000000)
For i = 1 To 30
j + i + 5
gCircle(j,225,i*0.5)
Next i
j=0
gDrawText(5,245,"...outlined",$FF000000)
gDrawingMode(#PB_2DDrawing_Outlined)
For i = 1 To 30
j + i + 5
gSetPenColor(colors(i))
gCircle(j,285,i*0.5)
Next i
gSetPenImage(bufferedBackground)
gDrawingMode(#PB_2DDrawing_Default)
gSetPenTransform(penOriginX+200,penOriginY+470,penRotation,penScale,penScale)
gCircle(200,470,100)
gResetPenTransform()
gDrawingMode(#PB_2DDrawing_Outlined)
gSetPenSize(50)
gSetPenTransform(penOriginX+450,penOriginY+470,penRotation,penScale,penScale)
gCircle(450,470,75)
EndProcedure
Procedure demo_gPie()
gSetPenColor(RGBA($00,$00,$00,$FF))
gDrawText(5,5,"draw pie's at different sizes",$FF000000)
j=0
For i = 1 To 30
j + i + 5
gPie(j,45,i*0.5,i*0.5,-90,270)
Next i
j=0
gDrawText(5,65,"...with different colors",$FF000000)
For i = 1 To 30
j + i + 5
gSetPenColor(colors(i))
gPie(j,105,i*0.5,i*0.5,-90,270)
Next i
j=0
gDrawText(5,125,"...with patterns",$FF000000)
For i = 1 To 30
j + i + 5
gSetPenPattern(i,$FFFFFFFF,$FF000000)
gPie(j,165,i*0.5,i*0.5,-90,270)
Next i
j=0
gSetPenImage(bufferedBackground)
gDrawText(5,185,"...with image texture",$FF000000)
For i = 1 To 30
j + i + 5
gPie(j,225,i*0.5,i*0.5,-90,270)
Next i
j=0
gDrawText(5,245,"...outlined",$FF000000)
gDrawingMode(#PB_2DDrawing_Outlined)
For i = 1 To 30
j + i + 5
gSetPenColor(colors(i))
gPie(j,285,i*0.5,i*0.5,-90,270)
Next i
gSetPenImage(bufferedBackground)
gDrawingMode(#PB_2DDrawing_Default)
gSetPenTransform(penOriginX+200,penOriginY+470,penRotation,penScale,penScale)
gPie(200,470,100,100,-90,270)
gResetPenTransform()
gDrawingMode(#PB_2DDrawing_Outlined)
gSetPenSize(20)
gSetPenTransform(penOriginX+450,penOriginY+470,penRotation,penScale,penScale)
gPie(450,470,90,90,-90,270)
EndProcedure
Procedure demo_gArc()
gSetPenColor(RGBA($00,$00,$00,$FF))
gDrawText(5,5,"draw arc's at different sizes",$FF000000)
j=0
For i = 1 To 30
j + i + 5
gArc(j,45,i*0.5,i*0.5,-90,270)
Next i
j=0
gDrawText(5,65,"...with different colors",$FF000000)
For i = 1 To 30
j + i + 5
gSetPenColor(colors(i))
gArc(j,105,i*0.5,i*0.5,-90,270)
Next i
j=0
gDrawText(5,125,"...with patterns",$FF000000)
For i = 1 To 30
j + i + 5
gSetPenPattern(i,$FFFFFFFF,$FF000000)
gArc(j,165,i*0.5,i*0.5,-90,270)
Next i
j=0
gSetPenImage(bufferedBackground)
gDrawText(5,185,"...with image texture",$FF000000)
For i = 1 To 30
j + i + 5
gArc(j,225,i*0.5,i*0.5,-90,270)
Next i
gSetPenImage(bufferedBackground)
gSetPenTransform(penOriginX+200,penOriginY+470,penRotation,penScale,penScale)
For i = 10 To 100 Step 5
gArc(200,470,i,i,-180,180)
Next i
gResetPenTransform()
gSetPenSize(20)
gSetPenTransform(penOriginX+450,penOriginY+470,penRotation,penScale,penScale)
gArc(450,470,90,90,-90,270)
gArc(450,470,70,70,-180,45)
gArc(450,470,110,110,-135,45)
EndProcedure
Procedure demo_gSetPenPattern()
Protected patternCount.l = #PenPatternMax
gDrawText(5,5,"use "+Str(patternCount+1)+" (0-"+Str(patternCount)+") different pen patterns",$FF000000)
k = 0
For i = 0 To 7
For j = 0 To 6
gSetPenPattern(k,$FFFFFFFF,$FF000000)
If j&1
gBox(i*100,40+j*75,90,60)
ElseIf i&1
gEllipse(45+i*100,70+j*75,45,30)
Else
gPie(45+i*100,70+j*75,45,30,0,315)
EndIf
gDrawText(i*100,25+j*75,Str(k),$FF000000)
If k=#PenPatternMax : Break 2 : EndIf
k+1
Next j
Next i
EndProcedure
Procedure demo_gSetPenStyle()
gDrawText(5,5,"set different pen line styles",$FF000000)
gDrawingMode(#PB_2DDrawing_Outlined)
gSetFont("Arial",53)
gSetPen($FF000000,2)
Dim myStyle.f(5)
mystyle(0)=5 ; length of line
mystyle(1)=2 ; length of space
mystyle(2)=15 ; length of line
mystyle(3)=2 ; length of space
mystyle(4)=25 ; length of line
mystyle(5)=2 ; length of space
k = 0
For i = 0 To 5
gSetPenStyle(i,@myStyle(),6)
gLine(10,100+i*80,150,00)
gBox(180,75+i*80,50,50)
gCircle(280,100+i*80,25)
gEllipse(380,100+i*80,50,25)
gDrawText(450,60+i*80,"Text")
Next i
EndProcedure
Procedure demo_gDrawText()
gSetPenColor(RGBA($00,$00,$00,$FF))
gDrawText(5,5,"draw text at different sizes",$FF000000)
j=0
For i = 1 To 30
j + i + 5
gSetFont("Arial",i*1.5,#PB_Font_Bold)
gDrawText(j*1.2,45-i,"A")
Next i
j=0 : gSetFont()
gDrawText(5,65,"...with different colors",$FF000000)
For i = 1 To 30
j + i + 5
gSetPenColor(colors(i))
gSetFont("Arial",i*1.5,#PB_Font_Bold)
gDrawText(j*1.2,105-i,"B")
Next i
j=0 : gSetFont()
gDrawText(5,125,"...with patterns",$FF000000)
For i = 1 To 30
j + i + 5
gSetPenPattern(i,$FFFFFFFF,$FF000000)
gSetFont("Arial",i*1.5,#PB_Font_Bold)
gDrawText(j*1.2,165-i,"C")
Next i
j=0 : gSetFont()
gSetPenImage(bufferedBackground)
gDrawText(5,185,"...with image texture",$FF000000)
For i = 1 To 30
j + i + 5
gSetFont("Arial",i*1.5,#PB_Font_Bold)
gDrawText(j*1.2,225-i,"D")
Next i
j=0 : gSetFont()
gDrawText(5,245,"...outlined",$FF000000)
gDrawingMode(#PB_2DDrawing_Outlined)
For i = 1 To 30
j + i + 5
gSetPenColor(colors(i))
gSetFont("Arial",i*1.5,#PB_Font_Bold)
gDrawText(j*1.2,285-i,"E")
Next i
j = 300
gSetPenImage(bufferedBackground)
gDrawingMode(#PB_2DDrawing_Default)
gSetPenTransform(penOriginX+400,penOriginY+470,penRotation,penScale,penScale)
gSetFont("Arial",40) : gDrawText(50,j,"Normal") : j + gTextHeight()
gSetFont("Arial",40,#PB_Font_Bold) : gDrawText(50,j,"Bold") : j + gTextHeight()
gSetFont("Arial",40,#PB_Font_Italic) : gDrawText(50,j,"Italic") : j + gTextHeight()
gSetFont("Arial",40,#PB_Font_Underline) : gDrawText(50,j,"Underlined") : j + gTextHeight()
gSetFont("Arial",40,#PB_Font_StrikeOut) : gDrawText(50,j,"StrikeOut") : j + gTextHeight()
gSetFont("Arial",40,#PB_Font_Bold|#PB_Font_Italic|#PB_Font_Underline|#PB_Font_StrikeOut)
gDrawText(50,300+gTextHeight()*5,"All Styles")
gDrawingMode(#PB_2DDrawing_Outlined)
gSetPenSize(5)
;gSetPenAlignment(#PenAlignmentInset)
j=300
gSetFont("Arial",130) : gDrawText(250,j,"Outlined") : j + gTextHeight()
gDrawingMode(#PB_2DDrawing_Default)
gSetFont("Arial",130) : gDrawText(250,j,"Outlined",RGBA($FF,$FF,$FF,$FF))
gDrawingMode(#PB_2DDrawing_Outlined)
gSetFont("Arial",130) : gDrawText(250,j,"Outlined")
EndProcedure
Procedure demo_gDrawRotatedText()
gSetFont("Courier New",60,#PB_Font_Bold)
gSetPenSize(3)
For i = 50 To 0 Step -10
gDrawingMode(#PB_2DDrawing_Default)
gDrawRotatedText(10,10,"Rotated Text",i,RGBA($00,$00,$00,$FF-i*5))
gSetPenPattern(8,RGBA(0,0,0,$FF-i*5),0);RGBA($FF,$FF,$FF,$FF-i*5))
gDrawRotatedText(350,330,"PatternText",i-20)
gDrawingMode(#PB_2DDrawing_Outlined)
gDrawRotatedText(10,700,"Rotated Text",-i,RGBA($00,$00,$00,$FF-i*5))
Next i
EndProcedure
Procedure demo_gLine()
EndProcedure
Procedure demo_gBezier()
EndProcedure
Procedure demo_gTriangle()
EndProcedure
Procedure demo_gPoly()
EndProcedure
For i = 0 To 100
colors(i) = RGBA(Random($FF),Random($FF),Random($FF),$FF)
Next i
pbLogo = LoadImage(#PB_Any,#PB_Compiler_Home+"Examples\Sources\Data\PureBasicLogo.bmp")
If Not pbLogo : MessageRequester("ERROR","Unable to load PureBasic logo!") : End : EndIf
Background = CreateImage(#PB_Any,10,10,32|#PB_Image_Transparent)
If StartDrawing(ImageOutput(Background))
DrawingMode(#PB_2DDrawing_Gradient|#PB_2DDrawing_AllChannels)
BackColor($FF00FFFF)
FrontColor($FFFF0000)
CircularGradient(5, 5, 5)
Circle(5,5,5)
;Box(0,0,10,10)
StopDrawing()
EndIf
Procedure.i createWelcomeLogo()
Protected img
img = CreateImage(#PB_Any,600,400,32|#PB_Image_Transparent)
If gStartDrawing(ImageOutput(img))
gBox(0,0,600,400,RGBA($20,$20,$20,$EE))
gSetFont("Courier New",20,#PB_Font_Bold)
Define A$ = "Welcome to the world of"
i = 300 - gTextWidth(A$)*0.5
gDrawText(i,10,A$,RGBA($FF,$FF,$00,$FF))
gDrawingMode(#PB_2DDrawing_Outlined)
gSetPenSize(2)
gSetFont("Courier New",100,#PB_Font_Bold|#PB_Font_Italic)
A$ = "gDrawing!"
i = 300 - gTextWidth(A$)*0.5
gDrawText(i-2,28,A$,RGBA($00,$00,$FF,$FF))
gDrawText(i+2,32,A$,RGBA($00,$00,$FF,$FF))
gDrawText(i ,30,A$,RGBA($FF,$FF,$FF,$FF))
gSetFont()
gDrawingMode(#PB_2DDrawing_Default)
gDrawText(105,255,"Please choose a command on the left side.",$FFFFFFFF)
gDrawText(105,280,"Then play with the trackbars on the right side.",$FFFFFFFF)
gStopDrawing()
EndIf
ProcedureReturn gBufferImage(ImageID(img))
EndProcedure
If gInit()
img = CreateImage(#PB_Any,800,800,24)
welcomeLogo = createWelcomeLogo()
bufferedBackground = gBufferImage(ImageID(Background))
bufferedPbLogo = gBufferImage(ImageID(pbLogo))
mainWin = OpenWindow(#PB_Any,0,0,1100,800,"gDrawing feature demo",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
modeWin = ListViewGadget(#PB_Any,0,0,150,800)
AddGadgetItem(modeWin,-1,"Welcome") : demoProcedures(00) = @initpicture()
AddGadgetItem(modeWin,-1,"gBox()") : demoProcedures(01) = @demo_gBox()
AddGadgetItem(modeWin,-1,"gLine() / gLineXY()") : demoProcedures(02) = @demo_gLine()
AddGadgetItem(modeWin,-1,"gEllipse()") : demoProcedures(03) = @demo_gEllipse()
AddGadgetItem(modeWin,-1,"gCircle()") : demoProcedures(04) = @demo_gCircle()
AddGadgetItem(modeWin,-1,"gPlot()") : demoProcedures(05) = @demo_gPlot()
AddGadgetItem(modeWin,-1,"gDrawText()") : demoProcedures(06) = @demo_gDrawText()
AddGadgetItem(modeWin,-1,"gDrawRotatedText()") : demoProcedures(07) = @demo_gDrawRotatedText()
AddGadgetItem(modeWin,-1,"gPie()") : demoProcedures(08) = @demo_gPie()
AddGadgetItem(modeWin,-1,"gArc()") : demoProcedures(09) = @demo_gArc()
AddGadgetItem(modeWin,-1,"gBezier()") : demoProcedures(10) = @demo_gBezier()
AddGadgetItem(modeWin,-1,"gTriangle()") : demoProcedures(11) = @demo_gTriangle()
AddGadgetItem(modeWin,-1,"gPoly()") : demoProcedures(12) = @demo_gPoly()
AddGadgetItem(modeWin,-1,"gSetPenPattern()") : demoProcedures(13) = @demo_gSetPenPattern()
AddGadgetItem(modeWin,-1,"gSetPenStyle()") : demoProcedures(14) = @demo_gSetPenStyle()
SetGadgetState(modeWin,0)
TextGadget(#PB_Any,960,20,130,20,"Pen Rotation")
Define slider_penRotation = TrackBarGadget(#PB_Any,960,40,130,20,0,360)
TextGadget(#PB_Any,960,60,130,20,"Pen Scale")
Define slider_penScale = TrackBarGadget(#PB_Any,960,80,130,20,10,100) : SetGadgetState(slider_penScale,20)
TextGadget(#PB_Any,960,100,130,20,"Pen Origin X")
Define slider_penOriginX = TrackBarGadget(#PB_Any,960,120,130,20,0,100)
TextGadget(#PB_Any,960,140,130,20,"Pen Origin Y")
Define slider_penOriginY = TrackBarGadget(#PB_Any,960,160,130,20,0,100)
TextGadget(#PB_Any,960,220,130,20,"Global Rotation")
Define slider_globalRotation = TrackBarGadget(#PB_Any,960,240,130,20,0,7200) : SetGadgetState(slider_globalRotation,3600)
TextGadget(#PB_Any,960,260,130,20,"Global Scale (Zoom)")
Define slider_globalScale = TrackBarGadget(#PB_Any,960,280,130,20,0,100) : SetGadgetState(slider_globalScale,10)
TextGadget(#PB_Any,960,300,130,20,"Global Shear X")
Define slider_globalShearX = TrackBarGadget(#PB_Any,960,320,130,20,0,100) : SetGadgetState(slider_globalShearX,50)
TextGadget(#PB_Any,960,340,130,20,"Global Shear Y")
Define slider_globalShearY = TrackBarGadget(#PB_Any,960,360,130,20,0,100) : SetGadgetState(slider_globalShearY,50)
If gStartDrawing( ImageOutput(img) )
;gClear( RGBA($AA,$AA,$AA,$FF) )
initpicture()
gStopDrawing()
EndIf
imgWin = ImageGadget(#PB_Any,150,0,800,800,ImageID(img))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Define gadget = EventGadget()
If gadget = slider_penRotation
penRotation = GetGadgetState(slider_penRotation)
gadget = modeWin
ElseIf gadget = slider_penScale
penScale = GetGadgetState(slider_penScale)*0.05
gadget = modeWin
ElseIf gadget = slider_penOriginX
penOriginX = GetGadgetState(slider_penOriginX)
gadget = modeWin
ElseIf gadget = slider_penOriginY
penOriginY = GetGadgetState(slider_penOriginY)
gadget = modeWin
ElseIf gadget = slider_globalRotation
globalRotation = GetGadgetState(slider_globalRotation)*0.1 - 360.0
gadget = modeWin
ElseIf gadget = slider_globalScale
globalScale = GetGadgetState(slider_globalScale)*0.1+0.1
gadget = modeWin
ElseIf gadget = slider_globalShearX
globalShearX = GetGadgetState(slider_globalShearX) / 50 - 1.1
gadget = modeWin
ElseIf gadget = slider_globalShearY
globalShearY = GetGadgetState(slider_globalShearY) / 50 - 1.1
gadget = modeWin
EndIf
If gadget = modeWin
Define item.l = GetGadgetState(modeWin)
If item >= 0 And item <= CountGadgetItems(modeWin)
Define demo.demoProc = demoProcedures(item)
If demo
If gStartDrawing( ImageOutput(img) )
gShearAt(400,400,globalShearX,globalShearY)
gScaleAt(400,400,globalScale,globalScale)
gRotateAt(400,400,globalRotation)
gClear( RGBA($AA,$AA,$AA,$FF) )
gSetTextAntialiasMode(#TextAntialiasMode_ClearTypeGridFit)
;gSetTextAntialiasMode(#TextAntialiasMode_Antialias)
;gSetTextAntialiasMode(#TextAntialiasMode_AntialiasGridFit)
demo()
gResetTransform()
gStopDrawing()
SetGadgetState(imgWin,ImageID(img))
EndIf
EndIf
EndIf
EndIf
EndSelect
ForEver
gEnd()
EndIf
Re: slow drawing
is there more information about the fantastic danilo gdrawing.pbi file.
Some more explanations are so desirable
Some more explanations are so desirable
Re: slow drawing
Is this really much faster ?ludoke wrote:is there more information about the fantastic danilo gdrawing.pbi file.
If so, it's a bit strange because the VectorDrawing library and this gdrawing.pbi file both seem to use GDI+
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)