OpenCPN Partial API docs
Loading...
Searching...
No Matches
GrabberWin.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2010 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
23#include "wx/wx.h"
24
25#include "folder.xpm"
26
27#include "GrabberWin.h"
28
29//----------------------------------------------------------------------------
30// GrabberWindow Implementation
31//----------------------------------------------------------------------------
32BEGIN_EVENT_TABLE(GribGrabberWin, wxPanel)
33EVT_MOUSE_EVENTS(GribGrabberWin::OnMouseEvent)
34EVT_PAINT(GribGrabberWin::OnPaint)
35END_EVENT_TABLE()
36
37GribGrabberWin::GribGrabberWin(wxWindow* parent) {
38 Create(parent);
39
40 m_bLeftDown = false;
41}
42
43void GribGrabberWin::OnMouseEvent(wxMouseEvent& event) {
44 if (event.RightDown()) {
45 wxMouseEvent evt(event);
46 ((wxEvtHandler*)GetParent())->ProcessEvent(evt);
47 return;
48 }
49
50 static wxPoint s_gspt;
51 int x, y;
52
53 event.GetPosition(&x, &y);
54 wxPoint spt = ClientToScreen(wxPoint(x, y));
55
56#ifdef __WXOSX__
57 if (!m_bLeftDown && event.LeftIsDown()) {
58 m_bLeftDown = true;
59 s_gspt = spt;
60 if (!HasCapture()) CaptureMouse();
61 } else if (m_bLeftDown && !event.LeftIsDown()) {
62 // GetParent()->Move( GetParent()->GetPosition() );
63 m_bLeftDown = false;
64 if (HasCapture()) ReleaseMouse();
65 }
66#else
67
68 if (event.LeftDown()) {
69 s_gspt = spt;
70 CaptureMouse();
71 }
72
73 if (event.LeftUp()) {
74 // GetParent()->Move( GetParent()->GetPosition() );
75 if (HasCapture()) ReleaseMouse();
76 }
77#endif
78
79 if (event.Dragging()) {
80 wxPoint par_pos_old = GetParent()->GetPosition();
81
82 wxPoint par_pos = par_pos_old;
83 par_pos.x += spt.x - s_gspt.x;
84 par_pos.y += spt.y - s_gspt.y;
85
86 wxPoint pos_in_parent = GetOCPNCanvasWindow()->ScreenToClient(par_pos);
87 wxPoint pos_in_parent_old =
88 GetOCPNCanvasWindow()->ScreenToClient(par_pos_old);
89
90 // X
91 if (pos_in_parent.x < pos_in_parent_old.x) { // moving left
92 if (pos_in_parent.x < 10) {
93 pos_in_parent.x = 0;
94 }
95 } else if (pos_in_parent.x > pos_in_parent_old.x) { // moving right
96 int max_right =
97 GetOCPNCanvasWindow()->GetClientSize().x - GetParent()->GetSize().x;
98 if (pos_in_parent.x > (max_right - 10)) {
99 pos_in_parent.x = max_right;
100 }
101 }
102
103 // Y
104 if (pos_in_parent.y < pos_in_parent_old.y) { // moving up
105 if (pos_in_parent.y < 10) {
106 pos_in_parent.y = 0;
107 }
108 } else if (pos_in_parent.y > pos_in_parent_old.y) { // moving dow
109 int max_down =
110 GetOCPNCanvasWindow()->GetClientSize().y - GetParent()->GetSize().y;
111 if (pos_in_parent.y > (max_down - 10)) {
112 pos_in_parent.y = max_down;
113 }
114 }
115
116 wxPoint final_pos = GetOCPNCanvasWindow()->ClientToScreen(pos_in_parent);
117
118 GetParent()->Move(final_pos);
119
120 s_gspt = spt;
121 }
122}
123
124void GribGrabberWin::OnPaint(wxPaintEvent& event) {
125 wxPaintDC dc(this);
126 dc.DrawBitmap(m_bitmap, 0, 1, true);
127}
128
129void GribGrabberWin::Size() {
130 wxBitmap bitmap = (wxBitmap(grabber));
131 int height = GetParent()->GetSize().y - 2; // keep a small margin of 2
132 int width = height / 2;
133
134 wxImage scaled_image = bitmap.ConvertToImage();
135 m_bitmap = wxBitmap(scaled_image.Scale(width, height, wxIMAGE_QUALITY_HIGH));
136
137 SetSize(wxSize(width, height));
138 SetMinSize(wxSize(width, height));
139}
GRIB Dialog Grabber Control Interface.