OpenCPN Partial API docs
Loading...
Searching...
No Matches
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 "ChInfoWin.h"
30#include "OCPNPlatform.h"
31#include "FontMgr.h"
32#include "color_handler.h"
33
34#ifdef __OCPN__ANDROID__
35#include "androidUTIL.h"
36#endif
37
38extern bool g_btouch;
39extern OCPNPlatform* g_Platform;
40
41BEGIN_EVENT_TABLE(ChInfoWin, wxPanel)
42EVT_PAINT(ChInfoWin::OnPaint)
43EVT_ERASE_BACKGROUND(ChInfoWin::OnEraseBackground)
44EVT_MOUSE_EVENTS(ChInfoWin::MouseEvent)
45END_EVENT_TABLE()
46
47// Define a constructor
48ChInfoWin::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 ( "" ), wxDefaultPosition,
58 wxDefaultSize, ststyle);
59
60 dbIndex = -1;
61 Hide();
62}
63
64ChInfoWin::~ChInfoWin() { delete m_pInfoTextCtl; }
65
66void ChInfoWin::OnEraseBackground(wxEraseEvent& event) {}
67
68void ChInfoWin::MouseEvent(wxMouseEvent& event) {
69 if (g_btouch) {
70 if (event.LeftDown()) {
71 Hide();
72
73#ifdef __OCPN__ANDROID__
74 androidForceFullRepaint();
75#endif
76 }
77 }
78}
79
80void ChInfoWin::OnPaint(wxPaintEvent& event) {
81 int width, height;
82 GetClientSize(&width, &height);
83 wxPaintDC dc(this);
84
85 dc.SetBrush(wxBrush(GetGlobalColor(_T ( "UIBCK" ))));
86 dc.SetPen(wxPen(GetGlobalColor(_T ( "UITX1" ))));
87 dc.DrawRectangle(0, 0, width, height);
88}
89
90void ChInfoWin::SetBitmap() {
91 SetBackgroundColour(GetGlobalColor(_T ( "UIBCK" )));
92
93 m_pInfoTextCtl->SetBackgroundColour(GetGlobalColor(_T ( "UIBCK" )));
94 m_pInfoTextCtl->SetForegroundColour(GetGlobalColor(_T ( "UITX1" )));
95
96 m_pInfoTextCtl->SetSize(1, 1, m_size.x - 2, m_size.y - 2);
97 m_pInfoTextCtl->SetLabel(m_string);
98
99 wxPoint top_position =
100 m_position; // GetParent()->ClientToScreen( m_position);
101 SetSize(top_position.x, top_position.y, m_size.x, m_size.y);
102 SetClientSize(m_size.x, m_size.y);
103}
104
105void ChInfoWin::FitToChars(int char_width, int char_height) {
106 wxSize size;
107
108 int adjust = 1;
109
110#ifdef __WXOSX__
111 adjust = 2;
112#endif
113
114#ifdef __OCPN__ANDROID__
115 adjust = 4;
116#endif
117
118 size.x = GetCharWidth() * char_width;
119 size.y = GetCharHeight() * (char_height + adjust);
120 size.x = wxMin(size.x, g_Platform->getDisplaySize().x - 10);
121 SetWinSize(size);
122}