Beispiel #1
0
        // /////////////////////////////////////////////////////////////////////////////////
        internal Point AutoPosition(Point nearPos, Size sizeOfControl)
        {
            Rect conRect = new Rect(nearPos, sizeOfControl);
            int dx = 0;
            int dy = 0;

            int screenRight = Application.ScreenSize.Width - 1;
            int screenBottom = Application.ScreenSize.Height - 1;

            if (conRect.Left < 0)
                dx = -conRect.Left;
            else if (conRect.Right > screenRight)
                dx = screenRight - conRect.Right;

            if (conRect.Top < 0)
                dy = -conRect.Top;
            else if (conRect.Bottom > screenBottom)
                dy = screenBottom - conRect.Bottom;

            int finalX = nearPos.X + dx;
            int finalY = nearPos.Y + dy;

            return new Point(finalX, finalY);
        }
Beispiel #2
0
 // /////////////////////////////////////////////////////////////////////////////////
 // /////////////////////////////////////////////////////////////////////////////////
 private void AlignSouthWest(Rect ofRect, int padding)
 {
     SetUpperRight(ofRect.LowerLeft.Shift(-(1 + padding), 1 + padding));
 }
Beispiel #3
0
        // /////////////////////////////////////////////////////////////////////////////////
        // /////////////////////////////////////////////////////////////////////////////////
        private void AlignWest(Rect ofRect, int padding)
        {
            Point ourCtr = CalculateRect().Center;
            Point ofCtr = ofRect.Center;

            SetUpperRight(new Point(ofRect.Left - (1 + padding), ofCtr.Y - ourCtr.Y));
        }
Beispiel #4
0
        // /////////////////////////////////////////////////////////////////////////////////
        private void AlignSouth(Rect ofRect, int padding)
        {
            Point ourCtr = CalculateRect().Center;
            Point ofCtr = ofRect.Center;

            UpperLeftPos = new Point(ofCtr.X - ourCtr.X, ofRect.Bottom + 1 + padding);
        }
Beispiel #5
0
 // /////////////////////////////////////////////////////////////////////////////////
 // /////////////////////////////////////////////////////////////////////////////////
 private void AlignSouthEast(Rect ofRect, int padding)
 {
     UpperLeftPos = ofRect.LowerRight.Shift(1 + padding, 1 + padding);
 }
Beispiel #6
0
        /// <summary>
        /// Adds dx to left and right, and dy to top and bottom
        /// New width += dx*2, new height = dy*2
        /// </summary>
        /// <param name="source"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static Rect Inflate(Rect source, int dx, int dy)
        {
            Rect ret;
            Point newUpperLeft;
            Size newSize;

            newUpperLeft = new Point(source.upperLeft.X - dx,
                source.upperLeft.Y - dy);

            newSize = new Size(source.size.Width + dx*2, source.size.Height + dy*2);

            ret = new Rect(newUpperLeft,newSize);

            return ret;
        }
Beispiel #7
0
 // /////////////////////////////////////////////////////////////////////////////////
 // /////////////////////////////////////////////////////////////////////////////////
 private void AlignNorthWest(Rect ofRect, int padding)
 {
     SetLowerRight(ofRect.UpperLeft.Shift(-(1 + padding), -(1 + padding)));
 }
Beispiel #8
0
        // /////////////////////////////////////////////////////////////////////////////////
        // /////////////////////////////////////////////////////////////////////////////////
        protected override void OnSettingUp()
        {
            base.OnSettingUp();

            if (!string.IsNullOrEmpty(Label))
            {
                labelRect = new Rect(1, 1, Label.Length + 1, 1);
                upButtonPos = new Point(Label.Length + 2, 1);
            }
            else
            {
                upButtonPos = new Point(1, 1);
            }

            int fieldWidth = NumberEntryTemplate.CalculateFieldWidth(MaximumValue, MinimumValue);
            Size fieldSize = new Size(fieldWidth, 1);
            fieldRect = new Rect(upButtonPos.Shift(2, 0), fieldSize);

            downButtonPos = fieldRect.UpperRight.Shift(1, 0);

            numEntry = new NumberEntry(new NumberEntryTemplate()
            {
                HasFrameBorder = false,
                MinimumValue = this.MinimumValue,
                MaximumValue = this.MaximumValue,
                StartingValue = CurrentValue,
                CommitOnLostFocus = true,
                ReplaceOnFirstKey = true,
                UpperLeftPos = fieldRect.UpperLeft
            });

            upButton = new EmitterButton(new EmitterButtonTemplate()
            {
                HasFrameBorder = false,
                Label = ((char)libtcod.TCODSpecialCharacter.ArrowNorthNoTail).ToString(),
                UpperLeftPos = upButtonPos,
                StartEmittingDelay = SpinDelay,
                Speed = SpinSpeed
            });

            downButton = new EmitterButton(new EmitterButtonTemplate()
            {
                HasFrameBorder = false,
                Label = ((char)libtcod.TCODSpecialCharacter.ArrowSouthNoTail).ToString(),
                UpperLeftPos = downButtonPos,
                StartEmittingDelay = SpinDelay,
                Speed = SpinSpeed
            });

            ParentWindow.AddControls(downButton, upButton, numEntry);

            upButton.Emit += new EventHandler(upButton_Emit);
            downButton.Emit += new EventHandler(downButton_Emit);
            numEntry.EntryChanged += new EventHandler(numEntry_EntryChanged);
        }
