作図ソフト dia の改良版
Revisão | d8ba6da4da8301cc6fa4a45f25c14e234f3c6de6 (tree) |
---|---|
Hora | 2004-04-30 17:15:38 |
Autor | Lars Clausen <lclausen@src....> |
Commiter | Lars Clausen |
Grid align, and less undo
@@ -1,3 +1,14 @@ | ||
1 | +2004-04-30 Lars Clausen <larsrc@linux.local> | |
2 | + | |
3 | + * app/undo.c: Undoing broken undo stuff for diagram properties and | |
4 | + page setup. Shouldn't be mixed into undo at all. | |
5 | + | |
6 | + * app/render_gdk.c (draw_pixel_line): Use the dash-setting | |
7 | + function to avoid in particular the grid crawling. | |
8 | + | |
9 | + * lib/diagdkrenderer.[ch] (dia_gdk_renderer_set_dashes): Function | |
10 | + to allow aligning dashes, so they don't crawl. | |
11 | + | |
1 | 12 | 2004-04-28 Lars Clausen <lars@raeder.dk> |
2 | 13 | |
3 | 14 | * app/Makefile.am: New files diacanvas.[ch] |
@@ -178,6 +178,8 @@ draw_pixel_line(DiaRenderer *object, | ||
178 | 178 | DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object); |
179 | 179 | GdkGC *gc = renderer->gc; |
180 | 180 | GdkColor gdkcolor; |
181 | + | |
182 | + dia_gdk_renderer_set_dashes(renderer, x1+y1); | |
181 | 183 | |
182 | 184 | color_convert(color, &gdkcolor); |
183 | 185 | gdk_gc_set_foreground(gc, &gdkcolor); |
@@ -195,6 +197,8 @@ draw_pixel_rect(DiaRenderer *object, | ||
195 | 197 | GdkGC *gc = renderer->gc; |
196 | 198 | GdkColor gdkcolor; |
197 | 199 | |
200 | + dia_gdk_renderer_set_dashes(renderer, x+y); | |
201 | + | |
198 | 202 | color_convert(color, &gdkcolor); |
199 | 203 | gdk_gc_set_foreground(gc, &gdkcolor); |
200 | 204 |
@@ -1183,244 +1183,3 @@ undo_parenting(Diagram *dia, Object* parentobj, Object* childobj, | ||
1183 | 1183 | undo_push_change(dia->undo, change); |
1184 | 1184 | return change; |
1185 | 1185 | } |
1186 | - | |
1187 | -/* ******* DIAGRAM PROPERTIES ******** */ | |
1188 | - | |
1189 | -typedef enum { DYNAMIC_GRID, SPACING, BG_COLOR, GRID_COLOR, PAGE_COLOR, | |
1190 | - PAPER_SIZE, PORTRAIT, MARGINS, SCALING } DiagramChangeType; | |
1191 | -typedef union { | |
1192 | - /* Diagram properties dialog */ | |
1193 | - gboolean dynamic_grid; | |
1194 | - struct { real space_x, space_y; int visible_x, visible_y; } spacing; | |
1195 | - Color bg_color, grid_color, page_color; | |
1196 | - /* Page setup dialog */ | |
1197 | - gchar *paper_size; | |
1198 | - gboolean portrait; | |
1199 | - struct { real top, bottom, left, right; } margins; | |
1200 | - struct { real scale; int fit_x, fit_y; } scaling; | |
1201 | -} DiagramChangeData; | |
1202 | - | |
1203 | -typedef struct { | |
1204 | - Change change; | |
1205 | - DiagramChangeType t; | |
1206 | - DiagramChangeData change_from, change_to; | |
1207 | -} DiagramChange; | |
1208 | - | |
1209 | -static void | |
1210 | -diagram_update_properties(Diagram *dia) | |
1211 | -{ | |
1212 | - /* If diagram properties window open */ | |
1213 | - /*diagram_properties_retrieve(dia);*/ | |
1214 | - diagram_set_modified(dia, TRUE); | |
1215 | - diagram_add_update_all(dia); | |
1216 | - diagram_flush(dia); | |
1217 | -} | |
1218 | - | |
1219 | -static void | |
1220 | -diagram_update_pagesetup(Diagram *dia) | |
1221 | -{ | |
1222 | - /* update diagram -- this is needed to reposition page boundaries */ | |
1223 | - diagram_set_modified(dia, TRUE); | |
1224 | - diagram_add_update_all(dia); | |
1225 | - diagram_flush(dia); | |
1226 | -} | |
1227 | - | |
1228 | -static void | |
1229 | -diagram_change_apply_or_revert(Diagram *dia, DiagramChangeType t, | |
1230 | - DiagramChangeData *to) | |
1231 | -{ | |
1232 | - switch (t) { | |
1233 | - case DYNAMIC_GRID: | |
1234 | - dia->data->grid.dynamic = to->dynamic_grid; | |
1235 | - diagram_update_properties(dia); | |
1236 | - break; | |
1237 | - case SPACING: | |
1238 | - dia->data->grid.width_x = to->spacing.space_x; | |
1239 | - dia->data->grid.width_y = to->spacing.space_y; | |
1240 | - dia->data->grid.visible_x = to->spacing.visible_x; | |
1241 | - dia->data->grid.visible_y = to->spacing.visible_y; | |
1242 | - diagram_update_properties(dia); | |
1243 | - break; | |
1244 | - case BG_COLOR: | |
1245 | - dia->data->bg_color = to->bg_color; | |
1246 | - diagram_update_properties(dia); | |
1247 | - break; | |
1248 | - case GRID_COLOR: | |
1249 | - dia->data->grid.colour = to->grid_color; | |
1250 | - diagram_update_properties(dia); | |
1251 | - break; | |
1252 | - case PAGE_COLOR: | |
1253 | - dia->data->pagebreak_color = to->page_color; | |
1254 | - diagram_update_properties(dia); | |
1255 | - break; | |
1256 | - case PAPER_SIZE: | |
1257 | - g_free(dia->data->paper.name); | |
1258 | - dia->data->paper.name = g_strdup(to->paper_size); | |
1259 | - diagram_update_pagesetup(dia); | |
1260 | - break; | |
1261 | - case PORTRAIT: | |
1262 | - dia->data->paper.is_portrait = to->portrait; | |
1263 | - diagram_update_pagesetup(dia); | |
1264 | - break; | |
1265 | - case MARGINS: | |
1266 | - dia->data->paper.tmargin = to->margins.top; | |
1267 | - dia->data->paper.bmargin = to->margins.bottom; | |
1268 | - dia->data->paper.lmargin = to->margins.left; | |
1269 | - dia->data->paper.rmargin = to->margins.right; | |
1270 | - diagram_update_pagesetup(dia); | |
1271 | - break; | |
1272 | - case SCALING: | |
1273 | - if (to->scaling.scale != 0) { | |
1274 | - dia->data->paper.fitto = TRUE; | |
1275 | - dia->data->paper.scaling = to->scaling.scale; | |
1276 | - } else { | |
1277 | - dia->data->paper.fitto = FALSE; | |
1278 | - dia->data->paper.fitwidth = to->scaling.fit_x; | |
1279 | - dia->data->paper.fitheight = to->scaling.fit_y; | |
1280 | - } | |
1281 | - diagram_update_pagesetup(dia); | |
1282 | - break; | |
1283 | - } | |
1284 | -} | |
1285 | - | |
1286 | -static void | |
1287 | -diagram_change_apply(Change *change, Diagram *dia) | |
1288 | -{ | |
1289 | - DiagramChange *diachange = (DiagramChange *)change; | |
1290 | - diagram_change_apply_or_revert(dia, diachange->t, &diachange->change_to); | |
1291 | -} | |
1292 | - | |
1293 | -static void | |
1294 | -diagram_change_revert(Change *change, Diagram *dia) | |
1295 | -{ | |
1296 | - DiagramChange *diachange = (DiagramChange *)change; | |
1297 | - diagram_change_apply_or_revert(dia, diachange->t, &diachange->change_from); | |
1298 | -} | |
1299 | - | |
1300 | -static void | |
1301 | -diagram_change_free(Change *change) | |
1302 | -{ | |
1303 | - DiagramChange *diachange = (DiagramChange *)change; | |
1304 | - if (diachange->t == PAPER_SIZE) { | |
1305 | - g_free(diachange->change_to.paper_size); | |
1306 | - g_free(diachange->change_from.paper_size); | |
1307 | - } | |
1308 | -} | |
1309 | - | |
1310 | -Change * | |
1311 | -undo_diagram(Diagram *dia, DiagramChangeType t, | |
1312 | - DiagramChangeData from, DiagramChangeData to) | |
1313 | -{ | |
1314 | - DiagramChange *change = g_new0(DiagramChange, 1); | |
1315 | - change->t = t; | |
1316 | - change->change_from = from; | |
1317 | - change->change_to = to; | |
1318 | - | |
1319 | - return (Change*)change; | |
1320 | -} | |
1321 | - | |
1322 | -Change * | |
1323 | -undo_diagram_grid(Diagram *dia, gboolean on) | |
1324 | -{ | |
1325 | - DiagramChangeData from, to; | |
1326 | - from.dynamic_grid = dia->data->grid.dynamic; | |
1327 | - to.dynamic_grid = on; | |
1328 | - return undo_diagram(dia, DYNAMIC_GRID, from, to); | |
1329 | -} | |
1330 | - | |
1331 | -Change * | |
1332 | -undo_diagram_spacing(Diagram *dia, real space_x, real space_y, | |
1333 | - int visible_x, int visible_y) | |
1334 | -{ | |
1335 | - DiagramChangeData from, to; | |
1336 | - from.spacing.space_x = dia->data->grid.width_x; | |
1337 | - to.spacing.space_x = space_x; | |
1338 | - from.spacing.space_y = dia->data->grid.width_y; | |
1339 | - to.spacing.space_y = space_y; | |
1340 | - from.spacing.visible_x = dia->data->grid.visible_x; | |
1341 | - to.spacing.visible_x = visible_x; | |
1342 | - from.spacing.visible_x = dia->data->grid.visible_y; | |
1343 | - to.spacing.visible_x = visible_x; | |
1344 | - return undo_diagram(dia, DYNAMIC_GRID, from, to); | |
1345 | -} | |
1346 | - | |
1347 | -Change * | |
1348 | -undo_diagram_bg_color(Diagram *dia, Color *bg_color) | |
1349 | -{ | |
1350 | - DiagramChangeData from, to; | |
1351 | - from.bg_color = dia->data->bg_color; | |
1352 | - to.bg_color = *bg_color; | |
1353 | - return undo_diagram(dia, BG_COLOR, from, to); | |
1354 | -} | |
1355 | - | |
1356 | -Change * | |
1357 | -undo_diagram_grid_color(Diagram *dia, Color *grid_color) | |
1358 | -{ | |
1359 | - DiagramChangeData from, to; | |
1360 | - from.grid_color = dia->data->grid.colour; | |
1361 | - to.grid_color = *grid_color; | |
1362 | - return undo_diagram(dia, GRID_COLOR, from, to); | |
1363 | -} | |
1364 | - | |
1365 | -Change * | |
1366 | -undo_diagram_page_color(Diagram *dia, Color *page_color) | |
1367 | -{ | |
1368 | - DiagramChangeData from, to; | |
1369 | - from.page_color = dia->data->pagebreak_color; | |
1370 | - to.page_color = *page_color; | |
1371 | - return undo_diagram(dia, PAGE_COLOR, from, to); | |
1372 | -} | |
1373 | - | |
1374 | -Change * | |
1375 | -undo_diagram_paper_size(Diagram *dia, gchar *size) | |
1376 | -{ | |
1377 | - DiagramChangeData from, to; | |
1378 | - from.paper_size = g_strdup(dia->data->paper.name); | |
1379 | - to.paper_size = g_strdup(size); | |
1380 | - return undo_diagram(dia, PAPER_SIZE, from, to); | |
1381 | -} | |
1382 | - | |
1383 | -Change * | |
1384 | -undo_diagram_portrait(Diagram *dia, gboolean portrait) | |
1385 | -{ | |
1386 | - DiagramChangeData from, to; | |
1387 | - from.portrait = dia->data->paper.is_portrait; | |
1388 | - to.portrait = portrait; | |
1389 | - return undo_diagram(dia, PORTRAIT, from, to); | |
1390 | -} | |
1391 | - | |
1392 | -Change * | |
1393 | -undo_diagram_margins(Diagram *dia, real top, real bottom, | |
1394 | - real left, real right) | |
1395 | -{ | |
1396 | - DiagramChangeData from, to; | |
1397 | - from.margins.top = dia->data->paper.tmargin; | |
1398 | - to.margins.top = top ; | |
1399 | - from.margins.bottom = dia->data->paper.bmargin; | |
1400 | - to.margins.bottom = bottom ; | |
1401 | - from.margins.left = dia->data->paper.lmargin; | |
1402 | - to.margins.left = left ; | |
1403 | - from.margins.right = dia->data->paper.rmargin; | |
1404 | - to.margins.right = right ; | |
1405 | - return undo_diagram(dia, MARGINS, from, to); | |
1406 | -} | |
1407 | - | |
1408 | -Change * | |
1409 | -undo_diagram_scaling(Diagram *dia, real scale, | |
1410 | - int fit_x, int fit_y) | |
1411 | -{ | |
1412 | - DiagramChangeData from, to; | |
1413 | - if (dia->data->paper.fitto) { | |
1414 | - from.scaling.scale = 0; | |
1415 | - from.scaling.fit_x = dia->data->paper.fitwidth; | |
1416 | - from.scaling.fit_y = dia->data->paper.fitheight; | |
1417 | - } else { | |
1418 | - from.scaling.scale = dia->data->paper.scaling; | |
1419 | - from.scaling.fit_x = 0; | |
1420 | - from.scaling.fit_y = 0; | |
1421 | - } | |
1422 | - to.scaling.scale = scale; | |
1423 | - to.scaling.fit_x = fit_x; | |
1424 | - to.scaling.fit_y = fit_y; | |
1425 | - return undo_diagram(dia, SCALING, from, to); | |
1426 | -} |
@@ -329,27 +329,27 @@ set_linejoin (DiaRenderer *object, LineJoin mode) | ||
329 | 329 | renderer->join_style); |
330 | 330 | } |
331 | 331 | |
332 | -static void | |
333 | -set_linestyle (DiaRenderer *object, LineStyle mode) | |
332 | +/** Set the dashes for this renderer. | |
333 | + * offset determines where in the pattern the dashes will start. | |
334 | + * It is used by the grid in particular to make the grid dashes line up. | |
335 | + */ | |
336 | +void | |
337 | +dia_gdk_renderer_set_dashes(DiaGdkRenderer *renderer, int offset) | |
334 | 338 | { |
335 | - DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object); | |
336 | - | |
337 | 339 | char dash_list[6]; |
338 | 340 | int hole_width; |
341 | + int pattern_length; | |
339 | 342 | |
340 | - renderer->saved_line_style = mode; | |
341 | - switch(mode) { | |
343 | + switch(renderer->saved_line_style) { | |
342 | 344 | case LINESTYLE_SOLID: |
343 | - renderer->line_style = GDK_LINE_SOLID; | |
344 | 345 | break; |
345 | 346 | case LINESTYLE_DASHED: |
346 | - renderer->line_style = GDK_LINE_ON_OFF_DASH; | |
347 | 347 | dash_list[0] = renderer->dash_length; |
348 | 348 | dash_list[1] = renderer->dash_length; |
349 | - gdk_gc_set_dashes(renderer->gc, 0, dash_list, 2); | |
349 | + pattern_length = renderer->dash_length*2; | |
350 | + gdk_gc_set_dashes(renderer->gc, offset, dash_list, 2); | |
350 | 351 | break; |
351 | 352 | case LINESTYLE_DASH_DOT: |
352 | - renderer->line_style = GDK_LINE_ON_OFF_DASH; | |
353 | 353 | hole_width = (renderer->dash_length - renderer->dot_length) / 2; |
354 | 354 | if (hole_width==0) |
355 | 355 | hole_width = 1; |
@@ -357,10 +357,10 @@ set_linestyle (DiaRenderer *object, LineStyle mode) | ||
357 | 357 | dash_list[1] = hole_width; |
358 | 358 | dash_list[2] = renderer->dot_length; |
359 | 359 | dash_list[3] = hole_width; |
360 | - gdk_gc_set_dashes(renderer->gc, 0, dash_list, 4); | |
360 | + pattern_length = renderer->dash_length+renderer->dot_length+2*hole_width; | |
361 | + gdk_gc_set_dashes(renderer->gc, offset, dash_list, 2); | |
361 | 362 | break; |
362 | 363 | case LINESTYLE_DASH_DOT_DOT: |
363 | - renderer->line_style = GDK_LINE_ON_OFF_DASH; | |
364 | 364 | hole_width = (renderer->dash_length - 2*renderer->dot_length) / 3; |
365 | 365 | if (hole_width==0) |
366 | 366 | hole_width = 1; |
@@ -370,13 +370,44 @@ set_linestyle (DiaRenderer *object, LineStyle mode) | ||
370 | 370 | dash_list[3] = hole_width; |
371 | 371 | dash_list[4] = renderer->dot_length; |
372 | 372 | dash_list[5] = hole_width; |
373 | - gdk_gc_set_dashes(renderer->gc, 0, dash_list, 6); | |
373 | + pattern_length = renderer->dash_length+2*renderer->dot_length+3*hole_width; | |
374 | + gdk_gc_set_dashes(renderer->gc, offset, dash_list, 2); | |
374 | 375 | break; |
375 | 376 | case LINESTYLE_DOTTED: |
376 | - renderer->line_style = GDK_LINE_ON_OFF_DASH; | |
377 | 377 | dash_list[0] = renderer->dot_length; |
378 | 378 | dash_list[1] = renderer->dot_length; |
379 | - gdk_gc_set_dashes(renderer->gc, 0, dash_list, 2); | |
379 | + pattern_length = renderer->dot_length; | |
380 | + gdk_gc_set_dashes(renderer->gc, offset, dash_list, 2); | |
381 | + break; | |
382 | + } | |
383 | + | |
384 | +} | |
385 | + | |
386 | +static void | |
387 | +set_linestyle (DiaRenderer *object, LineStyle mode) | |
388 | +{ | |
389 | + DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object); | |
390 | + | |
391 | + renderer->saved_line_style = mode; | |
392 | + switch(mode) { | |
393 | + case LINESTYLE_SOLID: | |
394 | + renderer->line_style = GDK_LINE_SOLID; | |
395 | + break; | |
396 | + case LINESTYLE_DASHED: | |
397 | + renderer->line_style = GDK_LINE_ON_OFF_DASH; | |
398 | + dia_gdk_renderer_set_dashes(renderer, 0); | |
399 | + break; | |
400 | + case LINESTYLE_DASH_DOT: | |
401 | + renderer->line_style = GDK_LINE_ON_OFF_DASH; | |
402 | + dia_gdk_renderer_set_dashes(renderer, 0); | |
403 | + break; | |
404 | + case LINESTYLE_DASH_DOT_DOT: | |
405 | + renderer->line_style = GDK_LINE_ON_OFF_DASH; | |
406 | + dia_gdk_renderer_set_dashes(renderer, 0); | |
407 | + break; | |
408 | + case LINESTYLE_DOTTED: | |
409 | + renderer->line_style = GDK_LINE_ON_OFF_DASH; | |
410 | + dia_gdk_renderer_set_dashes(renderer, 0); | |
380 | 411 | break; |
381 | 412 | } |
382 | 413 | gdk_gc_set_line_attributes(renderer->gc, |
@@ -15,6 +15,7 @@ G_BEGIN_DECLS | ||
15 | 15 | #define DIA_GDK_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DIA_TYPE_GDK_RENDERER, DiaGdkRendererClass)) |
16 | 16 | |
17 | 17 | GType dia_gdk_renderer_get_type (void) G_GNUC_CONST; |
18 | +void dia_gdk_renderer_set_dashes(DiaGdkRenderer *renderer, int offset); | |
18 | 19 | |
19 | 20 | struct _DiaGdkRenderer |
20 | 21 | { |