1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2007 Ales Hvezda
4 * Copyright (C) 1998-2007 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
27 #include <libgeda/libgeda.h>
29 #include "../include/gschem_struct.h"
30 #include "../include/x_states.h"
31 #include "../include/prototype.h"
33 #ifdef HAVE_LIBDMALLOC
37 static GdkPoint points
[5000];
39 /*! \todo Finish function documentation!!!
41 * \par Function Description
44 void x_grid_draw(GSCHEM_TOPLEVEL
*w_current
)
46 TOPLEVEL
*toplevel
= w_current
->toplevel
;
55 if (!w_current
->grid
) {
56 i_set_grid(w_current
, -1);
60 if (w_current
->grid_mode
== GRID_VARIABLE_MODE
)
62 /* In the variable mode around every 30th screenpixel will be grid-point */
63 /* adding 0.1 for correct cast*/
64 incr
= round_5_2_1(toplevel
->page_current
->to_world_x_constant
*30)+0.1;
66 /*limit grid to snap_size; only a idea of mine, hope you like it (hw) */
67 if (incr
< toplevel
->snap_size
) {
68 incr
= toplevel
->snap_size
;
70 /* usually this should never happen */
77 incr
= toplevel
->snap_size
;
78 screen_incr
= SCREENabs(toplevel
, incr
);
79 if (screen_incr
< w_current
->grid_fixed_threshold
)
81 /* don't draw the grid if the screen incr spacing is less than the */
87 /* update status bar */
88 i_set_grid(w_current
, incr
);
91 printf("---------x_grid_draw\n incr: %d\n",incr
);
93 printf("x1 %d\n", pix_x(w_current
, 100));
94 printf("x2 %d\n", pix_x(w_current
, 200));
95 printf("y1 %d\n", pix_y(w_current
, 100));
96 printf("y2 %d\n", pix_y(w_current
, 200));
99 gdk_gc_set_foreground(w_current
->gc
,
100 x_get_color(w_current
->grid_color
));
102 /* figure starting grid coordinates, work by taking the start
103 * and end coordinates and rounding down to the nearest
105 x_start
= (toplevel
->page_current
->left
-
106 (toplevel
->page_current
->left
% incr
));
107 y_start
= (toplevel
->page_current
->top
-
108 (toplevel
->page_current
->top
% incr
));
110 for (i
= x_start
; i
< toplevel
->page_current
->right
; i
= i
+ incr
) {
111 for(j
= y_start
; j
< toplevel
->page_current
->bottom
; j
= j
+ incr
) {
112 WORLDtoSCREEN(toplevel
, i
,j
, &x
, &y
);
113 if (inside_region(toplevel
->page_current
->left
,
114 toplevel
->page_current
->top
,
115 toplevel
->page_current
->right
,
116 toplevel
->page_current
->bottom
,
119 if (w_current
->grid_dot_size
== 1)
125 /* get out of loop if more than 1000 points */
128 w_current
->backingstore
,
129 w_current
->gc
, points
, count
);
135 gdk_draw_arc(w_current
->backingstore
, w_current
->gc
,
137 w_current
->grid_dot_size
,
138 w_current
->grid_dot_size
, 0, FULL_CIRCLE
);
144 /* now draw all the points in one step */
146 gdk_draw_points(w_current
->backingstore
,
147 w_current
->gc
, points
, count
);
151 /* highly temp, just for diag purposes */
152 x_draw_tiles(w_current
);
156 /*! \todo Finish function documentation!!!
158 * \par Function Description
161 void x_draw_tiles(GSCHEM_TOPLEVEL
*w_current
)
163 TOPLEVEL
*toplevel
= w_current
->toplevel
;
168 int screen_x
, screen_y
;
172 gdk_gc_set_foreground(w_current
->gc
, x_get_color(w_current
->lock_color
));
174 font
= gdk_fontset_load ("fixed");
175 for (j
= 0; j
< MAX_TILES_Y
; j
++) {
176 for (i
= 0; i
< MAX_TILES_X
; i
++) {
177 t_current
= &toplevel
->page_current
->world_tiles
[i
][j
];
178 WORLDtoSCREEN(toplevel
, t_current
->left
,
179 t_current
->top
, &x1
, &y1
);
180 WORLDtoSCREEN(toplevel
, t_current
->right
,
181 t_current
->bottom
, &x2
, &y2
);
183 screen_x
= min(x1
, x2
);
184 screen_y
= min(y1
, y2
);
186 width
= abs(x1
- x2
);
187 height
= abs(y1
- y2
);
190 printf("x, y: %d %d\n", screen_x
, screen_y
);
191 printf("w x h: %d %d\n", width
, height
);
193 gdk_draw_rectangle(w_current
->backingstore
,
195 FALSE
, screen_x
, screen_y
,
198 tempstring
= g_strdup_printf("%d %d", i
, j
);
200 gdk_draw_text (w_current
->backingstore
,
203 screen_x
+10, screen_y
+10,
210 gdk_font_unref(font
);