GUIのデフォルト分割サイズがすごく大きい値になってしまうことがあるバグを修正

This commit is contained in:
lltcggie 2015-06-08 19:38:12 +09:00
parent 6e0dbb9abd
commit afaf635742

View File

@ -27,6 +27,7 @@ const size_t AR_PATH_MAX(1024);
const int MinCommonDivisor = 50; const int MinCommonDivisor = 50;
const int DefaultCommonDivisor = 128; const int DefaultCommonDivisor = 128;
const std::pair<int, int> DefaultCommonDivisorRange = {90, 140};
const char * const CropSizeListName = "crop_size_list.txt"; const char * const CropSizeListName = "crop_size_list.txt";
@ -292,7 +293,7 @@ private:
), list.end()); ), list.end());
int mindiff = INT_MAX; int mindiff = INT_MAX;
int defaultIndex = 0; int defaultIndex = -1;
for (int i = 0; i < list.size(); i++) for (int i = 0; i < list.size(); i++)
{ {
const int n = list[i]; const int n = list[i];
@ -301,23 +302,34 @@ private:
SendMessageA(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str()); SendMessageA(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str());
const int diff = abs(DefaultCommonDivisor - n); const int diff = abs(DefaultCommonDivisor - n);
if (diff < mindiff) if (DefaultCommonDivisorRange.first <= n && n <= DefaultCommonDivisorRange.second && diff < mindiff)
{ {
mindiff = diff; mindiff = diff;
defaultIndex = i; defaultIndex = i;
} }
} }
if (SendMessageA(hcrop, CB_ADDSTRING, 0, (LPARAM)"-----------------------") == defaultIndex) SendMessageA(hcrop, CB_ADDSTRING, 0, (LPARAM)"-----------------------");
defaultIndex = 1;
// CropSizeListÌlðljÁµÄ¢­ // CropSizeListÌlðljÁµÄ¢­
mindiff = INT_MAX;
int defaultListIndex = -1;
for (const auto n : CropSizeList) for (const auto n : CropSizeList)
{ {
std::string str(std::to_string(n)); std::string str(std::to_string(n));
SendMessageA(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str()); const int index = SendMessageA(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str());
const int diff = abs(DefaultCommonDivisor - n);
if (DefaultCommonDivisorRange.first <= n && n <= DefaultCommonDivisorRange.second && diff < mindiff)
{
mindiff = diff;
defaultListIndex = index;
}
} }
if (defaultIndex == -1)
defaultIndex = defaultListIndex;
if (GetWindowTextLength(hcrop) == 0) if (GetWindowTextLength(hcrop) == 0)
SendMessage(hcrop, CB_SETCURSEL, defaultIndex, 0); SendMessage(hcrop, CB_SETCURSEL, defaultIndex, 0);
} }