~ubuntu-branches/ubuntu/intrepid/gimp/intrepid

« back to all changes in this revision

Viewing changes to app/display/gimpnavigationeditor.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20081006133041-axco233xt49jobn7
Tags: 2.6.0-1ubuntu1
* Sync on debian and new version (lp: #276839)
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch:
  - updated some strings for ubuntu
* debian/rules:
  - updated translation templates

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
#include "gimp-intl.h"
54
54
 
55
55
 
56
 
static void   gimp_navigation_editor_docked_iface_init (GimpDockedInterface  *iface);
57
 
 
58
 
static void   gimp_navigation_editor_destroy           (GtkObject            *object);
59
 
 
60
 
static void   gimp_navigation_editor_set_context       (GimpDocked           *docked,
61
 
                                                        GimpContext          *context);
62
 
 
63
 
static GtkWidget * gimp_navigation_editor_new_private  (GimpMenuFactory      *menu_factory,
64
 
                                                        GimpDisplayShell     *shell);
65
 
 
66
 
static void     gimp_navigation_editor_set_shell       (GimpNavigationEditor *view,
67
 
                                                        GimpDisplayShell     *shell);
68
 
static gboolean gimp_navigation_editor_button_release  (GtkWidget            *widget,
69
 
                                                        GdkEventButton       *bevent,
70
 
                                                        GimpDisplayShell     *shell);
71
 
static void   gimp_navigation_editor_marker_changed    (GimpNavigationView   *view,
72
 
                                                        gdouble               x,
73
 
                                                        gdouble               y,
74
 
                                                        GimpNavigationEditor *editor);
75
 
static void   gimp_navigation_editor_zoom              (GimpNavigationView   *view,
76
 
                                                        GimpZoomType          direction,
77
 
                                                        GimpNavigationEditor *editor);
78
 
static void   gimp_navigation_editor_scroll            (GimpNavigationView   *view,
79
 
                                                        GdkScrollDirection    direction,
80
 
                                                        GimpNavigationEditor  *editor);
81
 
 
82
 
static void   gimp_navigation_editor_zoom_adj_changed  (GtkAdjustment        *adj,
83
 
                                                        GimpNavigationEditor *editor);
84
 
 
85
 
static void   gimp_navigation_editor_shell_scaled      (GimpDisplayShell     *shell,
86
 
                                                        GimpNavigationEditor *editor);
87
 
static void   gimp_navigation_editor_shell_scrolled    (GimpDisplayShell     *shell,
88
 
                                                        GimpNavigationEditor *editor);
89
 
static void   gimp_navigation_editor_shell_reconnect   (GimpDisplayShell     *shell,
90
 
                                                        GimpNavigationEditor *editor);
91
 
static void   gimp_navigation_editor_update_marker     (GimpNavigationEditor *editor);
 
56
static void        gimp_navigation_editor_docked_iface_init (GimpDockedInterface  *iface);
 
57
 
 
58
static void        gimp_navigation_editor_destroy           (GtkObject            *object);
 
59
 
 
60
static void        gimp_navigation_editor_set_context       (GimpDocked           *docked,
 
61
                                                             GimpContext          *context);
 
62
 
 
63
static GtkWidget * gimp_navigation_editor_new_private       (GimpMenuFactory      *menu_factory,
 
64
                                                             GimpDisplayShell     *shell);
 
65
 
 
66
static void        gimp_navigation_editor_set_shell         (GimpNavigationEditor *editor,
 
67
                                                             GimpDisplayShell     *shell);
 
68
static gboolean    gimp_navigation_editor_button_release    (GtkWidget            *widget,
 
69
                                                             GdkEventButton       *bevent,
 
70
                                                             GimpDisplayShell     *shell);
 
71
static void        gimp_navigation_editor_marker_changed    (GimpNavigationView   *view,
 
72
                                                             gdouble               x,
 
73
                                                             gdouble               y,
 
74
                                                             gdouble               width,
 
75
                                                             gdouble               height,
 
76
                                                             GimpNavigationEditor *editor);
 
77
static void        gimp_navigation_editor_zoom              (GimpNavigationView   *view,
 
78
                                                             GimpZoomType          direction,
 
79
                                                             GimpNavigationEditor *editor);
 
80
static void        gimp_navigation_editor_scroll            (GimpNavigationView   *view,
 
81
                                                             GdkScrollDirection    direction,
 
82
                                                             GimpNavigationEditor *editor);
 
83
 
 
84
static void        gimp_navigation_editor_zoom_adj_changed  (GtkAdjustment        *adj,
 
85
                                                             GimpNavigationEditor *editor);
 
86
 
 
87
static void        gimp_navigation_editor_shell_scaled      (GimpDisplayShell     *shell,
 
88
                                                             GimpNavigationEditor *editor);
 
89
static void        gimp_navigation_editor_shell_scrolled    (GimpDisplayShell     *shell,
 
90
                                                             GimpNavigationEditor *editor);
 
91
static void        gimp_navigation_editor_shell_reconnect   (GimpDisplayShell     *shell,
 
92
                                                             GimpNavigationEditor *editor);
 
93
static void        gimp_navigation_editor_update_marker     (GimpNavigationEditor *editor);
92
94
 
93
95
 
94
96
G_DEFINE_TYPE_WITH_CODE (GimpNavigationEditor, gimp_navigation_editor,
220
222
                              gint              click_x,
221
223
                              gint              click_y)
222
224
{
 
225
  GtkStyle             *style = gtk_widget_get_style (widget);
223
226
  GimpNavigationEditor *editor;
224
227
  GimpNavigationView   *view;
225
228
  GdkScreen            *screen;
226
229
  gint                  x, y;
227
 
  gint                  x_org, y_org;
 
230
  gint                  view_marker_x, view_marker_y;
 
231
  gint                  view_marker_width, view_marker_height;
228
232
 
229
233
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
230
234
  g_return_if_fail (GTK_IS_WIDGET (widget));
252
256
    }
253
257
  else
254
258
    {
255
 
      editor = GIMP_NAVIGATION_EDITOR (GTK_BIN (GTK_BIN (shell->nav_popup)->child)->child);
 
259
      GtkWidget *bin = gtk_bin_get_child (GTK_BIN (shell->nav_popup));
 
260
 
 
261
      editor = GIMP_NAVIGATION_EDITOR (gtk_bin_get_child (GTK_BIN (bin)));
256
262
    }
257
263
 
 
264
  view = GIMP_NAVIGATION_VIEW (editor->view);
 
265
 
 
266
  /* Set poup screen */
258
267
  screen = gtk_widget_get_screen (widget);
259
 
 
260
268
  gtk_window_set_screen (GTK_WINDOW (shell->nav_popup), screen);
261
269
 
262
 
  view = GIMP_NAVIGATION_VIEW (editor->view);
263
 
 
264
 
  /* decide where to put the popup */
265
 
  gdk_window_get_origin (widget->window, &x_org, &y_org);
266
 
 
267
 
#define BORDER_PEN_WIDTH  3
268
 
 
269
 
  x = (x_org + click_x -
270
 
       view->p_x -
271
 
       0.5 * (view->p_width  - BORDER_PEN_WIDTH) -
272
 
       2   * widget->style->xthickness);
273
 
 
274
 
  y = (y_org + click_y -
275
 
       view->p_y -
276
 
       0.5 * (view->p_height - BORDER_PEN_WIDTH) -
277
 
       2   * widget->style->ythickness);
278
 
 
279
 
  /* If the popup doesn't fit into the screen, we have a problem.
280
 
   * We move the popup onscreen and risk that the pointer is not
281
 
   * in the square representing the viewable area anymore. Moving
282
 
   * the pointer will make the image scroll by a large amount,
283
 
   * but then it works as usual. Probably better than a popup that
284
 
   * is completely unusable in the lower right of the screen.
285
 
   *
286
 
   * Warping the pointer would be another solution ...
287
 
   */
288
 
 
289
 
  x = CLAMP (x, 0, (gdk_screen_get_width (screen)  -
290
 
                    GIMP_VIEW (view)->renderer->width  -
291
 
                    4 * widget->style->xthickness));
292
 
  y = CLAMP (y, 0, (gdk_screen_get_height (screen) -
293
 
                    GIMP_VIEW (view)->renderer->height -
294
 
                    4 * widget->style->ythickness));
295
 
 
296
 
  gtk_window_move (GTK_WINDOW (shell->nav_popup), x, y);
 
270
  gimp_navigation_view_get_local_marker (view,
 
271
                                         &view_marker_x,
 
272
                                         &view_marker_y,
 
273
                                         &view_marker_width,
 
274
                                         &view_marker_height);
 
275
  /* Position the popup */
 
276
  {
 
277
    gint x_origin, y_origin;
 
278
    gint popup_width, popup_height;
 
279
    gint border_width, border_height;
 
280
    gint screen_click_x, screen_click_y;
 
281
 
 
282
    gdk_window_get_origin (widget->window, &x_origin, &y_origin);
 
283
 
 
284
    screen_click_x = x_origin + click_x;
 
285
    screen_click_y = y_origin + click_y;
 
286
    border_width   = style->xthickness * 4;
 
287
    border_height  = style->ythickness * 4;
 
288
    popup_width    = GIMP_VIEW (view)->renderer->width  - border_width;
 
289
    popup_height   = GIMP_VIEW (view)->renderer->height - border_height;
 
290
 
 
291
    x = screen_click_x -
 
292
        border_width -
 
293
        view_marker_x -
 
294
        view_marker_width / 2;
 
295
 
 
296
    y = screen_click_y -
 
297
        border_height -
 
298
        view_marker_y -
 
299
        view_marker_height / 2;
 
300
 
 
301
    /* When the image is zoomed out and overscrolled, the above
 
302
     * calculation risks positioning the popup far far away from the
 
303
     * click coordinate. We don't want that, so perform some clamping.
 
304
     */
 
305
    x = CLAMP (x, screen_click_x - popup_width,  screen_click_x);
 
306
    y = CLAMP (y, screen_click_y - popup_height, screen_click_y);
 
307
 
 
308
    /* If the popup doesn't fit into the screen, we have a problem.
 
309
     * We move the popup onscreen and risk that the pointer is not
 
310
     * in the square representing the viewable area anymore. Moving
 
311
     * the pointer will make the image scroll by a large amount,
 
312
     * but then it works as usual. Probably better than a popup that
 
313
     * is completely unusable in the lower right of the screen.
 
314
     *
 
315
     * Warping the pointer would be another solution ...
 
316
     */
 
317
    x = CLAMP (x, 0, gdk_screen_get_width (screen)  - popup_width);
 
318
    y = CLAMP (y, 0, gdk_screen_get_height (screen) - popup_height);
 
319
 
 
320
    gtk_window_move (GTK_WINDOW (shell->nav_popup), x, y);
 
321
  }
 
322
 
297
323
  gtk_widget_show (shell->nav_popup);
298
 
 
299
324
  gdk_flush ();
300
325
 
301
326
  /* fill in then grab pointer */
302
 
  view->motion_offset_x = 0.5 * (view->p_width  - BORDER_PEN_WIDTH);
303
 
  view->motion_offset_y = 0.5 * (view->p_height - BORDER_PEN_WIDTH);
304
 
 
305
 
#undef BORDER_PEN_WIDTH
306
 
 
 
327
  gimp_navigation_view_set_motion_offset (view,
 
328
                                          view_marker_width  / 2,
 
329
                                          view_marker_height / 2);
307
330
  gimp_navigation_view_grab_pointer (view);
308
331
}
309
332
 
