Logo Search packages:      
Sourcecode: inkscape version File versions

static void sp_export_detect_size ( GtkObject *  base  )  [static]

This function is used to detect the current selection setting based on the values in the x0, y0, x1 and y0 fields.

Parameters:
base The export dialog itself
One of the most confusing parts of this function is why the array is built at the beginning. What needs to happen here is that we should always check the current selection to see if it is the valid one. While this is a performance improvement it is also a usability one during the cases where things like selections and drawings match size. This way buttons change less 'randomly' (atleast in the eyes of the user). To do this an array is built where the current selection type is placed first, and then the others in an order from smallest to largest (this can be configured by reshuffling test_order).

All of the values in this function are rounded to two decimal places because that is what is shown to the user. While everything is kept more accurate than that, the user can't control more acurrate than that, so for this to work for them - it needs to check on that level of accuracy.

Todo:
finish writing this up

Definition at line 1219 of file export.cpp.

References NR::Rect::round(), SELECTION_CUSTOM, SELECTION_DRAWING, selection_names, SELECTION_PAGE, SELECTION_SELECTION, and sp_export_value_get_px().

                                        {
    static const selection_type test_order[SELECTION_NUMBER_OF] = {SELECTION_SELECTION, SELECTION_DRAWING, SELECTION_PAGE, SELECTION_CUSTOM};
    selection_type this_test[SELECTION_NUMBER_OF + 1];
    selection_type key = SELECTION_NUMBER_OF;

    NR::Point x(sp_export_value_get_px (base, "x0"),
                sp_export_value_get_px (base, "y0"));
    NR::Point y(sp_export_value_get_px (base, "x1"),
                sp_export_value_get_px (base, "y1"));
    NR::Rect current_bbox(x, y);
    current_bbox.round(2);
    // std::cout << "Current " << current_bbox;

    this_test[0] = (selection_type)((int)gtk_object_get_data(GTK_OBJECT(base), "selection-type"));
    for (int i = 0; i < SELECTION_NUMBER_OF; i++) {
        this_test[i + 1] = test_order[i];
    }

    for (int i = 0;
            i < SELECTION_NUMBER_OF + 1 &&
                key == SELECTION_NUMBER_OF &&
                SP_ACTIVE_DESKTOP != NULL;
            i++) {
        // std::cout << "Looking at: " << selection_names[this_test[i]] << std::endl;
        switch (this_test[i]) {
            case SELECTION_SELECTION:
                if ((SP_DT_SELECTION(SP_ACTIVE_DESKTOP))->isEmpty() == false) {
                    NR::Rect bbox = (SP_DT_SELECTION (SP_ACTIVE_DESKTOP))->bounds();

                    bbox.round(2);
                    // std::cout << "Selection " << bbox2;
                    //if (bbox == current_bbox) {
                    if (sp_export_bbox_equal(bbox,current_bbox)) {
                        key = SELECTION_SELECTION;
                    }
                }
                break;
            case SELECTION_DRAWING: {
                SPDocument *doc = SP_DT_DOCUMENT (SP_ACTIVE_DESKTOP);

                NR::Rect bbox = sp_item_bbox_desktop (SP_ITEM (SP_DOCUMENT_ROOT (doc)));

                bbox.round(2);
                // std::cout << "Drawing " << bbox2;
                //if (bbox == current_bbox) {
                if (sp_export_bbox_equal(bbox,current_bbox)) {
                    key = SELECTION_DRAWING;
                }
                break;
            }

            case SELECTION_PAGE: {
                SPDocument *doc;

                doc = SP_DT_DOCUMENT (SP_ACTIVE_DESKTOP);

                NR::Point x(0.0, 0.0);
                NR::Point y(sp_document_width(doc),
                            sp_document_height(doc));
                NR::Rect bbox(x, y);
                bbox.round(2);

                // std::cout << "Page " << bbox;
                if (sp_export_bbox_equal(bbox,current_bbox)) {
                //if (bbox == current_bbox) {
                    key = SELECTION_PAGE;
                }

                break;
           }
        default:
           break;
        }
    }
    // std::cout << std::endl;

    if (key == SELECTION_NUMBER_OF) {
        key = SELECTION_CUSTOM;
    }

    /* We're now using a custom size, not a fixed one */
    /* printf("Detecting state: %s\n", selection_names[key]); */
    selection_type old = (selection_type)((int)gtk_object_get_data(GTK_OBJECT(base), "selection-type"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(gtk_object_get_data(base, selection_names[old])), FALSE);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(gtk_object_get_data(base, selection_names[key])), TRUE);
    gtk_object_set_data(GTK_OBJECT(base), "selection-type", (gpointer)key);

    return;
} /* sp_export_detect_size */


Generated by  Doxygen 1.6.0   Back to index