コード例 #1
0
ファイル: TestBrush.cs プロジェクト: sw0817/open-brush
        /// Returns strokes read from the passed .tilt file
        public static List <Stroke> GetStrokesFromTilt(string path)
        {
            var            file = new DiskSceneFileInfo(path, readOnly: true);
            SketchMetadata metadata;

            using (var jsonReader = new JsonTextReader(
                       new StreamReader(
                           SaveLoadScript.GetMetadataReadStream(file))))
            {
                // TODO: should cache this?
                var serializer = new JsonSerializer();
                serializer.ContractResolver = new CustomJsonContractResolver();
                serializer.Error           += (sender, args) =>
                {
                    throw new Exception(args.ErrorContext.Error.Message);
                };
                metadata = serializer.Deserialize <SketchMetadata>(jsonReader);
            }

            using (var stream = file.GetReadStream(TiltFile.FN_SKETCH))
            {
                var bufferedStream = new BufferedStream(stream, 4096);
                return(SketchWriter.GetStrokes(
                           bufferedStream, metadata.BrushIndex, BitConverter.IsLittleEndian));
            }
        }
コード例 #2
0
ファイル: FileSketchSet.cs プロジェクト: mikeage/open-brush
        public void Update()
        {
            // process async directory changes from file system watcher
            // note: code here assumes we're the only consumer
            bool changedEvent = false;

            while (m_ToDelete.Count > 0)
            {
                string path = (string)m_ToDelete.Dequeue();
                if (RemoveSketchByPath(path))
                {
                    changedEvent = true;
                }
            }
            // be nice and only add one sketch per frame, since we're validating header
            if (m_ToAdd.Count > 0)
            {
                string path     = (string)m_ToAdd.Dequeue();
                var    fileInfo = new DiskSceneFileInfo(path);
                if (fileInfo.IsHeaderValid())
                {
                    AddSketchToSet(fileInfo);
                    m_Sketches.Sort();
                    changedEvent = true;
                }
            }
            if (changedEvent)
            {
                OnChanged();
            }

            // Grab a few units of work
            var working = Update__working; // = new Stack<int>();

            Debug.Assert(working.Count == 0);
            for (int i = 0; i < ICON_LOAD_PER_FRAME && m_RequestedLoads.Count > 0; ++i)
            {
                working.Push(m_RequestedLoads.Pop());
            }

            // Process work (perhaps generating future work)
            while (working.Count > 0)
            {
                int iSketch = working.Pop();
                if (!m_Sketches[iSketch].RequestLoadIconAndMetadata())
                {
                    m_RequestedLoads.Push(iSketch);
                }
            }
        }
コード例 #3
0
ファイル: FileSketchSet.cs プロジェクト: mikeage/open-brush
 public FileSketch(DiskSceneFileInfo info)
 {
     m_FileInfo       = info;
     m_bMetadataValid = false;
 }
コード例 #4
0
ファイル: FileSketchSet.cs プロジェクト: mikeage/open-brush
 protected void AddSketchToSet(DiskSceneFileInfo rInfo)
 {
     m_Sketches.Add(new FileSketch(rInfo));
 }