aardio 文档

aardio 范例: 窗口绘图基础: https://www.aardio.com/zh-cn/doc/library-guide/std/win/ui/drawing.html

窗口绘图基础

//窗口绘图基础: https://www.aardio.com/zh-cn/doc/library-guide/std/win/ui/drawing.html
import win.ui;
/*DSG{{*/
var winform = win.form(text="自绘示例";right=601;bottom=549)
winform.add(
plus={cls="plus";text="GDI+ 控件";left=53;top=27;right=539;bottom=513;z=1}
)
/*}}*/

import gdip;

//画背景,graphics 参数是内存画板( gdip.graphics 对象,已自动支持双缓冲优化)。
winform.plus.onDrawBackground = function(graphics,rc,bkColor,foreColor){

    //GDI+ 支持透明背景 PNG 图像
    var bmp = gdip.bitmap("~\extensions\wizard\project2\forms\images\winform.jpg");

    //绘图参数:位图,模式("expand"为九宫格切图),::RECT 结构体,九宫格切图上,右,下,左
    graphics.drawBackground(bmp,"expand",rc,140,140,100,225);

    //创建画笔,负责描边画线,GDI+ 使用 0xAARRGGBB 格式颜色值,支持 Alpha 透明通道。
    var pen = gdip.pen( 0xFFFF0000, 1, 2/*_GdipUnitPixel*/ );

    //画线
    graphics.drawLine( pen, 10, 10, 200, 100)

    //画曲线,可添加任意个坐标数值
    graphics.drawCurve(pen,
        10,10,//x,y
        100,100,//x2,y2
        50,150,//x3,y3
        200,200,//x4,y4
        50,250//x5,y5
    )

    //矩形描边
    graphics.drawRectangle(pen, 30, 30, 100, 100);

    //创建实色画刷,画刷负责填充、喷涂颜色。  
    var brush = gdip.solidBrush(0xAA0000FF);//GDI+使用 0xAARRGGBB 格式颜色值

    //用画刷填充矩形内部  
    graphics.fillRectangle(brush, 30, 30, 100, 100)

    //GDI+ 使用浮点数坐标结构体
    var p1 = ::POINTF(10,10)
    var p2 = ::POINTF(100,100)  

    //创建渐变画刷
    var lineBrush = gdip.lineBrush(p1/*渐变起始坐标*/, p2 /*渐变终止坐标*/ , 0xFF0000FF/*起始颜色*/, 0xFFFF0000/*结束颜色*/, 2/*_GdipWrapModeTileFlipY*/ )

    //为了圆形画的平滑自然,指定抗锯齿参数
    graphics.smoothingMode = 4/*_GdipSmoothingModeAntiAlias*/ ; 

    //画圆形、或椭圆
    graphics.fillEllipse(  brush, 150/*x坐标*/, 50/*y坐标*/,150/*宽*/, 120/*高*/);

    //用渐变色刷子填充矩形内部
    graphics.fillRectangle( lineBrush, 100, 100, 100, 100)

    //创建字体
    var family = gdip.family("Segoe UI");
    var curFont = family.createFont(30,2/*_GdipFontStyleItalic*/, 2/*_GdipUnitPixel*/)

    //创建字体格式
    var strformat = gdip.stringformat();  
    strformat.align = 0/*_GdipStringAlignmentNear*/; 

    //消除走样,且边作平滑处理
    graphics.textRenderingHint = 3/*_GdipTextRenderingHintAntiAliasGridFit*/;

    //设置文字区域
    var rclayout = ::RECTF(350,15,550,150) 

    graphics.drawString( "Hellow world!"  , curFont
    , rclayout,strformat,brush);

    //创建路径
    path = gdip.path();  
    path.addArc(0,0,30, 20, -90, 180);
    path.startFigure();
    path.addCurve( 
        5,30, 
        20,40,
        50,30
    )
    path.addPie(260, 10, 40, 40, 40, 110);

    //设置文字区域,GDI+ 使用浮点数矩形结构体
    rectfoat = ::RECTF(50,220,550,150); 

    //添加文字路径
    path.addstring( "AARDIO", family, 1/*_GdipFontStyleBold*/,60,rectfoat,strformat);

    //填充路径 
    graphics.fillPath(brush, path)

    //描边
    graphics.drawPath(pen, path)

    //自己创建的 GDI+ 对象,要自己释放
    pen.delete();
    brush.delete();
    lineBrush.delete();     
    strformat.delete();
    family.delete();
    curFont.delete();
    bmp.dispose();
}

//输出字符串
winform.plus.onDrawString = function(graphics,text,font,rectfoat,strformat,brush){

    if(#text){ 
        //回调参数中的 GDI+ 对象,不是自己创建的就不要释放
        //graphics.drawString(text,font,rectfoat,strformat,brush);
    }
}

winform.show();
win.loopMessage();

Markdown 格式