diff options
author | Werner Almesberger <werner@almesberger.net> | 2016-11-20 13:11:08 -0300 |
---|---|---|
committer | Werner Almesberger <werner@almesberger.net> | 2016-11-20 13:11:08 -0300 |
commit | 4881285222a520254a25e17c6748f638ffc2782d (patch) | |
tree | af4a64d448de0c9bfbe9ba1ded36cea520ef81bc | |
parent | e90e81202b07f9bf036018e95d7cd1af6a7288ee (diff) | |
download | eeshow-4881285222a520254a25e17c6748f638ffc2782d.tar.gz eeshow-4881285222a520254a25e17c6748f638ffc2782d.tar.bz2 eeshow-4881285222a520254a25e17c6748f638ffc2782d.zip |
gui/gui.c (current_sheet): de-duplicate sheet selection logic
-rw-r--r-- | gui/common.h | 1 | ||||
-rw-r--r-- | gui/gui.c | 9 | ||||
-rw-r--r-- | gui/sheet.c | 18 |
3 files changed, 13 insertions, 15 deletions
diff --git a/gui/common.h b/gui/common.h index efcd1c6..712469c 100644 --- a/gui/common.h +++ b/gui/common.h @@ -194,6 +194,7 @@ void show_index(struct gui *gui); struct gui_sheet *find_corresponding_sheet(struct gui_sheet *pick_from, struct gui_sheet *ref_in, const struct gui_sheet *ref); +struct gui_sheet *current_sheet(const struct gui *gui); void mark_aois(struct gui *gui, struct gui_sheet *sheet); #endif /* !GUI_COMMON_H */ @@ -74,6 +74,15 @@ struct gui_sheet *find_corresponding_sheet(struct gui_sheet *pick_from, } +struct gui_sheet *current_sheet(const struct gui *gui) +{ + if (!gui->old_hist || gui->diff_mode != diff_old) + return gui->curr_sheet; + return find_corresponding_sheet(gui->old_hist->sheets, + gui->new_hist->sheets, gui->curr_sheet); +} + + /* ----- AoIs -------------------------------------------------------------- */ diff --git a/gui/sheet.c b/gui/sheet.c index 8b66bf9..6131163 100644 --- a/gui/sheet.c +++ b/gui/sheet.c @@ -419,17 +419,13 @@ static bool go_next_sheet(struct gui *gui) static bool sheet_click(void *user, int x, int y) { struct gui *gui = user; - const struct gui_sheet *curr_sheet = gui->curr_sheet; + const struct gui_sheet *curr_sheet = current_sheet(gui); int ex, ey; canvas_coord(gui, x, y, &ex, &ey); ex += curr_sheet->xmin; ey += curr_sheet->ymin; - if (gui->old_hist && gui->diff_mode == diff_old) - curr_sheet = find_corresponding_sheet(gui->old_hist->sheets, - gui->new_hist->sheets, gui->curr_sheet); - if (aoi_click(&gui->aois, x, y)) return 1; if (aoi_click(&curr_sheet->aois, ex, ey)) @@ -449,15 +445,11 @@ static bool sheet_click(void *user, int x, int y) static bool sheet_hover_update(void *user, int x, int y) { struct gui *gui = user; - const struct gui_sheet *curr_sheet = gui->curr_sheet; + const struct gui_sheet *curr_sheet = current_sheet(gui); int ex, ey; canvas_coord(gui, x, y, &ex, &ey); - if (gui->old_hist && gui->diff_mode == diff_old) - curr_sheet = find_corresponding_sheet(gui->old_hist->sheets, - gui->new_hist->sheets, gui->curr_sheet); - if (aoi_hover(&gui->aois, x, y)) return 1; return aoi_hover(&curr_sheet->aois, @@ -468,7 +460,7 @@ static bool sheet_hover_update(void *user, int x, int y) static bool sheet_drag_begin(void *user, int x, int y) { struct gui *gui = user; - const struct gui_sheet *curr_sheet = gui->curr_sheet; + const struct gui_sheet *curr_sheet = current_sheet(gui); int ex, ey; struct record_bbox rec_bbox; @@ -478,10 +470,6 @@ static bool sheet_drag_begin(void *user, int x, int y) ex += curr_sheet->xmin; ey += curr_sheet->ymin; - if (gui->old_hist && gui->diff_mode == diff_old) - curr_sheet = find_corresponding_sheet(gui->old_hist->sheets, - gui->new_hist->sheets, gui->curr_sheet); - gui->drag_text = record_find_text_bbox(gfx_user(curr_sheet->gfx), show_extra, ex, ey, &rec_bbox); if (gui->drag_text) { |