323
346
 
324
347
  if (shell)
325
348
    {
326
 
      Gimp              *gimp   = shell->display->image->gimp;
 
349
      Gimp              *gimp   = shell->display->gimp;
327
350
      GimpDisplayConfig *config = GIMP_DISPLAY_CONFIG (gimp->config);
328
351
      GimpView          *view;
329
352
 
373
396
        gimp_editor_add_action_button (GIMP_EDITOR (editor), "view",
374
397
                                       "view-zoom-fit-in", NULL);
375
398
 
376
 
      editor->zoom_fit_to_button =
 
399
      editor->zoom_fill_button =
377
400
        gimp_editor_add_action_button (GIMP_EDITOR (editor), "view",
378
 
                                       "view-zoom-fit-to", NULL);
 
401
                                       "view-zoom-fill", NULL);
379
402
 
380
403
      editor->shrink_wrap_button =
381
404
        gimp_editor_add_action_button (GIMP_EDITOR (editor), "view",
488
511
gimp_navigation_editor_marker_changed (GimpNavigationView   *view,
489
512
                                       gdouble               x,
490
513
                                       gdouble               y,
 
514
                                       gdouble               width,
 
515
                                       gdouble               height,
491
516
                                       GimpNavigationEditor *editor)
492
517
{
493
518
  if (editor->shell)
494
519
    {
495
520
      GimpDisplayShell *shell = editor->shell;
496
521
 
497
 
      gimp_display_shell_scroll (shell,
498
 
                                 RINT (x * shell->scale_x - shell->offset_x),
499
 
                                 RINT (y * shell->scale_y - shell->offset_y));
 
522
      gimp_display_shell_scroll_center_image_coordinate (shell,
 
523
                                                         x + width / 2,
 
524
                                                         y + height / 2);
500
525
    }
501
526
}
502
527
 
538
563
 
539
564
      g_assert (adj != NULL);
540
565
 
541
 
      value = adj->value;
 
566
      value = gtk_adjustment_get_value (adj);
542
567
 
543
568
      switch (direction)
544
569
        {
563
588
gimp_navigation_editor_zoom_adj_changed (GtkAdjustment        *adj,
564
589
                                         GimpNavigationEditor *editor)
565
590
{
566
 
  gimp_display_shell_scale (editor->shell, GIMP_ZOOM_TO, pow (2.0, adj->value));
 
591
  gimp_display_shell_scale (editor->shell, GIMP_ZOOM_TO,
 
592
                            pow (2.0, gtk_adjustment_get_value (adj)));
567
593
}
568
594
 
569
595
static void
637
663
  if (renderer->dot_for_dot != shell->dot_for_dot)
638
664
    gimp_view_renderer_set_dot_for_dot (renderer, shell->dot_for_dot);
639
665
 
640
 
  gimp_navigation_view_set_marker (GIMP_NAVIGATION_VIEW (editor->view),
641
 
                                   shell->offset_x    / shell->scale_x,
642
 
                                   shell->offset_y    / shell->scale_y,
643
 
                                   shell->disp_width  / shell->scale_x,
644
 
                                   shell->disp_height / shell->scale_y);
 
666
  if (renderer->viewable)
 
667
    {
 
668
      GimpNavigationView *view = GIMP_NAVIGATION_VIEW (editor->view);
 
669
      gdouble             x, y;
 
670
      gdouble             w, h;
 
671
 
 
672
      gimp_display_shell_scroll_get_viewport (shell, &x, &y, &w, &h);
 
673
 
 
674
      gimp_navigation_view_set_marker (view, x, y, w, h);
 
675
    }
645
676
}