summaryrefslogtreecommitdiffstats
path: root/src/dialogs
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2007-03-04 19:06:34 +0000
committermental <mental@users.sourceforge.net>2007-03-04 19:06:34 +0000
commit06b346c6b592e8a0d9609e42c5a509ee9ebe519b (patch)
treed11771089b02bc74843859851025824a6d8ac3b9 /src/dialogs
parentreplace use of invokeBbox in flood fill tool (diff)
downloadinkscape-06b346c6b592e8a0d9609e42c5a509ee9ebe519b.tar.gz
inkscape-06b346c6b592e8a0d9609e42c5a509ee9ebe519b.zip
adapt code to new Maybe/bbox regime
(bzr r2538)
Diffstat (limited to 'src/dialogs')
-rw-r--r--src/dialogs/clonetiler.cpp39
-rw-r--r--src/dialogs/stroke-style.cpp101
-rw-r--r--src/dialogs/tiledialog.cpp101
-rw-r--r--src/dialogs/unclump.cpp23
4 files changed, 161 insertions, 103 deletions
diff --git a/src/dialogs/clonetiler.cpp b/src/dialogs/clonetiler.cpp
index 00fcac48e..cbf858f4d 100644
--- a/src/dialogs/clonetiler.cpp
+++ b/src/dialogs/clonetiler.cpp
@@ -786,6 +786,11 @@ clonetiler_trace_pick (NR::Rect box)
/* Set up pixblock */
guchar *px = g_new(guchar, 4 * width * height);
+
+ if (px == NULL) {
+ return 0; // buffer is too big or too small, cannot pick, so return 0
+ }
+
memset(px, 0x00, 4 * width * height);
/* Render */
@@ -793,7 +798,7 @@ clonetiler_trace_pick (NR::Rect box)
nr_pixblock_setup_extern( &pb, NR_PIXBLOCK_MODE_R8G8B8A8N,
ibox.x0, ibox.y0, ibox.x1, ibox.y1,
px, 4 * width, FALSE, FALSE );
- nr_arena_item_invoke_render( trace_root, &ibox, &pb,
+ nr_arena_item_invoke_render(NULL, trace_root, &ibox, &pb,
NR_ARENA_ITEM_RENDER_NO_CACHE );
double R = 0, G = 0, B = 0, A = 0;
@@ -1080,15 +1085,20 @@ clonetiler_apply (GtkWidget *widget, void *)
w = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-w", 0);
h = sp_repr_get_double_attribute (obj_repr, "inkscape:tile-h", 0);
} else {
- NR::Rect const r = SP_ITEM(obj)->getBounds(sp_item_i2doc_affine(SP_ITEM(obj)));
- c = r.midpoint();
- w = r.dimensions()[NR::X];
- h = r.dimensions()[NR::Y];
-
- sp_repr_set_svg_double(obj_repr, "inkscape:tile-w", w);
- sp_repr_set_svg_double(obj_repr, "inkscape:tile-h", h);
- sp_repr_set_svg_double(obj_repr, "inkscape:tile-cx", c[NR::X]);
- sp_repr_set_svg_double(obj_repr, "inkscape:tile-cy", c[NR::Y]);
+ NR::Maybe<NR::Rect> r = SP_ITEM(obj)->getBounds(sp_item_i2doc_affine(SP_ITEM(obj)));
+ if (r) {
+ c = r->midpoint();
+ w = r->dimensions()[NR::X];
+ h = r->dimensions()[NR::Y];
+
+ sp_repr_set_svg_double(obj_repr, "inkscape:tile-cx", c[NR::X]);
+ sp_repr_set_svg_double(obj_repr, "inkscape:tile-cy", c[NR::Y]);
+ sp_repr_set_svg_double(obj_repr, "inkscape:tile-w", w);
+ sp_repr_set_svg_double(obj_repr, "inkscape:tile-h", h);
+ } else {
+ c = NR::Point(0, 0);
+ w = h = 0;
+ }
}
NR::Point cur = NR::Point (0, 0);
@@ -1281,12 +1291,9 @@ clonetiler_apply (GtkWidget *widget, void *)
center_set = true;
}
- gchar affinestr[80];
- if (sp_svg_transform_write(affinestr, 79, t)) {
- clone->setAttribute("transform", affinestr);
- } else {
- clone->setAttribute("transform", NULL);
- }
+ gchar *affinestr=sp_svg_transform_write(t);
+ clone->setAttribute("transform", affinestr);
+ g_free(affinestr);
if (opacity < 1.0) {
sp_repr_set_css_double(clone, "opacity", opacity);
diff --git a/src/dialogs/stroke-style.cpp b/src/dialogs/stroke-style.cpp
index 53c5c722f..7894a89b8 100644
--- a/src/dialogs/stroke-style.cpp
+++ b/src/dialogs/stroke-style.cpp
@@ -83,7 +83,7 @@ static GtkWidget * marker_mid_menu = NULL;
static GtkWidget * marker_end_menu = NULL;
static SPObject *ink_extract_marker_name(gchar const *n);
-static void ink_markers_menu_update();
+static void ink_markers_menu_update(SPWidget* spw);
static Inkscape::UI::Cache::SvgPreview svg_preview_cache;
@@ -184,14 +184,6 @@ sp_stroke_style_widget_change_subselection ( Inkscape::Application *inkscape,
sp_stroke_style_paint_update (spw);
}
-static void
-sp_stroke_style_widget_transientize_callback(Inkscape::Application *inkscape,
- SPDesktop *desktop,
- SPWidget *spw )
-{
- ink_markers_menu_update();
-}
-
/**
* Gets the active stroke style property, then sets the appropriate color, alpha, gradient,
* pattern, etc. for the paint-selector.
@@ -567,6 +559,16 @@ sp_stroke_radio_button(GtkWidget *tb, char const *icon,
}
+static void
+sp_stroke_style_widget_transientize_callback(Inkscape::Application *inkscape,
+ SPDesktop *desktop,
+ SPWidget *spw )
+{
+// TODO: Either of these will cause crashes sometimes
+// sp_stroke_style_line_update( SP_WIDGET(spw), desktop ? sp_desktop_selection(desktop) : NULL);
+// ink_markers_menu_update(spw);
+}
+
/**
* Creates a copy of the marker named mname, determines its visible and renderable
* area in menu_id's bounding box, and then renders it. This allows us to fill in
@@ -609,9 +611,9 @@ sp_marker_prev_new(unsigned psize, gchar const *mname,
// Find object's bbox in document
NR::Matrix const i2doc(sp_item_i2doc_affine(SP_ITEM(object)));
- NR::Rect const dbox = SP_ITEM(object)->getBounds(i2doc);
+ NR::Maybe<NR::Rect> dbox = SP_ITEM(object)->getBounds(i2doc);
- if (dbox.isEmpty()) {
+ if (!dbox) {
return NULL;
}
@@ -623,7 +625,7 @@ sp_marker_prev_new(unsigned psize, gchar const *mname,
pixbuf = svg_preview_cache.get_preview_from_cache(key);
if (pixbuf == NULL) {
- pixbuf = render_pixbuf(root, sf, dbox, psize);
+ pixbuf = render_pixbuf(root, sf, *dbox, psize);
svg_preview_cache.set_preview_in_cache(key, pixbuf);
}
@@ -719,15 +721,6 @@ sp_marker_list_from_doc (GtkWidget *m, SPDocument *current_doc, SPDocument *sour
GSList *ml = ink_marker_list_get(source);
GSList *clean_ml = NULL;
- // Do this here, outside of loop, to speed up preview generation:
- /* Create new arena */
- NRArena const *arena = NRArena::create();
- /* Create ArenaItem and set transform */
- unsigned const visionkey = sp_item_display_key_new(1);
-/*
- NRArenaItem *root = sp_item_invoke_show( SP_ITEM(SP_DOCUMENT_ROOT (sandbox)), (NRArena *) arena, visionkey, SP_ITEM_SHOW_DISPLAY );
-*/
-
for (; ml != NULL; ml = ml->next) {
if (!SP_IS_MARKER(ml->data))
continue;
@@ -786,7 +779,7 @@ ink_marker_menu_create_menu(GtkWidget *m, gchar *menu_id, SPDocument *doc, SPDoc
GtkWidget *i = gtk_menu_item_new();
gtk_widget_show(i);
-// g_object_set_data(G_OBJECT(i), "marker", (void *) "none");
+ g_object_set_data(G_OBJECT(i), "marker", (void *) "none");
GtkWidget *hb = gtk_hbox_new(FALSE, MARKER_ITEM_MARGIN);
gtk_widget_show(hb);
@@ -825,6 +818,7 @@ ink_marker_menu_create_menu(GtkWidget *m, gchar *menu_id, SPDocument *doc, SPDoc
sp_document_ensure_up_to_date(doc);
sp_marker_list_from_doc ( m, doc, markers_doc, NULL, sandbox, menu_id );
}
+
}
@@ -912,9 +906,14 @@ sp_marker_select(GtkOptionMenu *mnu, GtkWidget *spw)
gchar *menu_id = (gchar *) g_object_get_data(G_OBJECT(mnu), "menu_id");
sp_repr_css_set_property(css, menu_id, marker);
- Inkscape::Selection *selection = sp_desktop_selection(desktop);
- GSList const *items = selection->itemList();
- for (; items != NULL; items = items->next) {
+ // Also update the marker dropdown menus, so the document's markers
+ // show up at the top of the menu
+// sp_stroke_style_line_update( SP_WIDGET(spw), desktop ? sp_desktop_selection(desktop) : NULL);
+ ink_markers_menu_update(SP_WIDGET(spw));
+
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
+ GSList const *items = selection->itemList();
+ for (; items != NULL; items = items->next) {
SPItem *item = (SPItem *) items->data;
if (!SP_IS_SHAPE(item) || SP_IS_RECT(item)) // can't set marker to rect, until it's converted to using <path>
continue;
@@ -931,35 +930,66 @@ sp_marker_select(GtkOptionMenu *mnu, GtkWidget *spw)
sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE,
_("Set markers"));
- // Lastly, also update the marker dropdown menus, so the document's markers
- // show up at the top of the menu
- ink_markers_menu_update();
};
+static int
+ink_marker_menu_get_pos(GtkMenu* mnu, gchar* markname) {
+
+ if (markname == NULL)
+ markname = (gchar *) g_object_get_data(G_OBJECT(gtk_menu_get_active(mnu)), "marker");
+
+ if (markname == NULL)
+ return 0;
+
+ GList *kids = GTK_MENU_SHELL(mnu)->children;
+ int i = 0;
+ for (; kids != NULL; kids = kids->next) {
+ gchar *mark = (gchar *) g_object_get_data(G_OBJECT(kids->data), "marker");
+ if ( mark && strcmp(mark, markname) == 0 ) {
+ break;
+ }
+ i++;
+ }
+ return i;
+}
+
static void
-ink_markers_menu_update() {
+ink_markers_menu_update(SPWidget* spw) {
SPDesktop *desktop = inkscape_active_desktop();
SPDocument *document = sp_desktop_document(desktop);
SPDocument *sandbox = ink_markers_preview_doc ();
GtkWidget *m;
+ int pos;
+ gtk_signal_handler_block_by_func( GTK_OBJECT(marker_start_menu), GTK_SIGNAL_FUNC(sp_marker_select), spw);
+ pos = ink_marker_menu_get_pos(GTK_MENU(gtk_option_menu_get_menu(GTK_OPTION_MENU(marker_start_menu))), NULL);
m = gtk_menu_new();
gtk_widget_show(m);
ink_marker_menu_create_menu(m, "marker-start", document, sandbox);
gtk_option_menu_remove_menu(GTK_OPTION_MENU(marker_start_menu));
gtk_option_menu_set_menu(GTK_OPTION_MENU(marker_start_menu), m);
+ gtk_option_menu_set_history(GTK_OPTION_MENU(marker_start_menu), pos);
+ gtk_signal_handler_unblock_by_func( GTK_OBJECT(marker_start_menu), GTK_SIGNAL_FUNC(sp_marker_select), spw);
+ gtk_signal_handler_block_by_func( GTK_OBJECT(marker_mid_menu), GTK_SIGNAL_FUNC(sp_marker_select), spw);
+ pos = ink_marker_menu_get_pos(GTK_MENU(gtk_option_menu_get_menu(GTK_OPTION_MENU(marker_mid_menu))), NULL);
m = gtk_menu_new();
gtk_widget_show(m);
ink_marker_menu_create_menu(m, "marker-mid", document, sandbox);
gtk_option_menu_remove_menu(GTK_OPTION_MENU(marker_mid_menu));
gtk_option_menu_set_menu(GTK_OPTION_MENU(marker_mid_menu), m);
+ gtk_option_menu_set_history(GTK_OPTION_MENU(marker_mid_menu), pos);
+ gtk_signal_handler_unblock_by_func( GTK_OBJECT(marker_mid_menu), GTK_SIGNAL_FUNC(sp_marker_select), spw);
+ gtk_signal_handler_block_by_func( GTK_OBJECT(marker_end_menu), GTK_SIGNAL_FUNC(sp_marker_select), spw);
+ pos = ink_marker_menu_get_pos(GTK_MENU(gtk_option_menu_get_menu(GTK_OPTION_MENU(marker_end_menu))), NULL);
m = gtk_menu_new();
gtk_widget_show(m);
ink_marker_menu_create_menu(m, "marker-end", document, sandbox);
gtk_option_menu_remove_menu(GTK_OPTION_MENU(marker_end_menu));
gtk_option_menu_set_menu(GTK_OPTION_MENU(marker_end_menu), m);
+ gtk_option_menu_set_history(GTK_OPTION_MENU(marker_end_menu), pos);
+ gtk_signal_handler_unblock_by_func( GTK_OBJECT(marker_end_menu), GTK_SIGNAL_FUNC(sp_marker_select), spw);
}
/**
@@ -1734,17 +1764,7 @@ ink_marker_menu_set_current(SPObject *marker, GtkOptionMenu *mnu)
else
markname = g_strdup(SP_OBJECT_REPR(marker)->attribute("id"));
- int markpos = 0;
- GList *kids = GTK_MENU_SHELL(m)->children;
- int i = 0;
- for (; kids != NULL; kids = kids->next) {
- gchar *mark = (gchar *) g_object_get_data(G_OBJECT(kids->data), "marker");
- if ( mark && strcmp(mark, markname) == 0 ) {
- markpos = i;
- break;
- }
- i++;
- }
+ int markpos = ink_marker_menu_get_pos(m, markname);
gtk_option_menu_set_history(GTK_OPTION_MENU(mnu), markpos);
g_free (markname);
@@ -1847,7 +1867,6 @@ ink_extract_marker_name(gchar const *n)
gchar* b = g_strdup(p);
b[c] = '\0';
-
SPDesktop *desktop = inkscape_active_desktop();
SPDocument *doc = sp_desktop_document(desktop);
SPObject *marker = doc->getObjectById(b);
diff --git a/src/dialogs/tiledialog.cpp b/src/dialogs/tiledialog.cpp
index d56d083ba..b10f952da 100644
--- a/src/dialogs/tiledialog.cpp
+++ b/src/dialogs/tiledialog.cpp
@@ -49,18 +49,23 @@ sp_compare_x_position(SPItem *first, SPItem *second)
using NR::X;
using NR::Y;
- NR::Rect const a = first->getBounds(sp_item_i2doc_affine(first));
- double const a_height = a.dimensions()[Y];
+ NR::Maybe<NR::Rect> a = first->getBounds(sp_item_i2doc_affine(first));
+ NR::Maybe<NR::Rect> b = second->getBounds(sp_item_i2doc_affine(second));
- NR::Rect const b = second->getBounds(sp_item_i2doc_affine(second));
- double const b_height = b.dimensions()[Y];
+ if ( !a || !b ) {
+ // FIXME?
+ return 0;
+ }
+
+ double const a_height = a->dimensions()[Y];
+ double const b_height = b->dimensions()[Y];
bool a_in_b_vert = false;
- if ((a.min()[Y] < b.min()[Y] + 0.1) && (a.min()[Y] > b.min()[Y] - b_height)) {
+ if ((a->min()[Y] < b->min()[Y] + 0.1) && (a->min()[Y] > b->min()[Y] - b_height)) {
a_in_b_vert = true;
- } else if ((b.min()[Y] < a.min()[Y] + 0.1) && (b.min()[Y] > a.min()[Y] - a_height)) {
+ } else if ((b->min()[Y] < a->min()[Y] + 0.1) && (b->min()[Y] > a->min()[Y] - a_height)) {
a_in_b_vert = true;
- } else if (b.min()[Y] == a.min()[Y]) {
+ } else if (b->min()[Y] == a->min()[Y]) {
a_in_b_vert = true;
} else {
a_in_b_vert = false;
@@ -69,10 +74,10 @@ sp_compare_x_position(SPItem *first, SPItem *second)
if (!a_in_b_vert) {
return -1;
}
- if (a_in_b_vert && a.min()[X] > b.min()[X]) {
+ if (a_in_b_vert && a->min()[X] > b->min()[X]) {
return 1;
}
- if (a_in_b_vert && a.min()[X] < b.min()[X]) {
+ if (a_in_b_vert && a->min()[X] < b->min()[X]) {
return -1;
}
return 0;
@@ -84,13 +89,18 @@ sp_compare_x_position(SPItem *first, SPItem *second)
int
sp_compare_y_position(SPItem *first, SPItem *second)
{
- NR::Rect const a = first->getBounds(sp_item_i2doc_affine(first));
- NR::Rect const b = second->getBounds(sp_item_i2doc_affine(second));
+ NR::Maybe<NR::Rect> a = first->getBounds(sp_item_i2doc_affine(first));
+ NR::Maybe<NR::Rect> b = second->getBounds(sp_item_i2doc_affine(second));
+
+ if ( !a || !b ) {
+ // FIXME?
+ return 0;
+ }
- if (a.min()[NR::Y] > b.min()[NR::Y]) {
+ if (a->min()[NR::Y] > b->min()[NR::Y]) {
return 1;
}
- if (a.min()[NR::Y] < b.min()[NR::Y]) {
+ if (a->min()[NR::Y] < b->min()[NR::Y]) {
return -1;
}
@@ -159,17 +169,22 @@ void TileDialog::Grid_Arrange ()
cnt=0;
for (; items != NULL; items = items->next) {
SPItem *item = SP_ITEM(items->data);
- NR::Rect const b = item->getBounds(sp_item_i2doc_affine(item));
- width = b.dimensions()[NR::X];
- height = b.dimensions()[NR::Y];
- cx = b.midpoint()[NR::X];
- cy = b.midpoint()[NR::Y];
-
- if (b.min()[NR::X] < grid_left) {
- grid_left = b.min()[NR::X];
+ NR::Maybe<NR::Rect> b = item->getBounds(sp_item_i2doc_affine(item));
+ if (!b) {
+ continue;
+ }
+
+ width = b->dimensions()[NR::X];
+ height = b->dimensions()[NR::Y];
+
+ cx = b->midpoint()[NR::X];
+ cy = b->midpoint()[NR::Y];
+
+ if (b->min()[NR::X] < grid_left) {
+ grid_left = b->min()[NR::X];
}
- if (b.min()[NR::Y] < grid_top) {
- grid_top = b.min()[NR::Y];
+ if (b->min()[NR::Y] < grid_top) {
+ grid_top = b->min()[NR::Y];
}
if (width > col_width) {
col_width = width;
@@ -196,15 +211,18 @@ void TileDialog::Grid_Arrange ()
const GSList *sizes = sorted;
for (; sizes != NULL; sizes = sizes->next) {
SPItem *item = SP_ITEM(sizes->data);
- NR::Rect const b = item->getBounds(sp_item_i2doc_affine(item));
- width = b.dimensions()[NR::X];
- height = b.dimensions()[NR::Y];
- if (width > col_widths[(cnt % NoOfCols)]) {
- col_widths[(cnt % NoOfCols)] = width;
- }
- if (height > row_heights[(cnt / NoOfCols)]) {
- row_heights[(cnt / NoOfCols)] = height;
+ NR::Maybe<NR::Rect> b = item->getBounds(sp_item_i2doc_affine(item));
+ if (b) {
+ width = b->dimensions()[NR::X];
+ height = b->dimensions()[NR::Y];
+ if (width > col_widths[(cnt % NoOfCols)]) {
+ col_widths[(cnt % NoOfCols)] = width;
+ }
+ if (height > row_heights[(cnt / NoOfCols)]) {
+ row_heights[(cnt / NoOfCols)] = height;
+ }
}
+
cnt++;
}
@@ -300,20 +318,25 @@ g_print("\n row = %f col = %f selection x= %f selection y = %f", total_row_h
for (; current_row != NULL; current_row = current_row->next) {
SPItem *item=SP_ITEM(current_row->data);
Inkscape::XML::Node *repr = SP_OBJECT_REPR(item);
- NR::Rect const b = item->getBounds(sp_item_i2doc_affine(item));
- width = b.dimensions()[NR::X];
- height = b.dimensions()[NR::Y];
+ NR::Maybe<NR::Rect> b = item->getBounds(sp_item_i2doc_affine(item));
+ NR::Point min;
+ if (b) {
+ width = b->dimensions()[NR::X];
+ height = b->dimensions()[NR::Y];
+ min = b->min();
+ } else {
+ width = height = 0;
+ min = NR::Point(0, 0);
+ }
+
row = cnt / NoOfCols;
col = cnt % NoOfCols;
- // original before I started fecking about with it.
- // new_x = grid_left + (((col_width - width)/2)*HorizAlign) + (( col_width + paddingx ) * (cnt % NoOfCols));
- // new_y = grid_top + (((row_height - height)/2)*VertAlign) +(( row_height + paddingy ) * (cnt / NoOfCols));
-
new_x = grid_left + (((col_widths[col] - width)/2)*HorizAlign) + col_xs[col];
new_y = grid_top + (((row_heights[row] - height)/2)*VertAlign) + row_ys[row];
- NR::Point move = NR::Point(new_x - b.min()[NR::X], b.min()[NR::Y] - new_y); // why are the two args the opposite ways round???
+ // signs are inverted between x and y due to y inversion
+ NR::Point move = NR::Point(new_x - min[NR::X], min[NR::Y] - new_y);
NR::Matrix const &affine = NR::Matrix(NR::translate(move));
sp_item_set_i2d_affine(item, sp_item_i2d_affine(item) * affine);
sp_item_write_transform(item, repr, item->transform, NULL);
diff --git a/src/dialogs/unclump.cpp b/src/dialogs/unclump.cpp
index f067aef5f..a15e17bc7 100644
--- a/src/dialogs/unclump.cpp
+++ b/src/dialogs/unclump.cpp
@@ -34,10 +34,15 @@ unclump_center (SPItem *item)
return i->second;
}
- NR::Rect const r = item->getBounds(sp_item_i2d_affine(item));
- NR::Point const c = r.midpoint();
- c_cache[SP_OBJECT_ID(item)] = c;
- return c;
+ NR::Maybe<NR::Rect> r = item->getBounds(sp_item_i2d_affine(item));
+ if (r) {
+ NR::Point const c = r->midpoint();
+ c_cache[SP_OBJECT_ID(item)] = c;
+ return c;
+ } else {
+ // FIXME
+ return NR::Point(0, 0);
+ }
}
NR::Point
@@ -48,9 +53,13 @@ unclump_wh (SPItem *item)
if ( i != wh_cache.end() ) {
wh = i->second;
} else {
- NR::Rect const r = item->getBounds(sp_item_i2d_affine(item));
- wh = r.dimensions();
- wh_cache[SP_OBJECT_ID(item)] = wh;
+ NR::Maybe<NR::Rect> r = item->getBounds(sp_item_i2d_affine(item));
+ if (r) {
+ wh = r->dimensions();
+ wh_cache[SP_OBJECT_ID(item)] = wh;
+ } else {
+ wh = NR::Point(0, 0);
+ }
}
return wh;