Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
IO 2.39 KB | None | 0 0
  1. KUIWidget := Object clone do (
  2.         /* parent & children here are used only for layout */
  3.         parent := nil
  4.         children := List clone
  5.  
  6.         bbox := Box clone
  7.         parentcenter := Point clone
  8.         center := Point clone
  9.         offset := Point clone
  10.  
  11.         zlayer := 0
  12.  
  13.         img := Image clone
  14.         img size := method(
  15.                 return Point clone set(width, height)
  16.         )
  17.         _calculateBbox := method(
  18.                 e := try(
  19.                         parentBbox := parent bbox
  20.                 )
  21.                 e catch (
  22.                         parentBbox := Box clone set(Point clone, Point clone)
  23.                 )
  24.                 bboxOrigin := ((parentBbox origin) + ((parentBbox size)*(parentcenter))) + offset
  25.                 bboxSize := Point clone set (img width, img height)
  26.                 self bbox := Box clone set(bboxOrigin, bboxSize)
  27.                 return bbox
  28.         )
  29.  
  30.         size := method( return bbox size )
  31.  
  32.         _calculateSize := method ( return size )
  33.  
  34.         calculateBbox := method(
  35.                 _calculateBbox
  36.                 children foreach(c, c ?calculateBbox)
  37.         )
  38.         calculateSize := method(
  39.                 children foreach(c, c ?calculateSize)
  40.                 _calculateSize
  41.         )
  42.         setParent := method(p,
  43.                 self parent := p
  44.                 p children append(self)
  45.         )
  46. )
  47. KUIContainer := KUIWidget clone do (
  48.         widgetLint := method(
  49.                 if(self children size < 1,
  50.                         self children foreach(c,
  51.                                 if(c zlayer <= self zlayer, c zlayer := (self zlayer + 1))
  52.                         )
  53.                         self children foreach(c, c ?widgetLint)
  54.                         self children foreach(c,
  55.                                 self bbox := self bbox Union(c bbox)
  56.                         )
  57.                 )
  58.                 return bbox
  59.         )
  60.         _calculateBbox := method(
  61.                 resend
  62.                 widgetLint
  63.                 return bbox
  64.         )
  65. )
  66. x := KUIWidget clone
  67. x offset set(10, 20)
  68. y := KUIContainer clone
  69. y setParent(x)
  70. y offset set(10, 20)
  71.  
  72. "Initial bbox for" println
  73. "X:" println
  74. x bbox println
  75. "Y:" println
  76. y bbox println
  77. "Recalculating..." println
  78. x calculateBbox
  79. "New bbox for" println
  80. "X:" println
  81. x bbox println
  82. "Y:" println
  83. y bbox println
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement