aardio 控件如何旋转方向

mfk 9天前 147

请问大神 aardio 中的控件旋转方向的方法(例如旋转90度)。

我想实现以下4个控件的自身角度旋转,还有其它的控件如何旋转方向!



 import win.ui;
import inet.http;
/*DSG{{*/
var winform = win.form(text="aardio form";right=351;bottom=210)
winform.add(
custom={cls="custom";text="自定义控件";left=142;top=99;right=338;bottom=201;ah=1;aw=1;z=4};
edit={cls="edit";text="样本文本框";left=15;top=84;right=92;bottom=151;edge=1;multiline=1;z=2};
plus={cls="plus";left=176;top=16;right=287;bottom=80;foreRepeat="stretch";z=3};
static={cls="static";text="样本文字";left=24;top=27;right=148;bottom=49;transparent=1;z=1}
)
/*}}*/

winform.plus.foreground = "https://i.loli.net/2018/04/22/5adc885d7b359.jpg";

import web.view;
var wb = web.view(winform.custom);

//在浏览器控件中显示网页并执行 JavaScript 脚本
wb.html = /**
<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <script src="https://lib.baomitu.com/Chart.js/3.7.1/chart.min.js"></script>
        <style>
        #chart-container {
            width: 100%;
            height: 100%;
            position: relative;
        }
        #chart {
            width: 100% !important;
            height: 100% !important;
        }
    </style>
</head>
<body>
<canvas id="chart"></canvas> 
<script>
  
let chart = new Chart(document.getElementById('chart'), {
    type: 'bar',
    data: {
        labels: [],
        datasets: [{
            label: '访问量图表',
            data: [],
            backgroundColor: 'rgba(75, 192, 192, 0.6)'
        }]
    },
    options: {
        responsive: true,
        scales: {
            y: {
                beginAtZero: true
            }
        },
        plugins: {
            title: {
                display: true,
                text: '统计图表'
            }
        }
    }
});


</script> 
</body></html>
**/

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



