Commit d9914774c801e5c1cf8af1a7c18865d05d8e2083

Authored by Peter Zhigalov
1 parent 59a224c2

Портировал изменения в проект с WinAPI

src_qt/paintwidget.h
... ... @@ -107,7 +107,7 @@ public:
107 107 float width;
108 108 float length;
109 109 float arrow_size;
110   - lines_config(QColor n_color = Qt::black, float n_width = 1.0f, float n_length = 10.0f, float n_arrow_size = 5.0f)
  110 + lines_config(const QColor & n_color = Qt::black, float n_width = 1.0f, float n_length = 10.0f, float n_arrow_size = 5.0f)
111 111 : color(n_color), width(n_width), length(n_length), arrow_size(n_arrow_size) {}
112 112 };
113 113  
... ...
src_winapi/main.cpp
... ... @@ -14,6 +14,7 @@
14 14 HWND hwnd;
15 15 HWND hwnd_about = NULL;
16 16 HWND hwnd_about_libs = NULL;
  17 +HWND hwnd_inputbox = NULL;
17 18 HBITMAP hbmp_logo = NULL;
18 19 HBITMAP hbmp_mask = NULL;
19 20 HACCEL haccel;
... ... @@ -24,6 +25,8 @@ namespace menu
24 25 HMENU hMenu;
25 26 HMENU hFileMenu;
26 27 HMENU hInterpMenu;
  28 + HMENU hIsolMenu;
  29 + HMENU hVecMenu;
27 30 HMENU hConfigMenu;
28 31 HMENU hAboutMenu;
29 32 }
... ... @@ -36,6 +39,26 @@ namespace config
36 39 int vect_min = 1, vect_max = 10000, vect_curr = 1;
37 40 TCHAR last_saved[260] = TEXT("draw.png");
38 41 TCHAR last_opened[260] = TEXT("");
  42 + COLORREF custom_colors[16] =
  43 + {
  44 + RGB(0, 0, 0),
  45 + RGB(128, 128, 128),
  46 + RGB(192, 192, 192),
  47 + RGB(255, 255, 255),
  48 + RGB(128, 0, 0),
  49 + RGB(255, 0, 0),
  50 + RGB(128, 128, 0),
  51 + RGB(255, 255, 0),
  52 + RGB(0, 128, 0),
  53 + RGB(0, 255, 0),
  54 + RGB(0, 128, 128),
  55 + RGB(0, 255, 255),
  56 + RGB(0, 0, 128),
  57 + RGB(0, 0, 255),
  58 + RGB(128, 0, 128),
  59 + RGB(255, 0, 255)
  60 + };
  61 + int inputbox_target = 0;
