00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Teddy/Graphics/View.h"
00026 #include "Teddy/PhysicalComponents/EventListener.h"
00027 #include "Teddy/PhysicalComponents/Layer.h"
00028 #include "Teddy/PhysicalComponents/Projection.h"
00029 #include "Teddy/SysSupport/Messages.h"
00030 using namespace Teddy::Graphics;
00031
00032
00033 namespace Teddy {
00034 namespace PhysicalComponents {
00035
00036
00038 Layer::Layer( std::string name, View *view ):Area(name){
00039
00040 this->parent = NULL;
00041 this->view = view;
00042 this->drawing_ordering = post_self;
00043 IntVector2 vs = view->getSize();
00044 IntVector2 ziv = IntVector2(0,0);
00045 this->rect = Rect( ziv, vs );
00046 this->size = rect.getSize();
00047 dmsg( M_WM, "Layer constructor done." );
00048 }
00049
00050
00052 Area *Layer::getHit( const Vector2 &pos ){
00053 EventListener *e = dynamic_cast<EventListener*>( this );
00054 const char *name = getName().c_str();
00055 if( e != NULL ){
00056 dmsg( M_WME, "Trying layer %s - Listening for events", name );
00057 }else{
00058 dmsg( M_WME, "Trying layer %s - not listening for events", name );
00059 }
00060 Area *hit = NULL;
00061
00062
00063 if( event_ordering == pre_self && e != NULL ){
00064 if( rect.hit(pos) ){
00065 dmsg( M_WME, "Hit this layer first" );
00066 return this;
00067 }
00068 }
00069
00070
00071 if( !areas.empty() ){
00072 dmsg( M_WME, "Begin try children of layer %s", name );
00073 list<Area*>::iterator a_it = areas.begin();
00074 while( a_it != areas.end() ){
00075 hit = (*a_it)->Area::getHit( pos );
00076 if( hit != NULL ){
00077 dmsg( M_WME, "Hit child Area" );
00078 return hit;
00079 }
00080 a_it++;
00081 }
00082 dmsg( M_WME, "End try children of layer %s", name );
00083 }
00084
00085
00086
00087 dmsg( M_WME, "Begin try projections of %s", name );
00088 list<Projection*>::iterator p_it = projs.begin();
00089 while( p_it != projs.end() ){
00090 hit = (*p_it)->getHit( pos );
00091 if( hit != NULL ){
00092 dmsg( M_WME, "Hit Projection Area" );
00093 return hit;
00094 }
00095 p_it++;
00096 }
00097 dmsg( M_WME, "End try projections of %s", name );
00098
00099
00100
00101 if( event_ordering == post_self && e != NULL ){
00102 if( rect.hit(pos) ){
00103 dmsg( M_WME, "Hit this last" );
00104 return this;
00105 }
00106 }
00107 return hit;
00108 }
00109
00110
00112 void Layer::update( View *view ){
00113 dmsg( M_WML, "" );
00114 dmsg( M_WML, "Layer::update() ..." );
00115 rect = Rect( IntVector2(0,0), view->getSize() );
00116 size = rect.getSize();
00117
00118
00119 place();
00120 dmsg( M_WML, "Layer::update() done" );
00121 }
00122
00123
00125 void Layer::drawSelf(){
00126 list<Projection*>::iterator p_it = projs.begin();
00127 while( p_it != projs.end() ){
00128 (*p_it)->drawSelf();
00129 p_it++;
00130 }
00131 }
00132
00134 void Layer::addProjection( Projection *p ){
00135 if( p!=NULL ){
00136 projs.push_back( p );
00137 p->setParent( this, this->view );
00138 this->insert( p );
00139 }
00140 }
00141
00142
00144 void Layer::place(){
00145 list<Area*>::iterator a_it = areas.begin();
00146 while( a_it != areas.end() ){
00147 (*a_it)->doSize( rect.getSize() );
00148 a_it++;
00149 }
00150
00151 a_it = areas.begin();
00152 while( a_it != areas.end() ){
00153 (*a_it)->doPlace( rect );
00154 a_it++;
00155 }
00156
00157 list<Projection*>::iterator p_it = projs.begin();
00158 while( p_it != projs.end() ){
00159 (*p_it)->doSize ( rect.getSize() );
00160 (*p_it)->doPlace( rect );
00161 p_it++;
00162 }
00163 }
00164
00165
00167 void Layer::drawLayer(){
00168 if( view == NULL ){
00169 dmsg( M_WM, "drawLayer() NULL view" );
00170 return;
00171 }else{
00172 dmsg(
00173 M_WM,
00174 "layer %s drawLayer() size %f x %f",
00175 getName().c_str(),
00176 size[0],
00177 size[1]
00178 );
00179 }
00180 drawSelf();
00181
00182 view->begin2d();
00183 list<Area*>::iterator a_it = areas.begin();
00184 while( a_it != areas.end() ){
00185 Area *a = *a_it;
00186 const char *name = a->getName().c_str();
00187 dmsg( M_WM, "drawLayer() calling draw for area %s", name );
00188 a->draw();
00189 a_it++;
00190 }
00191 view->end2d();
00192 }
00193
00194
00195 };
00196 };
00197