Move Gtkmm2ext widgets into libwidget

This commit is contained in:
Robin Gareus 2017-07-16 22:13:46 +02:00
parent b6e4dfe37b
commit f6e182b937
48 changed files with 218 additions and 252 deletions

View file

@ -0,0 +1,158 @@
/*
Copyright (C) 2006 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.
*/
#ifndef _WIDGETS_ARDOUR_FADER_H_
#define _WIDGETS_ARDOUR_FADER_H_
#include <cmath>
#include <stdint.h>
#include <gdkmm.h>
#include <gtkmm/adjustment.h>
#include "gtkmm2ext/cairo_widget.h"
#include "widgets/visibility.h"
namespace ArdourWidgets {
class LIBWIDGETS_API ArdourFader : public CairoWidget
{
public:
ArdourFader (Gtk::Adjustment& adjustment, int orientation, int span, int girth);
virtual ~ArdourFader ();
static void flush_pattern_cache();
sigc::signal<void> StartGesture;
sigc::signal<void> StopGesture;
sigc::signal<void> OnExpose;
void set_default_value (float);
void set_text (const std::string&, bool centered = true, bool expose = true);
enum Tweaks {
NoShowUnityLine = 0x1,
NoButtonForward = 0x2,
NoVerticalScroll = 0x4,
};
Tweaks tweaks() const { return _tweaks; }
void set_tweaks (Tweaks);
protected:
void on_size_request (GtkRequisition*);
void on_size_allocate (Gtk::Allocation& alloc);
void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
bool on_grab_broken_event (GdkEventGrabBroken*);
bool on_button_press_event (GdkEventButton*);
bool on_button_release_event (GdkEventButton*);
bool on_motion_notify_event (GdkEventMotion*);
bool on_scroll_event (GdkEventScroll* ev);
bool on_enter_notify_event (GdkEventCrossing* ev);
bool on_leave_notify_event (GdkEventCrossing* ev);
void on_state_changed (Gtk::StateType);
void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
enum Orientation {
VERT,
HORIZ,
};
private:
Glib::RefPtr<Pango::Layout> _layout;
std::string _text;
Tweaks _tweaks;
Gtk::Adjustment& _adjustment;
int _text_width;
int _text_height;
int _span, _girth;
int _min_span, _min_girth;
int _orien;
cairo_pattern_t* _pattern;
bool _hovering;
GdkWindow* _grab_window;
double _grab_loc;
double _grab_start;
bool _dragging;
float _default_value;
int _unity_loc;
bool _centered_text;
sigc::connection _parent_style_change;
Widget * _current_parent;
Gdk::Color get_parent_bg ();
void create_patterns();
void adjustment_changed ();
void set_adjustment_from_event (GdkEventButton *);
void update_unity_position ();
int display_span ();
struct FaderImage {
cairo_pattern_t* pattern;
double fr;
double fg;
double fb;
double br;
double bg;
double bb;
int width;
int height;
FaderImage (cairo_pattern_t* p,
double afr, double afg, double afb,
double abr, double abg, double abb,
int w, int h)
: pattern (p)
, fr (afr)
, fg (afg)
, fb (afb)
, br (abr)
, bg (abg)
, bb (abb)
, width (w)
, height (h)
{}
bool matches (double afr, double afg, double afb,
double abr, double abg, double abb,
int w, int h) {
return width == w &&
height == h &&
afr == fr &&
afg == fg &&
afb == fb &&
abr == br &&
abg == bg &&
abb == bb;
}
};
static std::list<FaderImage*> _patterns;
static cairo_pattern_t* find_pattern (double afr, double afg, double afb,
double abr, double abg, double abb,
int w, int h);
};
} /* namespace */
#endif /* __gtkmm2ext_pixfader_h__ */

View file

@ -0,0 +1,76 @@
/*
Copyright (C) 2000 Paul Barton-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.
*/
#ifndef _WIDGETS_AUTO_SPIN_H_
#define _WIDGETS_AUTO_SPIN_H_
#ifdef interface
#undef interface
#endif
#include <gtkmm.h>
#include "widgets/visibility.h"
namespace ArdourWidgets {
class LIBWIDGETS_API AutoSpin
{
public:
AutoSpin (Gtk::Adjustment &adj, gfloat cr = 0, bool round_to_steps_yn = false);
Gtk::Adjustment &get_adjustment() { return adjustment; }
void use_left_as_decrement (bool yn) { left_is_decrement = yn; }
void set_wrap (bool yn) { wrap = yn; }
void set_climb_rate (gfloat cr) { climb_rate = cr; }
void set_bounds (gfloat initial, gfloat low, gfloat high, bool with_reset = true);
gint button_press (GdkEventButton *);
gint stop_spinning (GdkEventButton *ignored_but_here_for_clicked);
void start_spinning (bool decrementing, bool use_page);
gint scroll_event (GdkEventScroll *);
private:
Gtk::Adjustment &adjustment;
gfloat climb_rate;
gfloat timer_increment;
gfloat initial;
unsigned int timer_calls;
bool have_timer;
bool need_timer;
bool wrap;
gint timeout_tag;
bool left_is_decrement;
bool round_to_steps;
static const unsigned int initial_timer_interval;
static const unsigned int timer_interval;
static const unsigned int climb_timer_calls;
void stop_timer ();
static gint _timer (void *arg);
gint timer ();
bool adjust_value (gfloat increment);
void set_value (gfloat value);
};
} /* namespace */
#endif

