📄 mapeventextender.cpp
字号:
/* * Roadnav * MapEventExtender.cpp * * Copyright (c) 2004 - 2007 Richard L. Lynch <rllynch@users.sourceforge.net> * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public License * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ ///////////////////////////////////////////////////////////////////////////////// \file////// This file contains an event handler that extends map control events/////////////////////////////////////////////////////////////////////////////////#ifdef HAVE_CONFIG_H# include <config.h>#endif#ifdef _MSC_VER#pragma warning(disable: 4786)#endif#define MAX(x,y) ( (x) > (y) ? (x) : (y) )#include "MapEventExtender.h"#include "libroadnav/MapControl.h"#include "Frame.h"#include "libroadnav/MapSupport.h"#include "libroadnav/MapRepresentations.h"//////////////////////////////////////////////////////////////////////////////////// MapEventExtender events/////////////////////////////////////////////////////////////////////////////////BEGIN_EVENT_TABLE(MapEventExtender, wxEvtHandler) EVT_LEFT_DOWN(MapEventExtender::OnLButtonDown) EVT_MOTION(MapEventExtender::OnMouseMove) EVT_LEFT_UP(MapEventExtender::OnLButtonUp)END_EVENT_TABLE()//////////////////////////////////////////////////////////////////////////////////// MapEventExtender constructor/////////////////////////////////////////////////////////////////////////////////MapEventExtender::MapEventExtender(MapFrame* pFrame,MapControl* pMap) : wxEvtHandler(){ m_pFrame = pFrame; m_pMap = pMap; m_bMeasuring = false; m_bZooming = false;}//////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////void MapEventExtender::OnLButtonDown(wxMouseEvent& event){ if ( m_pFrame->GetToolMode() == toolMeasure || m_pFrame->GetToolMode() == toolZoom ) { m_bMeasuring = (m_pFrame->GetToolMode() == toolMeasure); m_bZooming = (m_pFrame->GetToolMode() == toolZoom); m_pMap->CaptureMouse(); wxClientDC dc(m_pMap); m_Start = event.GetLogicalPosition(dc); m_Last = m_Start; m_ptStart = m_pMap->MapScreenToLongLat(m_Start); } else event.Skip();}//////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////void MapEventExtender::OnMouseMove(wxMouseEvent& event){ wxClientDC dc(m_pMap); dc.SetBrush(*wxTRANSPARENT_BRUSH); Point pt = m_pMap->MapScreenToLongLat(event.GetLogicalPosition(dc)); m_pFrame->SetStatusText(pt.FormatPoint()); if ( m_bMeasuring || m_bZooming ) { dc.SetLogicalFunction(wxINVERT); if ( m_bMeasuring ) dc.DrawLine(m_Start,m_Last); else dc.DrawRectangle(m_Start,wxSize(m_Last.x-m_Start.x,m_Last.y-m_Start.y)); m_Last = event.GetLogicalPosition(dc); if ( m_bMeasuring ) { dc.DrawLine(m_Start,m_Last); double distance = Distance(m_ptStart,pt); Direction direction = Bearing(m_Start,m_Last); wxString msg; msg = wxString::Format(wxT("Distance: %s, Direction: %s"), FormatDistance(distance).c_str(),direction.AsBearingString(true,true).c_str()); m_pFrame->SetStatusText(msg,1); } else dc.DrawRectangle(m_Start,wxSize(m_Last.x-m_Start.x,m_Last.y-m_Start.y)); } else event.Skip();}//////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////void MapEventExtender::OnLButtonUp(wxMouseEvent& event){ if ( m_bMeasuring || m_bZooming ) { wxClientDC dc(m_pMap); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetLogicalFunction(wxINVERT); if ( m_bMeasuring ) dc.DrawLine(m_Start,m_Last); else dc.DrawRectangle(m_Start,wxSize(m_Last.x-m_Start.x,m_Last.y-m_Start.y)); m_pFrame->SetStatusText(wxString(),1); // If zooming, center map on center of rectangle if ( m_bZooming ) { wxRect rect(m_Start,wxSize(m_Last.x-m_Start.x,m_Last.y-m_Start.y)); wxPoint center((m_Start.x + m_Last.x)/2,(m_Start.y + m_Last.y)/2); Point ptCenter = m_pMap->MapScreenToLongLat(center); m_pMap->SetCenterCoordinates(ptCenter); Point ptTopLeft = m_pMap->MapScreenToLongLat(m_Start); Point ptBottomRight = m_pMap->MapScreenToLongLat(m_Last); wxSize size = m_pMap->GetSize(); double s1 = (ptBottomRight.m_fLong - ptTopLeft.m_fLong)/size.GetWidth(); double s2 = (ptTopLeft.m_fLat - ptBottomRight.m_fLat)/size.GetHeight(); double s = MAX(s1,s2) * m_pMap->GetDrawingScaleFactor(); m_pMap->SetBestDetailLevel(s); m_pFrame->SetToolMode(toolNone); // cancel zoom mode after finished } m_pMap->ReleaseMouse(); m_bMeasuring = false; m_bZooming = false; } else event.Skip();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -