aardio高仿某浏览器下载软件界面
By
admin
at 2020-03-28 • 1人收藏 • 1971人看过
这个作为aardio界面练习的第一弹吧
之前发过listbox自绘初始版, 最近稍微修改了下, 自绘适应性更好了点, 后面会把这个listbox这个自绘封装成为一个独立的调用库.
自绘源码如下: 未用到其他任何界面库
//GDI自绘 import win.ui; import fonts.fontAwesome; /*DSG{{*/ var winform = win.form(text="listbox自绘(GDI方式)";right=778;bottom=472;border="none") winform.add( bk={cls="bk";text=" 下载 - 云加速由迅雷提供";left=0;top=0;right=779;bottom=33;align="left";bgcolor=16185078;color=5921370;dl=1;dr=1;dt=1;font=LOGFONT(h=-16;name='微软雅黑');forecolor=12632256;linearGradient=0;z=2}; listbox={cls="listbox";left=0;top=32;right=779;bottom=432;bgcolor=16777215;clipch=1;db=1;dl=1;dr=1;dt=1;items={};msel=1;ownerDraw=1;z=1}; plus={cls="plus";text="清空已下载";left=488;top=440;right=599;bottom=468;border={color=-6250332;width=1};color=7895160;db=1;dr=1;font=LOGFONT(h=-17;name='微软雅黑');z=3}; plus2={cls="plus";text="新建";left=605;top=440;right=683;bottom=468;align="right";border={color=-6250332;width=1};color=7895160;db=1;dr=1;font=LOGFONT(h=-17;name='微软雅黑');iconColor=32768;iconStyle={align="left";font=LOGFONT(h=-17;name='FontAwesome');padding={left=13}};iconText='\uF067';textPadding={right=9};z=4}; plus3={cls="plus";text="设置";left=689;top=440;right=767;bottom=468;align="right";border={color=-6250332;width=1};color=7895160;db=1;dr=1;font=LOGFONT(h=-17;name='微软雅黑');iconColor=32768;iconStyle={align="left";font=LOGFONT(h=-17;name='FontAwesome');padding={left=13}};iconText='\uF013';textPadding={right=9};z=5} ) /*}}*/ //添加无边框标题栏 import win.ui.simpleWindow; win.ui.simpleWindow(winform,,,,,3); //先设置行高(自绘用) winform.listbox.onMeasureItem = function(measureItem){ measureItem.itemHeight = 51; } //图标 import win.imageList; import process; var listboxsel = null; var beforesel = null; var colorsel = false; var opensel = false; var filesel = false; import fsys; import fsys.info; import fsys.file; import fsys.dlg; var filename; var boxTab = {}; //以下均是增加一些本地文件到列表 var dirPath; if( !io.exist(dirPath) ) { dirPath = fsys.dlg.opendir() } if(!dirPath){ dirPath = "D:\"; } var files,,dirs = ..fsys.list(dirPath); for(i=1;#files) { filename = files[ i ]; var sfi = fsys.info.get(files[filename],0x10/*_SHGFI_USEFILEATTRIBUTES*/ | 0x4000/*_SHGFI_SYSICONINDEX*/ ); var file = fsys.file(files[filename],"r"); var fileSize = tonumber(file.size64()); file.close();//不关掉后面删除就会出错 if(fileSize/1024 >= 1){ if(fileSize/1024/1024 >= 1){ sizes = tostring(math.round(fileSize/1024/1024,2))++" MB"; }else { sizes = tostring(math.round(fileSize/1024,2))++" KB"; } }else { sizes = tostring(fileSize)++" B"; } table.mixin(boxTab,{ iImage = sfi.iIcon; text = filename; size = sizes ; filePath = files[filename] }); winform.listbox.add(table.tostring(boxTab)) } //在行间开始自绘 winform.listbox.onDrawItem = function(drawItem){ gdi.selectBrush( function(hdc,pen,brush){ //获取并分解需要显示的数据(字符串转表) var strTab = eval(winform.listbox.getItemText(drawItem.itemID + 1)) var rc = drawItem.rcItem; gdi.fillRect(hdc,0xFFFFFF,rc); if (drawItem.itemID > 0) { gdi.drawLine(hdc,rc.left, rc.top,rc.right, rc.top); } if (drawItem.itemState & 1/*_ODS_SELECTED*/) { gdi.fillRect(hdc,0xFFF5E2,rc); }else { if(listboxsel == (drawItem.itemID+1)){ gdi.fillRect(hdc,0xEEB7FF,rc); } } //删除文件 if(colorsel){ var x,y = win.getMessagePos(); var item = winform.listbox.hitTest(x,y,true); if((drawItem.itemID+1) == item){ font = ::LOGFONT(weight=700;color=0x6112FF;name='FontAwesome';h=-16); gdi.textOut(hdc,font,'\uF057',/*rc.width()/2+345*/rc.right-30, rc.top+20); }else { font = ::LOGFONT(weight=700;color=0x9C9C9C;name='FontAwesome';h=-16); gdi.textOut(hdc,font,'\uF057',/*rc.width()/2+345*/rc.right-30, rc.top+20); } }else { font = ::LOGFONT(weight=700;color=0x9C9C9C;name='FontAwesome';h=-16); gdi.textOut(hdc,font,'\uF057',/*rc.width()/2+345*/rc.right-30, rc.top+20); } if(opensel){ var x,y = win.getMessagePos(); var item = winform.listbox.hitTest(x,y,true); if((drawItem.itemID+1) == item){ font = ::LOGFONT(weight=500;color=0x6112FF;name='FontAwesome';h=-16); gdi.textOut(hdc,font,'\uF0F6 打开',/*rc.width()/2+190*/rc.right-105, rc.top+20); }else { font = ::LOGFONT(weight=300;color=0x9C9C9C;name='FontAwesome';h=-16); gdi.textOut(hdc,font,'\uF0F6 打开',/*rc.width()/2+190*/rc.right-105, rc.top+20); } }else { font = ::LOGFONT(weight=300;color=0x9C9C9C;name='FontAwesome';h=-16); gdi.textOut(hdc,font,'\uF0F6 打开',/*rc.width()/2+190*/rc.right-105, rc.top+20); } if(filesel){ var x,y = win.getMessagePos(); var item = winform.listbox.hitTest(x,y,true); if((drawItem.itemID+1) == item){ font = ::LOGFONT(weight=500;color=0x6112FF;name='FontAwesome';h=-16); gdi.textOut(hdc,font,'\uF115 文件夹',/*rc.width()/2+260*/rc.right-205, rc.top+20); }else { font = ::LOGFONT(weight=300;color=0x9C9C9C;name='FontAwesome';h=-16); gdi.textOut(hdc,font,'\uF115 文件夹',/*rc.width()/2+260*/rc.right-205, rc.top+20); } }else { font = ::LOGFONT(weight=300;color=0x9C9C9C;name='FontAwesome';h=-16); gdi.textOut(hdc,font,'\uF115 文件夹',/*rc.width()/2+260*/rc.right-205, rc.top+20); } //文件图标 win.imageList.shell( 0/*_SHIL_LARGE*/ ).draw(strTab.iImage,hdc,rc.left+20,rc.top+10); //文件名 font = ::LOGFONT(weight=400;color=0x000000); gdi.textOut(hdc,font,strTab.text,rc.left+60, rc.top+10); //文件大小 font = ::LOGFONT(weight=300;color=0xB0B0B0); gdi.textOut(hdc,font,strTab.size,rc.left+60, rc.top+30); },drawItem.hDC,0xF5FDFF/*背景色*/,0xEEEEEE/*画笔色*/) } winform.listbox.wndproc = function(hwnd,message,wParam,lParam){ select(message) { case 0x200/*_WM_MOUSEMOVE*/ { var x,y = win.getMessagePos(); var item = winform.listbox.hitTest(x,y,true); if(item == null){ return ; } if(listboxsel == item){ /* 若鼠标在同一行item内游动 */ x,y = win.toClient(winform.listbox.hwnd,x,y); for(i=1;3;1){ select(i) { case 1 { //open var rc = winform.listbox.getItemRect(item); rc.left = rc.right-105; rc.right = rc.left+60; rc.top = rc.top+10; rc.bottom = rc.bottom-10 ; //判断鼠标游动的区间是不是在[删除]按钮范围 if( ::PtInRect(rc,x,y) ){ if(opensel == false){ //鼠标从[删除]按钮外部移动到内部区域 opensel = true; //设置更新区,并更新 winform.listbox.invalidate(winform.listbox.getItemRect(item)) winform.listbox.update(); break ; } continue ; //一直在内部区域游动,则不更新 }else { if(opensel == true){ //鼠标从内到外 opensel = false; //设置更新区,并更新 winform.listbox.invalidate(winform.listbox.getItemRect(item)) winform.listbox.update(); break ; } continue ; //一直在外部区域游动,则不更新 } } case 2 { //file var filerc = winform.listbox.getItemRect(item); filerc.left = filerc.right-205; filerc.right = filerc.left+70; filerc.top = filerc.top+10; filerc.bottom = filerc.bottom-10 ; //判断鼠标游动的区间是不是在[删除]按钮范围 if( ::PtInRect(filerc,x,y) ){ if(filesel == false){ //鼠标从[删除]按钮外部移动到内部区域 filesel = true; //设置更新区,并更新 winform.listbox.invalidate(winform.listbox.getItemRect(item)) winform.listbox.update(); break; } continue ; //一直在内部区域游动,则不更新 }else { if(filesel == true){ //鼠标从内到外 filesel = false; //设置更新区,并更新 winform.listbox.invalidate(winform.listbox.getItemRect(item)) winform.listbox.update(); break ; } continue ; //一直在外部区域游动,则不更新 } } case 3 { //del var delrc = winform.listbox.getItemRect(item); delrc.left = delrc.right-30; delrc.top = delrc.top+20; delrc.bottom = delrc.bottom-20 ; //判断鼠标游动的区间是不是在[删除]按钮范围 if( ::PtInRect(delrc,x,y) ){ if(colorsel == false){ //鼠标从[删除]按钮外部移动到内部区域 colorsel = true; //设置更新区,并更新 winform.listbox.invalidate(winform.listbox.getItemRect(item)) winform.listbox.update(); break; } continue ; //一直在内部区域游动,则不更新 }else { if(colorsel == true){ //鼠标从内到外 colorsel = false; //设置更新区,并更新 winform.listbox.invalidate(winform.listbox.getItemRect(item)) winform.listbox.update(); break ; } continue ; //一直在外部区域游动,则不更新 } } } } return ; }else { //设置hover效果 listboxsel = item; if(beforesel == null){ //第一次执行,初始化 beforesel = listboxsel; }else { //先关闭上次绘制区域 if(beforesel){ winform.listbox.invalidate(winform.listbox.getItemRect(beforesel),0) } beforesel = listboxsel; } //绘制当前区域 winform.listbox.invalidate(winform.listbox.getItemRect(item)); winform.listbox.update(); } } case 0x202/*_WM_LBUTTONUP*/ { //删除功能 if(colorsel){ /* 若鼠标在删除按钮区域内单击了 */ var selindex = winform.listbox.selIndex var strTab = winform.listbox.getItemText(selindex); var tabStr = eval(strTab) var ret = winform.msgboxTest("您确定要删除 ["++tabStr.text++"] 文件吗?"); if(ret){ winform.listbox.delete(selindex); colorsel = false; } return ; }; //打开文件 if(opensel){ /* 若鼠标在打开按钮区域内单击了 */ var selindex = winform.listbox.selIndex var strTab = winform.listbox.getItemText(selindex); var tabStr = eval(strTab) process.execute(tabStr.filePath); return ; } //打开文件夹 if(filesel){ /* 若鼠标在打开按钮区域内单击了 */ var selindex = winform.listbox.selIndex var strTab = winform.listbox.getItemText(selindex); var tabStr = eval(strTab) var path = io.splitpath(tabStr.filePath); process.execute(path.dir); return ; } } case 0x20A/*_WM_MOUSEWHEEL*/{ var wheelDelta = raw.convert({int wParam=wParam },{word vk;word delta}).delta; if( wheelDelta > 0 ){ ::SendMessageInt(winform.listbox.hwnd, 0x115/*_WM_VSCROLL*/, 0, 0); }else { ::SendMessageInt(winform.listbox.hwnd, 0x115/*_WM_VSCROLL*/, 1, 0); } return 0; }; else { } } } //底部按钮皮肤 var bskin={ background={ default=0xFFF8F8F8; hover=0xFFD1D1D1 }; } winform.plus.skin(bskin) winform.plus2.skin(bskin) winform.plus3.skin(bskin) winform.show(); win.loopMessage();
1 个回复 | 最后更新于 2020-03-28
登录后方可回帖
针对上面的应用封装了个库
listboxEx.aardio
使用的话:
mainform.aardio
进一步的封装, 只能有灵感的时候了...