コード例 #1
0
ファイル: UiSpritePresenter.cs プロジェクト: prepare/Sitana
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            base.Draw(ref parameters);

            Rectangle target = ScreenBounds;
            Rectangle source = Rectangle.Empty;


            source = new Rectangle(0, 0, _spriteInstance.FrameSize.X, _spriteInstance.FrameSize.Y);

            double scaleX = 1;
            double scaleY = 1;

            scaleX = scaleY = Math.Min((double)target.Width / (double)source.Width, (double)target.Height / (double)source.Height);

            Point pos = target.Center;

            int width  = (int)(Math.Ceiling(_spriteInstance.FrameSize.X * scaleX));
            int height = (int)(Math.Ceiling(_spriteInstance.FrameSize.Y * scaleY));

            Rectangle targetRect = new Rectangle(pos.X - width / 2 - width % 2, pos.Y - height / 2 - height % 2, width, height);

            target = GraphicsHelper.IntersectRectangle(targetRect, target);

            PartialTexture2D image = _spriteInstance.FrameImage;

            parameters.DrawBatch.DrawImage(image.Texture, target, image.Source, Color.White);
        }
コード例 #2
0
ファイル: UiLabel.cs プロジェクト: prepare/Sitana
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0 || TextColor.Value.A == 0)
            {
                return;
            }

            base.Draw(ref parameters);

            UiFont font = Font;

            float scale = font.Scale;

            scale *= _rescale;

            Rectangle bounds = ScreenBounds;

            if (Text.Length > 0)
            {
                bounds = _textMargin.ComputeRect(bounds);
            }

            parameters.DrawBatch.DrawText(font.Font, Text, bounds, TextAlign, TextColor.Value * opacity, font.Spacing, (float)_lineHeight / 100.0f, scale, _rotation);
        }
コード例 #3
0
ファイル: UiPage.cs プロジェクト: jacekwicherek/Sitana
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            DrawBackground(ref parameters);

            UiViewDrawParameters drawParams = parameters;

            drawParams.Opacity             = opacity;
            drawParams.Transition          = 1 - DisplayVisibility;
            drawParams.TransitionRectangle = ScreenBounds;

            drawParams.TransitionMode = DisplayVisibility == 1 ? TransitionMode.None : (Visible ? TransitionMode.Show : TransitionMode.Hide);

            if (DisplayVisibility == 1 && !_alreadyFullyVisible)
            {
                _alreadyFullyVisible = true;

                UiTask.BeginInvoke(() => CallDelegate("PageShown"));
            }

            for (int idx = 0; idx < _children.Count; ++idx)
            {
                _children[idx].ViewDraw(ref drawParams);
            }
        }
コード例 #4
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            if (Colors == null)
            {
                base.Draw(ref parameters);
                return;
            }

            float opacity = parameters.Opacity;

            if (opacity == 0 || TextColor.Value.A == 0)
            {
                return;
            }

            float scale = _font.Scale;

            if (_font.Font.SitanaFont == null)
            {
                throw new Exception("Only Sitana fonts support UiColoredLabel.");
            }

            lock (Text)
            {
                lock (Colors)
                {
                    parameters.DrawBatch.DrawText(_font.Font, Text.StringBuilder, ScreenBounds, TextAlign, Colors, opacity, _font.Spacing, (float)_lineHeight / 100.0f, scale);
                }
            }
        }
コード例 #5
0
        public bool Draw(float ellapsedTime)
        {
            if (_drawBatch == null)
            {
                return(false);
            }

            var drawParameters = new UiViewDrawParameters()
            {
                DrawBatch    = _drawBatch,
                Opacity      = 1,
                Transition   = 0,
                EllapsedTime = ellapsedTime
            };

            GraphicsDevice.Clear(MainView.BackgroundColor);

            _drawBatch.Reset();
            MainView.ViewDraw(ref drawParameters);
            _drawBatch.Flush();

            PerformanceProfiler.Instance.Draw(_drawBatch);
            _drawBatch.Flush();

            return(true);
        }
コード例 #6
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0 || TextColor.Value.A == 0)
            {
                return;
            }

            base.Draw(ref parameters);

            if (_fontFace == null)
            {
                _fontFace = FontManager.Instance.FindFont(FontName);
            }

            float         scale;
            UniversalFont font = _fontFace.Find(FontSize, out scale);

            Rectangle bounds = ScreenBounds;

            if (Text.Length > 0)
            {
                bounds = _textMargin.ComputeRect(bounds);
            }

            parameters.DrawBatch.DrawText(font, Text, bounds, TextAlign, TextColor.Value * opacity, (float)FontSpacing / 1000.0f, (float)LineHeight / 100.0f, scale, _rotation);
        }
コード例 #7
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            DrawBackground(ref parameters);

            UiViewDrawParameters drawParams = parameters;

            drawParams.Opacity = opacity;

            if (_clipChildren)
            {
                parameters.DrawBatch.PushClip(ScreenBounds);
            }

            for (int idx = 0; idx < _children.Count; ++idx)
            {
                _children[idx].ViewDraw(ref drawParams);
            }

            if (_clipChildren)
            {
                parameters.DrawBatch.PopClip();
            }
        }
コード例 #8
0
 void DrawCurrentLayer(ref UiViewDrawParameters parameters)
 {
     if (Document.Current.SelectedLayer is DocTiledLayer)
     {
         TiledLayer layer = Document.Current.SelectedLayer.Layer as TiledLayer;
         DrawTiles(ref parameters, layer);
     }
 }
コード例 #9
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            int spacing = _spacing.Compute(_vertical ? Bounds.Width : Bounds.Height);

            Rectangle rect = GetFirstRect();

            int size     = _vertical ? rect.Height : rect.Width;
            int selected = _element.SelectedIndex;

            int count = _element.Count;

            var drawInfo = new DrawButtonInfo();

            drawInfo.Opacity      = opacity;
            drawInfo.EllapsedTime = parameters.EllapsedTime;

            for (int idx = 0; idx < count; ++idx)
            {
                _element.GetText(_text, idx);

                drawInfo.ButtonState = ButtonState.None;
                if (idx == _pushedIndex)
                {
                    drawInfo.ButtonState |= ButtonState.Pushed;
                }

                if (idx == selected)
                {
                    drawInfo.ButtonState |= ButtonState.Checked;
                }

                drawInfo.Text   = _text;
                drawInfo.Target = rect;

                for (int di = 0; di < _drawables.Count; ++di)
                {
                    _drawables[di].DontForceRedraw();
                    _drawables[di].Draw(parameters.DrawBatch, drawInfo);
                }

                if (_vertical)
                {
                    rect.Y += size + spacing;
                }
                else
                {
                    rect.X += size + spacing;
                }
            }
        }
コード例 #10
0
ファイル: UiTilesetView.cs プロジェクト: prepare/Sitana
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            if (_currentTileset != null)
            {
                Rectangle sb = ScreenBounds;

                int   width = _currentTileset.Width / _divideWidth;
                float scale = _scale;

                int ww = (int)(scale * width);

                Point size = new Point((int)ww, (int)(_currentTileset.Height * scale));

                parameters.DrawBatch.DrawRectangle(new Rectangle(sb.X, sb.Y, (int)ww, (int)Math.Ceiling(_currentTileset.Height * scale * _divideWidth)), BackgroundColor);

                SamplerState oldSampler = parameters.DrawBatch.SamplerState;
                parameters.DrawBatch.SamplerState = SamplerState.PointClamp;

                for (int idx = 0; idx < _divideWidth; ++idx)
                {
                    Point target = sb.Location;
                    target.Y += size.Y * idx;

                    Point source = Point.Zero;
                    source.X += (int)width * idx;

                    parameters.DrawBatch.DrawImage(_currentTileset, target, size, source, scale, Color.White * opacity);
                }

                parameters.DrawBatch.SamplerState = oldSampler;

                if (_selection.HasValue)
                {
                    float tileSize = _tileSize;

                    Rectangle selection = sb;

                    selection.X += (int)(_selection.Value.X * tileSize);
                    selection.Y += (int)(_selection.Value.Y * tileSize);

                    selection.Width  = (int)Math.Ceiling((_selection.Value.Width + 1) * tileSize);
                    selection.Height = (int)Math.Ceiling((_selection.Value.Height + 1) * tileSize);

                    parameters.DrawBatch.DrawRectangle(selection, _selectionColor.Value * opacity);
                }
            }
        }
コード例 #11
0
ファイル: UiText.cs プロジェクト: prepare/Sitana
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0 || TextColor.Value.A == 0)
            {
                return;
            }

            base.Draw(ref parameters);

            UniversalFont font;
            float         scale;

            GetFont(out font, out scale);

            Rectangle target = ScreenBounds;
            int       height = (int)(font.Height * LineHeight * scale / 100);
            int       startX = target.X;

            int fullHeight = height * _lines.Count;

            switch (TextAlign & TextAlign.Vert)
            {
            case TextAlign.Middle:
                target.Y = target.Center.Y - fullHeight / 2;
                break;

            case TextAlign.Bottom:
                target.Y = target.Bottom - fullHeight;
                break;
            }

            int indent = _indent.Compute(Bounds.Width);

            for (int idx = 0; idx < _lines.Count; ++idx)
            {
                string line    = _lines[idx].Line;
                float  spacing = _lines[idx].Spacing;

                target.X = startX;

                target.X += _lines[idx].Indent * indent;

                parameters.DrawBatch.DrawText(font, line, target, TextAlign & TextAlign.Horz, TextColor.Value * opacity, spacing, 0, scale);

                target.Y += height;
            }
        }
