diff options
Diffstat (limited to 'src/gradient-chemistry.cpp')
| -rw-r--r-- | src/gradient-chemistry.cpp | 101 |
1 files changed, 76 insertions, 25 deletions
diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index 6a485e573..0f57ed901 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -19,6 +19,7 @@ #include "desktop-style.h" #include "sp-gradient-reference.h" +#include "sp-gradient-vector.h" #include "sp-linear-gradient.h" #include "sp-radial-gradient.h" #include "sp-stop.h" @@ -498,11 +499,24 @@ sp_last_stop(SPGradient *gradient) return stop; } return NULL; +} + +SPStop* +sp_get_stop_i(SPGradient *gradient, guint stop_i) +{ + SPStop *stop = sp_first_stop (gradient); + + for (guint i=0; i < stop_i; i++) { + if (!stop) return NULL; + stop = sp_next_stop (stop); + } + + return stop; } void -sp_item_gradient_edit_stop (SPItem *item, guint point_num, bool fill_or_stroke) +sp_item_gradient_edit_stop (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke) { SPGradient *gradient = sp_item_gradient (item, fill_or_stroke); @@ -510,8 +524,8 @@ sp_item_gradient_edit_stop (SPItem *item, guint point_num, bool fill_or_stroke) return; SPGradient *vector = sp_gradient_get_vector (gradient, false); - switch (point_num) { - case POINT_LG_P1: + switch (point_type) { + case POINT_LG_BEGIN: case POINT_RG_CENTER: case POINT_RG_FOCUS: { @@ -520,7 +534,7 @@ sp_item_gradient_edit_stop (SPItem *item, guint point_num, bool fill_or_stroke) } break; - case POINT_LG_P2: + case POINT_LG_END: case POINT_RG_R1: case POINT_RG_R2: { @@ -528,13 +542,20 @@ sp_item_gradient_edit_stop (SPItem *item, guint point_num, bool fill_or_stroke) gtk_widget_show (dialog); } break; + + case POINT_LG_MID: + { + GtkWidget *dialog = sp_gradient_vector_editor_new (vector, sp_get_stop_i (vector, point_i)); + gtk_widget_show (dialog); + } + break; default: break; } } guint32 -sp_item_gradient_stop_query_style (SPItem *item, guint point_num, bool fill_or_stroke) +sp_item_gradient_stop_query_style (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke) { SPGradient *gradient = sp_item_gradient (item, fill_or_stroke); @@ -546,8 +567,8 @@ sp_item_gradient_stop_query_style (SPItem *item, guint point_num, bool fill_or_s if (!vector) // orphan! return 0; // what else to do? - switch (point_num) { - case POINT_LG_P1: + switch (point_type) { + case POINT_LG_BEGIN: case POINT_RG_CENTER: case POINT_RG_FOCUS: { @@ -558,7 +579,7 @@ sp_item_gradient_stop_query_style (SPItem *item, guint point_num, bool fill_or_s } break; - case POINT_LG_P2: + case POINT_LG_END: case POINT_RG_R1: case POINT_RG_R2: { @@ -568,6 +589,16 @@ sp_item_gradient_stop_query_style (SPItem *item, guint point_num, bool fill_or_s } } break; + + case POINT_LG_MID: + { + SPStop *stopi = sp_get_stop_i (vector, point_i); + if (stopi) { + return sp_stop_get_rgba32(stopi); + } + } + break; + default: break; } @@ -575,7 +606,7 @@ sp_item_gradient_stop_query_style (SPItem *item, guint point_num, bool fill_or_s } void -sp_item_gradient_stop_set_style (SPItem *item, guint point_num, bool fill_or_stroke, SPCSSAttr *stop) +sp_item_gradient_stop_set_style (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, SPCSSAttr *stop) { SPGradient *gradient = sp_item_gradient (item, fill_or_stroke); @@ -592,8 +623,8 @@ sp_item_gradient_stop_set_style (SPItem *item, guint point_num, bool fill_or_str sp_gradient_repr_set_link(SP_OBJECT_REPR(gradient), vector); } - switch (point_num) { - case POINT_LG_P1: + switch (point_type) { + case POINT_LG_BEGIN: case POINT_RG_CENTER: case POINT_RG_FOCUS: { @@ -604,7 +635,7 @@ sp_item_gradient_stop_set_style (SPItem *item, guint point_num, bool fill_or_str } break; - case POINT_LG_P2: + case POINT_LG_END: case POINT_RG_R1: case POINT_RG_R2: { @@ -614,6 +645,16 @@ sp_item_gradient_stop_set_style (SPItem *item, guint point_num, bool fill_or_str } } break; + + case POINT_LG_MID: + { + SPStop *stopi = sp_get_stop_i (vector, point_i); + if (stopi) { + sp_repr_css_change (SP_OBJECT_REPR (stopi), stop, "style"); + } + } + break; + default: break; } @@ -674,11 +715,11 @@ sp_item_gradient_reverse_vector (SPItem *item, bool fill_or_stroke) /** -Set the position of point point_num of the gradient applied to item (either fill_or_stroke) to +Set the position of point point_type of the gradient applied to item (either fill_or_stroke) to p_w (in desktop coordinates). Write_repr if you want the change to become permanent. */ void -sp_item_gradient_set_coords (SPItem *item, guint point_num, NR::Point p_w, bool fill_or_stroke, bool write_repr, bool scale) +sp_item_gradient_set_coords (SPItem *item, guint point_type, guint point_i, NR::Point p_w, bool fill_or_stroke, bool write_repr, bool scale) { SPGradient *gradient = sp_item_gradient (item, fill_or_stroke); @@ -696,8 +737,8 @@ sp_item_gradient_set_coords (SPItem *item, guint point_num, NR::Point p_w, bool if (SP_IS_LINEARGRADIENT(gradient)) { SPLinearGradient *lg = SP_LINEARGRADIENT(gradient); - switch (point_num) { - case POINT_LG_P1: + switch (point_type) { + case POINT_LG_BEGIN: if (scale) { lg->x2.computed += (lg->x1.computed - p[NR::X]); lg->y2.computed += (lg->y1.computed - p[NR::Y]); @@ -715,7 +756,7 @@ sp_item_gradient_set_coords (SPItem *item, guint point_num, NR::Point p_w, bool SP_OBJECT (gradient)->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; - case POINT_LG_P2: + case POINT_LG_END: if (scale) { lg->x1.computed += (lg->x2.computed - p[NR::X]); lg->y1.computed += (lg->y2.computed - p[NR::Y]); @@ -733,6 +774,11 @@ sp_item_gradient_set_coords (SPItem *item, guint point_num, NR::Point p_w, bool SP_OBJECT (gradient)->requestModified(SP_OBJECT_MODIFIED_FLAG); } break; + case POINT_LG_MID: + { + //do stuff! + } + break; default: break; } @@ -741,14 +787,14 @@ sp_item_gradient_set_coords (SPItem *item, guint point_num, NR::Point p_w, bool SPRadialGradient *rg = SP_RADIALGRADIENT(gradient); NR::Point c (rg->cx.computed, rg->cy.computed); NR::Point c_w = c * gradient->gradientTransform * i2d; // now in desktop coords - if ((point_num == POINT_RG_R1 || point_num == POINT_RG_R2) && NR::L2 (p_w - c_w) < 1e-3) { + if ((point_type == POINT_RG_R1 || point_type == POINT_RG_R2) && NR::L2 (p_w - c_w) < 1e-3) { // prevent setting a radius too close to the center return; } NR::Matrix new_transform; bool transform_set = false; - switch (point_num) { + switch (point_type) { case POINT_RG_CENTER: rg->fx.computed = p[NR::X] + (rg->fx.computed - rg->cx.computed); rg->fy.computed = p[NR::Y] + (rg->fy.computed - rg->cy.computed); @@ -852,12 +898,12 @@ sp_item_gradient_get_spread (SPItem *item, bool fill_or_stroke) /** -Returns the position of point point_num of the gradient applied to item (either fill_or_stroke), +Returns the position of point point_type of the gradient applied to item (either fill_or_stroke), in desktop coordinates. */ NR::Point -sp_item_gradient_get_coords (SPItem *item, guint point_num, bool fill_or_stroke) +sp_item_gradient_get_coords (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke) { SPGradient *gradient = sp_item_gradient (item, fill_or_stroke); @@ -868,17 +914,22 @@ sp_item_gradient_get_coords (SPItem *item, guint point_num, bool fill_or_stroke) if (SP_IS_LINEARGRADIENT(gradient)) { SPLinearGradient *lg = SP_LINEARGRADIENT(gradient); - switch (point_num) { - case POINT_LG_P1: + switch (point_type) { + case POINT_LG_BEGIN: p = NR::Point (lg->x1.computed, lg->y1.computed); break; - case POINT_LG_P2: + case POINT_LG_END: p = NR::Point (lg->x2.computed, lg->y2.computed); break; + case POINT_LG_MID: + //p = somewhere in between (x1,y1)-(x2,y2) defined by percentage of point[point_i]; + gdouble offset = lg->vector.stops.at(point_i).offset; + p = (1-offset) * NR::Point(lg->x1.computed, lg->y1.computed) + offset * NR::Point(lg->x2.computed, lg->y2.computed); + break; } } else if (SP_IS_RADIALGRADIENT(gradient)) { SPRadialGradient *rg = SP_RADIALGRADIENT(gradient); - switch (point_num) { + switch (point_type) { case POINT_RG_CENTER: p = NR::Point (rg->cx.computed, rg->cy.computed); break; |