最新回复 (2)
  • mfk 8天前
    0 2

    在老论坛找到一个用鼠标旋转custom控件内bim图片的实例,

    import win.ui;
    /*DSG{{*/
    var winform = win.form(text="aardio form";right=348;bottom=274)
    winform.add(
    button={cls="button";text="旋转图片";left=212;top=241;right=329;bottom=269;z=2};
    custom={cls="custom";text="custom";left=15;top=13;right=332;bottom=229;bgcolor=0xC0C0C0;z=1}
    )
    /*}}*/
    
    import mouse.hook
    
    
    var show = false;
    
    var rotateOn = false; 
    var resizeOn = false;
    
    var cusRect = null;         //custom控件的Rect
    var angle = 0;                        //鼠标绕图片中心旋转的角度
    var mouseSpeed = 10; 
    var distance = 0;                //鼠标位置与图片左上角的距离
    
    
    var brush = gdip.solidBrush( 0xFFFFFFFF );
    var bmp = gdip.bitmap("~\protest\tes.bmp")
    var img = gdip.bitmap(bmp.width,bmp.height)
    var graphics = gdip.graphics(img);
    
    //为了模拟绕中心旋转,取得画布平移的XY
    //思路:知道两点坐标,可获取中点坐标
    var getOffsetXY = function( w,h,angle ){
            
            var sinA = math.sin(math.rad(angle));
            var cosA = math.cos(math.rad(angle));
            
            var x =  (w*cosA-h*sinA)/2 ;
            var y =  (w*sinA+h*cosA)/2 ;
            
            x = w/2 - x;
            y = h/2 - y;
            
            return x,y; 
    }
    
    //一定程度避免重复计算
    //顺时针旋转1°画布平移的x,y值
    var tsltX,tsltY = getOffsetXY( bmp.width,bmp.height,1 );
    //逆时针旋转1°画布平移的x,y值
    var negTsltX,negTsltY = getOffsetXY( bmp.width,bmp.height,-1 );
    
    
    //鼠标绕图片中心旋转时相比上一次移动的角度
    //很大程度是旋转1°
    var offsetAngle = function(cusRect,mx,my){
    
            var x = mx - (cusRect.right+cusRect.left)/2;
            var y = my - (cusRect.bottom+cusRect.top)/2;
            var newAngle = ..math.round( ..math.deg(..math.atan2(y,x)))
            var offsetAngle = newAngle - angle;        
            angle = newAngle;
                    
            return offsetAngle; 
    }
    
    //绘制图片
    var draw = function( msg,p ){
            show = true;
            gdi.windowBuffer( winform.custom.hwnd,
                function( hdc,hMemDc,hMemBitmap,width,height ){
                        
                        var g = gdip.graphics(hMemDc)
                        g.compositingQuality = 2/*_GdipCompositingQualityHighQuality*/ ;
                    g.smoothingMode = 2/*_GdipSmoothingModeHighQuality*/ ;
                        select( msg ) {
                                case "rotate" {
                                        
                                        graphics.fillRectangle(brush,0,0,bmp.width,bmp.height)
                                            graphics.rotate( p.angle, 1/*_MatrixOrderAppend*/ )
                                            graphics.translate( p.tsltX,p.tsltY, 1/*_MatrixOrderAppend*/)
                                            
                                            graphics.drawImageRect(bmp,0,0,bmp.width,bmp.height)
                                            
                                            g.setClipRect(0,0,width,height);
                                            g.drawImageRect(img,0,0,width,height)
                                        
                                }
                                case "room" {
                                        graphics.drawImageRect(bmp,0,0,bmp.width,bmp.height)
                                        //graphics.drawImageRectRect(bmp,0,0,width,height,0,0,bmp.width,bmp.height)
                                            g.drawImageRect(img,0,0,width,height)
                                            //g.drawImageScale(img,winform.custom.getRect())
                                            //console.log(bmp.width,bmp.height,img.width,img.height)
                                }
                                case "redraw" {
                                                
                                            g.drawImageRect(img,0,0,width,height)
                                }
                        }
                            g.delete();
                    ::BitBlt(hdc, 0, 0, width, height, hMemDc, 0, 0, 0xCC0020/*_SRCCOPY*/);
                }
            )
    }
    
    //定义获取鼠标的移动速度
    SystemParametersInfo = ::User32.api("SystemParametersInfoA","int(int uAction,int uParam,int &lpvParam,int fuWinIni)" )
    
    winform.button.oncommand = function(id,event){
    
            cusRect = winform.custom.getRect(true);
            
            rotateOn = true;
            
            //获得当前鼠标速度以便恢复
            var rs,lpvParam = SystemParametersInfo(0x70/*_SPI_GETMOUSESPEED*/,0,0,0)
            mouseSpeed = lpvParam;
            
            var lowMouseSpeed = 5;
            //降低鼠标速度
            ::User32.SystemParametersInfo(0x71/*_SPI_SETMOUSESPEED*/,0,lowMouseSpeed,0)
            
            var mx,my = win.getMessagePos();
    
            var x = mx - (cusRect.right+cusRect.left)/2;
            var y = my - (cusRect.bottom+cusRect.top)/2;
            angle = ..math.round( ..math.deg(..math.atan2(y,x)))
            
            var hk = mouse.hook();
            hk.proc = function(msg,x,y,mouseData,injected,flags,timeStamp,extraInfo){
                    if( injected ) return;         
                select(msg) {
                        case 0x201/*_WM_LBUTTONDOWN*/{
                            rotateOn = false;
                            hk.close();
                            ::User32.SystemParametersInfo(0x71/*_SPI_SETMOUSESPEED*/,0,mouseSpeed,0);
                            
                            return true; 
                        }
                        case 0x200/*_WM_MOUSEMOVE*/{
                                if(rotateOn){
                                            var offsetAngle = offsetAngle(cusRect,x,y);
                                            
                                            var prama = {
                                                    ["angle"] = offsetAngle;
                                            };
                                            select( offsetAngle ) {
                                                    case 1 {
                                                            prama = {
                                                                    ["angle"] = 1;
                                                                    ["tsltX"] = tsltX;
                                                                    ["tsltY"] = tsltY;
                                                            }        
                                                            draw( "rotate",prama );
                                                    }
                                                    case -1 {
                                                            prama = {
                                                                    ["angle"] = -1;
                                                                    ["tsltX"] = negTsltX;
                                                                    ["tsltY"] = negTsltY;
                                                            }
                                                            draw( "rotate",prama );
                                                    }
                                                    case !0 {
                                                            prama.tsltX,prama.tsltY = getOffsetXY( bmp.width,bmp.height,offsetAngle );
                                                            draw( "rotate",prama );
                                                    }
                                            }
                                            
                                    }
                        }  
                }   
            }
    }
    
    
    
    winform.custom.onEraseBkgnd  = function(hwnd,message,wParam,lParam){
            if(show){
                    draw( "redraw" );
                return false;
            }
            //show = true;
    }
    
    
    
    
    winform.onClose = function(hwnd,message,wParam,lParam){
        bmp.dispose();
            img.dispose();
            graphics.delete();
    }
    
    winform.custom.image = "~\protest\tes.bmp";
    
    
    winform.show(); 
    win.loopMessage();



  • 光庆 8天前
    0 3
    旋转图片简单。旋转组件应该不行。可以使用plus组件+图片模拟旋转后的按钮效果。
返回