-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.aardio
348 lines (333 loc) · 8.49 KB
/
main.aardio
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
//导入标准库
import fsys;
import gdip.bitmap;
import process;
import win.timer;
import win.ui;
import win.ui.atom;
import win.ui.menu;
//导入自定义库
import config;
import multiMonitors;
//声明全局常量和变量
_version = "0.5.0";
clip = {};//剪贴板数据
value = {};//图片地址数组
/*DSG{{*/
var winlist = win.form(text="列表";right=99;bottom=19;bgcolor=3618615;border="none";exmode="toolwindow";max=false;min=false;mode="popup")
winlist.add(
button_menu={cls="plus";text="QuickViewPic";left=0;top=0;right=100;bottom=20;bgcolor=-13951306;color=16777215;dl=1;dr=1;dt=1;font=LOGFONT(h=-14);notify=1;z=1};
custom={cls="custom";left=0;top=20;right=100;bottom=40;dl=1;dr=1;hide=1;z=2}
)
/*}}*/
var atom,hwnd = winlist.atom("FA63F815-E17E-47C0-AC07-2026D7B6D745");
if(!atom){
win.quitMessage(); return;
}
var winpic = winlist.loadForm("\dlg\pic_plus.aardio");
winlist.custom.loadForm("\dlg\listbox.aardio");
winlist.custom.orphanWindow();
/*窗口贴边自动吸附{{*/
var isDock,dockSide;//吸附状态
var mtimer = win.timer(winlist,100);//鼠标监视定时器
mtimer.onTimer = function(){
if( !isDock ){
winlist.custom.show(false);
return;
}
var msPos = ::POINT();
::User32.GetCursorPos( msPos );
var rc = ::RECT();
::User32.UnionRect(rc,winlist.getRect(true),winlist.custom.getRect(true));//获取完整的窗口RECT
if( rc.contains(msPos.x,msPos.y) ){
winpic.plus.show();
winlist.custom.show();
}
else{
winlist.custom.show(false);
winpic.plus.show(false);
}
}
var wtimer = win.timer(winlist,500);//窗口吸附定时器
wtimer.onTimer = function(){
if( isDock ){
var rc = winlist.getRect(true);
var index = multiMonitors.getIndex((rc.left + rc.right)/2,(rc.top + rc.bottom)/2);
if(index==-1)
return;
::User32.UnionRect(rc,winlist.getRect(true),winlist.custom.getRect(true));
var rc_screen = multiMonitors.getRect(index,true);
var wrc = winlist.getRect(true);
select(dockSide) {
case 'left'
wrc.setPos(rc_screen.left,rc.top);
case 'right'
wrc.setPos(rc_screen.right-rc.width(),rc.top);
}
winlist.setRect(wrc);
publish("Move",index,dockSide);
}
}
winlist.wndproc = function(hwnd,message,wParam,lParam){
//更新窗口吸附状态
if( message == 3/*_WM_MOVE*/ ){
var rc = winlist.getRect(true);
var index = multiMonitors.getIndex((rc.left + rc.right)/2,(rc.top + rc.bottom)/2);
if(index==-1){
winlist.center();
return;
}
var rc_screen = multiMonitors.getRect(index,true);
if( rc.left <= rc_screen.left )
dockSide = "left";
else if( rc.right >= rc_screen.right )
dockSide = "right";
else
dockSide = null;
if( dockSide )
isDock = true;
else
isDock = false;
config.X = rc.left;
config.Y = rc.top;
}
}
/*}}*/
/*添加菜单{{*/
var menu = win.ui.popmenu( winlist );
menu.addTable( {
{ "刷新列表"; function(id){
loaddata();
} };
{ /*分隔线*/ };
{ "默认模式"; function(id){
menu.check(id,,0);
menu.check(4,false);
menu.check(5,false);
menu.check(6,false);
config.Mode = "Default";
loaddata();
} };
{ "目录模式"; function(id){
menu.check(id,,0);
menu.check(3,false);
menu.check(5,false);
menu.check(6,false);
config.Mode = "CustomDir";
loaddata();
} };
{ "列表模式"; function(id){
menu.check(id,,0);
menu.check(3,false);
menu.check(4,false);
menu.check(6,false);
config.Mode = "CustomList";
loaddata();
} };
{ "剪贴板"; function(id){
menu.check(id,,0);
menu.check(3,false);
menu.check(4,false);
menu.check(5,false);
config.Mode = "Clip";
loaddata();
} };
{ /*分隔线*/ };
{ "高级设置"; function(id){
mtimer.disable();
winlist.custom.show(false);
select( config.Mode ){
case 'Default'
winlist.msgbox("默认模式下无高级设置。","信息");
case 'CustomDir'{
if( winlist.loadForm("\dlg\customdir_setting.aardio").doModal() )
loaddata();
}
case 'CustomList'{
if( winlist.loadForm("\dlg\customlist_setting.aardio").doModal() )
loaddata();
}
case 'Clip'{
winlist.loadForm("\dlg\clip_setting.aardio").doModal();
loaddata();
}
}
mtimer.enable();
} };
{ "其它设置"; function(id){
mtimer.disable();
winlist.custom.show(false);
if( winlist.loadForm("\dlg\global_setting.aardio").doModal() )
initialize();
mtimer.enable();
} };
{ /*分隔线*/ };
{ "主页"; function(id){
process.openUrl("https://github.com/xenon2333/QuickViewPic");
} };
{ "关于"; function(id){
mtimer.disable();
winlist.custom.show(false);
var str = "QuickViewPic v"++_version++'\r\nWritten by Xenon\r\nEmail:xenon2333@qq.com';
winlist.msgbox(str,"关于");
mtimer.enable();
} };
{ "退出"; function(id){
winlist.close();
} };
} )
select(config.Mode){
case 'Default'
menu.check(3);
case 'CustomDir'
menu.check(4);
case 'CustomList'
menu.check(5);
case 'Clip'
menu.check(6);
else
menu.check(3);
}
/*}}*/
/*菜单按钮{{*/
winlist.button_menu.onMouseEnter = function(wParam,lParam){
winlist.button_menu.text = "Drag to Move";
}
winlist.button_menu.onMouseLeave = function(wParam,lParam){
winlist.button_menu.text = "QuickViewPic";
}
winlist.button_menu.onMouseDown = function(wParam,lParam){
winlist.hitCaption();
}
winlist.button_menu.onRightMouseUp = function(wParam,lParam){
menu.popup();
}
/*}}*/
/*加载数据{{*/
loaddata = function(){
value = {};
select( config.Mode ){
case 'Default'{
var data = fsys.list( io._exedir,,{"*.jpg";"*.jpeg";"*.png";"*.bmp";"*.gif"});
var n = table.count( data )/2;
if( n != 0 ){
for(i=1;n;1){
value[i] = {};
value[i][1] = data[i];
value[i][2] = data[data[i]];
}
}
}
case 'CustomDir'{
if( !io.exist(config.CustomDir.current) ){
winlist.msgbox("当前路径不存在,程序已自动调整到默认目录。","提示");
config.CustomDir.current = io._exedir;
}
var data = fsys.list( config.CustomDir.current,,{"*.jpg";"*.jpeg";"*.png";"*.bmp";"*.gif"});
var n = table.count( data )/2;
if( n != 0 ){
for(i=1;n;1){
value[i] = {};
value[i][1] = data[i];
value[i][2] = data[data[i]];
}
}
}
case 'CustomList'{
var n = table.count( config.CustomList );
if( n != 0 ){
for(i=1;n;1){
value[i] = {};
value[i][1] = io.splitpath( config.CustomList[i] ).file;
value[i][2] = config.CustomList[i];
}
}
}
case 'Clip'{
var n = table.count( ..clip );
if( n != 0 ){
for(i=1;n;1){
value[..clip[i][1]] = {};
value[..clip[i][1]][1] = ..clip[i][3];
value[..clip[i][1]][2] = ..clip[i][2];
}
}
}
}
publish("LoadData",);
}
/*}}*/
/*窗口初始化{{*/
initialize = function(){
winlist.width = winlist.dpiScale(config.Width);
if( config.Theme == 'Light' ){
winlist.button_menu.skin({
background={
default=0xFFF5F5F5;
hover=0xFFF5F5F5
};
color={
default=0xFFB61E2B;
}
})
}
else {
winlist.button_menu.skin({
background={
default=0xFFB61E2B;
hover=0xFFB61E2B
};
color={
default=0xFFFFFFFF;
}
})
}
winlist.redrawBackground();
publish("ChangeTheme",);
loaddata();
}
/*}}*/
/*监视剪贴板{{*/
win.clip.viewer( winlist );
winlist.onDrawClipboard = function(){
if( config.Mode == 'Clip' && config.Clip.monitor == 'ON' ){
var hbmp = win.clip.readBitmap();
if( hbmp == null )
return;
var n = table.count( ..clip ) +1;
..clip[n] = {};
..clip[n][1] = n;
..clip[n][2] = hbmp;
..clip[n][3] = tostring( time.tick() );
loaddata();
publish("ClipChange",);
publish("AutoSave",);
}
}
/*}}*/
/*订阅消息{{*/
subscribe("ChangeHeight",function(...){
var para = {...}
winlist.custom.height = para[1];
})
subscribe("AutoSave",function(...){
var n = table.count(..clip);
if( config.Clip.autosave == 'ON' ){
if( !io.exist( config.Clip.savepath ) )
io.createDir( config.Clip.savepath );
var path = config.Clip.savepath ++ "\" ++ tostring( time(), config.Clip.filename ) ++ config.Clip.format;
var bmp = gdip.bitmap( ..clip[n][2] );
bmp.save( path );
bmp.dispose();
}
} )
/*}}*/
/*程序初始化{{*/
mtimer.enable();
wtimer.enable();
initialize();//窗口初始化
if( config.X && config.Y && multiMonitors.getIndex(config.X,config.Y)!=-1 )
winlist.setPos(config.X,config.Y);
win.setTopmost(winlist.hwnd);
/*}}*/
win.loopMessage();