Small feature: hovering over an image will not just display the image parameters in the status bar, but also the value of the pixel the mouse is over

This commit is contained in:
Matthias Koefferlein 2026-04-05 22:18:39 +02:00
parent 60a210c264
commit d09734fe0d
4 changed files with 40 additions and 6 deletions

View File

@ -1295,7 +1295,6 @@ Object::box () const
// include landmarks
for (std::vector <db::DPoint>::const_iterator l = m_landmarks.begin (); l != m_landmarks.end (); ++l) {
b += m_trans * *l;
}

View File

@ -794,7 +794,7 @@ public:
/**
* @brief Set the transformation matrix
*
* This transformation matrix converts pixel coordinates (0,0 being the lower left corner and each pixel having the dimension of pixel_width and pixel_height)
* This transformation matrix converts pixel coordinates (0,0 being the center and each pixel having the dimension of pixel_width and pixel_height)
* to micron coordinates. The coordinate of the pixel is the lower left corner of the pixel.
*/
void set_matrix (const db::Matrix3d &trans);
@ -802,7 +802,7 @@ public:
/**
* @brief Return the pixel-to-micron transformation
*
* This transformation converts pixel coordinates (0,0 being the lower left corner and each pixel having the dimension of pixel_width and pixel_height)
* This transformation converts pixel coordinates (0,0 being the center and each pixel having the dimension of pixel_width and pixel_height)
* to micron coordinates. The coordinate of the pixel is the lower left corner of the pixel.
*/
const db::Matrix3d &matrix () const

View File

@ -1309,6 +1309,7 @@ Service::transient_select (const db::DPoint &pos)
clear_transient_selection ();
bool any_selected = false;
std::string data_string;
// compute search box
double l = catch_distance ();
@ -1336,12 +1337,41 @@ Service::transient_select (const db::DPoint &pos)
mp_transient_view = new img::View (this, imin, img::View::mode_transient);
}
if (mp_transient_view->image_object ()) {
const img::Object *image = mp_transient_view->image_object ();
db::DPoint pixel = image->matrix ().inverted ().trans (pos);
if (pixel.x () > image->width () * -0.5 - 0.5 + db::epsilon && pixel.x () < image->width () * 0.5 + 0.5 - db::epsilon &&
pixel.y () > image->height () * -0.5 - 0.5 + db::epsilon && pixel.y () < image->height () * 0.5 + 0.5 - db::epsilon) {
db::Point pixel_index = db::Point (pixel + db::DVector (image->width () * 0.5 - 0.5, image->height () * 0.5 - 0.5));
// check once again to account to rounding issues
if (pixel_index.x () >= 0 && pixel_index.x () < image->width () &&
pixel_index.y () >= 0 && pixel_index.y () < image->height ()) {
if (image->is_color ()) {
data_string = tl::sprintf ("RGB: %.5g,%.5g,%.5g",
image->pixel (pixel_index.x (), pixel_index.y (), 0),
image->pixel (pixel_index.x (), pixel_index.y (), 1),
image->pixel (pixel_index.x (), pixel_index.y (), 2));
} else {
data_string = tl::sprintf ("%.5g", image->pixel (pixel_index.x (), pixel_index.y ()));
}
}
}
}
any_selected = true;
}
if (any_selected && ! editables ()->has_selection ()) {
display_status (true);
display_status (true, data_string);
}
return any_selected;
@ -1464,11 +1494,13 @@ Service::select (const db::DBox &box, lay::Editable::SelectionMode mode)
}
void
Service::display_status (bool transient)
Service::display_status (bool transient, const std::string &data_string)
{
View *selected_view = transient ? mp_transient_view : (m_selected_image_views.size () == 1 ? m_selected_image_views [0] : 0);
if (! selected_view) {
view ()->message (std::string ());
} else {
const img::Object *image = selected_view->image_object ();
@ -1478,6 +1510,9 @@ Service::display_status (bool transient)
msg = tl::to_string (tr ("selected: "));
}
msg += tl::sprintf (tl::to_string (tr ("image(%dx%d)")), image->width (), image->height ());
if (! data_string.empty ()) {
msg += " [" + data_string + "]";
}
view ()->message (msg);
}

View File

@ -586,7 +586,7 @@ private:
/**
* @brief Display a message about the current selection
*/
void display_status (bool transient);
void display_status (bool transient, const std::string &data_string = std::string ());
/**
* @brief Gets a value indicating the (new) top z position