31#include "ocpn_types.h"
32#include "compasswin.h"
36#include "wx28compat.h"
38BEGIN_EVENT_TABLE(ocpnFloatingCompassWindow, wxWindow)
39EVT_PAINT(ocpnFloatingCompassWindow::OnPaint)
40 EVT_LEFT_DOWN(ocpnFloatingCompassWindow::MouseEvent) END_EVENT_TABLE()
42 extern ocpnStyle::StyleManager* g_StyleManager;
44extern
bool g_bCourseUp;
45extern
bool g_bskew_comp;
48ocpnFloatingCompassWindow::ocpnFloatingCompassWindow(wxWindow* parent) {
50 long wstyle = wxNO_BORDER | wxFRAME_NO_TASKBAR | wxFRAME_SHAPED;
52 wstyle |= wxSTAY_ON_TOP;
54 wxDialog::Create(parent, -1, _T(
""), wxPoint(0, 0), wxSize(-1, -1), wstyle);
57 _img_compass = style->GetIcon(_T(
"CompassRose"));
58 _img_gpsRed = style->GetIcon(_T(
"gpsRed"));
62 m_pStatBoxToolStaticBmp = NULL;
66 ((_img_compass.GetWidth() + _img_gpsRed.GetWidth()) +
67 style->GetCompassLeftMargin() * 2 + style->GetToolSeparation()),
68 m_scale * (_img_compass.GetHeight() + style->GetCompassTopMargin() +
69 style->GetCompassBottomMargin()));
71 m_xoffset = style->GetCompassXOffset();
72 m_yoffset = style->GetCompassYOffset();
75ocpnFloatingCompassWindow::~ocpnFloatingCompassWindow() {
76 delete m_pStatBoxToolStaticBmp;
79void ocpnFloatingCompassWindow::OnPaint(wxPaintEvent& event) {
81 GetClientSize(&width, &height);
84 dc.DrawBitmap(m_StatBmp, 0, 0,
false);
87void ocpnFloatingCompassWindow::MouseEvent(wxMouseEvent& event) {
88 gFrame->ToggleCourseUp();
91void ocpnFloatingCompassWindow::SetColorScheme(ColorScheme cs) {
92 wxColour back_color = GetGlobalColor(_T(
"GREY2"));
95 SetBackgroundColour(back_color);
101void ocpnFloatingCompassWindow::UpdateStatus(
bool bnew) {
102 if (bnew) m_lastgpsIconName.Clear();
104 wxBitmap statbmp = CreateBmp(bnew);
105 if (statbmp.IsOk()) m_StatBmp = statbmp;
111void ocpnFloatingCompassWindow::SetScaleFactor(
float factor) {
121 ((_img_compass.GetWidth() + _img_gpsRed.GetWidth()) +
122 style->GetCompassLeftMargin() * 2 + style->GetToolSeparation()),
123 m_scale * (_img_compass.GetHeight() + style->GetCompassTopMargin() +
124 style->GetCompassBottomMargin()));
127wxBitmap ocpnFloatingCompassWindow::CreateBmp(
bool newColorScheme) {
128 wxString gpsIconName;
134 static wxBitmap compassBg, gpsBg;
135 static wxSize toolsize;
136 static int topmargin, leftmargin, radius;
138 if (!compassBg.IsOk() || newColorScheme) {
139 int orient = style->GetOrientation();
140 style->SetOrientation(wxTB_HORIZONTAL);
141 if (style->HasBackground()) {
142 compassBg = style->GetNormalBG();
143 style->DrawToolbarLineStart(compassBg);
144 compassBg = style->SetBitmapBrightness(compassBg);
145 gpsBg = style->GetNormalBG();
146 style->DrawToolbarLineEnd(gpsBg);
147 gpsBg = style->SetBitmapBrightness(gpsBg);
149 if (fabs(m_scale - 1.0) > 0.1) {
150 wxImage bg_img = compassBg.ConvertToImage();
151 bg_img.Rescale(compassBg.GetWidth() * m_scale,
152 compassBg.GetHeight() * m_scale, wxIMAGE_QUALITY_NORMAL);
153 compassBg = wxBitmap(bg_img);
155 bg_img = gpsBg.ConvertToImage();
156 bg_img.Rescale(gpsBg.GetWidth() * m_scale, gpsBg.GetHeight() * m_scale,
157 wxIMAGE_QUALITY_NORMAL);
158 gpsBg = wxBitmap(bg_img);
162 leftmargin = style->GetCompassLeftMargin();
163 topmargin = style->GetCompassTopMargin();
164 toolsize = style->GetToolSize();
166 radius = style->GetCompassCornerRadius();
168 if (orient) style->SetOrientation(wxTB_VERTICAL);
171 bool b_need_refresh =
false;
175 gpsIconName = _T(
"gps3Bar");
176 if (g_SatsInView <= 8) gpsIconName = _T(
"gps2Bar");
177 if (g_SatsInView <= 4) gpsIconName = _T(
"gps1Bar");
178 if (g_SatsInView < 0) gpsIconName = _T(
"gpsGry");
181 gpsIconName = _T(
"gpsGrn");
183 gpsIconName = _T(
"gpsRed");
185 if (m_lastgpsIconName != gpsIconName) b_need_refresh =
true;
187 double rose_angle = -999.;
189 if ((fabs(cc1->GetVPRotation()) > .01) || (fabs(cc1->GetVPSkew()) > .01)) {
190 rose_angle = -cc1->GetVPRotation();
192 if (!g_bCourseUp && !g_bskew_comp) rose_angle -= cc1->GetVPSkew();
197 if (fabs(m_rose_angle - rose_angle) > .1) b_need_refresh =
true;
199 if (b_need_refresh) {
204 ((_img_compass.GetWidth() + _img_gpsRed.GetWidth()) +
205 style->GetCompassLeftMargin() * 2 + style->GetToolSeparation()),
206 m_scale * (_img_compass.GetHeight() + style->GetCompassTopMargin() +
207 style->GetCompassBottomMargin()));
209 if (StatBmp.IsOk()) {
211 mdc.SelectObject(StatBmp);
213 wxBrush(GetGlobalColor(_T(
"GREY2")), wxBRUSHSTYLE_SOLID));
216 mdc.SetPen(wxPen(GetGlobalColor(_T(
"UITX1")), 1));
218 wxBrush(GetGlobalColor(_T(
"UITX1")), wxBRUSHSTYLE_TRANSPARENT));
220 mdc.DrawRoundedRectangle(0, 0, StatBmp.GetWidth(), StatBmp.GetHeight(),
221 m_scale * style->GetCompassCornerRadius());
223 wxPoint offset(style->GetCompassLeftMargin(),
224 style->GetCompassTopMargin());
230 wxPoint after_rotate;
233 BMPRose = style->GetIcon(_T(
"CompassRose"));
235 BMPRose = style->GetIcon(_T(
"CompassRoseBlue"));
237 if ((fabs(cc1->GetVPRotation()) > .01) ||
238 (fabs(cc1->GetVPSkew()) > .01) || (fabs(m_scale - 1.0) > 0.1)) {
239 int width = BMPRose.GetWidth() * m_scale;
240 int height = BMPRose.GetHeight() * m_scale;
242 wxImage rose_img = BMPRose.ConvertToImage();
244 if (fabs(m_scale - 1.0) > 0.1)
245 rose_img.Rescale(width, height, wxIMAGE_QUALITY_NORMAL);
247 if (fabs(rose_angle) > 0.01) {
248 wxPoint rot_ctr(width / 2, height / 2);
250 rose_img.Rotate(rose_angle, rot_ctr,
true, &after_rotate);
251 BMPRose = wxBitmap(rot_image).GetSubBitmap(
252 wxRect(-after_rotate.x, -after_rotate.y, width, height));
254 BMPRose = wxBitmap(rose_img);
257 if (style->HasBackground()) {
258 iconBm = MergeBitmaps(compassBg, BMPRose, wxSize(0, 0));
263 mdc.DrawBitmap(iconBm, offset);
264 offset.x += iconBm.GetWidth();
266 m_rose_angle = rose_angle;
269 wxBitmap gicon = style->GetIcon(gpsIconName);
270 if (fabs(m_scale - 1.0) > 0.1) {
271 int width = gicon.GetWidth() * m_scale;
272 int height = gicon.GetHeight() * m_scale;
274 wxImage gps_img = gicon.ConvertToImage();
275 gps_img.Rescale(width, height, wxIMAGE_QUALITY_NORMAL);
276 gicon = wxBitmap(gps_img);
279 if (style->HasBackground()) {
280 iconBm = MergeBitmaps(gpsBg, gicon, wxSize(0, 0));
284 mdc.DrawBitmap(iconBm, offset);
285 mdc.SelectObject(wxNullBitmap);
286 m_lastgpsIconName = gpsIconName;
289#if !defined(__WXMAC__) && !defined(__OCPN__ANDROID__)
290 if (style->marginsInvisible) {
291 m_MaskBmp = wxBitmap(StatBmp.GetWidth(), StatBmp.GetHeight());
292 wxMemoryDC sdc(m_MaskBmp);
293 sdc.SetBackground(*wxWHITE_BRUSH);
295 sdc.SetBrush(*wxBLACK_BRUSH);
296 sdc.SetPen(*wxBLACK_PEN);
297 sdc.DrawRoundedRectangle(wxPoint(leftmargin, topmargin), toolsize,
299 sdc.SelectObject(wxNullBitmap);
300 SetShape(wxRegion(m_MaskBmp, *wxWHITE, 0));
302 m_MaskBmp = wxBitmap(GetSize().x, GetSize().y);
303 wxMemoryDC sdc(m_MaskBmp);
304 sdc.SetBackground(*wxWHITE_BRUSH);
306 sdc.SetBrush(*wxBLACK_BRUSH);
307 sdc.SetPen(*wxBLACK_PEN);
308 sdc.DrawRoundedRectangle(0, 0, m_MaskBmp.GetWidth(),
309 m_MaskBmp.GetHeight(), radius);
310 sdc.SelectObject(wxNullBitmap);
311 SetShape(wxRegion(m_MaskBmp, *wxWHITE, 0));