fix problems with pixmaps/xpm files
git-svn-id: svn://localhost/trunk/ardour2@392 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
@@ -32,6 +32,8 @@ using namespace Glib;
|
||||
using namespace Gtkmm2ext;
|
||||
using namespace std;
|
||||
|
||||
string FastMeter::v_image_path;
|
||||
string FastMeter::h_image_path;
|
||||
RefPtr<Pixmap> FastMeter::v_pixmap;
|
||||
RefPtr<Bitmap> FastMeter::v_mask;
|
||||
gint FastMeter::v_pixheight = 0;
|
||||
@@ -56,16 +58,8 @@ FastMeter::FastMeter (long hold, unsigned long dimen, Orientation o)
|
||||
pixrect.x = 0;
|
||||
pixrect.y = 0;
|
||||
|
||||
if (orientation == Vertical) {
|
||||
pixrect.width = min (v_pixwidth, (gint) dimen);
|
||||
pixrect.height = v_pixheight;
|
||||
} else {
|
||||
pixrect.width = h_pixwidth;
|
||||
pixrect.height = min (h_pixheight, (gint) dimen);
|
||||
}
|
||||
|
||||
request_width = pixrect.width;
|
||||
request_height= pixrect.height;
|
||||
request_width = dimen;
|
||||
request_height = dimen;
|
||||
}
|
||||
|
||||
FastMeter::~FastMeter ()
|
||||
@@ -73,31 +67,57 @@ FastMeter::~FastMeter ()
|
||||
}
|
||||
|
||||
void
|
||||
FastMeter::set_vertical_xpm (const std::string& xpm_file)
|
||||
FastMeter::on_realize ()
|
||||
{
|
||||
if (v_pixmap == 0) {
|
||||
gint w, h;
|
||||
DrawingArea::on_realize ();
|
||||
|
||||
v_pixmap = Pixmap::create_from_xpm(get_bogus_drawable(), Colormap::get_system(), v_mask, Gdk::Color(), xpm_file);
|
||||
Glib::RefPtr<Gdk::Drawable> drawable = Glib::RefPtr<Gdk::Window>::cast_dynamic (get_window());
|
||||
Gdk::Color transparent;
|
||||
|
||||
if (!v_image_path.empty() && v_pixmap == 0) {
|
||||
gint w, h;
|
||||
|
||||
v_pixmap = Pixmap::create_from_xpm (drawable, Colormap::get_system(), v_mask, transparent, v_image_path);
|
||||
v_pixmap->get_size(w, h);
|
||||
|
||||
v_pixheight = h;
|
||||
v_pixwidth = w;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FastMeter::set_horizontal_xpm (const std::string& xpm_file)
|
||||
{
|
||||
if (h_pixmap == 0) {
|
||||
if (!h_image_path.empty() && h_pixmap == 0) {
|
||||
gint w, h;
|
||||
|
||||
h_pixmap = Pixmap::create_from_xpm(get_bogus_drawable(), Colormap::get_system(), h_mask, Gdk::Color(), xpm_file);
|
||||
h_pixmap = Pixmap::create_from_xpm (drawable, Colormap::get_system(), h_mask, transparent, h_image_path);
|
||||
h_pixmap->get_size(w, h);
|
||||
|
||||
h_pixheight = h;
|
||||
h_pixwidth = w;
|
||||
}
|
||||
|
||||
if (orientation == Vertical) {
|
||||
pixrect.width = min (v_pixwidth, request_width);
|
||||
pixrect.height = v_pixheight;
|
||||
} else {
|
||||
pixrect.width = h_pixwidth;
|
||||
pixrect.height = min (h_pixheight, request_height);
|
||||
}
|
||||
|
||||
request_width = pixrect.width;
|
||||
request_height= pixrect.height;
|
||||
|
||||
set_size_request (request_width, request_height);
|
||||
}
|
||||
|
||||
void
|
||||
FastMeter::set_vertical_xpm (std::string path)
|
||||
{
|
||||
v_image_path = path;
|
||||
}
|
||||
|
||||
void
|
||||
FastMeter::set_horizontal_xpm (std::string path)
|
||||
{
|
||||
h_image_path = path;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -46,14 +46,17 @@ class FastMeter : public Gtk::DrawingArea {
|
||||
long hold_count() { return hold_cnt; }
|
||||
void set_hold_count (long);
|
||||
|
||||
static void set_horizontal_xpm (const std::string&);
|
||||
static void set_vertical_xpm (const std::string&);
|
||||
static void set_horizontal_xpm (std::string);
|
||||
static void set_vertical_xpm (std::string);
|
||||
|
||||
protected:
|
||||
bool on_expose_event (GdkEventExpose*);
|
||||
void on_size_request (GtkRequisition*);
|
||||
void on_realize ();
|
||||
|
||||
private:
|
||||
static std::string h_image_path;
|
||||
static std::string v_image_path;
|
||||
static Glib::RefPtr<Gdk::Pixmap> h_pixmap;
|
||||
static Glib::RefPtr<Gdk::Bitmap> h_mask;
|
||||
static gint h_pixheight;
|
||||
|
||||
@@ -17,7 +17,7 @@ class Pix
|
||||
int refcnt;
|
||||
bool generated;
|
||||
std::vector<std::string *> *files;
|
||||
std::vector<const char **> data;
|
||||
std::vector<const char* const*> data;
|
||||
bool from_files;
|
||||
int pixmap_count;
|
||||
int last_pixmap;
|
||||
@@ -29,21 +29,21 @@ class Pix
|
||||
|
||||
Pix (const std::string &dirpath, const std::string ®exp,
|
||||
bool homogenous = true);
|
||||
Pix (std::vector<const char **> xpm_data, bool homogenous = true);
|
||||
Pix (std::vector<const char* const*> xpm_data, bool homogenous = true);
|
||||
virtual ~Pix();
|
||||
|
||||
friend Pix *get_pix (const std::string &dirpath,
|
||||
const std::string ®exp,
|
||||
bool homogenous);
|
||||
friend Pix *get_pix (std::string name,
|
||||
std::vector<const char **> xpm_data,
|
||||
std::vector<const char* const*> xpm_data,
|
||||
bool homogenous);
|
||||
friend void finish_pix (Pix *);
|
||||
|
||||
public:
|
||||
Pix (bool homogenous = true);
|
||||
|
||||
void generate ();
|
||||
void generate (Glib::RefPtr<Gdk::Drawable>&);
|
||||
int n_pixmaps() { return pixmap_count; }
|
||||
int max_pixmap() { return last_pixmap; }
|
||||
bool homogenous () { return _homegenous; }
|
||||
|
||||
@@ -20,11 +20,14 @@ class PixScroller : public Gtk::DrawingArea
|
||||
bool on_button_press_event (GdkEventButton*);
|
||||
bool on_button_release_event (GdkEventButton*);
|
||||
void on_size_request (GtkRequisition*);
|
||||
|
||||
void on_realize ();
|
||||
|
||||
protected:
|
||||
Gtk::Adjustment& adj;
|
||||
|
||||
private:
|
||||
Pix& pix;
|
||||
|
||||
Glib::RefPtr<Gdk::Pixmap> rail;
|
||||
Glib::RefPtr<Gdk::Pixmap> slider;
|
||||
Glib::RefPtr<Gdk::Bitmap> rail_mask;
|
||||
|
||||
@@ -57,7 +57,7 @@ Pix::Pix (bool homog)
|
||||
_homegenous = homog;
|
||||
}
|
||||
|
||||
Pix::Pix (vector<const char **> xpm_data, bool homog)
|
||||
Pix::Pix (vector<const char* const*> xpm_data, bool homog)
|
||||
{
|
||||
if (xpm_data.size() == 0) {
|
||||
throw failed_constructor();
|
||||
@@ -132,24 +132,22 @@ Pix::~Pix ()
|
||||
}
|
||||
|
||||
void
|
||||
Pix::generate ()
|
||||
|
||||
Pix::generate (Glib::RefPtr<Gdk::Drawable>& drawable)
|
||||
{
|
||||
if (generated) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < pixmap_count; i++) {
|
||||
|
||||
Gdk::Color transparent;
|
||||
|
||||
if (from_files) {
|
||||
pixmaps[i] = Gdk::Pixmap::create_from_xpm (get_bogus_drawable(), Gdk::Colormap::get_system(),
|
||||
bitmaps[i], Gdk::Color(), *(*files)[i]);
|
||||
pixmaps[i] = Gdk::Pixmap::create_from_xpm(drawable, bitmaps[i], transparent, *(*files)[i]);
|
||||
} else {
|
||||
gchar **xpm;
|
||||
xpm = const_cast<gchar **> (data[i]);
|
||||
|
||||
pixmaps[i] = Gdk::Pixmap::create_from_xpm(Gdk::Colormap::get_system(),
|
||||
bitmaps[i], Gdk::Color(), xpm);
|
||||
pixmaps[i] = Gdk::Pixmap::create_from_xpm(drawable, Gdk::Colormap::get_system(), bitmaps[i], Gdk::Color(), data[i]);
|
||||
}
|
||||
|
||||
|
||||
int w, h;
|
||||
pixmaps[i]->get_size(w, h);
|
||||
@@ -161,7 +159,7 @@ Pix::generate ()
|
||||
}
|
||||
|
||||
Pix *
|
||||
Gtkmm2ext::get_pix (string name, vector<const char **> xpm_data, bool homog)
|
||||
Gtkmm2ext::get_pix (string name, vector<const char* const*> xpm_data, bool homog)
|
||||
{
|
||||
Pix *ret = 0;
|
||||
Pix::PixCache::iterator iter;
|
||||
|
||||
@@ -29,8 +29,9 @@ using namespace std;
|
||||
using namespace Gtk;
|
||||
using namespace Gtkmm2ext;
|
||||
|
||||
PixScroller::PixScroller (Adjustment& a, Pix& pix)
|
||||
: adj (a)
|
||||
PixScroller::PixScroller (Adjustment& a, Pix& p)
|
||||
: adj (a),
|
||||
pix (p)
|
||||
{
|
||||
dragging = false;
|
||||
add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK|Gdk::SCROLL_MASK);
|
||||
@@ -38,7 +39,16 @@ PixScroller::PixScroller (Adjustment& a, Pix& pix)
|
||||
adj.signal_value_changed().connect (mem_fun (*this, &PixScroller::adjustment_changed));
|
||||
default_value = adj.get_value();
|
||||
|
||||
pix.generate ();
|
||||
}
|
||||
|
||||
void
|
||||
PixScroller::on_realize ()
|
||||
{
|
||||
DrawingArea::on_realize ();
|
||||
|
||||
Glib::RefPtr<Gdk::Drawable> drawable = Glib::RefPtr<Gdk::Window>::cast_dynamic (get_window());
|
||||
|
||||
pix.generate (drawable);
|
||||
|
||||
rail = *(pix.pixmap (0));
|
||||
rail_mask = *(pix.shape_mask (0));
|
||||
@@ -61,6 +71,8 @@ PixScroller::PixScroller (Adjustment& a, Pix& pix)
|
||||
|
||||
sliderrect.set_y((int) rint ((overall_height - sliderrect.get_height()) * (adj.get_upper() - adj.get_value())));
|
||||
railrect.set_x((sliderrect.get_width() / 2) - 2);
|
||||
|
||||
set_size_request (sliderrect.get_width(), overall_height);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -43,8 +43,6 @@ SliderController::SliderController (Pix *pixset,
|
||||
bind_statemask (Gdk::CONTROL_MASK)
|
||||
|
||||
{
|
||||
pixset->generate ();
|
||||
|
||||
signal_button_press_event().connect (mem_fun (this, &SliderController::button_press));
|
||||
spin.set_name ("SliderControllerValue");
|
||||
spin.set_size_request (70,-1); // should be based on font size somehow
|
||||
|
||||
@@ -83,15 +83,3 @@ void Gtkmm2ext::set_treeview_header_as_default_label(Gtk::TreeViewColumn* c)
|
||||
gtk_tree_view_column_set_widget( c->gobj(), GTK_WIDGET(0) );
|
||||
}
|
||||
|
||||
Glib::RefPtr<Gdk::Drawable>
|
||||
Gtkmm2ext::get_bogus_drawable()
|
||||
{
|
||||
static Gtk::Button* button = 0;
|
||||
|
||||
if (button == 0) {
|
||||
button = new Gtk::Button ("blah"); //bogus button to extract a Gdk::Drawable from
|
||||
}
|
||||
static Glib::RefPtr<Gdk::Drawable> drawable = button->get_window();
|
||||
return drawable;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user