audun's tempo redraw fix; sort-of cache time axis view item name widths and avoid pango-width-computation when unnecessary

git-svn-id: svn://localhost/ardour2/trunk@1657 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2007-04-03 02:05:34 +00:00
parent edfc81352e
commit 4b35fc4c68
15 changed files with 116 additions and 28 deletions

View File

@ -1136,6 +1136,13 @@ AutomationLine::set_selected_points (PointSelection& points)
}
void AutomationLine::set_colors() {
set_line_color( color_map[cAutomationLine] );
for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
(*i)->show_color (false, !points_visible);
}
}
void
AutomationLine::show_selection ()
{

View File

@ -159,6 +159,7 @@ class AutomationLine : public sigc::trackable, public PBD::StatefulThingWithGoin
XMLNode& get_state (void);
int set_state (const XMLNode&);
void set_colors();
protected:

View File

@ -163,6 +163,7 @@ AutomationTimeAxisView::AutomationTimeAxisView (Session& s, boost::shared_ptr<Ro
/* make sure labels etc. are correct */
automation_state_changed ();
ColorChanged.connect (mem_fun (*this, &AutomationTimeAxisView::color_handler));
}
AutomationTimeAxisView::~AutomationTimeAxisView ()
@ -787,6 +788,42 @@ AutomationTimeAxisView::exited ()
hide_all_but_selected_control_points ();
}
void
AutomationTimeAxisView::set_colors () {
for( list<GhostRegion *>::iterator i=ghosts.begin(); i != ghosts.end(); i++ ) {
(*i)->set_colors();
}
for( vector<AutomationLine *>::iterator i=lines.begin(); i != lines.end(); i++ ) {
(*i)->set_colors();
}
}
void
AutomationTimeAxisView::color_handler (ColorID id, uint32_t val) {
switch (id) {
case cGhostTrackWave:
case cGhostTrackWaveClip:
case cGhostTrackZeroLine:
case cControlPoint:
case cControlPointFill:
case cControlPointOutline:
case cAutomationLine:
set_colors ();
break;
default:
break;
}
}
void
AutomationTimeAxisView::set_state (const XMLNode& node)
{

View File

@ -122,6 +122,9 @@ class AutomationTimeAxisView : public TimeAxisView {
void entered ();
void exited ();
void set_colors ();
void color_handler (ColorID, uint32_t);
static Pango::FontDescription name_font;
static bool have_name_font;
};

View File

@ -1075,7 +1075,7 @@ Editor::connect_to_session (Session *t)
session_connections.push_back (session->SMPTEOffsetChanged.connect (mem_fun(*this, &Editor::update_just_smpte)));
session_connections.push_back (session->tempo_map().StateChanged.connect (bind (mem_fun(*this, &Editor::tempo_map_changed), false)));
session_connections.push_back (session->tempo_map().StateChanged.connect (mem_fun(*this, &Editor::tempo_map_changed)));
edit_groups_changed ();
@ -3665,7 +3665,7 @@ Editor::idle_visual_changer ()
/* the signal handler will do the rest */
} else {
update_fixed_rulers();
tempo_map_changed (Change (0), true);
redisplay_tempo (true);
}
}

View File

@ -1275,8 +1275,8 @@ class Editor : public PublicEditor
void remove_metric_marks ();
void draw_metric_marks (const ARDOUR::Metrics& metrics);
void tempo_map_changed (ARDOUR::Change, bool immediate_redraw);
void redisplay_tempo ();
void tempo_map_changed (ARDOUR::Change);
void redisplay_tempo (bool immediate_redraw);
void snap_to (nframes_t& first, int32_t direction = 0, bool for_mark = false);
uint32_t bbt_beat_subdivision;

View File

@ -368,7 +368,7 @@ Editor::track_canvas_size_allocated ()
}
update_fixed_rulers();
tempo_map_changed (Change (0), true);
redisplay_tempo (true);
Resized (); /* EMIT_SIGNAL */
@ -723,6 +723,6 @@ Editor::canvas_horizontally_scrolled ()
update_fixed_rulers ();
tempo_map_changed (Change (0), !_dragging_hscrollbar);
redisplay_tempo (!_dragging_hscrollbar);
}

View File

@ -709,7 +709,7 @@ Editor::update_ruler_visibility ()
update_fixed_rulers();
//update_tempo_based_rulers();
tempo_map_changed(Change (0), false);
redisplay_tempo (false);
time_canvas_event_box.show_all();
time_button_frame.show_all();

View File

