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/x_states.h"
30 #include "../include/prototype.h"
32 #ifdef HAVE_LIBDMALLOC
36 static GdkPoint points
[5000];
38 /*! \todo Finish function documentation!!!
40 * \par Function Description
43 void x_grid_draw(TOPLEVEL
*w_current
)
53 if (!w_current
->grid
) {
54 i_set_grid(w_current
, -1);
58 if (w_current
->grid_mode
== GRID_VARIABLE_MODE
)
60 /* In the variable mode around every 30th screenpixel will be grid-point */
61 /* adding 0.1 for correct cast*/
62 incr
= round_5_2_1(w_current
->page_current
->to_world_x_constant
*30)+0.1;
64 /*limit grid to snap_size; only a idea of mine, hope you like it (hw) */
65 if (incr
< w_current
->snap_size
) {
66 incr
= w_current
->snap_size
;
68 /* usually this should never happen */
75 incr
= w_current
->snap_size
;
76 screen_incr
= SCREENabs(w_current
, incr
);
77 if (screen_incr
< w_current
->grid_fixed_threshold
)
79 /* don't draw the grid if the screen incr spacing is less than the */
85 /* update status bar */
86 i_set_grid(w_current
, incr
);
89 printf("---------x_grid_draw\n incr: %d\n",incr
);
91 printf("x1 %d\n", pix_x(w_current
, 100));
92 printf("x2 %d\n", pix_x(w_current
, 200));
93 printf("y1 %d\n", pix_y(w_current
, 100));
94 printf("y2 %d\n", pix_y(w_current
, 200));
97 gdk_gc_set_foreground(w_current
->gc
,
98 x_get_color(w_current
->grid_color
));
100 /* figure starting grid coordinates, work by taking the start
101 * and end coordinates and rounding down to the nearest
103 x_start
= (w_current
->page_current
->left
-
104 (w_current
->page_current
->left
% incr
));
105 y_start
= (w_current
->page_current
->top
-
106 (w_current
->page_current
->top
% incr
));
108 for (i
= x_start
; i
< w_current
->page_current
->right
; i
= i
+ incr
) {
109 for(j
= y_start
; j
< w_current
->page_current
->bottom
; j
= j
+ incr
) {
110 WORLDtoSCREEN(w_current
, i
,j
, &x
, &y
);
111 if (inside_region(w_current
->page_current
->left
,
112 w_current
->page_current
->top
,
113 w_current
->page_current
->right
,
114 w_current
->page_current
->bottom
,
117 if (w_current
->grid_dot_size
== 1)
123 /* get out of loop if more than 1000 points */
125 gdk_draw_points(w_current
->window
,
129 w_current
->backingstore
,
130 w_current
->gc
, points
, count
);
136 gdk_draw_arc(w_current
->window
, w_current
->gc
,
138 w_current
->grid_dot_size
,
139 w_current
->grid_dot_size
, 0, FULL_CIRCLE
);
140 gdk_draw_arc(w_current
->backingstore
, w_current
->gc
,
142 w_current
->grid_dot_size
,
143 w_current
->grid_dot_size
, 0, FULL_CIRCLE
);
149 /* now draw all the points in one step */
151 gdk_draw_points(w_current
->window
,
152 w_current
->gc
, points
, count
);
153 gdk_draw_points(w_current
->backingstore
,
154 w_current
->gc
, points
, count
);
158 /* highly temp, just for diag purposes */
159 x_draw_tiles(w_current
);
163 /*! \todo Finish function documentation!!!
165 * \par Function Description
168 void x_draw_tiles(TOPLEVEL
*w_current
)
174 int screen_x
, screen_y
;
178 gdk_gc_set_foreground(w_current
->gc
, x_get_color(w_current
->lock_color
));
180 font
= gdk_fontset_load ("fixed");
181 for (j
= 0; j
< MAX_TILES_Y
; j
++) {
182 for (i
= 0; i
< MAX_TILES_X
; i
++) {
183 t_current
= &w_current
->page_current
->world_tiles
[i
][j
];
184 WORLDtoSCREEN(w_current
, t_current
->left
,
185 t_current
->top
, &x1
, &y1
);
186 WORLDtoSCREEN(w_current
, t_current
->right
,
187 t_current
->bottom
, &x2
, &y2
);
189 screen_x
= min(x1
, x2
);
190 screen_y
= min(y1
, y2
);
192 width
= abs(x1
- x2
);
193 height
= abs(y1
- y2
);
196 printf("x, y: %d %d\n", screen_x
, screen_y
);
197 printf("w x h: %d %d\n", width
, height
);
199 gdk_draw_rectangle(w_current
->window
,
201 FALSE
, screen_x
, screen_y
,
203 gdk_draw_rectangle(w_current
->backingstore
,
205 FALSE
, screen_x
, screen_y
,
208 tempstring
= g_strdup_printf("%d %d", i
, j
);
209 gdk_draw_text (w_current
->window
,
212 screen_x
+10, screen_y
+10,
216 gdk_draw_text (w_current
->backingstore
,
219 screen_x
+10, screen_y
+10,
226 gdk_font_unref(font
);