private void DrawTextBoxComponent(TextBoxObject component, Object2D parent) { GraphicObject Parent = (GraphicObject)parent; component.offset.X = Parent.Size.X / 100 * component.ioffset.X; component.offset.Y = Parent.Size.Y / 100 * component.ioffset.Y; component.Init = true; Vector2 off = component.offset; component.BoundingRect = new Rectangle((int)Parent.Position.X + (int)off.X, (int)Parent.Position.Y + (int)off.Y, (int)Parent.Size.X, (int)Parent.Size.Y); if (Game.Content.Load<SpriteFont>(component.Font).MeasureString(component.Text).Y > component.BoundingRect.Height) { float maxY = (Parent.Position.Y - (Parent.Size.Y / 2)+5); float minY = (Parent.Position.Y + component.BoundingRect.Height - (Parent.Size.Y / 2)) - (Game.Content.Load<SpriteFont>(component.Font).MeasureString(component.Text).Y); if (component.currentOffset.Y > maxY) component.currentOffset.Y = maxY; else if (component.currentOffset.Y < minY) component.currentOffset.Y = minY; } Rectangle currentRect = SpriteManager.ScissorRectangle; SpriteManager.ScissorRectangle = component.BoundingRect; SpriteManager.DrawString(Game.Content.Load<SpriteFont>(component.Font), component.Text, Parent.Position + off + component.currentOffset, new Color(component.fontColor)); SpriteManager.ScissorRectangle = currentRect; DrawGraphicComponent(component.UpScroller, ref parent); DrawGraphicComponent(component.DownScroller, ref parent); }
private void UpdateTextBox(TextBoxObject component) { float textHeight = textHeight = Game.Content.Load<SpriteFont>(component.Font).MeasureString(component.Text).Y; if (textHeight > component.BoundingRect.Height) { Rectangle UpRect = new Rectangle((int)component.UpScroller.Position.X, (int)component.UpScroller.Position.Y, (int)component.UpScroller.Size.X, (int)component.UpScroller.Size.Y); Rectangle DownRect = new Rectangle((int)component.DownScroller.Position.X, (int)component.DownScroller.Position.Y, (int)component.DownScroller.Size.X, (int)component.DownScroller.Size.Y); if (UpRect.Contains(InputHandler.MouseX, InputHandler.MouseY) && InputHandler.LeftClickDown) component.Scroll(component.UpScroller.scrollDirection); if (DownRect.Contains(InputHandler.MouseX, InputHandler.MouseY) && InputHandler.LeftClickDown) component.Scroll(component.DownScroller.scrollDirection); } }