Beispiel #9
0
        // /////////////////////////////////////////////////////////////////////////////////
        // /////////////////////////////////////////////////////////////////////////////////
        private void AlignEast(Rect ofRect, int padding)
        {
            Point ourCtr = CalculateRect().Center;
            Point ofCtr = ofRect.Center;

            UpperLeftPos = new Point(ofRect.Right + 1 + padding, ofCtr.Y - ourCtr.Y);
        }
Beispiel #10
0
        private void CalcMetrics(MenuTemplate template)
        {
            itemsRect = this.LocalRect;
            if (HasFrame)
            {
                itemsRect = Rect.Inflate(itemsRect, -1, -1);
            }

            int delta = itemsRect.Size.Height - Items.Count;

            numberItemsDisplayed = Items.Count;

            if (delta < 0)
            {
                numberItemsDisplayed += delta;
            }
        }
Beispiel #11
0
        private void CalcMetrics(ListBoxTemplate template)
        {
            int nitms = Items.Count;
            int expandTitle = 0;

            int delta = Size.Height - nitms - 1;
            if (template.HasFrameBorder)
            {
                delta -= 3;
            }

            numberItemsDisplayed = Items.Count;
            if (delta < 0)
            {
                numberItemsDisplayed += delta;
            }
            else if (delta > 0)
            {
                expandTitle = delta;
            }

            int titleWidth = Size.Width;

            int titleHeight = 1 + expandTitle;

            if (Title != "")
            {
                if (template.HasFrameBorder)
                {
                    titleRect = new Rect(Point.Origin.Shift(1, 1),
                        new Size(titleWidth - 2, titleHeight));
                }
                else
                {
                    titleRect = new Rect(Point.Origin,
                        new Size(titleWidth, titleHeight));
                }
            }

            int itemsWidth = Size.Width;
            int itemsHeight = numberItemsDisplayed;

            if (template.HasFrameBorder)
            {
                itemsRect = new Rect(titleRect.LowerLeft.Shift(0, 2),
                    new Size(itemsWidth - 2, itemsHeight));
            }
            else
            {
                itemsRect = new Rect(titleRect.LowerLeft.Shift(0, 1),
                    new Size(itemsWidth, itemsHeight));
            }
        }
Beispiel #12
0
 public bool Equals(Rect rect)
 {
     return (this.upperLeft == rect.upperLeft && this.size == rect.size);
 }
Beispiel #13
0
 public static Rect MoveTo(Rect rect, Point upperLeft)
 {
     return new Rect(upperLeft, rect.size);
 }
Beispiel #14
0
        public static Rect MoveBy(Rect rect, Size delta)
        {
            Point newUpperleft = new Point(rect.upperLeft.X + delta.Width,
                rect.upperLeft.Y+delta.Height);

            return new Rect(newUpperleft,rect.size);
        }
Beispiel #15
0
        protected override void OnSettingUp()
        {
            base.OnSettingUp();

            // Create and add interior panel that will "hold" all of the example controls
            Size panelSize = new Size(this.Size.Width-2,this.Size.Height-24);

            PanelTemplate panelTemplate = new PanelTemplate()
            {
                HasFrame = true,
                UpperLeftPos = this.LocalRect.UpperLeft.Shift(1,3),
                Size = panelSize
            };
            //panelTemplate.SetLowerRight(this.ScreenRect.LowerRight.Shift(-1, -17));
            AddControl(new Panel(panelTemplate));

            ViewRect = Rect.Inflate(panelTemplate.CalculateRect(),-1,-1);

            // Create the page info TextBox control.  Each page will have one.
            Rect textBoxRect = new Rect(panelTemplate.CalculateRect().LowerLeft.Shift(0, 1),
                this.LocalRect.LowerRight.Shift(-1, -1));

            TextBoxTemplate tbt = new TextBoxTemplate()
            {
                Size = textBoxRect.Size,
                UpperLeftPos = textBoxRect.UpperLeft,
                TextSpeed = 5,
                Pigments = new PigmentAlternatives()
                {
                    {PigmentType.Window,new Pigment(0xaaaaaa,0x111511)}
                }
            };

            PageInfo = new TextBox(tbt);
            AddControl(PageInfo);

            // Create the next, previous and quit buttons.  Each page will have these
            // buttons
            ButtonTemplate nextButtonTemplate = new ButtonTemplate()
            {
                Label = "Next->",
                Tooltip = "Click to go to the next page",
                HilightWhenMouseOver = true,
                LabelAlignment = HorizontalAlignment.Center,
                MinimumWidth = 12
            };
            nextButtonTemplate.SetUpperRight(Application.ScreenRect.UpperRight);

            ButtonTemplate previousButtonTemplate = new ButtonTemplate()
            {
                Label = "<-Previous",
                Tooltip = "Click to go to the previous page",
                HilightWhenMouseOver = true,
                UpperLeftPos = new Point(0, 0),
                LabelAlignment = HorizontalAlignment.Center,
                MinimumWidth = 12
            };

            ButtonTemplate quitButtonTemplate = new ButtonTemplate()
            {
                Label = "QUIT",
                Tooltip = "Quit the demo",
                HilightWhenMouseOver = true,
                LabelAlignment = HorizontalAlignment.Center,
                MinimumWidth = 38
            };
            quitButtonTemplate.SetTopCenter(Application.ScreenRect.TopCenter);

            Button quitButton = new Button(quitButtonTemplate);
            nextButton = new Button(nextButtonTemplate);
            prevButton = new Button(previousButtonTemplate);

            AddControls(nextButton, prevButton, quitButton);

            quitButton.ButtonPushed += new EventHandler(quitButton_ButtonClicked);
            prevButton.ButtonPushed += new EventHandler(prevButton_ButtonClicked);
            nextButton.ButtonPushed += new EventHandler(nextButton_ButtonClicked);

            prevButton.IsActive = hasPrev;
            nextButton.IsActive = hasNext;
        }