コード例 #12
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float zoom     = (float)_zoom.Value / 100f;
            int   unitSize = Tools.Tool.UnitToPixels(zoom);

            int startX = CurrentPosition.X / unitSize;
            int startY = CurrentPosition.Y / unitSize;

            Rectangle bounds = ScreenBounds;

            startX = startX * unitSize - CurrentPosition.X + bounds.X;
            startY = startY * unitSize - CurrentPosition.Y + bounds.Y + 1;

            int size = (int)Math.Ceiling(UiUnit.Unit * 3);

            int right  = bounds.Right + size;
            int bottom = bounds.Bottom + size;

            AdvancedDrawBatch batch = parameters.DrawBatch;

            batch.PushClip(bounds);

            Color color = Color.White * 0.25f;

            for (int x = startX; x < right; x += unitSize)
            {
                for (int y = startY; y < bottom; y += unitSize)
                {
                    batch.DrawLine(new Point(x - size, y), new Point(x + size - 1, y), color);
                    batch.DrawLine(new Point(x, y - size), new Point(x, y + size - 1), color);
                }
            }

            DrawCurrentLayer(ref parameters);

            if (MousePosition.HasValue)
            {
                Point pos = CurrentPosition;
                pos.X -= bounds.X;
                pos.Y -= bounds.Y;

                Tools.Tool.Current.Draw(parameters.DrawBatch, pos, MousePosition.Value, zoom);
            }

            batch.PopClip();
        }
コード例 #13
0
ファイル: UiSeparatorLine.cs プロジェクト: prepare/Sitana
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            Texture2D image = _image.Value;
            float     scale = Scale;

            Vector2 textureCoord = Vector2.One;

            Vector2 size = Vector2.Zero;

            Color color = _color.Value * parameters.Opacity;

            if (_vertical)
            {
                size.X = (float)Math.Ceiling(scale * image.Width);
                size.Y = scale * image.Height;

                textureCoord.Y = Bounds.Height / size.Y;
                size.Y         = Bounds.Height;
            }
            else
            {
                size.Y = (float)Math.Ceiling(scale * image.Height);
                size.X = scale * image.Width;

                textureCoord.X = Bounds.Width / size.X;
                size.X         = Bounds.Width;
            }

            Vector2 p1 = new Vector2(ScreenBounds.X, (int)(ScreenBounds.Center.Y - size.Y / 2));
            Vector2 p2 = new Vector2(ScreenBounds.Right, p1.Y + size.Y);

            parameters.DrawBatch.BeginPrimitive(PrimitiveType.TriangleStrip, image);
            SamplerState oldState = parameters.DrawBatch.SamplerState;

            parameters.DrawBatch.SamplerState = SamplerState.LinearWrap;

            parameters.DrawBatch.PushVertex(new Vector2(p1.X, p1.Y), color, new Vector2(0, 0));
            parameters.DrawBatch.PushVertex(new Vector2(p2.X, p1.Y), color, new Vector2(textureCoord.X, 0));
            parameters.DrawBatch.PushVertex(new Vector2(p1.X, p2.Y), color, new Vector2(0, textureCoord.Y));
            parameters.DrawBatch.PushVertex(new Vector2(p2.X, p2.Y), color, new Vector2(textureCoord.X, textureCoord.Y));

            parameters.DrawBatch.Flush();

            parameters.DrawBatch.SamplerState = oldState;
        }
コード例 #14
0
ファイル: UiRectangle.cs プロジェクト: jacekwicherek/Sitana
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            Color color = _color != null ? _color.Value : Color.White;

            float scale = _scaleByUnit ? (float)UiUnit.Unit : 1;

            if (color.A > 0)
            {
                parameters.DrawBatch.DrawNinePatchRect(_image, ScreenBounds, color * opacity, scale * _scale);
            }
        }
コード例 #15
0
ファイル: UiScrollBar.cs プロジェクト: prepare/Sitana
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }
            Rectangle screen = ScreenBounds;
            Rectangle thumb  = ThumbRect;

            if (thumb != screen || _alwaysVisible)
            {
                var batch = parameters.DrawBatch;

                var drawInfo = new DrawButtonInfo();
                drawInfo.Text        = null;
                drawInfo.ButtonState = _touchId != 0 ? ButtonState.Pushed : ButtonState.None;

                if (thumb == screen)
                {
                    drawInfo.ButtonState = ButtonState.Disabled;
                }

                drawInfo.Target       = screen;
                drawInfo.Opacity      = opacity;
                drawInfo.EllapsedTime = parameters.EllapsedTime;

                for (int idx = 0; idx < _trackDrawables.Count; ++idx)
                {
                    var drawable = _trackDrawables[idx];
                    drawable.Draw(batch, drawInfo);
                }

                drawInfo.Target = thumb;

                for (int idx = 0; idx < _thumbDrawables.Count; ++idx)
                {
                    var drawable = _thumbDrawables[idx];
                    drawable.Draw(batch, drawInfo);
                }
            }
        }
