original 1.0.1 release
[xwelltris.git] / src / welldrawing.cxx
blob74e59e28ee6959761d5ee2e2d9d42007955b3db2
1 // docm_prefix(///)
2 /****************************************************************************
3 * Copyright (C) 2002 by Leo Khramov
4 * email: leo@xnc.dubna.su
5 *
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.
15 ****************************************************************************/
16 // $Id: welldrawing.cxx,v 1.1.1.1 2003/01/04 11:37:22 leo Exp $
17 #include "globals.h"
18 #include "welldrawing.h"
20 //===========================================================================
21 /// global init(int n_fields, int dx, int dy, unsigned l, unsigned h)
22 /// init indexes and allocate FieldPoints
23 /// tags WellDrawingEngine
24 void WellDrawingEngine::init(int inum_fields, int idx, int idy,
25 unsigned int il, unsigned int ih)
27 l=il;h=ih;
28 delta_x=idx;
29 delta_y=idy;
30 current_id=0;
31 num_fields=inum_fields;
32 points=new FieldPoints[num_fields];
33 inner_max_alpha=0.0;
34 f_step=1;
38 //===========================================================================
39 /// global flush_dirty()
40 /// pseudo function that need flush dirty rec to the screen,
41 /// here it only delete dirty rect from queue
42 /// tags WellDrawingEngine
43 void WellDrawingEngine::flush_dirty()
45 DirtyList *plist;
46 do
48 plist=dirty_list.get_next();
49 if(plist)
51 //Here we need to draw dirty rec on the screen -> will be in overloaded childs
53 plist->del_self();
54 delete plist;
56 } while(plist);
61 void WellDrawingEngine::draw_square(int color, int x, int y)
66 void WellDrawingEngine::draw_trapazoid(int color, int x, int y)
71 void WellDrawingEngine::sync()
76 void WellDrawingEngine::flush_all()
81 void WellDrawingEngine::bell(int)
87 //===========================================================================
88 /// global outer_rotation()
89 /// make shift current field id -> switch to next field -> rotate it
90 /// tags WellDrawingEngine
91 void WellDrawingEngine::outer_rotation()
93 current_id+=f_step;
94 if(current_id>=num_fields)
96 f_step*=-1;
97 current_id+=(f_step+f_step);
99 if(current_id<0)
101 f_step*=-1;
102 current_id+=(f_step+f_step);
107 //===========================================================================
108 /// global set_field_sizes(int dx, int dy, int wall_delta, int base_delta)
109 /// set and calculate base vars
110 /// tags WellDrawingEngine
111 void WellDrawingEngine::set_field_sizes(int idx, int idy,
112 int ipix_wall_delta,
113 int ipix_base_delta)
115 pix_dx=idx;
116 pix_dy=idy;
117 pix_wall_delta=ipix_wall_delta;
118 pix_base_delta=ipix_base_delta;
119 pix_base_width=pix_base_delta*MAX_WIDTH;
120 pix_max_delta=pix_wall_delta*MAX_DEPTH;
121 pix_max_width=pix_base_width + 2*pix_max_delta;
124 //===========================================================================
125 /// global calc_grid_points()
126 /// calculate all points for each field, rotate it with inner and
127 /// outer alpha angle
128 /// tags WellDrawingEngine
129 void WellDrawingEngine::calc_grid_points()
131 int gi,i,j,w,x,y,n;
132 float alpha;
133 center_x=pix_dx+pix_max_width/2;
134 center_y=pix_dy+pix_max_width/2;
135 for(n=0;n<num_fields;n++) //For each field
137 //Calculate points for the walls
138 for(gi=0;gi<MAX_PERIMETER;gi++)
139 for(j=0;j<MAX_DEPTH+1;j++)
141 w=gi/MAX_WIDTH; //calc wall number
142 i=gi-w*MAX_WIDTH; //and delta inside it
143 switch(w)
145 case 0:
146 x=j*pix_wall_delta + (i*(pix_max_width - 2*pix_wall_delta*j))/MAX_WIDTH;
147 y=j*pix_wall_delta;
148 break;
149 case 1:
150 x=pix_max_width - j*pix_wall_delta;
151 y=j*pix_wall_delta + (i*(pix_max_width - 2*pix_wall_delta*j))/MAX_WIDTH;
152 break;
153 case 2:
154 x=pix_max_width - (j*pix_wall_delta +
155 (i*(pix_max_width - 2*pix_wall_delta*j))/MAX_WIDTH);
156 y=pix_max_width - j*pix_wall_delta;
157 break;
158 case 3:
159 x=j*pix_wall_delta;
160 y=pix_max_width - (j*pix_wall_delta +
161 (i*(pix_max_width - 2*pix_wall_delta*j))/MAX_WIDTH);
162 break;
164 // dbgprintf(("i=%2d, j=%2d -> x=%4d, y=%4d\n",i,j,x,y));
165 x+=pix_dx;
166 y+=pix_dy;
167 alpha=
168 inner_max_alpha*float(j)/float(MAX_DEPTH)*float(n)/float(num_fields-1)+
169 float(n)*outer_max_alpha/float(num_fields-1);
171 if(alpha!=0.0) //lets make rotation
173 points[n].wall_points[gi][j].x=int(
174 float((x-center_x))*cos(alpha) -
175 float((y-center_y))*sin(alpha) +
176 center_x);
178 points[n].wall_points[gi][j].y=int(
179 float((x-center_x))*sin(alpha) +
180 float((y-center_y))*cos(alpha) +
181 center_y);
183 } else
185 points[n].wall_points[gi][j].x=x;
186 points[n].wall_points[gi][j].y=y;
189 for(j=0;j<MAX_DEPTH+1;j++)
190 points[n].wall_points[MAX_PERIMETER][j]=points[n].wall_points[0][j];
192 //Calculate points for the base (floor) of the glass
193 for(i=0;i<MAX_WIDTH+1;i++)
194 for(j=0;j<MAX_WIDTH+1;j++)
196 x=pix_dx + pix_max_delta + i*pix_base_delta;
197 y=pix_dy + pix_max_delta + j*pix_base_delta;
198 alpha=
199 float(n)*inner_max_alpha/float(num_fields-1) +
200 float(n)*outer_max_alpha/float(num_fields-1);
201 if(alpha!=0.0) //lets make rotation
203 points[n].base_points[i][j].x=int(
204 float((x-center_x))*cos(alpha) -
205 float((y-center_y))*sin(alpha) +
206 center_x);
208 points[n].base_points[i][j].y=int(
209 float((x-center_x))*sin(alpha) +
210 float((y-center_y))*cos(alpha) +
211 center_y);
213 } else
215 points[n].base_points[i][j].x=x;
216 points[n].base_points[i][j].y=y;