This is example 5. This example demonstrates the following:
-
Showing/hiding the eye-tracker user-interface
Source code
Source file: example5.c
Initialization and clean-up
In this example we want to toggle the display of the eye-tracker user-interface. We’re not interested in any eye-tracker events. Therefore it is not necessary to monitor the eye-tracker like we did in example 3 or 4.
The initialization and cleanup parts are the same as in example 1.
int main(void)
{
// Create an idle EyeVec object.
EyeVec* eyevec = eyevec_create();
// Setup communication with the eyevec-control/server application.
EyeVecResult err = eyevec_initialize(eyevec, true);
printError("eyevec_initialize()", err);
if (err) return EXIT_FAILURE;
.
.
printf("Type q to quit, ? for help.\n");
int ret = inputLoop(eyevec); (1)
.
.
// Terminate communication with the eyevec-control/server application.
err = eyevec_cleanup(eyevec);
printError("eyevec_cleanup()", err);
// Destroy the EyeVec object.
eyevec_destroy(eyevec);
return (ret >= 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
1 | Pass EyeVec object to inputLoop() . |
processInput()
The following single character commands are implemented here:
q
: quit
u
: show/hide control window
x
: toggle show gui on setup mode
X
: toggle show gui on data mode
When you press u
then eyevec_show_control_window()
or
eyevec_hide_control_window()
will be called depending on whether the
user-interface is currently shown or not.
Similarly you can toggle the show-gui-on-setup-mode and
show-gui-on-data-mode flags by pressing x
resp. X
. Setting these flags
makes the user-interface come up automatically when the eye-tracker enters
setup mode resp. data mode. You can play with this in example 6.
static int processInput(EyeVec* eyevec, int ch)
{
.
.
.
else if (ch == 'u') {
bool windowshown;
err = eyevec_is_control_window_shown(eyevec, &windowshown); (1)
if (err) {
printError("eyevec_is_control_window_shown()", err);
}
else if (windowshown) {
err = eyevec_hide_control_window(eyevec); (2)
printError("eyevec_hide_control_window()", err);
}
else {
err = eyevec_show_control_window(eyevec); (3)
printError("eyevec_show_control_window()", err);
}
}
else if (ch == 'x') {
bool show;
err = eyevec_get_show_gui_on_setup_mode(eyevec, &show); (4)
if (err) {
printError("eyevec_get_show_gui_on_setup_mode()", err);
}
else {
if (show) {
err = eyevec_set_show_gui_on_setup_mode(eyevec, false); (5)
printError("eyevec_set_show_gui_on_setup_mode(false)", err);
}
else {
err = eyevec_set_show_gui_on_setup_mode(eyevec, true); (6)
printError("eyevec_set_show_gui_on_setup_mode(true)", err);
}
}
}
else if (ch == 'X') {
bool show;
err = eyevec_get_show_gui_on_data_mode(eyevec, &show); (7)
if (err) {
printError("eyevec_get_show_gui_on_data_mode()", err);
}
else {
if (show) {
err = eyevec_set_show_gui_on_data_mode(eyevec, false); (8)
printError("eyevec_set_show_gui_on_data_mode(false)", err);
}
else {
err = eyevec_set_show_gui_on_data_mode(eyevec, true); (9)
printError("eyevec_set_show_gui_on_data_mode(true)", err);
}
}
}
.
.
.
}
1 | Check if the user-interface is currently shown. |
2 | Hide the user-interface. |
3 | Show the user-interface. |
4 | Check if the show-gui-on-setup-mode flag is currently set. |
5 | Clear the show-gui-on-setup-mode flag. |
6 | Set the show-gui-on-setup-mode flag. |
7 | Check if the show-gui-on-data-mode flag is currently set. |
8 | Clear the show-gui-on-data-mode flag. |
9 | Set the show-gui-on-data-mode flag. |
Running
After a succesful build run the program:
-
Press
o
to calleyevec_open()
. Eye-tracker should go from off mode to idle mode. -
Press
u
to calleyevec_show_control_window()
. User-interface should appear. -
Press
u
to calleyevec_hide_control_window()
. User-interface should disappear. -
Press
q
to quit.
Output might look like this (empty lines added for clarity):
eyevec_initialize(): OK
Type q to quit, ? for help.
[o]
eyevec_open(): OK
[u]
eyevec_show_control_window(): OK
[u]
eyevec_hide_control_window(): OK
[q]
eyevec_cleanup(): OK
The first time you hit the u
key the user-interface comes up. Hitting u
again (make sure your console window has the focus) hides the user-interface.
You might notice you can’t close the user-interface by clicking the window’s
close button. This is deliberate; the example program controls the
user-interface, not the user.