diff options
Diffstat (limited to 'tools/mapedit/src/widget.cpp')
| -rw-r--r-- | tools/mapedit/src/widget.cpp | 52 |
1 files changed, 34 insertions, 18 deletions
| 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 | } | ||
