just want to share a small app I created, also I only needed two lines to port it from PB to Spiderbasic so thats cool
here's the code:
Code: Select all
;RollCalc by Erlend Rovik
;Calculate the length of material on a roll, eg. a roll of carpet
;
Procedure.i Icon_Roll (img.i, size.i, color.i,innout=#True,diaomk=#True)
Protected ret.i, hw.d
Protected Dim dash.d(1)
hw = size / 16.0
ret = CreateImage(img, size, size, 32, #PB_Image_Transparent)
If img = #PB_Any
img = ret
EndIf
If ret And StartVectorDrawing(ImageVectorOutput(img))
If diaomk=#True
If innout=#True
VectorSourceColor(color)
AddPathCircle(size/2, size/2,size/4)
ClosePath()
StrokePath(4.0 * hw)
VectorSourceColor(RGBA(0,0,0,255))
MovePathCursor(size/2,(size/2)-4)
AddPathLine(size-hw,(size/2)-4)
ClosePath()
MovePathCursor(size/2,(size/2)+4)
AddPathLine(size-hw,(size/2)+4)
ClosePath()
StrokePath(0.7)
StopVectorDrawing()
ElseIf innout=#False
VectorSourceColor(color)
AddPathCircle(size/2, size/2,size/4)
ClosePath()
StrokePath(4.0 * hw)
VectorSourceColor(RGBA(0,0,0,255))
MovePathCursor(size/2,(size/2)-11)
AddPathLine(size-hw,(size/2)-11)
ClosePath()
MovePathCursor(size/2,(size/2)+11)
AddPathLine(size-hw,(size/2)+11)
ClosePath()
StrokePath(0.7)
StopVectorDrawing()
EndIf
ElseIf diaomk=#False
If innout=#True
VectorSourceColor(color)
AddPathCircle(size/2, size/2,size/4)
ClosePath()
StrokePath(4.0 * hw)
VectorSourceColor(RGBA(0,0,0,255))
AddPathCircle(size/2, size/2,size/8)
ClosePath()
MovePathCursor((size/2)+(hw*2),size/2)
AddPathLine(size-(hw*2),size/2)
ClosePath()
StrokePath(1.0)
MovePathCursor(((size/2)+hw*3.5)-hw,((size/2))-hw*2)
AddPathLine(((size/2)+hw*3.5)+hw,((size/2))+hw*2)
AddPathLine(((size/2)+hw*3.5)-hw,((size/2))+hw*2)
AddPathLine(((size/2)+hw*3.5)+hw,((size/2))-hw*2)
AddPathLine(((size/2)+hw*3.5)-hw,((size/2))-hw*2)
ClosePath()
FillPath()
StopVectorDrawing()
ElseIf innout=#False
VectorSourceColor(color)
AddPathCircle(size/2, size/2,size/4)
ClosePath()
StrokePath(4.0 * hw)
VectorSourceColor(RGBA(0,0,0,255))
AddPathCircle(size/2, size/2,size/2.7)
ClosePath()
MovePathCursor((size/2)+(hw*2),size/2)
AddPathLine(size-(hw*2),size/2)
ClosePath()
StrokePath(1.0)
MovePathCursor(((size/2)+hw*3.5)-hw,((size/2))-hw*2)
AddPathLine(((size/2)+hw*3.5)+hw,((size/2))+hw*2)
AddPathLine(((size/2)+hw*3.5)-hw,((size/2))+hw*2)
AddPathLine(((size/2)+hw*3.5)+hw,((size/2))-hw*2)
AddPathLine(((size/2)+hw*3.5)-hw,((size/2))-hw*2)
ClosePath()
FillPath()
StopVectorDrawing()
EndIf
EndIf
EndIf
ProcedureReturn ret
EndProcedure
Procedure.i Icon_Thickness (img.i, size.i, color.i)
Protected ret.i, hw.d
Protected Dim dash.d(1)
hw = size / 16.0
ret = CreateImage(img, size, size, 32, #PB_Image_Transparent)
If img = #PB_Any
img = ret
EndIf
If ret And StartVectorDrawing(ImageVectorOutput(img))
VectorSourceColor(RGBA(255,0,0,255))
MovePathCursor(hw,size/2)
AddPathLine(size-hw,size/2)
ClosePath()
StrokePath(1)
VectorSourceColor(RGBA(0,0,0,255))
MovePathCursor((size/2)-hw,(size/2)-(hw*2))
AddPathLine(size/2,(size/2)-1)
AddPathLine((size/2)+hw,(size/2)-(hw*2))
ClosePath()
FillPath();StrokePath(0.7)
MovePathCursor((size/2)-hw,(size/2)+(hw*2))
AddPathLine(size/2,(size/2)+1)
AddPathLine((size/2)+hw,(size/2)+(hw*2))
ClosePath()
FillPath();StrokePath(0.7)
StopVectorDrawing()
EndIf
ProcedureReturn ret
EndProcedure
OpenWindow(0,0,0,250,70,"RollCalc (use mm)",#PB_Window_ScreenCentered)
Icon_Roll(0,30,RGBA(255,0,0,255),#True)
ImageGadget(#PB_Any,0,0,30,30,ImageID(0))
dia_in=StringGadget(#PB_Any,30,0,50,30,"86")
Icon_Roll(0,30,RGBA(255,0,0,255),#False)
ImageGadget(#PB_Any,0,30,30,30,ImageID(0))
dia_out=StringGadget(#PB_Any,30,30,50,30,"200")
Icon_Roll(0,30,RGBA(255,0,0,255),#True,#False)
ImageGadget(#PB_Any,80,0,0,30,ImageID(0))
omk_in=StringGadget(#PB_Any,110,0,50,30,"270")
Icon_Roll(0,30,RGBA(255,0,0,255),#False,#False)
ImageGadget(#PB_Any,80,30,0,30,ImageID(0))
omk_out=StringGadget(#PB_Any,110,30,50,30,"628")
Icon_Thickness(0,30,RGBA(255,0,0,255))
ImageGadget(#PB_Any,160,0,30,30,ImageID(0))
thick=StringGadget(#PB_Any,190,0,50,30,"0.54")
result=TextGadget(#PB_Any,170,35,50,30,"=47.40m")
Procedure eventcallback()
Shared thick, result, omk_out, omk_in, dia_out, dia_in
evgadget=EventGadget()
SetGadgetText(dia_out,Str(Val(GetGadgetText(dia_out))))
SetGadgetText(dia_in,Str(Val(GetGadgetText(dia_in))))
SetGadgetText(omk_out,Str(Val(GetGadgetText(omk_out))))
SetGadgetText(omk_in,Str(Val(GetGadgetText(omk_in))))
SetGadgetText(thick,StrF(ValF(GetGadgetText(thick)),2))
If evgadget=dia_out:SetGadgetText(omk_out,Str(Val(GetGadgetText(dia_out))*3.14)):EndIf
If evgadget=dia_in:SetGadgetText(omk_in,Str(Val(GetGadgetText(dia_in))*3.14)):EndIf
If evgadget=omk_out:SetGadgetText(dia_out,Str(Val(GetGadgetText(omk_out))/3.14)):EndIf
If evgadget=omk_in:SetGadgetText(dia_in,Str(Val(GetGadgetText(omk_in))/3.14)):EndIf
L.f=3.14*((Val(GetGadgetText(dia_out))+Val(GetGadgetText(dia_in)))*(Val(GetGadgetText(dia_out))-Val(GetGadgetText(dia_in)))/(4*ValF(GetGadgetText(thick))))
SetGadgetText(result,"="+StrF(L/1000,2)+"m")
EndProcedure
BindEvent(#PB_Event_Gadget,@eventcallback())
CompilerIf #PB_Compiler_OS<>#PB_OS_Web ;This is all I needed to make it compilable on both Purebasic and Spiderbasic :-)
Repeat
ev=WaitWindowEvent()
Until ev=#PB_Event_CloseWindow
CompilerEndIf