author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Thu, 16 Apr 2009 12:49:12 +0200 | |
changeset 42 | 83b8151b966d |
child 43 | cf8c1b5127b2 |
permissions | -rw-r--r-- |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
1 |
/** |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
2 |
* test/demos/pmc/rectangle.cc |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
4 |
*/ |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
5 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
6 |
#include <rectangle.h> |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
7 |
#include <cstdio> |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
8 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
9 |
Rectangle::Rectangle (Surface * s) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
10 |
{ |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
11 |
P[0] = new Vector (0, 0); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
12 |
P[1] = new Vector (0, 100); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
13 |
P[2] = new Vector (100, 100); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
14 |
P[3] = new Vector (0, 100); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
15 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
16 |
anker = Vector (0, 0); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
17 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
18 |
surface = s; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
19 |
} |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
20 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
21 |
Rectangle::Rectangle (Surface * s, Vector p1, Vector p2, Vector p3, Vector p4) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
22 |
{ |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
23 |
P[0] = new Vector (p1); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
24 |
P[1] = new Vector (p2); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
25 |
P[2] = new Vector (p3); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
26 |
P[3] = new Vector (p4); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
27 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
28 |
anker = Vector (0, 0); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
29 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
30 |
surface = s; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
31 |
} |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
32 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
33 |
Rectangle::~Rectangle () |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
34 |
{ |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
35 |
for (int i = 0; i < 4; i++) { |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
36 |
#ifdef DEBUG |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
37 |
fprintf (stderr, "Removing P[%d]: ", i); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
38 |
#endif |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
39 |
delete P[i]; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
40 |
} |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
41 |
} |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
42 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
43 |
void Rectangle::move (Vector location) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
44 |
{ |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
45 |
if ((anker.X () + location.X ()) < 0) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
46 |
return; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
47 |
if ((anker.Y () + location.Y ()) < 0) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
48 |
return; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
49 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
50 |
if ((anker.X () + location.X ()) >= surface->getWidth ()) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
51 |
return; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
52 |
if ((anker.Y () + location.Y ()) >= surface->getHeight ()) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
53 |
return; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
54 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
55 |
for (int i = 0; i < 4; i++) { |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
56 |
*P[i] = *P[i] + location; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
57 |
} |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
58 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
59 |
anker = Vector (P[0]->X (), P[0]->Y ()); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
60 |
} |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
61 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
62 |
void Rectangle::show () |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
63 |
{ |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
64 |
int i; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
65 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
66 |
for (i = 0; i < 4; i++) { |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
67 |
fprintf (stderr, "[%d] ", i); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
68 |
P[i]->vector (); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
69 |
if ((i + 1) % 4 != 0) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
70 |
fprintf (stderr, ", "); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
71 |
else |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
72 |
fprintf (stderr, "\n"); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
73 |
} |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
74 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
75 |
surface->drawLine (P[0]->X (), P[0]->Y (), P[1]->X (), P[1]->Y ()); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
76 |
surface->drawLine (P[3]->X (), P[3]->Y (), P[2]->X (), P[2]->Y ()); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
77 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
78 |
surface->drawLine (P[2]->X (), P[2]->Y (), P[1]->X (), P[1]->Y ()); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
79 |
surface->drawLine (P[3]->X (), P[3]->Y (), P[0]->X (), P[0]->Y ()); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
80 |
} |