The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Layer.vala in libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of libbirdfont/Layer.vala.
Layer boundaries
1 /* 2 Copyright (C) 2015 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 namespace BirdFont { 16 17 public class Layer : GLib.Object { 18 public PathList paths; 19 public Gee.ArrayList<Layer> subgroups; 20 public bool visible = true; 21 public string name = "Layer"; 22 public bool is_counter = false; 23 24 public Layer () { 25 paths = new PathList (); 26 subgroups = new Gee.ArrayList<Layer> (); 27 } 28 29 public PathList get_all_paths () { 30 PathList p = new PathList (); 31 32 p.append (paths); 33 34 foreach (Layer sublayer in subgroups) { 35 p.append (sublayer.get_all_paths ()); 36 } 37 38 return p; 39 } 40 41 public PathList get_visible_paths () { 42 PathList p = new PathList (); 43 44 p.append (paths); 45 46 foreach (Layer sublayer in subgroups) { 47 if (sublayer.visible) { 48 p.append (sublayer.get_all_paths ()); 49 } 50 } 51 52 return p; 53 } 54 55 public void add_layer (Layer layer) { 56 subgroups.add (layer); 57 } 58 59 public void add_path (Path path) { 60 paths.add (path); 61 } 62 63 public void remove_path (Path path) { 64 paths.remove (path); 65 foreach (Layer sublayer in subgroups) { 66 sublayer.remove_path (path); 67 } 68 } 69 70 public void remove_layer (Layer layer) { 71 subgroups.remove (layer); 72 foreach (Layer sublayer in subgroups) { 73 sublayer.remove_layer (layer); 74 } 75 } 76 77 public Layer copy () { 78 Layer layer = new Layer (); 79 80 layer.name = name; 81 layer.paths = paths.copy (); 82 foreach (Layer l in subgroups) { 83 layer.subgroups.add (l.copy ()); 84 } 85 86 return layer; 87 } 88 89 public void print (int indent = 0) { 90 foreach (Path p in paths.paths) { 91 for (int i = 0; i < indent; i++) { 92 stdout.printf ("\t"); 93 } 94 stdout.printf (@"Path open: $(p.is_open ())"); 95 96 if (p.color != null) { 97 stdout.printf (" %s", ((!) p.color).to_rgb_hex ()); 98 } 99 100 stdout.printf ("\n"); 101 } 102 103 foreach (Layer l in subgroups) { 104 for (int i = 0; i < indent; i++) { 105 stdout.printf ("\t"); 106 } 107 stdout.printf ("%s\n", l.name); 108 l.print (indent + 1); 109 } 110 } 111 } 112 113 } 114