diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-15 15:50:04 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-15 15:50:04 -0400 |
commit | 8702c11db08f78b6c91ef950ce280f2289b1a6e6 (patch) | |
tree | ed0f093974c07cfd0a7b1d7fd24573662c05d5f3 /tools | |
parent | 3e989517ec46c40a82671620577c40765c94a41f (diff) | |
download | therapy-8702c11db08f78b6c91ef950ce280f2289b1a6e6.tar.gz therapy-8702c11db08f78b6c91ef950ce280f2289b1a6e6.tar.bz2 therapy-8702c11db08f78b6c91ef950ce280f2289b1a6e6.zip |
Added scrolling and zooming to map editor
Diffstat (limited to 'tools')
-rw-r--r-- | tools/mapedit/src/frame.cpp | 55 | ||||
-rw-r--r-- | tools/mapedit/src/frame.h | 10 | ||||
-rw-r--r-- | tools/mapedit/src/main.cpp | 2 | ||||
-rw-r--r-- | tools/mapedit/src/tile_widget.cpp | 46 | ||||
-rw-r--r-- | tools/mapedit/src/tile_widget.h | 9 | ||||
-rw-r--r-- | tools/mapedit/src/widget.cpp | 52 | ||||
-rw-r--r-- | tools/mapedit/src/widget.h | 7 |
7 files changed, 131 insertions, 50 deletions
diff --git a/tools/mapedit/src/frame.cpp b/tools/mapedit/src/frame.cpp index 858620e..537cd16 100644 --- a/tools/mapedit/src/frame.cpp +++ b/tools/mapedit/src/frame.cpp | |||
@@ -1,30 +1,75 @@ | |||
1 | #include "frame.h" | 1 | #include "frame.h" |
2 | #include "widget.h" | 2 | #include "widget.h" |
3 | #include "tile_widget.h" | 3 | #include "tile_widget.h" |
4 | #include <wx/splitter.h> | ||
5 | #include "panel.h" | ||
6 | |||
7 | enum { | ||
8 | MENU_VIEW_ZOOM_IN, | ||
9 | MENU_VIEW_ZOOM_OUT | ||
10 | }; | ||
4 | 11 | ||
5 | wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) | 12 | wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) |
6 | EVT_MENU(wxID_EXIT, MapeditFrame::OnExit) | 13 | EVT_MENU(wxID_EXIT, MapeditFrame::OnExit) |
14 | EVT_MENU(MENU_VIEW_ZOOM_IN, MapeditFrame::ZoomIn) | ||
15 | EVT_MENU(MENU_VIEW_ZOOM_OUT, MapeditFrame::ZoomOut) | ||
7 | wxEND_EVENT_TABLE() | 16 | wxEND_EVENT_TABLE() |
8 | 17 | ||
9 | MapeditFrame::MapeditFrame(Map map) : wxFrame(NULL, wxID_ANY, "Map Editor", wxPoint(50, 50), wxSize(GAME_WIDTH*3, GAME_HEIGHT*2)), map(map) | 18 | MapeditFrame::MapeditFrame(Map map) : wxFrame(NULL, wxID_ANY, "Map Editor", wxPoint(50, 50), wxSize(GAME_WIDTH*3, GAME_HEIGHT*2)), map(map) |
10 | { | 19 | { |
11 | wxMenu* menuFile = new wxMenu; | 20 | wxMenu* menuFile = new wxMenu; |
12 | menuFile->Append(wxID_EXIT); | 21 | menuFile->Append(wxID_EXIT); |
22 | |||
23 | wxMenu* menuView = new wxMenu; | ||
24 | menuView->Append(MENU_VIEW_ZOOM_IN, "Zoom In\tCtrl-+"); | ||
25 | menuView->Append(MENU_VIEW_ZOOM_OUT, "Zoom Out\tCtrl--"); | ||
13 | 26 | ||
14 | wxMenuBar* menuBar = new wxMenuBar; | 27 | wxMenuBar* menuBar = new wxMenuBar; |
15 | menuBar->Append(menuFile, "&File"); | 28 | menuBar->Append(menuFile, "&File"); |
29 | menuBar->Append(menuView, "&View"); | ||
16 | 30 | ||
17 | SetMenuBar(menuBar); | 31 | SetMenuBar(menuBar); |
18 | 32 | ||
19 | wxPanel* panel = new wxPanel(this, wxID_ANY); | 33 | wxBoxSizer* sizermain = new wxBoxSizer(wxVERTICAL); |
20 | int clientWidth, clientHeight; | 34 | wxSplitterWindow* splitter = new wxSplitterWindow(this, wxID_ANY); |
21 | GetClientSize(&clientWidth, &clientHeight); | 35 | splitter->SetSashGravity(0.0); |
36 | splitter->SetMinimumPaneSize(50); | ||
37 | sizermain->Add(splitter, 1, wxEXPAND, 0); | ||
38 | |||
39 | wxPanel* tileEditorPanel = new wxPanel(splitter, wxID_ANY); | ||
40 | tileEditor = new TileWidget(tileEditorPanel, wxID_ANY, 6, 6, wxPoint(0,0)); | ||
41 | wxBoxSizer* tileSizer = new wxBoxSizer(wxVERTICAL); | ||
42 | tileSizer->Add(tileEditor, 1, wxEXPAND, 0); | ||
43 | tileEditorPanel->SetSizer(tileSizer); | ||
44 | |||
45 | wxPanel* mapEditorPanel = new wxPanel(splitter, wxID_ANY); | ||
46 | mapEditor = new MapeditWidget(mapEditorPanel, wxID_ANY, &this->map, tileEditor, wxPoint(0,0)); | ||
47 | wxBoxSizer* mapSizer = new wxBoxSizer(wxVERTICAL); | ||
48 | mapSizer->Add(mapEditor, 1, wxEXPAND, 0); | ||
49 | mapEditorPanel->SetSizer(mapSizer); | ||
22 | 50 | ||
23 | TileWidget* tileEdit = new TileWidget(panel, wxID_ANY, 6, wxPoint(0,0), wxSize(TILE_WIDTH*3*6, clientHeight)); | 51 | splitter->SplitVertically(tileEditorPanel, mapEditorPanel); |
24 | MapeditWidget* wid = new MapeditWidget(panel, wxID_ANY, &this->map, tileEdit, wxPoint(TILE_WIDTH*3*6+8,0), wxSize(GAME_WIDTH*1.5, GAME_HEIGHT*1.5)); | 52 | |
53 | this->SetSizer(sizermain); | ||
54 | sizermain->SetSizeHints(this); | ||
25 | } | 55 | } |
26 | 56 | ||
27 | void MapeditFrame::OnExit(wxCommandEvent& event) | 57 | void MapeditFrame::OnExit(wxCommandEvent& event) |
28 | { | 58 | { |
29 | Close(true); | 59 | Close(true); |
30 | } | 60 | } |
61 | |||
62 | MapeditWidget* MapeditFrame::GetMapEditor() | ||
63 | { | ||
64 | return mapEditor; | ||
65 | } | ||
66 | |||
67 | void MapeditFrame::ZoomIn(wxCommandEvent& event) | ||
68 | { | ||
69 | mapEditor->ZoomIn(); | ||
70 | } | ||
71 | |||
72 | void MapeditFrame::ZoomOut(wxCommandEvent& event) | ||
73 | { | ||
74 | mapEditor->ZoomOut(); | ||
75 | } | ||
diff --git a/tools/mapedit/src/frame.h b/tools/mapedit/src/frame.h index e5d8562..4d6c3dc 100644 --- a/tools/mapedit/src/frame.h +++ b/tools/mapedit/src/frame.h | |||
@@ -8,16 +8,26 @@ | |||
8 | #endif | 8 | #endif |
9 | 9 | ||
10 | #include "map.h" | 10 | #include "map.h" |
11 | #include "widget.h" | ||
12 | #include "tile_widget.h" | ||
11 | 13 | ||
12 | class MapeditFrame : public wxFrame { | 14 | class MapeditFrame : public wxFrame { |
13 | public: | 15 | public: |
14 | MapeditFrame() : MapeditFrame(Map()) {} | 16 | MapeditFrame() : MapeditFrame(Map()) {} |
15 | MapeditFrame(Map map); | 17 | MapeditFrame(Map map); |
16 | 18 | ||
19 | MapeditWidget* GetMapEditor(); | ||
20 | |||
21 | protected: | ||
22 | void ZoomIn(wxCommandEvent& event); | ||
23 | void ZoomOut(wxCommandEvent& event); | ||
24 | |||
17 | private: | 25 | private: |
18 | void OnExit(wxCommandEvent& event); | 26 | void OnExit(wxCommandEvent& event); |
19 | 27 | ||
20 | Map map; | 28 | Map map; |
29 | MapeditWidget* mapEditor; | ||
30 | TileWidget* tileEditor; | ||
21 | 31 | ||
22 | wxDECLARE_EVENT_TABLE(); | 32 | wxDECLARE_EVENT_TABLE(); |
23 | }; | 33 | }; |
diff --git a/tools/mapedit/src/main.cpp b/tools/mapedit/src/main.cpp index 28fa010..cfc5a46 100644 --- a/tools/mapedit/src/main.cpp +++ b/tools/mapedit/src/main.cpp | |||
@@ -19,6 +19,8 @@ bool MapeditApp::OnInit() | |||
19 | wxInitAllImageHandlers(); | 19 | wxInitAllImageHandlers(); |
20 | 20 | ||
21 | MapeditFrame* frame = new MapeditFrame(); | 21 | MapeditFrame* frame = new MapeditFrame(); |
22 | SetTopWindow(frame); | ||
22 | frame->Show(true); | 23 | frame->Show(true); |
24 | |||
23 | return true; | 25 | return true; |
24 | } | 26 | } |
diff --git a/tools/mapedit/src/tile_widget.cpp b/tools/mapedit/src/tile_widget.cpp index 423b7c0..3dccecb 100644 --- a/tools/mapedit/src/tile_widget.cpp +++ b/tools/mapedit/src/tile_widget.cpp | |||
@@ -1,9 +1,9 @@ | |||
1 | #include "tile_widget.h" | 1 | #include "tile_widget.h" |
2 | #include "map.h" | 2 | #include "map.h" |
3 | 3 | ||
4 | IMPLEMENT_DYNAMIC_CLASS(TileWidget,wxControl) | 4 | IMPLEMENT_DYNAMIC_CLASS(TileWidget,wxScrolledWindow) |
5 | 5 | ||
6 | BEGIN_EVENT_TABLE(TileWidget, wxControl) | 6 | BEGIN_EVENT_TABLE(TileWidget, wxScrolledWindow) |
7 | EVT_PAINT(TileWidget::OnPaint) | 7 | EVT_PAINT(TileWidget::OnPaint) |
8 | EVT_LEFT_DOWN(TileWidget::OnClick) | 8 | EVT_LEFT_DOWN(TileWidget::OnClick) |
9 | END_EVENT_TABLE() | 9 | END_EVENT_TABLE() |
@@ -13,8 +13,8 @@ TileWidget::TileWidget() | |||
13 | Init(); | 13 | Init(); |
14 | } | 14 | } |
15 | 15 | ||
16 | TileWidget::TileWidget(wxWindow* parent, wxWindowID winid, int numTilesWidth, const wxPoint& pos, const wxSize& size) | 16 | TileWidget::TileWidget(wxWindow* parent, wxWindowID winid, int width, int scale, const wxPoint& pos, const wxSize& size) |
17 | : wxControl(parent, winid, pos, size), numTilesWidth(numTilesWidth) | 17 | : wxScrolledWindow(parent, winid, pos, size), numTilesWidth(width), scale(scale) |
18 | { | 18 | { |
19 | Init(); | 19 | Init(); |
20 | } | 20 | } |
@@ -27,7 +27,11 @@ int TileWidget::getSelected() | |||
27 | void TileWidget::Init() | 27 | void TileWidget::Init() |
28 | { | 28 | { |
29 | tiles = wxBitmap(wxImage("../../../res/tiles.png")); | 29 | tiles = wxBitmap(wxImage("../../../res/tiles.png")); |
30 | numTiles = 50; | 30 | |
31 | this->FitInside(); | ||
32 | this->SetScrollRate(5, 5); | ||
33 | |||
34 | SetVirtualSize(numTilesWidth*TILE_WIDTH*scale, (numTiles / numTilesWidth + 1) * TILE_HEIGHT*scale); | ||
31 | } | 35 | } |
32 | 36 | ||
33 | void TileWidget::OnPaint(wxPaintEvent& event) | 37 | void TileWidget::OnPaint(wxPaintEvent& event) |
@@ -35,39 +39,35 @@ void TileWidget::OnPaint(wxPaintEvent& event) | |||
35 | wxPaintDC dc(this); | 39 | wxPaintDC dc(this); |
36 | wxMemoryDC tiles_dc; | 40 | wxMemoryDC tiles_dc; |
37 | tiles_dc.SelectObject(tiles); | 41 | tiles_dc.SelectObject(tiles); |
38 | wxRegionIterator upd(GetUpdateRegion()); | ||
39 | int vW = upd.GetW(); | ||
40 | int vH = upd.GetH(); | ||
41 | 42 | ||
42 | wxPen pen(*wxGREEN, 2); | 43 | int vX, vY, vW, vH, aW, aH; |
43 | dc.SetPen(pen); | 44 | GetViewStart(&vX, &vY); |
44 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | 45 | GetVirtualSize(&vW, &vH); |
46 | GetSize(&aW, &aH); | ||
45 | 47 | ||
46 | double endWidth = (double) vW / (double) numTilesWidth; | ||
47 | double endHeight = TILE_HEIGHT * (endWidth / (double) TILE_WIDTH); | ||
48 | |||
49 | for (int i=0; i<numTiles; i++) | 48 | for (int i=0; i<numTiles; i++) |
50 | { | 49 | { |
51 | dc.StretchBlit(i%numTilesWidth*endWidth, i/numTilesWidth*endHeight, endWidth, endHeight, &tiles_dc, i%8*TILE_WIDTH, i/8*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); | 50 | dc.StretchBlit(i%numTilesWidth*TILE_WIDTH*scale-vX, i/numTilesWidth*TILE_HEIGHT*scale-vY, TILE_WIDTH*scale, TILE_HEIGHT*scale, &tiles_dc, i%8*TILE_WIDTH, i/8*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); |
52 | 51 | ||
53 | if (i == selected) | 52 | if (i == selected) |
54 | { | 53 | { |
55 | dc.DrawRectangle(i%numTilesWidth*endWidth, i/numTilesWidth*endHeight, endWidth, endHeight); | 54 | wxPen pen(*wxGREEN, 2); |
55 | dc.SetPen(pen); | ||
56 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | ||
57 | dc.DrawRectangle(i%numTilesWidth*TILE_WIDTH*scale - vX, i/numTilesWidth*TILE_HEIGHT*scale - vY, TILE_WIDTH*scale, TILE_HEIGHT*scale); | ||
56 | } | 58 | } |
57 | } | 59 | } |
58 | } | 60 | } |
59 | 61 | ||
60 | void TileWidget::OnClick(wxMouseEvent& event) | 62 | void TileWidget::OnClick(wxMouseEvent& event) |
61 | { | 63 | { |
62 | wxRegionIterator upd(GetUpdateRegion()); | 64 | int vX, vY, vW, vH; |
63 | int vW = upd.GetW(); | 65 | GetViewStart(&vX, &vY); |
64 | int vH = upd.GetH(); | 66 | GetVirtualSize(&vW, &vH); |
65 | double endWidth = (double) vW / (double) numTilesWidth; | ||
66 | double endHeight = TILE_HEIGHT * (endWidth / (double) TILE_WIDTH); | ||
67 | 67 | ||
68 | wxPoint pos = event.GetPosition(); | 68 | wxPoint pos = event.GetPosition(); |
69 | int x = pos.x / endWidth; | 69 | int x = (pos.x + vX) / (TILE_WIDTH * scale); |
70 | int y = pos.y / endHeight; | 70 | int y = (pos.y + vY) / (TILE_HEIGHT * scale); |
71 | 71 | ||
72 | selected = x+y*numTilesWidth; | 72 | selected = x+y*numTilesWidth; |
73 | 73 | ||
diff --git a/tools/mapedit/src/tile_widget.h b/tools/mapedit/src/tile_widget.h index 6d65f7b..f4bbc07 100644 --- a/tools/mapedit/src/tile_widget.h +++ b/tools/mapedit/src/tile_widget.h | |||
@@ -7,10 +7,12 @@ | |||
7 | #include <wx/wx.h> | 7 | #include <wx/wx.h> |
8 | #endif | 8 | #endif |
9 | 9 | ||
10 | class TileWidget : public wxControl { | 10 | #include "map.h" |
11 | |||
12 | class TileWidget : public wxScrolledWindow { | ||
11 | public: | 13 | public: |
12 | TileWidget(); | 14 | TileWidget(); |
13 | TileWidget(wxWindow* parent, wxWindowID winid, int numTilesWidth = 8, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize); | 15 | TileWidget(wxWindow* parent, wxWindowID winid, int width, int scale, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize); |
14 | 16 | ||
15 | int getSelected(); | 17 | int getSelected(); |
16 | 18 | ||
@@ -22,8 +24,9 @@ class TileWidget : public wxControl { | |||
22 | private: | 24 | private: |
23 | int numTilesWidth; | 25 | int numTilesWidth; |
24 | wxBitmap tiles; | 26 | wxBitmap tiles; |
25 | int numTiles; | 27 | int numTiles = 50; |
26 | int selected = 0; | 28 | int selected = 0; |
29 | int scale; | ||
27 | 30 | ||
28 | DECLARE_DYNAMIC_CLASS(MapeditWidget); | 31 | DECLARE_DYNAMIC_CLASS(MapeditWidget); |
29 | DECLARE_EVENT_TABLE(); | 32 | DECLARE_EVENT_TABLE(); |
diff --git a/tools/mapedit/src/widget.cpp b/tools/mapedit/src/widget.cpp index 030e556..47efa18 100644 --- a/tools/mapedit/src/widget.cpp +++ b/tools/mapedit/src/widget.cpp | |||
@@ -1,8 +1,8 @@ | |||
1 | #include "widget.h" | 1 | #include "widget.h" |
2 | 2 | ||
3 | IMPLEMENT_DYNAMIC_CLASS(MapeditWidget,wxControl) | 3 | IMPLEMENT_DYNAMIC_CLASS(MapeditWidget,wxScrolledWindow) |
4 | 4 | ||
5 | BEGIN_EVENT_TABLE(MapeditWidget, wxControl) | 5 | BEGIN_EVENT_TABLE(MapeditWidget, wxScrolledWindow) |
6 | EVT_PAINT(MapeditWidget::OnPaint) | 6 | EVT_PAINT(MapeditWidget::OnPaint) |
7 | EVT_LEFT_DOWN(MapeditWidget::OnClick) | 7 | EVT_LEFT_DOWN(MapeditWidget::OnClick) |
8 | EVT_LEFT_UP(MapeditWidget::OnMouseUp) | 8 | EVT_LEFT_UP(MapeditWidget::OnMouseUp) |
@@ -15,7 +15,7 @@ MapeditWidget::MapeditWidget() | |||
15 | } | 15 | } |
16 | 16 | ||
17 | MapeditWidget::MapeditWidget(wxWindow* parent, wxWindowID winid, Map* map, TileWidget* tileWidget, const wxPoint& pos, const wxSize& size) | 17 | MapeditWidget::MapeditWidget(wxWindow* parent, wxWindowID winid, Map* map, TileWidget* tileWidget, const wxPoint& pos, const wxSize& size) |
18 | : wxControl(parent, winid, pos, size), map(map), tileWidget(tileWidget) | 18 | : wxScrolledWindow(parent, winid, pos, size), map(map), tileWidget(tileWidget) |
19 | { | 19 | { |
20 | Init(); | 20 | Init(); |
21 | } | 21 | } |
@@ -23,6 +23,11 @@ MapeditWidget::MapeditWidget(wxWindow* parent, wxWindowID winid, Map* map, TileW | |||
23 | void MapeditWidget::Init() | 23 | void MapeditWidget::Init() |
24 | { | 24 | { |
25 | tiles = wxBitmap(wxImage("../../../res/tiles.png")); | 25 | tiles = wxBitmap(wxImage("../../../res/tiles.png")); |
26 | |||
27 | this->FitInside(); | ||
28 | this->SetScrollRate(5, 5); | ||
29 | |||
30 | SetZoomSize(2); | ||
26 | } | 31 | } |
27 | 32 | ||
28 | wxSize MapeditWidget::DoGetBestSize() const | 33 | wxSize MapeditWidget::DoGetBestSize() const |
@@ -35,34 +40,26 @@ void MapeditWidget::OnPaint(wxPaintEvent& event) | |||
35 | wxPaintDC dc(this); | 40 | wxPaintDC dc(this); |
36 | wxMemoryDC tiles_dc; | 41 | wxMemoryDC tiles_dc; |
37 | tiles_dc.SelectObject(tiles); | 42 | tiles_dc.SelectObject(tiles); |
38 | wxRegionIterator upd(GetUpdateRegion()); | 43 | int vX, vY; |
39 | int vW = upd.GetW(); | 44 | GetViewStart(&vX, &vY); |
40 | int vH = upd.GetH(); | ||
41 | 45 | ||
42 | double endWidth = TILE_WIDTH * ((double) vW / (double) GAME_WIDTH); | ||
43 | double endHeight = TILE_HEIGHT * ((double) vH / (double) GAME_HEIGHT); | ||
44 | |||
45 | for (int y=0; y<MAP_HEIGHT; y++) | 46 | for (int y=0; y<MAP_HEIGHT; y++) |
46 | { | 47 | { |
47 | for (int x=0; x<MAP_WIDTH; x++) | 48 | for (int x=0; x<MAP_WIDTH; x++) |
48 | { | 49 | { |
49 | int tile = map->mapdata[x+y*MAP_WIDTH]; | 50 | int tile = map->mapdata[x+y*MAP_WIDTH]; |
50 | dc.StretchBlit(x*endWidth, y*endHeight, endWidth, endHeight, &tiles_dc, tile%8*TILE_WIDTH, tile/8*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); | 51 | 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); |
51 | } | 52 | } |
52 | } | 53 | } |
53 | } | 54 | } |
54 | 55 | ||
55 | void MapeditWidget::SetTile(wxPoint pos) | 56 | void MapeditWidget::SetTile(wxPoint pos) |
56 | { | 57 | { |
57 | wxRegionIterator upd(GetUpdateRegion()); | 58 | int vX, vY; |
58 | int vW = upd.GetW(); | 59 | GetViewStart(&vX, &vY); |
59 | int vH = upd.GetH(); | ||
60 | 60 | ||
61 | double endWidth = TILE_WIDTH * ((double) vW / (double) GAME_WIDTH); | 61 | int x = (pos.x + vX) / (TILE_WIDTH * scale); |
62 | double endHeight = TILE_HEIGHT * ((double) vH / (double) GAME_HEIGHT); | 62 | int y = (pos.y + vY) / (TILE_HEIGHT * scale); |
63 | |||
64 | int x = pos.x / endWidth; | ||
65 | int y = pos.y / endHeight; | ||
66 | 63 | ||
67 | map->mapdata[x+y*MAP_WIDTH] = tileWidget->getSelected(); | 64 | map->mapdata[x+y*MAP_WIDTH] = tileWidget->getSelected(); |
68 | Refresh(); | 65 | Refresh(); |
@@ -89,3 +86,22 @@ void MapeditWidget::OnMouseUp(wxMouseEvent& event) | |||
89 | { | 86 | { |
90 | mouseIsDown = false; | 87 | mouseIsDown = false; |
91 | } | 88 | } |
89 | |||
90 | void MapeditWidget::ZoomIn() | ||
91 | { | ||
92 | SetZoomSize(scale+1); | ||
93 | } | ||
94 | |||
95 | void MapeditWidget::ZoomOut() | ||
96 | { | ||
97 | SetZoomSize(scale-1); | ||
98 | } | ||
99 | |||
100 | void MapeditWidget::SetZoomSize(int zoom) | ||
101 | { | ||
102 | scale = zoom; | ||
103 | |||
104 | SetVirtualSize(MAP_WIDTH*TILE_WIDTH*scale, MAP_HEIGHT*TILE_HEIGHT*scale); | ||
105 | |||
106 | GetParent()->Refresh(); | ||
107 | } | ||
diff --git a/tools/mapedit/src/widget.h b/tools/mapedit/src/widget.h index f2bfbbe..f66b0b2 100644 --- a/tools/mapedit/src/widget.h +++ b/tools/mapedit/src/widget.h | |||
@@ -10,11 +10,14 @@ | |||
10 | #include "map.h" | 10 | #include "map.h" |
11 | #include "tile_widget.h" | 11 | #include "tile_widget.h" |
12 | 12 | ||
13 | class MapeditWidget : public wxControl { | 13 | class MapeditWidget : public wxScrolledWindow { |
14 | public: | 14 | public: |
15 | MapeditWidget(); | 15 | MapeditWidget(); |
16 | MapeditWidget(wxWindow* parent, wxWindowID winid, Map* map, TileWidget* tileWidget, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize); | 16 | MapeditWidget(wxWindow* parent, wxWindowID winid, Map* map, TileWidget* tileWidget, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize); |
17 | 17 | ||
18 | void ZoomIn(); | ||
19 | void ZoomOut(); | ||
20 | |||
18 | protected: | 21 | protected: |
19 | void Init(); | 22 | void Init(); |
20 | virtual wxSize DoGetBestSize() const; | 23 | virtual wxSize DoGetBestSize() const; |
@@ -25,11 +28,13 @@ class MapeditWidget : public wxControl { | |||
25 | 28 | ||
26 | private: | 29 | private: |
27 | void SetTile(wxPoint pos); | 30 | void SetTile(wxPoint pos); |
31 | void SetZoomSize(int zoom); | ||
28 | 32 | ||
29 | Map* const map = nullptr; | 33 | Map* const map = nullptr; |
30 | wxBitmap tiles; | 34 | wxBitmap tiles; |
31 | TileWidget* tileWidget; | 35 | TileWidget* tileWidget; |
32 | bool mouseIsDown = false; | 36 | bool mouseIsDown = false; |
37 | int scale; | ||
33 | 38 | ||
34 | DECLARE_DYNAMIC_CLASS(MapeditWidget); | 39 | DECLARE_DYNAMIC_CLASS(MapeditWidget); |
35 | DECLARE_EVENT_TABLE(); | 40 | DECLARE_EVENT_TABLE(); |