一、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 后可实现自己的特殊功能。