コード例 #16
0
        protected override void Draw(ref Parameters.UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            DrawBackground(ref parameters);

            UiViewDrawParameters drawParams = parameters;

            drawParams.Opacity = opacity;

            if (_clipChildren || _expandedValue < 1)
            {
                parameters.DrawBatch.PushClip(ScreenBounds);
            }

            Rectangle bound = new Rectangle(0, 0, Bounds.Width, Bounds.Height);

            for (int idx = 0; idx < _children.Count; ++idx)
            {
                var       child       = _children[idx];
                Rectangle childBounds = child.Bounds;

                if (childBounds.X < bound.Width && childBounds.Y < bound.Height &&
                    childBounds.Right >= 0 && childBounds.Bottom >= 0)
                {
                    child.ViewDraw(ref drawParams);
                }
            }

            if (_clipChildren || _expandedValue < 1)
            {
                parameters.DrawBatch.PopClip();
            }
        }
コード例 #17
0
        protected override void Draw(ref Parameters.UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            DrawBackground(ref parameters);

            UiViewDrawParameters drawParams = parameters;

            drawParams.Opacity             = opacity;
            drawParams.Transition          = 1 - DisplayVisibility;
            drawParams.TransitionRectangle = ScreenBounds;
            drawParams.TransitionMode      = DisplayVisibility == 1 ? TransitionMode.None : (Visible ? TransitionMode.Show : TransitionMode.Hide);

            for (int idx = 0; idx < _children.Count; ++idx)
            {
                _children[idx].ViewDraw(ref drawParams);
            }
        }
コード例 #18
0
ファイル: UiView.cs プロジェクト: jacekwicherek/Sitana
        protected void DrawBackground(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            Color backgroundColor = BackgroundColor * opacity;

            if (backgroundColor.A > 0)
            {
                if (BackgroundDrawable != null)
                {
                    BackgroundDrawable.Draw(parameters.DrawBatch, ScreenBounds, backgroundColor);
                }
                else
                {
                    parameters.DrawBatch.DrawRectangle(ScreenBounds, backgroundColor);
                }
            }
        }
コード例 #19
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            Color color = _color != null ? _color.Value : Color.White;

            float scale = _scaleByUnit ? (float)UiUnit.Unit : 1;

            if (color.A > 0)
            {
                Rectangle bounds = ScreenBounds;

                bounds.Height = Math.Max(Bounds.Height, 1);
                bounds.Width  = Math.Max(Bounds.Width, 1);

                parameters.DrawBatch.DrawNinePatchRect(_image, bounds, color * opacity, scale * _scale);
            }
        }
コード例 #20
0
ファイル: UiScrollView.cs プロジェクト: jacekwicherek/Sitana
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            DrawBackground(ref parameters);

            UiViewDrawParameters drawParams = parameters;

            drawParams.Opacity = opacity;

            if (_clipChildren)
            {
                parameters.DrawBatch.PushClip(ScreenBounds);
            }

            Rectangle bounds = new Rectangle(0, 0, Bounds.Width, Bounds.Height);

            for (int idx = 0; idx < _children.Count; ++idx)
            {
                var child = _children[idx];

                if (bounds.Intersects(child.Bounds))
                {
                    child.ViewDraw(ref drawParams);
                }
            }

            if (_clipChildren)
            {
                parameters.DrawBatch.PopClip();
            }
        }
コード例 #21
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            if (Colors == null)
            {
                base.Draw(ref parameters);
                return;
            }

            float opacity = parameters.Opacity;

            if (opacity == 0 || TextColor.Value.A == 0)
            {
                return;
            }

            if (_fontFace == null)
            {
                _fontFace = FontManager.Instance.FindFont(FontName);
            }

            float         scale;
            UniversalFont font = _fontFace.Find(FontSize, out scale);

            if (font.SitanaFont == null)
            {
                throw new Exception("Only Sitana fonts support UiColoredLabel.");
            }

            lock (Text)
            {
                lock (Colors)
                {
                    parameters.DrawBatch.DrawText(font, Text.StringBuilder, ScreenBounds, TextAlign, Colors, opacity, (float)FontSpacing / 1000.0f, (float)LineHeight / 100.0f, scale);
                }
            }
        }
コード例 #22
0
ファイル: UiVerticalGradient.cs プロジェクト: prepare/Sitana
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            Color topColor    = _topColor != null ? _topColor.Value : Color.Transparent;
            Color bottomColor = _bottomColor != null ? _bottomColor.Value : Color.Transparent;

            parameters.DrawBatch.BeginPrimitive(PrimitiveType.TriangleStrip, null);

            Rectangle bounds = ScreenBounds;

            parameters.DrawBatch.PushVertex(new Vector2(bounds.Left, bounds.Top), topColor * opacity);
            parameters.DrawBatch.PushVertex(new Vector2(bounds.Left, bounds.Bottom), bottomColor * opacity);

            parameters.DrawBatch.PushVertex(new Vector2(bounds.Right, bounds.Top), topColor * opacity);
            parameters.DrawBatch.PushVertex(new Vector2(bounds.Right, bounds.Bottom), bottomColor * opacity);

            parameters.DrawBatch.Flush();
        }
コード例 #23
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            base.Draw(ref parameters);

            int position      = 0;
            int startPosition = ScreenBounds.Top;

            int separatorHeight = _separator != null?Math.Max(1, _separatorHeight.Compute(Bounds.Height)) : 0;

            int rowHeight = _rowHeight.Compute(Bounds.Height);

            Rectangle target = new Rectangle();


            float startIndexF = _scrollingService.ScrollPositionY / (float)(rowHeight + separatorHeight);

            int startIndex = (int)startIndexF;

            startPosition -= (int)_scrollingService.ScrollPositionY % (rowHeight + separatorHeight);

            if (_reversed)
            {
                startIndex = _items.Count - startIndex - 1;
            }

            Rectangle textTarget = new Rectangle();
            int       maxY       = ScreenBounds.Bottom;

            parameters.DrawBatch.PushClip(ScreenBounds);

            target        = ScreenBounds;
            target.Y      = startPosition;
            target.Height = separatorHeight;

            if (separatorHeight > 0)
            {
                for (int dataIndex = startIndex; dataIndex < _items.Count && dataIndex >= 0;)
                {
                    _separator.Draw(parameters.DrawBatch, target, parameters.Opacity);

                    target.Y += rowHeight + separatorHeight;

                    if (target.Y > maxY)
                    {
                        break;
                    }

                    dataIndex += _reversed ? -1 : 1;
                }
            }

            startPosition += separatorHeight;

            for (int columnIndex = 0; columnIndex < _columns.Count; ++columnIndex)
            {
                var column = _columns[columnIndex];
                int width  = column.Width.Compute(Bounds.Width);

                UniversalFont font        = column.Font.Font;
                float         fontScale   = column.Font.Scale;
                float         fontSpacing = column.Font.Spacing;

                int lineHeight = column.LineHeight;

                TextAlign textAlign = column.TextAlign;

                target.X     = position + column.TextMargin.Left + ScreenBounds.Left;
                target.Width = width - column.TextMargin.Width;

                target.Y      = startPosition;
                target.Height = rowHeight;

                Margin textMargin = column.TextMargin;

                int dataIndex = startIndex;
                int count     = _items.Count;

                for (int idx = 0; idx < count; idx++)
                {
                    textTarget.X     = target.X;
                    textTarget.Width = target.Width;

                    textTarget.Y      = target.Y + textMargin.Top;
                    textTarget.Height = target.Height - textMargin.Height;

                    if (dataIndex >= 0 && dataIndex < count)
                    {
                        QuickDataRow row = (QuickDataRow)(_items.ElementAt(dataIndex));

                        Color  color = row.Colors[columnIndex].Value;
                        string text  = row.Labels[columnIndex];

                        parameters.DrawBatch.DrawText(font, text, textTarget, textAlign, color, fontSpacing, lineHeight, fontScale);
                    }

                    target.Y += target.Height + separatorHeight;

                    if (target.Y > maxY)
                    {
                        break;
                    }

                    dataIndex += _reversed ? -1 : 1;
                }

                position += width;
            }

            parameters.DrawBatch.PopClip();
        }
コード例 #24
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            base.Draw(ref parameters);

            AdvancedDrawBatch batch  = parameters.DrawBatch;
            Rectangle         bounds = ScreenBounds;

            _selectedPosition = bounds.Center.Y + _selectedPositionOffset.Compute(bounds.Height);

            int size = _elementHeight.Compute(bounds.Height) + _spacing.Compute();

            int start  = 0;
            int center = _selectedPosition + (int)(_scroll * size);

            Rectangle rect = bounds;

            rect.Height = _elementHeight.Compute(bounds.Height);

            while (center > bounds.Top - size / 2)
            {
                center -= size;
                start--;
            }

            rect.Y = center - _elementHeight.Compute(bounds.Height) / 2;

            DrawButtonInfo drawInfo = new DrawButtonInfo();

            drawInfo.Icon         = null;
            drawInfo.Opacity      = parameters.Opacity;
            drawInfo.EllapsedTime = parameters.EllapsedTime;
            drawInfo.Text         = _captionText;

            while (rect.Bottom <= bounds.Bottom + size)
            {
                ButtonState state = _touchId != 0 ? ButtonState.Pushed : ButtonState.None;

                if (center == _selectedPosition && !_isScrolling && float.IsNaN(_scrollTo))
                {
                    state |= ButtonState.Checked;
                }

                if (start == (int)((_scroll > 0 ? -0.5 : 0.5) - _scroll))
                {
                    state |= ButtonState.Checked;
                }

                bool enabled = false;
                _context.GetData(start, _captionText.StringBuilder, out enabled);

                if (!enabled)
                {
                    state |= ButtonState.Disabled;
                    state &= ~ButtonState.Pushed;
                }

                drawInfo.Target      = rect;
                drawInfo.ButtonState = state;

                for (int idx = 0; idx < _drawables.Count; ++idx)
                {
                    var drawable = _drawables[idx];
                    drawable.Draw(batch, drawInfo);
                }

                start++;
                center += size;
                rect.Y += size;
            }
        }
