static GValueArray * brushes_get_spacing_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GValueArray *args) { gboolean success = TRUE; GValueArray *return_vals; gint32 spacing = 0; GimpBrush *brush = gimp_context_get_brush (context); if (brush) spacing = gimp_brush_get_spacing (brush); else success = FALSE; return_vals = gimp_procedure_get_return_values (procedure, success); if (success) g_value_set_int (&return_vals->values[1], spacing); return return_vals; }
/* * gfig_read_gimp_style() reads the style settings from the Gimp core, * and applies them to the specified style, giving that style the * specified name. This is mainly useful as a way of initializing * a style. The function does not cause a repaint. */ void gfig_read_gimp_style (Style *style, const gchar *name) { gint dummy; if (!name) g_message ("Error: name is NULL in gfig_read_gimp_style."); if (gfig_context->debug_styles) g_printerr ("Reading Gimp settings as style %s\n", name); style->name = g_strdup (name); gimp_context_get_foreground (&style->foreground); gimp_context_get_background (&style->background); style->brush_name = gimp_context_get_brush (); gimp_brush_get_info (style->brush_name, &style->brush_width, &style->brush_height, &dummy, &dummy); gimp_brush_get_spacing (style->brush_name, &style->brush_spacing); style->gradient = gimp_context_get_gradient (); style->pattern = gimp_context_get_pattern (); style->fill_opacity = 100.; gfig_context->bdesc.name = style->brush_name; gfig_context->bdesc.width = style->brush_width; gfig_context->bdesc.height = style->brush_height; }
static void gimp_brush_editor_set_data (GimpDataEditor *editor, GimpData *data) { GimpBrushEditor *brush_editor = GIMP_BRUSH_EDITOR (editor); GimpBrushGeneratedShape shape = GIMP_BRUSH_GENERATED_CIRCLE; gdouble radius = 0.0; gint spikes = 2; gdouble hardness = 0.0; gdouble ratio = 0.0; gdouble angle = 0.0; gdouble spacing = 0.0; if (editor->data) g_signal_handlers_disconnect_by_func (editor->data, gimp_brush_editor_notify_brush, editor); GIMP_DATA_EDITOR_CLASS (parent_class)->set_data (editor, data); if (editor->data) g_signal_connect (editor->data, "notify", G_CALLBACK (gimp_brush_editor_notify_brush), editor); gimp_view_set_viewable (GIMP_VIEW (editor->view), GIMP_VIEWABLE (data)); if (editor->data) { spacing = gimp_brush_get_spacing (GIMP_BRUSH (editor->data)); if (GIMP_IS_BRUSH_GENERATED (editor->data)) { GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (editor->data); shape = gimp_brush_generated_get_shape (brush); radius = gimp_brush_generated_get_radius (brush); spikes = gimp_brush_generated_get_spikes (brush); hardness = gimp_brush_generated_get_hardness (brush); ratio = gimp_brush_generated_get_aspect_ratio (brush); angle = gimp_brush_generated_get_angle (brush); } } gtk_widget_set_sensitive (brush_editor->options_box, editor->data_editable); gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (brush_editor->shape_group), shape); gtk_adjustment_set_value (brush_editor->radius_data, radius); gtk_adjustment_set_value (brush_editor->spikes_data, spikes); gtk_adjustment_set_value (brush_editor->hardness_data, hardness); gtk_adjustment_set_value (brush_editor->aspect_ratio_data, ratio); gtk_adjustment_set_value (brush_editor->angle_data, angle); gtk_adjustment_set_value (brush_editor->spacing_data, spacing); }
static void gimp_brush_editor_update_brush (GtkAdjustment *adjustment, GimpBrushEditor *editor) { GimpBrushGenerated *brush; gdouble radius; gint spikes; gdouble hardness; gdouble ratio; gdouble angle; gdouble spacing; if (! GIMP_IS_BRUSH_GENERATED (GIMP_DATA_EDITOR (editor)->data)) return; brush = GIMP_BRUSH_GENERATED (GIMP_DATA_EDITOR (editor)->data); radius = gtk_adjustment_get_value (editor->radius_data); spikes = ROUND (gtk_adjustment_get_value (editor->spikes_data)); hardness = gtk_adjustment_get_value (editor->hardness_data); ratio = gtk_adjustment_get_value (editor->aspect_ratio_data); angle = gtk_adjustment_get_value (editor->angle_data); spacing = gtk_adjustment_get_value (editor->spacing_data); if (radius != gimp_brush_generated_get_radius (brush) || spikes != gimp_brush_generated_get_spikes (brush) || hardness != gimp_brush_generated_get_hardness (brush) || ratio != gimp_brush_generated_get_aspect_ratio (brush) || angle != gimp_brush_generated_get_angle (brush) || spacing != gimp_brush_get_spacing (GIMP_BRUSH (brush))) { g_signal_handlers_block_by_func (brush, gimp_brush_editor_notify_brush, editor); gimp_data_freeze (GIMP_DATA (brush)); g_object_freeze_notify (G_OBJECT (brush)); gimp_brush_generated_set_radius (brush, radius); gimp_brush_generated_set_spikes (brush, spikes); gimp_brush_generated_set_hardness (brush, hardness); gimp_brush_generated_set_aspect_ratio (brush, ratio); gimp_brush_generated_set_angle (brush, angle); gimp_brush_set_spacing (GIMP_BRUSH (brush), spacing); g_object_thaw_notify (G_OBJECT (brush)); gimp_data_thaw (GIMP_DATA (brush)); g_signal_handlers_unblock_by_func (brush, gimp_brush_editor_notify_brush, editor); } }
void gimp_paint_options_set_default_brush_spacing (GimpPaintOptions *paint_options, GimpBrush *brush) { g_return_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options)); g_return_if_fail (brush == NULL || GIMP_IS_BRUSH (brush)); if (! brush) brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options)); if (brush) { g_object_set (paint_options, "brush-spacing", (gdouble) gimp_brush_get_spacing (brush) / 100.0, NULL); } }
static GValueArray * brushes_get_brush_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GValueArray *args) { gboolean success = TRUE; GValueArray *return_vals; gchar *name = NULL; gint32 width = 0; gint32 height = 0; gint32 spacing = 0; GimpBrush *brush = gimp_context_get_brush (context); if (brush) { name = g_strdup (gimp_object_get_name (GIMP_OBJECT (brush))); width = brush->mask->width; height = brush->mask->height; spacing = gimp_brush_get_spacing (brush); } else success = FALSE; return_vals = gimp_procedure_get_return_values (procedure, success); if (success) { g_value_take_string (&return_vals->values[1], name); g_value_set_int (&return_vals->values[2], width); g_value_set_int (&return_vals->values[3], height); g_value_set_int (&return_vals->values[4], spacing); } return return_vals; }
gboolean gimp_brush_generated_save (GimpData *data, GError **error) { GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data); const gchar *name = gimp_object_get_name (data); FILE *file; gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; gboolean have_shape = FALSE; g_return_val_if_fail (name != NULL && *name != '\0', FALSE); file = g_fopen (gimp_data_get_filename (data), "wb"); if (! file) { g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN, _("Could not open '%s' for writing: %s"), gimp_filename_to_utf8 (gimp_data_get_filename (data)), g_strerror (errno)); return FALSE; } /* write magic header */ fprintf (file, "GIMP-VBR\n"); /* write version */ if (brush->shape != GIMP_BRUSH_GENERATED_CIRCLE || brush->spikes > 2) { fprintf (file, "1.5\n"); have_shape = TRUE; } else { fprintf (file, "1.0\n"); } /* write name */ fprintf (file, "%.255s\n", name); if (have_shape) { GEnumClass *enum_class; GEnumValue *shape_val; enum_class = g_type_class_peek (GIMP_TYPE_BRUSH_GENERATED_SHAPE); /* write shape */ shape_val = g_enum_get_value (enum_class, brush->shape); fprintf (file, "%s\n", shape_val->value_nick); } /* write brush spacing */ fprintf (file, "%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", gimp_brush_get_spacing (GIMP_BRUSH (brush)))); /* write brush radius */ fprintf (file, "%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", brush->radius)); if (have_shape) { /* write brush spikes */ fprintf (file, "%d\n", brush->spikes); } /* write brush hardness */ fprintf (file, "%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", brush->hardness)); /* write brush aspect_ratio */ fprintf (file, "%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", brush->aspect_ratio)); /* write brush angle */ fprintf (file, "%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", brush->angle)); fclose (file); return TRUE; }
gboolean gimp_brush_generated_save (GimpData *data, GOutputStream *output, GError **error) { GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data); const gchar *name = gimp_object_get_name (data); GString *string; gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; gboolean have_shape = FALSE; g_return_val_if_fail (name != NULL && *name != '\0', FALSE); /* write magic header */ string = g_string_new ("GIMP-VBR\n"); /* write version */ if (brush->shape != GIMP_BRUSH_GENERATED_CIRCLE || brush->spikes > 2) { g_string_append (string, "1.5\n"); have_shape = TRUE; } else { g_string_append (string, "1.0\n"); } /* write name */ g_string_append_printf (string, "%.255s\n", name); if (have_shape) { GEnumClass *enum_class; GEnumValue *shape_val; enum_class = g_type_class_peek (GIMP_TYPE_BRUSH_GENERATED_SHAPE); /* write shape */ shape_val = g_enum_get_value (enum_class, brush->shape); g_string_append_printf (string, "%s\n", shape_val->value_nick); } /* write brush spacing */ g_string_append_printf (string, "%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", gimp_brush_get_spacing (GIMP_BRUSH (brush)))); /* write brush radius */ g_string_append_printf (string, "%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", brush->radius)); if (have_shape) { /* write brush spikes */ g_string_append_printf (string, "%d\n", brush->spikes); } /* write brush hardness */ g_string_append_printf (string, "%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", brush->hardness)); /* write brush aspect_ratio */ g_string_append_printf (string, "%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", brush->aspect_ratio)); /* write brush angle */ g_string_append_printf (string, "%s\n", g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", brush->angle)); if (! g_output_stream_write_all (output, string->str, string->len, NULL, NULL, error)) { g_string_free (string, TRUE); return FALSE; } g_string_free (string, TRUE); return TRUE; }
static GimpBrush * gimp_brush_pipe_select_brush (GimpBrush *brush, const GimpCoords *last_coords, const GimpCoords *current_coords) { GimpBrushPipe *pipe = GIMP_BRUSH_PIPE (brush); gint i, brushix, ix; gdouble velocity, spacing; if (pipe->nbrushes == 1) return GIMP_BRUSH (pipe->current); /* calculates brush native spacing in pixels, based on it's width)*/ spacing = ((gdouble) gimp_brush_get_spacing (pipe->current) / 100) * MAX (brush->mask->width, brush->mask->height); brushix = 0; for (i = 0; i < pipe->dimension; i++) { switch (pipe->select[i]) { case PIPE_SELECT_INCREMENTAL: ix = (pipe->index[i] + 1) % pipe->rank[i]; break; case PIPE_SELECT_ANGULAR: /* Coords angle is already nomalized, * offset by 90 degrees is still needed * because hoses were made PS compatible*/ ix = (gint) RINT ((1.0 - current_coords->direction + 0.25) * pipe->rank[i]) % pipe->rank[i]; break; case PIPE_SELECT_VELOCITY: velocity = current_coords->velocity; /* Max velocity is 3.0, picking stamp as a ratio*/ ix = ROUND ((3.0 / velocity) * pipe->rank[i]); break; case PIPE_SELECT_RANDOM: /* This probably isn't the right way */ ix = g_random_int_range (0, pipe->rank[i]); break; case PIPE_SELECT_PRESSURE: ix = RINT (current_coords->pressure * (pipe->rank[i] - 1)); break; case PIPE_SELECT_TILT_X: ix = RINT (current_coords->xtilt / 2.0 * pipe->rank[i]) + pipe->rank[i] / 2; break; case PIPE_SELECT_TILT_Y: ix = RINT (current_coords->ytilt / 2.0 * pipe->rank[i]) + pipe->rank[i] / 2; break; case PIPE_SELECT_CONSTANT: default: ix = pipe->index[i]; break; } pipe->index[i] = CLAMP (ix, 0, pipe->rank[i] - 1); brushix += pipe->stride[i] * pipe->index[i]; } /* Make sure is inside bounds */ brushix = CLAMP (brushix, 0, pipe->nbrushes - 1); pipe->current = pipe->brushes[brushix]; return GIMP_BRUSH (pipe->current); }
static GValueArray * brushes_get_brush_data_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GValueArray *args) { gboolean success = TRUE; GValueArray *return_vals; const gchar *name; gchar *actual_name = NULL; gdouble opacity = 0.0; gint32 spacing = 0; gint32 paint_mode = 0; gint32 width = 0; gint32 height = 0; gint32 length = 0; guint8 *mask_data = NULL; name = g_value_get_string (&args->values[0]); if (success) { GimpBrush *brush; if (name && strlen (name)) { brush = (GimpBrush *) gimp_container_get_child_by_name (gimp->brush_factory->container, name); } else { brush = gimp_context_get_brush (context); } if (brush) { actual_name = g_strdup (gimp_object_get_name (GIMP_OBJECT (brush))); opacity = 1.0; spacing = gimp_brush_get_spacing (brush); paint_mode = 0; width = brush->mask->width; height = brush->mask->height; length = brush->mask->height * brush->mask->width; mask_data = g_memdup (temp_buf_data (brush->mask), length); } else success = FALSE; } return_vals = gimp_procedure_get_return_values (procedure, success); if (success) { g_value_take_string (&return_vals->values[1], actual_name); g_value_set_double (&return_vals->values[2], opacity); g_value_set_int (&return_vals->values[3], spacing); g_value_set_enum (&return_vals->values[4], paint_mode); g_value_set_int (&return_vals->values[5], width); g_value_set_int (&return_vals->values[6], height); g_value_set_int (&return_vals->values[7], length); gimp_value_take_int8array (&return_vals->values[8], mask_data, length); } return return_vals; }