【分享】取色器

JRJJ 1月前 288

最近研究了取色器,最初基于光庆大佬的:https://blog.csdn.net/sdlgq/article/details/129097601

效果:

源码:

import win.ui;
/*DSG{{*/
var winform = win.form(text="取色器";right=699;bottom=279;border="thin";edge=1;exmode="toolwindow")
winform.add(
c={cls="edit";left=600;top=104;right=695;bottom=122;z=3};
color={cls="edit";left=600;top=136;right=696;bottom=154;db=1;dr=1;multiline=1;z=1};
plus={cls="plus";left=601;top=3;right=701;bottom=103;db=1;dr=1;z=2};
static={cls="static";text="16进制ARGB";left=512;top=104;right=595;bottom=120;align="right";transparent=1;z=4};
static2={cls="static";text="10进制";left=544;top=136;right=592;bottom=152;align="right";notify=1;transparent=1;z=5}
)
/*}}*/

/**
三种取色器:
	1,10种基本颜色(以及8种子色)基于:https://blog.csdn.net/sdlgq/article/details/129097601
	2,钉钉头像设置使用的8种基本颜色
	3,5组经典对比色
@author JRJJ.

最终都会执行,上级通过这2个字段取值。不知是否有更专业的写法?:
//10进制argb
winform.color.text = color
//16进制argb
winform.c.text=tohex(color)
//发送消息,用于触发上级
User32.SendNotifyMessage(winform.hwnd,0/*_WM_NULL*/,null,null);
**/
//10进制转为16进制,不包含0x
var toHex=function(rgb){
	return string.slice(tostring(rgb,16),(3))
}
//argb 10进制转为16进制,包含0x
var tohex = function(argb){
	var str = toHex(argb)
	//避免左侧00被省略
	return string.format("0x%08s",str)
}
var rgb2argb = function(rgb){
	var str = string.concat(toHex(rgb));
	//至少6位,不足前面补0
	str = string.format("%06s",str);
	//var strnew = string.concat('',string.slice(str,5,6),string.slice(str,3,4),string.slice(str,1,2));
	var argb =  "0xff"+str
	//console.log(rgb,str,argb,tonumber(argb))
	return tonumber(argb)
}


/*钉钉头像默认色彩{{*/
var ddrgbs={0x0089ff,0x00b042,0x6f9200,0xff92ff,0xe34986,0xb963d3,0xc3ac1a,0x884d31,0xd33f0e}
var argbcolors={};
//简单色彩
for(i=1;9;1){
	argbcolors[i]=rgb2argb(ddrgbs[i])
	winform.add(
		["main"+i] = {cls="plus";left=50*(i-1);top=110;right=50*i;bottom=160;notify=1;notifyid=i;}
	)
	winform["main"+i].foreground = argbcolors[i]
	winform["main"+i].color = 0xFFFFFFFF
	winform["main"+i].oncommand = function(id,event){
		var color=argbcolors[i]
		winform.color.text=color
		winform.c.text=tohex(color)
		winform.plus.foreground=color ;
		::User32.SendNotifyMessage(winform.hwnd,0/*_WM_NULL*/,null,null);
	}
}
/*}}*/

/*经典对比色{{*/
var cs = {
	{
		//rgb 名字 bgr
		{0x002EA6,'克莱因蓝'},
		{0xFFE78F,'拿坡里黄'}
	},
	{
		{0xD7000F,'中国红'},
		{0xF1F2E5,'鱼肚白'}
	},
	{
		{0xFF770F,'爱马仕橙'},
		{0x000010,'漆黑'}
	},
	{
		{0x91B822,'茶绿'},
		{0xFFE76F,'松花'}
	},
	{
		{0x80D1C8,'蒂芙尼蓝'},
		{0xFFD4A9,'浅驼色'}
	},
	{
		{0x8BA583,'莫兰迪绿'},
		{0xCDA59E,'莫兰迪粉'}
	}	
}

var i = 1;
var bgrcs={}
for(k,v in cs){
	{
		var i=2*(k-1)+1
		bgrcs[i]=rgb2argb(v[1][1])
		winform.add(
			["classic"+i] = {cls="plus";left=140*(k-1);top=170;right=140*k-2;bottom=220;notify=1;notifyid=i;}
		)
		winform["classic"+i].foreground = bgrcs[i]
		winform["classic"+i].color = 0xFFFFFFFF
		if(i==9)winform["classic"+i].color=0xffffFFFF
		winform['classic'+i].text=v[1][2]+string.format("#%06s",string.concat(toHex(v[1][1])))
		winform["classic"+i].oncommand = function(id,event){
			var color=bgrcs[i]
			winform.color.text=color
			winform.c.text=tohex(color)
			winform.plus.foreground=color ;
			::User32.SendNotifyMessage(winform.hwnd,0/*_WM_NULL*/,null,null);
		}
	}
	{
		var i=2*k
		bgrcs[i]=rgb2argb(v[2][1])
		winform.add(
			["classic"+i] = {cls="plus";left=140*(k-1);top=220;right=140*k-2;bottom=270;notify=1;notifyid=i;}
		)
		winform["classic"+i].foreground = bgrcs[i]
		winform["classic"+i].color = 0x000000
		if(i==6)winform["classic"+i].color=0xFFFFFF
		winform['classic'+i].text=v[2][2]+string.format("#%06s",string.concat(toHex(v[2][1])))
		winform["classic"+i].oncommand = function(id,event){
			var color=bgrcs[i]
			winform.color.text=color
			winform.c.text=tohex(color)
			winform.plus.foreground=color ;
			::User32.SendNotifyMessage(winform.hwnd,0/*_WM_NULL*/,null,null);
		}
	}
}
/*}}*/

