diff --git a/Variables.go b/Variables.go index 567eb48..dfbb64b 100644 --- a/Variables.go +++ b/Variables.go @@ -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. +) diff --git a/colors.go b/colors/colors.go similarity index 89% rename from colors.go rename to colors/colors.go index 5d43d1d..acc7dd3 100644 --- a/colors.go +++ b/colors/colors.go @@ -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()) -// } diff --git a/structs.go b/structs.go index e9f2db8..59ee5c8 100644 --- a/structs.go +++ b/structs.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/sbrow/ps/colors" "io/ioutil" "log" "os" @@ -183,14 +184,14 @@ func (d *Document) Dump() { // // TODO: (2) Make TextLayer a subclass of ArtLayer. type ArtLayer struct { - name string // The layer's name. - bounds [2][2]int // The corners of the layer's bounding box. - 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). - *TextItem // The layer's text, if it's a text layer. + name string // The layer's name. + bounds [2][2]int // The corners of the layer's bounding box. + 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. + 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. } // Bounds returns the coordinates of the corners of the ArtLayer's bounding box. @@ -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)