17 #include "../include/tscope5/mouse.h"
18 #include "../include/tscope5/timer.h"
19 #include "../include/tscope5/graphics.h"
20 #include "../include/tscope5/bitmaps.h"
21 #include "../include/tscope5/display.h"
22 #include "../include/tscope5/primitives.h"
23 #include "../include/tscope5/mouse_internal.h"
24 #include "../include/tscope5/system_internal.h"
25 #include "../include/tscope5/graphics_internal.h"
49 ts5_log(TS5_LOGLEVEL_3,
"ts5_define_mouse_button(%d)\n", button);
52 ts5_fatal(
"%s: %s\n",
"ts5_define_mouse_button",
53 "button argument is 0, response buttons are numbered from 1");
56 if (abs(button)>_ts5_status.timer.mouse.num_buttons) {
57 ts5_fatal(
"%s: %s %d, %s is %d\n",
"ts5_define_mouse_button",
58 "button argument is", button,
59 "number of mouse buttons",
60 _ts5_status.timer.mouse.num_buttons);
63 if (button>0 && _ts5_status.timer.mouse
64 .button_press_defined[button-1]!=0) {
65 ts5_fatal(
"%s: %s %d %s\n",
"ts5_define_mouse_button",
66 "button press", button,
"is already defined");
69 if (button<0 && _ts5_status.timer.mouse
70 .button_release_defined[-button-1]!=0) {
71 ts5_fatal(
"%s: %s %d %s\n",
"ts5_define_mouse_button",
72 "button release", button,
"is already defined");
75 _ts5_status.timer.mouse_is_response_device = 1;
76 _ts5_status.timer.num_defined_buttons++;
77 _ts5_status.timer.num_active_buttons++;
78 _ts5_status.timer.mouse.num_defined_buttons++;
79 _ts5_status.timer.mouse.num_active_buttons++;
82 _ts5_status.timer.mouse.button_press_defined[button-1] =
83 _ts5_status.timer.num_defined_buttons;
85 _ts5_status.timer.mouse.button_press_active[button-1] =
86 _ts5_status.timer.num_defined_buttons;
89 _ts5_status.timer.mouse.button_release_defined[-button-1] =
90 _ts5_status.timer.num_defined_buttons;
92 _ts5_status.timer.mouse.button_release_active[-button-1] =
93 _ts5_status.timer.num_defined_buttons;
96 return _ts5_status.timer.num_defined_buttons;
108 ts5_log(TS5_LOGLEVEL_4,
"ts5_get_num_mouse_buttons()\n");
110 return _ts5_status.timer.mouse.num_buttons;
131 ts5_log(TS5_LOGLEVEL_5,
"ts5_show_mouse()\n");
133 #ifndef TS5_RASPBERRYPI
134 al_show_mouse_cursor(_ts5_data.display[_ts5_status.active_display]);
146 ts5_log(TS5_LOGLEVEL_5,
"ts5_hide_mouse()\n");
148 #ifndef TS5_RASPBERRYPI
149 al_hide_mouse_cursor(_ts5_data.display[_ts5_status.active_display]);
164 ts5_log(TS5_LOGLEVEL_5,
"ts5_set_mouse_position(%f,%f)\n", x, y);
166 if (_ts5_status.graphics.coordinate_scale
167 == TS5_RELATIVE_COORDINATES) {
172 if (_ts5_status.graphics.coordinate_system
173 == TS5_CARTESIAN_COORDINATES) {
178 al_set_mouse_xy(_ts5_data.display[_ts5_status.active_display],
193 ts5_log(TS5_LOGLEVEL_6,
"ts5_get_mouse_position(%p,%p)\n", x, y);
195 ALLEGRO_MOUSE_STATE status;
196 al_get_mouse_state(&status);
200 xx = al_get_mouse_state_axis(&status, 0);
201 yy = al_get_mouse_state_axis(&status, 1);
203 #ifdef TS5_RASPBERRYPI
204 #include <allegro5/allegro_primitives.h>
207 al_set_target_backbuffer(_ts5_data.display[_ts5_status.active_display]);
208 al_draw_bitmap(_ts5_data.display_buffer[_ts5_status.active_display], 0.0, 0.0, 0);
214 al_draw_line(xx-8.0, yy-8.0, xx+8.0, yy+8.0, _ts5_status.graphics.background_color, 9.0);
215 al_draw_line(xx-8.0, yy+8.0, xx+8.0, yy-8.0, _ts5_status.graphics.background_color, 9.0);
216 al_draw_line(xx-6.0, yy-6.0, xx+6.0, yy+6.0, _ts5_status.graphics.foreground_color, 3.0);
217 al_draw_line(xx-6.0, yy+6.0, xx+6.0, yy-6.0, _ts5_status.graphics.foreground_color, 3.0);
224 if (_ts5_status.graphics.coordinate_system
225 == TS5_CARTESIAN_COORDINATES) {
230 if (_ts5_status.graphics.coordinate_scale
231 == TS5_RELATIVE_COORDINATES) {
254 ts5_log(TS5_LOGLEVEL_6,
"ts5_get_mouse_x()\n");
271 ts5_log(TS5_LOGLEVEL_6,
"ts5_get_mouse_y()\n");
298 ts5_log(TS5_LOGLEVEL_5,
"ts5_draw_mouse_button(%f,%f)\n", x, y);
304 _ts5_data.display_buffer
305 [_ts5_status.active_display]);
315 double w_abs_disp = 40, h_abs_disp = 40;
316 double x1_abs_disp, x2_abs_disp, y1_abs_disp, y2_abs_disp;
319 if (_ts5_status.graphics.coordinate_scale
320 == TS5_RELATIVE_COORDINATES) {
330 if (_ts5_status.graphics.coordinate_system
331 == TS5_CARTESIAN_COORDINATES) {
335 x1_abs_disp -= w_abs_disp/2;
336 y1_abs_disp -= h_abs_disp/2;
339 x2_abs_disp = x1_abs_disp + w_abs_disp;
340 y2_abs_disp = y1_abs_disp + h_abs_disp;
346 double dispw = _ts5_status.display[_ts5_status.active_display].w;
347 double disph = _ts5_status.display[_ts5_status.active_display].h;
349 if (x1_abs_disp < 0.0 || x2_abs_disp > dispw
350 || y1_abs_disp < 0.0 || y2_abs_disp > disph) {
351 ts5_fatal(
"%s: %s (%f,%f)\n",
"ts5_draw_mouse_button",
352 "button will be off screen", x1_abs_disp, y1_abs_disp);
356 x2_abs_disp, y2_abs_disp, 3.0, 3.0);
361 x1_abs_disp+5.0, y1_abs_disp+5.0, x1_abs_disp+5.0, y2_abs_disp-5.0);
365 #ifndef ALLEGRO_RASPBERRYPI
371 ALLEGRO_MOUSE_STATE status;
377 al_get_mouse_state(&status);
378 down = al_mouse_button_down(&status, 1);
379 if (down && xp > x1_abs_disp && xp < x2_abs_disp
380 && yp > y1_abs_disp && yp < y2_abs_disp) {
387 x1_abs_disp+5, y1_abs_disp+5, x1_abs_disp+5, y2_abs_disp-5);
392 al_get_mouse_state(&status);
393 down = al_mouse_button_down(&status, 1);
401 x1_abs_disp+5, y1_abs_disp+5, x1_abs_disp+5, y2_abs_disp-5);
double ts5_display_to_cartesian_coordinate_y(const double y)
Convert a vertical display coordinate into a vertical Cartisian coordinate.
void ts5_hide_mouse()
Make the mouse cursor invisible on the active display.
TS5_COLOR ts5_make_named_color(const char *name, const double a)
Return a color that corresponds to name.
double ts5_display_to_cartesian_coordinate_x(const double x)
Convert a horizontal display coordinate into a horizontal Cartisian coordinate.
double ts5_flip_display()
Make what has been drawn visible on the screen.
int ts5_set_active_display(const int display)
Set the active display.
int ts5_set_fill_mode(const int fill_mode)
Set the fill mode.
void ts5_show_mouse()
Make the mouse cursor visible on the active display.
TS5_COLOR ts5_set_foreground_color(const TS5_COLOR foreground_color)
Set the foreground color.
void ts5_get_mouse_position(double *x, double *y)
Get the horizontal and vertical position of the mouse pointer.
int ts5_set_coordinate_scale(const int coordinate_scale)
Set the coordinate scale.
void ts5_set_mouse_position(double x, double y)
Move the mouse pointer to position (x,y).
TS5_BITMAP * ts5_set_drawing_target(TS5_BITMAP *target)
Set the active drawing target.
void ts5_draw_rounded_rectangle(double x1, double y1, double x2, double y2, double rx, double ry)
Draw a rounded rectangle.
int ts5_get_num_mouse_buttons()
Get the number of buttons available on the mouse.
void ts5_draw_mouse_button(double x, double y)
Draw a mouse button and wait for a click.
double ts5_relative_to_absolute_coordinate_x(const double x)
Convert a relative horizontal coordinate into an absolute horizontal coordinate.
double ts5_set_drawing_thickness(double drawing_thickness)
Set the drawing thickness.
int ts5_define_mouse_button(int button)
Define a mouse button as a response button.
void ts5_log(const unsigned int level, const char *format,...)
Send info to a logging window.
double ts5_cartesian_to_display_coordinate_x(const double x)
Convert a horizontal Cartesian coordinate into a horizontal display coordinate.
double ts5_cartesian_to_display_coordinate_y(const double y)
Convert a vertical Cartesian coordinate into a vertical display coordinate.
void ts5_check_mouse(char *calling_function)
Do some checks at the start of each mouse function.
void ts5_draw_triangle(double x1, double y1, double x2, double y2, double x3, double y3)
Draw a triangle.
double ts5_absolute_to_relative_coordinate_y(const double y)
Convert an absolute vertical coordinate into a relative vertical coordinate.
TS5_COLOR ts5_make_rgb_color(const double r, const double g, const double b, const double a)
Generate a color specification based on an RGB triplet plus an alpha channel.
double ts5_absolute_to_relative_coordinate_x(const double x)
Convert an absolute horizontal coordinate into a relative horizontal coordinate.
void ts5_fatal(const char *format,...)
Exit safely with an error message.
double ts5_relative_to_absolute_coordinate_y(const double y)
Convert a relative vertical coordinate into an absolute vertical coordinate.
double ts5_get_mouse_x()
Get the horizontal position of the mouse pointer.
int ts5_set_coordinate_system(const int coordinate_system)
Set the coordinate system.
double ts5_get_mouse_y()
Get the vertical position of the mouse pointer.