28#include <wx/dcmemory.h>
29#include <wx/dcscreen.h>
32#if defined(__OCPN__ANDROID__)
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"
56extern GLenum g_texture_rectangle_format;
62EVT_PAINT(RolloverWin::OnPaint)
63EVT_TIMER(ROLLOVER_TIMER, RolloverWin::OnTimer)
64EVT_MOUSE_EVENTS(RolloverWin::OnMouseEvent)
70 : wxWindow(parent, wxID_ANY, wxPoint(0, 0), wxSize(1, 1), wxNO_BORDER),
71 m_bmaincanvas(maincanvas) {
74 m_timer_timeout.SetOwner(
this, ROLLOVER_TIMER);
75 m_timeout_sec = timeout;
76 m_mmouse_propogate = 0;
83RolloverWin::~RolloverWin() {
86 if (g_bopengl) glDeleteTextures(1, &m_texture);
89void RolloverWin::OnTimer(wxTimerEvent &event) {
92 GetParent()->Refresh(
true);
97void RolloverWin::OnMouseEvent(wxMouseEvent &event) {
100 if (m_mmouse_propogate) {
101 event.ResumePropagation(m_mmouse_propogate);
106void 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);
213void 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);
225void 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;
264 auto pCanvas =
dynamic_cast<ChartCanvas *
>(GetParent());
266 pCanvas->GetglCanvas()->RenderTextures(dc, coords, uv, 4,
269 glDisable(g_texture_rectangle_format);
275 double scale = m_parent->GetContentScaleFactor();
277 wxImage image = m_pbm->ConvertToImage();
278 image.Rescale(image.GetWidth() *
scale, image.GetHeight() *
scale);
280 dc.DrawBitmap(bmp, m_position.x, m_position.y,
false);
282 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"));
316 wxMax(8 * g_current_monitor_dip_px_ratio, dFont->GetPointSize());
317 font_size /= OCPN_GetWinDIPScaleFactor();
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");
341 m_size.x = w + sizeM.x;
342 m_size.y = h + sizeM.y;
345 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));
wxFont * FindOrCreateFont(int point_size, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underline=false, const wxString &facename=wxEmptyString, wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
Creates or finds a matching font in the font cache.
wxFont * GetFont(const wxString &TextElement, int requested_font_size=0)
Gets a font object for a UI element.
Device context class that can use either wxDC or OpenGL for drawing.
PlugIn Object Definition/API.