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/mapedit/src/tile_widget.cpp | |
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/mapedit/src/tile_widget.cpp')
-rw-r--r-- | tools/mapedit/src/tile_widget.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
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 | ||