Пример #1
0
        public LayoutRenderer(TrackerLayoutFile trackerDefinition, string layoutName)
        {
            this.trackerDefinition = trackerDefinition;
            this.layoutName        = layoutName;
            this.layout            = trackerDefinition.layouts[layoutName];

            backgrounds = new Bitmap[layout.backgrounds.Length];
            for (var i = 0; i < layout.backgrounds.Length; i++)
            {
                var bgPath = layout.backgrounds[i];
                backgrounds[i] = trackerDefinition.Meta.GetImage(bgPath);
            }

            if (backgrounds.Length == 0)
            {
                throw new TrackerFileException("Layout " + layoutName + " has no background.");
            }
            width  = backgrounds[0].Width;
            height = backgrounds[0].Height;

            foreach (var placement in layout.maps)
            {
                maps.Add(new MapRenderer(this, placement));
            }

            renderer = new Renderer(width, height);
            RenderInitial();

            trackerDefinition.Meta.State.AddListener(this);
        }
Пример #2
0
        private void InitializeTracker()
        {
            bool isEmpty     = _layout == null;
            bool willBeEmpty = false;

            if (_layoutFile == null || _layoutName == null)
            {
                willBeEmpty = true;
            }
            else
            {
                TrackerLayout l;
                if (!_layoutFile.layouts.TryGetValue(_layoutName, out l))
                {
                    willBeEmpty = true;
                }
            }

            if (!isEmpty && willBeEmpty)
            {
                UninitializeTracker();
            }
            else if (!willBeEmpty)
            {
                // ACTUALLY INITIALIZE
                FreeLayoutResources();

                _layout = _layoutFile.layouts[_layoutName];
                if (cachedViews.ContainsKey(_layoutName))
                {
                    _renderer = cachedViews[_layoutName];
                    _renderer.Update(); // Todo: determine if cached views should update in realtime, or if not, they should at least to allow redundant invalidations
                }
                else
                {
                    _renderer = new LayoutRenderer(_layoutFile, _layoutName);
                    if (CacheViews && !cachedViews.ContainsKey(_layoutName))
                    {
                        cachedViews.Add(_layoutName, _renderer);
                    }
                }
                foreach (var placement in _layout.maps)
                {
                    var       mmap   = _layoutFile.GetEffectiveMetrics(placement);
                    Rectangle bounds = new Rectangle(
                        mmap.x,
                        mmap.y,
                        mmap.cellWidth * mmap.gridWidth,
                        mmap.cellHeight * mmap.gridHeight
                        );
                    mapBounds.Add(Tuple.Create(mmap, bounds));
                }

                SetupPicker();
                Invalidate(new Rectangle(0, 0, _renderer.Width, _renderer.Height));
            }
        }
Пример #3
0
        private void ApplyLayoutExternalMetrics(TrackerLayout layout)
        {
            var backcolor = layout.GetBackcolor();

            if (backcolor != null)
            {
                //this.BackColor =
            }
        }
Пример #4
0
 private void FreeLayoutResources()
 {
     // Todo: clear any layout-specific values and free any resources
     if (_renderer != null && (_unloadingLayoutName != null && !cachedViews.ContainsKey(_unloadingLayoutName)))
     {
         _renderer.Dispose();
     }
     _renderer = null;
     _layout   = null;
     mapBounds.Clear();
 }