Przeglądaj źródła

changed math32.color and math32.color4 api

leonsal 8 lat temu
rodzic
commit
5b7a3d1e6c
7 zmienionych plików z 58 dodań i 61 usunięć
  1. 1 1
      graphic/skybox.go
  2. 2 2
      gui/builder.go
  3. 1 10
      gui/label.go
  4. 1 1
      loader/collada/scene.go
  5. 30 35
      math32/color.go
  6. 21 10
      math32/color4.go
  7. 2 2
      text/font.go

+ 1 - 1
graphic/skybox.go

@@ -39,7 +39,7 @@ func NewSkybox(data SkyboxData) (*Skybox, error) {
 		if err != nil {
 			return nil, err
 		}
-		matFace := material.NewStandard(math32.NewColor(1, 1, 1))
+		matFace := material.NewStandard(math32.NewColor("white"))
 		matFace.AddTexture(tex)
 		matFace.SetSide(material.SideBack)
 		matFace.SetUseLights(material.UseLightAmbient)

+ 2 - 2
gui/builder.go

@@ -1249,10 +1249,10 @@ func (b *Builder) parseColor(fname, field string) (*math32.Color4, error) {
 	parts := strings.Fields(field)
 	if len(parts) == 1 || len(parts) == 2 {
 		// First part must be a color name
-		if !math32.IsColor(parts[0]) {
+		c, ok := math32.IsColorName(parts[0])
+		if !ok {
 			return nil, b.err(fname, fmt.Sprintf("Invalid color name:%s", parts[0]))
 		}
-		c := math32.ColorName(parts[0])
 		c4 := math32.Color4{c.R, c.G, c.B, 1}
 		if len(parts) == 2 {
 			val, err := strconv.ParseFloat(parts[1], 32)

+ 1 - 10
gui/label.go

@@ -39,15 +39,6 @@ func NewLabel(msg string, icon ...bool) *Label {
 	return l
 }
 
-//// NewIconLabel creates and returns a label panel using the specified text
-//// drawn using the default icon font.
-//func NewIconLabel(msg string) *Label {
-//
-//	l := new(Label)
-//	l.initialize(msg, StyleDefault().FontIcon)
-//	return l
-//}
-
 // initialize initializes this label and is normally used by other
 // gui types which contains a label.
 func (l *Label) initialize(msg string, font *text.Font) {
@@ -58,7 +49,7 @@ func (l *Label) initialize(msg string, font *text.Font) {
 	l.fontDPI = 72
 	l.lineSpacing = 1.0
 	l.bgColor = math32.Color4{0, 0, 0, 0}
-	l.fgColor = math32.Black4
+	l.fgColor = math32.Color4{0, 0, 0, 1}
 	l.SetText(msg)
 }
 

+ 1 - 1
loader/collada/scene.go

@@ -87,7 +87,7 @@ func (d *Decoder) newNode(cnode *Node) (core.INode, error) {
 			node = mesh
 
 		case gls.POINTS:
-			mat := material.NewPoint(math32.NewColor(0, 0, 0))
+			mat := material.NewPoint(&math32.Color{})
 			mat.SetSize(1000)
 			node = graphic.NewPoints(geomi, mat)
 

+ 30 - 35
math32/color.go

@@ -1,29 +1,37 @@
 // Copyright 2016 The G3N Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
-
 package math32
 
-import ()
+import (
+	"strings"
+)
 
+// Type color describes an RGB color
 type Color struct {
 	R float32
 	G float32
 	B float32
 }
 
-var Black = Color{0, 0, 0}
-var White = Color{1, 1, 1}
-var Red = Color{1, 0, 0}
-var Green = Color{0, 1, 0}
-var Blue = Color{0, 0, 1}
-var Gray = Color{0.5, 0.5, 0.5}
+// New creates and returns a pointer to a new Color
+// with the specified web standard color name (case insensitive).
+// Returns nil if the color name not found
+func NewColor(name string) *Color {
+
+	c, ok := mapColorNames[strings.ToLower(name)]
+	if !ok {
+		return nil
+	}
+	return &c
+}
 
-// NewColor creates and returns a pointer to a new color
-// with the specified RGB components
-func NewColor(r, g, b float32) *Color {
+// Name returns a Color with the specified standard web color
+// name (case insensitive).
+// Returns black color if the specified color name not found
+func ColorName(name string) Color {
 
-	return &Color{R: r, G: g, B: b}
+	return mapColorNames[strings.ToLower(name)]
 }
 
 // NewColorHex creates and returns a pointer to a new color
@@ -56,7 +64,10 @@ func (c *Color) SetHex(value uint) *Color {
 // specified standard web color name
 func (c *Color) SetName(name string) *Color {
 
-	*c = colorNames[name]
+	color, ok := mapColorNames[strings.ToLower(name)]
+	if ok {
+		*c = color
+	}
 	return c
 }
 
@@ -113,31 +124,15 @@ func (c *Color) Equals(other *Color) bool {
 	return (c.R == other.R) && (c.G == other.G) && (c.B == other.B)
 }
 
-// IsColor returns true if the specified name is a standard web color name
-func IsColor(name string) bool {
-
-	_, ok := colorNames[name]
-	return ok
-
-}
-
-// ColorName returns a Color with the specified standard web color name.
-func ColorName(name string) Color {
-
-	return colorNames[name]
-}
-
-// Color4Name returns a Color4 with the specified standard web color name
-// and specified alpha channel.
-func Color4Name(name string, alpha float32) Color4 {
+func IsColorName(name string) (Color, bool) {
 
-	c := colorNames[name]
-	return Color4{c.R, c.G, c.B, alpha}
+	c, ok := mapColorNames[strings.ToLower(name)]
+	return c, ok
 }
 
-// colorNames maps standard web color names to a Vector3 with
-// the color's RGB component values
-var colorNames = map[string]Color{
+// mapColorNames maps standard web color names to a Color with
+// the standard web color's RGB component values
+var mapColorNames = map[string]Color{
 	"aliceblue":            Color{0.941, 0.973, 1.000},
 	"antiquewhite":         Color{0.980, 0.922, 0.843},
 	"aqua":                 Color{0.000, 1.000, 1.000},

+ 21 - 10
math32/color4.go

@@ -1,11 +1,13 @@
 // Copyright 2016 The G3N Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
-
 package math32
 
-import ()
+import (
+	"strings"
+)
 
+// Type Color4 describes an RGBA color
 type Color4 struct {
 	R float32
 	G float32
@@ -13,16 +15,25 @@ type Color4 struct {
 	A float32
 }
 
-var Black4 = Color4{0, 0, 0, 1}
-var White4 = Color4{1, 1, 1, 1}
-var Red4 = Color4{1, 0, 0, 1}
-var Green4 = Color4{0, 1, 0, 1}
-var Blue4 = Color4{0, 0, 1, 1}
-var Gray4 = Color4{0.5, 0.5, 0.5, 1}
+// NewColor4 creates and returns a pointer to a new Color4
+// with the specified standard web color name (case insensitive)
+// and specified alpha channel value.
+// Returns nil if the specified color name not found
+func NewColor4(name string, alpha float32) *Color4 {
+
+	c, ok := mapColorNames[strings.ToLower(name)]
+	if !ok {
+		return nil
+	}
+	return &Color4{c.R, c.G, c.B, alpha}
+}
 
-func NewColor4(r, g, b, a float32) *Color4 {
+// Color4Name returns a Color4 with the specified standard web color name
+// and specified alpha channel.
+func Color4Name(name string, alpha float32) Color4 {
 
-	return &Color4{R: r, G: g, B: b, A: a}
+	c := mapColorNames[name]
+	return Color4{c.R, c.G, c.B, alpha}
 }
 
 // Set sets this color individual R,G,B,A components

+ 2 - 2
text/font.go

@@ -65,8 +65,8 @@ func NewFontFromData(fontData []byte) (*Font, error) {
 	f.fontDPI = 72
 	f.lineSpacing = 1.0
 	f.hinting = font.HintingNone
-	f.SetFgColor4(math32.NewColor4(0, 0, 0, 1))
-	f.SetBgColor4(math32.NewColor4(1, 1, 1, 0))
+	f.SetFgColor4(&math32.Color4{0, 0, 0, 1})
+	f.SetBgColor4(&math32.Color4{1, 1, 1, 0})
 	f.changed = false
 
 	// Creates font face