29#include <wx/dcmemory.h>
30#include <wx/dcscreen.h>
51extern GLenum g_texture_rectangle_format;
55EVT_PAINT(RolloverWin::OnPaint)
56EVT_TIMER(ROLLOVER_TIMER, RolloverWin::OnTimer)
57EVT_MOUSE_EVENTS(RolloverWin::OnMouseEvent)
63 : wxWindow(parent, wxID_ANY, wxPoint(0, 0), wxSize(1, 1), wxNO_BORDER),
64 m_bmaincanvas(maincanvas) {
67 m_timer_timeout.SetOwner(
this, ROLLOVER_TIMER);
68 m_timeout_sec = timeout;
69 m_mmouse_propogate = 0;
76RolloverWin::~RolloverWin() {
79 if (g_bopengl) glDeleteTextures(1, &m_texture);
82void RolloverWin::OnTimer(wxTimerEvent &event) {
85 GetParent()->Refresh(
true);
90void RolloverWin::OnMouseEvent(wxMouseEvent &event) {
93 if (m_mmouse_propogate) {
94 event.ResumePropagation(m_mmouse_propogate);
99void RolloverWin::SetBitmap(
int rollover) {
102 m_pbm =
new wxBitmap(m_size.x, m_size.y);
103 mdc.SelectObject(*m_pbm);
105 mdc.SetBackground(wxBrush(GetGlobalColor(
"YELO1")));
108 bool usegl = g_bopengl && g_texture_rectangle_format;
115 wxDC *cdc =
new wxScreenDC();
116 int cpx = 0, cpy = 0;
117 GetParent()->ClientToScreen(&cpx, &cpy);
118 mdc.Blit(0, 0, m_size.x, m_size.y, cdc, m_position.x + cpx,
130 text = _(
"AISRollover");
133 text = _(
"TideCurrentGraphRollover"), radius = 0;
137 text = _(
"RouteLegInfoRollover");
142 AlphaBlending(dc, 0, 0, m_size.x, m_size.y, radius, GetGlobalColor(
"YELO1"),
145 mdc.SetTextForeground(FontMgr::Get().GetFontColor(text));
148 mdc.SetTextForeground(wxColour(0, 0, 0));
151 if (m_plabelFont && m_plabelFont->IsOk()) {
153 mdc.SetFont(*m_plabelFont);
155 mdc.DrawLabel(m_string, wxRect(0, 0, m_size.x, m_size.y),
156 wxALIGN_CENTRE_HORIZONTAL | wxALIGN_CENTRE_VERTICAL);
159 mdc.SelectObject(wxNullBitmap);
161 SetSize(m_position.x, m_position.y, m_size.x, m_size.y);
166 glGenTextures(1, &m_texture);
168 glBindTexture(g_texture_rectangle_format, m_texture);
169 glTexParameterf(g_texture_rectangle_format, GL_TEXTURE_MIN_FILTER,
171 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_MAG_FILTER,
173 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_S,
175 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_T,
179 glBindTexture(g_texture_rectangle_format, m_texture);
182 wxImage image = m_pbm->ConvertToImage();
184 unsigned char *d = image.GetData();
185 unsigned char *e =
new unsigned char[4 * m_size.x * m_size.y];
186 for (
int y = 0; y < m_size.y; y++)
187 for (
int x = 0; x < m_size.x; x++) {
188 int i = y * m_size.x + x;
189 memcpy(e + 4 * i, d + 3 * i, 3);
190 e[4 * i + 3] = 255 - d[3 * i + 2];
192 glTexImage2D(g_texture_rectangle_format, 0, GL_RGBA, m_size.x, m_size.y, 0,
193 GL_RGBA, GL_UNSIGNED_BYTE, e);
195 glDisable(g_texture_rectangle_format);
201 if (m_timeout_sec > 0) {
202 m_timer_timeout.Start(m_timeout_sec * 1000, wxTIMER_ONE_SHOT);
206void RolloverWin::OnPaint(wxPaintEvent &event) {
208 GetClientSize(&width, &height);
211 if (m_string.Len()) {
213 mdc.SelectObject(*m_pbm);
214 dc.Blit(0, 0, width, height, &mdc, 0, 0);
218void RolloverWin::Draw(
ocpnDC &dc) {
219 if (!IsActive())
return;
221 if (g_bopengl && m_texture) {
222 glEnable(g_texture_rectangle_format);
223 glBindTexture(g_texture_rectangle_format, m_texture);
226 int x0 = m_position.x, x1 = x0 + m_size.x;
227 int y0 = m_position.y, y1 = y0 + m_size.y;
229 if (GL_TEXTURE_RECTANGLE_ARB == g_texture_rectangle_format)
230 tx = m_size.x, ty = m_size.y;
257 auto pCanvas =
dynamic_cast<ChartCanvas *
>(GetParent());
259 pCanvas->GetglCanvas()->RenderTextures(dc, coords, uv, 4,
262 glDisable(g_texture_rectangle_format);
268 double scale = m_parent->GetContentScaleFactor();
270 wxImage image = m_pbm->ConvertToImage();
271 image.Rescale(image.GetWidth() *
scale, image.GetHeight() *
scale);
273 dc.DrawBitmap(bmp, m_position.x, m_position.y,
false);
275 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
277 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
279 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
284 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
288void RolloverWin::SetBestPosition(
int x,
int y,
int off_x,
int off_y,
289 int rollover, wxSize parent_size) {
295 dFont = FontMgr::Get().
GetFont(_(
"AISRollover"));
299 dFont = FontMgr::Get().
GetFont(_(
"TideCurrentGraphRollover"));
304 dFont = FontMgr::Get().
GetFont(_(
"RouteLegInfoRollover"));
313 font_size, dFont->GetFamily(), dFont->GetStyle(), dFont->GetWeight(),
314 false, dFont->GetFaceName());
317 if (m_plabelFont && m_plabelFont->IsOk()) {
320 sdc.SetFont(*m_plabelFont);
321 sdc.GetMultiLineTextExtent(m_string, &w, &h, NULL, m_plabelFont);
322 sizeM = sdc.GetTextExtent(
"M");
324 wxClientDC cdc(GetParent());
325 cdc.SetFont(*m_plabelFont);
326 cdc.GetMultiLineTextExtent(m_string, &w, &h, NULL, m_plabelFont);
327 sizeM = cdc.GetTextExtent(
"M");
334 m_size.x = w + sizeM.x;
335 m_size.y = h + sizeM.y;
341 if ((x + off_x + m_size.x) > parent_size.x) {
342 xp = x - (off_x / 2) - m_size.x;
347 if ((y + off_y + m_size.y) > parent_size.y) {
348 yp = y - (off_y / 2) - m_size.y;
352 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.
Global variables stored in configuration file.
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, not persisted in configuration file.
PlugIn Object Definition/API.
double OCPN_GetWinDIPScaleFactor()
Gets Windows-specific DPI scaling factor.
Layer to use wxDC or opengl.
Timer identification constants.