コード例 #25
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            base.Draw(ref parameters);

            Rectangle bounds = ScreenBounds;
            Rectangle parentBounds = Parent.ScreenBounds;

            Point position = bounds.Location;

            int unitSize = (int)Math.Ceiling(_zoom.Value * UiUnit.Unit);

            int indexX = 0;
            int indexY = 0;

            while (parentBounds.X > position.X + unitSize)
            {
                position.X += unitSize;
                indexX++;
            }

            while (parentBounds.Y > position.Y + unitSize)
            {
                position.Y += unitSize;
                indexY++;
            }

            int width = _grid.Value.Width;
            int height = _grid.Value.Height;

            float maxCoordinateX = parentBounds.Right;
            float maxCoordinateY = parentBounds.Bottom;

            AdvancedDrawBatch drawBatch = parameters.DrawBatch;

            AutomataGrid grid = _grid.Value;

            Point originalPosition = position;

            for(int idxX = indexX; idxX < width; ++idxX)
            {
                position.Y = originalPosition.Y;
                for (int idxY = indexY; idxY < height; ++idxY)
                {
                    if (position.Y > maxCoordinateY)
                    {
                        break;
                    }

                    int state = grid[idxX, idxY];

                    if(state > 0)
                    {
                        drawBatch.DrawRectangle(new Rectangle(position.X, position.Y, unitSize, unitSize), _colors[state]);
                    }

                    position.Y += unitSize;
                }

                if (position.X > maxCoordinateX)
                {
                    break;
                }

                position.X += unitSize;
            }

            if (unitSize > 3)
            {
                Color gridColor = _gridColor.Value;

                position = originalPosition;

                for (int idxX = indexX; idxX < width; ++idxX)
                {
                    position.Y = originalPosition.Y;
                    for (int idxY = indexY; idxY < height; ++idxY)
                    {
                        if (position.Y > maxCoordinateY)
                        {
                            break;
                        }

                        drawBatch.DrawPoint(position, gridColor);

                        position.Y += unitSize;
                    }

                    if (position.X > maxCoordinateX)
                    {
                        break;
                    }

                    position.X += unitSize;
                }
            }
        }
コード例 #26
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            base.Draw(ref parameters);

            Rectangle target = ScreenBounds;
            Rectangle source = Rectangle.Empty;

            float scale = Scale;

            lock (_image)
            {
                Texture2D image = _image.Value;

                if (image != null)
                {
                    source = new Rectangle(0, 0, image.Width, image.Height);

                    double scaleX = scale;
                    double scaleY = scale;

                    switch (_stretch)
                    {
                    case Stretch.Uniform:
                        scaleX = scaleY = Math.Min((double)target.Width / (double)image.Width, (double)target.Height / (double)image.Height) * _scale;
                        scale  = (float)scaleX;
                        break;

                    case Stretch.UniformToFill:
                        scaleX = scaleY = Math.Max((double)target.Width / (double)image.Width, (double)target.Height / (double)image.Height) * _scale;
                        scale  = (float)scaleX;
                        break;

                    case Stretch.Fill:
                        scaleX = Scale * (double)target.Width / (double)image.Width;
                        scaleY = Scale * (double)target.Height / (double)image.Height;
                        scale  = (float)Math.Min(scaleX, scaleY);
                        break;
                    }

                    Point pos = target.Center;

                    int width  = (int)(Math.Ceiling(image.Width * scaleX));
                    int height = (int)(Math.Ceiling(image.Height * scaleY));

                    Rectangle targetRect = new Rectangle(pos.X - width / 2 - width % 2, pos.Y - height / 2 - height % 2, width, height);
                    target = GraphicsHelper.IntersectRectangle(targetRect, target);

                    int srcWidth  = (int)((double)target.Width / scaleX);
                    int srcHeight = (int)((double)target.Height / scaleY);

                    pos    = source.Center;
                    source = new Rectangle(pos.X - srcWidth / 2, pos.Y - srcHeight / 2, srcWidth, srcHeight);
                }

                Color color = _color != null ? _color.Value * opacity : Color.White;

                if (_rotationSpeed == 0)
                {
                    parameters.DrawBatch.DrawImage(image, target, source, color);
                }
                else
                {
                    parameters.DrawBatch.DrawImage(image, target.Center.ToVector2(), null, color, _rotation, new Vector2(image.Width / 2, image.Height / 2), scale);
                }
            }
        }
