diff options
Diffstat (limited to 'src/ArrowButton.cc')
-rw-r--r-- | src/ArrowButton.cc | 52 |
1 files changed, 7 insertions, 45 deletions
diff --git a/src/ArrowButton.cc b/src/ArrowButton.cc index aa319d6..e1a2fc9 100644 --- a/src/ArrowButton.cc +++ b/src/ArrowButton.cc | |||
@@ -24,27 +24,27 @@ | |||
24 | #include "ArrowButton.hh" | 24 | #include "ArrowButton.hh" |
25 | #include "ButtonTheme.hh" | 25 | #include "ButtonTheme.hh" |
26 | 26 | ||
27 | ArrowButton::ArrowButton(ArrowButton::Type arrow_type, | 27 | ArrowButton::ArrowButton(FbTk::FbDrawable::TriangleType arrow_type, |
28 | const FbTk::FbWindow &parent, | 28 | const FbTk::FbWindow &parent, |
29 | int x, int y, | 29 | int x, int y, |
30 | unsigned int width, unsigned int height): | 30 | unsigned int width, unsigned int height): |
31 | FbTk::Button(parent, x, y, width, height), | 31 | FbTk::Button(parent, x, y, width, height), |
32 | m_arrow_type(arrow_type), | 32 | m_arrow_type(arrow_type), |
33 | m_mouse_handler(0), | 33 | m_mouse_handler(0), |
34 | m_arrowscale(300) { | 34 | m_arrowscale(250) { |
35 | 35 | ||
36 | setEventMask(ExposureMask | ButtonPressMask | ButtonReleaseMask | | 36 | setEventMask(ExposureMask | ButtonPressMask | ButtonReleaseMask | |
37 | EnterWindowMask | LeaveWindowMask); | 37 | EnterWindowMask | LeaveWindowMask); |
38 | } | 38 | } |
39 | 39 | ||
40 | ArrowButton::ArrowButton(ArrowButton::Type arrow_type, | 40 | ArrowButton::ArrowButton(FbTk::FbDrawable::TriangleType arrow_type, |
41 | int screen_num, | 41 | int screen_num, |
42 | int x, int y, | 42 | int x, int y, |
43 | unsigned int width, unsigned int height): | 43 | unsigned int width, unsigned int height): |
44 | FbTk::Button(screen_num, x, y, width, height), | 44 | FbTk::Button(screen_num, x, y, width, height), |
45 | m_arrow_type(arrow_type), | 45 | m_arrow_type(arrow_type), |
46 | m_mouse_handler(0), | 46 | m_mouse_handler(0), |
47 | m_arrowscale(300) { | 47 | m_arrowscale(250) { |
48 | 48 | ||
49 | setEventMask(ExposureMask | ButtonPressMask | ButtonReleaseMask | | 49 | setEventMask(ExposureMask | ButtonPressMask | ButtonReleaseMask | |
50 | EnterWindowMask | LeaveWindowMask); | 50 | EnterWindowMask | LeaveWindowMask); |
@@ -84,46 +84,8 @@ void ArrowButton::leaveNotifyEvent(XCrossingEvent &ce) { | |||
84 | redraws the arrow button | 84 | redraws the arrow button |
85 | */ | 85 | */ |
86 | void ArrowButton::drawArrow() { | 86 | void ArrowButton::drawArrow() { |
87 | XPoint pts[3]; | 87 | if (gc() != 0) |
88 | unsigned int w = width(); | 88 | drawTriangle(gc(), m_arrow_type, 0, 0, width(), height(), m_arrowscale); |
89 | unsigned int h = height(); | ||
90 | |||
91 | int arrowscale_n = m_arrowscale; | ||
92 | int arrowscale_d = 100; | ||
93 | unsigned int ax = arrowscale_d * w / arrowscale_n; | ||
94 | unsigned int ay = arrowscale_d * h / arrowscale_n; | ||
95 | // if these aren't an even number, left and right arrows end up different | ||
96 | if (( ax % 2 ) == 1) ax++; | ||
97 | if (( ay % 2 ) == 1) ay++; | ||
98 | switch (m_arrow_type) { | ||
99 | case LEFT: | ||
100 | // start at the tip | ||
101 | pts[0].x = (w / 2) - (ax / 2); pts[0].y = h / 2; | ||
102 | pts[1].x = ax; pts[1].y = -ay / 2; | ||
103 | pts[2].x = 0; pts[2].y = ay; | ||
104 | break; | ||
105 | case RIGHT: | ||
106 | pts[0].x = (w / 2) + (ax / 2); pts[0].y = h / 2; | ||
107 | pts[1].x = - ax; pts[1].y = ay / 2; | ||
108 | pts[2].x = 0; pts[2].y = - ay; | ||
109 | break; | ||
110 | case UP: | ||
111 | pts[0].x = (w / 2); pts[0].y = (h / 2) - (ay / 2); | ||
112 | pts[1].x = ax / 2; pts[1].y = ay; | ||
113 | pts[2].x = - ax; pts[2].y = 0; | ||
114 | break; | ||
115 | case DOWN: | ||
116 | pts[0].x = (w / 2); pts[0].y = (h / 2) + (ay / 2); | ||
117 | pts[1].x = ax / 2; pts[1].y = - ay; | ||
118 | pts[2].x = - ax; pts[2].y = 0; | ||
119 | break; | ||
120 | } | ||
121 | |||
122 | if (gc() != 0) { | ||
123 | fillPolygon(gc(), | ||
124 | pts, 3, | ||
125 | Convex, CoordModePrevious); | ||
126 | } | ||
127 | } | 89 | } |
128 | 90 | ||
129 | void ArrowButton::updateTheme(const FbTk::Theme &theme) { | 91 | void ArrowButton::updateTheme(const FbTk::Theme &theme) { |
@@ -131,7 +93,7 @@ void ArrowButton::updateTheme(const FbTk::Theme &theme) { | |||
131 | const ButtonTheme &btheme = static_cast<const ButtonTheme &>(theme); | 93 | const ButtonTheme &btheme = static_cast<const ButtonTheme &>(theme); |
132 | 94 | ||
133 | m_arrowscale = btheme.scale(); | 95 | m_arrowscale = btheme.scale(); |
134 | if (m_arrowscale == 0) m_arrowscale = 300; // default is 0 => 300 | 96 | if (m_arrowscale == 0) m_arrowscale = 250; // default is 0 => 300 |
135 | else if (m_arrowscale < 100) m_arrowscale = 100; // otherwise clamp | 97 | else if (m_arrowscale < 100) m_arrowscale = 100; // otherwise clamp |
136 | else if (m_arrowscale > 100000) m_arrowscale = 100000; // clamp below overflow when *100 | 98 | else if (m_arrowscale > 100000) m_arrowscale = 100000; // clamp below overflow when *100 |
137 | } | 99 | } |