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"
)
// 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

@@ -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)