#7785 - 3D view tooltip position as a function of mouse cursor size on Windows
This commit is contained in:
parent
7d45da065a
commit
12763c0a53
@ -817,9 +817,42 @@ void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position, GLCanvas3D& canvas
|
||||
static ImVec2 size(0.0f, 0.0f);
|
||||
|
||||
auto validate_position = [](const Vec2d& position, const GLCanvas3D& canvas, const ImVec2& wnd_size) {
|
||||
auto calc_cursor_height = []() {
|
||||
float ret = 16.0f;
|
||||
#ifdef _WIN32
|
||||
// see: https://forums.codeguru.com/showthread.php?449040-get-the-system-current-cursor-size
|
||||
// this code is not perfect because it returns a maximum height equal to 31 even if the cursor bitmap shown on screen is bigger
|
||||
// but at least it gives the same result as wxWidgets in the settings tabs
|
||||
ICONINFO ii;
|
||||
if (::GetIconInfo((HICON)GetCursor(), &ii) != 0) {
|
||||
BITMAP bitmap;
|
||||
::GetObject(ii.hbmMask, sizeof(BITMAP), &bitmap);
|
||||
int width = bitmap.bmWidth;
|
||||
int height = (ii.hbmColor == nullptr) ? bitmap.bmHeight / 2 : bitmap.bmHeight;
|
||||
HDC dc = ::CreateCompatibleDC(nullptr);
|
||||
if (dc != nullptr) {
|
||||
if (::SelectObject(dc, ii.hbmMask) != nullptr) {
|
||||
for (int i = 0; i < width; ++i) {
|
||||
for (int j = 0; j < height; ++j) {
|
||||
if (::GetPixel(dc, i, j) != RGB(255, 255, 255)) {
|
||||
if (ret < float(j))
|
||||
ret = float(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
::DeleteDC(dc);
|
||||
}
|
||||
}
|
||||
::DeleteObject(ii.hbmColor);
|
||||
::DeleteObject(ii.hbmMask);
|
||||
}
|
||||
#endif // _WIN32
|
||||
return ret;
|
||||
};
|
||||
|
||||
const Size cnv_size = canvas.get_canvas_size();
|
||||
const float x = std::clamp((float)position.x(), 0.0f, (float)cnv_size.get_width() - wnd_size.x);
|
||||
const float y = std::clamp((float)position.y() + 16.0f, 0.0f, (float)cnv_size.get_height() - wnd_size.y);
|
||||
const float x = std::clamp(float(position.x()), 0.0f, float(cnv_size.get_width()) - wnd_size.x);
|
||||
const float y = std::clamp(float(position.y()) + calc_cursor_height(), 0.0f, float(cnv_size.get_height()) - wnd_size.y);
|
||||
return Vec2f(x, y);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user