summaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/FbDrawable.cc64
-rw-r--r--src/FbTk/FbDrawable.hh14
-rw-r--r--src/FbTk/MenuItem.cc27
3 files changed, 85 insertions, 20 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)
diff --git a/src/FbTk/FbDrawable.hh b/src/FbTk/FbDrawable.hh
index 7590f54..8d91377 100644
--- a/src/FbTk/FbDrawable.hh
+++ b/src/FbTk/FbDrawable.hh
@@ -48,6 +48,20 @@ public:
48 virtual void fillPolygon(GC gc, XPoint *points, int npoints, 48 virtual void fillPolygon(GC gc, XPoint *points, int npoints,
49 int shape, int mode); 49 int shape, int mode);
50 50
51 /// type of arrow that should be drawn
52 enum TriangleType {
53 LEFT,
54 RIGHT,
55 UP,
56 DOWN
57 };
58
59 // x, y, width and height define a space within which we're drawing a triangle
60 // scale defines number of triangles that'd fit in a space of 100 width x 100 height
61 // (i.e. 200 = half size, 300 = a third).
62
63 virtual void drawTriangle(GC gc, TriangleType type, int x, int y, unsigned int width, unsigned int height, int scale);
64
51#ifdef NOT_USED 65#ifdef NOT_USED
52 virtual void drawPoint(GC gc, int x, int y); 66 virtual void drawPoint(GC gc, int x, int y);
53#endif 67#endif
diff --git a/src/FbTk/MenuItem.cc b/src/FbTk/MenuItem.cc
index fafedc0..a2c3fe2 100644
--- a/src/FbTk/MenuItem.cc
+++ b/src/FbTk/MenuItem.cc
@@ -216,26 +216,13 @@ void MenuItem::draw(FbDrawable &draw,
216 break; 216 break;
217 217
218 case MenuTheme::TRIANGLE: 218 case MenuTheme::TRIANGLE:
219 XPoint tri[3]; 219 draw.drawTriangle(gc, ((theme.bulletPos() == FbTk::RIGHT)?
220 220 FbTk::FbDrawable::RIGHT:
221 if (theme.bulletPos() == FbTk::RIGHT) { 221 FbTk::FbDrawable::LEFT),
222 tri[0].x = sel_x + half_w - 2; 222 sel_x, sel_y,
223 tri[0].y = sel_y + half_w - 2; 223 item_pm_height,
224 tri[1].x = 4; 224 item_pm_height,
225 tri[1].y = 2; 225 300); // 33% triangle
226 tri[2].x = -4;
227 tri[2].y = 2;
228 } else { // point the other way
229 tri[0].x = sel_x + half_w - 2;
230 tri[0].y = sel_y + half_w;
231 tri[1].x = 4;
232 tri[1].y = 2;
233 tri[2].x = 0;
234 tri[2].y = -4;
235 }
236
237 draw.fillPolygon(gc, tri, 3, Convex,
238 CoordModePrevious);
239 break; 226 break;
240 227
241 case MenuTheme::DIAMOND: 228 case MenuTheme::DIAMOND: