Projects
Multimedia
dvswitch-git
movable_selection.diff
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File movable_selection.diff of Package dvswitch-git
--- src/dv_display_widget.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++--- src/dv_display_widget.hpp | 7 ++++- 2 files changed, 60 insertions(+), 4 deletions(-) Index: dvswitch-0.9-1-da15ba4/src/dv_display_widget.cpp =================================================================== --- dvswitch-0.9-1-da15ba4.orig/src/dv_display_widget.cpp +++ dvswitch-0.9-1-da15ba4/src/dv_display_widget.cpp @@ -590,11 +590,41 @@ void dv_full_display_widget::window_to_f div_round_nearest<int>(window_y * (source_region_.bottom - source_region_.top), dest_height_)); } -void dv_full_display_widget::update_selection(int x2, int y2) +bool dv_full_display_widget::is_inside_selection(int x, int y) +{ + if (x < selection_.left || x > selection_.right) return false; + if (y < selection_.top || y > selection_.bottom) return false; + return true; +} + +void dv_full_display_widget::update_selection_move(int x2, int y2) +{ + if (source_region_.empty()) + return; + + int dx, dy; + dx = x2 - sel_start_x_; sel_start_x_ = x2; + dy = y2 - sel_start_y_; sel_start_y_ = y2; + + // constrain movement within source_region + if (selection_.left + dx < source_region_.left) dx = source_region_.left - selection_.left; + if (selection_.top + dy < source_region_.top) dy = source_region_.top - selection_.top; + if (selection_.right + dx > source_region_.right) dx = source_region_.right - selection_.right; + if (selection_.bottom + dy > source_region_.bottom) dy = source_region_.bottom- selection_.bottom; + + selection_.left += dx; + selection_.right += dx; + selection_.top += dy; + selection_.bottom += dy; + queue_draw(); // jw@suse.de: this eats CPU. FIXME: do it only if no more drag events follow +} + + +void dv_full_display_widget::update_selection_redraw(int x2, int y2) { if (source_region_.empty()) return; int frame_width = source_region_.right - source_region_.left; @@ -658,11 +688,27 @@ bool dv_full_display_widget::on_button_p if (event->button == 1) { sel_start_x_ = x; sel_start_y_ = y; } - update_selection(x, y); + // jw@suse.de: we now decide redraw or move mode. + // If we click inside the existing selection, change to a closed-hand cursor, + // and go into move mode, until we get a button_release_event + if (is_inside_selection(x, y)) + { + sel_in_progress_mode_ = SEL_IN_PROGRESS_MODE_MOVE; + Glib::RefPtr<Gdk::Window> window(get_window()); + window->set_cursor(Gdk::Cursor(Gdk::FLEUR)); + sel_start_x_ = x; + sel_start_y_ = y; + update_selection_move(x, y); + } + else + { + sel_in_progress_mode_ = SEL_IN_PROGRESS_MODE_REDRAW; + update_selection_redraw(x, y); + } return true; } return false; } @@ -670,10 +716,12 @@ bool dv_full_display_widget::on_button_p bool dv_full_display_widget::on_button_release_event(GdkEventButton * event) throw() { if (sel_in_progress_ && (event->button == 1 || event->button == 2)) { + Glib::RefPtr<Gdk::Window> window(get_window()); + window->set_cursor(Gdk::Cursor(Gdk::CROSSHAIR)); sel_in_progress_ = false; remove_modal_grab(); return true; } @@ -683,11 +731,14 @@ bool dv_full_display_widget::on_button_r bool dv_full_display_widget::on_motion_notify_event(GdkEventMotion * event) throw() { int x, y; window_to_frame_coords(x, y, int(event->x), int(event->y)); - update_selection(x, y); + if (sel_in_progress_mode_ == SEL_IN_PROGRESS_MODE_REDRAW) + update_selection_redraw(x, y); + else // if (sel_in_progress_mode_ == SEL_IN_PROGRESS_MODE_MOVE) + update_selection_move(x, y); return true; } bool dv_full_display_widget::on_expose_event(GdkEventExpose *) throw() { Index: dvswitch-0.9-1-da15ba4/src/dv_display_widget.hpp =================================================================== --- dvswitch-0.9-1-da15ba4.orig/src/dv_display_widget.hpp +++ dvswitch-0.9-1-da15ba4/src/dv_display_widget.hpp @@ -73,11 +73,13 @@ private: bool try_init_xvideo(PixelFormat pix_fmt, unsigned height) throw(); void fini_xvideo() throw(); void window_to_frame_coords(int & frame_x, int & frame_y, int window_x, int window_y) throw(); - void update_selection(int x, int y); + void update_selection_redraw(int x, int y); // jw@suse.de: renamed from update_selection() + void update_selection_move(int x, int y); // jw@suse.de: variant of update_selection(). + bool is_inside_selection(int x, int y); virtual AVFrame * get_frame_header(); virtual AVFrame * get_frame_buffer(AVFrame * header, PixelFormat pix_fmt, unsigned height); virtual void put_frame_buffer(const display_region &); @@ -96,10 +98,13 @@ private: AVFrame frame_header_; display_region source_region_; unsigned dest_width_, dest_height_; bool sel_enabled_; bool sel_in_progress_; + bool sel_in_progress_mode_; +#define SEL_IN_PROGRESS_MODE_REDRAW 0 // traditional redraw from scratch +#define SEL_IN_PROGRESS_MODE_MOVE 1 // drag the selection around, size unchanged bool highlight_title_safe_area_; int sel_start_x_, sel_start_y_; rectangle selection_; };
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.