Migrated colors to a subpackage

This commit is contained in:
Unknown
2018-05-04 14:31:15 -04:00
parent 0d8be61858
commit 0901c689b1
3 changed files with 31 additions and 33 deletions

View File

@@ -4,13 +4,6 @@ import (
"fmt"
)
// Colors enumerates some basic, commonly used colors.
var Colors map[string]Color = map[string]Color{
"Black": &RGB{0, 0, 0},
"Gray": &RGB{128, 128, 128},
"White": &RGB{255, 255, 255},
}
// ModeEnum determines how aggressively the package will attempt to sync with Photoshop.
// Loading Photoshop files from scratch takes a long time, so the package saves
// the state of the document in a JSON file in the /data folder whenever you call
@@ -42,12 +35,8 @@ func (p *PSSaveOptions) String() string {
return fmt.Sprint("", *p)
}
// PSSaveChanges saves changes before closing documents.
const PSSaveChanges PSSaveOptions = 1
// PSDoNotSaveChanges closes documents without saving.
const PSDoNotSaveChanges PSSaveOptions = 2
// PSPromptToSaveChanges prompts the user whether to save each
// document before closing it.
const PSPromptToSaveChanges PSSaveOptions = 3
const (
PSSaveChanges PSSaveOptions = iota + 1 // Saves changes before closing documents.
PSDoNotSaveChanges // Closes documents without saving.
PSPromptToSaveChanges // Prompts whether to save before closing.
)

View File

@@ -1,10 +1,22 @@
package ps
package colors
import (
"encoding/hex"
// "fmt"
)
func Black() Color {
return &RGB{0, 0, 0}
}
func Gray() Color {
return &RGB{128, 128, 128}
}
func White() Color {
return &RGB{255, 255, 255}
}
// Color is an interface for color objects, allowing colors to be
// used in various formats.
//
@@ -66,7 +78,3 @@ type Stroke struct {
Size float32
Color
}
// func (s *Stroke) String() string {
// return fmt.Sprintf("%vpt %v", s.Size, s.Color.RGB())
// }

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/sbrow/ps/colors"
"io/ioutil"
"log"
"os"
@@ -188,8 +189,8 @@ type ArtLayer struct {
parent Group // The LayerSet/Document this layer is in.
visible bool // Whether or not the layer is visible.
current bool // Whether we've checked this layer since we loaded from disk.
Color // The layer's color overlay effect (if any).
*Stroke // The layer's stroke effect (if any).
colors.Color // The layer's color overlay effect (if any).
*colors.Stroke // The layer's stroke effect (if any).
*TextItem // The layer's text, if it's a text layer.
}
@@ -232,8 +233,8 @@ func (a *ArtLayer) UnmarshalJSON(b []byte) error {
}
a.name = tmp.Name
a.bounds = tmp.Bounds
a.Color = RGB{tmp.Color[0], tmp.Color[1], tmp.Color[2]}
a.Stroke = &Stroke{tmp.StrokeAmt, RGB{tmp.Stroke[0], tmp.Stroke[1], tmp.Stroke[2]}}
a.Color = colors.RGB{tmp.Color[0], tmp.Color[1], tmp.Color[2]}
a.Stroke = &colors.Stroke{tmp.StrokeAmt, colors.RGB{tmp.Stroke[0], tmp.Stroke[1], tmp.Stroke[2]}}
a.visible = tmp.Visible
a.current = false
a.TextItem = tmp.TextItem
@@ -284,7 +285,7 @@ func (a *ArtLayer) SetActive() ([]byte, error) {
}
// SetColor creates a color overlay for the layer
func (a *ArtLayer) SetColor(c Color) {
func (a *ArtLayer) SetColor(c colors.Color) {
if a.Color.RGB() == c.RGB() {
if Mode == 2 || (Mode == 0 && a.current) {
// log.Println("Skipping color: already set.")
@@ -318,7 +319,7 @@ func (a *ArtLayer) SetColor(c Color) {
}
}
func (a *ArtLayer) SetStroke(stk Stroke, fill Color) {
func (a *ArtLayer) SetStroke(stk colors.Stroke, fill colors.Color) {
if stk.Size == 0 {
a.Stroke = &stk
a.SetColor(fill)