为什么我输入的所有鼠标事件都变成数字?



我试图在Drracket中构建一个绘图应用程序(使用语言是BSL)。我想要实现的对象是

  1. 当鼠标事件为"button-down"时,开始画线
  2. 当鼠标事件为"拖拽"时,移动当前行的终点
  3. 当mouse-event为"button-up"时,将当前行添加到画布中。所以我在
  4. 下面写了这些代码
(define (handle-mouse appstate mouse-event x-mouse y-mouse)
(cond
[(string=? mouse-event "button-down") (add-line (AppState-image appstate) x-mouse y-mouse x-mouse y-mouse "red")]
[(string=? mouse-event "drag") (move-end appstate x-mouse y-mouse)]
[(string=? mouse-event "button-up") (add-line-to-canvas appstate)]
[else appstate]))

但是当我将鼠标移动到画布中时,会出现如下错误

string=?: expects a string, given 319

这意味着输入鼠标事件是一个数字,所以我将代码更改为

(define (handle-mouse appstate mouse-event x-mouse y-mouse)
(cond
[(string? mouse-event) (cond
[(string=? mouse-event "button-down") (add-line (AppState-image appstate) x-mouse y-mouse x-mouse y-mouse "red")]
[(string=? mouse-event "drag") (move-end appstate x-mouse y-mouse)]
[(string=? mouse-event "button-up") (add-line-to-canvas appstate)])]
[else appstate])) 

所以没有更多的错误,但是程序也不响应鼠标事件。我认为这是因为一些错误,把所有的鼠标事件变成数字。但是我想不明白。有人能帮忙吗?谢谢你!

*AppState是我定义的用来显示应用状态的结构。

(define-struct AppState [image mbline boolean])

和联机的意思是;也许,一行也是一个由起点和终点组成的结构

(define-struct Line [startpoint endpoint])

你把参数顺序弄混了——事件字符串是最后一个参数,所以应该是

(define (handle-mouse appstate x-mouse y-mouse mouse-event)

相关内容

  • 没有找到相关文章

最新更新