OpenCPN Partial API docs
Loading...
Searching...
No Matches
grabber_win.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, see <https://www.gnu.org/licenses/>. *
16 ***************************************************************************/
17
24#include "wx/wx.h"
25
26#include "folder.xpm"
27
28#include "grabber_win.h"
29
30//----------------------------------------------------------------------------
31// GrabberWindow Implementation
32//----------------------------------------------------------------------------
33BEGIN_EVENT_TABLE(GribGrabberWin, wxPanel)
34EVT_MOUSE_EVENTS(GribGrabberWin::OnMouseEvent)
35EVT_PAINT(GribGrabberWin::OnPaint)
36END_EVENT_TABLE()
37
38GribGrabberWin::GribGrabberWin(wxWindow* parent) {
39 Create(parent);
40
41 m_bLeftDown = false;
42}
43
44void GribGrabberWin::OnMouseEvent(wxMouseEvent& event) {
45 if (event.RightDown()) {
46 wxMouseEvent evt(event);
47 ((wxEvtHandler*)GetParent())->ProcessEvent(evt);
48 return;
49 }
50
51 static wxPoint s_gspt;
52 int x, y;
53
54 event.GetPosition(&x, &y);
55 wxPoint spt = ClientToScreen(wxPoint(x, y));
56
57#ifdef __WXOSX__
58 if (!m_bLeftDown && event.LeftIsDown()) {
59 m_bLeftDown = true;
60 s_gspt = spt;
61 if (!HasCapture()) CaptureMouse();
62 } else if (m_bLeftDown && !event.LeftIsDown()) {
63 // GetParent()->Move( GetParent()->GetPosition() );
64 m_bLeftDown = false;
65 if (HasCapture()) ReleaseMouse();
66 }
67#else
68
69 if (event.LeftDown()) {
70 s_gspt = spt;
71 CaptureMouse();
72 }
73
74 if (event.LeftUp()) {
75 // GetParent()->Move( GetParent()->GetPosition() );
76 if (HasCapture()) ReleaseMouse();
77 }
78#endif
79
80 if (event.Dragging()) {
81 wxPoint par_pos_old = GetParent()->GetPosition();
82
83 wxPoint par_pos = par_pos_old;
84 par_pos.x += spt.x - s_gspt.x;
85 par_pos.y += spt.y - s_gspt.y;
86
87 wxPoint pos_in_parent = GetOCPNCanvasWindow()->ScreenToClient(par_pos);
88 wxPoint pos_in_parent_old =
89 GetOCPNCanvasWindow()->ScreenToClient(par_pos_old);
90
91 // X
92 if (pos_in_parent.x < pos_in_parent_old.x) { // moving left
93 if (pos_in_parent.x < 10) {
94 pos_in_parent.x = 0;
95 }
96 } else if (pos_in_parent.x > pos_in_parent_old.x) { // moving right
97 int max_right =
98 GetOCPNCanvasWindow()->GetClientSize().x - GetParent()->GetSize().x;
99 if (pos_in_parent.x > (max_right - 10)) {
100 pos_in_parent.x = max_right;
101 }
102 }
103
104 // Y
105 if (pos_in_parent.y < pos_in_parent_old.y) { // moving up
106 if (pos_in_parent.y < 10) {
107 pos_in_parent.y = 0;
108 }
109 } else if (pos_in_parent.y > pos_in_parent_old.y) { // moving dow
110 int max_down =
111 GetOCPNCanvasWindow()->GetClientSize().y - GetParent()->GetSize().y;
112 if (pos_in_parent.y > (max_down - 10)) {
113 pos_in_parent.y = max_down;
114 }
115 }
116
117 wxPoint final_pos = GetOCPNCanvasWindow()->ClientToScreen(pos_in_parent);
118
119 GetParent()->Move(final_pos);
120
121 s_gspt = spt;
122 }
123}
124
125void GribGrabberWin::OnPaint(wxPaintEvent& event) {
126 wxPaintDC dc(this);
127 dc.DrawBitmap(m_bitmap, 0, 1, true);
128}
129
130void GribGrabberWin::Size() {
131 wxBitmap bitmap = (wxBitmap(grabber));
132 int height = GetParent()->GetSize().y - 2; // keep a small margin of 2
133 int width = height / 2;
134
135 wxImage scaled_image = bitmap.ConvertToImage();
136 m_bitmap = wxBitmap(scaled_image.Scale(width, height, wxIMAGE_QUALITY_HIGH));
137
138 SetSize(wxSize(width, height));
139 SetMinSize(wxSize(width, height));
140}
GRIB Dialog Grabber Control Interface.
wxWindow * GetOCPNCanvasWindow()
Gets OpenCPN's main canvas window.