You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.6 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 CERN
  5. * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef __TOOL_DISPATCHER_H
  25. #define __TOOL_DISPATCHER_H
  26. #include <vector>
  27. #include <tool/tool_event.h>
  28. #include <wx/event.h>
  29. #include <wx/kbdstate.h>
  30. class TOOL_MANAGER;
  31. class PCB_BASE_FRAME;
  32. namespace KiGfx {
  33. class VIEW;
  34. };
  35. /**
  36. * Class TOOL_DISPATCHER
  37. *
  38. * - takes wx events,
  39. * - fixes all wx quirks (mouse warping, etc)
  40. * - translates coordinates to world space
  41. * - low-level input conditioning (drag/click threshold), updating mouse position during view auto-scroll/pan.
  42. * - issues TOOL_EVENTS to the manager
  43. */
  44. class TOOL_DISPATCHER
  45. {
  46. public:
  47. /**
  48. * Constructor
  49. *
  50. * @param aToolMgr: tool manager instance the events will be sent to
  51. * @param aEditFrame: the frame wx events come from
  52. */
  53. TOOL_DISPATCHER( TOOL_MANAGER* aToolMgr, PCB_BASE_FRAME* aEditFrame );
  54. virtual ~TOOL_DISPATCHER();
  55. virtual void ResetState();
  56. virtual void DispatchWxEvent( wxEvent& aEvent );
  57. virtual void DispatchWxCommand( wxCommandEvent& aEvent );
  58. private:
  59. static const int MouseButtonCount = 3;
  60. static const int DragTimeThreshold = 300;
  61. static const int DragDistanceThreshold = 8;
  62. bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion );
  63. bool handlePopupMenu( wxEvent& aEvent );
  64. wxPoint getCurrentMousePos();
  65. int decodeModifiers( const wxKeyboardState* aState ) const;
  66. struct ButtonState;
  67. VECTOR2D m_lastMousePos;
  68. std::vector<ButtonState*> m_buttons;
  69. KiGfx::VIEW* getView();
  70. TOOL_MANAGER* m_toolMgr;
  71. PCB_BASE_FRAME* m_editFrame;
  72. };
  73. #endif