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 "chart1.h"
31 #include "OCPNPlatform.h"
32 #include "FontMgr.h"
33
34
35 #ifdef __OCPN__ANDROID__
36 #include "androidUTIL.h"
37 #endif
38
39 extern bool g_btouch;
40 extern OCPNPlatform *g_Platform;
41
BEGIN_EVENT_TABLE(ChInfoWin,wxPanel)42 BEGIN_EVENT_TABLE(ChInfoWin, wxPanel)
43 EVT_PAINT ( ChInfoWin::OnPaint )
44 EVT_ERASE_BACKGROUND(ChInfoWin::OnEraseBackground)
45 EVT_MOUSE_EVENTS ( ChInfoWin::MouseEvent )
46 END_EVENT_TABLE()
47
48 // Define a constructor
49 ChInfoWin::ChInfoWin( wxWindow *parent )
50 {
51
52 long style = wxSIMPLE_BORDER | wxCLIP_CHILDREN | wxFRAME_FLOAT_ON_PARENT;
53
54 wxPanel::Create( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style );
55
56 wxFont *dFont = FontMgr::Get().GetFont( _("Dialog") );
57 SetFont(*dFont);
58
59 int ststyle = wxALIGN_LEFT | wxST_NO_AUTORESIZE;
60 m_pInfoTextCtl = new wxStaticText( this, -1, _T ( "" ), wxDefaultPosition, wxDefaultSize,
61 ststyle );
62
63 dbIndex = -1;
64 Hide();
65 }
66
~ChInfoWin()67 ChInfoWin::~ChInfoWin()
68 {
69 delete m_pInfoTextCtl;
70 }
71
OnEraseBackground(wxEraseEvent & event)72 void ChInfoWin::OnEraseBackground( wxEraseEvent& event )
73 {
74 }
75
MouseEvent(wxMouseEvent & event)76 void ChInfoWin::MouseEvent( wxMouseEvent& event )
77 {
78 if(g_btouch){
79 if( event.LeftDown() ) {
80 Hide();
81
82 #ifdef __OCPN__ANDROID__
83 androidForceFullRepaint();
84 #endif
85 }
86 }
87 }
88
89
OnPaint(wxPaintEvent & event)90 void ChInfoWin::OnPaint( wxPaintEvent& event )
91 {
92 int width, height;
93 GetClientSize( &width, &height );
94 wxPaintDC dc( this );
95
96 dc.SetBrush( wxBrush( GetGlobalColor( _T ( "UIBCK" ) ) ) );
97 dc.SetPen( wxPen( GetGlobalColor( _T ( "UITX1" ) ) ) );
98 dc.DrawRectangle( 0, 0, width, height );
99 }
100
SetBitmap()101 void ChInfoWin::SetBitmap()
102 {
103 SetBackgroundColour( GetGlobalColor( _T ( "UIBCK" ) ) );
104
105 m_pInfoTextCtl->SetBackgroundColour( GetGlobalColor( _T ( "UIBCK" ) ) );
106 m_pInfoTextCtl->SetForegroundColour( GetGlobalColor( _T ( "UITX1" ) ) );
107
108 m_pInfoTextCtl->SetSize( 1, 1, m_size.x - 2, m_size.y - 2 );
109 m_pInfoTextCtl->SetLabel( m_string );
110
111 wxPoint top_position = m_position; //GetParent()->ClientToScreen( m_position);
112 SetSize( top_position.x, top_position.y, m_size.x, m_size.y );
113 SetClientSize( m_size.x, m_size.y );
114 }
115
FitToChars(int char_width,int char_height)116 void ChInfoWin::FitToChars( int char_width, int char_height )
117 {
118 wxSize size;
119
120 int adjust = 1;
121
122 #ifdef __WXOSX__
123 adjust = 2;
124 #endif
125
126 #ifdef __OCPN__ANDROID__
127 adjust = 4;
128 #endif
129
130 size.x = GetCharWidth() * char_width;
131 size.y = GetCharHeight() * ( char_height + adjust );
132 size.x = wxMin(size.x, g_Platform->getDisplaySize().x-10);
133 SetWinSize( size );
134 }
135
136