View file

@ -0,0 +1,83 @@
/*
Copyright (C) 2004 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.
*/
#ifndef _WIDGETS_BAR_CONTROLLER_H_
#define _WIDGETS_BAR_CONTROLLER_H_
#include <gtkmm/alignment.h>
#include <cairo.h>
#include "gtkmm2ext/binding_proxy.h"
#include "widgets/slider_controller.h"
#include "widgets/visibility.h"
namespace ArdourWidgets {
class LIBWIDGETS_API BarController : public Gtk::Alignment
{
public:
BarController (Gtk::Adjustment& adj, boost::shared_ptr<PBD::Controllable>);
virtual ~BarController ();
void set_sensitive (bool yn);
ArdourFader::Tweaks tweaks() const { return _slider.tweaks (); }
void set_tweaks (ArdourFader::Tweaks t) { _slider.set_tweaks (t);}
sigc::signal<void> StartGesture;
sigc::signal<void> StopGesture;
/* export this to allow direct connection to button events */
Gtk::Widget& event_widget() { return _slider; }
/** Emitted when the adjustment spinner is activated or deactivated;
* the parameter is true on activation, false on deactivation.
*/
sigc::signal<void, bool> SpinnerActive;
protected:
bool on_button_press_event (GdkEventButton*);
bool on_button_release_event (GdkEventButton*);
void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
virtual std::string get_label (double& /*x*/) {
return "";
}
private:
HSliderController _slider;
bool entry_focus_out (GdkEventFocus*);
void entry_activated ();
void before_expose ();
gint switch_to_bar ();
gint switch_to_spinner ();
bool _switching;
bool _switch_on_release;
void passtrhu_gesture_start() { StartGesture (); }
void passtrhu_gesture_stop() { StopGesture (); }
};
}; /* namespace */
#endif // __gtkmm2ext_bar_controller_h__

View file

@ -0,0 +1,81 @@
/*
Copyright (C) 1999 Paul Barton-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.
*/
#ifndef _WIDGETS_CLICK_BOX_H_
#define _WIDGETS_CLICK_BOX_H_
#ifdef interface
#undef interface
#endif
#include <string>
#include <gtkmm.h>
#include "gtkmm2ext/binding_proxy.h"
#include "widgets/auto_spin.h"
#include "widgets/visibility.h"
namespace PBD {
class Controllable;
}
namespace ArdourWidgets {
class LIBWIDGETS_API ClickBox : public Gtk::DrawingArea, public AutoSpin
{
public:
ClickBox (Gtk::Adjustment *adj, const std::string &name, bool round_to_steps = false);
~ClickBox ();
/** Set a slot to `print' the value to put in the box.
* The slot should write the value of the Gtk::Adjustment
* into the char array, and should return true if it has done the printing,
* or false to use the ClickBox's default printing method.
*/
void set_printer (sigc::slot<bool, char *, Gtk::Adjustment &>);
void set_controllable (boost::shared_ptr<PBD::Controllable> c) {
_binding_proxy.set_controllable (c);
}
protected:
bool on_expose_event (GdkEventExpose*);
bool on_enter_notify_event (GdkEventCrossing* ev);
bool on_leave_notify_event (GdkEventCrossing* ev);
BindingProxy _binding_proxy;
private:
Glib::RefPtr<Pango::Layout> layout;
int twidth;
int theight;
void set_label ();
void style_changed (const Glib::RefPtr<Gtk::Style> &);
bool button_press_handler (GdkEventButton *);
bool button_release_handler (GdkEventButton *);
bool on_scroll_event (GdkEventScroll*);
sigc::slot<bool, char *, Gtk::Adjustment &> _printer;
};
} /* namespace */
#endif

View file

