diff options
Diffstat (limited to 'tools/mapedit/src')
-rw-r--r-- | tools/mapedit/src/frame.cpp | 4 | ||||
-rw-r--r-- | tools/mapedit/src/widget.cpp | 95 | ||||
-rw-r--r-- | tools/mapedit/src/widget.h | 6 | ||||
-rw-r--r-- | tools/mapedit/src/world.cpp | 2 |
4 files changed, 78 insertions, 29 deletions
diff --git a/tools/mapedit/src/frame.cpp b/tools/mapedit/src/frame.cpp index 2a553b6..6fb70c8 100644 --- a/tools/mapedit/src/frame.cpp +++ b/tools/mapedit/src/frame.cpp | |||
@@ -134,7 +134,7 @@ MapeditFrame::MapeditFrame(std::unique_ptr<World> world) : wxFrame(NULL, wxID_AN | |||
134 | // Layout 3: Splitter between map editor and properties editor | 134 | // Layout 3: Splitter between map editor and properties editor |
135 | 135 | ||
136 | wxSplitterWindow* layout1 = new wxSplitterWindow(this, wxID_ANY); | 136 | wxSplitterWindow* layout1 = new wxSplitterWindow(this, wxID_ANY); |
137 | mapTree = new wxTreeCtrl(layout1, MAP_EDITOR_TREE, wxDefaultPosition, wxSize(200, 0), wxTR_HIDE_ROOT | wxTR_HAS_BUTTONS); | 137 | mapTree = new wxTreeCtrl(layout1, MAP_EDITOR_TREE, wxDefaultPosition, wxSize(150, 0), wxTR_HIDE_ROOT | wxTR_HAS_BUTTONS); |
138 | wxTreeItemId mapTreeRoot = mapTree->AddRoot("root"); | 138 | wxTreeItemId mapTreeRoot = mapTree->AddRoot("root"); |
139 | populateMapTree(mapTreeRoot, this->world->getRootMaps()); | 139 | populateMapTree(mapTreeRoot, this->world->getRootMaps()); |
140 | 140 | ||
@@ -152,7 +152,7 @@ MapeditFrame::MapeditFrame(std::unique_ptr<World> world) : wxFrame(NULL, wxID_AN | |||
152 | mapEditor->frame = this; | 152 | mapEditor->frame = this; |
153 | 153 | ||
154 | // Set up property editor | 154 | // Set up property editor |
155 | wxPanel* propertyEditor = new wxPanel(layout3, wxID_ANY); | 155 | wxPanel* propertyEditor = new wxPanel(layout3, wxID_ANY, wxDefaultPosition, wxSize(-1, 100)); |
156 | titleBox = new UndoableTextBox(propertyEditor, MAP_TITLE_TEXTBOX, currentMap->getTitle(), "Edit Map Title", this); | 156 | titleBox = new UndoableTextBox(propertyEditor, MAP_TITLE_TEXTBOX, currentMap->getTitle(), "Edit Map Title", this); |
157 | titleBox->SetMaxLength(40); | 157 | titleBox->SetMaxLength(40); |
158 | 158 | ||
diff --git a/tools/mapedit/src/widget.cpp b/tools/mapedit/src/widget.cpp index 61a8d65..cb10489 100644 --- a/tools/mapedit/src/widget.cpp +++ b/tools/mapedit/src/widget.cpp | |||
@@ -1,9 +1,14 @@ | |||
1 | #include "widget.h" | 1 | #include "widget.h" |
2 | #include "frame.h" | 2 | #include "frame.h" |
3 | 3 | ||
4 | IMPLEMENT_DYNAMIC_CLASS(MapeditWidget,wxScrolledWindow) | 4 | const int EDITOR_SPACING_X = MAP_WIDTH * TILE_WIDTH / 2; |
5 | const int EDITOR_SPACING_Y = MAP_HEIGHT * TILE_HEIGHT / 2; | ||
6 | const int EDITOR_WIDTH = MAP_WIDTH * TILE_WIDTH + EDITOR_SPACING_X * 2; | ||
7 | const int EDITOR_HEIGHT = MAP_HEIGHT * TILE_HEIGHT + EDITOR_SPACING_Y * 2; | ||
5 | 8 | ||
6 | BEGIN_EVENT_TABLE(MapeditWidget, wxScrolledWindow) | 9 | IMPLEMENT_DYNAMIC_CLASS(MapeditWidget,wxScrolledCanvas) |
10 | |||
11 | BEGIN_EVENT_TABLE(MapeditWidget, wxScrolledCanvas) | ||
7 | EVT_PAINT(MapeditWidget::OnPaint) | 12 | EVT_PAINT(MapeditWidget::OnPaint) |
8 | EVT_LEFT_DOWN(MapeditWidget::OnClick) | 13 | EVT_LEFT_DOWN(MapeditWidget::OnClick) |
9 | EVT_RIGHT_DOWN(MapeditWidget::OnRightClick) | 14 | EVT_RIGHT_DOWN(MapeditWidget::OnRightClick) |
@@ -18,7 +23,7 @@ MapeditWidget::MapeditWidget() | |||
18 | } | 23 | } |
19 | 24 | ||
20 | MapeditWidget::MapeditWidget(wxWindow* parent, wxWindowID winid, Map* map, TileWidget* tileWidget, const wxPoint& pos, const wxSize& size) | 25 | MapeditWidget::MapeditWidget(wxWindow* parent, wxWindowID winid, Map* map, TileWidget* tileWidget, const wxPoint& pos, const wxSize& size) |
21 | : wxScrolledWindow(parent, winid, pos, size), map(map), tileWidget(tileWidget) | 26 | : wxScrolledCanvas(parent, winid, pos, size), map(map), tileWidget(tileWidget) |
22 | { | 27 | { |
23 | Init(); | 28 | Init(); |
24 | } | 29 | } |
@@ -30,12 +35,21 @@ void MapeditWidget::Init() | |||
30 | this->FitInside(); | 35 | this->FitInside(); |
31 | this->SetScrollRate(5, 5); | 36 | this->SetScrollRate(5, 5); |
32 | 37 | ||
38 | SetVirtualSize(EDITOR_WIDTH, EDITOR_HEIGHT); | ||
39 | |||
40 | int cW, cH; | ||
41 | GetClientSize(&cW, &cH); | ||
42 | mousePos.x = cW / 2; | ||
43 | mousePos.y = cH / 2; | ||
44 | |||
45 | // Scroll(GAME_WIDTH*1.5-mousePos.x, GAME_HEIGHT*1.5-mousePos.y); | ||
46 | |||
33 | SetZoomSize(2); | 47 | SetZoomSize(2); |
34 | } | 48 | } |
35 | 49 | ||
36 | wxSize MapeditWidget::DoGetBestSize() const | 50 | wxSize MapeditWidget::DoGetBestSize() const |
37 | { | 51 | { |
38 | return {GAME_WIDTH*2, GAME_HEIGHT*2}; | 52 | return {EDITOR_WIDTH*scale, EDITOR_HEIGHT*scale}; |
39 | } | 53 | } |
40 | 54 | ||
41 | void MapeditWidget::OnPaint(wxPaintEvent&) | 55 | void MapeditWidget::OnPaint(wxPaintEvent&) |
@@ -43,12 +57,18 @@ void MapeditWidget::OnPaint(wxPaintEvent&) | |||
43 | wxPaintDC dc(this); | 57 | wxPaintDC dc(this); |
44 | wxMemoryDC tiles_dc; | 58 | wxMemoryDC tiles_dc; |
45 | tiles_dc.SelectObject(tiles); | 59 | tiles_dc.SelectObject(tiles); |
46 | int vX, vY; | 60 | |
61 | int vX, vY, vXX, vXY, vW, vH, cW, cH; | ||
47 | GetViewStart(&vX, &vY); | 62 | GetViewStart(&vX, &vY); |
48 | int vXX, vYX; | 63 | GetVirtualSize(&vW, &vH); |
49 | GetScrollPixelsPerUnit(&vXX, &vYX); | 64 | GetClientSize(&cW, &cH); |
65 | GetScrollPixelsPerUnit(&vXX, &vXY); | ||
50 | vX *= vXX; | 66 | vX *= vXX; |
51 | vY *= vYX; | 67 | vY *= vXY; |
68 | |||
69 | dc.SetPen(*wxGREY_PEN); | ||
70 | dc.SetBrush(*wxGREY_BRUSH); | ||
71 | dc.DrawRectangle(0, 0, cW, cH); | ||
52 | 72 | ||
53 | for (int y=0; y<MAP_HEIGHT; y++) | 73 | for (int y=0; y<MAP_HEIGHT; y++) |
54 | { | 74 | { |
@@ -60,7 +80,9 @@ void MapeditWidget::OnPaint(wxPaintEvent&) | |||
60 | tile = tileWidget->getSelected(); | 80 | tile = tileWidget->getSelected(); |
61 | } | 81 | } |
62 | 82 | ||
63 | dc.StretchBlit(x*TILE_WIDTH*scale-vX, y*TILE_HEIGHT*scale-vY, TILE_WIDTH*scale, TILE_HEIGHT*scale, &tiles_dc, tile%8*TILE_WIDTH, tile/8*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); | 83 | wxPoint pos {(x*TILE_WIDTH + EDITOR_SPACING_X)*scale - vX, (y*TILE_HEIGHT + EDITOR_SPACING_Y) * scale - vY}; |
84 | |||
85 | dc.StretchBlit(pos.x, pos.y, TILE_WIDTH*scale, TILE_HEIGHT*scale, &tiles_dc, tile%8*TILE_WIDTH, tile/8*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); | ||
64 | } | 86 | } |
65 | } | 87 | } |
66 | 88 | ||
@@ -71,7 +93,7 @@ void MapeditWidget::OnPaint(wxPaintEvent&) | |||
71 | wxBitmap sprite = object->object->getSprite(); | 93 | wxBitmap sprite = object->object->getSprite(); |
72 | tiles_dc.SelectObject(sprite); | 94 | tiles_dc.SelectObject(sprite); |
73 | 95 | ||
74 | wxPoint pos {(int) object->position.first*scale-vX, (int) object->position.second*scale-vY}; | 96 | wxPoint pos {(object->position.first + EDITOR_SPACING_X)*scale-vX, (object->position.second + EDITOR_SPACING_Y)*scale-vY}; |
75 | wxSize size {object->object->getWidth()*scale, object->object->getHeight()*scale}; | 97 | wxSize size {object->object->getWidth()*scale, object->object->getHeight()*scale}; |
76 | dc.StretchBlit(pos.x, pos.y, size.GetWidth(), size.GetHeight(), &tiles_dc, 0, 0, object->object->getWidth(), object->object->getHeight()); | 98 | dc.StretchBlit(pos.x, pos.y, size.GetWidth(), size.GetHeight(), &tiles_dc, 0, 0, object->object->getWidth(), object->object->getHeight()); |
77 | 99 | ||
@@ -99,9 +121,9 @@ void MapeditWidget::OnPaint(wxPaintEvent&) | |||
99 | tiles_dc.SelectObject(wxNullBitmap); | 121 | tiles_dc.SelectObject(wxNullBitmap); |
100 | tiles_dc.SelectObject(sprite); | 122 | tiles_dc.SelectObject(sprite); |
101 | 123 | ||
102 | std::pair<double, double> startPos = map->getWorld()->getStartingPosition(); | 124 | std::pair<int, int> startPos = map->getWorld()->getStartingPosition(); |
103 | 125 | ||
104 | wxPoint pos {(int) startPos.first*scale-vX, (int) startPos.second*scale-vY}; | 126 | wxPoint pos {(startPos.first + EDITOR_SPACING_X)*scale-vX, (startPos.second + EDITOR_SPACING_Y)*scale-vY}; |
105 | wxSize size {PLAYER_WIDTH[currentPlayer]*scale, PLAYER_HEIGHT[currentPlayer]*scale}; | 127 | wxSize size {PLAYER_WIDTH[currentPlayer]*scale, PLAYER_HEIGHT[currentPlayer]*scale}; |
106 | 128 | ||
107 | dc.StretchBlit(pos.x, pos.y, size.GetWidth(), size.GetHeight(), &tiles_dc, 0, 0, PLAYER_WIDTH[currentPlayer], PLAYER_HEIGHT[currentPlayer]); | 129 | dc.StretchBlit(pos.x, pos.y, size.GetWidth(), size.GetHeight(), &tiles_dc, 0, 0, PLAYER_WIDTH[currentPlayer], PLAYER_HEIGHT[currentPlayer]); |
@@ -127,10 +149,10 @@ void MapeditWidget::OnPaint(wxPaintEvent&) | |||
127 | } else if (editMode == EditTiles) | 149 | } else if (editMode == EditTiles) |
128 | { | 150 | { |
129 | int tile = tileWidget->getSelected(); | 151 | int tile = tileWidget->getSelected(); |
130 | int x = (mousePos.x + vX) / (TILE_WIDTH * scale); | 152 | int x = (mousePos.x + vX - EDITOR_SPACING_X*scale) / (TILE_WIDTH * scale); |
131 | int y = (mousePos.y + vY) / (TILE_HEIGHT * scale); | 153 | int y = (mousePos.y + vY - EDITOR_SPACING_Y*scale) / (TILE_HEIGHT * scale); |
132 | 154 | ||
133 | wxPoint pos {x*TILE_WIDTH*scale-vX, y*TILE_HEIGHT*scale-vY}; | 155 | wxPoint pos {(x*TILE_WIDTH + EDITOR_SPACING_X)*scale-vX, (y*TILE_HEIGHT + EDITOR_SPACING_Y)*scale-vY}; |
134 | wxSize size {TILE_WIDTH*scale, TILE_HEIGHT*scale}; | 156 | wxSize size {TILE_WIDTH*scale, TILE_HEIGHT*scale}; |
135 | 157 | ||
136 | tiles_dc.SelectObject(wxNullBitmap); | 158 | tiles_dc.SelectObject(wxNullBitmap); |
@@ -184,8 +206,8 @@ void MapeditWidget::SetTile(wxPoint pos) | |||
184 | vX *= vXX; | 206 | vX *= vXX; |
185 | vY *= vYX; | 207 | vY *= vYX; |
186 | 208 | ||
187 | int x = (pos.x + vX) / (TILE_WIDTH * scale); | 209 | int x = (pos.x + vX - EDITOR_SPACING_X*scale) / (TILE_WIDTH * scale); |
188 | int y = (pos.y + vY) / (TILE_HEIGHT * scale); | 210 | int y = (pos.y + vY - EDITOR_SPACING_Y*scale) / (TILE_HEIGHT * scale); |
189 | 211 | ||
190 | changeBuffer.insert({x,y}); | 212 | changeBuffer.insert({x,y}); |
191 | 213 | ||
@@ -194,6 +216,8 @@ void MapeditWidget::SetTile(wxPoint pos) | |||
194 | 216 | ||
195 | void MapeditWidget::OnClick(wxMouseEvent& event) | 217 | void MapeditWidget::OnClick(wxMouseEvent& event) |
196 | { | 218 | { |
219 | if (!mouseIsIn) return; | ||
220 | |||
197 | mouseIsDown = true; | 221 | mouseIsDown = true; |
198 | 222 | ||
199 | int vX, vY; | 223 | int vX, vY; |
@@ -338,14 +362,29 @@ void MapeditWidget::OnRightClick(wxMouseEvent& event) | |||
338 | void MapeditWidget::OnMouseMove(wxMouseEvent& event) | 362 | void MapeditWidget::OnMouseMove(wxMouseEvent& event) |
339 | { | 363 | { |
340 | mousePos = event.GetPosition(); | 364 | mousePos = event.GetPosition(); |
341 | mouseIsIn = true; | ||
342 | 365 | ||
343 | if (editMode == EditTiles) | 366 | int vX, vY, vW, vH; |
367 | GetViewStart(&vX, &vY); | ||
368 | GetVirtualSize(&vW, &vH); | ||
369 | int vXX, vYX; | ||
370 | GetScrollPixelsPerUnit(&vXX, &vYX); | ||
371 | vX *= vXX; | ||
372 | vY *= vYX; | ||
373 | |||
374 | if ((mousePos.x+vX >= EDITOR_SPACING_X*scale) && (mousePos.x+vX < (EDITOR_WIDTH-EDITOR_SPACING_X)*scale) | ||
375 | && (mousePos.y+vY >= EDITOR_SPACING_Y*scale) && (mousePos.y+vY < (EDITOR_HEIGHT-EDITOR_SPACING_Y)*scale)) | ||
344 | { | 376 | { |
345 | if (mouseIsDown) | 377 | mouseIsIn = true; |
378 | |||
379 | if (editMode == EditTiles) | ||
346 | { | 380 | { |
347 | SetTile(event.GetPosition()); | 381 | if (mouseIsDown) |
382 | { | ||
383 | SetTile(event.GetPosition()); | ||
384 | } | ||
348 | } | 385 | } |
386 | } else { | ||
387 | mouseIsIn = false; | ||
349 | } | 388 | } |
350 | 389 | ||
351 | Refresh(); | 390 | Refresh(); |
@@ -406,9 +445,19 @@ void MapeditWidget::ZoomOut() | |||
406 | 445 | ||
407 | void MapeditWidget::SetZoomSize(int zoom) | 446 | void MapeditWidget::SetZoomSize(int zoom) |
408 | { | 447 | { |
409 | scale = zoom; | 448 | int vX, vY, vXX, vXY; |
449 | GetViewStart(&vX, &vY); | ||
450 | GetScrollPixelsPerUnit(&vXX, &vXY); | ||
451 | vX *= vXX; | ||
452 | vY *= vXY; | ||
410 | 453 | ||
411 | SetVirtualSize(MAP_WIDTH*TILE_WIDTH*scale, MAP_HEIGHT*TILE_HEIGHT*scale); | 454 | int newViewStartX = (vX + mousePos.x) / scale * zoom - mousePos.x; |
455 | int newViewStartY = (vY + mousePos.y) / scale * zoom - mousePos.y; | ||
456 | |||
457 | SetVirtualSize(EDITOR_WIDTH * zoom, EDITOR_HEIGHT * zoom); | ||
458 | Scroll(newViewStartX / vXX, newViewStartY / vXY); | ||
459 | |||
460 | scale = zoom; | ||
412 | 461 | ||
413 | Refresh(); | 462 | Refresh(); |
414 | } | 463 | } |
diff --git a/tools/mapedit/src/widget.h b/tools/mapedit/src/widget.h index 4ae22c7..77b840e 100644 --- a/tools/mapedit/src/widget.h +++ b/tools/mapedit/src/widget.h | |||
@@ -21,7 +21,7 @@ enum EditMode { | |||
21 | EditEntities | 21 | EditEntities |
22 | }; | 22 | }; |
23 | 23 | ||
24 | class MapeditWidget : public wxScrolledWindow { | 24 | class MapeditWidget : public wxScrolledCanvas { |
25 | public: | 25 | public: |
26 | MapeditWidget(); | 26 | MapeditWidget(); |
27 | MapeditWidget(wxWindow* parent, wxWindowID winid, Map* map, TileWidget* tileWidget, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize); | 27 | MapeditWidget(wxWindow* parent, wxWindowID winid, Map* map, TileWidget* tileWidget, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize); |
@@ -54,8 +54,8 @@ class MapeditWidget : public wxScrolledWindow { | |||
54 | wxBitmap tiles; | 54 | wxBitmap tiles; |
55 | TileWidget* tileWidget; | 55 | TileWidget* tileWidget; |
56 | bool mouseIsDown = false; | 56 | bool mouseIsDown = false; |
57 | int scale; | 57 | int scale = 1; |
58 | wxPoint mousePos; | 58 | wxPoint mousePos {GAME_WIDTH/2, GAME_HEIGHT/2}; |
59 | bool mouseIsIn = false; | 59 | bool mouseIsIn = false; |
60 | EditMode editMode = EditTiles; | 60 | EditMode editMode = EditTiles; |
61 | int currentPlayer = 0; | 61 | int currentPlayer = 0; |
diff --git a/tools/mapedit/src/world.cpp b/tools/mapedit/src/world.cpp index db1201e..fb0bb36 100644 --- a/tools/mapedit/src/world.cpp +++ b/tools/mapedit/src/world.cpp | |||
@@ -114,7 +114,7 @@ World::World(std::string filename) | |||
114 | xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); | 114 | xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); |
115 | if (key != 0) | 115 | if (key != 0) |
116 | { | 116 | { |
117 | map->setRightmap(atoi((char*) key)); | 117 | map->setRightmap(atoi((char*) key), false); |
118 | } | 118 | } |
119 | xmlFree(key); | 119 | xmlFree(key); |
120 | } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "entities")) | 120 | } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "entities")) |