@ -93,13 +93,28 @@ Editor::draw_metric_marks (const Metrics& metrics)
}
void
Editor::tempo_map_changed (Change ignored, bool immediate_redraw)
Editor::tempo_map_changed (Change ignored)
{
if (!session) {
return;
}
ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::tempo_map_changed), ignored, immediate_redraw));
ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::tempo_map_changed), ignored));
redisplay_tempo (false); // redraw rulers and measures
session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); // redraw metric markers
}
/**
* This code was originally in tempo_map_changed, but this is called every time the canvas scrolls horizontally.
* That's why this is moved in here. The new tempo_map_changed is called when the ARDOUR::TempoMap actually changed.
*/
void
Editor::redisplay_tempo (bool immediate_redraw)
{
if (!session) {
return;
}
BBT_Time previous_beat, next_beat; // the beats previous to the leftmost frame and after the rightmost frame
@ -152,11 +167,6 @@ Editor::tempo_map_changed (Change ignored, bool immediate_redraw)
}
}
void
Editor::redisplay_tempo ()
{
}
void
Editor::hide_measures ()
{
@ -307,8 +317,6 @@ Editor::mouse_add_new_tempo_event (nframes_t frame)
commit_reversible_command ();
map.dump (cerr);
session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
}
void
@ -349,8 +357,6 @@ Editor::mouse_add_new_meter_event (nframes_t frame)
commit_reversible_command ();
map.dump (cerr);
session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
}
void
@ -401,8 +407,6 @@ Editor::edit_meter_section (MeterSection* section)
XMLNode &after = session->tempo_map().get_state();
session->add_command(new MementoCommand<TempoMap>(session->tempo_map(), &before, &after));
commit_reversible_command ();
session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
}
void
@ -433,8 +437,6 @@ Editor::edit_tempo_section (TempoSection* section)
XMLNode &after = session->tempo_map().get_state();
session->add_command (new MementoCommand<TempoMap>(session->tempo_map(), &before, &after));
commit_reversible_command ();
session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
}
void
@ -485,8 +487,6 @@ Editor::real_remove_tempo_marker (TempoSection *section)
session->add_command(new MementoCommand<TempoMap>(session->tempo_map(), &before, &after));
commit_reversible_command ();
session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
return FALSE;
}
@ -521,7 +521,5 @@ Editor::real_remove_meter_marker (MeterSection *section)
session->add_command(new MementoCommand<TempoMap>(session->tempo_map(), &before, &after));
commit_reversible_command ();
session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
return FALSE;
}

View File

@ -69,3 +69,13 @@ GhostRegion::set_height ()
}
}
void
GhostRegion::set_colors ()
{
for (uint32_t n=0; n < waves.size(); ++n) {
waves[n]->property_wave_color() = color_map[cGhostTrackWave];
waves[n]->property_clip_color() = color_map[cGhostTrackWaveClip];
waves[n]->property_zero_color() = color_map[cGhostTrackZeroLine];
}
}

View File

@ -41,6 +41,7 @@ struct GhostRegion : public sigc::trackable
void set_samples_per_unit (double spu);
void set_duration (double units);
void set_height ();
void set_colors ();
sigc::signal<void,GhostRegion*> GoingAway;
};

View File

@ -125,6 +125,8 @@ void
TimeAxisViewItem::init (const string& it_name, double spu, Gdk::Color& base_color, nframes_t start, nframes_t duration, Visibility vis)
{
item_name = it_name ;
name_text_width = ::pixel_width (it_name, NAME_FONT);
last_name_text_width = 0;
samples_per_unit = spu ;
should_show_selection = true;
frame_position = start ;
@ -488,6 +490,7 @@ TimeAxisViewItem::set_item_name(std::string new_name, void* src)
if (new_name != item_name) {
std::string temp_name = item_name ;
item_name = new_name ;
name_text_width = ::pixel_width (new_name, NAME_FONT);
NameChanged (item_name, temp_name, src) ; /* EMIT_SIGNAL */
}
}
@ -553,10 +556,11 @@ TimeAxisViewItem::get_time_axis_view()
* @param new_name the new name text to display
*/
void
TimeAxisViewItem::set_name_text(std::string new_name)
TimeAxisViewItem::set_name_text(const ustring& new_name)
{
if (name_text) {
name_text->property_text() = new_name.c_str();
name_text_width = pixel_width (new_name, NAME_FONT);
}
}
@ -913,6 +917,13 @@ TimeAxisViewItem::reset_name_width (double pixel_width)
if (name_text == 0) {
return;
}
if ((last_name_text_width && // we did this once
(name_text_width <= pixel_width - NAME_X_OFFSET) && // fits the new size
(name_text_width <= last_name_text_width - NAME_X_OFFSET))) { // fit into the old size too
last_name_text_width = pixel_width;
return;
}
int width;
@ -941,6 +952,8 @@ TimeAxisViewItem::reset_name_width (double pixel_width)
name_text->property_text() = ustr;
name_text->show();
}
last_name_text_width = pixel_width;
}

View File

@ -199,7 +199,7 @@ class TimeAxisViewItem : public Selectable
*
* @param new_name the new name text to display
*/
void set_name_text(std::string new_name) ;
void set_name_text(const Glib::ustring& new_name) ;
/**
* Set the height of this item
@ -461,6 +461,9 @@ class TimeAxisViewItem : public Selectable
ArdourCanvas::SimpleRect* frame_handle_start;
ArdourCanvas::SimpleRect* frame_handle_end;
int name_text_width;
double last_name_text_width;
Visibility visibility;
}; /* class TimeAxisViewItem */

View File

@ -44,6 +44,20 @@ using namespace sigc;
using namespace Glib;
using namespace PBD;
int
pixel_width (const ustring& str, Pango::FontDescription& font)
{
Label foo;
Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout ("");
layout->set_font_description (font);
layout->set_text (str);
int width, height;
Gtkmm2ext::get_ink_pixel_size (layout, width, height);
return width;
}
ustring
fit_to_pixels (const ustring& str, int pixel_width, Pango::FontDescription& font, int& actual_width, bool with_ellipses)
{

View File

@ -53,6 +53,7 @@ slider_position_to_gain (double pos)
}
Glib::ustring fit_to_pixels (const Glib::ustring&, int pixel_width, Pango::FontDescription& font, int& actual_width, bool with_ellipses = false);
int pixel_width (const Glib::ustring& str, Pango::FontDescription& font);
gint just_hide_it (GdkEventAny*, Gtk::Window*);
void allow_keyboard_focus (bool);