2014-06-26 15:03:21 -04:00
|
|
|
/*
|
2019-08-02 22:40:09 -04:00
|
|
|
* Copyright (C) 2014-2015 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2014-06-26 15:03:21 -04:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "canvas/canvas.h"
|
|
|
|
#include "canvas/tracking_text.h"
|
|
|
|
|
|
|
|
using namespace ArdourCanvas;
|
|
|
|
|
|
|
|
TrackingText::TrackingText (Canvas* c)
|
|
|
|
: Text (c)
|
|
|
|
, track_x (true)
|
|
|
|
, track_y (true)
|
|
|
|
, offset (Duple (10, 10))
|
|
|
|
{
|
|
|
|
init ();
|
|
|
|
}
|
|
|
|
|
|
|
|
TrackingText::TrackingText (Item* p)
|
|
|
|
: Text (p)
|
|
|
|
, track_x (true)
|
|
|
|
, track_y (true)
|
|
|
|
, offset (Duple (10, 10))
|
|
|
|
{
|
|
|
|
init ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrackingText::init ()
|
|
|
|
{
|
|
|
|
_canvas->MouseMotion.connect (sigc::mem_fun (*this, &TrackingText::pointer_motion));
|
|
|
|
set_ignore_events (true);
|
2014-06-30 10:39:41 -04:00
|
|
|
set_outline (true);
|
2014-06-26 15:03:21 -04:00
|
|
|
hide ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-12-29 17:54:07 -05:00
|
|
|
TrackingText::pointer_motion (Duple const& winpos)
|
2014-06-26 15:03:21 -04:00
|
|
|
{
|
|
|
|
if (!_visible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Duple pos (_parent->window_to_item (winpos));
|
|
|
|
|
|
|
|
if (!track_x) {
|
2020-12-29 17:54:07 -05:00
|
|
|
pos.x = position ().x;
|
2020-12-29 18:04:47 -05:00
|
|
|
} else {
|
|
|
|
pos.x += offset.x;
|
2014-06-26 15:03:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!track_y) {
|
2020-12-29 17:54:07 -05:00
|
|
|
pos.y = position ().y;
|
2020-12-29 18:04:47 -05:00
|
|
|
} else {
|
|
|
|
pos.y += offset.y;
|
2014-06-26 15:03:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* keep inside the window */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2020-12-29 17:54:07 -05:00
|
|
|
Rect r (0, 0, _canvas->width (), _canvas->height ());
|
2014-06-26 15:03:21 -04:00
|
|
|
|
|
|
|
/* border of 200 pixels on the right, and 50 on all other sides */
|
|
|
|
|
|
|
|
const double border = 50.0;
|
|
|
|
|
|
|
|
r.x0 += border;
|
|
|
|
r.x1 = std::max (r.x0, (r.x1 - 200.0));
|
|
|
|
r.y0 += border;
|
|
|
|
r.y1 = std::max (r.y0, (r.y1 - border));
|
|
|
|
|
|
|
|
/* clamp */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-06-26 15:03:21 -04:00
|
|
|
if (pos.x < r.x0) {
|
|
|
|
pos.x = r.x0;
|
|
|
|
} else if (pos.x > r.x1) {
|
|
|
|
pos.x = r.x1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos.y < r.y0) {
|
|
|
|
pos.y = r.y0;
|
|
|
|
} else if (pos.y > r.y1) {
|
|
|
|
pos.y = r.y1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* move */
|
|
|
|
|
|
|
|
set_position (pos);
|
2024-04-11 22:07:27 -04:00
|
|
|
set_bbox_dirty ();
|
2014-06-26 15:03:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrackingText::show_and_track (bool tx, bool ty)
|
|
|
|
{
|
|
|
|
track_x = tx;
|
|
|
|
track_y = ty;
|
|
|
|
|
|
|
|
bool was_visible = _visible;
|
|
|
|
show ();
|
|
|
|
|
|
|
|
if (!was_visible) {
|
|
|
|
/* move to current pointer location. do this after show() so that
|
2015-10-04 14:51:05 -04:00
|
|
|
* _visible is true, and thus ::pointer_motion() will do
|
2014-06-26 15:03:21 -04:00
|
|
|
* something.
|
|
|
|
*/
|
|
|
|
Duple winpos;
|
|
|
|
|
|
|
|
if (!_canvas->get_mouse_position (winpos)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pointer_motion (winpos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrackingText::set_x_offset (double o)
|
|
|
|
{
|
2020-12-29 17:54:07 -05:00
|
|
|
begin_change ();
|
2014-06-26 15:03:21 -04:00
|
|
|
offset.x = o;
|
2020-12-29 17:54:07 -05:00
|
|
|
end_change ();
|
2014-06-26 15:03:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrackingText::set_y_offset (double o)
|
|
|
|
{
|
2020-12-29 17:54:07 -05:00
|
|
|
begin_change ();
|
2014-06-26 15:03:21 -04:00
|
|
|
offset.y = o;
|
2020-12-29 17:54:07 -05:00
|
|
|
end_change ();
|
2014-06-26 15:03:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-12-29 17:54:07 -05:00
|
|
|
TrackingText::set_offset (Duple const& d)
|
2014-06-26 15:03:21 -04:00
|
|
|
{
|
2020-12-29 17:54:07 -05:00
|
|
|
begin_change ();
|
2014-06-26 15:03:21 -04:00
|
|
|
offset = d;
|
2020-12-29 17:54:07 -05:00
|
|
|
end_change ();
|
2014-06-26 15:03:21 -04:00
|
|
|
}
|