@ -0,0 +1,177 @@
/*
Copyright (C) 2003 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.
*/
#ifndef _WIDGETS_FAST_METER_H_
#define _WIDGETS_FAST_METER_H_
#include <map>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>
#include <cairomm/pattern.h>
#include "gtkmm2ext/cairo_widget.h"
#include "widgets/visibility.h"
namespace ArdourWidgets {
class LIBWIDGETS_API FastMeter : public CairoWidget {
public:
enum Orientation {
Horizontal,
Vertical
};
FastMeter (long hold_cnt, unsigned long width, Orientation, int len=0,
int clr0=0x008800ff, int clr1=0x008800ff,
int clr2=0x00ff00ff, int clr3=0x00ff00ff,
int clr4=0xffaa00ff, int clr5=0xffaa00ff,
int clr6=0xffff00ff, int clr7=0xffff00ff,
int clr8=0xff0000ff, int clr9=0xff0000ff,
int bgc0=0x333333ff, int bgc1=0x444444ff,
int bgh0=0x991122ff, int bgh1=0x551111ff,
float stp0 = 55.0, // log_meter(-18);
float stp1 = 77.5, // log_meter(-9);
float stp2 = 92.5, // log_meter(-3); // 95.0, // log_meter(-2);
float stp3 = 100.0,
int styleflags = 3
);
virtual ~FastMeter ();
static void flush_pattern_cache();
void set (float level, float peak = -1);
void clear ();
float get_level() { return current_level; }
float get_user_level() { return current_user_level; }
float get_peak() { return current_peak; }
long hold_count() { return hold_cnt; }
void set_hold_count (long);
void set_highlight (bool);
bool get_highlight () { return highlight; }
void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
protected:
void on_size_request (GtkRequisition*);
void on_size_allocate (Gtk::Allocation&);
private:
Cairo::RefPtr<Cairo::Pattern> fgpattern;
Cairo::RefPtr<Cairo::Pattern> bgpattern;
gint pixheight;
gint pixwidth;
float _stp[4];
int _clr[10];
int _bgc[2];
int _bgh[2];
int _styleflags;
Orientation orientation;
GdkRectangle pixrect;
GdkRectangle last_peak_rect;
gint request_width;
gint request_height;
unsigned long hold_cnt;
unsigned long hold_state;
bool bright_hold;
float current_level;
float current_peak;
float current_user_level;
bool highlight;
void vertical_expose (cairo_t*, cairo_rectangle_t*);
void vertical_size_request (GtkRequisition*);
void vertical_size_allocate (Gtk::Allocation&);
void queue_vertical_redraw (const Glib::RefPtr<Gdk::Window>&, float);
void horizontal_expose (cairo_t*, cairo_rectangle_t*);
void horizontal_size_request (GtkRequisition*);
void horizontal_size_allocate (Gtk::Allocation&);
void queue_horizontal_redraw (const Glib::RefPtr<Gdk::Window>&, float);
static bool no_rgba_overlay;
static Cairo::RefPtr<Cairo::Pattern> generate_meter_pattern (
int, int, int *, float *, int, bool);
static Cairo::RefPtr<Cairo::Pattern> request_vertical_meter (
int, int, int *, float *, int);
static Cairo::RefPtr<Cairo::Pattern> request_horizontal_meter (
int, int, int *, float *, int);
static Cairo::RefPtr<Cairo::Pattern> generate_meter_background (
int, int, int *, bool, bool);
static Cairo::RefPtr<Cairo::Pattern> request_vertical_background (
int, int, int *, bool);
static Cairo::RefPtr<Cairo::Pattern> request_horizontal_background (
int, int, int *, bool);
struct Pattern10MapKey {
Pattern10MapKey (
int w, int h,
float stp0, float stp1, float stp2, float stp3,
int c0, int c1, int c2, int c3,
int c4, int c5, int c6, int c7,
int c8, int c9, int st
)
: dim(w, h)
, stp(stp0, stp1, stp2, stp3)
, cols(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9)
, style(st)
{}
inline bool operator<(const Pattern10MapKey& rhs) const {
return (dim < rhs.dim)
|| (dim == rhs.dim && stp < rhs.stp)
|| (dim == rhs.dim && stp == rhs.stp && cols < rhs.cols)
|| (dim == rhs.dim && stp == rhs.stp && cols == rhs.cols && style < rhs.style);
}
boost::tuple<int, int> dim;
boost::tuple<float, float, float, float> stp;
boost::tuple<int, int, int, int, int, int, int, int, int, int> cols;
int style;
};
typedef std::map<Pattern10MapKey, Cairo::RefPtr<Cairo::Pattern> > Pattern10Map;
struct PatternBgMapKey {
PatternBgMapKey (int w, int h, int c0, int c1, bool shade)
: dim(w, h)
, cols(c0, c1)
, sh(shade)
{}
inline bool operator<(const PatternBgMapKey& rhs) const {
return (dim < rhs.dim) || (dim == rhs.dim && cols < rhs.cols) || (dim == rhs.dim && cols == rhs.cols && (sh && !rhs.sh));
}
boost::tuple<int, int> dim;
boost::tuple<int, int> cols;
bool sh;
};
typedef std::map<PatternBgMapKey, Cairo::RefPtr<Cairo::Pattern> > PatternBgMap;
static Pattern10Map vm_pattern_cache;
static PatternBgMap vb_pattern_cache;
static Pattern10Map hm_pattern_cache;
static PatternBgMap hb_pattern_cache;
static int min_pattern_metric_size; // min dimension for axis that displays the meter level
static int max_pattern_metric_size; // max dimension for axis that displays the meter level
};
} /* namespace */
#endif

