2013-04-05 17:16:33 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2007 Paul Davis
|
|
|
|
Author: Dave Robillard
|
|
|
|
|
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "evoral/Note.hpp"
|
2014-03-06 13:26:36 -05:00
|
|
|
|
2013-04-05 17:16:33 -04:00
|
|
|
#include "canvas/polygon.h"
|
2014-03-06 13:26:36 -05:00
|
|
|
#include "canvas/debug.h"
|
|
|
|
|
2013-04-05 17:16:33 -04:00
|
|
|
#include "hit.h"
|
|
|
|
|
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace ArdourCanvas;
|
|
|
|
|
2014-06-21 11:44:22 -04:00
|
|
|
Hit::Hit (MidiRegionView& region, Item* parent, double size, const boost::shared_ptr<NoteType> note, bool with_events)
|
2013-04-05 17:16:33 -04:00
|
|
|
: NoteBase (region, with_events, note)
|
|
|
|
{
|
2014-06-21 11:44:22 -04:00
|
|
|
_polygon = new ArdourCanvas::Polygon (parent);
|
2014-03-06 13:26:36 -05:00
|
|
|
CANVAS_DEBUG_NAME (_polygon, "note");
|
2013-04-05 17:16:33 -04:00
|
|
|
set_item (_polygon);
|
2014-03-06 13:26:36 -05:00
|
|
|
set_height (size);
|
2013-04-05 17:16:33 -04:00
|
|
|
}
|
|
|
|
|
2014-03-06 23:17:04 -05:00
|
|
|
Hit::~Hit ()
|
|
|
|
{
|
|
|
|
delete _polygon;
|
|
|
|
}
|
|
|
|
|
2013-04-05 17:16:33 -04:00
|
|
|
void
|
|
|
|
Hit::move_event (double dx, double dy)
|
|
|
|
{
|
2014-03-13 11:02:06 -04:00
|
|
|
Points points = _polygon->get();
|
|
|
|
Points moved;
|
|
|
|
for (Points::iterator p = points.begin(); p != points.end(); ++p) {
|
|
|
|
moved.push_back ((*p).translate (ArdourCanvas::Duple (dx, dy)));
|
|
|
|
}
|
|
|
|
_polygon->set (moved);
|
2013-04-05 17:16:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Hit::set_outline_color (uint32_t color)
|
|
|
|
{
|
|
|
|
_polygon->set_outline_color (color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Hit::set_fill_color (uint32_t color)
|
|
|
|
{
|
|
|
|
_polygon->set_fill_color (color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Hit::show ()
|
|
|
|
{
|
|
|
|
_polygon->show ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Hit::hide ()
|
|
|
|
{
|
|
|
|
_polygon->hide ();
|
|
|
|
}
|
|
|
|
|
2014-12-28 21:31:33 -05:00
|
|
|
Points
|
|
|
|
Hit::points(Distance height)
|
2013-04-05 17:16:33 -04:00
|
|
|
{
|
2014-03-06 13:26:36 -05:00
|
|
|
/* draw a diamond */
|
|
|
|
|
|
|
|
Points p;
|
|
|
|
|
|
|
|
const double half_height = height/2.0;
|
|
|
|
p.push_back (Duple (-half_height, 0)); // left, middle
|
|
|
|
p.push_back (Duple (0, -half_height)); // top
|
|
|
|
p.push_back (Duple (+half_height, 0)); // right, middle
|
|
|
|
p.push_back (Duple (0, +half_height)); // bottom
|
|
|
|
|
2014-12-28 21:31:33 -05:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Hit::set_height (Distance height)
|
|
|
|
{
|
|
|
|
_polygon->set (points(height));
|
|
|
|
}
|
|
|
|
|
|
|
|
Duple
|
|
|
|
Hit::position ()
|
|
|
|
{
|
|
|
|
return _polygon->position ();
|
2013-04-05 17:16:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Hit::set_position (Duple position)
|
|
|
|
{
|
|
|
|
_polygon->set_position (position);
|
|
|
|
}
|
2014-03-06 13:26:36 -05:00
|
|
|
|
|
|
|
Coord
|
|
|
|
Hit::x0 () const
|
|
|
|
{
|
|
|
|
/* left vertex */
|
2014-12-28 20:03:38 -05:00
|
|
|
return _polygon->position().x + _polygon->get()[0].x;
|
2014-03-06 13:26:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Coord
|
|
|
|
Hit::x1 () const
|
|
|
|
{
|
|
|
|
/* right vertex */
|
2014-12-28 20:03:38 -05:00
|
|
|
return _polygon->position().x + _polygon->get()[2].x;
|
2014-03-06 13:26:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Coord
|
|
|
|
Hit::y0 () const
|
|
|
|
{
|
|
|
|
/* top vertex */
|
2014-12-28 20:03:38 -05:00
|
|
|
return _polygon->position().y + _polygon->get()[1].y;
|
2014-03-06 13:26:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Coord
|
|
|
|
Hit::y1 () const
|
|
|
|
{
|
|
|
|
/* bottom vertex */
|
2014-12-28 20:03:38 -05:00
|
|
|
return _polygon->position().y + _polygon->get()[3].y;
|
2014-03-06 13:26:36 -05:00
|
|
|
}
|
2014-12-28 20:23:52 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
Hit::set_ignore_events (bool ignore)
|
|
|
|
{
|
|
|
|
_polygon->set_ignore_events (ignore);
|
|
|
|
}
|