2002-02-27 09:59:52 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file GraphicsImage.h
|
|
|
|
* Copyright 2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author Baruch Even <baruch.even@writeme.com>
|
2002-07-15 10:19:45 +00:00
|
|
|
* \author Angus Leeming <leeming@lyx.org>
|
2002-02-27 09:59:52 +00:00
|
|
|
*
|
|
|
|
* An abstract base class for the images themselves.
|
|
|
|
* Allows the user to retrieve the pixmap, once loaded and to issue commands
|
|
|
|
* to modify it.
|
|
|
|
*
|
|
|
|
* The signals newImage and loadableFormats are connected to the approriate
|
|
|
|
* derived classes elsewhere, allowing the graphics cache to access them
|
|
|
|
* without knowing anything about their instantiation.
|
|
|
|
*
|
|
|
|
* The loading process can be asynchronous, but cropping, rotating and
|
|
|
|
* scaling block execution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GRAPHICSIMAGE_H
|
|
|
|
#define GRAPHICSIMAGE_H
|
|
|
|
|
|
|
|
#include "LString.h"
|
2002-05-22 01:16:37 +00:00
|
|
|
|
|
|
|
#include <boost/shared_ptr.hpp>
|
2002-07-04 17:45:35 +00:00
|
|
|
#include <boost/function/function0.hpp>
|
2002-05-29 16:21:03 +00:00
|
|
|
#include <boost/signals/signal1.hpp>
|
2002-05-22 01:16:37 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
#include <X11/X.h> // for Pixmap :-(
|
2002-05-22 01:16:37 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace grfx {
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
class Params;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
class Image {
|
2002-02-27 09:59:52 +00:00
|
|
|
public:
|
2002-06-28 11:22:56 +00:00
|
|
|
/** This is to be connected to a function that will return a new
|
|
|
|
* instance of a viable derived class.
|
2002-02-27 09:59:52 +00:00
|
|
|
*/
|
2002-06-28 11:22:56 +00:00
|
|
|
typedef boost::shared_ptr<Image> ImagePtr;
|
|
|
|
///
|
2002-07-04 17:45:35 +00:00
|
|
|
static boost::function0<ImagePtr> newImage;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Return the list of loadable formats.
|
2002-06-28 11:22:56 +00:00
|
|
|
typedef std::vector<string> FormatList;
|
|
|
|
///
|
2002-07-04 17:45:35 +00:00
|
|
|
static boost::function0<FormatList> loadableFormats;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
/// Must define default c-tor explicitly as we define a copy c-tor.
|
|
|
|
Image() {}
|
|
|
|
/// Don't copy the signal finishedLoading
|
|
|
|
Image(Image const &) {}
|
2002-02-27 09:59:52 +00:00
|
|
|
///
|
2002-06-28 11:22:56 +00:00
|
|
|
virtual ~Image() {}
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Create a copy
|
2002-06-28 11:22:56 +00:00
|
|
|
virtual Image * clone() const = 0;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
virtual Pixmap getPixmap() const = 0;
|
|
|
|
|
|
|
|
/// Get the image width
|
|
|
|
virtual unsigned int getWidth() const = 0;
|
|
|
|
|
|
|
|
/// Get the image height
|
|
|
|
virtual unsigned int getHeight() const = 0;
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
/** At the end of the loading process inform the outside world
|
|
|
|
* by emitting a signal.
|
|
|
|
*/
|
2002-05-29 16:21:03 +00:00
|
|
|
typedef boost::signal1<void, bool> SignalType;
|
2002-02-27 09:59:52 +00:00
|
|
|
///
|
2002-06-28 11:22:56 +00:00
|
|
|
SignalType finishedLoading;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
/** Start loading the image file.
|
|
|
|
* The caller should expect this process to be asynchronous and
|
|
|
|
* so should connect to the "finished" signal above.
|
|
|
|
*/
|
|
|
|
virtual void load(string const & filename) = 0;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/** Generate the pixmap.
|
|
|
|
* Uses the params to decide on color, grayscale etc.
|
|
|
|
* Returns true if the pixmap is created.
|
|
|
|
*/
|
2002-06-28 11:22:56 +00:00
|
|
|
virtual bool setPixmap(Params const & params) = 0;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Clip the image using params.
|
2002-06-28 11:22:56 +00:00
|
|
|
virtual void clip(Params const & params) = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// Rotate the image using params.
|
2002-06-28 11:22:56 +00:00
|
|
|
virtual void rotate(Params const & params) = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// Scale the image using params.
|
2002-06-28 11:22:56 +00:00
|
|
|
virtual void scale(Params const & params) = 0;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/** Uses the params to ascertain the dimensions of the scaled image.
|
|
|
|
* Returned as make_pair(width, height).
|
2002-06-28 11:22:56 +00:00
|
|
|
* If something goes wrong, returns make_pair(getWidth(), getHeight())
|
2002-02-27 09:59:52 +00:00
|
|
|
*/
|
|
|
|
std::pair<unsigned int, unsigned int>
|
2002-06-28 11:22:56 +00:00
|
|
|
getScaledDimensions(Params const & params) const;
|
2002-02-27 09:59:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace grfx
|
|
|
|
|
|
|
|
#endif // GRAPHICSIMAGE_H
|