aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/FbDrawable.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/FbDrawable.cc')
-rw-r--r--src/FbTk/FbDrawable.cc64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/FbTk/FbDrawable.cc b/src/FbTk/FbDrawable.cc
index 061da0b..dd6e4a9 100644
--- a/src/FbTk/FbDrawable.cc
+++ b/src/FbTk/FbDrawable.cc
@@ -89,6 +89,70 @@ void FbDrawable::fillPolygon(GC gc, XPoint *points, int npoints,
89 shape, mode); 89 shape, mode);
90} 90}
91 91
92// x, y, width and height define a space within which we're drawing a triangle (centred)
93// scale defines number of triangles that'd fit in a space of 100 width x 100 height
94// (i.e. 200 = half size, 300 = a third). Its a bit backwards but it allows more flexibility
95void FbDrawable::drawTriangle(GC gc, FbDrawable::TriangleType type,
96 int x, int y, unsigned int width, unsigned int height,
97 int scale) {
98 if (drawable() == 0 || gc == 0 || width == 0 || height == 0)
99 return;
100
101 XPoint pts[3];
102
103 if (scale < 100) scale = 100; // not bigger than the space allowed
104 else if (scale > 10000) scale = 10000; // not too small...
105
106 int arrowscale_n = scale;
107 int arrowscale_d = 100;
108 unsigned int ax = arrowscale_d * width / arrowscale_n;
109 unsigned int ay = arrowscale_d * height / arrowscale_n;
110 // if these aren't an even number, left and right arrows end up different
111 if (type == FbTk::FbDrawable::LEFT ||
112 type == FbTk::FbDrawable::RIGHT) {
113 if (( ax % 2 ) == 1) ax--;
114 if (( ay % 2 ) == 1) ay--;
115 } else {
116 if (( ax % 2 ) == 0) ax--;
117 }
118
119 switch (type) {
120 case FbTk::FbDrawable::LEFT:
121 // start at the tip
122 pts[0].x = (width / 2) - (ax / 2); pts[0].y = height / 2;
123 pts[1].x = ax; pts[1].y = -ay / 2;
124 pts[2].x = 0; pts[2].y = ay;
125 break;
126 case FbTk::FbDrawable::RIGHT:
127 pts[0].x = (width / 2) + (ax / 2); pts[0].y = height / 2;
128 pts[1].x = - ax; pts[1].y = ay / 2;
129 pts[2].x = 0; pts[2].y = - ay;
130 break;
131 case FbTk::FbDrawable::UP:
132 pts[0].x = (width / 2); pts[0].y = (height / 2) - (ay / 2)-1;
133 pts[1].x = ax / 2; pts[1].y = ay+1;
134 pts[2].x = - ax; pts[2].y = 0;
135 break;
136 case FbTk::FbDrawable::DOWN:
137 /* I tried and tried, but couldn't get the left diagonal of the down
138 arrow to be symmetrical with the right (for small widths)!
139 So we opt for this setup. It is symmetrical with larger widths */
140 pts[0].x = (width / 2) ; pts[0].y = (height / 2) + (ay / 2);
141 pts[1].x = -ax/2+1; pts[1].y = -ay;
142 pts[2].x = ax-1; pts[2].y = 0;
143 break;
144
145 }
146
147 // re-centre on the specified points
148 pts[0].x += x;
149 pts[0].y += y;
150
151 fillPolygon(gc,
152 pts, 3,
153 Convex, CoordModePrevious);
154}
155
92#ifdef NOT_USED 156#ifdef NOT_USED
93void FbDrawable::drawPoint(GC gc, int x, int y) { 157void FbDrawable::drawPoint(GC gc, int x, int y) {
94 if (drawable() == 0 || gc == 0) 158 if (drawable() == 0 || gc == 0)