@@ -27,6 +27,7 @@ const size_t AR_PATH_MAX(1024);
27
27
28
28
const int MinCommonDivisor = 50 ;
29
29
const int DefaultCommonDivisor = 128 ;
30
+ const std::pair<int , int > DefaultCommonDivisorRange = {90 , 140 };
30
31
31
32
const char * const CropSizeListName = " crop_size_list.txt" ;
32
33
@@ -292,7 +293,7 @@ class DialogEvent
292
293
), list.end ());
293
294
294
295
int mindiff = INT_MAX;
295
- int defaultIndex = 0 ;
296
+ int defaultIndex = - 1 ;
296
297
for (int i = 0 ; i < list.size (); i++)
297
298
{
298
299
const int n = list[i];
@@ -301,23 +302,34 @@ class DialogEvent
301
302
SendMessageA (hcrop, CB_ADDSTRING, 0 , (LPARAM)str.c_str ());
302
303
303
304
const int diff = abs (DefaultCommonDivisor - n);
304
- if (diff < mindiff)
305
+ if (DefaultCommonDivisorRange. first <= n && n <= DefaultCommonDivisorRange. second && diff < mindiff)
305
306
{
306
307
mindiff = diff;
307
308
defaultIndex = i;
308
309
}
309
310
}
310
311
311
- if (SendMessageA (hcrop, CB_ADDSTRING, 0 , (LPARAM)" -----------------------" ) == defaultIndex)
312
- defaultIndex = 1 ;
312
+ SendMessageA (hcrop, CB_ADDSTRING, 0 , (LPARAM)" -----------------------" );
313
313
314
314
// CropSizeListの値を追加していく
315
+ mindiff = INT_MAX;
316
+ int defaultListIndex = -1 ;
315
317
for (const auto n : CropSizeList)
316
318
{
317
319
std::string str (std::to_string (n));
318
- SendMessageA (hcrop, CB_ADDSTRING, 0 , (LPARAM)str.c_str ());
320
+ const int index = SendMessageA (hcrop, CB_ADDSTRING, 0 , (LPARAM)str.c_str ());
321
+
322
+ const int diff = abs (DefaultCommonDivisor - n);
323
+ if (DefaultCommonDivisorRange.first <= n && n <= DefaultCommonDivisorRange.second && diff < mindiff)
324
+ {
325
+ mindiff = diff;
326
+ defaultListIndex = index ;
327
+ }
319
328
}
320
329
330
+ if (defaultIndex == -1 )
331
+ defaultIndex = defaultListIndex;
332
+
321
333
if (GetWindowTextLength (hcrop) == 0 )
322
334
SendMessage (hcrop, CB_SETCURSEL, defaultIndex, 0 );
323
335
}
0 commit comments