75 lines
2.3 KiB
C++
75 lines
2.3 KiB
C++
#include <vcl.h>
|
||
#pragma hdrstop
|
||
|
||
#include "BoundsUnit.h"
|
||
#include "BaseFigure.h"
|
||
|
||
#pragma package(smart_init)
|
||
#pragma resource "*.dfm"
|
||
TfrmBounds *frmBounds;
|
||
|
||
__fastcall TfrmBounds::TfrmBounds(TComponent* Owner) : TForm(Owner)
|
||
{
|
||
}
|
||
|
||
// TUpDown при показе пишет в поле свой Position, поэтому ставим и то и другое
|
||
void TfrmBounds::Put(TEdit *e, TUpDown *ud, int v)
|
||
{
|
||
ud->Position = v;
|
||
e->Text = IntToStr(v);
|
||
}
|
||
|
||
// показать окно; true - если нажали OK, тогда x, y, w, h - новые значения
|
||
// (для группы это общая рамка, и пределы размера у неё свои)
|
||
bool TfrmBounds::Edit(String title, int &x, int &y, int &w, int &h,
|
||
int wMin, int wMax, int hMin, int hMax)
|
||
{
|
||
minW = wMin; maxW = wMax;
|
||
minH = hMin; maxH = hMax;
|
||
udW->Min = wMin; udW->Max = wMax;
|
||
udH->Min = hMin; udH->Max = hMax;
|
||
lblFigure->Caption = title;
|
||
Put(edtX, udX, x);
|
||
Put(edtY, udY, y);
|
||
Put(edtW, udW, w);
|
||
Put(edtH, udH, h);
|
||
// по центру окна, из которого открыли
|
||
TForm *parent = Screen->ActiveForm;
|
||
if (parent)
|
||
{
|
||
Left = parent->Left + (parent->Width - Width) / 2;
|
||
Top = parent->Top + (parent->Height - Height) / 2;
|
||
}
|
||
ActiveControl = edtX;
|
||
if (ShowModal() != mrOk)
|
||
return false; // "Отмена" - ничего не меняется
|
||
x = StrToInt(edtX->Text);
|
||
y = StrToInt(edtY->Text);
|
||
w = StrToInt(edtW->Text);
|
||
h = StrToInt(edtH->Text);
|
||
return true;
|
||
}
|
||
|
||
bool TfrmBounds::Valid(TEdit *e, String what, int a, int b)
|
||
{
|
||
int v;
|
||
if (TryStrToInt(e->Text.Trim(), v) && v >= a && v <= b)
|
||
{
|
||
e->Text = IntToStr(v);
|
||
return true;
|
||
}
|
||
String msg = what + L" - введите целое число от " + IntToStr(a) + L" до " + IntToStr(b) + L".";
|
||
Application->MessageBox(msg.c_str(), L"Неверное значение", MB_OK | MB_ICONWARNING);
|
||
e->SetFocus();
|
||
e->SelectAll();
|
||
return false;
|
||
}
|
||
|
||
void __fastcall TfrmBounds::btnOkClick(TObject *Sender)
|
||
{
|
||
if (!Valid(edtX, "X", POS_MIN, POS_MAX)) return;
|
||
if (!Valid(edtY, "Y", POS_MIN, POS_MAX)) return;
|
||
if (!Valid(edtW, L"Ширина", minW, maxW)) return;
|
||
if (!Valid(edtH, L"Высота", minH, maxH)) return;
|
||
ModalResult = mrOk;
|
||
}
|