View file

@ -0,0 +1,43 @@
/*
Copyright (C) 2000-2007 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.
*/
#ifndef _WIDGETS_FOCUS_ENTRY_H_
#define _WIDGETS_FOCUS_ENTRY_H_
#include <gtkmm/entry.h>
#include "widgets/visibility.h"
namespace ArdourWidgets {
class LIBWIDGETS_API FocusEntry : public Gtk::Entry
{
public:
FocusEntry ();
protected:
bool on_button_press_event (GdkEventButton*);
bool on_button_release_event (GdkEventButton*);
private:
bool next_release_selects;
};
} /* end namespace */
#endif

View file

@ -0,0 +1,40 @@
#pragma once
#include <gtkmm/entry.h>
#include <string>
#include "widgets/visibility.h"
namespace ArdourWidgets {
class LIBWIDGETS_API SearchBar : public Gtk::Entry
{
public:
SearchBar (
const std::string& placeholder_text = "Search...",
bool icon_click_resets = true);
/** resets the searchbar to the initial state */
void reset ();
/* emitted when the filter has been updated */
sigc::signal<void, const std::string&> signal_search_string_updated () { return sig_search_string_updated; }
protected:
bool focus_in_event (GdkEventFocus*);
bool focus_out_event (GdkEventFocus*);
bool key_press_event (GdkEventKey*);
void icon_clicked_event (Gtk::EntryIconPosition, const GdkEventButton*);
const std::string placeholder_text;
sigc::signal<void, const std::string&> sig_search_string_updated;
private:
void search_string_changed () const;
Glib::RefPtr<Gdk::Pixbuf> icon;
bool icon_click_resets;
};
} /* end namespace */

View file

@ -0,0 +1,81 @@
/*
Copyright (C) 1998-2006 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.
*/
#ifndef _WIDGETS_SLIDER_CONTROLLER_H_
#define _WIDGETS_SLIDER_CONTROLLER_H_
#ifdef interface
#undef interface
#endif
#include <gtkmm.h>
#include <boost/shared_ptr.hpp>
#include "gtkmm2ext/popup.h"
#include "gtkmm2ext/binding_proxy.h"
#include "widgets/ardour_fader.h"
#include "widgets/visibility.h"
namespace PBD {
class Controllable;
}
namespace ArdourWidgets {
class LIBWIDGETS_API SliderController : public ArdourWidgets::ArdourFader
{
public:
SliderController (Gtk::Adjustment* adj, boost::shared_ptr<PBD::Controllable> mc, int orientation, int, int);
virtual ~SliderController () {}
Gtk::SpinButton& get_spin_button () { assert(_ctrl); return _spin; }
void set_controllable (boost::shared_ptr<PBD::Controllable> c) { _binding_proxy.set_controllable (c); }
protected:
bool on_button_press_event (GdkEventButton *ev);
bool on_enter_notify_event (GdkEventCrossing* ev);
bool on_leave_notify_event (GdkEventCrossing* ev);
void ctrl_adjusted();
void spin_adjusted();
BindingProxy _binding_proxy;
boost::shared_ptr<PBD::Controllable> _ctrl;
Gtk::Adjustment *_ctrl_adj;
Gtk::Adjustment _spin_adj;
Gtk::SpinButton _spin;
bool _ctrl_ignore;
bool _spin_ignore;
};
class LIBWIDGETS_API VSliderController : public SliderController
{
public:
VSliderController (Gtk::Adjustment *adj, boost::shared_ptr<PBD::Controllable> mc, int, int);
};
class LIBWIDGETS_API HSliderController : public SliderController
{
public:
HSliderController (Gtk::Adjustment *adj, boost::shared_ptr<PBD::Controllable> mc, int, int);
};
}; /* namespace */
#endif