From 811acc5e6ed88a8268791f7a0520d36b350f6414 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 2 Jun 2011 17:58:02 +0000 Subject: Tidy. git-svn-id: svn://localhost/ardour2/branches/3.0@9674 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/gtkmm2ext/cairocell.cc | 80 ++++----- libs/gtkmm2ext/gtkmm2ext/cairocell.h | 303 ++++++++++++++++++----------------- 2 files changed, 193 insertions(+), 190 deletions(-) diff --git a/libs/gtkmm2ext/cairocell.cc b/libs/gtkmm2ext/cairocell.cc index 91ed08922e..6f9a53e314 100644 --- a/libs/gtkmm2ext/cairocell.cc +++ b/libs/gtkmm2ext/cairocell.cc @@ -50,7 +50,7 @@ CairoColonCell::render (Cairo::RefPtr& context) context->fill (); } -void +void CairoColonCell::set_size (Glib::RefPtr& context, const Pango::FontDescription& font) { Pango::FontMetrics metrics = context->get_metrics (font); @@ -66,7 +66,7 @@ CairoTextCell::CairoTextCell (double wc) void CairoTextCell::set_text (const std::string& txt) { - layout->set_text (txt); + layout->set_text (txt); } void @@ -88,7 +88,7 @@ CairoTextCell::set_size (Glib::RefPtr& context, const Pango::Fon layout = Pango::Layout::create (context); } - layout->set_font_description (font); + layout->set_font_description (font); Pango::FontMetrics metrics = context->get_metrics (font); @@ -107,20 +107,20 @@ CairoEditableText::get_cell (uint32_t id) } CairoEditableText::CairoEditableText () - : editing_id (0) - , width (0) - , max_cell_height (0) - , height (0) - , corner_radius (18) - , xpad (10) - , ypad (5) + : editing_id (0) + , width (0) + , max_cell_height (0) + , height (0) + , corner_radius (18) + , xpad (10) + , ypad (5) { - add_events (Gdk::POINTER_MOTION_HINT_MASK | Gdk::SCROLL_MASK | Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK | - Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::SCROLL_MASK); - set_flags (Gtk::CAN_FOCUS); + add_events (Gdk::POINTER_MOTION_HINT_MASK | Gdk::SCROLL_MASK | Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK | + Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::SCROLL_MASK); + set_flags (Gtk::CAN_FOCUS); - set_can_default (true); - set_receives_default (true); + set_can_default (true); + set_receives_default (true); } CairoEditableText::~CairoEditableText () @@ -152,11 +152,11 @@ CairoEditableText::on_focus_in_event (GdkEventFocus* ev) bool CairoEditableText::on_focus_out_event (GdkEventFocus* ev) { - if (editing_id) { - CairoCell* cell = get_cell (editing_id); - queue_draw_cell (cell); - editing_id = 0; - } + if (editing_id) { + CairoCell* cell = get_cell (editing_id); + queue_draw_cell (cell); + editing_id = 0; + } return false; } @@ -182,10 +182,10 @@ CairoEditableText::set_text (uint32_t id, const string& text) CairoTextCell* textcell = dynamic_cast (i->second); - if (textcell) { - set_text (textcell, text); - } -} + if (textcell) { + set_text (textcell, text); + } +} void CairoEditableText::set_text (CairoTextCell* cell, const string& text) @@ -198,7 +198,7 @@ bool CairoEditableText::on_expose_event (GdkEventExpose* ev) { Cairo::RefPtr context = get_window()->create_cairo_context(); - + if (cells.empty()) { return true; } @@ -209,27 +209,27 @@ CairoEditableText::on_expose_event (GdkEventExpose* ev) context->set_source_rgba (bg_r, bg_g, bg_b, bg_a); rounded_rectangle (context, 0, 0, width, height, corner_radius); context->fill (); - + for (CellMap::iterator i = cells.begin(); i != cells.end(); ++i) { - + uint32_t id = i->first; CairoCell* cell = i->second; - + /* is cell inside the expose area? */ - if (cell->intersects (ev->area)) { + if (cell->intersects (ev->area)) { if (id == editing_id) { context->set_source_rgba (edit_r, edit_b, edit_g, edit_a); } else { context->set_source_rgba (r, g, b, a); } - + cell->render (context); } } - return true; + return true; } void @@ -268,26 +268,26 @@ CairoEditableText::find_cell (uint32_t x, uint32_t y, uint32_t& id) bool CairoEditableText::on_button_press_event (GdkEventButton* ev) { - uint32_t id; - CairoCell* cell = find_cell (ev->x, ev->y, id); - + uint32_t id; + CairoCell* cell = find_cell (ev->x, ev->y, id); + if (!cell) { return false; } - + return button_press (ev, id); } bool CairoEditableText::on_button_release_event (GdkEventButton* ev) { - uint32_t id; - CairoCell* cell = find_cell (ev->x, ev->y, id); - + uint32_t id; + CairoCell* cell = find_cell (ev->x, ev->y, id); + if (!cell) { return false; } - + return button_release (ev, id); } @@ -363,7 +363,7 @@ CairoEditableText::set_font (const Pango::FontDescription& fd) { Glib::RefPtr context = get_pango_context (); - for (CellMap::iterator i = cells.begin(); i != cells.end(); ++i) { + for (CellMap::iterator i = cells.begin(); i != cells.end(); ++i) { i->second->set_size (context, fd); } diff --git a/libs/gtkmm2ext/gtkmm2ext/cairocell.h b/libs/gtkmm2ext/gtkmm2ext/cairocell.h index 998f6f99d0..336a440c5b 100644 --- a/libs/gtkmm2ext/gtkmm2ext/cairocell.h +++ b/libs/gtkmm2ext/gtkmm2ext/cairocell.h @@ -28,175 +28,178 @@ class CairoCell { - public: - CairoCell(); - virtual ~CairoCell() {} - - virtual void render (Cairo::RefPtr&) = 0; - - double x() const { return bbox.x; } - double y() const { return bbox.y; } - double width() const { return bbox.width; } - double height() const { return bbox.height; } - - void set_position (double x, double y) { - bbox.x = x; - bbox.y = y; - } - - bool intersects (GdkRectangle& r) const { - return gdk_rectangle_intersect (&r, &bbox, 0); - } - - bool covers (double x, double y) const { - return bbox.x <= x && bbox.x + bbox.width > x && - bbox.y <= y && bbox.y + bbox.height > y; - } - - double xpad() const { return _xpad; } - void set_xpad (double x) { _xpad = x; } - - void set_visible (bool yn) { _visible = yn; } - bool visible() const { return _visible; } - virtual void set_size (Glib::RefPtr&, const Pango::FontDescription&) {} - - protected: - GdkRectangle bbox; - bool _visible; - uint32_t _xpad; +public: + CairoCell(); + virtual ~CairoCell() {} + + virtual void render (Cairo::RefPtr&) = 0; + + double x() const { return bbox.x; } + double y() const { return bbox.y; } + double width() const { return bbox.width; } + double height() const { return bbox.height; } + + void set_position (double x, double y) { + bbox.x = x; + bbox.y = y; + } + + bool intersects (GdkRectangle& r) const { + return gdk_rectangle_intersect (&r, &bbox, 0); + } + + bool covers (double x, double y) const { + return bbox.x <= x && bbox.x + bbox.width > x && + bbox.y <= y && bbox.y + bbox.height > y; + } + + double xpad() const { return _xpad; } + void set_xpad (double x) { _xpad = x; } + + void set_visible (bool yn) { _visible = yn; } + bool visible() const { return _visible; } + virtual void set_size (Glib::RefPtr&, + const Pango::FontDescription&) {} + +protected: + GdkRectangle bbox; + bool _visible; + uint32_t _xpad; }; class CairoBarCell : public CairoCell { - public: - CairoBarCell() {}; - - void render (Cairo::RefPtr& context) { - context->move_to (bbox.x, bbox.y); - context->set_line_width (bbox.width); - context->rel_line_to (0, bbox.height); - context->stroke (); - } - - void set_size (Glib::RefPtr& context, const Pango::FontDescription& font) { - Pango::FontMetrics metrics = context->get_metrics (font); - bbox.width = 2; - bbox.height = (metrics.get_ascent() + metrics.get_descent()) / PANGO_SCALE; - } - - private: +public: + CairoBarCell() {}; + + void render (Cairo::RefPtr& context) { + context->move_to (bbox.x, bbox.y); + context->set_line_width (bbox.width); + context->rel_line_to (0, bbox.height); + context->stroke (); + } + + void set_size (Glib::RefPtr& context, + const Pango::FontDescription& font) { + Pango::FontMetrics metrics = context->get_metrics (font); + bbox.width = 2; + bbox.height = (metrics.get_ascent() + metrics.get_descent()) / PANGO_SCALE; + } + +private: }; class CairoColonCell : public CairoCell { - public: - CairoColonCell() {}; - - void render (Cairo::RefPtr& context); - void set_size (Glib::RefPtr& context, const Pango::FontDescription& font); +public: + CairoColonCell() {}; + + void render (Cairo::RefPtr& context); + void set_size (Glib::RefPtr& context, + const Pango::FontDescription& font); }; class CairoTextCell : public CairoCell { - public: - CairoTextCell (double width_chars); - void set_size (Glib::RefPtr&, const Pango::FontDescription&); +public: + CairoTextCell (double width_chars); + void set_size (Glib::RefPtr&, const Pango::FontDescription&); - void set_text (const std::string& txt); + void set_text (const std::string& txt); - std::string get_text() const { - return layout->get_text (); - } - double width_chars() const { return _width_chars; } - void render (Cairo::RefPtr&); + std::string get_text() const { + return layout->get_text (); + } + double width_chars() const { return _width_chars; } + void render (Cairo::RefPtr&); - protected: - double _width_chars; - Glib::RefPtr layout; +protected: + double _width_chars; + Glib::RefPtr layout; }; class CairoEditableText : public Gtk::Misc { - public: - CairoEditableText (); - ~CairoEditableText (); - - void add_cell (uint32_t id, CairoCell*); - CairoCell* get_cell (uint32_t id); - - void start_editing (uint32_t id); - void stop_editing (); - - void set_text (uint32_t id, const std::string& text); - void set_text (CairoTextCell* cell, const std::string&); - - void set_colors (double cr, double cg, double cb, double ca) { - r = cr; - g = cg; - b = cb; - a = ca; - queue_draw (); - } - - void set_edit_colors (double cr, double cg, double cb, double ca) { - edit_r = cr; - edit_g = cg; - edit_b = cb; - edit_a = ca; - queue_draw (); - } - - void set_bg (double r, double g, double b, double a) { - bg_r = r; - bg_g = g; - bg_b = b; - bg_a = a; - } - - void set_font (const std::string& str); - void set_font (const Pango::FontDescription&); - - sigc::signal scroll; - sigc::signal button_press; - sigc::signal button_release; - - protected: - bool on_expose_event (GdkEventExpose*); - bool on_button_press_event (GdkEventButton*); - bool on_button_release_event (GdkEventButton*); - void on_size_request (GtkRequisition*); - void on_size_allocate (Gtk::Allocation&); - bool on_focus_in_event (GdkEventFocus*); - bool on_focus_out_event (GdkEventFocus*); - bool on_scroll_event (GdkEventScroll*); - - private: - typedef std::map CellMap; - - CellMap cells; - Pango::FontDescription font; - uint32_t editing_id; - double width; - double max_cell_height; - double height; - double corner_radius; - double xpad; - double ypad; - double r; - double g; - double b; - double a; - double edit_r; - double edit_g; - double edit_b; - double edit_a; - double bg_r; - double bg_g; - double bg_b; - double bg_a; - - CairoCell* find_cell (uint32_t x, uint32_t y, uint32_t& cell_id); - void queue_draw_cell (CairoCell* target); +public: + CairoEditableText (); + ~CairoEditableText (); + + void add_cell (uint32_t id, CairoCell*); + CairoCell* get_cell (uint32_t id); + + void start_editing (uint32_t id); + void stop_editing (); + + void set_text (uint32_t id, const std::string& text); + void set_text (CairoTextCell* cell, const std::string&); + + void set_colors (double cr, double cg, double cb, double ca) { + r = cr; + g = cg; + b = cb; + a = ca; + queue_draw (); + } + + void set_edit_colors (double cr, double cg, double cb, double ca) { + edit_r = cr; + edit_g = cg; + edit_b = cb; + edit_a = ca; + queue_draw (); + } + + void set_bg (double r, double g, double b, double a) { + bg_r = r; + bg_g = g; + bg_b = b; + bg_a = a; + } + + void set_font (const std::string& str); + void set_font (const Pango::FontDescription&); + + sigc::signal scroll; + sigc::signal button_press; + sigc::signal button_release; + +protected: + bool on_expose_event (GdkEventExpose*); + bool on_button_press_event (GdkEventButton*); + bool on_button_release_event (GdkEventButton*); + void on_size_request (GtkRequisition*); + void on_size_allocate (Gtk::Allocation&); + bool on_focus_in_event (GdkEventFocus*); + bool on_focus_out_event (GdkEventFocus*); + bool on_scroll_event (GdkEventScroll*); + +private: + typedef std::map CellMap; + + CellMap cells; + Pango::FontDescription font; + uint32_t editing_id; + double width; + double max_cell_height; + double height; + double corner_radius; + double xpad; + double ypad; + double r; + double g; + double b; + double a; + double edit_r; + double edit_g; + double edit_b; + double edit_a; + double bg_r; + double bg_g; + double bg_b; + double bg_a; + + CairoCell* find_cell (uint32_t x, uint32_t y, uint32_t& cell_id); + void queue_draw_cell (CairoCell* target); }; #endif /* __libgtmm2ext_cairocell_h__ */ -- cgit v1.2.3