コード例 #27
0
ファイル: UiView.cs プロジェクト: jacekwicherek/Sitana
        public void ViewDraw(ref UiViewDrawParameters parameters)
        {
            _isViewDisplayed = Visible && Math.Abs(parameters.Transition) < 0.000001;

            if (DisplayVisibility == 0)
            {
                return;
            }

            TransitionEffect transitionEffect         = null;
            TransitionEffect transitionEffectShowHide = null;

            switch (parameters.TransitionMode)
            {
            case TransitionMode.Show:
                transitionEffect = _parentShowTransitionEffect;
                break;

            case TransitionMode.Hide:
                transitionEffect = _parentHideTransitionEffect;
                break;

            case TransitionMode.None:
                transitionEffectShowHide = DisplayVisibility == 1 ? null : (Visible ? _showTransitionEffect : _hideTransitionEffect);
                break;
            }

            if (transitionEffect != null || transitionEffectShowHide != null)
            {
                UiViewDrawParameters drawParameters = parameters;

                float  opacity;
                Matrix transform;

                Matrix targetTransform = Matrix.Identity;
                float  targetOpacity   = 1;

                if (transitionEffect != null)
                {
                    transitionEffect.Get(parameters.Transition, parameters.TransitionRectangle, ScreenBounds, out transform, out opacity);
                    targetOpacity   *= opacity;
                    targetTransform *= transform;
                }

                if (transitionEffectShowHide != null)
                {
                    transitionEffectShowHide.Get(1 - DisplayVisibility, Parent != null ? Parent.ScreenBounds : ScreenBounds, ScreenBounds, out transform, out opacity);
                    targetOpacity   *= opacity;
                    targetTransform *= transform;
                }

                drawParameters.DrawBatch.PushTransform(targetTransform);
                drawParameters.Opacity *= (float)Opacity.Value * targetOpacity;

                Draw(ref drawParameters);

                drawParameters.DrawBatch.PopTransform();
            }
            else
            {
                UiViewDrawParameters drawParameters = parameters;
                drawParameters.Opacity *= DisplayVisibility * (float)Opacity.Value;

                Draw(ref drawParameters);
            }
        }
コード例 #28
0
ファイル: UiContentSlider.cs プロジェクト: prepare/Sitana
        protected override void Draw(ref Parameters.UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            DrawBackground(ref parameters);

            if (_clipChildren)
            {
                parameters.DrawBatch.PushClip(ScreenBounds);
            }

            for (int idx = 0; idx < 2; ++idx)
            {
                UiView view       = idx == 0 ? _previous : _current;
                float  transition = _transition;

                if (idx == 0)
                {
                    transition = 1 - transition;
                }

                if (view != null)
                {
                    UiViewDrawParameters drawParams = parameters;

                    drawParams.Opacity = opacity;

                    TransitionEffect transitionEffect = FindTransition(idx == 0);

                    if (transitionEffect != null)
                    {
                        float  opacity2;
                        Matrix transform;

                        drawParams.Transition = transition;

                        transitionEffect.Get(transition, ScreenBounds, view.ScreenBounds, out transform, out opacity2);

                        drawParams.Opacity *= opacity2;

                        drawParams.DrawBatch.PushTransform(transform);

                        view.ViewDraw(ref drawParams);

                        drawParams.DrawBatch.PopTransform();
                    }
                    else
                    {
                        view.ViewDraw(ref drawParams);
                    }
                }
            }

            if (_clipChildren)
            {
                parameters.DrawBatch.PopClip();
            }

            if (_transition > 0)
            {
                AppMain.RedrawNextFrame();
            }
        }
コード例 #29
0
ファイル: UiView.cs プロジェクト: jacekwicherek/Sitana
 protected virtual void Draw(ref UiViewDrawParameters parameters)
 {
     DrawBackground(ref parameters);
 }
