29#include <wx/dcmemory.h>
30#include <wx/dcscreen.h>
52extern GLenum g_texture_rectangle_format;
56EVT_PAINT(RolloverWin::OnPaint)
57EVT_TIMER(ROLLOVER_TIMER, RolloverWin::OnTimer)
58EVT_MOUSE_EVENTS(RolloverWin::OnMouseEvent)
64 : wxWindow(parent, wxID_ANY, wxPoint(0, 0), wxSize(1, 1), wxNO_BORDER),
65 m_bmaincanvas(maincanvas) {
68 m_timer_timeout.SetOwner(
this, ROLLOVER_TIMER);
69 m_timeout_sec = timeout;
70 m_mmouse_propogate = 0;
77RolloverWin::~RolloverWin() {
80 if (g_bopengl) glDeleteTextures(1, &m_texture);
83void RolloverWin::OnTimer(wxTimerEvent &event) {
86 GetParent()->Refresh(
true);
91void RolloverWin::OnMouseEvent(wxMouseEvent &event) {
94 if (m_mmouse_propogate) {
95 event.ResumePropagation(m_mmouse_propogate);
100void RolloverWin::SetBitmap(
int rollover) {
103 m_pbm =
new wxBitmap(m_size.x, m_size.y);
104 mdc.SelectObject(*m_pbm);
106 mdc.SetBackground(wxBrush(GetGlobalColor(
"YELO1")));
109 bool usegl = g_bopengl && g_texture_rectangle_format;
116 wxDC *cdc =
new wxScreenDC();
117 int cpx = 0, cpy = 0;
118 GetParent()->ClientToScreen(&cpx, &cpy);
119 mdc.Blit(0, 0, m_size.x, m_size.y, cdc, m_position.x + cpx,
131 text = _(
"AISRollover");
134 text = _(
"TideCurrentGraphRollover"), radius = 0;
138 text = _(
"RouteLegInfoRollover");
143 AlphaBlending(dc, 0, 0, m_size.x, m_size.y, radius, GetGlobalColor(
"YELO1"),
146 mdc.SetTextForeground(FontMgr::Get().GetFontColor(text));
149 mdc.SetTextForeground(wxColour(0, 0, 0));
152 if (m_plabelFont && m_plabelFont->IsOk()) {
154 mdc.SetFont(*m_plabelFont);
156 mdc.DrawLabel(m_string, wxRect(0, 0, m_size.x, m_size.y),
157 wxALIGN_CENTRE_HORIZONTAL | wxALIGN_CENTRE_VERTICAL);
160 mdc.SelectObject(wxNullBitmap);
162 SetSize(m_position.x, m_position.y, m_size.x, m_size.y);
167 glGenTextures(1, &m_texture);
169 glBindTexture(g_texture_rectangle_format, m_texture);
170 glTexParameterf(g_texture_rectangle_format, GL_TEXTURE_MIN_FILTER,
172 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_MAG_FILTER,
174 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_S,
176 glTexParameteri(g_texture_rectangle_format, GL_TEXTURE_WRAP_T,
180 glBindTexture(g_texture_rectangle_format, m_texture);
183 wxImage image = m_pbm->ConvertToImage();
185 unsigned char *d = image.GetData();
186 unsigned char *e =
new unsigned char[4 * m_size.x * m_size.y];
187 for (
int y = 0; y < m_size.y; y++)
188 for (
int x = 0; x < m_size.x; x++) {
189 int i = y * m_size.x + x;
190 memcpy(e + 4 * i, d + 3 * i, 3);
191 e[4 * i + 3] = 255 - d[3 * i + 2];
193 glTexImage2D(g_texture_rectangle_format, 0, GL_RGBA, m_size.x, m_size.y, 0,
194 GL_RGBA, GL_UNSIGNED_BYTE, e);
196 glDisable(g_texture_rectangle_format);
202 if (m_timeout_sec > 0) {
203 m_timer_timeout.Start(m_timeout_sec * 1000, wxTIMER_ONE_SHOT);
207void RolloverWin::OnPaint(wxPaintEvent &event) {
209 GetClientSize(&width, &height);
212 if (m_string.Len()) {
214 mdc.SelectObject(*m_pbm);
215 dc.Blit(0, 0, width, height, &mdc, 0, 0);
219void RolloverWin::Draw(
ocpnDC &dc) {
220 if (!IsActive())
return;
222 if (g_bopengl && m_texture) {
223 glEnable(g_texture_rectangle_format);
224 glBindTexture(g_texture_rectangle_format, m_texture);
227 int x0 = m_position.x, x1 = x0 + m_size.x;
228 int y0 = m_position.y, y1 = y0 + m_size.y;
230 if (GL_TEXTURE_RECTANGLE_ARB == g_texture_rectangle_format)
231 tx = m_size.x, ty = m_size.y;
258 auto pCanvas =
dynamic_cast<ChartCanvas *
>(GetParent());
260 pCanvas->GetglCanvas()->RenderTextures(dc, coords, uv, 4,
263 glDisable(g_texture_rectangle_format);
269 double scale = m_parent->GetContentScaleFactor();
271 wxImage image = m_pbm->ConvertToImage();
272 image.Rescale(image.GetWidth() *
scale, image.GetHeight() *
scale);
274 dc.DrawBitmap(bmp, m_position.x, m_position.y,
false);
276 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
278 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
280 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
285 dc.DrawBitmap(*m_pbm, m_position.x, m_position.y,
false);
289void RolloverWin::SetBestPosition(
int x,
int y,
int off_x,
int off_y,
290 int rollover, wxSize parent_size) {
296 dFont = FontMgr::Get().
GetFont(_(
"AISRollover"));
300 dFont = FontMgr::Get().
GetFont(_(
"TideCurrentGraphRollover"));
305 dFont = FontMgr::Get().
GetFont(_(
"RouteLegInfoRollover"));
314 font_size, dFont->GetFamily(), dFont->GetStyle(), dFont->GetWeight(),
315 false, dFont->GetFaceName());
318 if (m_plabelFont && m_plabelFont->IsOk()) {
321 sdc.SetFont(*m_plabelFont);
322 sdc.GetMultiLineTextExtent(m_string, &w, &h, NULL, m_plabelFont);
323 sizeM = sdc.GetTextExtent(
"M");
325 wxClientDC cdc(GetParent());
326 cdc.SetFont(*m_plabelFont);
327 cdc.GetMultiLineTextExtent(m_string, &w, &h, NULL, m_plabelFont);
328 sizeM = cdc.GetTextExtent(
"M");
335 m_size.x = w + sizeM.x;
336 m_size.y = h + sizeM.y;
342 if ((x + off_x + m_size.x) > parent_size.x) {
343 xp = x - (off_x / 2) - m_size.x;
348 if ((y + off_y + m_size.y) > parent_size.y) {
349 yp = y - (off_y / 2) - m_size.y;
353 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.