//core 初始化 import util.metaProperty; namespace gdip.core{} namespace gdip{ ::Gdiplus := ..raw.loadDll("Gdiplus.dll"); _dll = ::Gdiplus; var $ = _dll; GdiplusStartup = $.api("GdiplusStartup","int(int& token,struct& inputbuf,pointer outputbuf)") GdiplusShutdown = $.api("GdiplusShutdown","void(int token)") GdiplusStartupInput = class{ int GdiplusVersion; int DebugEventCallback; int SuppressBackgroundThread; int SuppressExternalCodecs; } var defaultToken; //<-- function open(){ if(defaultToken) return; var uInput = GdiplusStartupInput(); uInput.GdiplusVersion = 1 var re,token = GdiplusStartup(0,uInput); if(re) error("GDI+ 初始化错误。" ,2) defaultToken = token; } function close(){ if(defaultToken){ GdiplusShutdown(defaultToken); defaultToken = null; } } open(); ..table.gc(self,"close"); //<--table.gc 按调用顺序的逆序析构对象 errMsg = { "GenericError! an error on the method call."; "InvalidParameter!"; "OutOfMemory!"; "ObjectBusy!"; "InsufficientBuffer!"; "NotImplemented!"; "Win32Error!"; "WrongState!"; "Aborted!"; "FileNotFound!"; "ValueOverflow!"; "AccessDenied!"; "UnknownImageFormat!"; "FontFamilyNotFound!"; "FontStyleNotFound!"; "NotTrueTypeFont!"; "UnsupportedGdiplusVersion!"; "GdiplusNotInitialized!"; "PropertyNotFound!"; "PropertyNotSupported!"; "ProfileNotFound!"; } checkError = function( err,ci = 1 ){ if( err ) error( errMsg[err] : "Unknown Error",ci + 1 ); } self.assert = function(err,...) { if( err ) error(errMsg[err] : "Unknown Error",2) return ... } self.assert2 = function(err,...) { if( err ) error(errMsg[err] : "Unknown Error",3) return ... } class ::RECTF{ ctor(x=0,y=0,width=0,height=0){ if(type(x)==="table"){ var rc = x; if(rc[["left"]]){ this.x = rc.left; this.y = rc.top; this.width = rc.right - rc.left; this.height = rc.bottom - rc.top; } else{ this.x = rc.x; this.y = rc.y; this.width = rc.width; this.height = rc.height; } } else{ this.x = x; this.y = y; this.width = width; this.height = height; } } float x; float y; float width; float height; @_meta; } ::RECTF._meta = { _get = { ltrb = function(x,y,cx,cy){ if(x!==null){ //@Deprecated 废弃带参数的用法 owner.x = x; owner.y = y; owner.width = cx; owner.height = cy; } return owner.x,owner.y,owner.x + owner.width,owner.y + owner.height; }; xywh = function(l,t,r,b){ if(l!==null){ //@Deprecated 废弃带参数的用法 owner.x = l; owner.y = t; owner.width = r - l; owner.height = b - t; } return owner.x,owner.y,owner.width,owner.height; }; setPos = function(x,y,cx,cy){ if(x!==null)owner.x = x; if(y!==null)owner.y = y; if(cx!==null)owner.width = cx; if(cx!==null)owner.height = cy; }; copy = function(w,h){ return ::RECTF(owner.x,owner.y,w : owner.width,h : owner.height); }; } } with ::RECTF._meta._get{ getPos = xywh; clone = copy;//@Deprecated } class ::POINTF{ ctor(x=0,y=0){ this.x = x; this.y = y; } float x ; float y ; } self.POINTF = POINTF; self.RECTF = RECTF; } /**intellisense(gdip) open() = 初始化GDI+\n导入gdip时会默认执行此函数 close() = 关闭GDI+\n在程序退出时会自动调用此函数\n一般不需要显示调用此函数 errMsg[__] = 根据返回值取错误信息 checkError(__/*请输入GDI+函数返回值*/) = 如果有错误调用error函数抛出异常 checkError(__/*请输入GDI+函数返回值*/,2) = 如果有错误调用error函数抛出异常\n参数2指定抛出异常的调用级别\n2表示调用当前函数的函数 assert(__/*请输入GDI+函数返回值*/) = 校验GDI+函数返回值\n如果返回值非零,则抛出错误信息\n否则返回该函数的所有输出参数 assert2(__/*请输入GDI+函数返回值*/) = 校验GDI+函数返回值\n如果返回值非零,则向上层调用函数抛出错误信息\n否则返回该函数的所有输出参数 end intellisense**/ /**intellisense() ?::RECTF = !rectf. end intellisense**/ /**intellisense(::) ::RECTF( = 创建表示浮点格式区块的结构体。\n由 GDI+ 基础支持库(gdip.core)加载。\ngdip.image, gdip.bitmap, gdip.graphics, plus 控件等都已经自动加载 gdip.core。 ::RECTF(.(x,y,width,height) = 创建表示浮点格式区块的结构体。\n可使用 4 个数值参数依次指定 x 坐标,y 坐标,宽度(width),高度(height)四个字段的初始值。 \n所有参数都是可选参数,未指定的字段则默认设为 0。 ::RECTF(.(rectObject) = 创建表示浮点格式区块的结构体。\n参数 rectObject 可以是其他 ::RECTF 或 ::RECT 结构体,\n或者直接包含 left,top,right,bottom 字段(可通过直接下标获取)的普通表,\n也可以指定支持 x,y,width,height 字段的任意对象(例如 .NET 的 System.Windows.Rect 对象)。\nectObject 可通过重载操作符返回 x,y,width,height 字段,\n\n返回新创建的 ::RECTF 结构体。 ::POINTF( = 浮点格式坐标 ::POINTF(.(x,y) = 浮点格式坐标 ::RECTF() = !rectf. ::POINTF() = !point. ::RECTF() = !rectf. ::POINTF() = !point. ::Gdiplus = !dllModule. end intellisense**/ /**intellisense(!rectf) x = x坐标 y = y坐标 width = 宽 height = 高 ltrb() = 返回结构体的 left,top,right,bottom 等 4 个值。\n::RECT,::RECTF 结构体都有这个同名函数,作用一样。 xywh() = 返回结构体的左上角坐标 x,y 以及宽度 width,高度 height 等4个值。\n::RECT,::RECTF 结构体都有这个同名函数,作用一样。 getPos() = 此方法是 xywh 方法的别名。\n返回结构体的左上角坐标 x,y 以及宽度 width,高度 height 等4个值。\n::RECT,::RECTF 结构体都有这个同名函数,作用一样。 setPos( = 重新调整坐标与大小,返回结构体自身。 setPos(.(x,y,cx,cy) = 移动到 x,y 指定的坐标,\n可选用 cx,cy 重新指定宽度和高度,\n所有参数可选,不指定则保持旧值。\n::RECT,::RECTF 结构体都有这个同名函数,作用一样。 setPos() = !rectf. end intellisense**/