Home Page Toolkit Overview Using GML User Input Services Finger Tracker Calibrator Frame Grabber Service protocol Obtaining GML Installing GML Licence Developer Documentation Tcl/Tk API The GML Canvas Image processing Tcl Scripts Library List of Classes List of Files C/C++ API List of Classes List of Files |
gml_GRItem.h00001 // gml_GRItem.h -- 00002 // 00003 // Declares the "gml_TGRItem" class. A gml_TGRItem objects is a graphical 00004 // object. It as a parent and its geometric transformation is expressed in 00005 // its parent reference. 00006 // 00007 // Copyright (c) 2003 CLIPS-IMAG 00008 // 00009 // See the file "gml_LicenseTerms.txt" for information on usage and redistribution 00010 // of this file, and for a DISCLAIMER OF ALL WARRANTIES. 00011 // 00012 // November 17, 2003 (FB) 00013 // Re-written for gml 00014 // separate GL rendering 00015 // debug 00016 // 00017 // Created on July 2003 (Yohan Piccoli / FB). 00018 00019 #ifndef __GML_GRITEM__ 00020 #define __GML_GRITEM__ 00021 00022 #include <stdlib.h> 00023 00024 #include "gml/base/gml_Errors.h" 00025 #include "gml/base/gml_List.h" 00026 #include "gml/ui/gml_GRItem_Scene.h" 00027 #include "gml/ui/gml_GRItemTransfo.h" 00028 00029 00030 extern gml_TError gml_gGRItem_noScene; 00031 extern gml_TError gml_gGRItem_settingSelfAsParent; 00032 extern gml_TError gml_gGRItem_settingOffspringAsParent; 00033 extern gml_TError gml_gGRItem_notEnoughShapePoints; 00034 extern gml_TError gml_gGRItem_clippingLoop; 00035 extern gml_TError gml_gGRItem_settingSelfAsClipper; 00036 00037 00038 // gml_TGRItemAnchor -- 00039 // 00040 // Anchor of an item to a point, one on the 9 possibilities: 00041 // NW N NE 00042 // W C E 00043 // SW S SE 00044 00045 typedef enum { 00046 gml_cGRItem_AnchorN, 00047 gml_cGRItem_AnchorNE, 00048 gml_cGRItem_AnchorE, 00049 gml_cGRItem_AnchorSE, 00050 gml_cGRItem_AnchorS, 00051 gml_cGRItem_AnchorSW, 00052 gml_cGRItem_AnchorW, 00053 gml_cGRItem_AnchorNW, 00054 gml_cGRItem_AnchorC 00055 00056 } gml_TGRItemAnchor; 00057 00058 extern char gml_cGRItem_AnchorStrings[9][3]; 00059 00060 00061 00062 // gml_TGRItem -- 00063 00064 class gml_TGRItem 00065 { 00066 public: 00067 00068 // Init -- 00069 // 00070 // Initializes the item. 00071 // <scene> is the scene in which to add the new item. May be <NULL> is 00072 // <parentItem> is not NULL: an item is always in its parent scene. 00073 // <parentItem> is the parent item which transformation is applied before 00074 // drawing the item. 00075 // <NULL> means that this item is the root item. 00076 // <transfo> is the initial transformation from parent reference to 00077 // the origin of the item reference. 00078 // <NULL> means identity. 00079 // <clientData> is a client supplied parameter stored in the item and 00080 // made accessible through the "ClientData" method. 00081 virtual 00082 gml_TError Init (gml_TGRItem_Scene* scene = (gml_TGRItem_Scene*)NULL, 00083 gml_TGRItem* parentItem = (gml_TGRItem*)NULL, 00084 gml_TGRItemTransfo* transfo = (gml_TGRItemTransfo*)NULL, 00085 gml_TPointer clientData = (gml_TPointer)NULL); 00086 00087 // Dispose -- 00088 // 00089 // Removes the Item from the hierarchy. 00090 virtual 00091 void Dispose (); 00092 00093 virtual ~gml_TGRItem () {} 00094 00095 // Suicide -- 00096 // 00097 // The C++ delete operator should not be called on gml_TGRItems, instead call 00098 // the "Suicide" method which must me implemented as "delete this;" in 00099 // the join (most specialized) class. 00100 00101 virtual 00102 void Suicide () = 0; 00103 00104 // Scene -- 00105 // 00106 // Return the scene in which the item is drawn. 00107 00108 gml_TGRItem_Scene* Scene () 00109 { return fScene; } 00110 00111 // SetParent -- 00112 // 00113 // Set <parent> as the parent of this item. Manages the update 00114 // of a previous parent if necessary. 00115 // <parent> may be NULL. 00116 00117 gml_TError SetParent (gml_TGRItem* item); 00118 00119 // Children -- 00120 // 00121 // Returns the list of children of this item. The list must be 00122 // used as read only. 00123 00124 gml_TList* Children () 00125 { return fChildren; } 00126 00127 // IsAncestor -- 00128 00129 gml_TBoolean IsAncestor (gml_TGRItem* item); 00130 00131 // IsOffspring -- 00132 00133 gml_TBoolean IsOffspring (gml_TGRItem* item); 00134 00135 // IsClipped -- 00136 00137 gml_TBoolean IsClipped () 00138 { return (gml_TBoolean)(fClipper != NULL); } 00139 00140 // ClippedByMe -- 00141 // 00142 // Returns the list of items clipped by this item. The list must be 00143 // used as read only. 00144 00145 gml_TList* ClippedByMe () 00146 { return fClippedByMe; } 00147 00148 // Clipper -- 00149 00150 gml_TGRItem* Clipper () 00151 { return fClipper; } 00152 00153 // SetClipper -- 00154 00155 gml_TError SetClipper (gml_TGRItem* item); 00156 00157 // SetItemTransfo -- 00158 // SetItemStdTransfov -- 00159 // SetItemStdTransfo -- 00160 inline 00161 void SetItemTransfo (gml_TGRItemTransfo* t); 00162 inline 00163 void SetItemStdTransfov (gml_TGRItemParam* stdTransfo); 00164 inline 00165 void SetItemStdTransfo (gml_TGRItemParam tx, 00166 gml_TGRItemParam ty, 00167 gml_TGRItemParam r, 00168 gml_TGRItemParam sx, 00169 gml_TGRItemParam sy); 00170 00171 00172 00173 // Transfo -- 00174 // 00175 // Returns local transformation of the item from its immediate parent. 00176 00177 gml_TGRItemTransfo* Transfo () 00178 { return fTransfo; } 00179 00180 // GlobalTransfo -- 00181 // 00182 // Returns a pointer to the global transformation of the item. The returned 00183 // transformation must be considered as read only. 00184 inline 00185 gml_TGRItemTransfo* GlobalTransfo (); 00186 00187 // ComputeGlobalTransfo -- 00188 // 00189 // Compute the global transformation: the transformation from item coordinates to 00190 // root coordinates. 00191 00192 void ComputeGlobalTransfo (); 00193 00194 // InvalidateGlobalTransfo -- 00195 // 00196 // Mark the global transformation as "dirty" so that the next time it is requested, it will 00197 // be recalculated. Inverse global transformation, bouding box and extended bounding box 00198 // are also marked "dirty". Propagates to the children. 00199 // If <ancestors> is true, propagates the invalidation of the extended bounding box to the 00200 // ancestors of the item. 00201 00202 void InvalidateGlobalTransfo (gml_TBoolean ancestors = gml_cTrue); 00203 00204 // InvGlobalTransfo -- 00205 // 00206 // Returns a pointer to the inverse global transformation of the item. The returned 00207 // transformation must be considered as read only. 00208 inline 00209 gml_TGRItemTransfo* InvGlobalTransfo (); 00210 00211 00212 00213 00214 // BBox -- 00215 // 00216 // Returns a pointer to the bounding box of the item. The returned array must be 00217 // considered as read only. 00218 // The bounding box is the smallest rectangle aligned with the root axis that 00219 // contains the item, expressed in root coordinates. 00220 // The bounding box is represented by the array of its 00221 // { left, bottom, right, top } coordinates. 00222 inline 00223 gml_TGRItemParam* BBox (); 00224 00225 // UpdateNonClippedBBox -- 00226 // 00227 // Update the bounding box of an item as if it was not clipped by another item 00228 // (which may be the cas). 00229 virtual 00230 void UpdateNonClippedBBox () = 0; 00231 00232 // InvalidateBBox -- 00233 // 00234 // Mark the bounding box "dirty" so that the next time it is requested, it will 00235 // be recalculated. Propagates to parent's extended bounding box. 00236 inline 00237 void InvalidateBBox (); 00238 00239 // ExtBBox -- 00240 // 00241 // Returns the extended BBox of the item. See the "BBox" method for a definition of the 00242 // bouding box of the item. The extended BBox is the bounding box of the item and all 00243 // its children that are not clipped inside the item. 00244 inline 00245 gml_TGRItemParam* ExtBBox (); 00246 00247 // ComputeExtBBox -- 00248 // 00249 // Updates the extended bounding box of the item. 00250 00251 void ComputeExtBBox (); 00252 00253 // InvalidateExtBBox -- 00254 // 00255 // Mark the extended bounding box "dirty" so that the next time it is requested, 00256 // it will be recalculated. Propagates to parent's extended bounding box. 00257 inline 00258 void InvalidateExtBBox (); 00259 00260 00261 00262 // Draw -- 00263 // 00264 // Draws the item on screen. 00265 virtual 00266 void Draw () =0; 00267 00268 00269 00270 // LocalToGlobal -- 00271 // GlobalToLocal -- 00272 // 00273 // "LocalToGlobal" transforms local (item) 2 dimentional vector coordinates in <locSrc> 00274 // to global (root window) 2 dimentional vector coordinates in <gloDst>. 00275 // "GlobalToLocal" does the opposite from <gloSrc> to <locDst>. 00276 00277 inline void LocalToGlobal (gml_TGRItemParam* locSrc, gml_TGRItemParam* gloDst); 00278 inline void GlobalToLocal (gml_TGRItemParam* gloSrc, gml_TGRItemParam* locDst); 00279 00280 00281 00282 // IsOverItem -- 00283 // 00284 // Returns true if the point <pt>, expressed in the global reference, is above a non 00285 // transparent pixel of the item. 00286 00287 virtual 00288 gml_TBoolean IsOverItem (gml_TGRItemParam* pt) =0; 00289 00290 00291 00292 // PointToItem and RelationToRect are deprecated. The only available way to pick items is 00293 // by calling "IsOverItem". 00294 // 00295 // PointToItem -- 00296 // 00297 // Returns the distance between the point <pt>, expressed in root coordinates, 00298 // to the item. 00299 virtual 00300 gml_TGRItemParam PointToItem (gml_TGRItemParam* pt) =0; 00301 00302 // RelationToRect -- 00303 // 00304 // Returns the relation of the item versus a rectangle <rect>. 00305 // Returns 1 if the item is completely enclosed in the rectangle, 00306 // returns 0 if the item boundaries intersect the rectangle, and 00307 // returns -1 if the item is completely outside the rectangle. 00308 // <rect> is specified as the array of left, bottom, right, top coordinates 00309 // of the rectangle. 00310 virtual 00311 int RelationToRect (gml_TGRItemParam* rect) =0; 00312 00313 00314 // Layer -- 00315 00316 int Layer () 00317 { return fLayer; } 00318 00319 // SetLayer -- 00320 // 00321 // Set this layer level to <level> 00322 // change all descendant layer level if <withHierarchy> is not 0 00323 // don't modify DisplayList order 00324 00325 void SetLayer (int level, int whithHierarchy); 00326 00327 // Visible -- 00328 00329 gml_TBoolean Visible ( ) 00330 { return fVisible; } 00331 00332 // SetVisible -- 00333 00334 void SetVisible (gml_TBoolean visible) 00335 { fVisible = visible; } 00336 00337 // GetEvents -- 00338 00339 gml_TBoolean GetEvents ( ) 00340 { return fGetEvents; } 00341 00342 // SetGetEvents -- 00343 00344 void SetGetEvents (gml_TBoolean getEvents) 00345 { fGetEvents = getEvents; } 00346 00347 // SetClientData-- 00348 // 00349 // Stores a pointer <clientData> in the item. This pointer is never used by the GRItem 00350 // library, it is provided to the library client code through the "ClientData" method. 00351 00352 void SetClientData (void* clientData) 00353 { fClientData = clientData; } 00354 00355 // ClientData -- 00356 // 00357 // See "SetClientData". 00358 00359 gml_TPointer ClientData () 00360 { return fClientData; } 00361 00362 protected: 00363 00364 // IsInMyClippers -- 00365 00366 gml_TBoolean IsInMyClippers (gml_TGRItem *item); 00367 00368 friend gml_TError gml_GRItem_Initialize (); 00369 00370 gml_TGRItem_Scene* fScene; /* scene in which item is drawn */ 00371 gml_TGRItemTransfo* fTransfo; /* transformation from item coordinates to parent's */ 00372 gml_TGRItemTransfo* fGlobal; /* transformation from item coordinates to root coordinates */ 00373 gml_TBoolean fGlobalDirty; /* true if fGlobal needs to be recomputed */ 00374 gml_TGRItemTransfo* fInvGlobal; /* transformation from root coordinates to item coordinates */ 00375 gml_TBoolean fInvGlobalDirty; /* true if fInvGlobal needs to be recomputed */ 00376 gml_TGRItemParam fBBox[4]; /* bounding box in global coords. (left bottom right top) */ 00377 gml_TBoolean fBBoxDirty; /* true if fBBox needs to be recomputed */ 00378 gml_TGRItemParam fExtBBox[4]; /* extended bounding box in global coords. (left bottom 00379 right top), i.e. the bouding box of the item plus all 00380 its non clipped children */ 00381 gml_TBoolean fExtBBoxDirty; /* true if fExtBBox needs to be recomputed */ 00382 00383 gml_TGRItem* fParent; /* parent item */ 00384 gml_TList* fChildren; /* list of children */ 00385 gml_TGRItem* fClipper; /* clipping item */ 00386 gml_TList* fClippedByMe; /* list of items directly clipped by this item */ 00387 00388 int fLayer; /* layer number (0 = bottom most) */ 00389 gml_TBoolean fVisible; /* true if item is visible */ 00390 gml_TBoolean fGetEvents; /* true if item recieves events */ 00391 00392 gml_TPointer fClientData; /* Arbitrary one-word value for client use */ 00393 }; 00394 00395 00396 00397 00398 00399 00400 // Inline function definitions. 00401 00402 // gml_TGRItem::SetItemTransfo -- 00403 // gml_TGRItem::SetItemStdTransfov -- 00404 // gml_TGRItem::SetItemStdTransfo -- 00405 inline 00406 void gml_TGRItem::SetItemTransfo (gml_TGRItemTransfo* t) 00407 { 00408 t->CopyTo (fTransfo); 00409 this->InvalidateGlobalTransfo (); 00410 } 00411 00412 inline 00413 void gml_TGRItem::SetItemStdTransfov (gml_TGRItemParam* stdTransfo) 00414 { 00415 fTransfo->SetFromStdv (stdTransfo); 00416 this->InvalidateGlobalTransfo (); 00417 } 00418 00419 inline 00420 void gml_TGRItem::SetItemStdTransfo (gml_TGRItemParam tx, 00421 gml_TGRItemParam ty, 00422 gml_TGRItemParam r, 00423 gml_TGRItemParam sx, 00424 gml_TGRItemParam sy) 00425 { 00426 fTransfo->SetFromStd (tx, ty, r, sx, sy); 00427 this->InvalidateGlobalTransfo (); 00428 } 00429 00430 // gml_TGRItem::GlobalTransfo -- 00431 inline 00432 gml_TGRItemTransfo* gml_TGRItem::GlobalTransfo () 00433 { 00434 if (fGlobalDirty) 00435 this->ComputeGlobalTransfo (); 00436 return fGlobal; 00437 } 00438 00439 // gml_TGRItem::InvGlobalTransfo -- 00440 inline 00441 gml_TGRItemTransfo* gml_TGRItem::InvGlobalTransfo () 00442 { 00443 if (fInvGlobalDirty) { 00444 fInvGlobal->SetFromInverse (this->GlobalTransfo ()); 00445 fInvGlobalDirty = gml_cFalse; 00446 } 00447 return fInvGlobal; 00448 } 00449 00450 // gml_TGRItem::BBox -- 00451 inline 00452 gml_TGRItemParam* gml_TGRItem::BBox () 00453 { 00454 gml_TGRItemParam* bbox; 00455 00456 if (fBBoxDirty) { 00457 this->UpdateNonClippedBBox (); 00458 if (fClipper != NULL) { 00459 bbox = fClipper->BBox (); 00460 if (bbox[0] > fBBox[0]) 00461 fBBox[0] = bbox[0]; 00462 if (bbox[1] > fBBox[1]) 00463 fBBox[1] = bbox[1]; 00464 if (bbox[2] < fBBox[2]) 00465 fBBox[2] = bbox[2]; 00466 if (bbox[3] < fBBox[3]) 00467 fBBox[3] = bbox[3]; 00468 } 00469 fBBoxDirty = gml_cFalse; 00470 } 00471 return fBBox; 00472 } 00473 00474 // gml_TGRItem::InvalidateBBox -- 00475 inline 00476 void gml_TGRItem::InvalidateBBox () 00477 { 00478 fBBoxDirty = gml_cTrue; 00479 fExtBBoxDirty = gml_cTrue; 00480 00481 if (fParent != (gml_TGRItem*)NULL) 00482 fParent->InvalidateExtBBox (); 00483 } 00484 00485 // gml_TGRItem::ExtBBox -- 00486 inline 00487 gml_TGRItemParam* gml_TGRItem::ExtBBox () 00488 { 00489 if (fExtBBoxDirty) 00490 this->ComputeExtBBox (); 00491 return fExtBBox; 00492 } 00493 00494 // gml_TGRItem::InvalidateExtBBox -- 00495 inline 00496 void gml_TGRItem::InvalidateExtBBox () 00497 { 00498 fExtBBoxDirty = gml_cTrue; 00499 00500 if (fParent != (gml_TGRItem*)NULL) 00501 fParent->InvalidateExtBBox (); 00502 } 00503 00504 00505 00506 // gml_TGRItem::LocalToGlobal -- 00507 inline 00508 void gml_TGRItem::LocalToGlobal (gml_TGRItemParam* locSrc, gml_TGRItemParam* gloDst) 00509 { 00510 this->GlobalTransfo ()->Transform2v (locSrc, gloDst); 00511 } 00512 00513 00514 // gml_TGRItem::GlobalToLocal -- 00515 inline 00516 void gml_TGRItem::GlobalToLocal (gml_TGRItemParam* gloSrc, gml_TGRItemParam* locDst) 00517 { 00518 this->InvGlobalTransfo ()->Transform2v (gloSrc, locDst); 00519 } 00520 00521 #endif
Generated on Tue Jun 12 14:03:27 2007 for gml by
Doxygen 1.5.2.
|
Contact: julien (dot) letessier (at) gmail (dot) com.
Copyright (c) 2000-2007 CLIPS-IMAG Laboratory, Grenoble, France. All rights reserved. W3CXHTML 1.0 W3CCSS 2.0 |