Skip to content

Commit aa78bd2

Browse files
committed
improve window duplicate
1 parent 46dff32 commit aa78bd2

File tree

5 files changed

+51
-24
lines changed

5 files changed

+51
-24
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ On success, merge to master.
230230

231231
## TODO
232232

233-
- duplicate could copy zoom/pan settings
234-
235233
- get `object_unref: assertion 'G_IS_OBJECT (object)' failed` during free of
236234
stack ... seems to be a harmless minor glib bug with `g_clear_object()`
237235
failing with a crit for a null value

src/imagedisplay.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ enum {
7777
PROP_VADJUSTMENT,
7878
PROP_VSCROLL_POLICY,
7979

80+
/* We need bestfit off for eg. suplicate.
81+
*/
82+
PROP_BESTFIT,
83+
8084
/* Control transform with this.
8185
*/
8286
PROP_BACKGROUND,
@@ -435,6 +439,10 @@ imagedisplay_set_property(GObject *object,
435439
g_value_get_object(value));
436440
break;
437441

442+
case PROP_BESTFIT:
443+
imagedisplay->bestfit = g_value_get_boolean(value);
444+
break;
445+
438446
case PROP_BACKGROUND:
439447
if (imagedisplay->tile_cache)
440448
g_object_set(imagedisplay->tile_cache,
@@ -505,6 +513,10 @@ imagedisplay_get_property(GObject *object,
505513
g_value_set_object(value, imagedisplay->tile_source);
506514
break;
507515

516+
case PROP_BESTFIT:
517+
g_value_set_boolean(value, imagedisplay->bestfit);
518+
break;
519+
508520
case PROP_BACKGROUND:
509521
if (imagedisplay->tile_cache)
510522
g_object_get_property(G_OBJECT(imagedisplay->tile_cache),
@@ -664,6 +676,13 @@ imagedisplay_class_init(ImagedisplayClass *class)
664676
TILE_SOURCE_TYPE,
665677
G_PARAM_READWRITE));
666678

679+
g_object_class_install_property(gobject_class, PROP_BESTFIT,
680+
g_param_spec_boolean("bestfit",
681+
_("Bestfit"),
682+
_("Shrink on first display"),
683+
FALSE,
684+
G_PARAM_READWRITE));
685+
667686
g_object_class_install_property(gobject_class, PROP_BACKGROUND,
668687
g_param_spec_int("background",
669688
_("Background"),

src/imageui.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,9 @@ imageui_tick(GtkWidget *widget, GdkFrameClock *frame_clock, gpointer user_data)
346346
double new_scale;
347347

348348
#ifdef DEBUG_VERBOSE
349+
// FIXME could display FPS from this?
350+
printf("imageui_tick: dt = %g\n", dt);
349351
#endif /*DEBUG_VERBOSE*/
350-
printf("image_window_tick: dt = %g\n", dt);
351352

352353
new_scale = scale;
353354

@@ -903,6 +904,29 @@ imageui_new(TileSource *tile_source)
903904
return imageui;
904905
}
905906

907+
Imageui *
908+
imageui_duplicate(TileSource *tile_source, Imageui *old_imageui)
909+
{
910+
Imageui *new_imageui = imageui_new(tile_source);
911+
912+
/* We want to copy position and scale, so no bestfit.
913+
*/
914+
g_object_set(new_imageui->imagedisplay,
915+
"bestfit", FALSE,
916+
NULL);
917+
918+
double scale = imageui_get_scale(old_imageui);
919+
imageui_set_scale(new_imageui, scale);
920+
921+
// this won't work until imagedisplay has had a layout :( think about this
922+
// again
923+
int left, top, width, height;
924+
imageui_get_position(old_imageui, &left, &top, &width, &height);
925+
imageui_set_position(new_imageui, left, top);
926+
927+
return new_imageui;
928+
}
929+
906930
void
907931
imageui_image_to_gtk(Imageui *imageui,
908932
double x_image, double y_image, double *x_gtk, double *y_gtk)
@@ -918,18 +942,3 @@ imageui_gtk_to_image(Imageui *imageui,
918942
imagedisplay_gtk_to_image(IMAGEDISPLAY(imageui->imagedisplay),
919943
x_gtk, y_gtk, x_image, y_image);
920944
}
921-
922-
void
923-
imageui_copy_position(Imageui *new, Imageui *old)
924-
{
925-
copy_adj(
926-
gtk_scrolled_window_get_hadjustment(
927-
GTK_SCROLLED_WINDOW(new->scrolled_window)),
928-
gtk_scrolled_window_get_hadjustment(
929-
GTK_SCROLLED_WINDOW(old->scrolled_window)));
930-
copy_adj(
931-
gtk_scrolled_window_get_vadjustment(
932-
GTK_SCROLLED_WINDOW(new->scrolled_window)),
933-
gtk_scrolled_window_get_vadjustment(
934-
GTK_SCROLLED_WINDOW(old->scrolled_window)));
935-
}

src/imageui.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
G_DECLARE_FINAL_TYPE(Imageui, imageui, VIPSDISP, IMAGEUI, GtkWidget)
1717

18-
Imageui *imageui_new(TileSource *tile_source);
1918
double imageui_get_scale(Imageui *imageui);
2019
TileSource *imageui_get_tile_source(Imageui *imageui);
2120
void imageui_get_mouse_position(Imageui *imageui,
@@ -27,10 +26,12 @@ void imageui_magout(Imageui *imageui);
2726
void imageui_oneone(Imageui *imageui);
2827
gboolean imageui_scale(Imageui *imageui);
2928

29+
Imageui *imageui_new(TileSource *tile_source);
30+
Imageui *imageui_duplicate(TileSource *tile_source, Imageui *old_imageui);
31+
3032
void imageui_image_to_gtk(Imageui *imageui,
3133
double x_image, double y_image, double *x_gtk, double *y_gtk);
3234
void imageui_gtk_to_image(Imageui *imageui,
3335
double x_gtk, double y_gtk, double *x_image, double *y_image);
34-
void imageui_copy_position(Imageui *new, Imageui *old);
3536

3637
#endif /* __IMAGEUI_H */

src/imagewindow.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,8 @@ image_window_open_current_file(ImageWindow *win,
658658
Active *active;
659659

660660
#ifdef DEBUG
661-
printf("image_window_open_current_file: %s:\n", filename);
662661
#endif /*DEBUG*/
662+
printf("image_window_open_current_file: %s:\n", filename);
663663

664664
/* An old image selected again?
665665
*/
@@ -990,10 +990,10 @@ image_window_duplicate_action(GSimpleAction *action,
990990
TileSource *tile_source = imageui_get_tile_source(win->imageui);
991991
g_autoptr(TileSource) new_tile_source =
992992
tile_source_duplicate(tile_source);
993-
Imageui *imageui = imageui_new(new_tile_source);
993+
Imageui *new_imageui = imageui_duplicate(new_tile_source, win->imageui);
994994

995-
image_window_imageui_add(new_win, imageui);
996-
image_window_imageui_set_visible(new_win, imageui, transition);
995+
image_window_imageui_add(new_win, new_imageui);
996+
image_window_imageui_set_visible(new_win, new_imageui, transition);
997997
}
998998

999999
gtk_window_present(GTK_WINDOW(new_win));

0 commit comments

Comments
 (0)