Compile error
Compile error
Could someone tell me what is wrong with this line of code?
Line 167 drawline((Xpos),(Ypos),z,R,15,b1,b2,1,0)
Here's the compiler error on line 167.
fbh_clk.bas(167) error 3: Expected End-of-Line in 'drawline((Xpos),(Ypos),z,R,15,b1,b2,1,0)'
If I comment out line 167 then it compiles.
Line 167 drawline((Xpos),(Ypos),z,R,15,b1,b2,1,0)
Here's the compiler error on line 167.
fbh_clk.bas(167) error 3: Expected End-of-Line in 'drawline((Xpos),(Ypos),z,R,15,b1,b2,1,0)'
If I comment out line 167 then it compiles.
Re: Compile error
How is defined drawline ?
Sub drawline(??????,.....
Sub drawline(??????,.....
Re: Compile error
@SARG
This code is from a FreeBasic Horse Clock by dodicat.
Here's the link to the source code from February 2018.
viewtopic.php?p=243874#p243874
The reason I want to get this clock working properly is because it works on Linux.
Here's a snippet of code.
#macro drawline(x,y,ang,length,col,x2,y2,flag,flag2)
ang2=ang:ang2=ang2*.0174532925199433
x2=(x)+length*Cos(ang2)
y2=(y)-length*Sin(ang2)
If flag>1 Then :thickline(x,y,x2,y2,(rad/flag),col,tmp,flag2):s1+=tmp:End If
#endmacro
This is another example how drawline is used. This works
drawline(Xpos,Ypos,(h+90)-5*(360-m)/60,.6*R,Rgb(10,100,200),tmp1,tmp2,50,1) 'hour
The problem code. Line 167
drawline((Xpos),(Ypos),z,R,15,b1,b2,1,0)
This code is from a FreeBasic Horse Clock by dodicat.
Here's the link to the source code from February 2018.
viewtopic.php?p=243874#p243874
The reason I want to get this clock working properly is because it works on Linux.
Here's a snippet of code.
#macro drawline(x,y,ang,length,col,x2,y2,flag,flag2)
ang2=ang:ang2=ang2*.0174532925199433
x2=(x)+length*Cos(ang2)
y2=(y)-length*Sin(ang2)
If flag>1 Then :thickline(x,y,x2,y2,(rad/flag),col,tmp,flag2):s1+=tmp:End If
#endmacro
This is another example how drawline is used. This works
drawline(Xpos,Ypos,(h+90)-5*(360-m)/60,.6*R,Rgb(10,100,200),tmp1,tmp2,50,1) 'hour
The problem code. Line 167
drawline((Xpos),(Ypos),z,R,15,b1,b2,1,0)
Re: Compile error
Compile the code with the '-pp' option.
That produces a '*.pp.bas' file (source file after pre-processing).
Then debug the '*.pp.bas' file as a source file.
For more information, see Macros in the Programmer's Guide.
That produces a '*.pp.bas' file (source file after pre-processing).
Then debug the '*.pp.bas' file as a source file.
For more information, see Macros in the Programmer's Guide.
Re: Compile error
@fxm
I am still correcting a lot of errors in the clk.pp.bas file. Some of the errors are like this: s1+=tmp, which needs to be changed to s1 += tmp. FreeBasic 1.09 did not care about not having spaces. Starting with 1.10, it requires spaces on certain parts of code. Thanks for your expertise about using the -pp compiler directive.
I am still correcting a lot of errors in the clk.pp.bas file. Some of the errors are like this: s1+=tmp, which needs to be changed to s1 += tmp. FreeBasic 1.09 did not care about not having spaces. Starting with 1.10, it requires spaces on certain parts of code. Thanks for your expertise about using the -pp compiler directive.
Re: Compile error
Indeed, I noticed it on old user sources.
The safest thing is that any operator is separated from the other terms (before and after) by a space.
Re: Compile error
To fix the errors : change 2 lines by adding parenthesis for col. I have not an explaination. The result is to get &(15) instead &O15.
line 53
line 59
About s1+=tmp it's strange. I don't get this error. Fbc 1.20
line 53
Code: Select all
g+="C" &(col)
Code: Select all
g+="BM" &(xc) &"," &(yc) &"P" &(col+2) &"," &(col)
Re: Compile error
@SARG
You got it going. Thank You!
I noticed that the second hand jumps forward sometimes. Other times it jumps backwards; this could be the algorithm trying to sync the clock. Maybe Dodicat could let us know if this is a feature or a bug.
You got it going. Thank You!
I noticed that the second hand jumps forward sometimes. Other times it jumps backwards; this could be the algorithm trying to sync the clock. Maybe Dodicat could let us know if this is a feature or a bug.
Re: Compile error
Hi neil
Yes, the &something was changed a couple of versions ago, now & something ( a space between).
The hand should only jump at the first minute to align it.
But kudo for noticing the jump, I thought it would be so insignificant that testers would blame their eyesight.
I'll repair the code in the post.
Yes, the &something was changed a couple of versions ago, now & something ( a space between).
The hand should only jump at the first minute to align it.
But kudo for noticing the jump, I thought it would be so insignificant that testers would blame their eyesight.
I'll repair the code in the post.
Re: Compile error
@dodicat
I forgot how smooth your Smiths Cairo clock is. Very nice
Is there any way to make it smaller?
Then I could keep it on my Linux desktop all of the time.
viewtopic.php?p=261788#p261788
I forgot how smooth your Smiths Cairo clock is. Very nice
Is there any way to make it smaller?
Then I could keep it on my Linux desktop all of the time.
viewtopic.php?p=261788#p261788
Re: Compile error
Hi Neil.
The hard way to shrink the Cairo clock is to change manually all the sizes.
An easy way is to put the clock into an image and half the size of the image.
Here is the easy way.
I'll do the hard way later.
Click exit to kill the clock or press End.
The hard way to shrink the Cairo clock is to change manually all the sizes.
An easy way is to put the clock into an image and half the size of the image.
Here is the easy way.
I'll do the hard way later.
Click exit to kill the clock or press End.
Code: Select all
#cmdline "-s gui"
#include "fbgfx.bi"
#include once "cairo/cairo.bi"
#define _rd_ Cast(Ubyte Ptr,@colour)[2]/255
#define _gr_ Cast(Ubyte Ptr,@colour)[1]/255
#define _bl_ Cast(Ubyte Ptr,@colour)[0]/255
#define _al_ Cast(Ubyte Ptr,@colour)[3]/255
Dim Shared As cairo_font_extents_t _fonts
Dim Shared As cairo_text_extents_t _text
Const pi=4*Atn(1)
Sub InitFonts(surf As cairo_t Ptr,fonttype As String="times new roman")
If Len(fonttype) Then
cairo_select_font_face (surf,fonttype, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD)
End If
cairo_font_extents (surf, @_fonts)
End Sub
Sub Cprint(surf As cairo_t Ptr,x As Long,y As Long,text As String,size As Single,colour As Ulong)
cairo_set_font_size (surf,(size))
cairo_move_to (surf, _ ' lower left corner of text
(x) - (_text.width / 2 + _text.x_bearing), _
(y) + (_text.height / 2) - _fonts.descent)
cairo_set_source_rgba surf,_rd_,_gr_,_bl_,_al_
cairo_show_text(surf, text)
cairo_stroke(surf)
End Sub
'rectangle unused
Sub Crectangle(surf As cairo_t Ptr,x As Long,y As Long,wide As Long,high As Long,thickness As Single,colour As Ulong)
cairo_set_line_width(surf, (thickness))
cairo_set_source_rgba surf,_rd_,_gr_,_bl_,_al_
cairo_move_to(surf, (x), (y))
cairo_rectangle(surf,(x),(y),(wide),(high))
cairo_stroke(surf)
End Sub
Sub Ccircle(surf As cairo_t Ptr,cx As Long,cy As Long,radius As Long,start As Single,finish As Single,thickness As Single,colour As Ulong,Capoption As boolean)
cairo_set_line_width(surf,(thickness))
cairo_set_source_rgba surf,_rd_,_gr_,_bl_,_al_
cairo_arc(surf,(cx),(cy),(radius),(start),(finish))
If Capoption Then
cairo_set_line_cap(surf,CAIRO_LINE_CAP_ROUND)
Else
cairo_set_line_cap(surf,CAIRO_LINE_CAP_SQUARE)
End If
cairo_stroke(surf)
End Sub
Sub Cline(surf As cairo_t Ptr,x1 As Long,y1 As Long,x2 As Long,y2 As Long,thickness As Single,colour As Ulong,CapOption As boolean)
cairo_set_line_width(surf, (thickness))
cairo_set_source_rgba surf,_rd_,_gr_,_bl_,_al_
cairo_move_to(surf, (x1), (y1))
cairo_line_to(surf,(x2),(y2))
If Capoption Then
cairo_set_line_cap(surf,CAIRO_LINE_CAP_ROUND)
Else
cairo_set_line_cap(surf,CAIRO_LINE_CAP_SQUARE)
End If
cairo_stroke(surf)
End Sub
Sub SetBackgroundColour(c As cairo_t Ptr,colour As Ulong)
cairo_set_source_rgba c,_rd_,_gr_,_bl_,_al_
cairo_paint(c)
End Sub
Function setscreen(xres As Integer,yres As Integer) As cairo_t Ptr
Screenres xres,yres,32,1,fb.GFX_SHAPED_WINDOW
Var surface = cairo_image_surface_create_for_data(Screenptr(), CAIRO_FORMAT_ARGB32,xres,yres,xres*4)
Static As cairo_t Ptr res
res= cairo_create(surface)
Return res
End Function
Sub lineto(C As cairo_t Ptr,x1 As Long,y1 As Long,x2 As Long,y2 As Long,L As Single,t As Single,colour As Ulong)
Dim As Long ox,oy
Var dx=x2-x1,dy=y2-y1
Var d=Sqr(dx*dx + dy*dy)
ox=x1+L*dx/d:oy=y1+L*dy/d
cline(C,x1,y1,ox,oy,t,colour,false)
End Sub
Sub drawline(C As cairo_t Ptr,x As Long,y As Long,angle As Single,length As Long,t As Single,colour As Ulong,Byref x2 As Long=0,Byref y2 As Long=0)
angle=angle*.0174532925199433 '=4*atn(1)/180
x2=x+length*Cos(angle)
y2=y-length*Sin(angle)
cline(C,x,y,x2,y2,t,colour,true)
End Sub
Sub dial(C As cairo_t Ptr)
Dim As Long ctr,L
For z As Single=0 To 8*Atn(1)-.1 Step 8*Atn(1)/12
ctr+=1
L=Iif(Len(Str(ctr Mod 13))=2,8*2,0)
cprint(C,400-L+230*Cos(z-2*Atn(1)*(2/3)),8+300+230*Sin(z-2*Atn(1)*(2/3)),Str(ctr Mod 13),40,Rgba(200,0,0,255))
Next z
ctr=0
For z As Single=0 To 8*Atn(1)-.1 Step 8*Atn(1)/60
lineto(C,410+200*Cos(z),300-10+200*Sin(z),400,300,10,2,Rgba(200,0,200,255))
If ctr Mod 5=0 Then
CCircle(C,410+200*Cos(z),300-10+200*Sin(z),3,0,2*pi,2,Rgba(0,200,0,255),false)
lineto(C,410+200*Cos(z),300-10+200*Sin(z),400,300,20,2,Rgba(200,100,0,255))
End If
ctr+=1
Next z
End Sub
Sub rotateimage(Byref dest As Any Ptr=0,im As Any Ptr,angle As Single,shiftx As Long=0,shifty As Long=0,sc As Single=1,miss As Ulong=Rgb(255,0,255),fixedpivot As boolean=false)
Static As Integer pitch,pitchs,xres,yres,runflag
Static As Any Ptr row,rows
Static As Integer ddx,ddy,resultx,resulty
Imageinfo im,ddx,ddy,,pitch,row
If dest=0 Then
Screeninfo xres,yres,,,pitchS
rowS=Screenptr
Else
If sc<>1 Then
Dim As Integer x,y
Imageinfo dest,x,y
Imagedestroy dest:dest=0: dest=Imagecreate(x*sc,y*sc)
End If
Imageinfo dest, xres,yres,,pitchS,rows
End If
Dim As Long centreX=ddx\2,centreY=ddy\2
Dim As Single sx=Sin(angle)
Dim As Single cx=Cos(angle)
Dim As Long mx=Iif(ddx>=ddy,ddx,ddy),shftx,shfty
Var fx=sc*.7071067811865476,sc2=1/sc
If fixedpivot=false Then
shiftx+=centreX*sc-centrex
shiftY+=centrey*sc-centrey
End If
For y As Long=centrey-fx*mx+1 To centrey+ fx*mx
Dim As Single sxcy=Sx*(y-centrey),cxcy=Cx*(y-centrey)
shfty=y+shifty
For x As Long=centrex-mx*fx To centrex+mx*fx
If x+shiftx >=0 Then 'on the screen
If x+shiftx <xres Then
If shfty >=0 Then
If shfty<yres Then
resultx=sc2*(Cx*(x-centrex)-Sxcy) +centrex:resulty=sc2*(Sx*(x-centrex)+Cxcy) +centrey
If resultx >=0 Then 'on the image
If resultx<ddx Then
If resulty>=0 Then
If resulty<ddy Then
Dim As Ulong u=*Cast(Ulong Ptr,row+pitch*((resultY))+((resultX)) Shl 2 ) 'point(image)
If u<>miss Then *Cast(Ulong Ptr,rowS+pitchS*(y+shifty)+(x+shiftx) Shl 2)= u 'pset (screen)
End If:End If:End If:End If
End If:End If:End If:End If
Next x
Next y
End Sub
Function start As Long
#define incircle(cx,cy,radius,x,y) (cx-x)*(cx-x) +(cy-y)*(cy-y)<= radius*radius
dim as long xx,yy
screencontrol fb.GET_DESKTOP_SIZE ,xx,yy
#define map(a,b,x,c,d) ((d)-(c))*((x)-(a))/((b)-(a))+(c)
Dim As cairo_t Ptr C
C=setscreen(800,600)
Dim As String t,lt,s,m,h
Dim As Single sa,ma,ha
Dim As Double offset
dim as any ptr im=imagecreate(800,600)
color ,rgba(255,0,255,0)
dim as long MX,MY,BUTTON
Do
getmouse MX,MY,,BUTTON
Screenlock
Var t=Time
SetBackgroundColour(C,Rgb(0,25,25))
InitFonts(C,"comic sans MS")
dial(C)
initfonts(C) 'default times new roman
cprint(C,375,200,"Smiths",25,Rgba(20,20,20,255))
s=Mid(t,7,2):m=Mid(t,4,2):h=Mid(t,1,2)
If lt<>t Then offset=Timer
sa=map(0,60,(Vallng(s)+(Timer)-offset),360,0):ma=map(0,60,(Val(m)+Val(s)/60),360,0):ha=map(0,12,(Vallng(h)+Val(m)/60),360,0)
circle(410,400),50,rgb(200,200,200),,,,f
cprint(C,375,420,"exit",40,Rgba(20,20,20,255))
drawline(C,410,300-10,ha+90,100,15,Rgba(0,200,0,255))
drawline(C,410,300-10,ma+90,185,15,Rgba(0,200,200,255))
drawline(C,410,300-10,sa+90,199,2,Rgba(20,20,0,255))
drawline(C,410,300-10,sa+90+180,15,4,Rgba(20,20,0,255))
get(0,0)-(799,599),im
cls
screencontrol fb.SET_WINDOW_POS, xx-400,0
rotateimage(,im,0,0,0,.5,Rgb(0,25,25))
lt=t
Screenunlock
Sleep 10,1
if multikey (fb.SC_END) then exit do
Loop Until incircle(410\2,400\2,50,MX,MY) and BUTTON=1
Return 0
End Function
End start
Sleep
Re: Compile error
@dodicat
Your smaller clock does not work on Linux. I only get a black screen.
It does work OK on Windows 10.
Your smaller clock does not work on Linux. I only get a black screen.
It does work OK on Windows 10.