/*基本色彩{{*/
for(i=1;8;1){
	winform.add(
		["color"+i] = {cls="plus";left=50*(i-1);top=50;right=50*i;bottom=100;notify=1;key=i;text=tostring(i)}
	)
}
//主色
var godkingcolors = {
	[1]=4292804649;
	[2]=4293691150;
	[3]=4294571008;
	[4]=4278231147;
	[5]=4278232749;
	[6]=4283474175;
	[7]=4284889783;
	[8]=4287390800;
	[9]=4287401100;
	[10]=4293681825;
	YELLOW={[1]=4287596544;[2]=4291214336;[3]=4294039808;[4]=4294571008;[5]=4294768759;[6]=4294899875;[7]=4294966722;[8]=4294966759};
	CYAN={[1]=4278203960;[2]=4278212699;[3]=4278222209;[4]=4278232749;[5]=4278235839;[6]=4285449161;[7]=4288270803;[8]=4291487208};
	namesCH={[1]="红";[2]="橙";[3]="黄";[4]="绿";[5]="青";[6]="蓝";[7]="紫";[8]="咖";[9]="灰";[10]="粉"};
	RED={[1]=4287299606;[2]=4289855519;[3]=4291100707;[4]=4292804649;[5]=4293215814;[6]=4293819499;[7]=4294289562;[8]=4294761173};
	BLUE={[1]=4280106078;[2]=4281360793;[3]=4282351559;[4]=4283474175;[5]=4286626303;[6]=4289188607;[7]=4291221759;[8]=4292667391};
	namesEN={[1]="RED";[2]="ORANGE";[3]="YELLOW";[4]="GREEN";[5]="CYAN";[6]="BLUE";[7]="PURPLE";[8]="COFFEE";[9]="GRAY";[10]="PINK"};
	PURPLE={[1]=4281802595;[2]=4282853761;[3]=4283642265;[4]=4284889783;[5]=4286466535;[6]=4288768767;[7]=4290605823;[8]=4292326655};
	PINK={[1]=4286395478;[2]=4288430443;[3]=4290662531;[4]=4293681825;[5]=4294935497;[6]=4294354641;[7]=4294954479;[8]=4294764538};
	GREEN={[1]=4278205992;[2]=4278215745;[3]=4278222677;[4]=4278231147;[5]=4278234738;[6]=4284989311;[7]=4288204985;[8]=4291421398};
	ORANGE={[1]=4287910661;[2]=4290603785;[3]=4291852043;[4]=4293691150;[5]=4293958722;[6]=4294291821;[7]=4294626972;[8]=4294828746};
	COFFEE={[1]=4282790184;[2]=4283776049;[3]=4285222205;[4]=4287390800;[5]=4290413930;[6]=4293371268;[7]=4294948498;[8]=4294956215};
	GRAY={[1]=4281742902;[2]=4283058762;[3]=4285558896;[4]=4287401100;[5]=4289440683;[6]=4290624957;[7]=4291875024;[8]=4293059298}
}
for(i=1;10;1){
	winform.add(
		["plus"+i] = {cls="plus";left=50*(i-1);top=0;right=50*i;bottom=50;notify=1;notifyid=i;}
	)
	winform["plus"+i].foreground = godkingcolors[i]
	winform["plus"+i].text =  godkingcolors.namesCH[i]++'\n'++godkingcolors.namesEN[i]
	winform["plus"+i].color = 0xFFFFFFFF
	winform["plus"+i].oncommand = function(id,event){
		var color=godkingcolors[i]
		//color=tostring(string.right(color,8))
		winform.color.text=color
		winform.c.text=tohex(color)
		winform.plus.foreground=color ;
		::User32.SendNotifyMessage(winform.hwnd,0/*_WM_NULL*/,null,null);
		for(n=1;8;1){
			winform["color"+n].foreground = godkingcolors[godkingcolors.namesEN[i]][n];
			winform["color"+n].oncommand = function(id,event){
				var key = owner.key;
				var color = godkingcolors[godkingcolors.namesEN[i]][n];
				//color = string.right(color,8)
				winform.color.text = color
				winform.c.text=tohex(color)
				winform.plus.foreground=color;
				::User32.SendNotifyMessage(winform.hwnd,0/*_WM_NULL*/,null,null);
			}
		}
	}
}
i=1
for(n=1;8;1){
	winform["color"+n].foreground = godkingcolors[godkingcolors.namesEN[i]][n];
	winform["color"+n].oncommand = function(id,event){
		var key = owner.key;
		var color = godkingcolors[godkingcolors.namesEN[i]][n];
		//color = string.right(color,8)
		winform.color.text = color
		winform.c.text=tohex(color)
		winform.plus.foreground=color;
		::User32.SendNotifyMessage(winform.hwnd,0/*_WM_NULL*/,null,null);
	}
}
/*}}*/

winform.static2.oncommand = function(id,event){
	
}

winform.show();
win.loopMessage();
最新回复 (1)
  • 光庆 1月前
    0 2

返回