Beispiel #16
0
        // /////////////////////////////////////////////////////////////////////////////////
        // /////////////////////////////////////////////////////////////////////////////////
        private void AlignNorth(Rect ofRect, int padding)
        {
            Point ourCtr = CalculateRect().Center;
            Point ofCtr = ofRect.Center;

            SetLowerLeft(new Point(ofCtr.X - ourCtr.X, ofRect.Top -(1 + padding)));
        }
Beispiel #17
0
        // /////////////////////////////////////////////////////////////////////////////////
        // /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Creates the NumberEntry and ValueBar for this slider.
        /// </summary>
        protected override void OnSettingUp()
        {
            base.OnSettingUp();

            Point fieldPos;
            if (!string.IsNullOrEmpty(Label))
            {
                labelRect = new Rect(1, 1, Label.Length + 1, 1);
                fieldPos = new Point(Label.Length + 2, 1);
            }
            else
            {
                fieldPos = new Point(1, 1);
            }

            int fieldWidth = NumberEntryTemplate.CalculateFieldWidth(MaximumValue, MinimumValue);
            Size fieldSize = new Size(fieldWidth, 1);
            fieldRect = new Rect(fieldPos, fieldSize);

            if (BarPigment == null)
                BarPigment = DetermineMainPigment();

            numEntry = new NumberEntry(new NumberEntryTemplate()
            {
                HasFrameBorder = false,
                MinimumValue = this.MinimumValue,
                MaximumValue = this.MaximumValue,
                StartingValue = CurrentValue,
                CommitOnLostFocus = true,
                ReplaceOnFirstKey = true,
                UpperLeftPos = this.LocalToScreen(fieldRect.UpperLeft)
            });

            valueBar = new ValueBar(new ValueBarTemplate()
            {
                UpperLeftPos = this.LocalToScreen(new Point(1,2)),
                Width = this.Size.Width-4,
                MaximumValue = this.MaximumValue,
                MinimumValue = this.MinimumValue,
                StartingValue = this.CurrentValue,
                BarPigment = this.BarPigment
            });

            ParentWindow.AddControls(valueBar, numEntry);

            numEntry.EntryChanged += new EventHandler(numEntry_EntryChanged);

            valueBar.MouseMoved += new EventHandler<MouseEventArgs>(valueBar_MouseMoved);

            valueBar.MouseButtonDown += new EventHandler<MouseEventArgs>(valueBar_MouseButtonDown);
        }
Beispiel #18
0
        private void CalcMetrics(CheckBoxTemplate template)
        {
            Rect inner = this.LocalRect;

            if (template.HasFrameBorder && template.CalculateSize().Height >= 3)
            {
                inner = Rect.Inflate(inner, -1, -1);
            }

            int checkX;

            if (CheckOnLeft)
            {
                checkX = inner.Left;
                labelRect = new Rect(inner.UpperLeft.Shift(1, 0),
                    inner.LowerRight);
            }
            else
            {
                checkX = inner.Right;
                labelRect = new Rect(inner.UpperLeft,
                    inner.LowerRight.Shift(-1, 0));
            }

            if (labelRect.Size.Width < 1)
            {
                Label = "";
            }

            switch (VerticalAlign)
            {
                case VerticalAlignment.Bottom:
                    checkPos = new Point(checkX, labelRect.Bottom);
                    break;

                case VerticalAlignment.Center:
                    checkPos = new Point(checkX, labelRect.Center.Y);
                    break;

                case VerticalAlignment.Top:
                    checkPos = new Point(checkX, labelRect.Top);
                    break;
            }
        }