author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Fri, 01 May 2009 18:27:06 +0200 | |
changeset 89 | 66f0244c2863 |
parent 77 | 49e0babccb23 |
permissions | -rw-r--r-- |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
1 |
/** |
77 | 2 |
* pmc/rectangle.cc |
42
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 |
|
65
76514757b0d6
GNU Indent cannot handle C++ Source Files...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
54
diff
changeset
|
6 |
#include <rectangle.hpp> |
42
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 |
|
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
9 |
using namespace algebra; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
10 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
11 |
Rectangle::Rectangle (Surface * s) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
12 |
{ |
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
13 |
surface = s; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
14 |
name = "Rectangle"; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
15 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
16 |
anker = Vector (0, 0); |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
17 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
18 |
P[0] = new Vector (0, 0); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
19 |
P[1] = new Vector (0, 100); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
20 |
P[2] = new Vector (100, 100); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
21 |
P[3] = new Vector (0, 100); |
54
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
22 |
|
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
23 |
refCounter++; |
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
24 |
} |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
25 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
26 |
Rectangle::Rectangle (Surface * s, Vector & p1, Vector & p2, Vector & p3, Vector & p4) |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
27 |
{ |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
28 |
surface = s; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
29 |
name = "Rectangle"; |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
30 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
31 |
anker = Vector (0, 0); |
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 |
P[0] = new Vector (p1); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
34 |
P[1] = new Vector (p2); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
35 |
P[2] = new Vector (p3); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
36 |
P[3] = new Vector (p4); |
54
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
37 |
|
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
38 |
refCounter++; |
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
39 |
} |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
40 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
41 |
Rectangle::Rectangle (Surface * s, Vector p[4]) |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
42 |
{ |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
43 |
surface = s; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
44 |
name = "Rectangle"; |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
45 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
46 |
anker = Vector (0, 0); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
47 |
|
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
48 |
for (int i = 0; i < 4; i++) { |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
49 |
P[i] = new Vector (p[i]); |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
50 |
} |
54
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
51 |
|
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
52 |
refCounter++; |
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
53 |
} |
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
54 |
|
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
55 |
Rectangle::Rectangle (const Rectangle & copy) |
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
56 |
{ |
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
57 |
fprintf (stderr, "Copy Constructor in Rectangle disabled...\n"); |
42
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 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
60 |
Rectangle::~Rectangle () |
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 |
for (int i = 0; i < 4; i++) { |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
63 |
#ifdef DEBUG |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
64 |
fprintf (stderr, "Removing P[%d]: ", i); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
65 |
#endif |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
66 |
delete P[i]; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
67 |
} |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
68 |
} |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
69 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
70 |
void Rectangle::move (Vector location) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
71 |
{ |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
72 |
if ((anker.X () + location.X ()) < 0) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
73 |
return; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
74 |
if ((anker.Y () + location.Y ()) < 0) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
75 |
return; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
76 |
|
46
4b9e1ac40246
pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
45
diff
changeset
|
77 |
if ((anker.X () + location.X ()) > surface->getWidth ()) |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
78 |
return; |
46
4b9e1ac40246
pmc: Screen Depth Fix: Paint on 8, 16 and 32 bpp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
45
diff
changeset
|
79 |
if ((anker.Y () + location.Y ()) > surface->getHeight ()) |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
80 |
return; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
81 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
82 |
for (int i = 0; i < 4; i++) { |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
83 |
*P[i] = *P[i] + location; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
84 |
} |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
85 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
86 |
anker = Vector (P[0]->X (), P[0]->Y ()); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
87 |
} |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
88 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
89 |
void Rectangle::show () |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
90 |
{ |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
91 |
int i; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
92 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
93 |
for (i = 0; i < 4; i++) { |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
94 |
fprintf (stderr, "[%d] ", i); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
95 |
P[i]->vector (); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
96 |
if ((i + 1) % 4 != 0) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
97 |
fprintf (stderr, ", "); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
98 |
else |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
99 |
fprintf (stderr, "\n"); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
100 |
} |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
101 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
102 |
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
|
103 |
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
|
104 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
} |