X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Ftime_axis_view_item.cc;h=2b20b3c45e6db337c401003aafa25fbb87ebb7bd;hb=cd0d68a591ee64bb0e85d9a364af9fe6abdeecbe;hp=f0dd9a7984d79c56b064c107d8e2d663d877f0a5;hpb=4fca993a840368e8313827676f7a63e1c79af32d;p=ardour.git diff --git a/gtk2_ardour/time_axis_view_item.cc b/gtk2_ardour/time_axis_view_item.cc index f0dd9a7984..2b20b3c45e 100644 --- a/gtk2_ardour/time_axis_view_item.cc +++ b/gtk2_ardour/time_axis_view_item.cc @@ -23,7 +23,8 @@ #include "ardour/types.h" #include "ardour/ardour.h" -#include +#include "gtkmm2ext/utils.h" +#include "gtkmm2ext/gui_thread.h" #include "ardour_ui.h" /* @@ -49,9 +50,10 @@ using namespace PBD; using namespace ARDOUR; using namespace Gtkmm2ext; -Pango::FontDescription* TimeAxisViewItem::NAME_FONT = 0; +Pango::FontDescription TimeAxisViewItem::NAME_FONT; const double TimeAxisViewItem::NAME_X_OFFSET = 15.0; -const double TimeAxisViewItem::GRAB_HANDLE_LENGTH = 6; +const double TimeAxisViewItem::GRAB_HANDLE_TOP = 6; +const double TimeAxisViewItem::GRAB_HANDLE_WIDTH = 5; int TimeAxisViewItem::NAME_HEIGHT; double TimeAxisViewItem::NAME_Y_OFFSET; @@ -62,18 +64,18 @@ void TimeAxisViewItem::set_constant_heights () { NAME_FONT = get_font_for_style (X_("TimeAxisViewItemName")); - + Gtk::Window win; Gtk::Label foo; win.add (foo); - + Glib::RefPtr layout = foo.create_pango_layout (X_("Hg")); /* ascender + descender */ int width = 0; int height = 0; - - layout->set_font_description (*NAME_FONT); + + layout->set_font_description (NAME_FONT); Gtkmm2ext::get_ink_pixel_size (layout, width, height); - + NAME_HEIGHT = height; NAME_Y_OFFSET = height + 3; NAME_HIGHLIGHT_SIZE = height + 2; @@ -101,6 +103,7 @@ TimeAxisViewItem::TimeAxisViewItem( , _height (1.0) , _recregion (recording) , _automation (automation) + , _dragging (false) { group = new ArdourCanvas::Group (parent); @@ -108,11 +111,13 @@ TimeAxisViewItem::TimeAxisViewItem( } TimeAxisViewItem::TimeAxisViewItem (const TimeAxisViewItem& other) - : sigc::trackable(other) + : trackable (other) + , Selectable (other) , PBD::ScopedConnectionList() , trackview (other.trackview) , _recregion (other._recregion) , _automation (other._automation) + , _dragging (other._dragging) { Gdk::Color c; @@ -129,10 +134,8 @@ TimeAxisViewItem::TimeAxisViewItem (const TimeAxisViewItem& other) _selected = other._selected; - init ( - other.item_name, other.samples_per_unit, c, other.frame_position, - other.item_duration, other.visibility, other.wide_enough_for_name, other.high_enough_for_name - ); + init (other.item_name, other.samples_per_unit, c, other.frame_position, + other.item_duration, other.visibility, other.wide_enough_for_name, other.high_enough_for_name); } void @@ -155,6 +158,7 @@ TimeAxisViewItem::init ( last_item_width = 0; wide_enough_for_name = wide; high_enough_for_name = high; + rect_visible = true; if (duration == 0) { warning << "Time Axis Item Duration == 0" << endl; @@ -168,16 +172,16 @@ TimeAxisViewItem::init ( if (visibility & ShowFrame) { frame = new ArdourCanvas::SimpleRect (*group, 0.0, 1.0, trackview.editor().frame_to_pixel(duration), trackview.current_height()); - + frame->property_outline_pixels() = 1; frame->property_outline_what() = 0xF; - + if (_recregion) { frame->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RecordingRect.get(); } else { frame->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeAxisFrame.get(); } - + frame->property_outline_what() = 0x1|0x2|0x4|0x8; } else { @@ -185,13 +189,13 @@ TimeAxisViewItem::init ( } if (visibility & ShowNameHighlight) { - + if (visibility & FullWidthNameHighlight) { name_highlight = new ArdourCanvas::SimpleRect (*group, 0.0, trackview.editor().frame_to_pixel(item_duration), trackview.current_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE, trackview.current_height()); } else { name_highlight = new ArdourCanvas::SimpleRect (*group, 1.0, trackview.editor().frame_to_pixel(item_duration) - 1, trackview.current_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE, trackview.current_height()); } - + name_highlight->set_data ("timeaxisviewitem", this); name_highlight->property_outline_what() = 0x4; /* we should really use a canvas color property here */ @@ -212,9 +216,12 @@ TimeAxisViewItem::init ( /* create our grab handles used for trimming/duration etc */ if (!_recregion && !_automation) { - frame_handle_start = new ArdourCanvas::SimpleRect (*group, 0.0, TimeAxisViewItem::GRAB_HANDLE_LENGTH, 5.0, trackview.current_height()); + double top = TimeAxisViewItem::GRAB_HANDLE_TOP; + double width = TimeAxisViewItem::GRAB_HANDLE_WIDTH; + + frame_handle_start = new ArdourCanvas::SimpleRect (*group, 0.0, top, width, trackview.current_height()); frame_handle_start->property_outline_what() = 0x0; - frame_handle_end = new ArdourCanvas::SimpleRect (*group, 0.0, TimeAxisViewItem::GRAB_HANDLE_LENGTH, 5.0, trackview.current_height()); + frame_handle_end = new ArdourCanvas::SimpleRect (*group, 0.0, top, width, trackview.current_height()); frame_handle_end->property_outline_what() = 0x0; } else { frame_handle_start = frame_handle_end = 0; @@ -224,6 +231,8 @@ TimeAxisViewItem::init ( set_duration (item_duration, this); set_position (start, this); + + Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&TimeAxisViewItem::parameter_changed, this, _1), gui_context ()); } TimeAxisViewItem::~TimeAxisViewItem() @@ -231,6 +240,30 @@ TimeAxisViewItem::~TimeAxisViewItem() delete group; } +void +TimeAxisViewItem::hide_rect () +{ + rect_visible = false; + set_frame_color (); + + if (name_highlight) { + name_highlight->property_outline_what() = 0x0; + name_highlight->property_fill_color_rgba() = UINT_RGBA_CHANGE_A(fill_color,64); + } +} + +void +TimeAxisViewItem::show_rect () +{ + rect_visible = true; + set_frame_color (); + + if (name_highlight) { + name_highlight->property_outline_what() = 0x4; + name_highlight->property_fill_color_rgba() = fill_color; + } +} + /** * Set the position of this item on the timeline. @@ -292,10 +325,12 @@ TimeAxisViewItem::get_position() const */ bool -TimeAxisViewItem::set_duration (framepos_t dur, void* src) +TimeAxisViewItem::set_duration (framecnt_t dur, void* src) { if ((dur > max_item_duration) || (dur < min_item_duration)) { - warning << string_compose (_("new duration %1 frames is out of bounds for %2"), get_item_name(), dur) + warning << string_compose ( + P_("new duration %1 frame is out of bounds for %2", "new duration of %1 frames is out of bounds for %2", dur), + get_item_name(), dur) << endmsg; return false; } @@ -480,7 +515,7 @@ TimeAxisViewItem::set_name_text(const string& new_name) } last_item_width = trackview.editor().frame_to_pixel(item_duration); - name_pixbuf_width = pixel_width (new_name, *NAME_FONT) + 2; + name_pixbuf_width = pixel_width (new_name, NAME_FONT) + 2; name_pixbuf->property_pixbuf() = pixbuf_from_string(new_name, NAME_FONT, name_pixbuf_width, NAME_HEIGHT, Gdk::Color ("#000000")); } @@ -531,6 +566,7 @@ TimeAxisViewItem::set_height (double height) vestigial_frame->property_y2() = height - 1; update_name_pixbuf_visibility (); + set_colors (); } void @@ -678,27 +714,61 @@ TimeAxisViewItem::set_colors() void TimeAxisViewItem::set_frame_color() { + uint32_t f = 0; + if (!frame) { return; } - + if (_selected) { + + f = ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(); + if (fill_opacity) { - frame->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(), fill_opacity); - } else { - frame->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectedFrameBase.get(); + f = UINT_RGBA_CHANGE_A (f, fill_opacity); } + + if (!rect_visible) { + f = UINT_RGBA_CHANGE_A (f, 0); + } + } else { + if (_recregion) { - frame->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RecordingRect.get(); + f = ARDOUR_UI::config()->canvasvar_RecordingRect.get(); } else { - if (fill_opacity) { - frame->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (ARDOUR_UI::config()->canvasvar_FrameBase.get(), fill_opacity); + + if (high_enough_for_name && !Config->get_color_regions_using_track_color()) { + f = ARDOUR_UI::config()->canvasvar_FrameBase.get(); } else { - frame->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_FrameBase.get(); + f = fill_color; } - } + + if (fill_opacity) { + f = UINT_RGBA_CHANGE_A (f, fill_opacity); + } + + if (!rect_visible) { + f = UINT_RGBA_CHANGE_A (f, 0); + } + } } + + frame->property_fill_color_rgba() = f; + + if (!_recregion) { + if (_selected) { + f = ARDOUR_UI::config()->canvasvar_SelectedTimeAxisFrame.get(); + } else { + f = ARDOUR_UI::config()->canvasvar_TimeAxisFrame.get(); + } + + if (!rect_visible) { + f = UINT_RGBA_CHANGE_A (f, 64); + } + + frame->property_outline_color_rgba() = f; + } } /** @@ -743,14 +813,6 @@ TimeAxisViewItem::set_samples_per_unit (double spu) void TimeAxisViewItem::reset_width_dependent_items (double pixel_width) { - if (pixel_width < GRAB_HANDLE_LENGTH * 2) { - - if (frame_handle_start) { - frame_handle_start->hide(); - frame_handle_end->hide(); - } - - } if (pixel_width < 2.0) { @@ -788,7 +850,7 @@ TimeAxisViewItem::reset_width_dependent_items (double pixel_width) } high_enough_for_name = true; } - + name_highlight->property_x2() = pixel_width; } @@ -798,15 +860,23 @@ TimeAxisViewItem::reset_width_dependent_items (double pixel_width) } if (frame_handle_start) { - if (pixel_width < (2*TimeAxisViewItem::GRAB_HANDLE_LENGTH)) { + if (pixel_width < (3 * TimeAxisViewItem::GRAB_HANDLE_WIDTH)) { + /* + * there's less than GRAB_HANDLE_WIDTH of the region between + * the right-hand end of frame_handle_start and the left-hand + * end of frame_handle_end, so disable the handles + */ frame_handle_start->hide(); frame_handle_end->hide(); + } else { + frame_handle_start->show(); + frame_handle_end->property_x1() = pixel_width - (TimeAxisViewItem::GRAB_HANDLE_WIDTH); + frame_handle_end->property_x2() = pixel_width; + frame_handle_end->show(); } - frame_handle_start->show(); - frame_handle_end->property_x1() = pixel_width - (TimeAxisViewItem::GRAB_HANDLE_LENGTH); - frame_handle_end->show(); - frame_handle_end->property_x2() = pixel_width; } + + wide_enough_for_name = true; } update_name_pixbuf_visibility (); @@ -831,16 +901,16 @@ TimeAxisViewItem::reset_name_width (double /*pixel_width*/) if (pixbuf_holds_full_name && (it_width >= pb_width + NAME_X_OFFSET)) { /* - we've previously had the full name length showing + we've previously had the full name length showing and its still showing. */ return; } - + if (pb_width > it_width - NAME_X_OFFSET) { pb_width = it_width - NAME_X_OFFSET; } - + if (it_width <= NAME_X_OFFSET) { wide_enough_for_name = false; } else { @@ -848,9 +918,12 @@ TimeAxisViewItem::reset_name_width (double /*pixel_width*/) } update_name_pixbuf_visibility (); - if (pb_width > 0) { - name_pixbuf->property_pixbuf() = pixbuf_from_string(item_name, NAME_FONT, pb_width, NAME_HEIGHT, Gdk::Color ("#000000")); + + if (pb_width < 1) { + pb_width = 1; } + + name_pixbuf->property_pixbuf() = pixbuf_from_string(item_name, NAME_FONT, pb_width, NAME_HEIGHT, Gdk::Color ("#000000")); } /** @@ -885,7 +958,7 @@ TimeAxisViewItem::update_name_pixbuf_visibility () if (!name_pixbuf) { return; } - + if (wide_enough_for_name && high_enough_for_name) { name_pixbuf->show (); } else { @@ -893,3 +966,10 @@ TimeAxisViewItem::update_name_pixbuf_visibility () } } +void +TimeAxisViewItem::parameter_changed (string p) +{ + if (p == "color-regions-using-track-color") { + set_frame_color (); + } +}