OpenCPN Partial API docs
Loading...
Searching...
No Matches
tooltip.h
1/***************************************************************************
2 * Copyright (C) 2025 by OpenCPN developer team *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 **************************************************************************/
19
20#ifndef _TOOLTIP_H__
21#define _TOOLTIP_H__
22
23#include <functional>
24
25#include <wx/frame.h>
26#include <wx/timer.h>
27#include <wx/bitmap.h>
28#include "color_types.h"
29
30class Tooltip; // forward
31using TooltipCallback = std::function<void(const Tooltip *)>;
32
39class Tooltip : public wxFrame {
40public:
41 Tooltip(wxWindow *parent, TooltipCallback on_destroy);
42 ~Tooltip();
43
45 void SetString(const wxString &text);
59 void SetRelativePosition(const wxRect &windowRect, int offsetX = 2,
60 int offsetY = 0);
62 void SetHiviz(bool hiviz);
64 void SetColorScheme(ColorScheme cs);
65
72 void SetAbsolutePosition(const wxPoint &pt);
73
75 void SetBitmap();
77 wxSize GetRenderedSize() const;
78
87 void ShowTooltip(int delay_ms = 0);
89 void HideTooltip();
90
91 bool Destroy() override;
92
93 // Event handlers
94 void OnPaint(wxPaintEvent &event);
95 void OnTimer(wxTimerEvent &event);
96
97private:
98 void CreateBitmap();
99 void CalculateOptimalPosition();
100
101 wxString m_string;
102 wxSize m_size;
105 wxPoint m_position;
108 wxPoint m_requestedPosition;
109 wxBitmap *m_pbm;
110 wxColour m_back_color;
111 wxColour m_text_color;
112 ColorScheme m_cs;
113 bool m_hiviz;
114
115 wxTimer m_showTimer;
116 bool m_showPending;
117 TooltipCallback m_on_destroy;
118
119 DECLARE_EVENT_TABLE()
120};
121
141public:
143 static TooltipManager &Get();
144
156 void ShowTooltipForWindow(wxWindow *window, const wxString &text,
157 bool hiviz = false);
171 void ShowTooltipAtPosition(wxWindow *parent, const wxString &text,
172 const wxPoint &position, bool hiviz = false);
173
175 void HideTooltip();
177 void HideAllTooltips();
179 void SetColorScheme(ColorScheme cs);
181 void EnableTooltips(bool enable);
183 bool AreTooltipsEnabled() const { return m_enabled; }
184
186 bool IsShown() const;
187
189 void SetShowDelay(int ms) { m_showDelay = ms; }
191 void SetHideDelay(int ms) { m_hideDelay = ms; }
192
193private:
196
197 Tooltip *GetOrCreateTooltip(wxWindow *parent);
198 void CleanupTooltip();
199
200 Tooltip *m_currentTooltip;
201 wxWindow *m_currentParent;
202 ColorScheme m_colorScheme;
203 bool m_enabled;
204 int m_showDelay;
205 int m_hideDelay;
206
207 // Singleton instance
208 static TooltipManager *s_instance;
209};
210
211#endif // _TOOLTIP_H__
Coordinates tooltip display across OpenCPN components.
Definition tooltip.h:140
void SetColorScheme(ColorScheme cs)
Set color scheme for all tooltips.
Definition tooltip.cpp:373
void ShowTooltipForWindow(wxWindow *window, const wxString &text, bool hiviz=false)
Show tooltip for a window using automatic positioning relative to the window.
Definition tooltip.cpp:338
bool IsShown() const
Check if a tooltip is currently shown.
Definition tooltip.cpp:387
void HideAllTooltips()
Hide all tooltips.
Definition tooltip.cpp:368
static TooltipManager & Get()
Get the singleton instance.
Definition tooltip.cpp:308
bool AreTooltipsEnabled() const
Check if tooltips are enabled.
Definition tooltip.h:183
void HideTooltip()
Hide the current tooltip.
Definition tooltip.cpp:362
void SetHideDelay(int ms)
Set delay before hiding tooltips.
Definition tooltip.h:191
void SetShowDelay(int ms)
Set delay before showing tooltips.
Definition tooltip.h:189
void ShowTooltipAtPosition(wxWindow *parent, const wxString &text, const wxPoint &position, bool hiviz=false)
Show tooltip at specified position in absolute screen coordinates (physical pixels).
Definition tooltip.cpp:315
void EnableTooltips(bool enable)
Enable or disable tooltip system.
Definition tooltip.cpp:380
Tooltip with color scheme support and high-visibility mode.
Definition tooltip.h:39
void HideTooltip()
Hide the tooltip immediately.
Definition tooltip.cpp:260
void SetRelativePosition(const wxRect &windowRect, int offsetX=2, int offsetY=0)
Position tooltip relative to a window rectangle with automatic screen boundary detection.
Definition tooltip.cpp:88
void SetAbsolutePosition(const wxPoint &pt)
Set the tooltip position in absolute screen coordinates (physical pixels).
Definition tooltip.cpp:74
void SetHiviz(bool hiviz)
Enable/disable high visibility mode.
Definition tooltip.cpp:79
void SetColorScheme(ColorScheme cs)
Set the color scheme for tooltip appearance.
Definition tooltip.cpp:81
void SetBitmap()
Create the tooltip bitmap.
Definition tooltip.cpp:217
void SetString(const wxString &text)
Set the tooltip text to display.
Definition tooltip.cpp:72
wxSize GetRenderedSize() const
Get the rendered size of the tooltip.
Definition tooltip.cpp:141
void ShowTooltip(int delay_ms=0)
Show the tooltip with optional delay in milliseconds.
Definition tooltip.cpp:245