Thu, 21 Mar 2013 12:57:06 +0200
Scroll the color picker dialog to the selected color if it's off-screen
30
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
1 | /* |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
3 | * Copyright (C) 2013 Santeri `arezey` Piippo |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
4 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
8 | * (at your option) any later version. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
9 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
13 | * GNU General Public License for more details. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
14 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
17 | */ |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
26
diff
changeset
|
18 | |
0 | 19 | #include "common.h" |
20 | #include "bbox.h" | |
21 | #include "ldtypes.h" | |
26
83184d9407c7
Renamed io.cpp to file.cpp, draw.cpp to gldraw.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
22 | #include "file.h" |
0 | 23 | |
24 | void bbox::calculate () { | |
3
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
25 | if (!g_CurrentFile) |
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
26 | return; |
2b78cf8634c3
don't crash if g_CurrentFile is null
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
27 | |
0 | 28 | // The bounding box, bbox for short, is the |
29 | // box that encompasses the model we have open. | |
30 | // v0 is the minimum vertex, v1 is the maximum vertex. | |
31 | for (uint i = 0; i < g_CurrentFile->objects.size(); i++) { | |
32 | LDObject* obj = g_CurrentFile->objects[i]; | |
33 | switch (obj->getType ()) { | |
34 | ||
35 | case OBJ_Line: | |
36 | { | |
37 | LDLine* line = static_cast<LDLine*> (obj); | |
38 | for (short i = 0; i < 2; ++i) | |
39 | checkVertex (line->vaCoords[i]); | |
40 | } | |
41 | break; | |
42 | ||
43 | case OBJ_Triangle: | |
44 | { | |
45 | LDTriangle* tri = static_cast<LDTriangle*> (obj); | |
46 | for (short i = 0; i < 3; ++i) | |
47 | checkVertex (tri->vaCoords[i]); | |
48 | } | |
49 | break; | |
50 | ||
51 | case OBJ_Quad: | |
52 | { | |
53 | LDQuad* quad = static_cast<LDQuad*> (obj); | |
54 | for (short i = 0; i < 4; ++i) | |
55 | checkVertex (quad->vaCoords[i]); | |
56 | } | |
57 | break; | |
58 | ||
59 | case OBJ_CondLine: | |
60 | { | |
61 | LDCondLine* line = static_cast<LDCondLine*> (obj); | |
40
215b9f8f0cd7
Added triangle, quad and condline to the add object dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
62 | for (short i = 0; i < 4; ++i) |
0 | 63 | checkVertex (line->vaCoords[i]); |
64 | } | |
65 | break; | |
66 | ||
67 | default: | |
68 | break; | |
69 | } | |
70 | } | |
71 | } | |
72 | ||
73 | #define CHECK_DIMENSION(V,X) \ | |
74 | if (V.X < v0.X) v0.X = V.X; \ | |
75 | if (V.X > v1.X) v1.X = V.X; | |
76 | void bbox::checkVertex (vertex v) { | |
77 | CHECK_DIMENSION (v, x) | |
78 | CHECK_DIMENSION (v, y) | |
79 | CHECK_DIMENSION (v, z) | |
80 | } | |
81 | #undef CHECK_DIMENSION | |
82 | ||
83 | bbox::bbox () { | |
84 | memset (&v0, 0, sizeof v0); | |
85 | memset (&v1, 0, sizeof v1); | |
86 | } |