28#include <wx/dcmemory.h>
29#include <wx/dcscreen.h>
32#if defined(__OCPN__ANDROID__)
34#elif defined(__WXQT__) || defined(__WXGTK__)
42#include "RolloverWin.h"
48#include "ocpn_frame.h"
49#include "OCPNPlatform.h"
58extern GLenum g_texture_rectangle_format;
63EVT_PAINT(RolloverWin::OnPaint)
64EVT_TIMER(ROLLOVER_TIMER, RolloverWin::OnTimer)
65EVT_MOUSE_EVENTS(RolloverWin::OnMouseEvent)
71 : wxWindow(parent, wxID_ANY, wxPoint(0, 0), wxSize(1, 1), wxNO_BORDER),
72 m_bmaincanvas(maincanvas) {
75 m_timer_timeout.SetOwner(
this, ROLLOVER_TIMER);
76 m_timeout_sec = timeout;
77 m_mmouse_propogate = 0;
84RolloverWin::~RolloverWin() {
87 if (g_bopengl) glDeleteTextures(1, &m_texture);
90void RolloverWin::OnTimer(wxTimerEvent &event) {
93 GetParent()->Refresh(
true);
98void RolloverWin::OnMouseEvent(wxMouseEvent &event) {
101 if (m_mmouse_propogate) {
102 event.ResumePropagation(m_mmouse_propogate);
107void RolloverWin::SetBitmap(
int rollover) {
110 m_pbm =
new wxBitmap(m_size.x, m_size.y);
111 mdc.SelectObject(*m_pbm);
113 mdc.SetBackground(wxBrush(GetGlobalColor(_T (
"YELO1" ))));
116 bool usegl = g_bopengl && g_texture_rectangle_format;
123 wxDC *cdc =
new wxScreenDC();
124 int cpx = 0, cpy = 0;
125 GetParent()->ClientToScreen(&cpx, &cpy);
126 mdc.Blit(0, 0, m_size.x, m_size.y, cdc, m_position.x + cpx,
138 text = _(
"AISRollover");
141 text = _(
"TideCurrentGraphRollover"), radius = 0;
145 text = _(
"RouteLegInfoRollover");
150 AlphaBlending(dc, 0, 0, m_size.x, m_size.y, radius,
151 GetGlobalColor(_T (
"YELO1" )), 172);
153 mdc.SetTextForeground(FontMgr::Get().GetFontColor(text));
156 mdc.SetTextForeground(wxColour(0, 0, 0));
159 if (m_plabelFont && m_plabelFont->IsOk()) {
161 mdc.SetFont(*m_plabelFont);
163 mdc.DrawLabel(m_string, wxRect(0, 0, m_size.x, m_size.y),
164 wxALIGN_CENTRE_HORIZONTAL | wxALIGN_CENTRE_VERTICAL);
167 mdc.SelectObject(wxNullBitmap);
169 SetSize(m_position.x, m_position.y, m_size.x, m_size.y);
174 glGenTextures(1, &m_texture);
176 glBindTexture(g_texture_rectangle_format, m_texture);
177 glTexParameterf(g_texture_rectangle_format, GL_TEXTURE_MIN_FILTER,
179 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_MAG_FILTER,
181 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_S,
183 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_T,
187 glBindTexture(g_texture_rectangle_format, m_texture);
190 wxImage image = m_pbm->ConvertToImage();
192 unsigned char *d = image.GetData();
193 unsigned char *e =
new unsigned char[4 * m_size.x * m_size.y];
194 for (
int y = 0; y < m_size.y; y++)
195 for (
int x = 0; x < m_size.x; x++) {
196 int i = y * m_size.x + x;
197 memcpy(e + 4 * i, d + 3 * i, 3);
198 e[4 * i + 3] = 255 - d[3 * i + 2];
200 glTexImage2D(g_texture_rectangle_format, 0, GL_RGBA, m_size.x, m_size.y, 0,
201 GL_RGBA, GL_UNSIGNED_BYTE, e);
203 glDisable(g_texture_rectangle_format);
209 if (m_timeout_sec > 0) {
210 m_timer_timeout.Start(m_timeout_sec * 1000, wxTIMER_ONE_SHOT);
214void RolloverWin::OnPaint(wxPaintEvent &event) {
216 GetClientSize(&width, &height);
219 if (m_string.Len()) {
221 mdc.SelectObject(*m_pbm);
222 dc.Blit(0, 0, width, height, &mdc, 0, 0);
226void RolloverWin::Draw(
ocpnDC &dc) {
227 if (!IsActive())
return;
229 if (g_bopengl && m_texture) {
230 glEnable(g_texture_rectangle_format);
231 glBindTexture(g_texture_rectangle_format, m_texture);
234 int x0 = m_position.x, x1 = x0 + m_size.x;
235 int y0 = m_position.y, y1 = y0 + m_size.y;
237 if (GL_TEXTURE_RECTANGLE_ARB == g_texture_rectangle_format)
238 tx = m_size.x, ty = m_size.y;
265 auto pCanvas =
dynamic_cast<ChartCanvas *
>(GetParent());
267 pCanvas->GetglCanvas()->RenderTextures(dc, coords, uv, 4,
270 glDisable(g_texture_rectangle_format);
276 double scale = m_parent->GetContentScaleFactor();
278 wxImage image = m_pbm->ConvertToImage();
279 image.Rescale(image.GetWidth() *
scale, image.GetHeight() *
scale);
281 dc.DrawBitmap(bmp, 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);
287 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
292 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
296void 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"));
321 font_size, dFont->GetFamily(), dFont->GetStyle(), dFont->GetWeight(),
322 false, dFont->GetFaceName());
325 if (m_plabelFont && m_plabelFont->IsOk()) {
328 sdc.SetFont(*m_plabelFont);
329 sdc.GetMultiLineTextExtent(m_string, &w, &h, NULL, m_plabelFont);
330 sizeM = sdc.GetTextExtent(
"M");
332 wxClientDC cdc(GetParent());
333 cdc.SetFont(*m_plabelFont);
334 cdc.GetMultiLineTextExtent(m_string, &w, &h, NULL, m_plabelFont);
335 sizeM = cdc.GetTextExtent(
"M");
342 m_size.x = w + sizeM.x;
343 m_size.y = h + sizeM.y;
349 if ((x + off_x + m_size.x) > parent_size.x) {
350 xp = x - (off_x / 2) - m_size.x;
355 if ((y + off_y + m_size.y) > parent_size.y) {
356 yp = y - (off_y / 2) - m_size.y;
360 SetPosition(wxPoint(xp, yp));
Generic Chart canvas base.
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)
Get a font object for a UI element.
Device context class that can use either wxDC or OpenGL for drawing.
Global color handling by name.
OpenGL chart rendering canvas.
double g_current_monitor_dip_px_ratio
ratio to convert between DIP and physical pixels.
Miscellaneous globals primarely used by gui layer.
PlugIn Object Definition/API.
double OCPN_GetWinDIPScaleFactor()
Gets Windows-specific DPI scaling factor.