Always redraw the screen using a blit from the backbuffer.
[geda-gaf/peter-b.git] / gschem / src / x_grid.c
blob8074bc16a3062f9b8b71e0061ccc93362e1dc6a3
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/gschem_struct.h"
30 #include "../include/x_states.h"
31 #include "../include/prototype.h"
33 #ifdef HAVE_LIBDMALLOC
34 #include <dmalloc.h>
35 #endif
37 static GdkPoint points[5000];
39 /*! \todo Finish function documentation!!!
40 * \brief
41 * \par Function Description
44 void x_grid_draw(GSCHEM_TOPLEVEL *w_current)
46 TOPLEVEL *toplevel = w_current->toplevel;
47 int i, j;
48 int x, y;
49 int x_start, y_start;
50 int count = 0;
52 int incr = 100;
53 int screen_incr = 0;
55 if (!w_current->grid) {
56 i_set_grid(w_current, -1);
57 return;
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 */
71 if (incr < 1){
72 incr = 1;
75 else
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 */
82 /* threshold */
83 return;
87 /* update status bar */
88 i_set_grid(w_current, incr);
90 #if DEBUG
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));
97 #endif
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
104 * increment */
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,
117 i, j)) {
119 if (w_current->grid_dot_size == 1)
121 points[count].x = x;
122 points[count].y = y;
123 count++;
125 /* get out of loop if more than 1000 points */
126 if (count == 5000) {
127 gdk_draw_points(
128 w_current->backingstore,
129 w_current->gc, points, count);
130 count=0;
133 else
135 gdk_draw_arc(w_current->backingstore, w_current->gc,
136 TRUE, x, y,
137 w_current->grid_dot_size,
138 w_current->grid_dot_size, 0, FULL_CIRCLE);
144 /* now draw all the points in one step */
145 if(count != 0) {
146 gdk_draw_points(w_current->backingstore,
147 w_current->gc, points, count);
150 #if DEBUG
151 /* highly temp, just for diag purposes */
152 x_draw_tiles(w_current);
153 #endif
156 /*! \todo Finish function documentation!!!
157 * \brief
158 * \par Function Description
161 void x_draw_tiles(GSCHEM_TOPLEVEL *w_current)
163 TOPLEVEL *toplevel = w_current->toplevel;
164 TILE *t_current;
165 GdkFont *font;
166 int i,j;
167 int x1, y1, x2, y2;
168 int screen_x, screen_y;
169 int width, height;
170 char *tempstring;
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);
189 #if DEBUG
190 printf("x, y: %d %d\n", screen_x, screen_y);
191 printf("w x h: %d %d\n", width, height);
192 #endif
193 gdk_draw_rectangle(w_current->backingstore,
194 w_current->gc,
195 FALSE, screen_x, screen_y,
196 width, height);
198 tempstring = g_strdup_printf("%d %d", i, j);
200 gdk_draw_text (w_current->backingstore,
201 font,
202 w_current->gc,
203 screen_x+10, screen_y+10,
204 tempstring,
205 strlen(tempstring));
206 g_free(tempstring);
210 gdk_font_unref(font);