OpenCPN Partial API docs
ChInfoWin.cpp
1 /******************************************************************************
2  *
3  * Project: OpenCPN
4  *
5  ***************************************************************************
6  * Copyright (C) 2013 by David S. Register *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
22  ***************************************************************************
23  */
24 
25 #include <wx/wxprec.h>
26 
27 #include <wx/dcclient.h>
28 
29 #include "model/config_vars.h"
30 #include "ChInfoWin.h"
31 #include "OCPNPlatform.h"
32 #include "FontMgr.h"
33 #include "color_handler.h"
34 
35 #ifdef __OCPN__ANDROID__
36 #include "androidUTIL.h"
37 #endif
38 
39 extern OCPNPlatform* g_Platform;
40 
41 BEGIN_EVENT_TABLE(ChInfoWin, wxPanel)
42 EVT_PAINT(ChInfoWin::OnPaint)
43 EVT_ERASE_BACKGROUND(ChInfoWin::OnEraseBackground)
44 EVT_MOUSE_EVENTS(ChInfoWin::MouseEvent)
45 END_EVENT_TABLE()
46 
47 // Define a constructor
48 ChInfoWin::ChInfoWin(wxWindow* parent) {
49  long style = wxSIMPLE_BORDER | wxCLIP_CHILDREN | wxFRAME_FLOAT_ON_PARENT;
50 
51  wxPanel::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style);
52 
53  wxFont* dFont = FontMgr::Get().GetFont(_("Dialog"));
54  SetFont(*dFont);
55 
56  int ststyle = wxALIGN_LEFT | wxST_NO_AUTORESIZE;
57  m_pInfoTextCtl = new wxStaticText(this, -1, _T ( "" ),
58  wxDefaultPosition,
59  wxDefaultSize, ststyle);
60 
61  dbIndex = -1;
62  Hide();
63 }
64 
65 ChInfoWin::~ChInfoWin() { delete m_pInfoTextCtl; }
66 
67 void ChInfoWin::OnEraseBackground(wxEraseEvent& event) {}
68 
69 void ChInfoWin::MouseEvent(wxMouseEvent& event) {
70  if (g_btouch) {
71  if (event.LeftDown()) {
72  Hide();
73 
74 #ifdef __OCPN__ANDROID__
75  androidForceFullRepaint();
76 #endif
77  }
78  }
79 }
80 
81 void ChInfoWin::OnPaint(wxPaintEvent& event) {
82  int width, height;
83  GetClientSize(&width, &height);
84  wxPaintDC dc(this);
85 
86  dc.SetBrush(wxBrush(GetGlobalColor(_T ( "UIBCK" ))));
87  dc.SetPen(wxPen(GetGlobalColor(_T ( "UITX1" ))));
88  dc.DrawRectangle(0, 0, width, height);
89 }
90 
91 void ChInfoWin::SetBitmap() {
92  SetBackgroundColour(GetGlobalColor(_T ( "UIBCK" )));
93 
94  m_pInfoTextCtl->SetBackgroundColour(GetGlobalColor(_T ( "UIBCK" )));
95  m_pInfoTextCtl->SetForegroundColour(GetGlobalColor(_T ( "UITX1" )));
96 
97  m_pInfoTextCtl->SetSize(GetCharWidth(), 1, m_size.x - 2 * GetCharWidth(), m_size.y - 2);
98  m_pInfoTextCtl->SetLabel(m_string);
99 
100  wxPoint top_position =
101  m_position; // GetParent()->ClientToScreen( m_position);
102  SetSize(top_position.x, top_position.y, m_size.x, m_size.y);
103  SetClientSize(m_size.x, m_size.y);
104 }
105 
106 void ChInfoWin::FitToChars(int char_width, int char_height) {
107  wxSize size;
108 
109  int adjust = 1;
110 
111 #ifdef __WXOSX__
112  adjust = 2;
113 #endif
114 
115 #ifdef __OCPN__ANDROID__
116  adjust = 4;
117 #endif
118 
119  size.x = GetCharWidth() * char_width;
120  size.y = GetCharHeight() * (char_height + adjust);
121  size.x = wxMin(size.x, g_Platform->getDisplaySize().x - 10);
122  SetWinSize(size);
123 }