Esempio n. 1
0
        public static int Main(string[] args)
        {
            if (args.Length < 1)
            {
                var cmdName = Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location);
                Console.Error.WriteLine("{0} render config.json output.png", cmdName);
                Console.Error.WriteLine("{0} genconfig config.json", cmdName);
                return(1);
            }

            switch (args[0].ToLower())
            {
            case "render":
            {
                var config = JsonConvert.DeserializeObject <Configuration.Scene>(File.ReadAllText(args[1]));
                var scene  = Rendering.Layouter.Layout(config);
                Rendering.ImageRender.Render(args[2], scene);

                return(0);
            }

            case "genconfig":
            {
                var config = new Configuration.Scene
                {
                    TimeAxis    = new Configuration.TimeAxis(),
                    EventGroups = new List <Configuration.EventGroup>
                    {
                        new Configuration.EventGroup
                        {
                            Events = new List <Configuration.Event>
                            {
                                new Configuration.Event()
                            }
                        }
                    },
                    PixelsPerUnit = 1
                };

                File.WriteAllText(args[1], JsonConvert.SerializeObject(config));

                return(0);
            }

            default:
                throw new NotSupportedException("Unkown command :" + args[0]);
            }
        }
Esempio n. 2
0
        public static Scene Layout(Configuration.Scene config)
        {
            var scene = new Scene
            {
                X     = 0,
                Y     = 0,
                Width = (int)((config.TimeAxis.End - config.TimeAxis.Start) * config.PixelsPerUnit) + 2 * Style.kOuterBorder
            };

            scene.TimeAxis = new TimeAxis
            {
                X               = Style.kOuterBorder,
                Y               = Style.kOuterBorder,
                Width           = scene.Width - 2 * Style.kOuterBorder,
                Start           = config.TimeAxis.Start,
                End             = config.TimeAxis.End,
                AnchorAlignment = config.TimeAxis.AnchorAlignment
            };


            var y = Style.kOuterBorder + Style.kTimelineHeight;

            scene.EventGroups = new List <EventGroup>();
            foreach (var group in config.EventGroups.Where(g => g.Visible))
            {
                y += Style.kEventGroupGap;

                scene.EventGroups.Add(Layout(
                                          group,
                                          Style.kOuterBorder,
                                          y,
                                          scene.Width - 2 * Style.kOuterBorder,
                                          config.TimeAxis.Start, config.TimeAxis.End));

                y += scene.EventGroups.Last().Height;
            }

            scene.TimeAxis.Height = y + Style.kEventGroupGap + Style.kTimelineHeight - Style.kOuterBorder;

            scene.Height = scene.TimeAxis.Height + 2 * Style.kOuterBorder;

            return(scene);
        }