2012-01-03 12:39:06 -08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2009 Tias Guns
|
|
|
|
* Copyright (c) 2009 Soren Hauberg
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-01-11 16:21:44 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-01-10 18:34:30 +00:00
|
|
|
#include <math.h>
|
2012-01-03 12:39:06 -08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2012-01-11 16:21:44 +00:00
|
|
|
#include <glib/gi18n.h>
|
2012-01-03 12:39:06 -08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <cairo.h>
|
|
|
|
|
|
|
|
#include "calibrator.h"
|
|
|
|
#include "gui_gtk.h"
|
|
|
|
|
2012-01-11 19:17:14 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
struct Calib* calibrator;
|
|
|
|
double X[4], Y[4];
|
|
|
|
int display_width, display_height;
|
|
|
|
int time_elapsed;
|
|
|
|
|
|
|
|
const char* message;
|
|
|
|
|
|
|
|
guint anim_id;
|
|
|
|
|
|
|
|
GtkWidget *window;
|
|
|
|
} CalibArea;
|
|
|
|
|
|
|
|
|
2012-01-11 19:11:55 +00:00
|
|
|
/* Window parameters */
|
|
|
|
#define WINDOW_OPACITY 0.9
|
|
|
|
|
2012-01-03 12:39:06 -08:00
|
|
|
/* Timeout parameters */
|
2012-01-11 16:13:13 +00:00
|
|
|
#define TIME_STEP 100 /* in milliseconds */
|
|
|
|
#define MAX_TIME 15000 /* 5000 = 5 sec */
|
2012-01-03 12:39:06 -08:00
|
|
|
|
|
|
|
/* Clock appereance */
|
2012-01-11 18:16:36 +00:00
|
|
|
#define CROSS_LINES 47
|
2012-01-11 17:18:36 +00:00
|
|
|
#define CROSS_CIRCLE 7
|
2012-01-11 18:16:36 +00:00
|
|
|
#define CROSS_CIRCLE2 27
|
2012-01-11 16:13:13 +00:00
|
|
|
#define CLOCK_RADIUS 50
|
|
|
|
#define CLOCK_LINE_WIDTH 10
|
2012-01-03 12:39:06 -08:00
|
|
|
|
|
|
|
/* Text printed on screen */
|
2012-01-11 18:38:30 +00:00
|
|
|
#define HELP_TEXT_TITLE N_("Screen Calibration")
|
|
|
|
#define HELP_TEXT_MAIN N_("Please tap the target markers as they appear on screen to calibrate the tablet.")
|
2012-01-03 12:39:06 -08:00
|
|
|
|
2012-01-10 19:18:33 +00:00
|
|
|
static void
|
2012-01-11 19:17:14 +00:00
|
|
|
set_display_size(CalibArea *calib_area,
|
2012-01-03 12:39:06 -08:00
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
|
|
|
int delta_x;
|
|
|
|
int delta_y;
|
|
|
|
|
|
|
|
calib_area->display_width = width;
|
|
|
|
calib_area->display_height = height;
|
|
|
|
|
|
|
|
/* Compute absolute circle centers */
|
|
|
|
delta_x = calib_area->display_width/NUM_BLOCKS;
|
|
|
|
delta_y = calib_area->display_height/NUM_BLOCKS;
|
|
|
|
|
|
|
|
calib_area->X[UL] = delta_x;
|
|
|
|
calib_area->Y[UL] = delta_y;
|
|
|
|
|
|
|
|
calib_area->X[UR] = calib_area->display_width - delta_x - 1;
|
|
|
|
calib_area->Y[UR] = delta_y;
|
|
|
|
|
|
|
|
calib_area->X[LL] = delta_x;
|
|
|
|
calib_area->Y[LL] = calib_area->display_height - delta_y - 1;
|
|
|
|
|
|
|
|
calib_area->X[LR] = calib_area->display_width - delta_x - 1;
|
|
|
|
calib_area->Y[LR] = calib_area->display_height - delta_y - 1;
|
|
|
|
|
|
|
|
/* reset calibration if already started */
|
|
|
|
reset(calib_area->calibrator);
|
|
|
|
}
|
|
|
|
|
2012-01-10 19:18:33 +00:00
|
|
|
static void
|
2012-01-11 19:17:14 +00:00
|
|
|
resize_display(CalibArea *calib_area)
|
2012-01-03 12:39:06 -08:00
|
|
|
{
|
|
|
|
/* check that screensize did not change (if no manually specified geometry) */
|
|
|
|
GtkAllocation allocation;
|
2012-01-11 19:02:37 +00:00
|
|
|
gtk_widget_get_allocation(calib_area->window, &allocation);
|
2012-01-11 20:09:40 +00:00
|
|
|
if (calib_area->display_width != allocation.width ||
|
|
|
|
calib_area->display_height != allocation.height)
|
2012-01-03 12:39:06 -08:00
|
|
|
{
|
|
|
|
set_display_size(calib_area, allocation.width, allocation.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 19:18:33 +00:00
|
|
|
static void
|
2012-01-03 12:39:06 -08:00
|
|
|
draw(GtkWidget *widget, cairo_t *cr, gpointer data)
|
|
|
|
{
|
2012-01-11 19:17:14 +00:00
|
|
|
CalibArea *calib_area = (CalibArea*)data;
|
2012-01-03 12:39:06 -08:00
|
|
|
int i;
|
|
|
|
double x;
|
|
|
|
double y;
|
2012-01-11 16:13:13 +00:00
|
|
|
PangoLayout *layout;
|
|
|
|
PangoRectangle logical_rect;
|
|
|
|
GtkStyleContext *context;
|
2012-01-11 18:38:30 +00:00
|
|
|
char *markup;
|
2012-01-03 12:39:06 -08:00
|
|
|
|
|
|
|
resize_display(calib_area);
|
|
|
|
|
2012-01-11 16:13:13 +00:00
|
|
|
context = gtk_widget_get_style_context (widget);
|
|
|
|
|
2012-01-11 18:19:49 +00:00
|
|
|
/* Black background and reset the operator */
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
|
|
|
|
cairo_paint (cr);
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
|
|
|
|
|
2012-01-12 15:04:05 +00:00
|
|
|
/* Print the help lines */
|
2012-01-11 16:13:13 +00:00
|
|
|
layout = pango_layout_new (gtk_widget_get_pango_context (widget));
|
|
|
|
pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
|
2012-01-11 19:54:42 +00:00
|
|
|
markup = g_strdup_printf ("<span foreground=\"white\"><big><b>%s</b></big>\n<big>%s</big></span>",
|
2012-01-11 18:38:30 +00:00
|
|
|
_(HELP_TEXT_TITLE),
|
|
|
|
_(HELP_TEXT_MAIN));
|
|
|
|
pango_layout_set_markup (layout, markup, -1);
|
|
|
|
g_free (markup);
|
2012-01-11 16:13:13 +00:00
|
|
|
|
|
|
|
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
|
2012-01-03 12:39:06 -08:00
|
|
|
|
2012-01-11 16:13:13 +00:00
|
|
|
x = (calib_area->display_width - logical_rect.width) / 2 + logical_rect.x;
|
2012-01-11 18:38:49 +00:00
|
|
|
y = (calib_area->display_height - logical_rect.height) / 2 - logical_rect.height - 40 + logical_rect.y;
|
2012-01-03 12:39:06 -08:00
|
|
|
|
2012-01-11 16:13:13 +00:00
|
|
|
gtk_render_layout (context, cr,
|
|
|
|
x + logical_rect.x,
|
|
|
|
y + logical_rect.y,
|
|
|
|
layout);
|
|
|
|
g_object_unref (layout);
|
|
|
|
|
2012-01-03 12:39:06 -08:00
|
|
|
/* Draw the points */
|
2012-01-12 15:04:05 +00:00
|
|
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
|
|
|
|
|
2012-01-11 17:27:00 +00:00
|
|
|
i = calib_area->calibrator->num_clicks;
|
|
|
|
|
|
|
|
cairo_set_line_width(cr, 1);
|
2012-01-11 18:21:51 +00:00
|
|
|
cairo_move_to(cr, calib_area->X[i] - CROSS_LINES, calib_area->Y[i] - 0.5);
|
2012-01-11 17:27:00 +00:00
|
|
|
cairo_rel_line_to(cr, CROSS_LINES*2, 0);
|
2012-01-11 18:21:51 +00:00
|
|
|
cairo_move_to(cr, calib_area->X[i] - 0.5, calib_area->Y[i] - CROSS_LINES);
|
2012-01-11 17:27:00 +00:00
|
|
|
cairo_rel_line_to(cr, 0, CROSS_LINES*2);
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
2012-01-11 18:21:51 +00:00
|
|
|
cairo_set_line_width(cr, 2);
|
|
|
|
cairo_arc(cr, calib_area->X[i] - 0.5, calib_area->Y[i] - 0.5, CROSS_CIRCLE, 0.0, 2.0 * M_PI);
|
2012-01-11 17:27:00 +00:00
|
|
|
cairo_stroke(cr);
|
|
|
|
|
2012-01-11 18:21:51 +00:00
|
|
|
cairo_set_line_width(cr, 5);
|
|
|
|
cairo_arc(cr, calib_area->X[i] - 0.5, calib_area->Y[i] - 0.5, CROSS_CIRCLE2, 0.0, 2.0 * M_PI);
|
2012-01-11 17:27:00 +00:00
|
|
|
cairo_stroke(cr);
|
2012-01-03 12:39:06 -08:00
|
|
|
|
|
|
|
/* Draw the clock background */
|
2012-01-11 16:13:13 +00:00
|
|
|
cairo_arc(cr, calib_area->display_width/2, calib_area->display_height/2, CLOCK_RADIUS/2, 0.0, 2.0 * M_PI);
|
2012-01-03 12:39:06 -08:00
|
|
|
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
|
|
|
|
cairo_fill_preserve(cr);
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
2012-01-11 16:13:13 +00:00
|
|
|
cairo_set_line_width(cr, CLOCK_LINE_WIDTH);
|
|
|
|
cairo_arc(cr, calib_area->display_width/2, calib_area->display_height/2, (CLOCK_RADIUS - CLOCK_LINE_WIDTH)/2,
|
|
|
|
3/2.0*M_PI, (3/2.0*M_PI) + ((double)calib_area->time_elapsed/(double)MAX_TIME) * 2*M_PI);
|
2012-01-11 18:20:27 +00:00
|
|
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
|
2012-01-03 12:39:06 -08:00
|
|
|
cairo_stroke(cr);
|
|
|
|
|
|
|
|
/* Draw the message (if any) */
|
|
|
|
if (calib_area->message != NULL)
|
|
|
|
{
|
2012-01-11 18:20:27 +00:00
|
|
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
|
|
|
|
|
2012-01-03 12:39:06 -08:00
|
|
|
/* Frame the message */
|
2012-01-11 16:13:13 +00:00
|
|
|
layout = pango_layout_new (gtk_widget_get_pango_context (widget));
|
|
|
|
pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
|
2012-01-11 19:54:42 +00:00
|
|
|
markup = g_strdup_printf ("<span foreground=\"white\"><big>%s</big></span>",
|
|
|
|
_(calib_area->message));
|
|
|
|
pango_layout_set_markup (layout, markup, -1);
|
|
|
|
g_free (markup);
|
2012-01-11 16:13:13 +00:00
|
|
|
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
|
2012-01-03 12:39:06 -08:00
|
|
|
|
2012-01-11 16:13:13 +00:00
|
|
|
x = (calib_area->display_width - logical_rect.width) / 2 + logical_rect.x;
|
|
|
|
y = (calib_area->display_height - logical_rect.height + CLOCK_RADIUS) / 2 + 60 + logical_rect.y;
|
2012-01-03 12:39:06 -08:00
|
|
|
cairo_set_line_width(cr, 2);
|
2012-01-11 19:55:10 +00:00
|
|
|
cairo_rectangle(cr, x - 10 - 0.5 , y - 10 - 0.5,
|
|
|
|
logical_rect.width + 20 + 1, logical_rect.height + 20 + 1);
|
|
|
|
cairo_stroke (cr);
|
2012-01-03 12:39:06 -08:00
|
|
|
|
|
|
|
/* Print the message */
|
2012-01-11 16:13:13 +00:00
|
|
|
gtk_render_layout (context, cr,
|
|
|
|
x + logical_rect.x,
|
|
|
|
y + logical_rect.y,
|
|
|
|
layout);
|
|
|
|
g_object_unref (layout);
|
2012-01-03 12:39:06 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 19:18:33 +00:00
|
|
|
static void
|
2012-01-11 19:17:14 +00:00
|
|
|
draw_message(CalibArea *calib_area,
|
2012-01-10 19:18:33 +00:00
|
|
|
const char *msg)
|
2012-01-03 12:39:06 -08:00
|
|
|
{
|
2012-01-10 19:18:33 +00:00
|
|
|
calib_area->message = msg;
|
|
|
|
}
|
2012-01-03 12:39:06 -08:00
|
|
|
|
2012-01-10 19:18:33 +00:00
|
|
|
static void
|
2012-01-11 19:17:14 +00:00
|
|
|
redraw(CalibArea *calib_area)
|
2012-01-10 19:18:33 +00:00
|
|
|
{
|
2012-01-11 19:02:37 +00:00
|
|
|
GdkWindow *win = gtk_widget_get_window(calib_area->window);
|
2012-01-03 12:39:06 -08:00
|
|
|
if (win)
|
|
|
|
{
|
|
|
|
GdkRectangle rect;
|
2012-01-10 19:18:33 +00:00
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
|
|
|
rect.width = calib_area->display_width;
|
|
|
|
rect.height = calib_area->display_height;
|
2012-01-10 18:33:26 +00:00
|
|
|
gdk_window_invalidate_rect(win, &rect, FALSE);
|
2012-01-03 12:39:06 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 19:18:33 +00:00
|
|
|
static gboolean
|
2012-01-03 12:39:06 -08:00
|
|
|
on_button_press_event(GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2012-01-11 19:17:14 +00:00
|
|
|
CalibArea *calib_area = (CalibArea*)data;
|
2012-01-10 18:33:26 +00:00
|
|
|
gboolean success;
|
2012-01-03 12:39:06 -08:00
|
|
|
|
|
|
|
/* Handle click */
|
|
|
|
calib_area->time_elapsed = 0;
|
|
|
|
success = add_click(calib_area->calibrator, (int)event->x_root, (int)event->y_root);
|
|
|
|
|
|
|
|
if (!success && calib_area->calibrator->num_clicks == 0)
|
2012-01-11 19:46:25 +00:00
|
|
|
draw_message(calib_area, N_("Mis-click detected, restarting..."));
|
2012-01-03 12:39:06 -08:00
|
|
|
else
|
|
|
|
draw_message(calib_area, NULL);
|
|
|
|
|
|
|
|
/* Are we done yet? */
|
|
|
|
if (calib_area->calibrator->num_clicks >= 4)
|
|
|
|
{
|
2012-01-11 19:02:37 +00:00
|
|
|
gtk_widget_destroy (calib_area->window);
|
|
|
|
return FALSE;
|
2012-01-03 12:39:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Force a redraw */
|
|
|
|
redraw(calib_area);
|
|
|
|
|
2012-01-11 19:02:37 +00:00
|
|
|
return FALSE;
|
2012-01-03 12:39:06 -08:00
|
|
|
}
|
|
|
|
|
2012-01-10 19:18:33 +00:00
|
|
|
static gboolean
|
2012-01-11 18:39:09 +00:00
|
|
|
on_key_release_event(GtkWidget *widget,
|
|
|
|
GdkEventKey *event,
|
|
|
|
gpointer data)
|
2012-01-03 12:39:06 -08:00
|
|
|
{
|
2012-01-11 19:17:14 +00:00
|
|
|
CalibArea *calib_area = (CalibArea*)data;
|
2012-01-11 18:39:09 +00:00
|
|
|
|
|
|
|
if (event->type != GDK_KEY_RELEASE)
|
|
|
|
return FALSE;
|
|
|
|
if (event->keyval != GDK_KEY_Escape)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-01-11 19:02:37 +00:00
|
|
|
gtk_widget_destroy (calib_area->window);
|
2012-01-11 18:39:09 +00:00
|
|
|
return FALSE;
|
2012-01-03 12:39:06 -08:00
|
|
|
}
|
|
|
|
|
2012-01-10 19:18:33 +00:00
|
|
|
static gboolean
|
2012-01-11 19:17:14 +00:00
|
|
|
on_timer_signal(CalibArea *calib_area)
|
2012-01-10 19:18:33 +00:00
|
|
|
{
|
|
|
|
GdkWindow *win;
|
|
|
|
|
2012-01-11 16:13:13 +00:00
|
|
|
calib_area->time_elapsed += TIME_STEP;
|
2012-01-11 19:02:37 +00:00
|
|
|
if (calib_area->time_elapsed > MAX_TIME)
|
2012-01-10 19:18:33 +00:00
|
|
|
{
|
2012-01-11 19:02:37 +00:00
|
|
|
gtk_widget_destroy (calib_area->window);
|
2012-01-10 19:18:33 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update clock */
|
2012-01-11 19:02:37 +00:00
|
|
|
win = gtk_widget_get_window (calib_area->window);
|
2012-01-10 19:18:33 +00:00
|
|
|
if (win)
|
|
|
|
{
|
|
|
|
GdkRectangle rect;
|
2012-01-11 16:13:13 +00:00
|
|
|
rect.x = calib_area->display_width/2 - CLOCK_RADIUS - CLOCK_LINE_WIDTH;
|
|
|
|
rect.y = calib_area->display_height/2 - CLOCK_RADIUS - CLOCK_LINE_WIDTH;
|
|
|
|
rect.width = 2 * CLOCK_RADIUS + 1 + 2 * CLOCK_LINE_WIDTH;
|
|
|
|
rect.height = 2 * CLOCK_RADIUS + 1 + 2 * CLOCK_LINE_WIDTH;
|
2012-01-10 19:18:33 +00:00
|
|
|
gdk_window_invalidate_rect(win, &rect, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-11 19:17:14 +00:00
|
|
|
static CalibArea*
|
2012-01-11 19:23:06 +00:00
|
|
|
calibration_area_new (struct Calib *c)
|
2012-01-10 19:18:33 +00:00
|
|
|
{
|
2012-01-11 19:17:14 +00:00
|
|
|
CalibArea *calib_area;
|
2012-01-11 19:23:06 +00:00
|
|
|
GdkWindow *window;
|
|
|
|
GdkRGBA black;
|
2012-01-10 19:18:33 +00:00
|
|
|
|
2012-01-11 19:17:14 +00:00
|
|
|
calib_area = g_new0 (CalibArea, 1);
|
2012-01-10 19:18:33 +00:00
|
|
|
calib_area->calibrator = c;
|
2012-01-11 19:23:06 +00:00
|
|
|
|
|
|
|
/* Set up the window */
|
|
|
|
calib_area->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
gtk_widget_set_app_paintable (GTK_WIDGET (calib_area->window), TRUE);
|
|
|
|
|
|
|
|
/* Black background */
|
|
|
|
gdk_rgba_parse (&black, "rgb(0,0,0)");
|
|
|
|
gtk_window_set_opacity (GTK_WINDOW (calib_area->window), WINDOW_OPACITY);
|
|
|
|
|
|
|
|
gtk_widget_realize (calib_area->window);
|
|
|
|
window = gtk_widget_get_window (calib_area->window);
|
|
|
|
gdk_window_set_background_rgba (window, &black);
|
2012-01-10 19:18:33 +00:00
|
|
|
|
|
|
|
/* Listen for mouse events */
|
2012-01-11 19:23:06 +00:00
|
|
|
gtk_widget_add_events (calib_area->window, GDK_KEY_RELEASE_MASK | GDK_BUTTON_PRESS_MASK);
|
|
|
|
gtk_widget_set_can_focus (calib_area->window, TRUE);
|
|
|
|
gtk_window_fullscreen (GTK_WINDOW (calib_area->window));
|
2012-01-10 19:18:33 +00:00
|
|
|
|
|
|
|
/* Connect callbacks */
|
2012-01-11 19:23:06 +00:00
|
|
|
g_signal_connect (calib_area->window, "draw",
|
2012-01-11 19:02:37 +00:00
|
|
|
G_CALLBACK(draw), calib_area);
|
2012-01-11 19:23:06 +00:00
|
|
|
g_signal_connect (calib_area->window, "button-press-event",
|
2012-01-11 19:02:37 +00:00
|
|
|
G_CALLBACK(on_button_press_event), calib_area);
|
2012-01-11 19:23:06 +00:00
|
|
|
g_signal_connect (calib_area->window, "key-release-event",
|
2012-01-11 19:02:37 +00:00
|
|
|
G_CALLBACK(on_key_release_event), calib_area);
|
2012-01-11 19:23:06 +00:00
|
|
|
g_signal_connect (calib_area->window, "destroy",
|
|
|
|
G_CALLBACK (gtk_main_quit), NULL);
|
2012-01-11 19:02:37 +00:00
|
|
|
|
2012-01-10 19:18:33 +00:00
|
|
|
/* Setup timer for animation */
|
2012-01-11 16:13:13 +00:00
|
|
|
calib_area->anim_id = g_timeout_add(TIME_STEP, (GSourceFunc)on_timer_signal, calib_area);
|
2012-01-10 19:18:33 +00:00
|
|
|
|
|
|
|
return calib_area;
|
|
|
|
}
|
|
|
|
|
2012-01-03 12:39:06 -08:00
|
|
|
/**
|
|
|
|
* Creates the windows and other objects required to do calibration
|
|
|
|
* under GTK and then starts the main loop. When the main loop exits,
|
|
|
|
* the calibration will be calculated (if possible) and this function
|
2012-01-10 18:33:26 +00:00
|
|
|
* will then return ('TRUE' if successful, 'FALSE' otherwise).
|
2012-01-03 12:39:06 -08:00
|
|
|
*/
|
2012-01-10 18:33:26 +00:00
|
|
|
gboolean
|
2012-01-03 12:39:06 -08:00
|
|
|
run_gui(struct Calib *c,
|
2012-01-10 19:19:24 +00:00
|
|
|
XYinfo *new_axis,
|
2012-01-10 18:33:26 +00:00
|
|
|
gboolean *swap)
|
2012-01-03 12:39:06 -08:00
|
|
|
{
|
2012-01-10 18:33:26 +00:00
|
|
|
gboolean success;
|
2012-01-11 19:17:14 +00:00
|
|
|
CalibArea *calib_area;
|
2012-01-11 19:02:37 +00:00
|
|
|
GdkScreen *screen;
|
|
|
|
GdkRectangle rect;
|
2012-01-03 12:39:06 -08:00
|
|
|
|
2012-01-10 20:13:20 +00:00
|
|
|
g_debug ("Current calibration: %d, %d, %d, %d\n",
|
|
|
|
c->old_axis.x_min,
|
|
|
|
c->old_axis.y_min,
|
|
|
|
c->old_axis.x_max,
|
|
|
|
c->old_axis.y_max);
|
2012-01-03 12:39:06 -08:00
|
|
|
|
2012-01-11 19:02:37 +00:00
|
|
|
/* Which monitor are we on? */
|
|
|
|
screen = gdk_screen_get_default();
|
2012-01-03 12:39:06 -08:00
|
|
|
/*int num_monitors = screen->get_n_monitors(); TODO, multiple monitors?*/
|
|
|
|
gdk_screen_get_monitor_geometry(screen, 0, &rect);
|
|
|
|
|
2012-01-11 19:23:06 +00:00
|
|
|
calib_area = calibration_area_new (c);
|
2012-01-03 12:39:06 -08:00
|
|
|
|
2012-01-11 19:23:06 +00:00
|
|
|
gtk_window_move (GTK_WINDOW (calib_area->window), rect.x, rect.y);
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (calib_area->window), rect.width, rect.height);
|
2012-01-11 18:19:49 +00:00
|
|
|
|
2012-01-11 19:23:06 +00:00
|
|
|
gtk_widget_show_all(calib_area->window);
|
2012-01-03 12:39:06 -08:00
|
|
|
|
|
|
|
gtk_main();
|
|
|
|
|
2012-01-10 20:34:38 +00:00
|
|
|
g_source_remove (calib_area->anim_id);
|
|
|
|
|
2012-01-10 19:19:24 +00:00
|
|
|
success = finish(calib_area->calibrator, calib_area->display_width, calib_area->display_height, new_axis, swap);
|
2012-01-03 12:39:06 -08:00
|
|
|
|
2012-01-11 18:56:09 +00:00
|
|
|
g_free (calib_area);
|
|
|
|
|
2012-01-11 19:26:58 +00:00
|
|
|
if (success)
|
|
|
|
g_debug ("Final calibration: %d, %d, %d, %d\n",
|
|
|
|
new_axis->x_min,
|
|
|
|
new_axis->y_min,
|
|
|
|
new_axis->x_max,
|
|
|
|
new_axis->y_max);
|
|
|
|
else
|
|
|
|
g_debug ("Calibration was aborted or timed out");
|
2012-01-03 12:39:06 -08:00
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|