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;
61EVT_PAINT(RolloverWin::OnPaint)
62EVT_TIMER(ROLLOVER_TIMER, RolloverWin::OnTimer)
63EVT_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;
82RolloverWin::~RolloverWin() {
85 if (g_bopengl) glDeleteTextures(1, &m_texture);
88void RolloverWin::OnTimer(wxTimerEvent &event) {
91 GetParent()->Refresh(
true);
96void RolloverWin::OnMouseEvent(wxMouseEvent &event) {
99 if (m_mmouse_propogate) {
100 event.ResumePropagation(m_mmouse_propogate);
105void RolloverWin::SetBitmap(
int rollover) {
108 m_pbm =
new wxBitmap(m_size.x, m_size.y);
109 mdc.SelectObject(*m_pbm);
111 mdc.SetBackground(wxBrush(GetGlobalColor(_T (
"YELO1" ))));
114 bool usegl = g_bopengl && g_texture_rectangle_format;
121 wxDC *cdc =
new wxScreenDC();
122 int cpx = 0, cpy = 0;
123 GetParent()->ClientToScreen(&cpx, &cpy);
124 mdc.Blit(0, 0, m_size.x, m_size.y, cdc, m_position.x + cpx,
136 text = _(
"AISRollover");
139 text = _(
"TideCurrentGraphRollover"), radius = 0;
143 text = _(
"RouteLegInfoRollover");
148 AlphaBlending(dc, 0, 0, m_size.x, m_size.y, radius,
149 GetGlobalColor(_T (
"YELO1" )), 172);
151 mdc.SetTextForeground(FontMgr::Get().GetFontColor(text));
154 mdc.SetTextForeground(wxColour(0, 0, 0));
157 if (m_plabelFont && m_plabelFont->IsOk()) {
159 mdc.SetFont(*m_plabelFont);
161 mdc.DrawLabel(m_string, wxRect(0, 0, m_size.x, m_size.y),
162 wxALIGN_CENTRE_HORIZONTAL | wxALIGN_CENTRE_VERTICAL);
165 mdc.SelectObject(wxNullBitmap);
167 SetSize(m_position.x, m_position.y, m_size.x, m_size.y);
172 glGenTextures(1, &m_texture);
174 glBindTexture(g_texture_rectangle_format, m_texture);
175 glTexParameterf(g_texture_rectangle_format, GL_TEXTURE_MIN_FILTER,
177 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_MAG_FILTER,
179 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_S,
181 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_T,
185 glBindTexture(g_texture_rectangle_format, 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;
263 auto pCanvas =
dynamic_cast<ChartCanvas *
>(GetParent());
265 pCanvas->GetglCanvas()->RenderTextures(dc, coords, uv, 4,
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);
279 dc.DrawBitmap(bmp, m_position.x, m_position.y,
false);
281 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
283 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
285 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
290 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
294void RolloverWin::SetBestPosition(
int x,
int y,
int off_x,
int off_y,
295 int rollover, wxSize parent_size) {
301 dFont = FontMgr::Get().
GetFont(_(
"AISRollover"));
305 dFont = FontMgr::Get().
GetFont(_(
"TideCurrentGraphRollover"));
310 dFont = FontMgr::Get().
GetFont(_(
"RouteLegInfoRollover"));
315 wxMax(8 * g_current_monitor_dip_px_ratio, dFont->GetPointSize());
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");
340 m_size.x = w + sizeM.x;
341 m_size.y = h + sizeM.y;
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));
ChartCanvas - Main chart display and interaction component.
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.
double OCPN_GetWinDIPScaleFactor()
Gets Windows-specific DPI scaling factor.