一、goocanvas安裝
Linux mint 21.3 庫中帶有 libgoocanvas-2.0-dev,
用sudo apt install libgoocanvas-2.0-dev 安裝,安裝完成后,檢查一個 /usr/lib/x86_64-linux-gnu 下是否有libgoocanvas.so的軟件鏈接。如果沒有,或是 .so.x 等類似后面還有數字的話,則需要創建一個 libgoocanvas.so 的軟鏈接。
二、FreeBASIC安裝
freebasic 是跨平臺的,官方網址是 https://freebasic.net, Windows上用的話IDE比較多,但在linux上用比Windows上用要有趣得多,linux上用的話有很多外來庫可以使用,但不一定能在windows平臺上找到相應的庫。
Official site: https://freebasic.net/Forum: https://freebasic.net/forum/Online manual: https://freebasic.net/wiki/DocTocfbc project page: https://sourceforge.net/projects/fbc/GitHub mirror: https://github.com/freebasic/fbcDiscord: https://discord.gg/286rSdKIRC channel: ##freebasic at https://webchat.freenode.netFeatures: https://freebasic.net/wiki/CompilerFeaturesRequirements: https://freebasic.net/wiki/CompilerRequirements
到官方網址去下載最新版本,解壓到本地,查看readme.txt
下面是readme.txt中的說明,按說明先安裝需要的運行庫:
sudo apt install gcc libncurses5-dev libffi-dev libgl1-mesa-dev
????????? libx11-dev libxext-dev libxrender-dev libxrandr-dev libxpm-dev
????????? libtinfo5 libgpm-dev
下載并解壓最新FreeBASIC-x.xx.x-linux.tar.gz。打開一個terminal, 解壓的 FreeBASIC-x.xx.x-linux 并進入目錄,運行“sudo ./install.sh -i” 將 FB 設置復制到 /usr/local 中。要編譯FB程序,請安裝以下軟件包(名稱可以因您的Linux發行版而異)Debian/Ubuntu:gcc libncurses5-dev libffi-dev libgl1-mesa-devlibx11-dev libxext-dev libxrender-dev libxrandr-dev libxpm-devlibtinfo5 libgpm-devRedhead Linux:gcc ncurses-devel ncurses-compat-libs libffi-devel mesa-libGL-devellibX11-devel libXext-devel libXrender-devel libXrandr-devellibXpm-devel如果您想在 32 位系統上使用 64 位版本的 FB,需要具有 GCC 32 位 Multilib 支持和 32 位版本已安裝的庫。
然后在解壓的目錄中執行 sudo ./install.sh -i
安裝完成后,進入解壓目錄下的example子目錄,fbc hello.bas ,編譯后 ./hello 運行,能在終端上看到hello world表明安裝運行正確。
三、freebasic IDE
fbc 是個編譯器,支持它的ide很多,geany, vs code, atom 等都可用,目前我感覺用著比較舒服的是臺灣同胞寫的poseidonFB編輯器,它自智能提示,還可自己添加關鍵字。
下載主場:https://bitbucket.org/KuanHsu/poseidonfb/src/master/
運行界面
在sourceforge上還有一款比較陳年的IDE, 可下載源文件,編譯沒問題,但它用的是 iup 界面庫,是巴西石油某個項目中的一個產物,項目完成后開源了,還一直在維護,但在某些系統上 menu和toolbar混在一起,不是ide問題,是iup問題。在atom和vs code上用也比較好,有代碼美化插件可安裝使用。
四、goocanvas畫線
1. 黃色框、紅色填充、圓解矩形,呈45度角顯示Hello FB愛好者們。
'Draw a few simple items.
Sub DrawSimpleItems(x0 as integer, y0 as integer, w as integer, h as integer)
rect_item = goo_canvas_rect_new (root, x0, y0, w, h, _"line-width", 10.0, _"radius-x", 20.0, _"radius-y", 10.0, _"stroke-color", "yellow", _"fill-color", "red", _NULL)
text_item = goo_canvas_text_new (root, "Hello FB愛好者們!", x0+w/2, y0+h/2, -1, _GOO_CANVAS_ANCHOR_CENTER, _"font", "Sans 14", _NULL)
goo_canvas_item_rotate (text_item, -45, x0+w/2, y0+h/2)
End Sub
2. 畫斜線:左上角到右下角、左下角到右上角,然后清除。畫線是用polyline ,后面是可變座標點,從簡單直線到各種形裝的多點 item,? 可給不同樣子的item分組,進行組變換等。
'A function called by onButton1
Function GooCanDo(Byval ToH as integer) as gintVAR w = gtk_widget_get_allocated_width(GTK_WIDGET(canvas))VAR h = gtk_widget_get_allocated_height(GTK_WIDGET(canvas))PicItem = _goo_canvas_polyline_new_line (root, 0, 0, w, ToH*h/60, _"start-arrow", FALSE, _"end-arrow", FALSE, _"stroke-color", "red", _"line-width", 0.6, _NULL)PicItem = _goo_canvas_polyline_new_line (root, 0, h-ToH*h/60, w, 0, _"start-arrow", FALSE, _"end-arrow", FALSE, _"stroke-color", "red", _"line-width", 0.6, _NULL)DrawSimpleItems((w-200)/2, (h-200)/2, 200, 200)if ToH>=59 thenClearRootItems'Clear canvas surfacegoo_canvas_rect_new (root, 0, 0, SCREEN_W, SCREEN_H, _"fill_color", "white", _NULL) end ifReturn 0
End function
3. 清除所有線條
goocanvas會記住所有的線條,它們同屬于root item, 如果不清除的話就會越來越多,所以不用了就要清除它們。
'Clear children items in the Root of Canvans
Function ClearRootItems() as Integervar goocanvasitem = goo_canvas_item_get_child(root, 1)'i was previous defined as integer, 'it is 32-bit or 64-bit signed, viary per target platform'integer type is the same size as SizeOf(Any Ptr)i = 1Dogoocanvasitem = goo_canvas_item_get_child(root, i)If goocanvasitem <> NULL thengoo_canvas_item_remove_child(root, i)ElseExit DoEnd ifi += 1Loopprint "Item no: ", i, @goocanvasitemReturn 0
End function
4.定時畫線
時間事件 alarm(2) 表示2秒后產生 SIGALRM 事件,執行的是 wait_alarm 過程,進入過程后設置 alarm(1) 重新計數(否則停止不再觸發事件了),然后執行 timerevent 過程,timerevent 過程執行的是界面上的button1 鈕的 click
signal事件是在c的signal.h中定義的,與它同定義的還有 raise 事件,它們的由來自 unix 就有,歷史可謂優久。還有其它幾個信號,還有SIGUSR1和SIGUSR2自定義事件。這些信號是系統級的,在另一個shell的程序中可獲取它們,可以跨進程使用。
const SIGALRM=14Declare Function Signal cdecl alias "signal" (ByVal V_Signal As long, byval V_Function As Any Ptr) as Any Ptr
Declare function alarm cdecl alias "alarm" (byval __seconds as uinteger) as uinteger
......
......
......
......
......
......
Sub timerevent()on_button1_clicked(GTK_WIDGET(button1), GTK_WIDGET(drawarea1))
End Subsub wait_alarm(iSigno As Integer)'?"This is the scheduled event SIG = " & Str$(iSigno) & "--- @: " & Time$alarm(1) 'loads another alarm events: each alarm event is a single time event, so to repeat it it must be set again every timetimerevent
end subsignal(SIGALRM, @wait_alarm) 'when SIGALRM triggered, call subroutine wait_alarm
alarm(2) 'emitt SIGALRM signal after 2 seconds
畫線圖是下面的樣子
goocanvas2.0和goocanvas3.0源碼是c寫的,Backend是cairo和surface。如果不喜歡用它的畫線函數,可以自己增加自己的函數,重新編譯成 .so 后可實現自己的特殊功能。