Migrated colors to a subpackage

This commit is contained in:
Unknown
2018-05-04 14:31:15 -04:00
parent 0d8be61858
commit 311552c117
2 changed files with 18 additions and 28 deletions

View File

@@ -4,13 +4,6 @@ import (
"fmt" "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. // 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 // 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 // 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) return fmt.Sprint("", *p)
} }
// PSSaveChanges saves changes before closing documents. const (
const PSSaveChanges PSSaveOptions = 1 PSSaveChanges PSSaveOptions = iota + 1 // Saves changes before closing documents.
PSDoNotSaveChanges // Closes documents without saving.
// PSDoNotSaveChanges closes documents without saving. PSPromptToSaveChanges // Prompts whether to save before closing.
const PSDoNotSaveChanges PSSaveOptions = 2 )
// PSPromptToSaveChanges prompts the user whether to save each
// document before closing it.
const PSPromptToSaveChanges PSSaveOptions = 3

View File

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