//struct 预定义结构体 namespace builtin.struct{} class ::POINT { ctor(x=0,y=0){ this.x = x; this.y = y; } int x ; int y ; } class ::SIZE { ctor(cx=0,cy=0){ this.cx = cx; this.cy = cy; } int cx; int cy; } class ::RECT { ctor(left=0,top=0,right=0,bottom=0){ if(type(left)==="table"){ var rc = left; if(rc[["left"]]){ this.left = rc.left; this.top = rc.top; this.right = rc.right; this.bottom = rc.bottom; } else{ this.left = rc.x; this.top = rc.y; this.right = rc.x + rc.width; this.bottom = rc.y + rc.height; } } else{ this.left = left; this.top = top; this.right = right; this.bottom = bottom; } } int left; int top; int right; int bottom; @_meta; } var rectMetaTable = { inflate = function(dx,dy){ owner.left = owner.left - dx; owner.top = owner.top - dy; owner.right = owner.right + dx ; owner.bottom = owner.bottom + dy; return owner; }; offset = function(dx,dy){ owner.left = owner.left + dx; owner.top = owner.top + dy; owner.right = owner.right + dx ; owner.bottom = owner.bottom + dy; return owner; }; expand = function(dx,dy){ owner.right = owner.right + dx ; owner.bottom = owner.bottom + dy; return owner; }; move = function(dx,dy){ owner.left = owner.left + dx; owner.top = owner.top + dy; return owner; }; width = function(){ return owner.right - owner.left; } height = function(){ return owner.bottom - owner.top; } intersectsWith = function(rc) { return (rc.left < owner.right ) && (owner.left < rc.right ) && (rc.top < owner.bottom) && (owner.top < rc.bottom); } intersect = function(rc){ if(!owner.intersectsWith(rc)) return; owner.right = ..math.min(owner.right,rc.right) ; owner.bottom = ..math.min(owner.bottom,rc.bottom) owner.left = ..math.max(owner.left,rc.left) owner.top = ..math.max(owner.top,rc.top) }; copy = function(w,h){ var r = { int left = owner.left ; int top = owner.top; int right = owner.right; int bottom = owner.bottom; @::RECT._meta } if( w!==null ) r.right = r.left + w; if( h!==null ) r.bottom = r.top + h; return r; }; setPos = function(x,y,cx,cy){ if(cx===null){ cx = owner.right - owner.left } if(cy===null){ cy = owner.bottom - owner.top } if(x!==null) owner.left = x; if(y!==null) owner.top = y; owner.right = owner.left + cx; owner.bottom = owner.top + cy; return owner; }; ltrb = function(x,y,cx,cy){ if(x!==null){ owner.setPos(x,y,cx,cy) } //@Deprecated 废弃带参数的用法 return owner.left,owner.top,owner.right,owner.bottom; }; xywh = function(l,t,r,b){ if(l!==null){ //@Deprecated 废弃带参数的用法 owner.left = l; owner.top = t; owner.right = r; owner.bottom = b; } return owner.left,owner.top,owner.right-owner.left,owner.bottom-owner.top; }; float = function(f){ if(f) return owner.setPos(f.x,f.y,f.width,f.height) && null;//@Deprecated var x,y,cx,cy = owner.left,owner.top,owner.right - owner.left,owner.bottom - owner.top; if(::RECTF) return ::RECTF(x,y,cx,cy); return { float x = x; float y = y; float width = cx; float height = cy; } }; contains = function(x,y){ return (::User32.PtInRectB(owner,x,y)); }; } with rectMetaTable{ getPos = xywh; clone = copy;//@Deprecated } ::RECT2 = function(x=0,y=0,w=0,h=0){ return ::RECT(x,y,x+w,y+h); } ::RECT._meta = { _get = function(k,ownerCall){ if(!ownerCall){ if(k==="width") return owner.right - owner.left; if(k==="height") return owner.bottom - owner.top; if(k==="x") return owner.left; if(k==="y") return owner.top; } return rectMetaTable[k] }; _set = function(k,v,ownerAttr){ if(k==="width") owner.right = owner.left + v; elseif(k==="height") owner.bottom = owner.top + v; elseif(k==="x") owner.left = v; elseif(k==="y") owner.top = v; elseif(!rectMetaTable[k]) owner[[k]] = v; }; } ::OffsetRect = function(rc,dx,dy){ rc.offset(dx,dy); return true,rc; } /**intellisense() ::RECT( = 用于创建表示矩形区块的结构体。\n由内置库 builtin.struct 默认加载。\n::RECT 使用 left,top,right,bottom 等 4 个数值字段存储上、下、左、右位置。\n::RECT 结构体通过重载操作符支持读写 x,y,width,height 字段。 ::RECT(.(left,top,right,bottom) = 创建矩形区块结构体。\n可使用 4 个数值参数依次指定左(left),上(top),右(right),下(bottom)四个字段的初始值。 \n所有参数都是可选参数,未指定的字段则默认设为 0。 ::RECT(.(rectObject) = 创建矩形区块结构体。\n参数 rectObject 可以是其他 ::RECT 或 ::RECTF 结构体,\n或者直接包含 left,top,right,bottom 字段(可通过直接下标获取)的普通表,\n也可以指定支持 x,y,width,height 字段的任意对象(例如 .NET 的 System.Windows.Rect 对象)。\nectObject 可通过重载操作符返回 x,y,width,height 字段,\n\n返回新创建的 ::RECT 结构体。 ::RECT2(.(x,y,width,height) = 创建矩形区块结构体。\n可使用 4 个数值参数依次指定 x 坐标,y 坐标,宽度(width),高度(height)。\n所有参数都是可选参数,未指定的字段则默认设为 0。\n传入参数会转换为 left,top,right,bottom 格式并用于调用 ::RECT 构造函数。\n返回 ::RECT 结构体对象。 ::POINT( = 整型坐标结构体\n此结构体通过标准库 builtin.struct 默认加载 ::POINT(.(x,y) = 创建整型坐标结构体\n可选在参数中指定 x,y 坐标初始值 ::SIZE( = 整型尺寸结构体\n此结构体通过标准库 builtin.struct 默认加载 ::SIZE(.(cx,cy) = 创建整型尺寸结构体\n可选在参数中指定宽高 cx,cy 初始值 ::RECT() = !rect. ::RECT2 () = !rect. ::POINT() = !point. ::SIZE() = !size. ?::RECT = !rect. ?::RECT2 = !rect. ?::POINT = !point. ?::SIZE = !size. ?.getRect = !rect. ?.getItemRect = !rect. ?.getClientRect = !rect. !rect = ::RECT 结构体对象,包含用于表示区块位置的数值字段 left,top,right,bottom 。 !rect.left = 左(数值)。\n结构体实际存储的字段,原生类型为 32 位 int 类型。 !rect.top = 上(数值)。\n结构体实际存储的字段,原生类型为 32 位 int 类型。 !rect.right = 右(数值)。\n结构体实际存储的字段,原生类型为 32 位 int 类型。 !rect.bottom = 下(数值)。\n结构体实际存储的字段,原生类型为 32 位 int 类型。 !rect.width = 宽度(数值)。\n通过重载元方法支持的字段,读写此字段会自动转换为读写 right 字段。\n如果需要同时获取 x,y,width,height 等 4 个字段,改用 xywh 方法会更快。 !rect.height = 高度(数值)。\n通过重载元方法支持的字段,读写此字段会自动转换为读写 bottom 字段。\n如果需要同时获取 x,y,width,height 等 4 个字段,改用 xywh 方法会更快。 !rect.x = x 坐标(数值)。\n通过重载元方法支持的字段,读写此字段会自动转换为读写 left 字段。\n如果需要同时获取 x,y,width,height 等 4 个字段,改用 xywh 方法会更快。 !rect.y = y 坐标(数值)。\n通过重载元方法支持的字段,读写此字段会自动转换为读写 top 字段。\n如果需要同时获取 x,y,width,height 等 4 个字段,改用 xywh 方法会更快。 !rect.inflate( = 扩大区块并返回矩形区块自身 !rect.inflate(.(左右单位,上下单位) = 扩大区块并返回矩形区块自身\n忽略参数请传入0,不可省略\n上,下,左,右分别扩大指定的单位\n负数为缩小 !rect.offset( = 移动矩形框并返回自身 !rect.offset(.(横偏移,纵偏移) = 移动矩形框并返回自身,矩形大小不变,\n左上移使用负坐标,右下移使用正坐标\n忽略参数请传入0,不可省略 !rect.expand( = 扩展或缩小右下角坐标 !rect.expand(.(dx,dy) = dx指定正数扩展右边,负数缩小右边,\ndy指定正数扩展底边,负数缩小底边\n左上角不变,\n返回自身 !rect.move( = 移动左上角坐标 !rect.move(.(dx,dy) = 使用参数指定的x,y坐标偏移量移动左上角坐标,\n正数向右下移动,负数向左上移动,\n右下角位置不变\n返回自身\n如果需要移动坐标且大小不变请改用offset函数\n移动到指定坐标而不是偏移量请改用setPos函数 !rect.intersectsWith( = 检测两个矩形区块是否碰撞相交 !rect.intersectsWith(.(rc) = 检测两个矩形区块是否碰撞相交 !rect.intersect( = 与参数指定的矩形区块相交。\n如果仅检测两个区块是否相交请改用 intersectsWith 函数。 !rect.intersect(.(rc) = 如果与参数指定的矩形区块相交,则更新当前区块为相交的区块并返回自身。\n失败返回 null 值。 !rect.inflate() = !rect. !rect.offset() = !rect. !rect.expand() = !rect. !rect.move() = !rect. !rect.float() = 复制为 ::RECTF 结构体并返回该结构体。\n不允许指定参数。\n\n仅在使用 GDI+ 时aardio 会自动导入 :RECTF 结构体以后,\n此函数返回的对象才拥用 :RECTF 结构体的方法,\n否则仅返回具有相同字段的兼容结构体(不具有方法)。\n!rectf. !rect.copy( = 复制并返回新的矩形区块结构体。 !rect.copy(.(width,height) = 可选在参数中返回矩形区块的新宽度、新高度。\n所有参数都可以省略。\n此函数不会改变对象自身的值。 !rect.copy() = !rect. !rect.ltrb() = 返回结构体的 left,top,right,bottom 等 4 个值。\n::RECT,::RECTF 结构体都有这个同名函数,作用一样。 !rect.xywh() = 返回结构体的左上角坐标 x,y 以及宽度 width,高度 height 等4个值。\n::RECT,::RECTF 结构体都有这个同名函数,作用一样。 !rect.getPos() = 此方法是 xywh 方法的别名。\n返回结构体的左上角坐标 x,y 以及宽度 width,高度 height 等4个值。\n::RECT,::RECTF 结构体都有这个同名函数,作用一样。 !rect.setPos( = 重新调整坐标与大小,返回结构体自身。 !rect.setPos(.(x,y,cx,cy) = 移动到 x,y 指定的坐标,\n可选用 cx,cy 重新指定宽度和高度,\n所有参数可选,不指定则保持旧值。\n::RECT,::RECTF 结构体都有这个同名函数,作用一样。 !rect.setPos() = !rect. !rect.contains(.(x,y) = 检测指定的 x,y 坐标是否位于矩形区块内 !point = ::POINT 结构体对象,包含用于表示坐标的数值字段 x,y !point.x = x坐标 !point.y = y坐标 !size = ::SIZE 结构体对象,包含用于表示大小的数值字段 cx,cy !size.cx = 宽 !size.cy = 高 ::OffsetRect(.(rc,dx,dy) = 移动矩形框,\n此函数已废弃,请直接调用 rc.offset 函数 end intellisense**/ /**details(结构体定义) aardio 已默认定义以下结构体: ```aardio class ::POINT { ctor(x=0,y=0){ this.x = x; this.y = y; } int x ; int y ; } class ::SIZE { ctor(cx=0,cy=0){ this.cx = cx; this.cy = cy; } int cx; int cy; } class ::RECT { ctor(left=0,top=0,right=0,bottom=0){ this.left = left; this.top = top; this.right = right; this.bottom = bottom; } int left; int top; int right; int bottom; @_meta; } ``` end details**/