A generic touchscreen calibration program for X.Org
Revisión | 07978b90b81237d83071426643416161087e45dd (tree) |
---|---|
Tiempo | 2012-06-27 04:59:28 |
Autor | Tias Guns <tias@ulys...> |
Commiter | Tias Guns |
Rewrite and simplify swapping
Inspired by forest bond's 'calibrator: Convert to device coordinates
immediately.' patch:
https://github.com/forest-bond/xinput_calibrator/commit/12832527fba6dd1b3135751257ca6a734aa571cd
@@ -142,17 +142,6 @@ bool Calibrator::finish(int width, int height) | ||
142 | 142 | // based on old_axys: inversion/swapping is relative to the old axis |
143 | 143 | XYinfo new_axis(old_axys); |
144 | 144 | |
145 | - // Should x and y be swapped? | |
146 | - bool do_swap_xy = false; | |
147 | - if (abs(clicked.x[UL] - clicked.x[UR]) < abs(clicked.y[UL] - clicked.y[UR])) { | |
148 | - do_swap_xy = true; | |
149 | - new_axis.do_swap_xy(); | |
150 | - } | |
151 | - | |
152 | - if (do_swap_xy) { | |
153 | - std::swap(clicked.x[LL], clicked.x[UR]); | |
154 | - std::swap(clicked.y[LL], clicked.y[UR]); | |
155 | - } | |
156 | 145 | |
157 | 146 | // calculate average of clicks |
158 | 147 | float x_min = (clicked.x[UL] + clicked.x[LL])/2.0; |
@@ -160,6 +149,13 @@ bool Calibrator::finish(int width, int height) | ||
160 | 149 | float y_min = (clicked.y[UL] + clicked.y[UR])/2.0; |
161 | 150 | float y_max = (clicked.y[LL] + clicked.y[LR])/2.0; |
162 | 151 | |
152 | + // Should x and y be swapped? | |
153 | + if (abs(clicked.x[UL] - clicked.x[UR]) < abs(clicked.y[UL] - clicked.y[UR])) { | |
154 | + new_axis.swap_xy = !new_axis.swap_xy; | |
155 | + std::swap(x_min, y_min); | |
156 | + std::swap(x_max, y_max); | |
157 | + } | |
158 | + | |
163 | 159 | // the screen was divided in num_blocks blocks, and the touch points were at |
164 | 160 | // one block away from the true edges of the screen. |
165 | 161 | const float block_x = width/(float)num_blocks; |
@@ -184,12 +180,7 @@ bool Calibrator::finish(int width, int height) | ||
184 | 180 | y_max = scaleAxis(y_max, old_axys.y.max, old_axys.y.min, height, 0); |
185 | 181 | |
186 | 182 | |
187 | - // If x and y has to be swapped we also have to swap the parameters | |
188 | - if (do_swap_xy) { | |
189 | - std::swap(x_min, y_max); | |
190 | - std::swap(y_min, x_max); | |
191 | - } | |
192 | - | |
183 | + // round and put in new_axis struct | |
193 | 184 | new_axis.x.min = round(x_min); new_axis.x.max = round(x_max); |
194 | 185 | new_axis.y.min = round(y_min); new_axis.y.max = round(y_max); |
195 | 186 |