52
53
#include "gimp-intl.h"
55
#define MAX_SCALE_BUF 20
58
static void gimp_navigation_editor_class_init (GimpNavigationEditorClass *klass);
59
static void gimp_navigation_editor_init (GimpNavigationEditor *editor);
61
static void gimp_navigation_editor_docked_iface_init (GimpDockedInterface *docked_iface);
62
static void gimp_navigation_editor_set_context (GimpDocked *docked,
63
GimpContext *context);
65
static void gimp_navigation_editor_destroy (GtkObject *object);
67
static GtkWidget * gimp_navigation_editor_new_private (GimpMenuFactory *menu_factory,
68
GimpDisplayShell *shell);
56
static void gimp_navigation_editor_docked_iface_init (GimpDockedInterface *iface);
58
static void gimp_navigation_editor_destroy (GtkObject *object);
60
static void gimp_navigation_editor_set_context (GimpDocked *docked,
61
GimpContext *context);
63
static GtkWidget * gimp_navigation_editor_new_private (GimpMenuFactory *menu_factory,
64
GimpDisplayShell *shell);
70
66
static void gimp_navigation_editor_set_shell (GimpNavigationEditor *view,
71
67
GimpDisplayShell *shell);
72
static gboolean gimp_navigation_editor_button_release (GtkWidget *widget,
73
GdkEventButton *bevent,
74
GimpDisplayShell *shell);
68
static gboolean gimp_navigation_editor_button_release (GtkWidget *widget,
69
GdkEventButton *bevent,
70
GimpDisplayShell *shell);
75
71
static void gimp_navigation_editor_marker_changed (GimpNavigationView *view,
95
91
static void gimp_navigation_editor_update_marker (GimpNavigationEditor *editor);
98
static GimpEditorClass *parent_class = NULL;
102
gimp_navigation_editor_get_type (void)
104
static GType type = 0;
108
static const GTypeInfo editor_info =
110
sizeof (GimpNavigationEditorClass),
111
NULL, /* base_init */
112
NULL, /* base_finalize */
113
(GClassInitFunc) gimp_navigation_editor_class_init,
114
NULL, /* class_finalize */
115
NULL, /* class_navigation */
116
sizeof (GimpNavigationEditor),
118
(GInstanceInitFunc) gimp_navigation_editor_init,
120
static const GInterfaceInfo docked_iface_info =
122
(GInterfaceInitFunc) gimp_navigation_editor_docked_iface_init,
123
NULL, /* iface_finalize */
124
NULL /* iface_data */
127
type = g_type_register_static (GIMP_TYPE_EDITOR,
128
"GimpNavigationEditor",
131
g_type_add_interface_static (type, GIMP_TYPE_DOCKED,
94
G_DEFINE_TYPE_WITH_CODE (GimpNavigationEditor, gimp_navigation_editor,
96
G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
97
gimp_navigation_editor_docked_iface_init))
99
#define parent_class gimp_navigation_editor_parent_class
139
103
gimp_navigation_editor_class_init (GimpNavigationEditorClass *klass)
141
105
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
143
parent_class = g_type_class_peek_parent (klass);
145
107
gtk_object_class->destroy = gimp_navigation_editor_destroy;
111
gimp_navigation_editor_docked_iface_init (GimpDockedInterface *iface)
113
iface->set_context = gimp_navigation_editor_set_context;
149
117
gimp_navigation_editor_init (GimpNavigationEditor *editor)
151
119
GtkWidget *frame;
153
editor->shell = NULL;
121
editor->context = NULL;
122
editor->shell = NULL;
155
124
frame = gtk_frame_new (NULL);
156
125
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
157
126
gtk_box_pack_start (GTK_BOX (editor), frame, TRUE, TRUE, 0);
158
127
gtk_widget_show (frame);
160
editor->view = gimp_view_new_by_types (GIMP_TYPE_NAVIGATION_VIEW,
129
editor->view = gimp_view_new_by_types (NULL,
130
GIMP_TYPE_NAVIGATION_VIEW,
162
132
GIMP_VIEW_SIZE_MEDIUM, 0, TRUE);
163
133
gtk_container_add (GTK_CONTAINER (frame), editor->view);
164
134
gtk_widget_show (editor->view);
166
g_signal_connect (editor->view, "marker_changed",
136
g_signal_connect (editor->view, "marker-changed",
167
137
G_CALLBACK (gimp_navigation_editor_marker_changed),
169
139
g_signal_connect (editor->view, "zoom",
180
gimp_navigation_editor_docked_iface_init (GimpDockedInterface *docked_iface)
150
gimp_navigation_editor_destroy (GtkObject *object)
182
docked_iface->set_context = gimp_navigation_editor_set_context;
152
GimpNavigationEditor *editor = GIMP_NAVIGATION_EDITOR (object);
155
gimp_navigation_editor_set_shell (editor, NULL);
157
GTK_OBJECT_CLASS (parent_class)->destroy (object);
186
161
gimp_navigation_editor_context_changed (GimpContext *context,
162
GimpDisplay *display,
188
163
GimpNavigationEditor *editor)
190
165
GimpDisplayShell *shell = NULL;
193
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
168
shell = GIMP_DISPLAY_SHELL (display->shell);
195
170
gimp_navigation_editor_set_shell (editor, shell);
217
g_signal_connect (context, "display_changed",
192
g_signal_connect (context, "display-changed",
218
193
G_CALLBACK (gimp_navigation_editor_context_changed),
221
gdisp = gimp_context_get_display (context);
196
display = gimp_context_get_display (context);
225
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
199
gimp_view_renderer_set_context (GIMP_VIEW (editor->view)->renderer,
203
shell = GIMP_DISPLAY_SHELL (display->shell);
227
205
gimp_navigation_editor_set_shell (editor, shell);
231
gimp_navigation_editor_destroy (GtkObject *object)
233
GimpNavigationEditor *editor = GIMP_NAVIGATION_EDITOR (object);
236
gimp_navigation_editor_set_shell (editor, NULL);
238
GTK_OBJECT_CLASS (parent_class)->destroy (object);
242
209
/* public functions */
279
246
gtk_container_add (GTK_CONTAINER (frame), GTK_WIDGET (editor));
280
247
gtk_widget_show (GTK_WIDGET (editor));
282
g_signal_connect (editor->view, "button_release_event",
249
g_signal_connect (editor->view, "button-release-event",
283
250
G_CALLBACK (gimp_navigation_editor_button_release),
359
GimpDisplayConfig *config;
326
Gimp *gimp = shell->display->image->gimp;
327
GimpDisplayConfig *config = GIMP_DISPLAY_CONFIG (gimp->config);
362
330
editor = g_object_new (GIMP_TYPE_NAVIGATION_EDITOR, NULL);
364
config = GIMP_DISPLAY_CONFIG (shell->gdisp->gimage->gimp->config);
365
view = GIMP_VIEW (editor->view);
332
view = GIMP_VIEW (editor->view);
367
334
gimp_view_renderer_set_size (view->renderer,
368
335
config->nav_preview_size * 3,
369
336
view->renderer->border_width);
337
gimp_view_renderer_set_context (view->renderer,
338
gimp_get_user_context (gimp));
371
340
gimp_navigation_editor_set_shell (editor, shell);
375
345
GtkWidget *hscale;
377
348
editor = g_object_new (GIMP_TYPE_NAVIGATION_EDITOR,
378
349
"menu-factory", menu_factory,
413
384
/* the zoom scale */
386
hbox = gtk_hbox_new (FALSE, 6);
387
gtk_box_pack_end (GTK_BOX (editor), hbox, FALSE, FALSE, 0);
388
gtk_widget_show (hbox);
415
390
editor->zoom_adjustment =
416
391
GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -8.0, 8.0, 0.5, 1.0, 0.0));
418
g_signal_connect (editor->zoom_adjustment, "value_changed",
393
g_signal_connect (editor->zoom_adjustment, "value-changed",
419
394
G_CALLBACK (gimp_navigation_editor_zoom_adj_changed),
422
397
hscale = gtk_hscale_new (GTK_ADJUSTMENT (editor->zoom_adjustment));
423
398
gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_DELAYED);
424
399
gtk_scale_set_draw_value (GTK_SCALE (hscale), FALSE);
425
gtk_scale_set_digits (GTK_SCALE (hscale), 2);
426
gtk_box_pack_end (GTK_BOX (editor), hscale, FALSE, FALSE, 0);
400
gtk_box_pack_start (GTK_BOX (hbox), hscale, TRUE, TRUE, 0);
427
401
gtk_widget_show (hscale);
429
403
/* the zoom label */
431
405
editor->zoom_label = gtk_label_new ("100%");
432
gtk_box_pack_end (GTK_BOX (editor), editor->zoom_label, FALSE, FALSE, 0);
406
gtk_label_set_width_chars (GTK_LABEL (editor->zoom_label), 7);
407
gtk_box_pack_start (GTK_BOX (hbox), editor->zoom_label, FALSE, FALSE, 0);
433
408
gtk_widget_show (editor->zoom_label);
437
GtkRequisition requisition;
439
gtk_widget_size_request (editor->zoom_label, &requisition);
440
gtk_widget_set_size_request (editor->zoom_label,
441
4 * requisition.width,
446
411
gimp_view_renderer_set_background (GIMP_VIEW (editor->view)->renderer,
528
493
if (editor->shell)
535
xratio = SCALEFACTOR_X (editor->shell);
536
yratio = SCALEFACTOR_Y (editor->shell);
538
xoffset = RINT (x * xratio - editor->shell->offset_x);
539
yoffset = RINT (y * yratio - editor->shell->offset_y);
541
gimp_display_shell_scroll (editor->shell, xoffset, yoffset);
495
GimpDisplayShell *shell = editor->shell;
497
gimp_display_shell_scroll (shell,
498
RINT (x * shell->scale_x - shell->offset_x),
499
RINT (y * shell->scale_y - shell->offset_y));
616
573
if (editor->zoom_label)
618
gchar scale_str[MAX_SCALE_BUF];
620
/* Update the zoom scale string */
621
g_snprintf (scale_str, sizeof (scale_str),
622
shell->scale >= 0.15 ? "%.0f%%" : "%.2f%%",
623
editor->shell->scale * 100);
625
gtk_label_set_text (GTK_LABEL (editor->zoom_label), scale_str);
577
g_object_get (shell->zoom,
580
gtk_label_set_text (GTK_LABEL (editor->zoom_label), str);
628
584
if (editor->zoom_adjustment)
632
val = log (CLAMP (editor->shell->scale, 1.0 / 256, 256.0) ) / G_LN2;
588
val = log (gimp_zoom_model_get_factor (shell->zoom)) / G_LN2;
634
590
g_signal_handlers_block_by_func (editor->zoom_adjustment,
635
591
gimp_navigation_editor_zoom_adj_changed,
676
632
gimp_navigation_editor_update_marker (GimpNavigationEditor *editor)
678
GimpViewRenderer *renderer;
682
renderer = GIMP_VIEW (editor->view)->renderer;
684
xratio = SCALEFACTOR_X (editor->shell);
685
yratio = SCALEFACTOR_Y (editor->shell);
687
if (renderer->dot_for_dot != editor->shell->dot_for_dot)
688
gimp_view_renderer_set_dot_for_dot (renderer,
689
editor->shell->dot_for_dot);
634
GimpViewRenderer *renderer = GIMP_VIEW (editor->view)->renderer;
635
GimpDisplayShell *shell = editor->shell;
637
if (renderer->dot_for_dot != shell->dot_for_dot)
638
gimp_view_renderer_set_dot_for_dot (renderer, shell->dot_for_dot);
691
640
gimp_navigation_view_set_marker (GIMP_NAVIGATION_VIEW (editor->view),
692
editor->shell->offset_x / xratio,
693
editor->shell->offset_y / yratio,
694
editor->shell->disp_width / xratio,
695
editor->shell->disp_height / yratio);
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);