用鼠标画线的代码,见证一下aardio的强大
本帖最后由 rmajly 于 2024-1-30 16:47 编辑点击鼠标 画折线图。点击的过程中,移动鼠标指针时还能显示线条。
import win.ui;
/*DSG{{*/
winform = ..win.form(text="绘图演示";right=599;bottom=399;bgcolor=16777215)
winform.add(
plus={cls="plus";left=8;top=9;right=590;bottom=393;bgcolor=15793151;notify=1;z=1}
)
/*}}*/
import gdip.pen;
winform.plus.points ={}
winform.plus.onDrawContent = function(graphics,rc){
var pen = winform.plus.pen;
if(pen){
if( #winform.plus.points >=2 ) {
var pt,pt2;
for(i=1;#winform.plus.points-1;1){
var pt,pt2 = winform.plus.points,winform.plus.points
graphics.drawLine(pen,pt.x,pt.y,pt2.x,pt2.y)
}
}
var pt = winform.plus.points[#winform.plus.points]
if( pt && winform.plus.x2 && winform.plus.y2 ){
graphics.drawLine(pen,pt.x,pt.y,winform.plus.x2,winform.plus.y2 )
}
}
}
winform.plus.onMouseClick = function(wParam,lParam){
if( !winform.plus.pen )
winform.plus.pen = gdip.pen(0xFFFFFF00,2);
var x,y= win.getMessagePos(lParam);
table.push(winform.plus.points,{x=x;y=y} );
winform.plus.redrawTransparent()
}
winform.plus.onMouseMove = function(wParam,lParam){
winform.plus.x2,winform.plus.y2 = win.getMessagePos(lParam);
winform.plus.redrawTransparent()
}
winform.show()
win.loopMessage();
注意:
把plus控件的浮动透明属性设为false,利用plus控件提供的背景优化,可以避免绘图的时候闪烁
转自https://bbs.aardio.com/forum.php ... =%E9%BC%A0%E6%A0%87
谢谢分享。 本帖最后由 善小而为_ 于 2024-3-8 21:04 编辑
//加点注释
import gdip.pen;
winform.plus.pen = gdip.pen(0xFFFF0000,2); //画笔
var pen = winform.plus.pen; //画笔
winform.plus.points ={}; //点击坐标历史
winform.plus.onDrawContent = function(graphics,rc){
//历史坐标重画
if( #winform.plus.points >=2 ) {
var pt,pt2;
for(i=1;#winform.plus.points-1;1){
var pt,pt2 = winform.plus.points,winform.plus.points
graphics.drawLine(pen,pt.x,pt.y,pt2.x,pt2.y)
}
}
//当前鼠标移动坐标绘图
var pt = winform.plus.points[#winform.plus.points]
if( pt && winform.plus.x2 && winform.plus.y2 ){
graphics.drawLine(pen,pt.x,pt.y,winform.plus.x2,winform.plus.y2 )
}
}
//鼠标点击保存坐标
winform.plus.onMouseClick = function(wParam,lParam){
var x,y= win.getMessagePos(lParam);
table.push(winform.plus.points,{x=x;y=y} );
winform.plus.redrawTransparent()
}
//当前鼠标移动坐标
winform.plus.onMouseMove = function(wParam,lParam){
winform.plus.x2,winform.plus.y2 = win.getMessagePos(lParam);
winform.plus.redrawTransparent()
}
页:
[1]