39 62 }
40 63  
41 64 namespace fonts
... ... @@ -218,6 +241,47 @@ void bmp2rgb(const char * lpbitmap, LONG width, LONG height, unsigned colors, bo
218 241 }
219 242 }
220 243  
  244 +// Событие при копировании картинки в буфер обмена
  245 +void on_actionCopy_Image_to_Clipboard_triggered()
  246 +{
  247 + // Создадим все что нужно и запустим отрисовку
  248 + RECT r;
  249 + memset(&r, 0, sizeof(RECT));
  250 + GetClientRect(pdraw->hwnd, &r);
  251 + HDC hdc1 = BeginPaint(pdraw->hwnd, & pdraw->ps);
  252 + HDC hdc2 = CreateCompatibleDC(hdc1);
  253 + HBITMAP hbmp = pdraw->hbmp;
  254 +
  255 + // Создадим bmp-изображение
  256 + // https://msdn.microsoft.com/en-us/library/windows/desktop/dd183402(v=vs.85).aspx
  257 + BITMAP bmp;
  258 + GetObject(hbmp, sizeof(BITMAP), &bmp);
  259 + BITMAPINFOHEADER bi;
  260 + bi.biSize = sizeof(BITMAPINFOHEADER);
  261 + bi.biWidth = bmp.bmWidth;
  262 + bi.biHeight = bmp.bmHeight;
  263 + bi.biPlanes = 1;
  264 + bi.biBitCount = 32;
  265 + bi.biCompression = BI_RGB;
  266 + bi.biSizeImage = 0;
  267 + bi.biXPelsPerMeter = 0;
  268 + bi.biYPelsPerMeter = 0;
  269 + bi.biClrUsed = 0;
  270 + bi.biClrImportant = 0;
  271 + DWORD dwBmpSize = ((bmp.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmp.bmHeight;
  272 + // https://stackoverflow.com/questions/1977363/how-to-copy-bitmap-to-clipboard-using-the-win32-api
  273 + OpenClipboard(NULL);
  274 + EmptyClipboard();
  275 + HGLOBAL hResult = GlobalAlloc(GMEM_MOVEABLE, dwBmpSize + bi.biSize);
  276 + char *lpbitmap = (char *)GlobalLock(hResult);
  277 + GetDIBits(hdc2, hbmp, 0, (UINT)bmp.bmHeight, lpbitmap + bi.biSize, (BITMAPINFO *)&bi, DIB_RGB_COLORS);
  278 + memcpy(lpbitmap, & bi, bi.biSize);
  279 + GlobalUnlock(hResult);
  280 + SetClipboardData(CF_DIB, hResult);
  281 + CloseClipboard();
  282 + GlobalFree(hResult);
  283 +}
  284 +
221 285 // Событие при сохранении
222 286 void on_actionSave_Image_File_triggered()
223 287 {
... ... @@ -435,6 +499,179 @@ void on_actionDecrease_Interpolation_triggered()
435 499 }
436 500 }
437 501  
  502 +// InputBox
  503 +void InputBox(const TCHAR * header, const TCHAR * text, int val_curr, int val_min, int val_max)
  504 +{
  505 + // Создадим окно
  506 + RECT rw = { 0, 0, 200, 102 };
  507 + AdjustWindowRect(&rw, WS_CAPTION | WS_SYSMENU, FALSE);
  508 + int box_width = rw.right - rw.left;
  509 + int box_height = rw.bottom - rw.top;
  510 + HDC hDCScreen = GetDC(NULL);
  511 + HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
  512 + hwnd_inputbox = CreateWindow(
  513 + TEXT("inputboxwindow"), header,
  514 + WS_CAPTION | WS_SYSMENU,
  515 + (GetDeviceCaps(hDCScreen, HORZRES) - box_width) / 2,
  516 + (GetDeviceCaps(hDCScreen, VERTRES) - box_height) / 2,
  517 + box_width, box_height,
  518 + NULL, NULL, hInstance, NULL
  519 + );
  520 + ReleaseDC(NULL, hDCScreen);
  521 +
  522 + // Надпись, содержащаяся в text
  523 + CreateWindow(
  524 + WC_STATIC, text,
  525 + WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE,
  526 + 11, 10, 178, 25,
  527 + hwnd_inputbox, (HMENU)INPUTBOX_LABEL_TEXT, hInstance, NULL
  528 + );
  529 +
  530 + // Спинбокс со значениями
  531 + CreateWindowEx(
  532 + WS_EX_CLIENTEDGE,
  533 + WC_EDIT, NULL,
  534 + WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | ES_AUTOHSCROLL |
  535 + ES_NUMBER | WS_TABSTOP,
  536 + 11, 31, 178, 25,
  537 + hwnd_inputbox, (HMENU)INPUTBOX_SPINBOX_TEXT, hInstance, NULL
  538 + );
  539 + CreateUpDownControl(
  540 + WS_CHILD | WS_BORDER | WS_VISIBLE | UDS_ARROWKEYS |
  541 + UDS_ALIGNRIGHT | UDS_SETBUDDYINT,
  542 + 0, 0, 0, 0,
  543 + hwnd_inputbox, INPUTBOX_SPINBOX_UPDOWN, hInstance, GetDlgItem(hwnd_inputbox, INPUTBOX_SPINBOX_TEXT),
  544 + val_max, val_min, val_curr
  545 + );
  546 +
  547 + // Кнопка OK
  548 + CreateWindow(
  549 + WC_BUTTON, TEXT("OK"),
  550 + WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
  551 + 30, 67, 74, 22,
  552 + hwnd_inputbox, (HMENU)INPUTBOX_BUTTON_OK, hInstance, NULL
  553 + );
  554 +
  555 + // Кнопка Cancel
  556 + CreateWindow(
  557 + WC_BUTTON, TEXT("Cancel"),
  558 + WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
  559 + 113, 67, 74, 22,
  560 + hwnd_inputbox, (HMENU)INPUTBOX_BUTTON_CANCEL, hInstance, NULL
  561 + );
  562 +
  563 + // Шрифты
  564 + SendMessage(hwnd_inputbox, WM_SETFONT, (WPARAM)fonts::font_std, TRUE);
  565 + SendDlgItemMessage(hwnd_inputbox, INPUTBOX_LABEL_TEXT, WM_SETFONT, (WPARAM)fonts::font_std, TRUE);
  566 + SendDlgItemMessage(hwnd_inputbox, INPUTBOX_SPINBOX_TEXT, WM_SETFONT, (WPARAM)fonts::font_std, TRUE);
  567 + SendDlgItemMessage(hwnd_inputbox, INPUTBOX_SPINBOX_UPDOWN, WM_SETFONT, (WPARAM)fonts::font_std, TRUE);
  568 + SendDlgItemMessage(hwnd_inputbox, INPUTBOX_BUTTON_OK, WM_SETFONT, (WPARAM)fonts::font_std, TRUE);
  569 + SendDlgItemMessage(hwnd_inputbox, INPUTBOX_BUTTON_CANCEL, WM_SETFONT, (WPARAM)fonts::font_std, TRUE);
  570 +
  571 + EnableWindow(hwnd, FALSE);
  572 + ShowWindow(hwnd_inputbox, SW_SHOWNORMAL);
  573 + UpdateWindow(hwnd_inputbox);
  574 + SetFocus(GetDlgItem(hwnd_inputbox, INPUTBOX_SPINBOX_TEXT));
  575 +}
  576 +
  577 +// Событие при переключении рисования изолиний из меню
  578 +void on_actionShow_Isolines_triggered()
  579 +{
  580 + DWORD state = GetMenuState(menu::hIsolMenu, (UINT)CONTROL_MENU_ISOLINES_SHOW, MF_BYCOMMAND);
  581 + if(!(state & MF_CHECKED))
  582 + {
  583 + CheckMenuItem(menu::hIsolMenu, (UINT)CONTROL_MENU_ISOLINES_SHOW, MF_CHECKED | MF_BYCOMMAND);
  584 + SendMessage(GetDlgItem(hwnd, CONTROL_CHECKBOX_ISOLINES), BM_SETCHECK, BST_CHECKED, 0);
  585 + SendMessage(hwnd, WM_COMMAND, CONTROL_CHECKBOX_ISOLINES, 0);
  586 + }
  587 + else
  588 + {
  589 + CheckMenuItem(menu::hIsolMenu, (UINT)CONTROL_MENU_ISOLINES_SHOW, MF_UNCHECKED | MF_BYCOMMAND);
  590 + SendMessage(GetDlgItem(hwnd, CONTROL_CHECKBOX_ISOLINES), BM_SETCHECK, BST_UNCHECKED, 0);
  591 + SendMessage(hwnd, WM_COMMAND, CONTROL_CHECKBOX_ISOLINES, 0);
  592 + }
  593 +}
  594 +
  595 +// Событие при запросе конфигурации цвета изолиний
  596 +void on_actionIsolines_Color_triggered()
  597 +{
  598 + CHOOSECOLOR color;
  599 + memset(&color, 0, sizeof(CHOOSECOLOR));
  600 + color.lStructSize = sizeof(CHOOSECOLOR);
  601 + color.hwndOwner = hwnd;
  602 + color.rgbResult = pdraw->isolines_config.color;
  603 + color.Flags = CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT;
  604 + color.lpCustColors = config::custom_colors;
  605 + if(ChooseColor(&color))
  606 + {
  607 + pdraw->isolines_config.color = color.rgbResult;
  608 + widget_redraw(false);
  609 + }
  610 +}
  611 +
  612 +// Событие при запросе конфигурации толщины изолиний
  613 +void on_actionIsolines_Width_triggered()
  614 +{
  615 + config::inputbox_target = CONTROL_MENU_ISOLINES_WIDTH;
  616 + InputBox(TEXT("Width"), TEXT("Select Isolines Width:"), pdraw->isolines_config.width, 1, 10);
  617 +}
  618 +
  619 +// Событие при переключении рисования векторов из меню
  620 +void on_actionShow_Vectors_triggered()
  621 +{
  622 + DWORD state = GetMenuState(menu::hVecMenu, (UINT)CONTROL_MENU_VECTORS_SHOW, MF_BYCOMMAND);
  623 + if(!(state & MF_CHECKED))
  624 + {
  625 + CheckMenuItem(menu::hVecMenu, (UINT)CONTROL_MENU_VECTORS_SHOW, MF_CHECKED | MF_BYCOMMAND);
  626 + SendMessage(GetDlgItem(hwnd, CONTROL_CHECKBOX_VECTORS), BM_SETCHECK, BST_CHECKED, 0);
  627 + SendMessage(hwnd, WM_COMMAND, CONTROL_CHECKBOX_VECTORS, 0);
  628 + }
  629 + else
  630 + {
  631 + CheckMenuItem(menu::hVecMenu, (UINT)CONTROL_MENU_VECTORS_SHOW, MF_UNCHECKED | MF_BYCOMMAND);
  632 + SendMessage(GetDlgItem(hwnd, CONTROL_CHECKBOX_VECTORS), BM_SETCHECK, BST_UNCHECKED, 0);
  633 + SendMessage(hwnd, WM_COMMAND, CONTROL_CHECKBOX_VECTORS, 0);
  634 + }
  635 +}
  636 +
  637 +// Событие при запросе конфигурации цвета векторов
  638 +void on_actionVectors_Color_triggered()
  639 +{
  640 + CHOOSECOLOR color;
  641 + memset(&color, 0, sizeof(CHOOSECOLOR));
  642 + color.lStructSize = sizeof(CHOOSECOLOR);
  643 + color.hwndOwner = hwnd;
  644 + color.rgbResult = pdraw->vectors_config.color;
  645 + color.Flags = CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT;
  646 + color.lpCustColors = config::custom_colors;
  647 + if(ChooseColor(&color))
  648 + {
  649 + pdraw->vectors_config.color = color.rgbResult;
  650 + widget_redraw(false);
  651 + }
  652 +}
  653 +
  654 +// Событие при запросе конфигурации толщины векторов
  655 +void on_actionVectors_Width_triggered()
  656 +{
  657 + config::inputbox_target = CONTROL_MENU_VECTORS_WIDTH;
  658 + InputBox(TEXT("Width"), TEXT("Select Vectors Width:"), pdraw->vectors_config.width, 1, 10);
  659 +}
  660 +
  661 +// Событие при запросе конфигурации длины векторов
  662 +void on_actionVectors_Length_triggered()
  663 +{
  664 + config::inputbox_target = CONTROL_MENU_VECTORS_LENGTH;
  665 + InputBox(TEXT("Length"), TEXT("Select Vectors Length:"), (int)pdraw->vectors_config.length, 1, 100);
  666 +}
  667 +
  668 +// Событие при запросе конфигурации размера стрелок векторов
  669 +void on_actionArrowSize_triggered()
  670 +{
  671 + config::inputbox_target = CONTROL_MENU_VECTORS_ARROWSIZE;
  672 + InputBox(TEXT("Arrow Size"), TEXT("Select Arrow Size:"), (int)pdraw->vectors_config.arrow_size, 1, 25);
  673 +}
  674 +
438 675 // Событие при переключении рисования легенды
439 676 void on_actionShow_Legend_triggered()
440 677 {
... ... @@ -563,7 +800,7 @@ void on_actionAbout_FEM_Draw_triggered()
563 800  
564 801 // Надпись "FEM Draw <version_name> (WinAPI)"
565 802 CreateWindow(
566   - WC_STATIC, TEXT("FEM Draw v1.5 (WinAPI)"),
  803 + WC_STATIC, TEXT("FEM Draw v1.6 beta1 (WinAPI)"),
567 804 WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE,
568 805 92, 10, 205, 15,
569 806 hwnd_about, (HMENU)ABOUT_LABEL_VERSION, hInstance, NULL
... ... @@ -591,7 +828,7 @@ void on_actionAbout_FEM_Draw_triggered()
591 828 );
592 829 // Надпись "Copyright (c) ..."
593 830 CreateWindow(
594   - WC_STATIC, TEXT("Copyright (c) 2014-2015"),
  831 + WC_STATIC, TEXT("Copyright (c) 2014-2016"),
595 832 WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE,
596 833 92, 80, 205, 15,
597 834 hwnd_about, (HMENU)ABOUT_LABEL_COPYRIGHT, hInstance, NULL
... ... @@ -925,9 +1162,15 @@ void on_checkBox_Isolines_clicked()
925 1162 LRESULT res = SendMessage(GetDlgItem(hwnd, CONTROL_CHECKBOX_ISOLINES), BM_GETCHECK, 0, 0);
926 1163 bool draw_isolines = pdraw->draw_isolines;
927 1164 if(res == BST_CHECKED)
  1165 + {
  1166 + CheckMenuItem(menu::hIsolMenu, (UINT)CONTROL_MENU_ISOLINES_SHOW, MF_CHECKED | MF_BYCOMMAND);
928 1167 draw_isolines = true;
  1168 + }
929 1169 if(res == BST_UNCHECKED)
  1170 + {
  1171 + CheckMenuItem(menu::hIsolMenu, (UINT)CONTROL_MENU_ISOLINES_SHOW, MF_UNCHECKED | MF_BYCOMMAND);
930 1172 draw_isolines = false;
  1173 + }
931 1174 if(draw_isolines != pdraw->draw_isolines)
932 1175 {
933 1176 pdraw->draw_isolines = draw_isolines;
... ... @@ -969,9 +1212,15 @@ void on_checkBox_Vectors_clicked()
969 1212 LRESULT res = SendMessage(GetDlgItem(hwnd, CONTROL_CHECKBOX_VECTORS), BM_GETCHECK, 0, 0);
970 1213 bool draw_vectors = pdraw->draw_vectors;
971 1214 if(res == BST_CHECKED)
  1215 + {
  1216 + CheckMenuItem(menu::hVecMenu, (UINT)CONTROL_MENU_VECTORS_SHOW, MF_CHECKED | MF_BYCOMMAND);
972 1217 draw_vectors = true;
  1218 + }
973 1219 if(res == BST_UNCHECKED)
  1220 + {
  1221 + CheckMenuItem(menu::hVecMenu, (UINT)CONTROL_MENU_VECTORS_SHOW, MF_UNCHECKED | MF_BYCOMMAND);
974 1222 draw_vectors = false;
  1223 + }
975 1224 if(draw_vectors != pdraw->draw_vectors)
976 1225 {
977 1226 pdraw->draw_vectors = draw_vectors;
... ... @@ -1061,6 +1310,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
1061 1310 case CONTROL_MENU_TRANSPARENT: // Событие при переключении прозрачности
1062 1311 on_actionTransparent_Image_triggered();
1063 1312 break;
  1313 + case CONTROL_MENU_COPY: // Событие при копировании картинки в буфер обмена
  1314 + on_actionCopy_Image_to_Clipboard_triggered();
  1315 + break;
1064 1316 case CONTROL_MENU_SAVE: // Событие при сохранении
1065 1317 on_actionSave_Image_File_triggered();
1066 1318 break;
... ... @@ -1073,6 +1325,30 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
1073 1325 case CONTROL_MENU_DECREASE_INTERPOLATION: // Событие при уменьшении уровня интерполяции
1074 1326 on_actionDecrease_Interpolation_triggered();
1075 1327 break;
  1328 + case CONTROL_MENU_ISOLINES_SHOW: // Событие при переключении рисования изолиний из меню
  1329 + on_actionShow_Isolines_triggered();
  1330 + break;
  1331 + case CONTROL_MENU_ISOLINES_COLOR: // Событие при запросе конфигурации цвета изолиний
  1332 + on_actionIsolines_Color_triggered();
  1333 + break;
  1334 + case CONTROL_MENU_ISOLINES_WIDTH: // Событие при запросе конфигурации толщины изолиний
  1335 + on_actionIsolines_Width_triggered();
  1336 + break;
  1337 + case CONTROL_MENU_VECTORS_SHOW: // Событие при переключении рисования векторов из меню
  1338 + on_actionShow_Vectors_triggered();
  1339 + break;
  1340 + case CONTROL_MENU_VECTORS_COLOR: // Событие при запросе конфигурации цвета векторов
  1341 + on_actionVectors_Color_triggered();
  1342 + break;
  1343 + case CONTROL_MENU_VECTORS_WIDTH: // Событие при запросе конфигурации толщины векторов
  1344 + on_actionVectors_Width_triggered();
  1345 + break;
  1346 + case CONTROL_MENU_VECTORS_LENGTH: // Событие при запросе конфигурации длины векторов
  1347 + on_actionVectors_Length_triggered();
  1348 + break;
  1349 + case CONTROL_MENU_VECTORS_ARROWSIZE: // Событие при запросе конфигурации размера стрелок векторов
  1350 + on_actionArrowSize_triggered();
  1351 + break;
1076 1352 case CONTROL_MENU_USELEGEND: // Событие при переключении рисования легенды
1077 1353 on_actionShow_Legend_triggered();
1078 1354 break;
... ... @@ -1508,6 +1784,83 @@ LRESULT CALLBACK WndProcAboutLibs(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lPa
1508 1784 return 0;
1509 1785 }
1510 1786  
  1787 +// Обработка сообщений InputBox'а
  1788 +LRESULT CALLBACK WndProcInputBox(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1789 +{
  1790 + switch(Msg)
  1791 + {
  1792 + case WM_COMMAND: // Нажата кнопка
  1793 + {
  1794 + switch(LOWORD(wParam))
  1795 + {
  1796 + case IDOK: // Странная магия, чтобы перехватить Enter
  1797 + case INPUTBOX_BUTTON_OK:
  1798 + {
  1799 + const size_t bufsize = 16;
  1800 + char str[bufsize];
  1801 + GetWindowTextA(GetDlgItem(hwnd_inputbox, INPUTBOX_SPINBOX_TEXT), str, bufsize);
  1802 + int val = atoi(str);
  1803 + float fval = (float)val;
  1804 + LRESULT range = SendDlgItemMessage(hwnd_inputbox, INPUTBOX_SPINBOX_UPDOWN, UDM_GETRANGE, 0, 0);
  1805 + int min = HIWORD(range), max = LOWORD(range);
  1806 + if(val >= min && val <= max)
  1807 + {
  1808 + switch(config::inputbox_target)
  1809 + {
  1810 + case CONTROL_MENU_ISOLINES_WIDTH:
  1811 + if(val != pdraw->isolines_config.width)
  1812 + {
  1813 + pdraw->isolines_config.width = val;
  1814 + widget_redraw(false);
  1815 + }
  1816 + break;
  1817 + case CONTROL_MENU_VECTORS_WIDTH:
  1818 + if(val != pdraw->vectors_config.width)
  1819 + {
  1820 + pdraw->vectors_config.width = val;
  1821 + widget_redraw(false);
  1822 + }
  1823 + break;
  1824 + case CONTROL_MENU_VECTORS_LENGTH:
  1825 + if(fval != pdraw->vectors_config.length)
  1826 + {
  1827 + pdraw->vectors_config.length = fval;
  1828 + widget_redraw(false);
  1829 + }
  1830 + break;
  1831 + case CONTROL_MENU_VECTORS_ARROWSIZE:
  1832 + if(fval != pdraw->vectors_config.arrow_size)
  1833 + {
  1834 + pdraw->vectors_config.arrow_size = fval;
  1835 + widget_redraw(false);
  1836 + }
  1837 + break;
  1838 + }
  1839 + }
  1840 + SendMessage(hwnd_inputbox, WM_CLOSE, 0, 0);
  1841 + break;
  1842 + }
  1843 + case INPUTBOX_BUTTON_CANCEL:
  1844 + SendMessage(hwnd_inputbox, WM_CLOSE, 0, 0);
  1845 + break;
  1846 + }
  1847 + break;
  1848 + }
  1849 + case WM_CLOSE:
  1850 + {
  1851 + EnableWindow(hwnd, TRUE);
  1852 + SetFocus(hwnd);
  1853 + DestroyWindow(hwnd_inputbox);
  1854 + hwnd_inputbox = NULL;
  1855 + config::inputbox_target = 0;
  1856 + break;
  1857 + }
  1858 + default:
  1859 + return DefWindowProc(hWnd, Msg, wParam, lParam);
  1860 + }
  1861 + return 0;
  1862 +}
  1863 +
1511 1864 // Функция, устанавливающая подсказки
1512 1865 void set_tooltip(HINSTANCE hInstance, HWND hwnd, int item, LPTSTR text)
1513 1866 {
... ... @@ -1576,6 +1929,17 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow
1576 1929 wnd_about_libs.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
1577 1930 RegisterClass(&wnd_about_libs);
1578 1931  
  1932 + // И зарегистрируем диалог типа InputBox
  1933 + WNDCLASS wnd_inputbox;
  1934 + memset(&wnd_inputbox, 0, sizeof(WNDCLASS));
  1935 + wnd_inputbox.style = CS_HREDRAW | CS_VREDRAW;
  1936 + wnd_inputbox.lpfnWndProc = WndProcInputBox;
  1937 + wnd_inputbox.hInstance = hInstance;
  1938 + wnd_inputbox.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  1939 + wnd_inputbox.lpszClassName = TEXT("inputboxwindow");
  1940 + wnd_inputbox.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
  1941 + RegisterClass(&wnd_inputbox);
  1942 +
1579 1943 // Установка минимальных размеров окна
1580 1944 RECT rw = { 0, 0, 640, 500 };
1581 1945 AdjustWindowRect(&rw, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, FALSE);
... ... @@ -1600,16 +1964,29 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow
1600 1964 menu::hMenu = CreateMenu();
1601 1965 menu::hFileMenu = CreatePopupMenu();
1602 1966 AppendMenu(menu::hMenu, MF_STRING | MF_POPUP, (UINT_PTR)menu::hFileMenu, TEXT("File"));
1603   - AppendMenu(menu::hFileMenu, MF_STRING, CONTROL_MENU_OPEN, TEXT("Open Tecplot File\tCtrl+O"));
  1967 + AppendMenu(menu::hFileMenu, MF_STRING, CONTROL_MENU_OPEN, TEXT("Open Tecplot File...\tCtrl+O"));
1604 1968 AppendMenu(menu::hFileMenu, MF_SEPARATOR, (UINT_PTR)NULL, TEXT(""));
1605 1969 AppendMenu(menu::hFileMenu, MF_STRING | MF_UNCHECKED, CONTROL_MENU_TRANSPARENT, TEXT("Transparent Image"));
1606   - AppendMenu(menu::hFileMenu, MF_STRING, CONTROL_MENU_SAVE, TEXT("Save Image\tCtrl+S"));
  1970 + AppendMenu(menu::hFileMenu, MF_STRING, CONTROL_MENU_COPY, TEXT("Copy Image to Clipboard\tCtrl+C"));
  1971 + AppendMenu(menu::hFileMenu, MF_STRING, CONTROL_MENU_SAVE, TEXT("Save Image...\tCtrl+S"));
1607 1972 AppendMenu(menu::hFileMenu, MF_SEPARATOR, (UINT_PTR)NULL, TEXT(""));
1608 1973 AppendMenu(menu::hFileMenu, MF_STRING, CONTROL_MENU_EXIT, TEXT("Exit\tCtrl+Q"));
1609 1974 menu::hInterpMenu = CreatePopupMenu();
1610 1975 AppendMenu(menu::hMenu, MF_STRING | MF_POPUP, (UINT_PTR)menu::hInterpMenu, TEXT("Interpolation"));
1611 1976 AppendMenu(menu::hInterpMenu, MF_STRING, CONTROL_MENU_INCREASE_INTERPOLATION, TEXT("Increase Interpolation\t="));
1612 1977 AppendMenu(menu::hInterpMenu, MF_STRING, CONTROL_MENU_DECREASE_INTERPOLATION, TEXT("Decrease Interpolation\t-"));
  1978 + menu::hIsolMenu = CreatePopupMenu();
  1979 + AppendMenu(menu::hMenu, MF_STRING | MF_POPUP, (UINT_PTR)menu::hIsolMenu, TEXT("Isolines"));
  1980 + AppendMenu(menu::hIsolMenu, MF_STRING | (pdraw->draw_isolines ? MF_CHECKED : MF_UNCHECKED), CONTROL_MENU_ISOLINES_SHOW, TEXT("Show Isolines"));
  1981 + AppendMenu(menu::hIsolMenu, MF_STRING, CONTROL_MENU_ISOLINES_COLOR, TEXT("Isolines Color..."));
  1982 + AppendMenu(menu::hIsolMenu, MF_STRING, CONTROL_MENU_ISOLINES_WIDTH, TEXT("Isolines Width..."));
  1983 + menu::hVecMenu = CreatePopupMenu();
  1984 + AppendMenu(menu::hMenu, MF_STRING | MF_POPUP, (UINT_PTR)menu::hVecMenu, TEXT("Vectors"));
  1985 + AppendMenu(menu::hVecMenu, MF_STRING | (pdraw->draw_vectors ? MF_CHECKED : MF_UNCHECKED), CONTROL_MENU_VECTORS_SHOW, TEXT("Show Vectors"));
  1986 + AppendMenu(menu::hVecMenu, MF_STRING, CONTROL_MENU_VECTORS_COLOR, TEXT("Vectors Color..."));
  1987 + AppendMenu(menu::hVecMenu, MF_STRING, CONTROL_MENU_VECTORS_WIDTH, TEXT("Vectors Width..."));
  1988 + AppendMenu(menu::hVecMenu, MF_STRING, CONTROL_MENU_VECTORS_LENGTH, TEXT("Vectors Length..."));
  1989 + AppendMenu(menu::hVecMenu, MF_STRING, CONTROL_MENU_VECTORS_ARROWSIZE, TEXT("Vectors Arrow Size..."));
1613 1990 menu::hConfigMenu = CreatePopupMenu();
1614 1991 AppendMenu(menu::hMenu, MF_STRING | MF_POPUP, (UINT_PTR)menu::hConfigMenu, TEXT("Configuration"));
1615 1992 AppendMenu(menu::hConfigMenu, MF_STRING | (pdraw->use_legend ? MF_CHECKED : MF_UNCHECKED), CONTROL_MENU_USELEGEND, TEXT("Show Legend"));
... ... @@ -1618,8 +1995,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow
1618 1995 AppendMenu(menu::hConfigMenu, MF_STRING | (pdraw->use_memory_limit ? MF_CHECKED : MF_UNCHECKED), CONTROL_MENU_USEMEMORYLIMIT, TEXT("1 GiB Memory Limit"));
1619 1996 menu::hAboutMenu = CreatePopupMenu();
1620 1997 AppendMenu(menu::hMenu, MF_STRING | MF_POPUP, (UINT_PTR)menu::hAboutMenu, TEXT("About"));
1621   - AppendMenu(menu::hAboutMenu, MF_STRING, CONTROL_MENU_ABOUT, TEXT("About FEM Draw"));
1622   - AppendMenu(menu::hAboutMenu, MF_STRING, CONTROL_MENU_ABOUT_LIBS, TEXT("About Third Party Libraries"));
  1998 + AppendMenu(menu::hAboutMenu, MF_STRING, CONTROL_MENU_ABOUT, TEXT("About FEM Draw..."));
  1999 + AppendMenu(menu::hAboutMenu, MF_STRING, CONTROL_MENU_ABOUT_LIBS, TEXT("About Third Party Libraries..."));
1623 2000 SetMenu(hwnd, menu::hMenu);
1624 2001 haccel = LoadAccelerators(hInstance, TEXT("APP_ACCELERATORS"));
1625 2002  
... ... @@ -1803,7 +2180,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow
1803 2180 {
1804 2181 if(!IsDialogMessage(hwnd, &msg) &&
1805 2182 !(hwnd_about && IsDialogMessage(hwnd_about, &msg)) &&
1806   - !(hwnd_about_libs && IsDialogMessage(hwnd_about_libs, &msg)))
  2183 + !(hwnd_about_libs && IsDialogMessage(hwnd_about_libs, &msg)) &&
  2184 + !(hwnd_inputbox && IsDialogMessage(hwnd_inputbox, &msg)))
1807 2185 {
1808 2186 TranslateMessage(&msg);
1809 2187 DispatchMessage(&msg);
... ...
src_winapi/paintwidget.cpp
... ... @@ -797,6 +797,8 @@ paintwidget::paintwidget()
797 797 hbmp_is_valid = false;
798 798 memset(&ps, 0, sizeof(PAINTSTRUCT));
799 799  
  800 + isolines_config = lines_config(RGB(0, 0, 0), 1);
  801 + vectors_config = lines_config(RGB(0, 0, 0), 1, 10.0f, 5.0f);
800 802 use_purple = false;
801 803 use_legend = true;
802 804 use_light_colors = true;
... ... @@ -1187,11 +1189,11 @@ void paintwidget::draw(HDC hdc_local)
1187 1189 }
1188 1190 }
1189 1191  
1190   - HPEN hIsolPen = GetStockPen(BLACK_PEN);
1191   - hOldPen = (HPEN)SelectObject(hdc_local, hIsolPen);
1192 1192 // Изолинии рисуем только если оно нам надо
1193 1193 if(draw_isolines)
1194 1194 {
  1195 + HPEN hIsolPen = CreatePen(PS_SOLID, isolines_config.width, isolines_config.color);
  1196 + hOldPen = (HPEN)SelectObject(hdc_local, hIsolPen);
1195 1197 for(size_t i = 0; i < triangles.size(); i++)
1196 1198 {
1197 1199 // Теперь рисуем изолинии
... ... @@ -1230,8 +1232,9 @@ void paintwidget::draw(HDC hdc_local)
1230 1232 LineTo(hdc_local, x + shift_x, y + shift_y);
1231 1233 }
1232 1234 }
  1235 + SelectObject(hdc_local, hOldPen);
  1236 + DeleteObject(hIsolPen);
1233 1237 }
1234   - SelectObject(hdc_local, hOldPen);
1235 1238  
1236 1239 // Легенда
1237 1240 if(use_legend)
... ... @@ -1325,12 +1328,10 @@ void paintwidget::draw(HDC hdc_local)
1325 1328  
1326 1329 if(draw_vectors)
1327 1330 {
1328   - HPEN hVecPen = GetStockPen(BLACK_PEN);
  1331 + HPEN hVecPen = CreatePen(PS_SOLID, vectors_config.width, vectors_config.color);
1329 1332 hOldPen = (HPEN)SelectObject(hdc_local, hVecPen);
1330   - HBRUSH hVecBrush = GetStockBrush(BLACK_BRUSH);
1331   - hOldBrush = (HBRUSH)SelectObject(hdc_local, hVecBrush);
1332 1333  
1333   - float vec_len = 10.5f, arrow_len = 5.5f;
  1334 + float vec_len = vectors_config.length + 0.5f, arrow_len = vectors_config.arrow_size + 0.5f;
1334 1335 float angle = 38.0f * 3.14159265358979323846f / 180.0f;
1335 1336 float sin_angle = std::sin(angle), cos_angle = std::cos(angle);
1336 1337  
... ... @@ -1376,7 +1377,7 @@ void paintwidget::draw(HDC hdc_local)
1376 1377 }
1377 1378 }
1378 1379 SelectObject(hdc_local, hOldPen);
1379   - SelectObject(hdc_local, hOldBrush);
  1380 + DeleteObject(hVecPen);
1380 1381 }
1381 1382  
1382 1383 DeleteObject(fnt_serif);
... ...
src_winapi/paintwidget.h
... ... @@ -86,6 +86,18 @@ public:
86 86 }
87 87 };
88 88  
  89 +// Класс конфигурация для объектов-линий (изолиний, векторов)
  90 +class lines_config
  91 +{
  92 +public:
  93 + COLORREF color;
  94 + int width;
  95 + float length;
  96 + float arrow_size;
  97 + lines_config(const COLORREF & n_color = RGB(0, 0, 0), int n_width = 1, float n_length = 10.0f, float n_arrow_size = 5.0f)
  98 + : color(n_color), width(n_width), length(n_length), arrow_size(n_arrow_size) {}
  99 +};
  100 +
89 101 // Класс виджет для рисования через WinAPI
90 102 class paintwidget
91 103 {
... ... @@ -149,6 +161,10 @@ public:
149 161 PAINTSTRUCT ps;
150 162 HBITMAP hbmp;
151 163  
  164 + // Конфигурация изолиний
  165 + lines_config isolines_config;
  166 + // Конфигурация векторов
  167 + lines_config vectors_config;
152 168 // Использовать ли фиолетовые оттенки цвета
153 169 // Дает большую комбинацию оттенков, но приводит к
154 170 // некоторому дисбалансу между красным и синим
... ...
src_winapi/resources.h
... ... @@ -18,18 +18,27 @@
18 18 #define CONTROL_COMBOBOX_VECTORS_U 10010
19 19 #define CONTROL_LABEL_VECTORS_V 10011
20 20 #define CONTROL_COMBOBOX_VECTORS_V 10012
21   -#define CONTROL_MENU_OPEN 10013
22   -#define CONTROL_MENU_TRANSPARENT 10014
23   -#define CONTROL_MENU_SAVE 10015
24   -#define CONTROL_MENU_EXIT 10016
25   -#define CONTROL_MENU_INCREASE_INTERPOLATION 10017
26   -#define CONTROL_MENU_DECREASE_INTERPOLATION 10018
27   -#define CONTROL_MENU_USELEGEND 10019
28   -#define CONTROL_MENU_USELIGHTCOLORS 10020
29   -#define CONTROL_MENU_USEPURPLE 10021
30   -#define CONTROL_MENU_USEMEMORYLIMIT 10022
31   -#define CONTROL_MENU_ABOUT 10023
32   -#define CONTROL_MENU_ABOUT_LIBS 10024
  21 +#define CONTROL_MENU_OPEN 10020
  22 +#define CONTROL_MENU_TRANSPARENT 10021
  23 +#define CONTROL_MENU_COPY 10022
  24 +#define CONTROL_MENU_SAVE 10023
  25 +#define CONTROL_MENU_EXIT 10024
  26 +#define CONTROL_MENU_INCREASE_INTERPOLATION 10030
  27 +#define CONTROL_MENU_DECREASE_INTERPOLATION 10031
  28 +#define CONTROL_MENU_ISOLINES_SHOW 10040
  29 +#define CONTROL_MENU_ISOLINES_COLOR 10041
  30 +#define CONTROL_MENU_ISOLINES_WIDTH 10042
  31 +#define CONTROL_MENU_VECTORS_SHOW 10050
  32 +#define CONTROL_MENU_VECTORS_COLOR 10051
  33 +#define CONTROL_MENU_VECTORS_WIDTH 10052
  34 +#define CONTROL_MENU_VECTORS_LENGTH 10053
  35 +#define CONTROL_MENU_VECTORS_ARROWSIZE 10054
  36 +#define CONTROL_MENU_USELEGEND 10060
  37 +#define CONTROL_MENU_USELIGHTCOLORS 10061
  38 +#define CONTROL_MENU_USEPURPLE 10062
  39 +#define CONTROL_MENU_USEMEMORYLIMIT 10063
  40 +#define CONTROL_MENU_ABOUT 10070
  41 +#define CONTROL_MENU_ABOUT_LIBS 10071
33 42 #define ABOUT_LABEL_VERSION 10100
34 43 #define ABOUT_LABEL_SITE 10101
35 44 #define ABOUT_LABEL_LICENSE 10102
... ... @@ -67,6 +76,11 @@
67 76 #define ABOUT_LIBS_LABEL_URL_TGA 10224
68 77 #define ABOUT_LIBS_BUTTON_OK 10225
69 78 #define ABOUT_LIBS_LABEL_LOGO 10226
  79 +#define INPUTBOX_LABEL_TEXT 10300
  80 +#define INPUTBOX_SPINBOX_TEXT 10301
  81 +#define INPUTBOX_SPINBOX_UPDOWN 10302
  82 +#define INPUTBOX_BUTTON_OK 10303
  83 +#define INPUTBOX_BUTTON_CANCEL 10304
70 84  
71 85 #include <windows.h>
72 86 #include <commctrl.h>
... ...
src_winapi/resources.rc
... ... @@ -7,6 +7,7 @@ IDC_HAND_FB CURSOR DISCARDABLE &quot;../resources/hand.cur&quot;
7 7 APP_ACCELERATORS ACCELERATORS
8 8 BEGIN
9 9 0x4F, CONTROL_MENU_OPEN, VIRTKEY, CONTROL
  10 + "^C", CONTROL_MENU_COPY, VIRTKEY, CONTROL
10 11 0x53, CONTROL_MENU_SAVE, VIRTKEY, CONTROL
11 12 0x51, CONTROL_MENU_EXIT, VIRTKEY, CONTROL
12 13 VK_OEM_PLUS, CONTROL_MENU_INCREASE_INTERPOLATION, VIRTKEY
... ...