/* libsswf_tag_scalinggrid.c++ -- written by Alexis WILKE for Made to Order Software Corp. (c) 2002-2008 */

/*

Copyright (c) 2002-2008 Made to Order Software Corp.

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and
associated documentation files (the "Software"), to
deal in the Software without restriction, including
without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the
following conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

/** \file
 *
 * \brief The implementation of the sswf::TagScalingGrid class
 *
 * This file declares the body of the functions which are not
 * inline. It is part of the SSWF library.
 */

#include	"sswf/libsswf.h"

using namespace sswf;



/////////////////////////////////////////// TagScalingGrid

/** \class sswf::TagScalingGrid
 *
 * \brief Defines a grid to scale windows, buttons and other objects with edges
 *
 * This class was introduced in version 1.8.0.
 *
 * The Scaling Grid tag defines a grid used to scale a button
 * or a sprite (some window like object which has a border/edge
 * and corners not to be scalled as usual.)
 *
 * This tag is derived by the TagButton and TagSprite and is
 * not otherwise supposed to be used by itself.
 *
 * This tag adds the Grid() and SetGrid() functionality to the
 * TagButton and TagSprite.
 *
 * Internally, it also adds the GridPreSave() and GridSave()
 * functions.
 *
 * \sa <a href="../SWFalexref.html#tag_definescalinggrid">SWF Alexis' Reference&mdash;Define Scaling Grid</a>
 * \sa <a href="../SWFalexref.html#swf_tag">SWF Alexis' Reference&mdash;swf_tag</a>
 */



/** \brief Cleans up the object
 *
 * The destructor is virtual. It has nothing to do otherwise.
 */
TagScalingGrid::~TagScalingGrid()
{
}



/** \brief Ensures the minimum version
 *
 * This function requests that the movie be at
 * least of version 8.
 *
 * This function is automatically called by the
 * TagButton::PreSave(Data& data) and
 * TagSprite::PreSave(Data& data)
 * functions.
 *
 * \return ErrorManager::ERROR_CODE_NONE when no error occured, an error otherwise
 */
ErrorManager::error_code_t TagScalingGrid::GridPreSave(void)
{
	if(!f_grid.IsEmpty()) {
		TagBase *base;

		base = dynamic_cast<TagBase *>(this);
		if(base != 0) {
			base->MinimumVersion(8);
		}
	}

	return ErrorManager::ERROR_CODE_NONE;
}


/** \brief Save the scaling grid tag
 *
 * This function saves the button or sprite reference and
 * grid rectangle.
 *
 * This function is automatically called by the
 * TagButton::PreSave(Data& data) and
 * TagSprite::PreSave(Data& data)
 * functions.
 *
 * \param data The Data buffer where the result is saved
 * \param id The identification of the button or sprite
 *
 * \return Zero when no error occur, non-zero otherwise
 */
ErrorManager::error_code_t TagScalingGrid::GridSave(Data& data, sswf_id_t id)
{
	if(!f_grid.IsEmpty()) {
		Data	rect_data;

		// needed to compute the size first!
		f_grid.Save(rect_data);

		TagBase::SaveTag(data, TagBase::SWF_TAG_DEFINE_SCALING_GRID, rect_data.ByteSize() + 2);
		data.PutShort(id);
		data.Append(rect_data);
	}

	return ErrorManager::ERROR_CODE_NONE;
}




/** \brief Returns the currently defined grid rectangle
 *
 * This function returns the currently defined grid rectangle.
 *
 * \return The grid rectangle
 */
const SRectangle& TagScalingGrid::Grid(void) const
{
	return f_grid;
}




/** \brief Define the Scaling Grid rectangle
 *
 * This function copies the input rectangle as the new Scaling
 * Grid rectangle of the button or sprite.
 *
 * You use this function directly from the button or sprite
 * as follow:
 *
 * \code
 *	TagButton *button;
 *
 *	...
 *	button->SetGrid(my_grid);
 *	...
 * \endcode
 *
 * \param rect The new Scaling Grid rectangle
 */
void TagScalingGrid::SetGrid(const SRectangle& rect)
{
	f_grid = rect;
}






/* The following options fold the documentation; use 'zi' to turn on and off
 *
 * vim: foldexpr=getline(v\:lnum)!~'^/\\*\\*'&&getline(v\:lnum)!~'^\ \\*'?0\:1 foldcolumn=2 foldmethod=expr
 */
