对鼠标交互做出反应
dev_set_preferences ('graphics_window_context_menu', 'false')
dev_close_window ()
dev_update_off ()
1. ****
2. step: acquire image
3. ****
read_image (Image, 'mreut')
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, 0, 0, Width, Height, WindowHandle)
set_display_font (WindowHandle, 12, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Image)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
get_window_param (WindowHandle, 'flush', Flush)
set_window_param (WindowHandle, 'flush', 'false')
4. ****
5. step: react to mouse
6. ****
Button := 0
while (Button != 4)
Row := -1
Column := -1
dev_set_check ('~give_error')
get_mposition (WindowHandle, Row, Column, Button)
dev_set_check ('give_error')
dev_display (Image)
set_tposition (WindowHandle, Height - 40, 4)
* check if mouse cursor is over window
if (Row >= 0 and Column >= 0)
gen_circle (Circle, Row, Column, 20)
boundary (Circle, RegionBorder, 'inner')
dev_display (RegionBorder)
write_string (WindowHandle, 'Hold down mouse button to apply filter')
if (Button == 1)
* apply filter to circle if left button is pressed
reduce_domain (Image, Circle, ImageReduced)
median_image (ImageReduced, ImageMedian, 'circle', 5, 'mirrored')
overpaint_gray (Image, ImageMedian)
endif
else
write_string (WindowHandle, 'Please move mouse cursor over window')
endif
flush_buffer (WindowHandle)
endwhile
dev_display (Image)
set_window_param (WindowHandle, 'flush', Flush)
get_mposition
——返回WindowHandle
中鼠标指针和按下鼠标按钮的像素精确图像坐标;无鼠标点击则Button
(返回参数)置0
,鼠标左击置1
,鼠标右击置4
;set_tposition
——设置文本光标的位置;WindowHandle
中获取Row
、Column
和Button
,由Row
和Column
生成处理区域,由Button
决定是否处理。代码中使用median_image
对选中区域进行反应。 get_mposition (WindowHandle, Row, Column, Button) //WindowHandle已根据Image的w,h生成
gen_circle (Circle, Row, Column, 20)
reduce_domain (Image, Circle, ImageReduced) //Image已读
median_image (ImageReduced, ImageMedian, 'circle', 5, 'mirrored')
overpaint_gray (Image, ImageMedian) //将区域中给定区域以固定灰度值绘制到图像中
WindowHandle
的参数flush
默认设置为true
;false
时,所有显示操作(disp_obj/disp_text…)都重定向到缓冲区,对 WindowHandle
没有影响,flush_buffer
会将缓存内容传给WindowHandle
。 get_window_param (WindowHandle, 'flush', Flush)
set_window_param (WindowHandle, 'flush', 'false')
……
flush_buffer (WindowHandle)