From 168b51517682b8d82fdbd6432af7511bb493c85f Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 15 Mar 2015 16:03:57 -0400 Subject: Added preview of tile to be placed under mouse in map editor --- tools/mapedit/src/widget.cpp | 26 ++++++++++++++++++++++++++ tools/mapedit/src/widget.h | 3 +++ 2 files changed, 29 insertions(+) (limited to 'tools') diff --git a/tools/mapedit/src/widget.cpp b/tools/mapedit/src/widget.cpp index 47efa18..53249c7 100644 --- a/tools/mapedit/src/widget.cpp +++ b/tools/mapedit/src/widget.cpp @@ -7,6 +7,7 @@ BEGIN_EVENT_TABLE(MapeditWidget, wxScrolledWindow) EVT_LEFT_DOWN(MapeditWidget::OnClick) EVT_LEFT_UP(MapeditWidget::OnMouseUp) EVT_MOTION(MapeditWidget::OnMouseMove) + EVT_LEAVE_WINDOW(MapeditWidget::OnMouseOut) END_EVENT_TABLE() MapeditWidget::MapeditWidget() @@ -51,6 +52,20 @@ void MapeditWidget::OnPaint(wxPaintEvent& event) 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); } } + + if (mouseIsIn) + { + int tile = tileWidget->getSelected(); + int x = (mousePos.x + vX) / (TILE_WIDTH * scale); + int y = (mousePos.y + vY) / (TILE_HEIGHT * scale); + + 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); + + wxPen pen(*wxGREEN, 2); + dc.SetPen(pen); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawRectangle(x*TILE_WIDTH*scale-vX, y*TILE_HEIGHT*scale-vY, TILE_WIDTH*scale, TILE_HEIGHT*scale); + } } void MapeditWidget::SetTile(wxPoint pos) @@ -80,6 +95,10 @@ void MapeditWidget::OnMouseMove(wxMouseEvent& event) { SetTile(event.GetPosition()); } + + mouseIsIn = true; + mousePos = event.GetPosition(); + Refresh(); } void MapeditWidget::OnMouseUp(wxMouseEvent& event) @@ -87,6 +106,13 @@ void MapeditWidget::OnMouseUp(wxMouseEvent& event) mouseIsDown = false; } +void MapeditWidget::OnMouseOut(wxMouseEvent& event) +{ + mouseIsIn = false; + + Refresh(); +} + void MapeditWidget::ZoomIn() { SetZoomSize(scale+1); diff --git a/tools/mapedit/src/widget.h b/tools/mapedit/src/widget.h index f66b0b2..c8bfb57 100644 --- a/tools/mapedit/src/widget.h +++ b/tools/mapedit/src/widget.h @@ -25,6 +25,7 @@ class MapeditWidget : public wxScrolledWindow { void OnClick(wxMouseEvent& event); void OnMouseMove(wxMouseEvent& event); void OnMouseUp(wxMouseEvent& event); + void OnMouseOut(wxMouseEvent& event); private: void SetTile(wxPoint pos); @@ -35,6 +36,8 @@ class MapeditWidget : public wxScrolledWindow { TileWidget* tileWidget; bool mouseIsDown = false; int scale; + wxPoint mousePos; + bool mouseIsIn = false; DECLARE_DYNAMIC_CLASS(MapeditWidget); DECLARE_EVENT_TABLE(); -- cgit 1.4.1