+/*
+ Copyright (C) 2012 Paul Davis
+
+ 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 "canvas-note.h"
#include "midi_region_view.h"
#include "public_editor.h"
namespace Gnome {
namespace Canvas {
+CanvasNote::CanvasNote (MidiRegionView& region,
+ Group& group,
+ const boost::shared_ptr<NoteType> note,
+ bool with_events)
+ : SimpleRect(group), CanvasNoteEvent(region, this, note)
+{
+ if (with_events) {
+ signal_event().connect (sigc::mem_fun (*this, &CanvasNote::on_event));
+ }
+}
+
bool
CanvasNote::on_event(GdkEvent* ev)
{
- double event_x;
- static double middle_point, last_x;
- Gdk::Cursor cursor;
- static NoteEnd note_end;
- Editing::MidiEditMode edit_mode = _region.get_trackview().editor.current_midi_edit_mode();
-
- switch(ev->type) {
- case GDK_BUTTON_PRESS:
- if (ev->button.button == 2 ||
- (ev->button.button == 1 &&
- edit_mode == Editing::MidiEditResize)) {
- double region_start = _region.get_position_pixels();
- event_x = ev->button.x;
- middle_point = region_start + x1() + (x2() - x1()) / 2.0L;
-
- if(event_x <= middle_point) {
- cursor = Gdk::Cursor(Gdk::LEFT_SIDE);
- note_end = NOTE_ON;
- } else {
- cursor = Gdk::Cursor(Gdk::RIGHT_SIDE);
- note_end = NOTE_OFF;
- }
-
- _item->grab(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, cursor, ev->motion.time);
+ bool r = true;
- if (_region.mouse_state() == MidiRegionView::SelectTouchDragging) {
- _note_state = AbsoluteResize;
- } else {
- _note_state = RelativeResize;
- }
-
- _region.note_selected(this, true);
- _region.begin_resizing(note_end);
- last_x = event_x;
-
- return true;
- }
-
- case GDK_MOTION_NOTIFY:
- event_x = ev->motion.x;
-
- if (_note_state == RelativeResize) {
- _region.update_resizing(note_end, event_x - last_x, true);
- last_x = event_x;
- return true;
- }
-
- if (_note_state == AbsoluteResize) {
- _region.update_resizing(note_end, event_x, false);
- return true;
- }
-
- case GDK_BUTTON_RELEASE:
- event_x = ev->button.x;
-
- switch (_note_state) {
- case RelativeResize: // Clicked
- _item->ungrab(ev->button.time);
- _region.commit_resizing(note_end, event_x, true);
- _note_state = None;
- return true;
-
- case AbsoluteResize: // Clicked
- _item->ungrab(ev->button.time);
- _region.commit_resizing(note_end, event_x, false);
- _note_state = None;
- return true;
+ if (!CanvasNoteEvent::on_event (ev)) {
+ r = _region.get_time_axis_view().editor().canvas_note_event (ev, this);
+ }
- default:
- return CanvasNoteEvent::on_event(ev);
- }
+ if (ev->type == GDK_BUTTON_RELEASE) {
+ _region.note_button_release ();
+ }
+
+ return r;
+}
- default:
- return CanvasNoteEvent::on_event(ev);
+void
+CanvasNote::move_event(double dx, double dy)
+{
+ property_x1() = property_x1() + dx;
+ property_y1() = property_y1() + dy;
+ property_x2() = property_x2() + dx;
+ property_y2() = property_y2() + dy;
+
+ if (_text) {
+ _text->hide();
+ _text->property_x() = _text->property_x() + dx;
+ _text->property_y() = _text->property_y() + dy;
+ _text->show();
}
}
+
} // namespace Gnome
} // namespace Canvas