Skip to content

Commit

Permalink
show the name of the device on screen
Browse files Browse the repository at this point in the history
* this is intended for a better handling of multiple devices
* while being here the common settings for both GUIs are shared

Signed-off-by: Andreas Müller <schnitzeltony@googlemail.com>
  • Loading branch information
schnitzeltony committed Feb 14, 2013
1 parent c4d1e11 commit 4828028
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 56 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -35,7 +35,7 @@ AC_PROG_LIBTOOL
AC_PROG_INSTALL

AC_PATH_X
AC_CHECK_HEADERS([stdlib.h string.h])
AC_CHECK_HEADERS([stdlib.h string.h string list])
AC_HEADER_STDBOOL
AC_FUNC_STRTOD

Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.am
Expand Up @@ -32,7 +32,7 @@ AM_CXXFLAGS = -Wall -ansi -pedantic

bin_PROGRAMS = xinput_calibrator tester

COMMON_SRCS=calibrator.cpp calibrator/XorgPrint.cpp calibrator/Evdev.cpp calibrator/Usbtouchscreen.cpp main_common.cpp
COMMON_SRCS=calibrator.cpp calibrator/XorgPrint.cpp calibrator/Evdev.cpp calibrator/Usbtouchscreen.cpp main_common.cpp gui/gui_common.cpp

# only one of the BUILD_ flags should be set
if BUILD_X11
Expand Down
1 change: 1 addition & 0 deletions src/gui/Makefile.am
@@ -1,3 +1,4 @@
EXTRA_DIST = \
gui_common.cpp \
gtkmm.cpp \
x11.cpp
39 changes: 12 additions & 27 deletions src/gui/gtkmm.cpp
Expand Up @@ -22,30 +22,13 @@
*/

#include "gui/gtkmm.hpp"

// Timeout parameters
const int time_step = 100; // in milliseconds
const int max_time = 15000; // 5000 = 5 sec

// Clock appereance
const int cross_lines = 25;
const int cross_circle = 4;
const int clock_radius = 50;
const int clock_line_width = 10;

// Text printed on screen
const int font_size = 16;
const int help_lines = 4;
const std::string help_text[help_lines] = {
"Touchscreen Calibration",
"Press the point, use a stylus to increase precision.",
"",
"(To abort, press any key or wait)"
};
#include "gui/gui_common.hpp"

