Layer class¶
The Layer class is responsible for working with invalid regions and serves as the shadow class for BViews.
Member Functions¶
Layer(BRect frame, const char *name, int32 resize, int32 flags, ServerWindow *win)¶
acquire a new layer token
validate (and fix, if necessary) parameters and assign to member objects
initalize relation pointers to NULL
set level to -1
set invalid region to NULL
set full and visible regions to bounds
set child count to 0
get ServerWindow’s window port and create a PortLink pointed at it
~Layer(void)¶
if parent is non-NULL, call RemoveSelf()
if topchild is non-NULL, iterate through children and delete them.
delete invalid, full, and visible regions if non-NULL
delete the internal PortLink
void AddChild(Layer *child, Layer *before=NULL, bool rebuild=true)¶
Function which corresponds to BView::AddChild
if child->parent is non-NULL, spew an error to stderr and return
set child->parent to this
if before == NULL:
if topchild is non-NULL, set child->uppersibling to child
set child->lowersibling to topchild
if topchild is NULL, set bottomchild to child
set topchild to child
if before != NULL:
if before->upper is non-NULL, set child->upper to before->upper
set before->upper to child
set child->lower to before
if child->upper is non-NULL, set child->upper->lower to child
increment child’s level
increment the child count
if rebuild flag is true, call RebuildRegions
RemoveChild(Layer *child, bool rebuild=true)¶
Function which corresponds to BView::RemoveChild
if child’s parent != this, spew an error to stderr and return
set child’s parent to NULL
set child’s level to -1
if top child matches child, set top child to child’s lower sibling
if bottom child matches child, set bottom child to child’s upper sibilng
if child->uppersibling is non-NULL, set its lowersibling to the child’s lowersibling
if child->lowersibling is non-NULL, set its uppersibling to the child’s uppersibling
decrement child count
call RebuildRegions
void RemoveSelf(bool rebuild=true)¶
Function which corresponds to BView::RemoveSelf
if parent is NULL, spew an error to stderr and return
call parent->RemoveChild(this)
void Invalidate(BRect r)¶
void Invalidate(BRegion *region)¶
Marks the area passed to the function as needing to be redrawn
if parent is NULL, return
if the passed area intersects the layer’s frame, add it to the invalid region, creating a new invalid object if necessary.
Iterate through all child layers, calling child->Invalidate() on the area converted from the parent
BRect 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 specified amount
offset the frame by the specified amount
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 as appropriate.
resize the frame by the specified amount
iterate through all children, checking the resize flags to see whether each should be resized and calling child->ResizeBy() by the appropriate 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. Instructions are written in Yiddish.
bool IsDirty(void)¶
Returns true if the layer needs redrawn (if invalid region is non-NULL).
BRect ConvertToTop(const BRect &r), BRegion ConvertToTop(const BRegion &r)¶
Converts the given data to the coordinates of the root layer in the layer tree.
if parent is non-NULL, return the data.
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 the layer tree.
if parent is non-NULL, return the layer’s frame
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 layer
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 layer
operates exactly like ConvertToParent, except that the offset values are multiplied by -1
void 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 layer is made or when a layer is hidden or shown.
get the frame
set full and visible regions to frame
iterate through each child and exclude its full region from the visible region if the child is visible.
iterate through each lowersibling and exclude its full region from the visible region if the it is visible and it intersects the layer’s frame.
void MakeTopChild(void)¶
Makes the layer the top child owned by its parent. Note that the top child is “behind” other children on the screen.
if parent is NULL, spew an error to stderr and return
if parent’s top child equals this, return without doing anything
if lowersibling and uppersibling are both NULL, return without doing anything
save pointer to parent layer to a temporary variable
call RemoveSelf and then the former parent’s AddChild
void MakeBottomChild(void)¶
Makes the layer the bottom child owned by its parent. Note that the top child is “in front of” other children on the screen.
if parent is NULL, spew an error to stderr and return
if parent’s bottom child equals this, return without doing anything
if lowersibling and uppersibling are both NULL, return without doing anything
save pointer to parent layer to a temporary variable
call RemoveSelf() with rebuild set to false
call former parent’s AddChild (rebuild is false), setting the before parameter to the former parent’s bottomchild
save lowersibling to a temporary variable
call lowersibling->RemoveSelf() with no rebuild
call the parent’s AddChild() with the before set to this and rebuild set to true
void RequestDraw(const BRect &r)¶
Requests that the layer be drawn on screen. The rectangle passed is in the layer’s own coordinates.
if invalid is NULL, return
set the PortLink opcode to B_DRAW
create a BMessage(B_DRAW) and attach all invalid rectangles to it
attach the view token to the message
flatten the message to a buffer, attach it to the PortLink, and Flush() it.
recurse through each child and call its RequestDraw() function if it intersects the child’s frame
Layer *FindLayer(int32 token)¶
Finds a child layer given an identifying token
iterate through children and check tokens. Return a match if found.
iterate through children, calling its FindLayer function, return any non-NULL results
return NULL - we got this far, so there is no match
Layer *GetChildAt(BPoint pt, bool recursive=false)¶
Gets the child at a given point. if recursive is true, all layers under the current one in the tree are searched. if the point is contained by the current layer’s frame and no child is found, this function returns the current layer. if the point is outside the current layer’s frame, it returns NULL
if frame does not contain the point, return NULL
if recursive is true:
start at the *bottom* child and iterate upward.
if the child has children, call the child’s GetChildAt with the point converted to the child’s coordinate space, returning any non-NULL results
if the child is hidden, continue to the next iteration
if the child’s frame contains the point, return the child
if none of the children contain the point, return this
if recursive is false:
start at the *bottom* child and iterate upward.
if the child is hidden, continue to the next iteration
if the child’s frame contains the point, return the child
if none of the children contain the point, return this
PortLink *GetLink(void)¶
Returns the layer’s internal PortLink object so a message can be sent to the Layer’s window.