From b968fe513e80e3cc29be86cef95994bc3487d586 Mon Sep 17 00:00:00 2001 From: joncruz Date: Thu, 21 Feb 2008 06:54:33 +0000 Subject: [PATCH] Initial implementation of non-square swatches --- src/dialogs/eek-preview.cpp | 16 ++++++++- src/dialogs/eek-preview.h | 3 +- src/dialogs/swatches.cpp | 4 +-- src/dialogs/swatches.h | 3 +- src/preferences-skeleton.h | 3 +- src/ui/previewable.h | 2 +- src/ui/previewfillable.h | 3 +- src/ui/previewholder.cpp | 18 +++++----- src/ui/previewholder.h | 4 ++- src/ui/widget/panel.cpp | 68 +++++++++++++++++++++++++++---------- 10 files changed, 90 insertions(+), 34 deletions(-) diff --git a/src/dialogs/eek-preview.cpp b/src/dialogs/eek-preview.cpp index d90137a04..145346af3 100644 --- a/src/dialogs/eek-preview.cpp +++ b/src/dialogs/eek-preview.cpp @@ -48,6 +48,7 @@ #define PREVIEW_SIZE_LAST PREVIEW_SIZE_HUGE #define PREVIEW_SIZE_NEXTFREE (PREVIEW_SIZE_HUGE + 1) +#define PREVIEW_MAX_RATIO 500 static void eek_preview_class_init( EekPreviewClass *klass ); static void eek_preview_init( EekPreview *preview ); @@ -154,6 +155,13 @@ static void eek_preview_size_request( GtkWidget* widget, GtkRequisition* req ) width *= 3; } + if ( preview->_ratio != 100 ) { + width = (width * preview->_ratio) / 100; + if ( width < 0 ) { + width = 1; + } + } + req->width = width; req->height = height; } @@ -582,7 +590,7 @@ void eek_preview_set_focus_on_click( EekPreview* preview, gboolean focus_on_clic } } -void eek_preview_set_details( EekPreview* preview, PreviewStyle prevstyle, ViewType view, PreviewSize size ) +void eek_preview_set_details( EekPreview* preview, PreviewStyle prevstyle, ViewType view, PreviewSize size, guint ratio ) { preview->_prevstyle = prevstyle; preview->_view = view; @@ -592,6 +600,11 @@ void eek_preview_set_details( EekPreview* preview, PreviewStyle prevstyle, ViewT } preview->_size = size; + if ( ratio > PREVIEW_MAX_RATIO ) { + ratio = PREVIEW_MAX_RATIO; + } + preview->_ratio = ratio; + gtk_widget_queue_draw(GTK_WIDGET(preview)); } @@ -624,6 +637,7 @@ static void eek_preview_init( EekPreview *preview ) preview->_prevstyle = PREVIEW_STYLE_ICON; preview->_view = VIEW_TYPE_LIST; preview->_size = PREVIEW_SIZE_SMALL; + preview->_ratio = 100; /* GdkColor color = {0}; diff --git a/src/dialogs/eek-preview.h b/src/dialogs/eek-preview.h index b2f8359f3..ee99125af 100644 --- a/src/dialogs/eek-preview.h +++ b/src/dialogs/eek-preview.h @@ -103,6 +103,7 @@ struct _EekPreview PreviewStyle _prevstyle; ViewType _view; PreviewSize _size; + guint _ratio; guint _linked; }; @@ -117,7 +118,7 @@ struct _EekPreviewClass GType eek_preview_get_type(void) G_GNUC_CONST; GtkWidget* eek_preview_new(void); -void eek_preview_set_details( EekPreview* splat, PreviewStyle prevstyle, ViewType view, PreviewSize size ); +void eek_preview_set_details( EekPreview* splat, PreviewStyle prevstyle, ViewType view, PreviewSize size, guint ratio ); void eek_preview_set_color( EekPreview* splat, int r, int g, int b ); void eek_preview_set_linked( EekPreview* splat, LinkType link ); diff --git a/src/dialogs/swatches.cpp b/src/dialogs/swatches.cpp index 28c21e270..68e6fff0d 100644 --- a/src/dialogs/swatches.cpp +++ b/src/dialogs/swatches.cpp @@ -503,7 +503,7 @@ void ColorItem::_colorDefChanged(void* data) } -Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewSize size) +Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewSize size, guint ratio) { Gtk::Widget* widget = 0; if ( style == PREVIEW_STYLE_BLURB ) { @@ -522,7 +522,7 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewS eek_preview_set_color( preview, (def.getR() << 8) | def.getR(), (def.getG() << 8) | def.getG(), (def.getB() << 8) | def.getB()); - eek_preview_set_details( preview, (::PreviewStyle)style, (::ViewType)view, (::PreviewSize)size ); + eek_preview_set_details( preview, (::PreviewStyle)style, (::ViewType)view, (::PreviewSize)size, ratio ); eek_preview_set_linked( preview, (LinkType)((_linkSrc ? PREVIEW_LINK_IN:0) | (_listeners.empty() ? 0:PREVIEW_LINK_OUT) | (_isLive ? PREVIEW_LINK_OTHER:0)) ); diff --git a/src/dialogs/swatches.h b/src/dialogs/swatches.h index f21aec1ff..310272b1c 100644 --- a/src/dialogs/swatches.h +++ b/src/dialogs/swatches.h @@ -43,7 +43,8 @@ public: virtual ColorItem &operator=(ColorItem const &other); virtual Gtk::Widget* getPreview(PreviewStyle style, ViewType view, - ::PreviewSize size); + ::PreviewSize size, + guint ratio); void buttonClicked(bool secondary = false); ColorDef def; diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h index 9415ca144..12783c022 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -125,9 +125,10 @@ static char const preferences_skeleton[] = " \n" " \n" " \n" -" \n" " \n" diff --git a/src/ui/previewable.h b/src/ui/previewable.h index f0c642082..c517e4f28 100644 --- a/src/ui/previewable.h +++ b/src/ui/previewable.h @@ -40,7 +40,7 @@ class Previewable public: // TODO need to add some nice parameters virtual ~Previewable() {} - virtual Gtk::Widget* getPreview( PreviewStyle style, ViewType view, ::PreviewSize size ) = 0; + virtual Gtk::Widget* getPreview( PreviewStyle style, ViewType view, ::PreviewSize size, guint ratio ) = 0; }; diff --git a/src/ui/previewfillable.h b/src/ui/previewfillable.h index d12771c90..6f02b60a8 100644 --- a/src/ui/previewfillable.h +++ b/src/ui/previewfillable.h @@ -27,10 +27,11 @@ public: virtual void addPreview( Previewable* preview ) = 0; virtual void freezeUpdates() = 0; virtual void thawUpdates() = 0; - virtual void setStyle( ::PreviewSize size, ViewType type) = 0; + virtual void setStyle( ::PreviewSize size, ViewType type, guint ratio) = 0; virtual void setOrientation( Gtk::AnchorType how ) = 0; virtual ::PreviewSize getPreviewSize() const = 0; virtual ViewType getPreviewType() const = 0; + virtual guint getPreviewRatio() const = 0; virtual void setWrap( bool b ) = 0; virtual bool getWrap() const = 0; }; diff --git a/src/ui/previewholder.cpp b/src/ui/previewholder.cpp index 764890395..da991e1df 100644 --- a/src/ui/previewholder.cpp +++ b/src/ui/previewholder.cpp @@ -36,6 +36,7 @@ PreviewHolder::PreviewHolder() : _updatesFrozen(false), _anchor(Gtk::ANCHOR_CENTER), _baseSize(PREVIEW_SIZE_SMALL), + _ratio(100), _view(VIEW_TYPE_LIST), _wrap(false) { @@ -72,13 +73,13 @@ void PreviewHolder::addPreview( Previewable* preview ) int i = items.size() - 1; if ( _view == VIEW_TYPE_LIST ) { - Gtk::Widget* label = manage(preview->getPreview(PREVIEW_STYLE_BLURB, VIEW_TYPE_LIST, _baseSize)); - Gtk::Widget* thing = manage(preview->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_LIST, _baseSize)); + Gtk::Widget* label = manage(preview->getPreview(PREVIEW_STYLE_BLURB, VIEW_TYPE_LIST, _baseSize, _ratio)); + Gtk::Widget* thing = manage(preview->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_LIST, _baseSize, _ratio)); _insides->attach( *thing, 0, 1, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); _insides->attach( *label, 1, 2, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK ); } else { - Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_GRID, _baseSize)); + Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_GRID, _baseSize, _ratio)); int width = 1; int height = 1; @@ -124,11 +125,12 @@ void PreviewHolder::thawUpdates() rebuildUI(); } -void PreviewHolder::setStyle( ::PreviewSize size, ViewType view ) +void PreviewHolder::setStyle( ::PreviewSize size, ViewType view, guint ratio ) { - if ( size != _baseSize || view != _view ) { + if ( size != _baseSize || view != _view || ratio != _ratio ) { _baseSize = size; _view = view; + _ratio = ratio; rebuildUI(); } } @@ -259,10 +261,10 @@ void PreviewHolder::rebuildUI() _insides->set_col_spacings( 8 ); for ( unsigned int i = 0; i < items.size(); i++ ) { - Gtk::Widget* label = manage(items[i]->getPreview(PREVIEW_STYLE_BLURB, _view, _baseSize)); + Gtk::Widget* label = manage(items[i]->getPreview(PREVIEW_STYLE_BLURB, _view, _baseSize, _ratio)); //label->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER); - Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize)); + Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio)); _insides->attach( *thing, 0, 1, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); _insides->attach( *label, 1, 2, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK ); @@ -275,7 +277,7 @@ void PreviewHolder::rebuildUI() int height = 1; for ( unsigned int i = 0; i < items.size(); i++ ) { - Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize)); + Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio)); if ( !_insides ) { calcGridSize( thing, items.size(), width, height ); diff --git a/src/ui/previewholder.h b/src/ui/previewholder.h index e3515c987..812d4b27d 100644 --- a/src/ui/previewholder.h +++ b/src/ui/previewholder.h @@ -32,12 +32,13 @@ public: virtual void addPreview( Previewable* preview ); virtual void freezeUpdates(); virtual void thawUpdates(); - virtual void setStyle( ::PreviewSize size, ViewType view ); + virtual void setStyle( ::PreviewSize size, ViewType view, guint ratio ); virtual void setOrientation( Gtk::AnchorType how ); virtual int getColumnPref() const { return _prefCols; } virtual void setColumnPref( int cols ); virtual ::PreviewSize getPreviewSize() const { return _baseSize; } virtual ViewType getPreviewType() const { return _view; } + virtual guint getPreviewRatio() const { return _ratio; } virtual void setWrap( bool b ); virtual bool getWrap() const { return _wrap; } @@ -57,6 +58,7 @@ private: bool _updatesFrozen; Gtk::AnchorType _anchor; ::PreviewSize _baseSize; + guint _ratio; ViewType _view; bool _wrap; }; diff --git a/src/ui/widget/panel.cpp b/src/ui/widget/panel.cpp index 51b289ddf..c01cb7768 100644 --- a/src/ui/widget/panel.cpp +++ b/src/ui/widget/panel.cpp @@ -35,8 +35,9 @@ namespace Widget { static const int PANEL_SETTING_SIZE = 0; static const int PANEL_SETTING_MODE = 1; -static const int PANEL_SETTING_WRAP = 2; -static const int PANEL_SETTING_NEXTFREE = 3; +static const int PANEL_SETTING_SHAPE = 2; +static const int PANEL_SETTING_WRAP = 3; +static const int PANEL_SETTING_NEXTFREE = 4; void Panel::prep() { @@ -106,6 +107,11 @@ void Panel::_init() panel_wrap = prefs_get_int_attribute_limited( _prefs_path, "panel_wrap", 0, 0, 1 ); } + guint panel_ratio = 100; + if (_prefs_path) { + panel_ratio = prefs_get_int_attribute_limited( _prefs_path, "panel_ratio", 100, 0, 500 ); + } + _menu = new Gtk::Menu(); { const char *things[] = { @@ -162,6 +168,7 @@ void Panel::_init() { Glib::ustring type_label(_("Shape")); + Glib::ustring ellipsis(_("...")); Glib::ustring shape_1_label(_("Tall")); Glib::ustring shape_2_label(_("Square")); Glib::ustring shape_3_label(_("Wide")); @@ -173,15 +180,24 @@ void Panel::_init() Gtk::RadioMenuItem::Group shapeGroup; - Gtk::RadioMenuItem *shape_1 = manage(new Gtk::RadioMenuItem(shapeGroup, shape_1_label)); - Gtk::RadioMenuItem *shape_2 = manage(new Gtk::RadioMenuItem(shapeGroup, shape_2_label)); - Gtk::RadioMenuItem *shape_3 = manage(new Gtk::RadioMenuItem(shapeGroup, shape_3_label)); - type_menu->append(*shape_1); - type_menu->append(*shape_2); - type_menu->append(*shape_3); - - shape_2->set_active(true); + Glib::ustring* labels[] = {&ellipsis, &shape_1_label, &ellipsis, &shape_2_label, &ellipsis, &shape_3_label}; + guint values[] = {0, 25, 50, 100, 200, 400}; + guint hot_index = 3; + for ( guint i = 0; i < G_N_ELEMENTS(labels); ++i ) { + // Assume all values are in increasing order + if ( values[i] <= panel_ratio ) { + hot_index = i; + } + } + for ( guint i = 0; i < G_N_ELEMENTS(labels); ++i ) { + Gtk::RadioMenuItem *single = manage(new Gtk::RadioMenuItem(shapeGroup, *(labels[i]))); + type_menu->append(*single); + if ( i <= hot_index ) { + single->set_active(true); + } + single->signal_activate().connect(sigc::bind(sigc::mem_fun(*this, &Panel::_bounceCall), PANEL_SETTING_SHAPE, values[i])); + } } sep = manage(new Gtk::SeparatorMenuItem()); @@ -228,6 +244,7 @@ void Panel::_init() _bounceCall(PANEL_SETTING_SIZE, panel_size); _bounceCall(PANEL_SETTING_MODE, panel_mode); + _bounceCall(PANEL_SETTING_SHAPE, panel_ratio); _bounceCall(PANEL_SETTING_WRAP, panel_wrap); } @@ -305,8 +322,13 @@ void Panel::restorePanelPrefs() if (_prefs_path) { panel_wrap = prefs_get_int_attribute_limited(_prefs_path, "panel_wrap", 0, 0, 1 ); } + guint panel_ratio = 100; + if (_prefs_path) { + panel_ratio = prefs_get_int_attribute_limited(_prefs_path, "panel_ratio", 000, 0, 500 ); + } _bounceCall(PANEL_SETTING_SIZE, panel_size); _bounceCall(PANEL_SETTING_MODE, panel_mode); + _bounceCall(PANEL_SETTING_SHAPE, panel_ratio); _bounceCall(PANEL_SETTING_WRAP, panel_wrap); } @@ -332,30 +354,31 @@ void Panel::_bounceCall(int i, int j) } if (_fillable) { ViewType curr_type = _fillable->getPreviewType(); + guint curr_ratio = _fillable->getPreviewRatio(); switch (j) { case 0: { - _fillable->setStyle(::PREVIEW_SIZE_TINY, curr_type); + _fillable->setStyle(::PREVIEW_SIZE_TINY, curr_type, curr_ratio); } break; case 1: { - _fillable->setStyle(::PREVIEW_SIZE_SMALL, curr_type); + _fillable->setStyle(::PREVIEW_SIZE_SMALL, curr_type, curr_ratio); } break; case 2: { - _fillable->setStyle(::PREVIEW_SIZE_MEDIUM, curr_type); + _fillable->setStyle(::PREVIEW_SIZE_MEDIUM, curr_type, curr_ratio); } break; case 3: { - _fillable->setStyle(::PREVIEW_SIZE_BIG, curr_type); + _fillable->setStyle(::PREVIEW_SIZE_BIG, curr_type, curr_ratio); } break; case 4: { - _fillable->setStyle(::PREVIEW_SIZE_HUGE, curr_type); + _fillable->setStyle(::PREVIEW_SIZE_HUGE, curr_type, curr_ratio); } break; default: @@ -369,15 +392,16 @@ void Panel::_bounceCall(int i, int j) } if (_fillable) { ::PreviewSize curr_size = _fillable->getPreviewSize(); + guint curr_ratio = _fillable->getPreviewRatio(); switch (j) { case 0: { - _fillable->setStyle(curr_size, VIEW_TYPE_LIST); + _fillable->setStyle(curr_size, VIEW_TYPE_LIST, curr_ratio); } break; case 1: { - _fillable->setStyle(curr_size, VIEW_TYPE_GRID); + _fillable->setStyle(curr_size, VIEW_TYPE_GRID, curr_ratio); } break; default: @@ -385,6 +409,16 @@ void Panel::_bounceCall(int i, int j) } } break; + case PANEL_SETTING_SHAPE: + if (_prefs_path) { + prefs_set_int_attribute (_prefs_path, "panel_ratio", j); + } + if ( _fillable ) { + ViewType curr_type = _fillable->getPreviewType(); + ::PreviewSize curr_size = _fillable->getPreviewSize(); + _fillable->setStyle(curr_size, curr_type, j); + } + break; case PANEL_SETTING_WRAP: if (_prefs_path) { prefs_set_int_attribute (_prefs_path, "panel_wrap", j ? 1 : 0); -- 2.39.5