2006-12-05 David Lodge <dave@cirt.net>
[dia.git] / lib / attributes.c
blob87e6d664da831bddabb17e6522a5503335420704
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #include <config.h>
20 #include "attributes.h"
21 #include "intl.h"
22 #include "persistence.h"
24 static Color attributes_foreground = { 0.0f, 0.0f, 0.0f };
25 static Color attributes_background = { 1.0f, 1.0f, 1.0f };
27 static real attributes_default_linewidth = 0.1;
29 static Arrow attributes_start_arrow = { ARROW_NONE,
30 DEFAULT_ARROW_SIZE,
31 DEFAULT_ARROW_SIZE };
32 static Arrow attributes_end_arrow = { ARROW_NONE,
33 DEFAULT_ARROW_SIZE,
34 DEFAULT_ARROW_SIZE };
36 static LineStyle attributes_linestyle = LINESTYLE_SOLID;
37 static real attributes_dash_length = 1.0;
39 static DiaFont *attributes_font = NULL;
40 static real attributes_font_height = 0.8;
42 /** Get the foreground color attribute (lines and text)
43 * @returns The current foreground color as set in the toolbox.
45 Color
46 attributes_get_foreground(void)
48 return attributes_foreground;
51 /** Get the background color attribute (for box background and such)
52 * @returns The current background color as set in the toolbox.
54 Color
55 attributes_get_background(void)
57 return attributes_background;
60 /** Set the default foreground color for new objects.
61 * @param color A color object to use for foreground color. This object is
62 * not stored by ths function and can be freed afterwards.
64 void
65 attributes_set_foreground(Color *color)
67 attributes_foreground = *color;
68 persistence_set_color("fg_color", color);
71 /** Set the default background color for new objects.
72 * @param color A color object to use for background color. This object is
73 * not stored by ths function and can be freed afterwards.
75 void
76 attributes_set_background(Color *color)
78 attributes_background = *color;
79 persistence_set_color("bg_color", color);
82 /** Swap the current foreground and background colors
84 void
85 attributes_swap_fgbg(void)
87 Color temp;
88 temp = attributes_foreground;
89 attributes_set_foreground(&attributes_background);
90 attributes_set_background(&temp);
93 /** Set the default foreground and background colors to black and white.
95 void
96 attributes_default_fgbg(void)
98 attributes_set_foreground(&color_black);
99 attributes_set_background(&color_white);
102 /** Get the default line width as defined by the toolbox.
103 * @returns A linewidth (0.0 < linewidth < 10.0) that should be used as default
104 * for new objects.
106 real
107 attributes_get_default_linewidth(void)
109 return attributes_default_linewidth;
112 /** Set the default line width.
113 * @param width The line width (0.0 < linewidth < 10.0) to use for new objects.
115 void
116 attributes_set_default_linewidth(real width)
118 attributes_default_linewidth = width;
119 persistence_set_real("linewidth", width);
122 /** Get the default arrow type to put at the start (origin) of a connector.
123 * @returns An arrow object for the arrow type defined in the toolbox.
125 Arrow
126 attributes_get_default_start_arrow(void)
128 return attributes_start_arrow;
131 /** Set the default arrow type that the toolbox will supply for new objects.
132 * @param arrow An arrow object to be used for the start of new connectors.
134 void
135 attributes_set_default_start_arrow(Arrow arrow)
137 attributes_start_arrow = arrow;
138 persistence_set_string("start-arrow-type",
139 arrow_types[arrow_index_from_type(arrow.type)].name);
140 persistence_set_real("start-arrow-width", arrow.width);
141 persistence_set_real("start-arrow-length", arrow.length);
144 /** Get the default arrow type to put at the end (target) of a connector.
145 * @returns An arrow object for the arrow type defined in the toolbox.
147 Arrow
148 attributes_get_default_end_arrow(void)
150 return attributes_end_arrow;
153 /** Set the default arrow type that the toolbox will supply for new objects.
154 * @param arrow An arrow object to be used for the end of new connectors.
156 void
157 attributes_set_default_end_arrow(Arrow arrow)
159 attributes_end_arrow = arrow;
160 persistence_set_string("end-arrow-type",
161 arrow_types[arrow_index_from_type(arrow.type)].name);
162 persistence_set_real("end-arrow-width", arrow.width);
163 persistence_set_real("end-arrow-length", arrow.length);
166 /** Get the default line style (dashes, dots etc)
167 * @param style A place to return the style (number of dots and dashes)
168 * @param dash_length A place to return how long a dash is
169 * (0.0 < dash_length < ???)
170 * @see dia-enums.h for possible values for style.
172 void
173 attributes_get_default_line_style(LineStyle *style, real *dash_length)
175 if (style)
176 *style = attributes_linestyle;
177 if (dash_length)
178 *dash_length = attributes_dash_length;
181 /** Set the default line style (dashes, dots etc)
182 * @param style The style (number of dots and dashes)
183 * @param dash_length The length of a dash (0.0 < dash_length < ???)
184 * @see dia-enums.h for possible values for style.
186 void
187 attributes_set_default_line_style(LineStyle style, real dash_length)
189 attributes_linestyle = style;
190 attributes_dash_length = dash_length;
191 persistence_set_integer("line-style", style);
192 persistence_set_real("dash-length", dash_length);
195 /** Get the default font.
196 * Note that there is currently no way for the user to set these.
197 * @param font A place to return the default font description set by the user
198 * @param font_height A place to return the default font height set by the user
200 void
201 attributes_get_default_font(DiaFont **font, real *font_height)
203 if (!attributes_font) {
204 attributes_font = dia_font_new_from_style(DIA_FONT_SANS,
205 attributes_font_height);
207 if (font)
208 *font = dia_font_ref(attributes_font);
209 if (font_height)
210 *font_height = attributes_font_height;
213 /** Set the default font.
214 * Note that this is not currently stored persistently.
215 * @param font The font to set as the new default.
216 * This object will be ref'd by this call.
217 * @param font_height The font height to set as the new default.
219 void
220 attributes_set_default_font(DiaFont *font, real font_height)
222 if (attributes_font != NULL)
223 dia_font_unref(attributes_font);
224 attributes_font = dia_font_ref(font);
225 attributes_font_height = font_height;