1 /* BurrTools
2 *
3 * BurrTools is the legal property of its developers, whose
4 * names are listed in the COPYRIGHT file, which is included
5 * within the source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21 #include "grideditor_2.h"
22
23 #include "../lib/voxel.h"
24 #include "../lib/puzzle.h"
25
26 #include "../tools/intdiv.h"
27
28 #include <FL/fl_draw.H>
29
30 // this function calculates the size of the circles and the starting position
31 // for the grid inside the available space of the widget
calcParameters(int * szx,int * szy,int * tx,int * ty)32 void gridEditor_2_c::calcParameters(int *szx, int *szy, int *tx, int *ty) {
33
34 // find out how many circles there must fit (this is double the
35 // size of the circles, so that we can have halve circles
36 int cx = puzzle->getShape(piecenumber)->getX();
37 int cy = puzzle->getShape(piecenumber)->getY();
38
39 // calculate the size of the squares
40 int sx = (w() > 2) ? ((10*w()-30)/(10*cx+6)) : 0;
41 int sy = (h() > 2) ? ((10*h()-30)/(10*cy+6)) : 0;
42
43 *szx = (sx < sy) ? sx : sy;
44
45 if (*szx > 20) *szx = 20;
46
47 *szy = *szx;
48 sx = sy = *szx;
49
50 *tx = x() + (w() - cx*sx) / 2;
51 *ty = y()+h()-1 - (h() - cy*sy) / 2;
52 }
53
drawNormalTile(int x,int y,int z,int tx,int ty,int sx,int sy)54 void gridEditor_2_c::drawNormalTile(int x, int y, int z, int tx, int ty, int sx, int sy) {
55
56 bt_assert(puzzle->getShape(piecenumber)->validCoordinate(x, y, z));
57
58 int sxc = 10000*sx/7072;
59 int syc = 10000*sy/7072;
60
61 tx -= 3*sx/10;
62 ty -= 3*sy/10;
63
64 fl_pie(tx+x*sx, ty-y*sy-sy, sxc, syc, 0, 360);
65 }
66
drawVariableTile(int x,int y,int z,int tx,int ty,int sx,int sy)67 void gridEditor_2_c::drawVariableTile(int x, int y, int z, int tx, int ty, int sx, int sy) {
68
69 bt_assert(puzzle->getShape(piecenumber)->validCoordinate(x, y, z));
70
71 int sxc = 10000*sx/7072;
72 int syc = 10000*sy/7072;
73
74 tx -= 3*sx/10;
75 ty -= 3*sy/10;
76
77 fl_pie(tx+x*sx+2, ty-y*sy+2-sy, sxc-4, syc-4, 0, 360);
78 }
79
drawTileFrame(int x,int y,int z,int tx,int ty,int sx,int sy)80 void gridEditor_2_c::drawTileFrame(int x, int y, int z, int tx, int ty, int sx, int sy) {
81
82 bt_assert(puzzle->getShape(piecenumber)->validCoordinate(x, y, z));
83
84 int sxc = 10000*sx/7072;
85 int syc = 10000*sy/7072;
86
87 tx -= 3*sx/10;
88 ty -= 3*sy/10;
89
90 fl_arc(tx+x*sx, ty-y*sy-sy, sxc, syc, 0, 360);
91 }
92
drawTileColor(int x,int y,int z,int tx,int ty,int sx,int sy)93 void gridEditor_2_c::drawTileColor(int x, int y, int z, int tx, int ty, int sx, int sy) {
94
95 bt_assert(puzzle->getShape(piecenumber)->validCoordinate(x, y, z));
96
97 int sxc = 10000*sx/7072;
98 int syc = 10000*sy/7072;
99
100 tx -= 3*sx/20;
101 ty -= 3*sy/20;
102
103 fl_pie(tx+x*sx, ty-y*sy-sy, sxc/2, syc/2, 0, 360);
104 }
105
drawTileCursor(int x,int y,int,int tx,int ty,int sx,int sy)106 void gridEditor_2_c::drawTileCursor(int x, int y, int /*z*/, int tx, int ty, int sx, int sy) {
107
108 int sxc = 10000*sx/7072;
109 int syc = 10000*sy/7072;
110
111 tx -= 3*sx/10;
112 ty -= 3*sy/10;
113
114 if (inRegion(x, y)) {
115
116 fl_arc(tx+x*sx-1, ty-y*sy-sy-1, sxc+2, syc+2, 0, 360);
117
118 fl_arc(tx+x*sx-1, ty-y*sy-sy-1, sxc+1, syc+1, 0, 360);
119 fl_arc(tx+x*sx, ty-y*sy-sy-1, sxc+1, syc+1, 0, 360);
120 fl_arc(tx+x*sx-1, ty-y*sy-sy, sxc+1, syc+1, 0, 360);
121 fl_arc(tx+x*sx, ty-y*sy-sy, sxc+1, syc+1, 0, 360);
122 }
123 }
124
calcGridPosition(int x,int y,int,int * gx,int * gy)125 bool gridEditor_2_c::calcGridPosition(int x, int y, int /*z*/, int *gx, int *gy) {
126
127 voxel_c * space = puzzle->getShape(piecenumber);
128
129 int sx, sy, tx, ty;
130 calcParameters(&sx, &sy, &tx, &ty);
131
132 if (sx == 0 || sy == 0) return false;
133
134 x -= tx;
135 y -= (ty-sy*space->getY());
136
137 x = intdiv_inf(x, sx);
138 y = intdiv_inf(y, sy);
139
140 *gx = x;
141 *gy = space->getY() - y - 1;
142
143 return true;
144 }
145
146