//--------------------------------
//********************************
//******** Class space ***********
//********************************
//--------------------------------


//********************************
//********* Constructors *********
//********************************
function space()
{
  //this.ancestor_create(i_rect, true, true, true, true);

   
   //rend_bitmap().background().r = 0;  
  // rend_bitmap().background().g = 0; 
  // rend_bitmap().background().b = 0; 
  // rend_bitmap().background().a = 0; 
  // layer_group::create(rect); 

  /* this.resizable(false);
   this.visible(true);
   this.dragable(false);*/

  // this.change_layer_order_on_click(true);
}



function owk_space_create(i_rect) 
{ 
   this.ancestor_create(i_rect, false, true, true, true);

}


function owk_space_destroy()
{

}

function owk_space_switch_in()
{
   this.m_mouse_on_layer_ptr = 0;
}

function owk_space_flatern_layers()
{

}

function owk_space_on_draw(i_background, i_region)
{
  /* owk_bool taken = false;

   // first copy the background inside the space
   i_background.rend_bitmap().copy(i_region, rend_bitmap(), i_region); // region is in space coordinates

   // render all layers to the current space
   taken = layer_group::on_draw(i_background, i_region);

   return taken;*/
}

space.prototype = new layer_group;
space.prototype.create = owk_space_create;
space.prototype.ancestor_create = owk_layer_create;
space.prototype.destroy = owk_space_destroy;
space.prototype.ancestor_destroy = owk_layer_group_destroy;
space.prototype.switch_in = owk_space_switch_in;
space.prototype.flatern_layers = owk_space_flatern_layers;
space.prototype.on_draw = owk_space_on_draw;

//--------------------------------
//********************************
//******** Class surface *********
//********************************
//--------------------------------


//********************************
//********* Constructors *********
//********************************
function surface()
{

}



function own_surface_create(i_rect)
{
   this.m_spaces = new Array();
   this.m_spaces.push(new space());
   this.m_spaces.push(new space());
   this.m_spaces.push(new space());
   this.m_spaces.push(new space());
   this.m_spaces.push(new space());
   
   this.m_space_index;
   
   //render_interface* m_render_interface;
   this.m_surface_blit;
   
   this.ancestor_create(i_rect, true, true, true);

   this.m_space_index = 0;
   //rend_bitmap().horizontal_gradient();

   this.m_surface_blit = true;

   for (var itr=0; itr < 5; itr++)
   {
      this.m_spaces[itr].create(i_rect);
	   this.m_spaces[itr].parent(this);
	   this.m_spaces[itr].visible(false);	   
   }
      
   mouse_device().push_back_listener(this);     
}

function owk_surface_destroy() 
{ 
   for (var itr=0; itr < 5; itr++)
   {  
      this.m_spaces[itr].destroy(); 
   }
   
   this.ancestor_destroy.destroy();
}

function owk_surface_on_resizing()
{
  // rend_bitmap().horizontal_gradient();

   for (var itr=0; itr < 5; itr++)
   {  
      this.m_spaces[itr].resize(region());
   }
}

function own_surface_invalidate() // refresh the entire surface
{ 
/*   owk_bool taken = false;
   // render the current space
   taken = viewed_space().on_draw(*this, region()); 
   // render the space to the true surface
   if (surface_blit())
      render().copy_bitmap_to_surface(viewed_space().rend_bitmap());
   return taken;*/
} 

function owk_surface_invalidate_region(i_region) // refresh a part of surface
{ 
 /*  owk_bool taken = false;
   // render the current space
   taken = viewed_space().on_draw(*this, i_region); 
   // render the space to the true surface
   if (surface_blit())
      render().copy_bitmap_to_surface(viewed_space().rend_bitmap(), i_region);
   return taken;*/
}

function owk_surface_do_surface_blit()
{
   //render().copy_bitmap_to_surface(viewed_space().rend_bitmap());
}

function owk_surface_set_surface_blit(i_dump)
{
   this.m_surface_blit = i_dump;
}



function own_surface_switch_space(i_index) 
{
  this.viewed_space().visible(false);	
  this.m_space_index = i_index; 
  this.viewed_space().switch_in(); 
  this.viewed_space().visible(true);	
  mouse_device().release_capture(); 
}

function own_surface_flatern_layers()
{

}


function owk_surface_draw(i_bitmap, i_region, i_alpha, i_rotation_angle, i_pivot_point, i_scale, i_refresh_region) // region is in surface coordinates
{
	
}

function viewed_space()
{
	return m_spaces[m_space_index];
}



surface.prototype = new layer;
surface.prototype.create = own_surface_create;
surface.prototype.ancestor_create = owk_layer_create;
surface.prototype.ancestor_destroy = owk_layer_group_destroy;
surface.prototype.destroy = owk_surface_destroy;
surface.prototype.switch_space = own_surface_switch_space;
surface.prototype.flatern_layers = own_surface_flatern_layers;
surface.prototype.on_draw = owk_surface_draw;
surface.prototype.do_surface_blit = owk_surface_do_surface_blit;
surface.prototype.on_resizing = owk_surface_on_resizing;
surface.prototype.invalidate_region = owk_surface_invalidate_region;
surface.prototype.invalidate = own_surface_invalidate;
surface.prototype.set_surface_blit = owk_surface_set_surface_blit;

