2
0

FloatForm.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "floatform.h"
  2. #include "floatattr.h"
  3. #include "..\strutil.h"
  4. #include "..\..\fast_atof.h"
  5. #define WINDOW_WIDTH 180
  6. #define WINDOW_HEIGHT 65
  7. TFloatEdit::TFloatEdit (int posX, int posY) : GUIWindow (NULL, posX, posY, WINDOW_WIDTH, WINDOW_HEIGHT)
  8. {
  9. bPopupStyle = true;
  10. bAlwaysOnTop = true;
  11. bSystemButton = false;
  12. Caption = FLOATEDIT_WINDOWNAME;
  13. eValue = NEW GUIEdit (this, 6, 5, 165, 19);
  14. eValue->OnAccept = (CONTROL_EVENT)&TFloatEdit::OnDataChange;
  15. eValue->Flat = true;
  16. eValue->pFont->SetName("arialcyrsmall");
  17. btnOK = NEW GUIButton (this, 9,30, 78, 24);
  18. btnOK->Glyph->Load ("meditor\\ok");
  19. btnOK->Caption = "Accept";
  20. btnOK->pFont->SetName("arialcyrsmall");
  21. btnOK->FlatButton = true;
  22. btnCancel = NEW GUIButton (this, 95,30, 78, 24);
  23. btnCancel->Glyph->Load ("meditor\\cancel");
  24. btnCancel->Caption = "Cancel";
  25. btnCancel->pFont->SetName("arialcyrsmall");
  26. btnCancel->FlatButton = true;
  27. btnOK->OnMousePressed = (CONTROL_EVENT)&TFloatEdit::OnButtonOK;
  28. btnCancel->OnMousePressed = (CONTROL_EVENT)&TFloatEdit::OnButtonCancel;
  29. // cbValue->OnChange =
  30. }
  31. TFloatEdit::~TFloatEdit ()
  32. {
  33. delete btnOK;
  34. delete btnCancel;
  35. delete eValue;
  36. }
  37. void _cdecl TFloatEdit::OnDataChange (GUIControl* sender)
  38. {
  39. if (MasterAttrib->GetIsLimit ())
  40. {
  41. float needValue = fast_atof (eValue->Text.GetBuffer ());
  42. if (needValue < MasterAttrib->GetMin ()) needValue = MasterAttrib->GetMin ();
  43. if (needValue > MasterAttrib->GetMax ()) needValue = MasterAttrib->GetMax ();
  44. eValue->Text = FloatToStr (needValue);
  45. }
  46. }
  47. void _cdecl TFloatEdit::OnButtonOK (GUIControl* sender)
  48. {
  49. float needValue = fast_atof (eValue->Text.GetBuffer ());
  50. MasterAttrib->SetValue (needValue);
  51. Close (this);
  52. }
  53. void _cdecl TFloatEdit::OnButtonCancel (GUIControl* sender)
  54. {
  55. Close (this);
  56. }
  57. bool TFloatEdit::ProcessMessages (GUIMessage message, DWORD lparam, DWORD hparam)
  58. {
  59. if (message == GUIMSG_KEYPRESSED)
  60. {
  61. int key = (int)lparam;
  62. if ((key == ' ') || (key == 13))
  63. {
  64. OnButtonOK (this);
  65. return true;
  66. }
  67. }
  68. return GUIWindow::ProcessMessages (message, lparam, hparam);
  69. }
  70. void TFloatEdit::OnCreate()
  71. {
  72. eValue->SelectText(0, eValue->Text.Size());
  73. eValue->SetFocus();
  74. }
  75. void TFloatEdit::KeyPressed(int key, bool bSysKey)
  76. {
  77. if (!bSysKey) return;
  78. if (key == 13) OnButtonOK (this);
  79. if (key == VK_ESCAPE) OnButtonCancel (this);
  80. }