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