Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- KUIWidget := Object clone do (
- /* parent & children here are used only for layout */
- parent := nil
- children := List clone
- bbox := Box clone
- parentcenter := Point clone
- center := Point clone
- offset := Point clone
- zlayer := 0
- img := Image clone
- img size := method(
- return Point clone set(width, height)
- )
- _calculateBbox := method(
- e := try(
- parentBbox := parent bbox
- )
- e catch (
- parentBbox := Box clone set(Point clone, Point clone)
- )
- bboxOrigin := ((parentBbox origin) + ((parentBbox size)*(parentcenter))) + offset
- bboxSize := Point clone set (img width, img height)
- self bbox := Box clone set(bboxOrigin, bboxSize)
- return bbox
- )
- size := method( return bbox size )
- _calculateSize := method ( return size )
- calculateBbox := method(
- _calculateBbox
- children foreach(c, c ?calculateBbox)
- )
- calculateSize := method(
- children foreach(c, c ?calculateSize)
- _calculateSize
- )
- setParent := method(p,
- self parent := p
- p children append(self)
- )
- )
- KUIContainer := KUIWidget clone do (
- widgetLint := method(
- if(self children size < 1,
- self children foreach(c,
- if(c zlayer <= self zlayer, c zlayer := (self zlayer + 1))
- )
- self children foreach(c, c ?widgetLint)
- self children foreach(c,
- self bbox := self bbox Union(c bbox)
- )
- )
- return bbox
- )
- _calculateBbox := method(
- resend
- widgetLint
- return bbox
- )
- )
- x := KUIWidget clone
- x offset set(10, 20)
- y := KUIContainer clone
- y setParent(x)
- y offset set(10, 20)
- "Initial bbox for" println
- "X:" println
- x bbox println
- "Y:" println
- y bbox println
- "Recalculating..." println
- x calculateBbox
- "New bbox for" println
- "X:" println
- x bbox println
- "Y:" println
- y bbox println
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement