//
// C++ Implementation: me_opengl_video_surface
//
// Description:
//
//
// Author: Messenger of death <Messengerofdeath@gmail.com>, (C) 2005
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifdef HAVE_CONFIG_H
#include <conf_config.h>
#endif

#include "video_int.h"
#include "video.h"

#include <iostream>
#ifdef Revision
#undef Revision
#endif
#define Revision "sprite.cpp $Revision: 1.3 $"
		Video_Sprite::Video_Sprite ( std::string spr_name, std::string spr_group, Video_Interface *vid ) : _surface_name_ ( "" ), _surface_group_ ( "" ), _sprite_name_(spr_name), _sprite_group_(spr_group), _Ablend_ ( 1.0 ),_Rblend_ ( 1.0 ),_Gblend_ ( 1.0 ),_Bblend_ ( 1.0 ), _scale_x_ ( 1.0 ), _scale_y_ ( 1.0 ),
		_base_x_ ( 0.0 ), _base_y_ ( 0.0 ), _w_ ( 0 ), _h_ ( 0 ), _drawed_ ( false ), _drv_(vid)
{
	_rotation_[0]=0.0;
	_rotation_[1]=0.0;
	_rotation_[2]=0.0;
	_need_draw_=false;
}


void Video_Sprite::_set_scale ( float x, float y )
{
	_scale_x_ = x;
	_scale_y_ = y;
}

void Video_Sprite::_set_rotation ( float x, float y, float z )
{
	_rotation_[0]=x;
	_rotation_[1]=y;
	_rotation_[2]=z;
}
void Video_Sprite::_set_base_point ( double x, double y )
{
	_base_x_=2*x* ( float ) _w_/ ( float ) _drv_->_get_width();
	_base_y_=2*y* ( float ) _h_/ ( float ) _drv_->_get_height();
}
void Video_Sprite::_set_base_point ( int x, int y )
{
	_set_base_point ( ( double ) x/ ( double ) _w_, ( double ) y/ ( double ) _h_ );
}
void Video_Sprite::_set_alpha ( float a )
{
	_Ablend_=a;
}
void Video_Sprite::_set_surface ( Video_Interface *vid, std::string name, std::string group )
{
	Video_Surface *surf;
	if(!(surf=vid->_get_surface ( name, group )))
	{
		std::cerr<<"Cant create sprite ["<<_sprite_name_<<":"<<_sprite_group_<<"]:"<<vid->_get_error()<<std::endl;
		return;
	}
	surf->_link_sprite ( _sprite_name_, _sprite_group_ );
	surf->_link_sprite (this);
	_surface_name_=name;
	_surface_group_=group;
	_w_=surf->_w_;
	_h_=surf->_h_;
}

void Video_Sprite::_set_coord ( double x, double y )
{
	_x_=x;
	_y_=y;
}
void Video_Sprite::_get_rectangle(VideoRect *rect)
{
	if(!rect)return;
	rect->x_s=_x_-_base_x_;
	rect->y_s=_y_-_base_y_;
	rect->x_e=rect->x_s+2.*(float)_w_/(float)_drv_->_get_width();
	rect->y_e=rect->y_s+2.*(float)_h_/(float)_drv_->_get_height();	
}
double Video_Sprite::_get_v_offset(double v_offset)
{
	return 2*v_offset* ( float ) _h_/ ( float ) _drv_->_get_height();
}
double Video_Sprite::_get_h_offset(double h_offset)
{
	return 2*h_offset* ( float ) _w_/ ( float ) _drv_->_get_width();
}
void Video_Sprite::_set_blend_color(float r, float g, float b)
{
	_Rblend_=r;
	_Gblend_=g;
	_Bblend_=b;
}

