leonsal 8 vuotta sitten
vanhempi
commit
577fb93143
4 muutettua tiedostoa jossa 69 lisäystä ja 70 poistoa
  1. 3 0
      graphic/graphic.go
  2. 10 9
      gui/chart.go
  3. 21 25
      gui/clipper.go
  4. 35 36
      gui/panel.go

+ 3 - 0
graphic/graphic.go

@@ -43,6 +43,9 @@ type IGraphic interface {
 	RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo)
 }
 
+// NewGraphic creates and returns a pointer to a new graphic object with
+// the specified geometry and OpenGL primitive.
+// The created graphic object, though, has not materials.
 func NewGraphic(igeom geometry.IGeometry, mode uint32) *Graphic {
 
 	gr := new(Graphic)

+ 10 - 9
gui/chart.go

@@ -5,6 +5,7 @@ import (
 	"github.com/g3n/engine/core"
 	"github.com/g3n/engine/geometry"
 	"github.com/g3n/engine/gls"
+	"github.com/g3n/engine/graphic"
 	"github.com/g3n/engine/material"
 	"github.com/g3n/engine/math32"
 	"github.com/g3n/engine/renderer/shader"
@@ -205,7 +206,9 @@ func newChartScaleX(chart *ChartLine, lines int, color *math32.Color) *ChartScal
 	mat.SetShader("shaderChart")
 
 	// Initializes the panel with this graphic
-	sx.Panel.InitializeGraphic(chart.ContentWidth(), chart.ContentHeight(), geom, mat, gls.LINES)
+	gr := graphic.NewGraphic(geom, gls.LINES)
+	gr.AddMaterial(sx, mat, 0, 0)
+	sx.Panel.InitializeGraphic(chart.ContentWidth(), chart.ContentHeight(), gr)
 
 	// Add labels after the panel is initialized
 	for i := 1; i < lines+1; i++ {
@@ -237,15 +240,13 @@ func (sx *ChartScaleX) recalc() {
 // Calculates the model matrix and transfer to OpenGL.
 func (sx *ChartScaleX) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo) {
 
-	log.Error("ChartScaleX RenderSetup")
+	log.Error("ChartScaleX RenderSetup:%p", sx)
 
-	//	// Set this model matrix the same as the chart panel
-	//	var mm math32.Matrix4
-	//	sx.chart.SetModelMatrix(gs, &mm)
-	//
-	//	// Sets and transfer the model matrix uniform
-	//	sx.modelMatrixUni.SetMatrix4(&mm)
-	//	sx.modelMatrixUni.Transfer(gs)
+	// Sets model matrix and transfer to shader
+	var mm math32.Matrix4
+	sx.SetModelMatrix(gs, &mm)
+	sx.modelMatrixUni.SetMatrix4(&mm)
+	sx.modelMatrixUni.Transfer(gs)
 }
 
 //func newChartScaleX(chart *ChartLine, lines int, color *math32.Color) *ChartScaleX {

+ 21 - 25
gui/clipper.go

@@ -6,7 +6,6 @@ package gui
 
 import (
 	"github.com/g3n/engine/core"
-	"github.com/g3n/engine/geometry"
 	"github.com/g3n/engine/gls"
 	"github.com/g3n/engine/graphic"
 	"github.com/g3n/engine/material"
@@ -15,43 +14,40 @@ import (
 
 // Clipper is a 2D graphic which optionally clips its children inside its boundary
 type Clipper struct {
-	graphic.Graphic                     // Embedded graphic
-	root            *Root               // pointer to root container
-	width           float32             // external width in pixels
-	height          float32             // external height in pixels
-	mat             *material.Material  // panel material
-	modelMatrixUni  gls.UniformMatrix4f // pointer to model matrix uniform
-	pospix          math32.Vector3      // absolute position in pixels
-	xmin            float32             // minimum absolute x this panel can use
-	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
-	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
+	*graphic.Graphic                     // Embedded graphic
+	root             *Root               // pointer to root container
+	width            float32             // external width in pixels
+	height           float32             // external height in pixels
+	mat              *material.Material  // panel material
+	modelMatrixUni   gls.UniformMatrix4f // pointer to model matrix uniform
+	pospix           math32.Vector3      // absolute position in pixels
+	xmin             float32             // minimum absolute x this panel can use
+	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
+	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
 }
 
 // NewClipper creates and returns a pointer to a new clipper with the
 // specified dimensions in pixels
-func NewClipper(width, height float32, geom *geometry.Geometry, mat *material.Material, mode uint32) *Clipper {
+func NewClipper(width, height float32, gr *graphic.Graphic) *Clipper {
 
 	c := new(Clipper)
-	c.Initialize(width, height, geom, mat, mode)
+	c.Initialize(width, height, gr)
 	return c
 }
 
 // Initialize initializes this panel with a different geometry, material and OpenGL primitive
-func (c *Clipper) Initialize(width, height float32, geom *geometry.Geometry, mat *material.Material, mode uint32) {
+func (c *Clipper) Initialize(width, height float32, gr *graphic.Graphic) {
 
+	c.Graphic = gr
 	c.width = width
 	c.height = height
 
-	// Initialize graphic
-	c.Graphic.Init(geom, mode)
-	c.AddMaterial(c, mat, 0, 0)
-
 	// Creates and adds uniform
 	c.modelMatrixUni.Init("ModelMatrix")
 
@@ -73,7 +69,7 @@ func (c *Clipper) RenderSetup(gl *gls.GLS, rinfo *core.RenderInfo) {
 	c.modelMatrixUni.Transfer(gl)
 }
 
-// SetModelMatrix calculates and sets the specified matrix with the model matrix for this panel
+// SetModelMatrix calculates and sets the specified matrix with the model matrix for this clipper
 func (c *Clipper) SetModelMatrix(gl *gls.GLS, mm *math32.Matrix4) {
 
 	// Get the current viewport width and height

+ 35 - 36
gui/panel.go

@@ -46,34 +46,38 @@ type IPanel interface {
 	TotalHeight() float32
 }
 
+// Panel is 2D rectangular graphic which by default has a quad (2 triangles) geometry.
+// When using the default geometry, a panel has margins, borders, paddings
+// and a content area. The content area can be associated wit a texture
+// It is the building block of most GUI widgets.
 type Panel struct {
-	graphic.Graphic                     // Embedded graphic
-	root            *Root               // pointer to root container
-	width           float32             // external width in pixels
-	height          float32             // external height in pixels
-	mat             *material.Material  // panel material
-	marginSizes     BorderSizes         // external margin sizes in pixel coordinates
-	borderSizes     BorderSizes         // border sizes in pixel coordinates
-	paddingSizes    BorderSizes         // padding sizes in pixel coordinates
-	content         Rect                // current content rectangle in pixel coordinates
-	modelMatrixUni  gls.UniformMatrix4f // pointer to model matrix uniform
-	borderColorUni  gls.Uniform4f       // pointer to border color uniform
-	paddingColorUni gls.Uniform4f       // pointer to padding color uniform
-	contentColorUni gls.Uniform4f       // pointer to content color uniform
-	boundsUni       gls.Uniform4f       // pointer to bounds uniform (texture coordinates)
-	borderUni       gls.Uniform4f       // pointer to border uniform (texture coordinates)
-	paddingUni      gls.Uniform4f       // pointer to padding uniform (texture coordinates)
-	contentUni      gls.Uniform4f       // pointer to content uniform (texture coordinates)
-	pospix          math32.Vector3      // absolute position in pixels
-	xmin            float32             // minimum absolute x this panel can use
-	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
-	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
+	*graphic.Graphic                     // Embedded graphic
+	root             *Root               // pointer to root container
+	width            float32             // external width in pixels
+	height           float32             // external height in pixels
+	mat              *material.Material  // panel material
+	marginSizes      BorderSizes         // external margin sizes in pixel coordinates
+	borderSizes      BorderSizes         // border sizes in pixel coordinates
+	paddingSizes     BorderSizes         // padding sizes in pixel coordinates
+	content          Rect                // current content rectangle in pixel coordinates
+	modelMatrixUni   gls.UniformMatrix4f // pointer to model matrix uniform
+	borderColorUni   gls.Uniform4f       // pointer to border color uniform
+	paddingColorUni  gls.Uniform4f       // pointer to padding color uniform
+	contentColorUni  gls.Uniform4f       // pointer to content color uniform
+	boundsUni        gls.Uniform4f       // pointer to bounds uniform (texture coordinates)
+	borderUni        gls.Uniform4f       // pointer to border uniform (texture coordinates)
+	paddingUni       gls.Uniform4f       // pointer to padding uniform (texture coordinates)
+	contentUni       gls.Uniform4f       // pointer to content uniform (texture coordinates)
+	pospix           math32.Vector3      // absolute position in pixels
+	xmin             float32             // minimum absolute x this panel can use
+	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
+	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 (
@@ -81,7 +85,7 @@ const (
 )
 
 // NewPanel creates and returns a pointer to a new panel with the
-// specified dimensions in pixels
+// specified dimensions in pixels and a default quad geometry
 func NewPanel(width, height float32) *Panel {
 
 	p := new(Panel)
@@ -121,7 +125,7 @@ func (p *Panel) Initialize(width, height float32) {
 	p.mat.SetShader("shaderPanel")
 
 	// Initialize graphic
-	p.Graphic.Init(geom, gls.TRIANGLES)
+	p.Graphic = graphic.NewGraphic(geom, gls.TRIANGLES)
 	p.AddMaterial(p, p.mat, 0, 0)
 
 	// Creates and adds uniform
@@ -138,20 +142,16 @@ func (p *Panel) Initialize(width, height float32) {
 	p.borderColorUni.Set(0, 0, 0, 1)
 	p.bounded = true
 	p.enabled = true
-
 	p.resize(width, height)
 }
 
 // InitializeGraphic initializes this panel with a different graphic
-func (p *Panel) InitializeGraphic(width, height float32, geom *geometry.Geometry, mat *material.Material, mode uint32) {
+func (p *Panel) InitializeGraphic(width, height float32, gr *graphic.Graphic) {
 
+	p.Graphic = gr
 	p.width = width
 	p.height = height
 
-	// Initialize graphic
-	p.Graphic.Init(geom, mode)
-	p.AddMaterial(p, mat, 0, 0)
-
 	// Creates and adds uniform
 	p.modelMatrixUni.Init("ModelMatrix")
 	p.borderColorUni.Init("BorderColor")
@@ -166,7 +166,6 @@ func (p *Panel) InitializeGraphic(width, height float32, geom *geometry.Geometry
 	p.borderColorUni.Set(0, 0, 0, 1)
 	p.bounded = true
 	p.enabled = true
-
 	p.resize(width, height)
 }