//
// 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 <iostream>
#ifdef Revision
#undef Revision
#endif
#define Revision "surface.cpp $Revision: 1.2 $"
Video_Surface::Video_Surface ( ) :
		_surface_ ( 0 ), _alpha_ ( ALPHA_CHANNEL ), _need_update_ ( true )
{}
Video_Surface::~Video_Surface()
{
	/// @todo реализовать корректный деструктор
	if ( _surface_ ) delete[] ( unsigned char* ) _surface_;
//	_tex_.clear();
}

int Video_Surface::_get_bpp() const
{
	return _bpp_;
}

int Video_Surface::_get_width() const
{
	return _w_;
}

int Video_Surface::_get_height() const
{
	return _h_;
}

void* Video_Surface::_get_surface_data()
{
	_need_update_ = true;
	return _surface_;
}

int Video_Surface::_get_line_size() const
{
	return _w_ * _bpp_;
}
Uint32 Video_Surface:: _get_Rmask() const
{
	return _Rmask_;
}
Uint32 Video_Surface:: _get_Gmask() const
{
	return _Gmask_;
}
Uint32 Video_Surface:: _get_Bmask() const
{
	return _Bmask_;
}
Uint32 Video_Surface:: _get_Amask() const
{
	return _Amask_;
}
bool Video_Surface::_create_ ( Uint16 w, Uint16 h )
{
	_need_update_ = true;
	_bpp_ = 4;
	_w_ = w;
	_h_ = h;
	_surface_ = new unsigned char[ w * h * _bpp_ ];
	_Rmask_ = 0xff000000;
	_Gmask_ = 0x00ff0000;
	_Bmask_ = 0x0000ff00;
	_Amask_ = 0x000000ff;
	_alpha_ = ALPHA_CHANNEL;
	return true;
}

void Video_Surface::_split_texture_ ( Uint16 x, Uint16 y, Uint16 w, Uint16 h, Sint16 *mas, Uint8 len )
{
/*	//Horiz_split
	Uint16 wn, hn;
	for ( Sint8 a = len - 1;a >= 0;a-- )
	{
		if ( mas[ a ] > w ) continue;
		wn = mas[ a ];
		break;
	}
	//Vert split
	for ( Sint8 a = len - 1;a >= 0;a-- )
	{
		if ( mas[ a ] > h ) continue;
		hn = mas[ a ];
		break;
	}
	Video_Surface_Data z ( x, y, wn, hn );
	_tex_.push_back ( z );

	if ( wn != _w_ -x ) _split_texture_ ( x + wn, y, _w_ - ( x + wn ), _h_ -y, mas, len );
	if ( hn != _h_ -y ) _split_texture_ ( x, y + hn, wn, _h_ - ( y + hn ), mas, len );*/
}

Video_Surface::ALPHASTATE Video_Surface::_get_alpha_status( )
{
	return _alpha_;
}

void Video_Surface::_set_alpha_status ( ALPHASTATE act )
{
	_alpha_ = act;
}

void Video_Surface::_link_sprite ( std::string sprite_name, std::string sprite_group )
{
	_sprites_.push_back ( std::make_pair ( sprite_name, sprite_group ) );
}
void Video_Surface::_link_sprite ( Video_Sprite *spr )
{
	_sprites_p_.push_back ( spr );
}
