1254 |
1254 |
|
1255 |
1255 |
bool RectLess(const Rect& a, const Rect& b)
|
1256 |
1256 |
{
|
1257 |
|
return max(a.top, b.top) < min(a.bottom, b.bottom) ? a.left < b.left : a.top < b.top;
|
|
1257 |
if(a.top < b.top)
|
|
1258 |
return true;
|
|
1259 |
if(a.top == b.top)
|
|
1260 |
return a.left < b.left;
|
|
1261 |
return false;
|
1258 |
1262 |
}
|
1259 |
1263 |
|
1260 |
1264 |
void LayDes::SortItems()
|
1261 |
1265 |
{
|
1262 |
1266 |
SaveState();
|
1263 |
|
if(currentlayout < 0 || cursor.GetCount() < 2)
|
|
1267 |
int count = cursor.GetCount();
|
|
1268 |
if(currentlayout < 0 || count < 2)
|
1264 |
1269 |
return;
|
1265 |
1270 |
LayoutData& l = CurrentLayout();
|
1266 |
|
|
1267 |
|
Sort(cursor);
|
1268 |
|
int count = cursor.GetCount();
|
1269 |
|
|
1270 |
1271 |
Array<LayoutItem> item;
|
|
1272 |
item.SetCount(count);
|
1271 |
1273 |
Vector<Rect> rect;
|
|
1274 |
rect.SetCount(count);
|
|
1275 |
Vector<int> order;
|
|
1276 |
order <<= cursor;
|
1272 |
1277 |
for(int i = 0; i < count; ++i) {
|
1273 |
|
rect.Add(CtrlRect(l.item[cursor[i]].pos, l.size));
|
1274 |
|
item.Add() = l.item[cursor[i]];
|
|
1278 |
rect[i] = CtrlRect(l.item[cursor[i]].pos, l.size);
|
|
1279 |
item[i] = l.item[cursor[i]];
|
1275 |
1280 |
}
|
|
1281 |
IndexSort2(rect, order, item, &RectLess);
|
|
1282 |
int q = FindIndex(order, cursor.Top());
|
|
1283 |
Sort(cursor);
|
1276 |
1284 |
l.item.Remove(cursor);
|
1277 |
|
|
1278 |
|
bool swap = false;
|
1279 |
|
do {
|
1280 |
|
swap = false;
|
1281 |
|
for(int i = 0; i < count - 1; i++)
|
1282 |
|
if(RectLess(rect[i + 1], rect[i])) {
|
1283 |
|
Swap(rect[i], rect[i + 1]);
|
1284 |
|
Swap(item[i], item[i + 1]);
|
1285 |
|
swap = true;
|
1286 |
|
}
|
1287 |
|
}
|
1288 |
|
while(swap);
|
1289 |
|
|
1290 |
1285 |
int ii = cursor[0];
|
1291 |
1286 |
l.item.InsertPick(ii, item);
|
1292 |
|
|
1293 |
1287 |
cursor.Clear();
|
1294 |
|
for(int i = 0; i < count; i++)
|
|
1288 |
for(int i = 0; i < count; ++i)
|
1295 |
1289 |
cursor.Add(i + ii);
|
1296 |
|
|
|
1290 |
if(q >= 0 && q != count - 1)
|
|
1291 |
Swap(cursor.Top(), cursor[q]);
|
1297 |
1292 |
ReloadItems();
|
1298 |
1293 |
}
|
1299 |
1294 |
|
... | ... | |
1489 |
1484 |
}
|
1490 |
1485 |
}
|
1491 |
1486 |
else if(item.IsCursor()) {
|
1492 |
|
if(!GetCtrl())
|
|
1487 |
int c = item.GetCursor();
|
|
1488 |
if(!GetCtrl()) {
|
1493 |
1489 |
cursor.Clear();
|
1494 |
|
cursor.Add(item.GetCursor());
|
|
1490 |
cursor.Add(c);
|
|
1491 |
}
|
|
1492 |
else {
|
|
1493 |
int q = FindIndex(cursor, c);
|
|
1494 |
if(q >= 0)
|
|
1495 |
cursor.Remove(q);
|
|
1496 |
else
|
|
1497 |
cursor.Add(c);
|
|
1498 |
}
|
1495 |
1499 |
}
|
1496 |
1500 |
SetFocus();
|
1497 |
1501 |
SyncItems();
|