28#include <wx/dcmemory.h>
29#include <wx/dcscreen.h>
31#if defined(__OCPN__ANDROID__)
33#elif defined(__WXQT__) || defined(__WXGTK__)
38#include "RolloverWin.h"
42#include "ocpn_plugin.h"
43#include "color_handler.h"
44#include "ocpn_frame.h"
45#include "OCPNPlatform.h"
48#include "glChartCanvas.h"
54extern GLenum g_texture_rectangle_format;
60EVT_PAINT(RolloverWin::OnPaint) EVT_TIMER(ROLLOVER_TIMER, RolloverWin::OnTimer)
61 EVT_MOUSE_EVENTS(RolloverWin::OnMouseEvent)
67 : wxWindow(parent, wxID_ANY, wxPoint(0, 0), wxSize(1, 1), wxNO_BORDER),
68 m_bmaincanvas(maincanvas) {
71 m_timer_timeout.SetOwner(
this, ROLLOVER_TIMER);
72 m_timeout_sec = timeout;
73 m_mmouse_propogate = 0;
80RolloverWin::~RolloverWin() {
82 glDeleteTextures(1, &m_texture);
84void RolloverWin::OnTimer(wxTimerEvent &event) {
87 GetParent()->Refresh(
true);
92void RolloverWin::OnMouseEvent(wxMouseEvent &event) {
95 if (m_mmouse_propogate) {
96 event.ResumePropagation(m_mmouse_propogate);
101void RolloverWin::SetBitmap(
int rollover) {
104 m_pbm =
new wxBitmap(m_size.x, m_size.y);
105 mdc.SelectObject(*m_pbm);
107 mdc.SetBackground(wxBrush(GetGlobalColor(_T (
"YELO1" ))));
110 bool usegl = g_bopengl && g_texture_rectangle_format;
117 wxDC *cdc =
new wxScreenDC();
118 int cpx = 0, cpy = 0;
119 GetParent()->ClientToScreen(&cpx, &cpy);
120 mdc.Blit(0, 0, m_size.x, m_size.y, cdc, m_position.x + cpx,
132 text = _(
"AISRollover");
135 text = _(
"TideCurrentGraphRollover"), radius = 0;
139 text = _(
"RouteLegInfoRollover");
144 AlphaBlending(dc, 0, 0, m_size.x, m_size.y, radius,
145 GetGlobalColor(_T (
"YELO1" )), 172);
147 mdc.SetTextForeground(FontMgr::Get().GetFontColor(text));
150 mdc.SetTextForeground(wxColour(0,0,0));
153 if (m_plabelFont && m_plabelFont->IsOk()) {
155 mdc.SetFont(*m_plabelFont);
157 mdc.DrawLabel(m_string, wxRect(0, 0, m_size.x, m_size.y),
158 wxALIGN_CENTRE_HORIZONTAL | wxALIGN_CENTRE_VERTICAL);
161 mdc.SelectObject(wxNullBitmap);
163 SetSize(m_position.x, m_position.y, m_size.x, m_size.y);
168 glGenTextures(1, &m_texture);
170 glBindTexture(g_texture_rectangle_format, m_texture);
171 glTexParameterf(g_texture_rectangle_format, GL_TEXTURE_MIN_FILTER,
173 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_MAG_FILTER,
175 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_S,
177 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_T,
181 glBindTexture(g_texture_rectangle_format, m_texture);
184 msg.Printf(_T(
"Render texture %d"), m_texture);
188 wxImage image = m_pbm->ConvertToImage();
190 unsigned char *d = image.GetData();
191 unsigned char *e =
new unsigned char[4 * m_size.x * m_size.y];
192 for (
int y = 0; y < m_size.y; y++)
193 for (
int x = 0; x < m_size.x; x++) {
194 int i = y * m_size.x + x;
195 memcpy(e + 4 * i, d + 3 * i, 3);
196 e[4 * i + 3] = 255 - d[3 * i + 2];
198 glTexImage2D(g_texture_rectangle_format, 0, GL_RGBA, m_size.x, m_size.y, 0,
199 GL_RGBA, GL_UNSIGNED_BYTE, e);
201 glDisable(g_texture_rectangle_format);
207 if (m_timeout_sec > 0) {
208 m_timer_timeout.Start(m_timeout_sec * 1000, wxTIMER_ONE_SHOT);
212void RolloverWin::OnPaint(wxPaintEvent &event) {
214 GetClientSize(&width, &height);
217 if (m_string.Len()) {
219 mdc.SelectObject(*m_pbm);
220 dc.Blit(0, 0, width, height, &mdc, 0, 0);
224void RolloverWin::Draw(
ocpnDC &dc) {
225 if (!IsActive())
return;
227 if (g_bopengl && m_texture) {
228 glEnable(g_texture_rectangle_format);
229 glBindTexture(g_texture_rectangle_format, m_texture);
232 int x0 = m_position.x, x1 = x0 + m_size.x;
233 int y0 = m_position.y, y1 = y0 + m_size.y;
235 if (GL_TEXTURE_RECTANGLE_ARB == g_texture_rectangle_format)
236 tx = m_size.x, ty = m_size.y;
265 pCanvas->GetglCanvas()->RenderTextures(dc, coords, uv, 4, pCanvas->GetpVP());
267 glDisable(g_texture_rectangle_format);
273 double scale = m_parent->GetContentScaleFactor();
275 wxImage image = m_pbm->ConvertToImage();
276 image.Rescale( image.GetWidth() *
scale, image.GetHeight() *
scale);
277 wxBitmap bmp( image );
278 dc.DrawBitmap(bmp, m_position.x, m_position.y,
false);
281 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
284 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
286 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
291 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
295void RolloverWin::SetBestPosition(
int x,
int y,
int off_x,
int off_y,
296 int rollover, wxSize parent_size) {
302 dFont = FontMgr::Get().GetFont(_(
"AISRollover"));
306 dFont = FontMgr::Get().GetFont(_(
"TideCurrentGraphRollover"));
311 dFont = FontMgr::Get().GetFont(_(
"RouteLegInfoRollover"));
315 int font_size = wxMax(8, dFont->GetPointSize());
316 font_size /= OCPN_GetWinDIPScaleFactor();
318 m_plabelFont = FontMgr::Get().FindOrCreateFont(
319 font_size, dFont->GetFamily(), dFont->GetStyle(), dFont->GetWeight(),
320 false, dFont->GetFaceName());
323 if (m_plabelFont && m_plabelFont->IsOk()) {
326 sdc.SetFont(*m_plabelFont);
327 sdc.GetMultiLineTextExtent(m_string, &w, &h, NULL, m_plabelFont);
328 sizeM = sdc.GetTextExtent(
"M");
330 wxClientDC cdc(GetParent());
331 cdc.SetFont(*m_plabelFont);
332 cdc.GetMultiLineTextExtent(m_string, &w, &h, NULL, m_plabelFont);
333 sizeM = cdc.GetTextExtent(
"M");
341 m_size.x = w + sizeM.x;
342 m_size.y = h + sizeM.y;
344 m_size *= OCPN_GetWinDIPScaleFactor();
347 if ((x + off_x + m_size.x) > parent_size.x) {
348 xp = x - (off_x / 2) - m_size.x;
353 if ((y + off_y + m_size.y) > parent_size.y) {
354 yp = y - (off_y / 2) - m_size.y;
358 SetPosition(wxPoint(xp, yp));