MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MovablePanel.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  MovablePanel.h Dragging layer for panels which wich to be dragged
3  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
27 #ifndef MOVABLEPANEL_H
28 #define MOVABLEPANEL_H
29 
30 #include "Panel.h"
31 
32 namespace MFM
33 {
34  class MovablePanel : public Panel
35  {
36  private:
37  SPoint m_dragPoint;
38  SPoint m_preDragLocation;
39  bool m_dragging;
40 
41  public:
42  MovablePanel(u32 width = 0, u32 height = 0) :
43  Panel(width, height),
44  m_dragging(false)
45  { }
46 
47  void BeginDrag(MouseButtonEvent& event)
48  {
49  m_dragging = true;
50  m_dragPoint = event.GetAt();
51  m_preDragLocation = Panel::GetRenderPoint();
52  }
53 
54  void EndDrag()
55  {
56  m_dragging = false;
57  }
58 
59  virtual bool Handle(MouseButtonEvent& event)
60  {
61  if(event.m_event.type == SDL_MOUSEBUTTONDOWN)
62  {
63  if(event.m_keyboard.CtrlHeld())
64  {
65  BeginDrag(event);
66  return true;
67  }
68  }
69  else if(m_dragging && event.m_event.type == SDL_MOUSEBUTTONUP)
70  {
71  EndDrag();
72  return true;
73  }
74 
75  return PostDragHandle(event);
76  }
77 
78  virtual bool Handle(MouseMotionEvent& event)
79  {
80  if(m_dragging)
81  {
82  SPoint dragOffset = event.GetAt() - m_dragPoint;
83  Panel::SetRenderPoint(m_preDragLocation + dragOffset);
84  return true;
85  }
86  else
87  {
88  return PostDragHandle(event);
89  }
90  }
91 
92  virtual void OnMouseExit()
93  {
94  m_dragging = false;
95  PostDragOnMouseExit();
96  }
97 
98  virtual bool PostDragHandle(MouseButtonEvent& event)
99  {
100  return false;
101  }
102 
103  virtual bool PostDragHandle(MouseMotionEvent& event)
104  {
105  return false;
106  }
107 
108  virtual void PostDragOnMouseExit()
109  { }
110  };
111 } /* namespace MFM */
112 #endif /*PANEL_H*/
Definition: Panel.h:115
Definition: Panel.h:91
Definition: Panel.h:74
Definition: MovablePanel.h:34
virtual bool Handle(MouseMotionEvent &event)
Definition: MovablePanel.h:78
virtual bool Handle(MouseButtonEvent &event)
Definition: MovablePanel.h:59
virtual void OnMouseExit()
Definition: MovablePanel.h:92