Layer class###########The Layer class is responsible for working with invalid regions andserves as the shadow class for BViews.Member Functions================Layer(BRect frame, const char \*name, int32 resize, int32 flags, ServerWindow \*win)------------------------------------------------------------------------------------1. acquire a new layer token2. validate (and fix, if necessary) parameters and assign to member objects3. initalize relation pointers to NULL4. set level to -15. set invalid region to NULL6. set full and visible regions to bounds7. set child count to 08. get ServerWindow's window port and create a PortLink pointed at it~Layer(void)------------1. if parent is non-NULL, call RemoveSelf()2. if topchild is non-NULL, iterate through children and delete them.3. delete invalid, full, and visible regions if non-NULL4. delete the internal PortLinkvoid AddChild(Layer \*child, Layer \*before=NULL, bool rebuild=true)--------------------------------------------------------------------Function which corresponds to BView::AddChild1) if child->parent is non-NULL, spew an error to stderr and return2) set child->parent to thisa) if before == NULL:A) if topchild is non-NULL, set child->uppersibling to childB) set child->lowersibling to topchildC) if topchild is NULL, set bottomchild to childD) set topchild to childb) if before != NULL:A) if before->upper is non-NULL, set child->upper to before->upperB) set before->upper to childC) set child->lower to beforeD) if child->upper is non-NULL, set child->upper->lower to childE) increment child's level3) increment the child count4) if rebuild flag is true, call RebuildRegionsRemoveChild(Layer \*child, bool rebuild=true)---------------------------------------------Function which corresponds to BView::RemoveChild1. if child's parent != this, spew an error to stderr and return2. set child's parent to NULL3. set child's level to -14. if top child matches child, set top child to child's lower sibling5. if bottom child matches child, set bottom child to child's upper sibilng6. if child->uppersibling is non-NULL, set its lowersibling to the child's lowersibling7. if child->lowersibling is non-NULL, set its uppersibling to the child's uppersibling8. decrement child count9. call RebuildRegionsvoid RemoveSelf(bool rebuild=true)----------------------------------Function which corresponds to BView::RemoveSelf1. if parent is NULL, spew an error to stderr and return2. call parent->RemoveChild(this)void Invalidate(BRect r)------------------------void Invalidate(BRegion \*region)---------------------------------Marks the area passed to the function as needing to be redrawn1) if parent is NULL, return2) if the passed area intersects the layer's frame, add it to theinvalid region, creating a new invalid object if necessary.3) Iterate through all child layers, calling child->Invalidate() on thearea converted from the parentBRect Frame(void), BRect Bounds(void)-------------------------------------Frame() returns the layer's frame in its parent coordinates. Bounds()returns the frame offset to (0,0).void MoveBy(BPoint pt), void MoveBy(float x, float y)-----------------------------------------------------Moves the layer in its parent's coordinate space by the specifiedamount1. offset the frame by the specified amount2. if parent is non-NULL, call parent->RebuildRegions()void ResizeBy(BPoint pt), void ResizeBy(float x, float y)---------------------------------------------------------Resizes the layer by the specified amount and all children asappropriate.1) resize the frame by the specified amount2) iterate through all children, checking the resize flags to seewhether each should be resized and calling child->ResizeBy() by theappropriate amount if it is necessary.int32 CountChildren(void)-------------------------Returns the number of children owned directly by the layer -grandchildren not included and some assembly required. Instructionsare written in Yiddish.bool IsDirty(void)------------------Returns true if the layer needs redrawn (if invalid region isnon-NULL).BRect ConvertToTop(const BRect &r), BRegion ConvertToTop(const BRegion &r)--------------------------------------------------------------------------Converts the given data to the coordinates of the root layer in thelayer tree.1) if parent is non-NULL, return the data.2) if parent is NULL, call this: return (parent->ConvertToTop(data_offset_by_frame.left_top ) )BRect ConvertFromTop(const BRect &r), BRegion ConvertFromTop(const BRegion &r)------------------------------------------------------------------------------Converts the given data from the coordinates of the root layer in thelayer tree.1. if parent is non-NULL, return the layer's frame2. if parent is NULL, call this: return (parent->ConvertFromTop(data_offset_by_frame.left_and_top \* -1 ) )BRect ConvertToParent(const BRect &r), BRegion ConvertToParent(const BRegion &r)Converts the given data to the coordinates of the parent layer1. return the data offset by the layer's frame's top left point, i.e.frame.LeftTop()BRect ConvertFromParent(const BRect &r), BRegion ConvertFromParent(const BRegion &r)------------------------------------------------------------------------------------Converts the given data from the coordinates of the parent layer1. operates exactly like ConvertToParent, except that the offsetvalues are multiplied by -1void RebuildRegions(bool recursive=false)-----------------------------------------Rebuilds the visible and invalid layers based on the layer hierarchy.Used to update the regions after a call to remove or add a child layeris made or when a layer is hidden or shown.1. get the frame2. set full and visible regions to frame3. iterate through each child and exclude its full region from thevisible region if the child is visible.4. iterate through each lowersibling and exclude its full region fromthe visible region if the it is visible and it intersects the layer'sframe.void MakeTopChild(void)-----------------------Makes the layer the top child owned by its parent. Note that the topchild is "behind" other children on the screen.1. if parent is NULL, spew an error to stderr and return2. if parent's top child equals this, return without doing anything3. if lowersibling and uppersibling are both NULL, return without doing anything4. save pointer to parent layer to a temporary variable5. call RemoveSelf and then the former parent's AddChildvoid MakeBottomChild(void)--------------------------Makes the layer the bottom child owned by its parent. Note that thetop child is "in front of" other children on the screen.1. if parent is NULL, spew an error to stderr and return2. if parent's bottom child equals this, return without doing anything3. if lowersibling and uppersibling are both NULL, return without doing anything4. save pointer to parent layer to a temporary variable5. call RemoveSelf() with rebuild set to false6. call former parent's AddChild (rebuild is false), setting the beforeparameter to the former parent's bottomchild7. save lowersibling to a temporary variable8. call lowersibling->RemoveSelf() with no rebuild9. call the parent's AddChild() with the before set to this and rebuild set to truevoid RequestDraw(const BRect &r)--------------------------------Requests that the layer be drawn on screen. The rectangle passed is inthe layer's own coordinates.1. if invalid is NULL, return2. set the PortLink opcode to B_DRAW3. create a BMessage(B_DRAW) and attach all invalid rectangles to it4. attach the view token to the message5. flatten the message to a buffer, attach it to the PortLink, and Flush() it.6. recurse through each child and call its RequestDraw() function if itintersects the child's frameLayer \*FindLayer(int32 token)------------------------------Finds a child layer given an identifying token1. iterate through children and check tokens. Return a match if found.2. iterate through children, calling its FindLayer function, return any non-NULL results3. return NULL - we got this far, so there is no matchLayer \*GetChildAt(BPoint pt, bool recursive=false)---------------------------------------------------Gets the child at a given point. if recursive is true, all layersunder the current one in the tree are searched. if the point iscontained by the current layer's frame and no child is found, thisfunction returns the current layer. if the point is outside thecurrent layer's frame, it returns NULL1. if frame does not contain the point, return NULLif recursive is true:A. start at the \*bottom\* child and iterate upward.B. if the child has children, call the child's GetChildAt with the pointconverted to the child's coordinate space, returning any non-NULLresultsC. if the child is hidden, continue to the next iterationD. if the child's frame contains the point, return the childE. if none of the children contain the point, return thisif recursive is false:A. start at the \*bottom\* child and iterate upward.B. if the child is hidden, continue to the next iterationC. if the child's frame contains the point, return the childD. if none of the children contain the point, return thisPortLink \*GetLink(void)------------------------Returns the layer's internal PortLink object so a message can be sentto the Layer's window.