Bumped versions to 1.1.2/20070818/30:2:0 for the next development snapshot
[geda-gaf/whiteaudio.git] / gschem / src / x_grid.c
blob58a0666dcf5d4fe951974038818db9f52f20ede2
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
20 #include <config.h>
22 #include <math.h>
23 #ifdef HAVE_STRING_H
24 #include <string.h>
25 #endif
27 #include <libgeda/libgeda.h>
29 #include "../include/x_states.h"
30 #include "../include/prototype.h"
32 #ifdef HAVE_LIBDMALLOC
33 #include <dmalloc.h>
34 #endif
36 static GdkPoint points[5000];
38 /*! \todo Finish function documentation!!!
39 * \brief
40 * \par Function Description
43 void x_grid_draw(TOPLEVEL *w_current)
45 int i, j;
46 int x, y;
47 int x_start, y_start;
48 int count = 0;
50 int incr = 100;
51 int screen_incr = 0;
53 if (!w_current->grid) {
54 i_set_grid(w_current, -1);
55 return;
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 */
69 if (incr < 1){
70 incr = 1;
73 else
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 */
80 /* threshold */
81 return;
85 /* update status bar */
86 i_set_grid(w_current, incr);
88 #if DEBUG
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));
95 #endif
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
102 * increment */
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,
115 i, j)) {
117 if (w_current->grid_dot_size == 1)
119 points[count].x = x;
120 points[count].y = y;
121 count++;
123 /* get out of loop if more than 1000 points */
124 if (count == 5000) {
125 gdk_draw_points(w_current->window,
126 w_current->gc,
127 points, count);
128 gdk_draw_points(
129 w_current->backingstore,
130 w_current->gc, points, count);
131 count=0;
134 else
136 gdk_draw_arc(w_current->window, w_current->gc,
137 TRUE, x, y,
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,
141 TRUE, x, y,
142 w_current->grid_dot_size,
143 w_current->grid_dot_size, 0, FULL_CIRCLE);
149 /* now draw all the points in one step */
150 if(count != 0) {
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);
157 #if DEBUG
158 /* highly temp, just for diag purposes */
159 x_draw_tiles(w_current);
160 #endif
163 /*! \todo Finish function documentation!!!
164 * \brief
165 * \par Function Description
168 void x_draw_tiles(TOPLEVEL *w_current)
170 TILE *t_current;
171 GdkFont *font;
172 int i,j;
173 int x1, y1, x2, y2;
174 int screen_x, screen_y;
175 int width, height;
176 char *tempstring;
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);
195 #if DEBUG
196 printf("x, y: %d %d\n", screen_x, screen_y);
197 printf("w x h: %d %d\n", width, height);
198 #endif
199 gdk_draw_rectangle(w_current->window,
200 w_current->gc,
201 FALSE, screen_x, screen_y,
202 width, height);
203 gdk_draw_rectangle(w_current->backingstore,
204 w_current->gc,
205 FALSE, screen_x, screen_y,
206 width, height);
208 tempstring = g_strdup_printf("%d %d", i, j);
209 gdk_draw_text (w_current->window,
210 font,
211 w_current->gc,
212 screen_x+10, screen_y+10,
213 tempstring,
214 strlen(tempstring));
216 gdk_draw_text (w_current->backingstore,
217 font,
218 w_current->gc,
219 screen_x+10, screen_y+10,
220 tempstring,
221 strlen(tempstring));
222 g_free(tempstring);
226 gdk_font_unref(font);