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/PhysicalComponents/Area.h"
00026 #include "Teddy/PhysicalComponents/ActionButton.h"
00027 #include "Teddy/PhysicalComponents/EventListener.h"
00028 #include "Teddy/PhysicalComponents/Projection.h"
00029 #include "Teddy/PhysicalComponents/Style.h"
00030 #include "Teddy/Graphics/View.h"
00031 #include "Teddy/Graphics/Font.h"
00032 #include "Teddy/SysSupport/Messages.h"
00033 #include "Teddy/SysSupport/StdIO.h"
00034 #ifndef SWIG
00035 #include <cassert>
00036 #endif
00037 using namespace Teddy::Graphics;
00038 using namespace Teddy::SysSupport;
00039
00040
00041 namespace Teddy {
00042 namespace PhysicalComponents {
00043
00044
00045 const unsigned long Area::CLIP_LAYOUT = (1L<<0L);
00046 const unsigned long Area::CLIP_RENDERING = (1L<<1L);
00047 const unsigned long Area::CLEAR = (1L<<2L);
00048 const unsigned long Area::PICK = (1L<<3L);
00049
00050 const unsigned long Area::USE_OFFSET_SELF_SIZE_RELATIVE = (1L<<8L) ;
00051 const unsigned long Area::USE_OFFSET_FREE_SIZE_RELATIVE = (1L<<9L) ;
00052 const unsigned long Area::USE_FILL_MAX_PIXELS = (1L<<10L) ;
00053 const unsigned long Area::USE_FILL_FREE_SIZE_RELATIVE = (1L<<11L) ;
00054 const unsigned long Area::USE_CLIP_TO_REFERENCE = (1L<<12L) ;
00055
00056
00057 WindowManager *Area::default_window_manager = NULL;
00058
00059
00060 void Area::setDefaultWindowManager( WindowManager *wm ){
00061 Area::default_window_manager = wm;
00062 }
00063
00064
00066 Area::Area( std::string &name )
00067 :
00068 Named (name),
00069 Options ( 0 ),
00070 ViewClient(NULL)
00071 {
00072 style = Style::default_style;
00073 parent = NULL;
00074 drawing_ordering = pre_self;
00075 event_ordering = post_self;
00076 window_manager = default_window_manager;
00077 offset_pixels = Vector2( 0, 0 );
00078 offset_self_size_relative = Vector2( 0, 0 );
00079 offset_free_size_relative = Vector2( 0, 0 );
00080 fill_base_pixels = Vector2( 0, 0 );
00081 fill_free_size_relative = Vector2( 0, 0 );
00082 Area *t_ar = dynamic_cast<Area *>( this );
00083 ActionButton *t_ab = dynamic_cast<ActionButton *>( this );
00084 EventListener *t_ev = dynamic_cast<EventListener *>( this );
00085 Named *t_na = dynamic_cast<Named *>( this );
00086 }
00087
00088
00089 Area::Area( const std::string &name )
00090 :
00091 Named (name),
00092 Options ( 0 ),
00093 ViewClient(NULL)
00094 {
00095 style = Style::default_style;
00096 parent = NULL;
00097 drawing_ordering = pre_self;
00098 event_ordering = post_self;
00099 window_manager = default_window_manager;
00100 offset_pixels = Vector2( 0, 0 );
00101 offset_self_size_relative = Vector2( 0, 0 );
00102 offset_free_size_relative = Vector2( 0, 0 );
00103 fill_base_pixels = Vector2( 0, 0 );
00104 fill_free_size_relative = Vector2( 0, 0 );
00105 }
00106
00107
00108 Area::Area()
00109 :
00110 Named (),
00111 Options ( 0 ),
00112 ViewClient(NULL)
00113 {
00114 style = Style::default_style;
00115 parent = NULL;
00116 drawing_ordering = pre_self;
00117 event_ordering = post_self;
00118 window_manager = default_window_manager;
00119 offset_pixels = Vector2( 0, 0 );
00120 offset_self_size_relative = Vector2( 0, 0 );
00121 offset_free_size_relative = Vector2( 0, 0 );
00122 fill_base_pixels = Vector2( 0, 0 );
00123 fill_free_size_relative = Vector2( 0, 0 );
00124 }
00125
00126
00128 Area::~Area(){
00129 }
00130
00131
00133 Area *Area::getHit( const Vector2 &pos ){
00134 const char *name = getName().c_str();
00135
00136 if( areas.empty() ){
00137 dmsg( M_WME, "Trying Area %s (no children)", name );
00138 }else{
00139 dmsg( M_WME, "Trying Area %s", name );
00140 }
00141
00142
00143 if( event_ordering == pre_self ){
00144 if( rect.hit(pos) ){
00145 dmsg( M_WME, "Hit Area Pre" );
00146 return this;
00147 }
00148 }
00149
00150
00151 dmsg( M_WME, "Begin area children of %s", name );
00152 list<Area*>::iterator a_it = areas.begin();
00153 while( a_it != areas.end() ){
00154 Area *hit = (*a_it)->getHit( pos );
00155 if( hit != NULL ){
00156 return hit;
00157 }
00158 a_it++;
00159 }
00160 dmsg( M_WME, "End Area Children of %s", name );
00161
00162
00163
00164 if( event_ordering == post_self ){
00165 if( rect.hit(pos) ){
00166 dmsg( M_WME, "Hit Area Post" );
00167 return this;
00168 }
00169 }
00170
00171
00172 return NULL;
00173 }
00174
00175
00177 void Area::setParent( Area *parent, View *view ){
00178 this->parent = parent;
00179 setView( view );
00180
00181
00182 list<Area*>::iterator a_it = areas.begin();
00183 while( a_it != areas.end() ){
00184 if( (*a_it)->getParent() != NULL ){
00185 (*a_it)->setParent( this, view );
00186 }
00187 a_it++;
00188 }
00189 }
00190
00191
00193 Area *Area::getParent(){
00194 return this->parent;
00195 }
00196
00197
00198 const Rect &Area::getRect() const {
00199 return rect;
00200 };
00201
00202
00203 const Vector2 &Area::getSize() const {
00204 return size;
00205 }
00206
00207
00209 void Area::insert( Area *area ){
00210 if( area == NULL ){
00211 dmsg( M_WM, "Area::insert() Area *area == NULL");
00212 return;
00213 }
00214 areas.push_back( area );
00215 area->setParent( this, this->view );
00216 }
00217
00218
00220 bool Area::remove( Area *child ){
00221 list<Area*>::iterator a_it = areas.begin();
00222 while( a_it != areas.end() ){
00223 if( *a_it == child ){
00224 this->areas.remove( child );
00225 dmsg( M_WM, "Area::remove succeeded\n" );
00226 return true;
00227 }
00228 a_it++;
00229 }
00230 dmsg( M_WM, "Area::remove FAILED\n" );
00231 return false;
00232 }
00233
00234
00235 };
00236 };
00237