diff options
Diffstat (limited to 'tools/mapedit/src/tile_widget.cpp')
| -rw-r--r-- | tools/mapedit/src/tile_widget.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
| diff --git a/tools/mapedit/src/tile_widget.cpp b/tools/mapedit/src/tile_widget.cpp new file mode 100644 index 0000000..423b7c0 --- /dev/null +++ b/tools/mapedit/src/tile_widget.cpp | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | #include "tile_widget.h" | ||
| 2 | #include "map.h" | ||
| 3 | |||
| 4 | IMPLEMENT_DYNAMIC_CLASS(TileWidget,wxControl) | ||
| 5 | |||
| 6 | BEGIN_EVENT_TABLE(TileWidget, wxControl) | ||
| 7 | EVT_PAINT(TileWidget::OnPaint) | ||
| 8 | EVT_LEFT_DOWN(TileWidget::OnClick) | ||
| 9 | END_EVENT_TABLE() | ||
| 10 | |||
| 11 | TileWidget::TileWidget() | ||
| 12 | { | ||
| 13 | Init(); | ||
| 14 | } | ||
| 15 | |||
| 16 | TileWidget::TileWidget(wxWindow* parent, wxWindowID winid, int numTilesWidth, const wxPoint& pos, const wxSize& size) | ||
| 17 | : wxControl(parent, winid, pos, size), numTilesWidth(numTilesWidth) | ||
| 18 | { | ||
| 19 | Init(); | ||
| 20 | } | ||
| 21 | |||
| 22 | int TileWidget::getSelected() | ||
| 23 | { | ||
| 24 | return selected; | ||
| 25 | } | ||
| 26 | |||
| 27 | void TileWidget::Init() | ||
| 28 | { | ||
| 29 | tiles = wxBitmap(wxImage("../../../res/tiles.png")); | ||
| 30 | numTiles = 50; | ||
| 31 | } | ||
| 32 | |||
| 33 | void TileWidget::OnPaint(wxPaintEvent& event) | ||
| 34 | { | ||
| 35 | wxPaintDC dc(this); | ||
| 36 | wxMemoryDC tiles_dc; | ||
| 37 | tiles_dc.SelectObject(tiles); | ||
| 38 | wxRegionIterator upd(GetUpdateRegion()); | ||
| 39 | int vW = upd.GetW(); | ||
| 40 | int vH = upd.GetH(); | ||
| 41 | |||
| 42 | wxPen pen(*wxGREEN, 2); | ||
| 43 | dc.SetPen(pen); | ||
| 44 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | ||
| 45 | |||
| 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++) | ||
| 50 | { | ||
| 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); | ||
| 52 | |||
| 53 | if (i == selected) | ||
| 54 | { | ||
| 55 | dc.DrawRectangle(i%numTilesWidth*endWidth, i/numTilesWidth*endHeight, endWidth, endHeight); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | void TileWidget::OnClick(wxMouseEvent& event) | ||
| 61 | { | ||
| 62 | wxRegionIterator upd(GetUpdateRegion()); | ||
| 63 | int vW = upd.GetW(); | ||
| 64 | int vH = upd.GetH(); | ||
| 65 | double endWidth = (double) vW / (double) numTilesWidth; | ||
| 66 | double endHeight = TILE_HEIGHT * (endWidth / (double) TILE_WIDTH); | ||
| 67 | |||
| 68 | wxPoint pos = event.GetPosition(); | ||
| 69 | int x = pos.x / endWidth; | ||
| 70 | int y = pos.y / endHeight; | ||
| 71 | |||
| 72 | selected = x+y*numTilesWidth; | ||
| 73 | |||
| 74 | Refresh(); | ||
| 75 | event.Skip(); | ||
| 76 | } | ||
