1//////////////////////////////////////////////////////////////////////
2// This file is part of Remere's Map Editor
3//////////////////////////////////////////////////////////////////////
4// Remere's Map Editor is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Remere's Map Editor 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//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//////////////////////////////////////////////////////////////////////
17
18#include "main.h"
19#include "positionctrl.h"
20#include "numbertextctrl.h"
21#include "position.h"
22
23PositionCtrl::PositionCtrl(wxWindow* parent, const wxString& label, int x, int y, int z, int maxx /*= MAP_MAX_WIDTH*/, int maxy /*= MAP_MAX_HEIGHT*/, int maxz /*= MAP_MAX_LAYER*/) :
24 wxStaticBoxSizer(wxHORIZONTAL, parent, label) {
25 x_field = newd NumberTextCtrl(parent, wxID_ANY, x, 0, maxx, wxTE_PROCESS_ENTER, "X", wxDefaultPosition, wxSize(60, 20));
26 x_field->Bind(wxEVT_TEXT_PASTE, &PositionCtrl::OnClipboardText, this);
27 Add(x_field, 2, wxEXPAND | wxLEFT | wxBOTTOM, 5);
28
29 y_field = newd NumberTextCtrl(parent, wxID_ANY, y, 0, maxy, wxTE_PROCESS_ENTER, "Y", wxDefaultPosition, wxSize(60, 20));
30 y_field->Bind(wxEVT_TEXT_PASTE, &PositionCtrl::OnClipboardText, this);
31 Add(y_field, 2, wxEXPAND | wxLEFT | wxBOTTOM, 5);
32
33 z_field = newd NumberTextCtrl(parent, wxID_ANY, z, 0, maxz, wxTE_PROCESS_ENTER, "Z", wxDefaultPosition, wxSize(35, 20));
34 z_field->Bind(wxEVT_TEXT_PASTE, &PositionCtrl::OnClipboardText, this);
35 Add(z_field, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
36
37 maxWidth = maxx;
38 maxHeight = maxy;
39}
40
41PositionCtrl::~PositionCtrl() {
42 ////
43}
44
45Position PositionCtrl::GetPosition() const {
46 Position pos;
47 pos.x = x_field->GetIntValue();
48 pos.y = y_field->GetIntValue();
49 pos.z = z_field->GetIntValue();
50 return pos;
51}
52
53void PositionCtrl::SetPosition(Position pos) {
54 x_field->SetIntValue(pos.x);
55 y_field->SetIntValue(pos.y);
56 z_field->SetIntValue(pos.z);
57}
58
59bool PositionCtrl::Enable(bool enable) {
60 return (x_field->Enable(enable) && y_field->Enable(enable) && z_field->Enable(enable));
61}
62
63void PositionCtrl::OnClipboardText(wxClipboardTextEvent& evt) {
64 Position position;
65 if (posFromClipboard(position, maxWidth, maxHeight)) {
66 x_field->SetIntValue(position.x);
67 y_field->SetIntValue(position.y);
68 z_field->SetIntValue(position.z);
69 } else {
70 evt.Skip();
71 }
72}
73