コード例 #30
0
        void DrawTiles(ref UiViewDrawParameters parameters, TiledLayer layer)
        {
            Rectangle bounds = ScreenBounds;

            AdvancedDrawBatch batch = parameters.DrawBatch;

            SamplerState oldSamplerState = batch.SamplerState;

            batch.SamplerState = SamplerState.PointClamp;

            int width  = layer.Width;
            int height = layer.Height;

            float zoom     = (float)_zoom.Value / 100f;
            int   unitSize = Tools.Tool.UnitToPixels(zoom);

            int tileSize = Tools.Tool.UnitToPixels(1);

            Rectangle target = new Rectangle(bounds.X - CurrentPosition.X, bounds.Y - CurrentPosition.Y, unitSize, unitSize);
            Rectangle source = new Rectangle(0, 0, tileSize - 1, tileSize - 1);

            Texture2D tileset = CurrentTemplate.Instance.Tileset(layer.Tileset).Item2;

            int startY = target.Y;

            int maxY = 0;

            ushort[,] tiles = layer.Content;

            for (int idxX = 0; idxX < width; ++idxX)
            {
                target.Y = startY;

                if (target.Right >= bounds.X && target.X <= bounds.Right)
                {
                    for (int idxY = 0; idxY < height; ++idxY)
                    {
                        if (target.Bottom >= bounds.Y && target.Y <= bounds.Bottom)
                        {
                            ushort tile = tiles[idxX, idxY];

                            if (tile != 0xffff)
                            {
                                source.X = (tile & 0xff) * tileSize;
                                source.Y = ((tile >> 8) & 0xff) * tileSize;

                                batch.DrawImage(tileset, target, source, Color.White * 0.5f);
                            }
                        }

                        target.Y += unitSize;
                        maxY      = Math.Max(target.Y, maxY);
                    }
                }

                target.X += unitSize;
            }

            Color color = Color.White * 0.25f;

            batch.DrawLine(new Point(target.X, bounds.Top), new Point(target.X, maxY), color);
            batch.DrawLine(new Point(bounds.Left, maxY), new Point(target.X, maxY), color);

            batch.SamplerState = oldSamplerState;
        }
コード例 #31
0
ファイル: UiRichView.cs プロジェクト: prepare/Sitana
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            base.Draw(ref parameters);

            Rectangle target = ScreenBounds;

            if (_height < target.Height)
            {
                switch (_textAlign & TextAlign.Vert)
                {
                case TextAlign.Middle:
                    target.Y = target.Center.Y - _height / 2;
                    break;

                case TextAlign.Bottom:
                    target.Y = target.Bottom - _height;
                    break;
                }
            }

            int startX = target.X;

            int endY = target.Bottom;

            int top    = parameters.DrawBatch.ClipRect.Top;
            int bottom = parameters.DrawBatch.ClipRect.Bottom;

            _firstVisibleLine = -1;

            for (int idx = 0; idx < _lines.Count; ++idx)
            {
                RichViewLine line = _lines[idx];

                if (target.Y > bottom)
                {
                    break;
                }

                target.Height = line.Height;

                if (target.Y + line.Height >= top)
                {
                    if (_firstVisibleLine < 0)
                    {
                        _firstVisibleLine = idx;
                    }

                    _lastVisibleLine = idx;

                    int lineOffset = OffsetFromWidthAndAlign(line.Width);

                    for (int ent = 0; ent < line.Entities.Count; ++ent)
                    {
                        RichViewEntity entity = line.Entities[ent];

                        float         spacing = entity.FontSpacing;
                        float         scale   = entity.FontScale;
                        UniversalFont font    = entity.Font;

                        int offset = 0;

                        if (font != null)
                        {
                            offset = line.BaseLine - (int)((font.BaseLine - 1) * scale);
                        }

                        target.X = startX + entity.Offset + lineOffset;

                        switch (entity.Type)
                        {
                        case EntityType.HorizontalLine:
                        {
                            Rectangle rect = new Rectangle(target.X, target.Y, Bounds.Width, _horizontalRulerHeight.Compute(0));
                            parameters.DrawBatch.DrawRectangle(rect, _colorRuler.Value * opacity);
                        }
                        break;

                        case EntityType.String:
                        {
                            Color textColor = _colorNormal.Value;

                            if (entity.Url != null)
                            {
                                textColor = _selected == entity ? _colorClickableActive.Value : _colorClickable.Value;
                            }

                            target.Y += offset;
                            parameters.DrawBatch.DrawText(font, entity.Text, target, TextAlign.Left, textColor * opacity, spacing, 0, scale);
                            target.Y -= offset;
                        }
                        break;

                        case EntityType.Image:
                        {
                            Point size = new Point((int)(entity.Image.Width * UiUnit.Unit), (int)(entity.Image.Height * UiUnit.Unit));

                            int maxWidth = Bounds.Width - entity.Offset;

                            if (size.X > maxWidth)
                            {
                                size.Y = maxWidth * size.Y / size.X;
                                size.X = maxWidth;
                            }

                            parameters.DrawBatch.DrawImage(entity.Image, target.Location, size, Point.Zero, (float)size.X / (float)entity.Image.Width, Color.White * opacity);
                        }
                        break;
                        }
                    }
                }

                target.Y += line.Height;
            }
        }