소스 검색

panel z coordinate calc

leonsal 8 년 전
부모
커밋
ec518dc573
4개의 변경된 파일33개의 추가작업 그리고 12개의 파일을 삭제
  1. 1 0
      gui/folder.go
  2. 1 0
      gui/list.go
  3. 29 10
      gui/panel.go
  4. 2 2
      gui/root.go

+ 1 - 0
gui/folder.go

@@ -110,6 +110,7 @@ func (f *Folder) onMouse(evname string, ev interface{}) {
 		cont := f.contentPanel.GetPanel()
 		if !cont.Visible() {
 			cont.SetVisible(true)
+			log.Error("Folder PanelZ:%6.5f", cont.Position().Z)
 		} else {
 			cont.SetVisible(false)
 		}

+ 1 - 0
gui/list.go

@@ -363,6 +363,7 @@ func (li *List) highlighted() (pos int) {
 // onMouseEvent receives subscribed mouse events for the list
 func (li *List) onMouseEvent(evname string, ev interface{}) {
 
+	log.Error("List Z:%6.5f", li.Position().Z)
 	li.root.SetKeyFocus(li)
 }
 

+ 29 - 10
gui/panel.go

@@ -68,12 +68,12 @@ type Panel struct {
 	xmax            float32             // maximum absolute x this panel can use
 	ymin            float32             // minimum absolute y this panel can use
 	ymax            float32             // maximum absolute y this panel can use
-	nextChildZ      float32             // Z coordinate of next child added
-	bounded         bool                // panel is bounded by its parent
-	enabled         bool                // enable event processing
-	cursorEnter     bool                // mouse enter dispatched
-	layout          ILayout             // current layout for children
-	layoutParams    interface{}         // current layout parameters used by container panel
+	//nextChildZ      float32             // Z coordinate of next child added
+	bounded      bool        // panel is bounded by its parent
+	enabled      bool        // enable event processing
+	cursorEnter  bool        // mouse enter dispatched
+	layout       ILayout     // current layout for children
+	layoutParams interface{} // current layout parameters used by container panel
 }
 
 const (
@@ -94,7 +94,7 @@ func (p *Panel) Initialize(width, height float32) {
 
 	p.width = width
 	p.height = height
-	p.nextChildZ = deltaZ
+	//p.nextChildZ = deltaZ
 
 	// Builds array with vertex positions and texture coordinates
 	positions := math32.NewArrayF32(0, 20)
@@ -194,7 +194,11 @@ func (p *Panel) Material() *material.Material {
 // child of this one.
 func (p *Panel) SetTopChild(ipan IPanel) {
 
-	ipan.GetPanel().SetPositionZ(p.nextChildZ)
+	// Remove panel and if found appends to the end
+	found := p.Remove(ipan)
+	if found {
+		p.Add(ipan)
+	}
 }
 
 // SetTopChild sets this panel to be on the foreground
@@ -476,8 +480,8 @@ func (p *Panel) Add(ichild IPanel) *Panel {
 	p.Node.Add(ichild)
 	node := ichild.GetPanel()
 	node.SetParent(p)
-	node.SetPositionZ(p.nextChildZ)
-	p.nextChildZ += deltaZ
+	//node.SetPositionZ(p.nextChildZ)
+	//p.nextChildZ += deltaZ
 	if p.layout != nil {
 		p.layout.Recalc(p)
 	}
@@ -515,12 +519,16 @@ func (p *Panel) SetBounded(bounded bool) {
 func (p *Panel) UpdateMatrixWorld() {
 
 	par := p.Parent()
+	// Panel has no parent
 	if par == nil {
 		p.updateBounds(nil)
+		p.setZ(0)
+		// Panel has parent
 	} else {
 		par, ok := par.(*Panel)
 		if ok {
 			p.updateBounds(par)
+			// Parent is not a panel
 		} else {
 			p.updateBounds(nil)
 		}
@@ -531,6 +539,17 @@ func (p *Panel) UpdateMatrixWorld() {
 	}
 }
 
+func (p *Panel) setZ(nextZ float32) float32 {
+
+	//log.Error("setZ:%6.5f", nextZ)
+	p.SetPositionZ(nextZ)
+	nextZ += deltaZ
+	for _, ichild := range p.Children() {
+		nextZ = ichild.(IPanel).GetPanel().setZ(nextZ)
+	}
+	return nextZ
+}
+
 // ContainsPosition returns indication if this panel contains
 // the specified screen position in pixels.
 func (p *Panel) ContainsPosition(x, y float32) bool {

+ 2 - 2
gui/root.go

@@ -348,7 +348,7 @@ func (p listPanelZ) Len() int      { return len(p) }
 func (p listPanelZ) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
 func (p listPanelZ) Less(i, j int) bool {
 
-	iz := p[i].GetPanel().pospix.Z
-	jz := p[j].GetPanel().pospix.Z
+	iz := p[i].GetPanel().Position().Z
+	jz := p[j].GetPanel().Position().Z
 	return iz < jz
 }