Added ScriptableImage plus the beginnings of dependency stuff

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@58 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-10-29 16:23:31 +00:00
parent 368082ade2
commit f46b0b6b7b
22 changed files with 533 additions and 18 deletions
+78
View File
@@ -0,0 +1,78 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_SCRIPT_IMAGE
#define HEADER_SCRIPT_IMAGE
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/age.hpp>
#include <script/scriptable.hpp>
#include <gfx/gfx.hpp>
#include <util/dynamic_arg.hpp>
class Package;
DECLARE_INTRUSIVE_POINTER_TYPE(ScriptImage);
// ----------------------------------------------------------------------------- : ScriptableImage
DECLARE_DYNAMIC_ARG(Package*, load_images_from);
/// An image, returned by a script function
class ScriptImage : public ScriptValue {
public:
inline ScriptImage() : combine(COMBINE_NORMAL) {}
inline ScriptImage(const Image& image, ImageCombine combine = COMBINE_NORMAL)
: image(image), combine(combine)
{}
Image image; ///< The image
ImageCombine combine; ///< How to combine the image with the background
virtual ScriptType type() const;
virtual String typeName() const;
};
/// An image that can also be scripted
/** Differs from Scriptable<Image> in that:
* - A script is always used
* - Age is checked, chached images are used if possible
* - The image can be scaled
*/
class ScriptableImage {
public:
/// Is there an image set?
inline operator bool() const { return script; }
/// Generate an image, doesn't cache, and doesn't scale
ScriptImageP generate(Context& ctx) const;
/// Generate an image, scaling it and optionally saturating it
ScriptImageP generate(Context& ctx, UInt width, UInt height, PreserveAspect preserve_aspect = ASPECT_STRETCH, bool saturate = false) const;
/// Update and return the cached image
/** Only recomputes the image if it is out of date, or the size doesn't match.
* If width==height==0 then doesn't resample.
*/
ScriptImageP update(Context& ctx, UInt width = 0, UInt height = 0, PreserveAspect preserve_aspect = ASPECT_STRETCH, bool saturate = false);
/// Is the cached image up to date?
bool upToDate(Context& ctx, Age age) const;
private:
OptionalScript script; ///< The script, not really optional
ScriptImageP cache; ///< The cached image
Age last_update; ///< Age of last image update of the cached image
DECLARE_REFLECTION();
};
/// Missing for now
inline ScriptValueP toScript(const ScriptableImage&) { return script_nil; }
// ----------------------------------------------------------------------------- : EOF
#endif