CalibrationArea::CalibrationArea(Calibrator* calibrator0)
: calibrator(calibrator0), time_elapsed(0), message(NULL)
{
// setup strings
get_display_texts(&display_texts, calibrator0);
// Listen for mouse events
add_events(Gdk::KEY_PRESS_MASK | Gdk::BUTTON_PRESS_MASK);
set_flags(Gtk::CAN_FOCUS);
Expand Down Expand Up @@ -110,8 +93,9 @@ bool CalibrationArea::on_expose_event(GdkEventExpose *event)
double text_height = -1;
double text_width = -1;
Cairo::TextExtents extent;
for (int i = 0; i != help_lines; i++) {
cr->get_text_extents(help_text[i], extent);
for (std::list<std::string>::iterator it = display_texts.begin();
it != display_texts.end(); it++) {
cr->get_text_extents(*it, extent);
text_width = std::max(text_width, extent.width);
text_height = std::max(text_height, extent.height);
}
Expand All @@ -120,15 +104,16 @@ bool CalibrationArea::on_expose_event(GdkEventExpose *event)
double x = (display_width - text_width) / 2;
double y = (display_height - text_height) / 2 - 60;
cr->set_line_width(2);
cr->rectangle(x - 10, y - (help_lines*text_height) - 10,
text_width + 20, (help_lines*text_height) + 20);
cr->rectangle(x - 10, y - (display_texts.size()*text_height) - 10,
text_width + 20, (display_texts.size()*text_height) + 20);

// Print help lines
y -= 3;
for (int i = help_lines-1; i != -1; i--) {
cr->get_text_extents(help_text[i], extent);
for (std::list<std::string>::reverse_iterator rev_it = display_texts.rbegin();
rev_it != display_texts.rend(); rev_it++) {
cr->get_text_extents(*rev_it, extent);
cr->move_to(x + (text_width-extent.width)/2, y);
cr->show_text(help_text[i]);
cr->show_text(*rev_it);
y -= text_height;
}
cr->stroke();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/gtkmm.hpp
Expand Up @@ -26,6 +26,7 @@

#include <gtkmm/drawingarea.h>
#include "calibrator.hh"
#include <list>

/*******************************************
* GTK-mm class for the the calibration GUI
Expand All @@ -41,6 +42,7 @@ class CalibrationArea : public Gtk::DrawingArea
double X[4], Y[4];
int display_width, display_height;
int time_elapsed;
std::list<std::string> display_texts;

const char* message;

Expand Down
51 changes: 51 additions & 0 deletions src/gui/gui_common.cpp
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2013 Andreas Müller
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "gui/gui_common.hpp"


void get_display_texts(std::list<std::string> *texts, Calibrator *calibrator)
{
std::string str;
/* 1st line */
str = "Touchscreen Calibration";
const char* sysfs_name = calibrator->get_sysfs_name();
if(sysfs_name != NULL) {
str += " for '";
str += sysfs_name;
str += "'";
}
texts->push_back(str);
/* 2nd line */
str = "Press the point, use a stylus to increase precision.";
texts->push_back(str);
/* 3rd line */
str = "";
texts->push_back(str);
/* 4th line */
str = "(To abort, press any key";
if(calibrator->get_use_timeout())
str += " or wait)";
else
str += ")";
texts->push_back(str);
}
45 changes: 45 additions & 0 deletions src/gui/gui_common.hpp
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2013 Andreas Müller
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef GUI_GUI_COMMON_HPP
#define GUI_GUI_COMMON_HPP

#include "calibrator.hh"
#include <list>
#include <string>

// Timeout parameters
const int time_step = 100; // in milliseconds
const int max_time = 15000; // in milliseconds, 5000 = 5 sec

// Clock appereance
const int cross_lines = 25;
const int cross_circle = 4;
const int clock_radius = 50;
const int clock_line_width = 10;

// Text printed on screen
const int font_size = 16;

void get_display_texts(std::list<std::string> *texts, Calibrator *calibrator);

#endif
40 changes: 13 additions & 27 deletions src/gui/x11.cpp
Expand Up @@ -21,6 +21,7 @@
*/

#include "gui/x11.hpp"
#include "gui/gui_common.hpp"

#include <X11/X.h>
#include <X11/Xlib.h>
Expand All @@ -43,26 +44,6 @@
#include <stdint.h>


// Timeout parameters
const int time_step = 100; // in milliseconds
const int max_time = 15000; // in milliseconds, 5000 = 5 sec

// Clock appereance
const int cross_lines = 25;
const int cross_circle = 4;
const int clock_radius = 50;
const int clock_line_width = 10;

// Text printed on screen
const int font_size = 16;
const int help_lines = 4;
const std::string help_text[help_lines] = {
"Touchscreen Calibration",
"Press the point, use a stylus to increase precision.",
"",
"(To abort, press any key or wait)"
};

const char* GuiCalibratorX11::colors[GuiCalibratorX11::NUM_COLORS] = {"BLACK", "WHITE", "GRAY", "DIMGRAY", "RED"};

#ifndef HAVE_TIMERFD
Expand All @@ -81,6 +62,9 @@ GuiCalibratorX11* GuiCalibratorX11::instance = NULL;
GuiCalibratorX11::GuiCalibratorX11(Calibrator* calibrator0)
: calibrator(calibrator0), time_elapsed(0)
{
// setup strings
get_display_texts(&display_texts, calibrator0);

display = XOpenDisplay(NULL);
if (display == NULL) {
throw std::runtime_error("Unable to connect to X server");
Expand Down Expand Up @@ -237,24 +221,26 @@ void GuiCalibratorX11::redraw()
// Print the text
int text_height = font_info->ascent + font_info->descent;
int text_width = -1;
for (int i = 0; i != help_lines; i++) {
for (std::list<std::string>::iterator it = display_texts.begin();
it != display_texts.end(); it++) {
text_width = std::max(text_width, XTextWidth(font_info,
help_text[i].c_str(), help_text[i].length()));
(*it).c_str(), (*it).length()));
}

int x = (display_width - text_width) / 2;
int y = (display_height - text_height) / 2 - 60;
XSetForeground(display, gc, pixel[BLACK]);
XSetLineAttributes(display, gc, 2, LineSolid, CapRound, JoinRound);
XDrawRectangle(display, win, gc, x - 10, y - (help_lines*text_height) - 10,
text_width + 20, (help_lines*text_height) + 20);
XDrawRectangle(display, win, gc, x - 10, y - (display_texts.size()*text_height) - 10,
text_width + 20, (display_texts.size()*text_height) + 20);

// Print help lines
y -= 3;
for (int i = help_lines-1; i != -1; i--) {
int w = XTextWidth(font_info, help_text[i].c_str(), help_text[i].length());
for (std::list<std::string>::reverse_iterator rev_it = display_texts.rbegin();
rev_it != display_texts.rend(); rev_it++) {
int w = XTextWidth(font_info, (*rev_it).c_str(), (*rev_it).length());
XDrawString(display, win, gc, x + (text_width-w)/2, y,
help_text[i].c_str(), help_text[i].length());
(*rev_it).c_str(), (*rev_it).length());
y -= text_height;
}

Expand Down
2 changes: 2 additions & 0 deletions src/gui/x11.hpp
Expand Up @@ -24,6 +24,7 @@
#define GUI_CALIBRATOR_X11

#include "calibrator.hh"
#include <list>

/*******************************************
* X11 class for the the calibration GUI
Expand All @@ -43,6 +44,7 @@ class GuiCalibratorX11
double X[NUM_POINTS], Y[NUM_POINTS];
int display_width, display_height;
int time_elapsed;
std::list<std::string> display_texts;

// X11 vars
Display* display;
Expand Down

0 comments on commit 4828028

Please sign in to comment.