FloatEdit.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. FinalSun/FinalAlert 2 Mission Editor
  3. Copyright (C) 1999-2024 Electronic Arts, Inc.
  4. Authored by Matthias Wagner
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. //
  17. // FloatEdit.cpp: Implementierungsdatei
  18. //
  19. #include "stdafx.h"
  20. #include "FinalSun.h"
  21. #include "FloatEdit.h"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CFloatEdit
  29. CFloatEdit::CFloatEdit()
  30. {
  31. }
  32. CFloatEdit::~CFloatEdit()
  33. {
  34. }
  35. BEGIN_MESSAGE_MAP(CFloatEdit, CEdit)
  36. //{{AFX_MSG_MAP(CFloatEdit)
  37. ON_WM_ACTIVATE()
  38. ON_CONTROL_REFLECT(EN_KILLFOCUS, OnKillfocus)
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // Behandlungsroutinen für Nachrichten CFloatEdit
  43. void CFloatEdit::OnKillfocus()
  44. {
  45. // okay, we need to convert it to a float
  46. CString text, originaltext;
  47. GetWindowText(text);
  48. originaltext=text;
  49. if(strlen(text)<1)
  50. {
  51. //SetWindowText("0.000000");
  52. return;
  53. }
  54. double res=atof(text);
  55. int c,d;
  56. char* j=_fcvt(res, 6, &c, &d);
  57. int i, slen=strlen(j);
  58. char j2[50];
  59. for(i=0;i<6-slen;i++)
  60. {
  61. strcpy(j2, j+i);
  62. j[i]=0;
  63. strcat(j, "0");
  64. strcat(j,j2);
  65. }
  66. if(j==NULL) return;
  67. //MessageBox(j,text);
  68. text=j;
  69. text.Insert(c, ".");
  70. //MessageBox(text);
  71. if(strchr(text, '.')==text) text.Insert(0, "0");
  72. //delete[](j);
  73. if(originaltext==text) return;
  74. SetWindowText(text);
  75. }