[glom] ImageGlom: Move scale_keeping_ratio() somewhere more sensible.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] ImageGlom: Move scale_keeping_ratio() somewhere more sensible.
- Date: Thu, 8 Apr 2010 17:22:47 +0000 (UTC)
commit eefed4f2e278dd18e19d18f0a99d65ed106bf893
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Apr 8 16:02:34 2010 +0200
ImageGlom: Move scale_keeping_ratio() somewhere more sensible.
* glom/utility_widgets/imageglom.[h|cc]: Move scale_keeping_ratio() to
glom/utils_ui.[h]cc] as Utils::image_scale_keeping_ratio().
* glom/utility_widgets/canvas/canvas_image_movable.cc:
* glom/utility_widgets/db_adddel/db_adddel.cc:
* glom/utility_widgets/flowtable_dnd.cc: Adapted.
ChangeLog | 10 +++
.../utility_widgets/canvas/canvas_image_movable.cc | 4 +-
glom/utility_widgets/db_adddel/db_adddel.cc | 4 +-
glom/utility_widgets/flowtable_dnd.cc | 1 -
glom/utility_widgets/imageglom.cc | 68 +------------------
glom/utility_widgets/imageglom.h | 2 -
glom/utils_ui.cc | 70 ++++++++++++++++++--
glom/utils_ui.h | 2 +
8 files changed, 83 insertions(+), 78 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 944590f..e1af060 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2010-04-08 Murray Cumming <murrayc murrayc com>
+ ImageGlom: Move scale_keeping_ratio() somewhere more sensible.
+
+ * glom/utility_widgets/imageglom.[h|cc]: Move scale_keeping_ratio() to
+ glom/utils_ui.[h]cc] as Utils::image_scale_keeping_ratio().
+ * glom/utility_widgets/canvas/canvas_image_movable.cc:
+ * glom/utility_widgets/db_adddel/db_adddel.cc:
+ * glom/utility_widgets/flowtable_dnd.cc: Adapted.
+
+2010-04-08 Murray Cumming <murrayc murrayc com>
+
glom/mode_data/datawidget/: Clean up classes, putting them in a namespace.
* glom/mode_data/datawidget/: Removed Glom suffixes from class names
diff --git a/glom/utility_widgets/canvas/canvas_image_movable.cc b/glom/utility_widgets/canvas/canvas_image_movable.cc
index 97e69d4..3609e64 100644
--- a/glom/utility_widgets/canvas/canvas_image_movable.cc
+++ b/glom/utility_widgets/canvas/canvas_image_movable.cc
@@ -24,7 +24,7 @@
#include "canvas_image_movable.h"
#include <goocanvasmm/canvas.h>
#include <gtkmm/stock.h>
-#include <glom/utility_widgets/imageglom.h> //For ImageGlom::scale_keeping_ratio().
+#include <glom/utils_ui.h> //For Utils::image_scale_keeping_ratio().
#include <iostream>
namespace Glom
@@ -205,7 +205,7 @@ void CanvasImageMovable::scale_to_size()
if(width && height)
{
- Glib::RefPtr<Gdk::Pixbuf> pixbuf = ImageGlom::scale_keeping_ratio(m_pixbuf, (int)height, (int)width);
+ Glib::RefPtr<Gdk::Pixbuf> pixbuf = Utils::image_scale_keeping_ratio(m_pixbuf, (int)height, (int)width);
#ifdef GLIBMM_PROPERTIES_ENABLED
property_pixbuf() = pixbuf;
#else
diff --git a/glom/utility_widgets/db_adddel/db_adddel.cc b/glom/utility_widgets/db_adddel/db_adddel.cc
index 6efbbba..3d435e2 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.cc
+++ b/glom/utility_widgets/db_adddel/db_adddel.cc
@@ -29,7 +29,7 @@
#include <glom/utils_ui.h>
#include "cellrenderer_buttonimage.h"
#include "cellrenderer_buttontext.h"
-#include <glom/utility_widgets/imageglom.h> //For ImageGlom::scale_keeping_ratio().
+#include <glom/utils_ui.h> //For Utils::image_scale_keeping_ratio().
#include <iostream> //For debug output.
#include <gtk/gtktreeview.h>
@@ -2299,7 +2299,7 @@ void DbAddDel::treeviewcolumn_on_cell_data(Gtk::CellRenderer* renderer, const Gt
//Scale it down to a sensible size.
if(pixbuf)
- pixbuf = ImageGlom::scale_keeping_ratio(pixbuf, get_fixed_cell_height(), pixbuf->get_width());
+ pixbuf = Utils::image_scale_keeping_ratio(pixbuf, get_fixed_cell_height(), pixbuf->get_width());
g_object_set(pDerived->gobj(), "pixbuf", pixbuf ? pixbuf->gobj() : 0, (gpointer)0);
}
diff --git a/glom/utility_widgets/flowtable_dnd.cc b/glom/utility_widgets/flowtable_dnd.cc
index 9edf349..1889e2d 100644
--- a/glom/utility_widgets/flowtable_dnd.cc
+++ b/glom/utility_widgets/flowtable_dnd.cc
@@ -24,7 +24,6 @@
#include <glom/mode_data/placeholder-glom.h>
#include "layouttoolbarbutton.h"
#include <glom/mode_data/buttonglom.h>
-#include "imageglom.h"
namespace Glom
{
diff --git a/glom/utility_widgets/imageglom.cc b/glom/utility_widgets/imageglom.cc
index f1f35d9..b5e797d 100644
--- a/glom/utility_widgets/imageglom.cc
+++ b/glom/utility_widgets/imageglom.cc
@@ -310,10 +310,10 @@ void ImageGlom::scale()
{
if(allocation.get_height() > 10 || allocation.get_width() > 10)
{
- Glib::RefPtr<Gdk::Pixbuf> pixbuf_scaled = scale_keeping_ratio(pixbuf, allocation.get_height(), allocation.get_width());
+ Glib::RefPtr<Gdk::Pixbuf> pixbuf_scaled = Utils::image_scale_keeping_ratio(pixbuf, allocation.get_height(), allocation.get_width());
if(!pixbuf_scaled)
{
- std::cerr << "ImageGlom::scale(): scale_keeping_ratio() returned NULL pixbuf." << std::endl;
+ std::cerr << "Utils::image_scale_keeping_ratio() returned NULL pixbuf." << std::endl;
}
else
{
@@ -333,70 +333,6 @@ void ImageGlom::scale()
// g_warning("ImageGlom::scale(): attempt to scale a null pixbuf.");
}
-//static:
-Glib::RefPtr<Gdk::Pixbuf> ImageGlom::scale_keeping_ratio(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf, int target_height, int target_width)
-{
- if( (target_height == 0) || (target_width == 0) )
- return Glib::RefPtr<Gdk::Pixbuf>(); //This shouldn't happen anyway.
-
- if(!pixbuf)
- return pixbuf;
-
- enum enum_scale_mode
- {
- SCALE_WIDTH,
- SCALE_HEIGHT,
- SCALE_NONE
- };
-
- enum_scale_mode scale_mode = SCALE_NONE; //Start with either the width or height, and scale the other according to the ratio.
-
- const int pixbuf_height = pixbuf->get_height();
- const int pixbuf_width = pixbuf->get_width();
-
- if(pixbuf_height > target_height)
- {
- if(pixbuf_width > target_width)
- {
- //Both are bigger than the target, so find the biggest one:
- if(pixbuf_width > pixbuf_height)
- scale_mode = SCALE_WIDTH;
- else
- scale_mode = SCALE_HEIGHT;
- }
- else
- {
- //Only the height is bigger:
- scale_mode = SCALE_HEIGHT;
- }
- }
- else if(pixbuf_width > target_width)
- {
- //Only the height is bigger:
- scale_mode = SCALE_WIDTH;
- }
-
- if(scale_mode == SCALE_NONE)
- return pixbuf;
- else if(scale_mode == SCALE_HEIGHT)
- {
- const float ratio = (float)target_height / (float)pixbuf_height;
- target_width = (int)((float)pixbuf_width * ratio);
- }
- else if(scale_mode == SCALE_WIDTH)
- {
- const float ratio = (float)target_width / (float) pixbuf_width;
- target_height = (int)((float)pixbuf_height * ratio);
- }
-
- if( (target_height == 0) || (target_width == 0) )
- {
- return Glib::RefPtr<Gdk::Pixbuf>(); //This shouldn't happen anyway. It seems to happen sometimes though, when ratio is very small.
- }
-
- return pixbuf->scale_simple(target_width, target_height, Gdk::INTERP_NEAREST);
-}
-
void ImageGlom::on_menupopup_activate_select_file()
{
if(m_read_only)
diff --git a/glom/utility_widgets/imageglom.h b/glom/utility_widgets/imageglom.h
index 64706f7..392ebfd 100644
--- a/glom/utility_widgets/imageglom.h
+++ b/glom/utility_widgets/imageglom.h
@@ -56,8 +56,6 @@ public:
void set_read_only(bool read_only = true);
- static Glib::RefPtr<Gdk::Pixbuf> scale_keeping_ratio(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf, int target_height, int target_width);
-
private:
void init();
diff --git a/glom/utils_ui.cc b/glom/utils_ui.cc
index 4e78553..5e7f734 100644
--- a/glom/utils_ui.cc
+++ b/glom/utils_ui.cc
@@ -283,11 +283,6 @@ Glib::RefPtr<Gdk::Pixbuf> Utils::get_pixbuf_for_gda_value(const Gnome::Gda::Valu
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
-
- //g_warning("ImageGlom::set_value(): debug: from db: ");
- //for(int i = 0; i < 10; ++i)
- // g_warning("%02X (%c), ", (guint8)puiData[i], (char)puiData[i]);
-
refPixbufLoader->write(puiData, (glong)buffer_binary_length);
result = refPixbufLoader->get_pixbuf();
@@ -438,4 +433,69 @@ std::string Utils::get_filepath_with_extension(const std::string& filepath, cons
}
+//static:
+Glib::RefPtr<Gdk::Pixbuf> Utils::image_scale_keeping_ratio(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf, int target_height, int target_width)
+{
+ if( (target_height == 0) || (target_width == 0) )
+ return Glib::RefPtr<Gdk::Pixbuf>(); //This shouldn't happen anyway.
+
+ if(!pixbuf)
+ return pixbuf;
+
+ enum enum_scale_mode
+ {
+ SCALE_WIDTH,
+ SCALE_HEIGHT,
+ SCALE_NONE
+ };
+
+ enum_scale_mode scale_mode = SCALE_NONE; //Start with either the width or height, and scale the other according to the ratio.
+
+ const int pixbuf_height = pixbuf->get_height();
+ const int pixbuf_width = pixbuf->get_width();
+
+ if(pixbuf_height > target_height)
+ {
+ if(pixbuf_width > target_width)
+ {
+ //Both are bigger than the target, so find the biggest one:
+ if(pixbuf_width > pixbuf_height)
+ scale_mode = SCALE_WIDTH;
+ else
+ scale_mode = SCALE_HEIGHT;
+ }
+ else
+ {
+ //Only the height is bigger:
+ scale_mode = SCALE_HEIGHT;
+ }
+ }
+ else if(pixbuf_width > target_width)
+ {
+ //Only the height is bigger:
+ scale_mode = SCALE_WIDTH;
+ }
+
+ if(scale_mode == SCALE_NONE)
+ return pixbuf;
+ else if(scale_mode == SCALE_HEIGHT)
+ {
+ const float ratio = (float)target_height / (float)pixbuf_height;
+ target_width = (int)((float)pixbuf_width * ratio);
+ }
+ else if(scale_mode == SCALE_WIDTH)
+ {
+ const float ratio = (float)target_width / (float) pixbuf_width;
+ target_height = (int)((float)pixbuf_height * ratio);
+ }
+
+ if( (target_height == 0) || (target_width == 0) )
+ {
+ return Glib::RefPtr<Gdk::Pixbuf>(); //This shouldn't happen anyway. It seems to happen sometimes though, when ratio is very small.
+ }
+
+ return pixbuf->scale_simple(target_width, target_height, Gdk::INTERP_NEAREST);
+}
+
+
} //namespace Glom
diff --git a/glom/utils_ui.h b/glom/utils_ui.h
index a0a9041..0d0cecc 100644
--- a/glom/utils_ui.h
+++ b/glom/utils_ui.h
@@ -85,6 +85,8 @@ int get_suitable_field_width_for_widget(Gtk::Widget& widget, const sharedptr<con
/// Add the @a extension if no extension is there already:
std::string get_filepath_with_extension(const std::string& filepath, const std::string& extension);
+Glib::RefPtr<Gdk::Pixbuf> image_scale_keeping_ratio(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf, int target_height, int target_width);
+
} //namespace Utils
} //namespace Glom
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]