25 #include <wx/wxprec.h>
27 #include <wx/bitmap.h>
28 #include <wx/dcmemory.h>
29 #include <wx/dcscreen.h>
32 #if defined(__OCPN__ANDROID__)
33 #include <GLES2/gl2.h>
34 #elif defined(__WXQT__) || defined(__WXGTK__)
40 #include "RolloverWin.h"
45 #include "color_handler.h"
46 #include "ocpn_frame.h"
47 #include "OCPNPlatform.h"
50 #include "glChartCanvas.h"
54 extern bool g_bopengl;
56 extern GLenum g_texture_rectangle_format;
62 EVT_PAINT(RolloverWin::OnPaint) EVT_TIMER(ROLLOVER_TIMER, RolloverWin::OnTimer)
63 EVT_MOUSE_EVENTS(RolloverWin::OnMouseEvent)
69 : wxWindow(parent, wxID_ANY, wxPoint(0, 0), wxSize(1, 1), wxNO_BORDER),
70 m_bmaincanvas(maincanvas) {
73 m_timer_timeout.SetOwner(
this, ROLLOVER_TIMER);
74 m_timeout_sec = timeout;
75 m_mmouse_propogate = 0;
82 RolloverWin::~RolloverWin() {
86 glDeleteTextures(1, &m_texture);
89 void RolloverWin::OnTimer(wxTimerEvent &event) {
92 GetParent()->Refresh(
true);
97 void RolloverWin::OnMouseEvent(wxMouseEvent &event) {
100 if (m_mmouse_propogate) {
101 event.ResumePropagation(m_mmouse_propogate);
106 void RolloverWin::SetBitmap(
int rollover) {
109 m_pbm =
new wxBitmap(m_size.x, m_size.y);
110 mdc.SelectObject(*m_pbm);
112 mdc.SetBackground(wxBrush(GetGlobalColor(_T (
"YELO1" ))));
115 bool usegl = g_bopengl && g_texture_rectangle_format;
122 wxDC *cdc =
new wxScreenDC();
123 int cpx = 0, cpy = 0;
124 GetParent()->ClientToScreen(&cpx, &cpy);
125 mdc.Blit(0, 0, m_size.x, m_size.y, cdc, m_position.x + cpx,
137 text = _(
"AISRollover");
140 text = _(
"TideCurrentGraphRollover"), radius = 0;
144 text = _(
"RouteLegInfoRollover");
149 AlphaBlending(dc, 0, 0, m_size.x, m_size.y, radius,
150 GetGlobalColor(_T (
"YELO1" )), 172);
152 mdc.SetTextForeground(FontMgr::Get().GetFontColor(text));
155 mdc.SetTextForeground(wxColour(0,0,0));
158 if (m_plabelFont && m_plabelFont->IsOk()) {
160 mdc.SetFont(*m_plabelFont);
162 mdc.DrawLabel(m_string, wxRect(0, 0, m_size.x, m_size.y),
163 wxALIGN_CENTRE_HORIZONTAL | wxALIGN_CENTRE_VERTICAL);
166 mdc.SelectObject(wxNullBitmap);
168 SetSize(m_position.x, m_position.y, m_size.x, m_size.y);
173 glGenTextures(1, &m_texture);
175 glBindTexture(g_texture_rectangle_format, m_texture);
176 glTexParameterf(g_texture_rectangle_format, GL_TEXTURE_MIN_FILTER,
178 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_MAG_FILTER,
180 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_S,
182 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_T,
186 glBindTexture(g_texture_rectangle_format, m_texture);
189 wxImage image = m_pbm->ConvertToImage();
191 unsigned char *d = image.GetData();
192 unsigned char *e =
new unsigned char[4 * m_size.x * m_size.y];
193 for (
int y = 0; y < m_size.y; y++)
194 for (
int x = 0; x < m_size.x; x++) {
195 int i = y * m_size.x + x;
196 memcpy(e + 4 * i, d + 3 * i, 3);
197 e[4 * i + 3] = 255 - d[3 * i + 2];
199 glTexImage2D(g_texture_rectangle_format, 0, GL_RGBA, m_size.x, m_size.y, 0,
200 GL_RGBA, GL_UNSIGNED_BYTE, e);
202 glDisable(g_texture_rectangle_format);
208 if (m_timeout_sec > 0) {
209 m_timer_timeout.Start(m_timeout_sec * 1000, wxTIMER_ONE_SHOT);
213 void RolloverWin::OnPaint(wxPaintEvent &event) {
215 GetClientSize(&width, &height);
218 if (m_string.Len()) {
220 mdc.SelectObject(*m_pbm);
221 dc.Blit(0, 0, width, height, &mdc, 0, 0);
225 void RolloverWin::Draw(
ocpnDC &dc) {
226 if (!IsActive())
return;
228 if (g_bopengl && m_texture) {
229 glEnable(g_texture_rectangle_format);
230 glBindTexture(g_texture_rectangle_format, m_texture);
233 int x0 = m_position.x, x1 = x0 + m_size.x;
234 int y0 = m_position.y, y1 = y0 + m_size.y;
236 if (GL_TEXTURE_RECTANGLE_ARB == g_texture_rectangle_format)
237 tx = m_size.x, ty = m_size.y;
266 pCanvas->GetglCanvas()->RenderTextures(dc, coords, uv, 4, pCanvas->GetpVP());
268 glDisable(g_texture_rectangle_format);
274 double scale = m_parent->GetContentScaleFactor();
276 wxImage image = m_pbm->ConvertToImage();
277 image.Rescale( image.GetWidth() *
scale, image.GetHeight() *
scale);
278 wxBitmap bmp( image );
279 dc.DrawBitmap(bmp, m_position.x, m_position.y,
false);
282 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
285 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
287 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
292 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
296 void RolloverWin::SetBestPosition(
int x,
int y,
int off_x,
int off_y,
297 int rollover, wxSize parent_size) {
303 dFont = FontMgr::Get().GetFont(_(
"AISRollover"));
307 dFont = FontMgr::Get().GetFont(_(
"TideCurrentGraphRollover"));
312 dFont = FontMgr::Get().GetFont(_(
"RouteLegInfoRollover"));
316 int font_size = wxMax(8 * g_current_monitor_dip_px_ratio, dFont->GetPointSize());
317 font_size /= OCPN_GetWinDIPScaleFactor();
319 m_plabelFont = FontMgr::Get().FindOrCreateFont(
320 font_size, dFont->GetFamily(), dFont->GetStyle(), dFont->GetWeight(),
321 false, dFont->GetFaceName());
324 if (m_plabelFont && m_plabelFont->IsOk()) {
327 sdc.SetFont(*m_plabelFont);
328 sdc.GetMultiLineTextExtent(m_string, &w, &h, NULL, m_plabelFont);
329 sizeM = sdc.GetTextExtent(
"M");
331 wxClientDC cdc(GetParent());
332 cdc.SetFont(*m_plabelFont);
333 cdc.GetMultiLineTextExtent(m_string, &w, &h, NULL, m_plabelFont);
334 sizeM = cdc.GetTextExtent(
"M");
342 m_size.x = w + sizeM.x;
343 m_size.y = h + sizeM.y;
345 m_size *= OCPN_GetWinDIPScaleFactor();
348 if ((x + off_x + m_size.x) > parent_size.x) {
349 xp = x - (off_x / 2) - m_size.x;
354 if ((y + off_y + m_size.y) > parent_size.y) {
355 yp = y - (off_y / 2) - m_size.y;
359 SetPosition(wxPoint(xp, yp));