Enhance inspector window with scrolling and pinning

- 2D scrolling during 1:1 view (tested with mac trackpad)
- click to pin inspector window
- another click or ESC to hide inspector window
- 'z' or 'F' to switch to 1:1 view, 'f' to switch to scaled view
This commit is contained in:
rfranke
2020-01-04 18:35:15 +01:00
parent c3c382e56e
commit 6604ab1b7c
2 changed files with 75 additions and 2 deletions

View File

@@ -82,12 +82,19 @@ InspectorBuffer::~InspectorBuffer() {
// return deg; // return deg;
//} //}
Inspector::Inspector () : currImage(nullptr), scaled(false), active(false) Inspector::Inspector () : currImage(nullptr), scaled(false), active(false), pinned(false)
{ {
set_name("Inspector"); set_name("Inspector");
window.set_visible(false); window.set_visible(false);
window.add_events(Gdk::KEY_PRESS_MASK); window.add_events(Gdk::KEY_PRESS_MASK);
window.add_events(Gdk::BUTTON_PRESS_MASK);
window.add_events(Gdk::SCROLL_MASK);
window.signal_key_release_event().connect(sigc::mem_fun(*this, &Inspector::on_key_release)); window.signal_key_release_event().connect(sigc::mem_fun(*this, &Inspector::on_key_release));
window.signal_button_press_event().connect(sigc::mem_fun(*this, &Inspector::on_button_press));
window.signal_key_press_event().connect(sigc::mem_fun(*this, &Inspector::on_key_press));
window.signal_scroll_event().connect(sigc::mem_fun(*this, &Inspector::on_scroll));
window.set_title("RawTherapee Inspector"); window.set_title("RawTherapee Inspector");
window.add(*this); window.add(*this);
window.show_all(); window.show_all();
@@ -105,11 +112,73 @@ void Inspector::showWindow(bool scaled)
this->scaled = scaled; this->scaled = scaled;
window.fullscreen(); window.fullscreen();
window.set_visible(true); window.set_visible(true);
pinned = false;
} }
bool Inspector::on_key_release(GdkEventKey *event) bool Inspector::on_key_release(GdkEventKey *event)
{ {
if (!pinned) {
switch (event->keyval) {
case GDK_KEY_f:
case GDK_KEY_F:
window.set_visible(false); window.set_visible(false);
return true;
}
}
return false;
}
bool Inspector::on_button_press(GdkEventButton *event)
{
if (event->type == GDK_BUTTON_PRESS) {
if (!pinned)
// pin window with mouse click
pinned = true;
else
// release window with another mouse click
window.set_visible(false);
return true;
}
return false;
}
bool Inspector::on_key_press(GdkEventKey *event)
{
switch (event->keyval) {
case GDK_KEY_z:
case GDK_KEY_F:
scaled = false;
queue_draw();
return true;
case GDK_KEY_f:
scaled = true;
queue_draw();
return true;
case GDK_KEY_Escape:
window.set_visible(false);
return true;
}
return false;
}
bool Inspector::on_scroll(GdkEventScroll *event)
{
if (!currImage)
return false;
rtengine::Coord margin; // limit for scroll area
int deviceScale = get_scale_factor();
int imW = currImage->imgBuffer.getWidth();
int imH = currImage->imgBuffer.getHeight();
margin.x = (window.get_width() * deviceScale) / 2;
margin.y = (window.get_height() * deviceScale) / 2;
int new_x = rtengine::min<int>(center.x + event->delta_x * deviceScale, imW - margin.x);
int new_y = rtengine::min<int>(center.y + event->delta_y * deviceScale, imH - margin.y);
center.set(rtengine::max<int>(margin.x, new_x), rtengine::max<int>(margin.y, new_y));
queue_draw();
return true; return true;
} }

View File

@@ -49,12 +49,16 @@ private:
InspectorBuffer* currImage; InspectorBuffer* currImage;
bool scaled; bool scaled;
bool active; bool active;
bool pinned;
sigc::connection delayconn; sigc::connection delayconn;
Glib::ustring next_image_path; Glib::ustring next_image_path;
Gtk::Window window; Gtk::Window window;
bool on_key_release(GdkEventKey *event); bool on_key_release(GdkEventKey *event);
bool on_button_press(GdkEventButton *event);
bool on_key_press(GdkEventKey *event);
bool on_scroll(GdkEventScroll *event);
bool on_draw(const ::Cairo::RefPtr< Cairo::Context> &cr) override; bool on_draw(const ::Cairo::RefPtr< Cairo::Context> &cr) override;
void deleteBuffers(); void deleteBuffers();