protected override void DrawBackground(idRectangle drawRect) { if ((_cvar == null) && (this.Buddy == null)) { return; } if ((_high - _low) <= 0.0f) { return; } idRectangle r = this.DrawRectangle; if (_scrollBar == false) { if (_vertical == true) { r.Y += _thumbHeight / 2.0f; r.Height -= _thumbHeight; } else { r.X += _thumbWidth / 2.0f; r.Width -= _thumbWidth; } } base.DrawBackground(r); }
public override void Draw(float x, float y) { PreRender(); Render(this.UserInterface.Time); _renderView.Clear(); _renderView.ViewOrigin = _viewOffset.ToVector3(); //refdef.vieworg.Set(-128, 0, 0); _renderView.ViewAxis = Matrix.Identity; _renderView.MaterialParameters[0] = 1; _renderView.MaterialParameters[1] = 1; _renderView.MaterialParameters[2] = 1; _renderView.MaterialParameters[3] = 1; idRectangle drawRect = this.DrawRectangle; _renderView.X = (int)drawRect.X; _renderView.Y = (int)drawRect.Y; _renderView.Width = (int)drawRect.Width; _renderView.Height = (int)drawRect.Height; _renderView.FovX = 90; _renderView.FovY = 2.0f * (float)System.Math.Atan(drawRect.Height / drawRect.Width) * idMath.Rad2Deg; _renderView.Time = this.UserInterface.Time;; _world.RenderScene(_renderView); }
public void Init() { _screenRect = new idRectangle(0, 0, 640, 480); _deviceContext = new idDeviceContext(); _deviceContext.Init(); }
private void DrawBackground(idRectangle drawRect) { if (_backColor.W > 0) { _context.DrawFilledRectangle(_drawRect.X, _drawRect.Y, _drawRect.Width, _drawRect.Height, _backColor); } if (_background != null) { if (_materialColor.W > 0) { float scaleX, scaleY; if ((_flags & WindowFlags.NaturalMaterial) == WindowFlags.NaturalMaterial) { scaleX = _drawRect.Width / _background.ImageWidth; scaleY = _drawRect.Height / _background.ImageHeight; } else { scaleX = _materialScaleX; scaleY = _materialScaleY; } _context.DrawMaterial(_drawRect.X, _drawRect.Y, _drawRect.Width, _drawRect.Height, _background, _materialColor, scaleX, scaleY); } } }
public override void Draw(float x, float y) { UpdateConsoleVariables(true); Vector4 color = this.ForeColor; int length = this.Text.Length; if (length != _lastTextLength) { _scroller.Value = 0.0f; EnsureCursorVisible(); _lastTextLength = length; } float scale = this.TextScale; string str = this.Text; if (_password == true) { str = new String('*', this.Text.Length); } if (_cursorPosition > length) { _cursorPosition = length; } idRectangle rect = this.TextRectangle; rect.X -= _paintOffset; rect.Width += _paintOffset; if ((_wrap == true) && (_scroller.High > 0.0f)) { float lineHeight = this.MaximumCharacterHeight + 5; rect.Y -= _scroller.Value * lineHeight; rect.Width -= _sizeBias; rect.Height = (_breaks.Count + 1) * lineHeight; } if ((this.Hover == true) && (this.NoEvents == false) && (this.Contains(this.UserInterface.CursorX, this.UserInterface.CursorY) == true)) { color = this.HoverColor; } else { this.Hover = false; } if ((this.Flags & WindowFlags.Focus) == WindowFlags.Focus) { color = this.HoverColor; } this.DeviceContext.DrawText(str, scale, 0, color, rect, _wrap, ((this.Flags & WindowFlags.Focus) == WindowFlags.Focus) ? _cursorPosition : -1); }
public void Set(idRectangle value) { _data = value; if (_guiDict != null) { _guiDict.Set(this.Name, _data); } }
public override void Set(string value) { _data = idHelper.ParseRectangle(value); if (_guiDict != null) { _guiDict.Set(this.Name, _data); } }
private void DrawBorderAndCaption(idRectangle drawRect) { if ((_flags & WindowFlags.Border) == WindowFlags.Border) { if (_borderSize > 0) { _context.DrawRectangle(drawRect.X, drawRect.Y, drawRect.Width, drawRect.Height, _borderSize, _borderColor); } } }
public void SetToRegisters(ref float[] registers) { Vector4 v = Vector4.Zero; Vector2 v2 = Vector2.Zero; Vector3 v3 = Vector3.Zero; idRectangle rect = idRectangle.Empty; if ((_enabled == false) || (_var == null) || ((_var != null) && ((_var.Dictionary != null) || (_var.Evaluate == false)))) { return; } switch (_type) { case RegisterType.Vector4: v = (idWinVector4)_var; break; case RegisterType.Rectangle: rect = (idWinRectangle)_var; v = new Vector4(rect.X, rect.Y, rect.Width, rect.Height); break; case RegisterType.Vector2: v2 = (idWinVector2)_var; v.X = v2.X; v.Y = v2.Y; break; case RegisterType.Vector3: v3 = (idWinVector3)_var; v.X = v3.X; v.Y = v3.Y; v.Z = v3.Z; break; case RegisterType.Float: v.X = (idWinFloat)_var; break; case RegisterType.Integer: v.X = (idWinInteger)_var; break; case RegisterType.Bool: v.X = (((idWinBool)_var) == true) ? 1 : 0; break; } registers[_indexes[0]] = v.X; registers[_indexes[1]] = v.Y; registers[_indexes[2]] = v.Z; registers[_indexes[3]] = v.W; }
public override void Update() { string s = this.Name; if ((_guiDict != null) && (s != string.Empty)) { idRectangle r = _guiDict.GetRectangle(this.Name); _data.X = r.X; _data.Y = r.Y; _data.Width = r.Width; _data.Height = r.Height; } }
public void Draw(float x, float y) { if (_visible == false) { return; } CalculateClientRectangle(0, 0); _context.FontFamily = _fontFamily; _drawRect.Offset(x, y); _clientRect.Offset(x, y); _textRect.Offset(x, y); SetupTransforms(x, y); if ((_flags & WindowFlags.NoClip) == WindowFlags.NoClip) { _context.ClippingEnabled = false; } DrawBackground(_drawRect); DrawBorderAndCaption(_drawRect); if (_textShadow > 0) { string shadowText = idHelper.RemoveColors(_text); idRectangle shadowRect = _textRect; shadowRect.X += _textShadow; shadowRect.Y += _textShadow; _context.DrawText(shadowText, _textScale, _textAlign, idColor.Black, shadowRect, (_flags & WindowFlags.NoWrap) == 0, -1); } _context.DrawText(_text, _textScale, _textAlign, _foreColor, _textRect, (_flags & WindowFlags.NoWrap) == 0, -1); _context.SetTransformInformation(Vector3.Zero, Matrix.Identity); if ((_flags & WindowFlags.NoClip) == WindowFlags.NoClip) { _context.ClippingEnabled = true; } _drawRect.Offset(-x, -y); _clientRect.Offset(-x, -y); _textRect.Offset(-x, -y); }
public override void Draw(float x, float y) { if (this.Disposed == true) { throw new ObjectDisposedException(this.GetType().Name); } Vector4 color = this.ForeColor; UpdateChoicesAndValues(); UpdateChoice(); // FIXME: It'd be really cool if textAlign worked, but a lot of the guis have it set wrong because it used to not work this.TextAlign = TextAlign.Left; if (this.TextShadow > 0) { string shadowText = _choices[_currentChoice]; idRectangle shadowRect = this.TextRectangle; shadowText = idHelper.RemoveColors(shadowText); shadowRect.X += this.TextShadow; shadowRect.Y += this.TextShadow; this.DeviceContext.DrawText(shadowText, this.TextScale, this.TextAlign, idColor.Black, shadowRect, false, -1); } if ((this.Hover == true) && (this.NoEvents == false) && (this.Contains(this.UserInterface.CursorX, this.UserInterface.CursorY) == true)) { color = this.HoverColor; } else { this.Hover = false; } if ((this.Flags & WindowFlags.Focus) == WindowFlags.Focus) { color = this.HoverColor; } this.DeviceContext.DrawText(_choices[_currentChoice], this.TextScale, this.TextAlign, color, this.TextRectangle, false, -1); }
public void InitWithDefaults(string name, idRectangle rect, Vector4 foreColor, Vector4 materialColor, string background, string thumbMaterial, bool vertical, bool scrollbar) { SetInitialState(name); _rect.Set(rect); _foreColor.Set(foreColor); _materialColor.Set(materialColor); _thumbMaterial = idE.DeclManager.FindMaterial(thumbMaterial); _thumbMaterial.Sort = (float)MaterialSort.Gui; _thumbWidth = _thumbMaterial.ImageWidth; _thumbHeight = _thumbMaterial.ImageHeight; _background = idE.DeclManager.FindMaterial(_backgroundName); _background.Sort = (float)MaterialSort.Gui; _vertical = vertical; _scrollBar = scrollbar; this.Flags |= WindowFlags.HoldCapture; }
private void CalculateClientRectangle(float offsetX, float offsetY) { _drawRect = _rect; if ((_flags & WindowFlags.InvertRectangle) == WindowFlags.InvertRectangle) { _drawRect.X = _rect.X - _rect.Width; _drawRect.Y = _rect.Y - _rect.Height; } _drawRect.X += offsetX; _drawRect.Y += offsetY; _clientRect = _drawRect; if ((_rect.Height > 0.0f) && (_rect.Width > 0.0f)) { if (((_flags & WindowFlags.Border) == WindowFlags.Border) && (_borderSize != 0.0f)) { _clientRect.X += _borderSize; _clientRect.Y += _borderSize; _clientRect.Width -= _borderSize; _clientRect.Height -= _borderSize; } _textRect = _clientRect; _textRect.X += 2; _textRect.Y += 2; _textRect.Width -= 2; _textRect.Height -= 2; _textRect.X += _textAlignX; _textRect.Y += _textAlignY; } _origin = new Vector2(_rect.X + (_rect.Width / 2), _rect.Y + (_rect.Height / 2)); }
private void DrawBackground(idRectangle drawRect) { if(_backColor.W > 0) { _context.DrawFilledRectangle(_drawRect.X, _drawRect.Y, _drawRect.Width, _drawRect.Height, _backColor); } if(_background != null) { if(_materialColor.W > 0) { float scaleX, scaleY; if((_flags & WindowFlags.NaturalMaterial) == WindowFlags.NaturalMaterial) { scaleX = _drawRect.Width / _background.ImageWidth; scaleY = _drawRect.Height / _background.ImageHeight; } else { scaleX = _materialScaleX; scaleY = _materialScaleY; } _context.DrawMaterial(_drawRect.X, _drawRect.Y, _drawRect.Width, _drawRect.Height, _background, _materialColor, scaleX, scaleY); } } }
private void CalculateClientRectangle(float offsetX, float offsetY) { _drawRect = _rect; if((_flags & WindowFlags.InvertRectangle) == WindowFlags.InvertRectangle) { _drawRect.X = _rect.X - _rect.Width; _drawRect.Y = _rect.Y - _rect.Height; } _drawRect.X += offsetX; _drawRect.Y += offsetY; _clientRect = _drawRect; if((_rect.Height > 0.0f) && (_rect.Width > 0.0f)) { if(((_flags & WindowFlags.Border) == WindowFlags.Border) && (_borderSize != 0.0f)) { _clientRect.X += _borderSize; _clientRect.Y += _borderSize; _clientRect.Width -= _borderSize; _clientRect.Height -= _borderSize; } _textRect = _clientRect; _textRect.X += 2; _textRect.Y += 2; _textRect.Width -= 2; _textRect.Height -= 2; _textRect.X += _textAlignX; _textRect.Y += _textAlignY; } _origin = new Vector2(_rect.X + (_rect.Width / 2), _rect.Y + (_rect.Height / 2)); }
public void Init() { _screenRect = new idRectangle(0, 0, 640, 480); _deviceContext = new idDeviceContext(); _deviceContext.Init(); }
public void PushClipRectangle(idRectangle rect) { _clipRectangles.Push(rect); }
public int DrawText(string text, float textScale, TextAlign textAlign, Vector4 color, idRectangle rectDraw, bool wrap, int cursor = -1, bool calcOnly = false, List<int> breaks = null, int limit = 0) { float textWidth = 0; float charSkip = MaxCharacterWidth(textScale) + 1; float lineSkip = MaxCharacterHeight(textScale); float cursorSkip = (cursor >= 0) ? charSkip : 0; SetFontByScale(textScale); // TODO: edit cursor /*if (!calcOnly && !(text && *text)) { if (cursor == 0) { renderSystem->SetColor(color); DrawEditCursor(rectDraw.x, lineSkip + rectDraw.y, textScale); } return idMath::FtoiFast( rectDraw.w / charSkip ); }*/ char c; int textPosition = 0; int length = 0, newLine = 0, newLineWidth = 0, newLinePosition = 0, count = 0; bool lineBreak = false; bool wordBreak = false; float y = lineSkip + rectDraw.Y; StringBuilder buffer = new StringBuilder(); if(breaks != null) { breaks.Add(0); } while(true) { c = idHelper.GetBufferCharacter(text, textPosition); if((c == '\n') || (c == '\r') || (c == '\0')) { lineBreak = true; if(((c == '\n') && (idHelper.GetBufferCharacter(text, textPosition + 1) == '\r')) || ((c == '\r') && (idHelper.GetBufferCharacter(text, textPosition + 1) == '\n'))) { textPosition++; c = idHelper.GetBufferCharacter(text, textPosition); } } int nextCharWidth = (int) ((idHelper.CharacterIsPrintable(c) == true) ? GetCharacterWidth(c, textScale) : cursorSkip); // FIXME: this is a temp hack until the guis can be fixed not not overflow the bounding rectangles // the side-effect is that list boxes and edit boxes will draw over their scroll bars // The following line and the !linebreak in the if statement below should be removed nextCharWidth = 0; if((lineBreak == false) && ((textWidth + nextCharWidth) > rectDraw.Width)) { // the next character will cause us to overflow, if we haven't yet found a suitable // break spot, set it to be this character if((length > 0) && (newLine == 0)) { newLine = length; newLinePosition = textPosition; newLineWidth = (int) textWidth; } wordBreak = true; } else if((lineBreak == true) || ((wrap == true) && ((c == ' ') || (c == '\t')))) { // The next character is in view, so if we are a break character, store our position newLine = length; newLinePosition = textPosition + 1; newLineWidth = (int) textWidth; } if((lineBreak == true) || (wordBreak == true)) { float x = rectDraw.X; if(textAlign == TextAlign.Right) { x = rectDraw.X + rectDraw.Width - newLineWidth; } else if(textAlign == TextAlign.Center) { x = rectDraw.X + ((rectDraw.Width - newLineWidth) / 2); } if((wrap == true) || (newLine > 0)) { // this is a special case to handle breaking in the middle of a word. // if we didn't do this, the cursor would appear on the end of this line // and the beginning of the next if((wordBreak == true) && (cursor >= newLine) && (newLine == length)) { cursor++; } } if(calcOnly == false) { count += DrawText(x, y, textScale, color, buffer.ToString(0, (newLine > 0) ? newLine : length), 0, 0, 0, cursor); buffer.Clear(); } if(cursor < newLine) { cursor = -1; } else if(cursor >= 0) { cursor -= (newLine + 1); } if(wrap == false) { return newLine; } if(((limit > 0) && (count > limit)) || (c == '\0')) { break; } y += lineSkip + 5; if((calcOnly == false) && (y > rectDraw.Bottom)) { break; } textPosition = newLinePosition; if(breaks != null) { breaks.Add(textPosition); } length = 0; newLine = 0; newLineWidth = 0; textWidth = 0; lineBreak = false; wordBreak = false; } else { length++; buffer.Append(idHelper.GetBufferCharacter(text, textPosition++)); // update the width if((buffer[length - 1] != (int) idColorIndex.Escape) && ((length <= 1) || (buffer[length - 2] != (int) idColorIndex.Escape))) { byte c2 = (byte) buffer[length - 1]; textWidth += textScale * _currentFont.GlyphScale * _currentFont.Glyphs[(char) c2].SkipX; } } } return (int) (rectDraw.Width / charSkip); }
private void CalculateClientRectangle(float offsetX, float offsetY) { _drawRect = _rect.Data; if((_flags & WindowFlags.InvertRectangle) == WindowFlags.InvertRectangle) { _drawRect.X = _rect.X - _rect.Width; _drawRect.Y = _rect.Y - _rect.Height; } if(((_flags & (WindowFlags.HorizontalCenter | WindowFlags.VerticalCenter)) != 0) && (_parent != null)) { // in this case treat xofs and yofs as absolute top left coords // and ignore the original positioning if((_flags & WindowFlags.HorizontalCenter) == WindowFlags.HorizontalCenter) { _drawRect.X = (_parent.Rectangle.Width - _rect.Width) / 2; } else { _drawRect.Y = (_parent.Rectangle.Height - _rect.Height) / 2; } } _drawRect.X += offsetX; _drawRect.Y += offsetY; _clientRect = _drawRect; if((_rect.Height > 0.0f) && (_rect.Width > 0.0f)) { if(((_flags & WindowFlags.Border) == WindowFlags.Border) && (_borderSize != 0.0f)) { _clientRect.X += _borderSize; _clientRect.Y += _borderSize; _clientRect.Width -= _borderSize; _clientRect.Height -= _borderSize; } _textRect = _clientRect; _textRect.X += 2; _textRect.Y += 2; _textRect.Width -= 2; _textRect.Height -= 2; _textRect.X += _textAlignX; _textRect.Y += _textAlignY; } _origin = new Vector2(_rect.X + (_rect.Width / 2), _rect.Y + (_rect.Height / 2)); }
public void ScreenToClient(ref idRectangle rect) { if(this.Disposed == true) { throw new ObjectDisposedException(this.GetType().Name); } int x, y; idWindow p; for(p = this, x = 0, y = 0; p != null; p = p.Parent) { x += (int) p.Rectangle.X; y += (int) p.Rectangle.Y; } rect.X -= x; rect.Y -= y; }
public void Set(Vector4 value) { _data = new idRectangle(value.X, value.Y, value.Z, value.W); }
public bool Contains(idRectangle rect, float x, float y) { if(this.Disposed == true) { throw new ObjectDisposedException(this.GetType().Name); } rect.X += _actualX - _drawRect.X; rect.Y += _actualY - _drawRect.Y; return rect.Contains(x, y); }
public override void Set(string value) { _data = idHelper.ParseRectangle(value); if(_guiDict != null) { _guiDict.Set(this.Name, _data); } }
public void Set(idRectangle value) { _data = value; if(_guiDict != null) { _guiDict.Set(this.Name, _data); } }
protected virtual void DrawBackground(idRectangle drawRect) { if(this.Disposed == true) { throw new ObjectDisposedException(this.GetType().Name); } if(_backColor.W != 0) { _context.DrawFilledRectangle(drawRect.X, drawRect.Y, drawRect.Width, drawRect.Height, _backColor); } if((_background != null) && (_materialColor.W != 0)) { float scaleX, scaleY; if((_flags & WindowFlags.NaturalMaterial) == WindowFlags.NaturalMaterial) { scaleX = _drawRect.Width / _background.ImageWidth; scaleY = _drawRect.Height / _background.ImageHeight; } else { scaleX = _materialScaleX; scaleY = _materialScaleY; } _context.DrawMaterial(_drawRect.X, _drawRect.Y, _drawRect.Width, _drawRect.Height, _background, _materialColor, scaleX, scaleY); } }
private void DrawBorderAndCaption(idRectangle drawRect) { if((_flags & WindowFlags.Border) == WindowFlags.Border) { if(_borderSize > 0) { _context.DrawRectangle(drawRect.X, drawRect.Y, drawRect.Width, drawRect.Height, _borderSize, _borderColor); } } }
public void InitWithDefaults(string name, idRectangle rect, Vector4 foreColor, Vector4 materialColor, string background, string thumbMaterial, bool vertical, bool scrollbar) { SetInitialState(name); _rect.Set(rect); _foreColor.Set(foreColor); _materialColor.Set(materialColor); _thumbMaterial = idE.DeclManager.FindMaterial(thumbMaterial); _thumbMaterial.Sort = (float) MaterialSort.Gui; _thumbWidth = _thumbMaterial.ImageWidth; _thumbHeight = _thumbMaterial.ImageHeight; _background = idE.DeclManager.FindMaterial(_backgroundName); _background.Sort = (float) MaterialSort.Gui; _vertical = vertical; _scrollBar = scrollbar; this.Flags |= WindowFlags.HoldCapture; }
public idSimpleWindow(idWindow win) { _gui = win.UserInterface; _context = win.DeviceContext; _drawRect = win.DrawRectangle; _clientRect = win.ClientRectangle; _textRect = win.TextRectangle; _origin = win.Origin; _fontFamily = win.FontFamily; _name = win.Name; _materialScaleX = win.MaterialScaleX; _materialScaleY = win.MaterialScaleY; _borderSize = win.BorderSize; _textAlign = win.TextAlign; _textAlignX = win.TextAlignX; _textAlignY = win.TextAlignY; _background = win.Background; _flags = win.Flags; _textShadow = win.TextShadow; _visible.Set(win.IsVisible); _text.Set(win.Text); _rect.Set(win.Rectangle); _backColor.Set(win.BackColor); _materialColor.Set(win.MaterialColor); _foreColor.Set(win.ForeColor); _borderColor.Set(win.BorderColor); _textScale.Set(win.TextScale); _rotate.Set(win.Rotate); _shear.Set(win.Shear); _backgroundName.Set(win.BackgroundName); if(_backgroundName != string.Empty) { _background = idE.DeclManager.FindMaterial(_backgroundName); _background.Sort = (float) MaterialSort.Gui; ; _background.ImageClassification = 1; // just for resource tracking } _backgroundName.Material = _background; _parent = win.Parent; _hideCursor.Set(win.HideCursor); if(_parent != null) { if(_text.NeedsUpdate == true) { _parent.AddUpdateVariable(_text); } if(_visible.NeedsUpdate == true) { _parent.AddUpdateVariable(_visible); } if(_rect.NeedsUpdate == true) { _parent.AddUpdateVariable(_rect); } if(_backColor.NeedsUpdate == true) { _parent.AddUpdateVariable(_backColor); } if(_materialColor.NeedsUpdate == true) { _parent.AddUpdateVariable(_materialColor); } if(_foreColor.NeedsUpdate == true) { _parent.AddUpdateVariable(_foreColor); } if(_borderColor.NeedsUpdate == true) { _parent.AddUpdateVariable(_borderColor); } if(_textScale.NeedsUpdate == true) { _parent.AddUpdateVariable(_textScale); } if(_rotate.NeedsUpdate == true) { _parent.AddUpdateVariable(_rotate); } if(_shear.NeedsUpdate == true) { _parent.AddUpdateVariable(_shear); } if(_backgroundName.NeedsUpdate == true) { _parent.AddUpdateVariable(_backgroundName); } } }
protected override void DrawBackground(idRectangle drawRect) { if((_cvar == null) && (this.Buddy == null)) { return; } if((_high - _low) <= 0.0f) { return; } idRectangle r = this.DrawRectangle; if(_scrollBar == false) { if(_vertical == true) { r.Y += _thumbHeight / 2.0f; r.Height -= _thumbHeight; } else { r.X += _thumbWidth / 2.0f; r.Width -= _thumbWidth; } } base.DrawBackground(r); }
public void PushClipRectangle(idRectangle rect) { _clipRectangles.Push(rect); }
private void EnsureCursorVisible() { if (_readOnly == true) { _cursorPosition = -1; } else if (_maxChars == 1) { _cursorPosition = 0; } if (this.DeviceContext == null) { return; } SetFont(); if (_wrap == false) { int cursorX = 0; if (_password == true) { cursorX = _cursorPosition * this.DeviceContext.GetCharacterWidth('*', this.TextScale); } else { int i = 0; int length = this.Text.Length; while ((i < length) && (i < _cursorPosition)) { if (idHelper.IsColor(this.Text, i) == true) { i += 2; } else { cursorX += this.DeviceContext.GetCharacterWidth(this.Text[i], this.TextScale); i++; } } } int maxWidth = (int)this.MaximumCharacterWidth; int left = cursorX - maxWidth; int right = (int)(cursorX - this.TextRectangle.Width) + maxWidth; if (_paintOffset > left) { // when we go past the left side, we want the text to jump 6 characters _paintOffset = left - maxWidth * 6; } if (_paintOffset < right) { _paintOffset = right; } if (_paintOffset < 0) { _paintOffset = 0; } _scroller.SetRange(0, 0, 1); } else { // word wrap _breaks.Clear(); idRectangle rect = this.TextRectangle; rect.Width -= _sizeBias; this.DeviceContext.DrawText(this.Text, this.TextScale, this.TextAlign, idColor.White, rect, true, ((this.Flags & WindowFlags.Focus) == WindowFlags.Focus) ? _cursorPosition : -1, true, _breaks); int fit = (int)(this.TextRectangle.Height / (this.MaximumCharacterHeight + 5)); if (fit < (_breaks.Count + 1)) { _scroller.SetRange(0, _breaks.Count + 1 - fit, 1); } else { // the text fits completely in the box _scroller.SetRange(0, 0, 1); } if (_forceScroll == true) { _scroller.Value = _breaks.Count - fit; } else if (_readOnly == true) { } else { _cursorLine = 0; int count = _breaks.Count; for (int i = 1; i < count; i++) { if (_cursorPosition >= _breaks[i]) { _cursorLine = i; } else { break; } } int topLine = (int)_scroller.Value; if (_cursorLine < topLine) { _scroller.Value = _cursorLine; } else if (_cursorLine >= (topLine + fit)) { _scroller.Value = (_cursorLine - fit) + 1; } } } }
protected override string RouteMouseCoordinates(float x, float y) { if ((this.Flags & WindowFlags.Capture) == 0) { return(string.Empty); } idRectangle rect = this.DrawRectangle; rect.X = this.ActualX; rect.Y = this.ActualY; rect.X += _thumbWidth / 2.0f; rect.Width -= _thumbWidth; float percent = 0; if (_vertical == true) { rect.Y += _thumbHeight / 2.0f; rect.Height -= _thumbHeight; if ((this.UserInterface.CursorY >= rect.Y) && (this.UserInterface.CursorY <= rect.Bottom)) { percent = (this.UserInterface.CursorY - rect.Y) / rect.Height; if (_verticalFlip == true) { percent = 1.0f - percent; } _value.Set(_low + (_high - _low) * percent); } else if (this.UserInterface.CursorY < rect.Y) { if (_verticalFlip == true) { _value.Set(_high); } else { _value.Set(_low); } } else { if (_verticalFlip == true) { _value.Set(_low); } else { _value.Set(_high); } } } else { rect.X += _thumbWidth / 2.0f; rect.Width -= _thumbWidth; if ((this.UserInterface.CursorX >= rect.X) && (this.UserInterface.CursorX <= rect.Right)) { percent = (this.UserInterface.CursorX - rect.X) / rect.Width; _value.Set(_low + (_high - _low) * percent); } else if (this.UserInterface.CursorX < rect.X) { _value.Set(_low); } else { _value.Set(_high); } } if (this.Buddy != null) { this.Buddy.HandleBuddyUpdate(this); } else { this.UserInterface.State.Set(_cvarStr.ToString(), _value); } UpdateConsoleVariables(false); return(string.Empty); }
public idSimpleWindow(idWindow win) { _gui = win.UserInterface; _context = win.DeviceContext; _drawRect = win.DrawRectangle; _clientRect = win.ClientRectangle; _textRect = win.TextRectangle; _origin = win.Origin; _fontFamily = win.FontFamily; _name = win.Name; _materialScaleX = win.MaterialScaleX; _materialScaleY = win.MaterialScaleY; _borderSize = win.BorderSize; _textAlign = win.TextAlign; _textAlignX = win.TextAlignX; _textAlignY = win.TextAlignY; _background = win.Background; _flags = win.Flags; _textShadow = win.TextShadow; _visible.Set(win.IsVisible); _text.Set(win.Text); _rect.Set(win.Rectangle); _backColor.Set(win.BackColor); _materialColor.Set(win.MaterialColor); _foreColor.Set(win.ForeColor); _borderColor.Set(win.BorderColor); _textScale.Set(win.TextScale); _rotate.Set(win.Rotate); _shear.Set(win.Shear); _backgroundName.Set(win.BackgroundName); if (_backgroundName != string.Empty) { _background = idE.DeclManager.FindMaterial(_backgroundName); _background.Sort = (float)MaterialSort.Gui;; _background.ImageClassification = 1; // just for resource tracking } _backgroundName.Material = _background; _parent = win.Parent; _hideCursor.Set(win.HideCursor); if (_parent != null) { if (_text.NeedsUpdate == true) { _parent.AddUpdateVariable(_text); } if (_visible.NeedsUpdate == true) { _parent.AddUpdateVariable(_visible); } if (_rect.NeedsUpdate == true) { _parent.AddUpdateVariable(_rect); } if (_backColor.NeedsUpdate == true) { _parent.AddUpdateVariable(_backColor); } if (_materialColor.NeedsUpdate == true) { _parent.AddUpdateVariable(_materialColor); } if (_foreColor.NeedsUpdate == true) { _parent.AddUpdateVariable(_foreColor); } if (_borderColor.NeedsUpdate == true) { _parent.AddUpdateVariable(_borderColor); } if (_textScale.NeedsUpdate == true) { _parent.AddUpdateVariable(_textScale); } if (_rotate.NeedsUpdate == true) { _parent.AddUpdateVariable(_rotate); } if (_shear.NeedsUpdate == true) { _parent.AddUpdateVariable(_shear); } if (_backgroundName.NeedsUpdate == true) { _parent.AddUpdateVariable(_backgroundName); } } }
public void Set(Vector4 value) { _data = new idRectangle(value.X, value.Y, value.Z, value.W); }
public int DrawText(string text, float textScale, TextAlign textAlign, Vector4 color, idRectangle rectDraw, bool wrap, int cursor = -1, bool calcOnly = false, List <int> breaks = null, int limit = 0) { float textWidth = 0; float charSkip = MaxCharacterWidth(textScale) + 1; float lineSkip = MaxCharacterHeight(textScale); float cursorSkip = (cursor >= 0) ? charSkip : 0; SetFontByScale(textScale); // TODO: edit cursor /*if (!calcOnly && !(text && *text)) { * if (cursor == 0) { * renderSystem->SetColor(color); * DrawEditCursor(rectDraw.x, lineSkip + rectDraw.y, textScale); * } * return idMath::FtoiFast( rectDraw.w / charSkip ); * }*/ char c; int textPosition = 0; int length = 0, newLine = 0, newLineWidth = 0, newLinePosition = 0, count = 0; bool lineBreak = false; bool wordBreak = false; float y = lineSkip + rectDraw.Y; StringBuilder buffer = new StringBuilder(); if (breaks != null) { breaks.Add(0); } while (true) { c = idHelper.GetBufferCharacter(text, textPosition); if ((c == '\n') || (c == '\r') || (c == '\0')) { lineBreak = true; if (((c == '\n') && (idHelper.GetBufferCharacter(text, textPosition + 1) == '\r')) || ((c == '\r') && (idHelper.GetBufferCharacter(text, textPosition + 1) == '\n'))) { textPosition++; c = idHelper.GetBufferCharacter(text, textPosition); } } int nextCharWidth = (int)((idHelper.CharacterIsPrintable(c) == true) ? GetCharacterWidth(c, textScale) : cursorSkip); // FIXME: this is a temp hack until the guis can be fixed not not overflow the bounding rectangles // the side-effect is that list boxes and edit boxes will draw over their scroll bars // The following line and the !linebreak in the if statement below should be removed nextCharWidth = 0; if ((lineBreak == false) && ((textWidth + nextCharWidth) > rectDraw.Width)) { // the next character will cause us to overflow, if we haven't yet found a suitable // break spot, set it to be this character if ((length > 0) && (newLine == 0)) { newLine = length; newLinePosition = textPosition; newLineWidth = (int)textWidth; } wordBreak = true; } else if ((lineBreak == true) || ((wrap == true) && ((c == ' ') || (c == '\t')))) { // The next character is in view, so if we are a break character, store our position newLine = length; newLinePosition = textPosition + 1; newLineWidth = (int)textWidth; } if ((lineBreak == true) || (wordBreak == true)) { float x = rectDraw.X; if (textAlign == TextAlign.Right) { x = rectDraw.X + rectDraw.Width - newLineWidth; } else if (textAlign == TextAlign.Center) { x = rectDraw.X + ((rectDraw.Width - newLineWidth) / 2); } if ((wrap == true) || (newLine > 0)) { // this is a special case to handle breaking in the middle of a word. // if we didn't do this, the cursor would appear on the end of this line // and the beginning of the next if ((wordBreak == true) && (cursor >= newLine) && (newLine == length)) { cursor++; } } if (calcOnly == false) { count += DrawText(x, y, textScale, color, buffer.ToString(0, (newLine > 0) ? newLine : length), 0, 0, 0, cursor); buffer.Clear(); } if (cursor < newLine) { cursor = -1; } else if (cursor >= 0) { cursor -= (newLine + 1); } if (wrap == false) { return(newLine); } if (((limit > 0) && (count > limit)) || (c == '\0')) { break; } y += lineSkip + 5; if ((calcOnly == false) && (y > rectDraw.Bottom)) { break; } textPosition = newLinePosition; if (breaks != null) { breaks.Add(textPosition); } length = 0; newLine = 0; newLineWidth = 0; textWidth = 0; lineBreak = false; wordBreak = false; } else { length++; buffer.Append(idHelper.GetBufferCharacter(text, textPosition++)); // update the width if ((buffer[length - 1] != (int)idColorIndex.Escape) && ((length <= 1) || (buffer[length - 2] != (int)idColorIndex.Escape))) { byte c2 = (byte)buffer[length - 1]; textWidth += textScale * _currentFont.GlyphScale * _currentFont.Glyphs[(char)c2].SkipX; } } } return((int)(rectDraw.Width / charSkip)); }
public void FixupParameters(idWindow window) { if (_handler == Script_Set) { bool precacheBackground = false; bool precacheSounds = false; idWinString str = (idWinString)_parameters[0].Variable; idWindowVariable dest = window.GetVariableByName(str.ToString(), true); if (dest != null) { _parameters[0].Variable = dest; _parameters[0].Owner = false; if (dest is idWinBackground) { precacheBackground = true; } } else if (str.ToString().ToLower() == "cmd") { precacheSounds = true; } int parameterCount = _parameters.Count; for (int i = 1; i < parameterCount; i++) { str = (idWinString)_parameters[i].Variable; string strValue = str.ToString(); if (strValue.StartsWith("gui::", StringComparison.InvariantCultureIgnoreCase) == true) { // always use a string here, no point using a float if it is one // FIXME: This creates duplicate variables, while not technically a problem since they // are all bound to the same guiDict, it does consume extra memory and is generally a bad thing idWinString defVar = new idWinString(null); defVar.Init(strValue, window); window.AddDefinedVariable(defVar); _parameters[i].Variable = defVar; _parameters[i].Owner = false; //dest = win->GetWinVarByName(*str, true); //if (dest) { // delete parms[i].var; // parms[i].var = dest; // parms[i].own = false; //} // } else if (strValue.StartsWith("$") == true) { // // dont include the $ when asking for variable dest = window.UserInterface.Desktop.GetVariableByName(strValue.Substring(1), true); // if (dest != null) { _parameters[i].Variable = dest; _parameters[i].Owner = false; } } else if (strValue.StartsWith("#str_") == true) { str.Set(idE.Language.Get(strValue)); } else if (precacheBackground == true) { idE.DeclManager.FindMaterial(strValue).Sort = (float)MaterialSort.Gui; } else if (precacheSounds == true) { idConsole.Warning("TODO: PrecacheSounds"); // Search for "play <...>" /*idToken token; * idParser parser( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT ); * parser.LoadMemory(str->c_str(), str->Length(), "command"); * * while ( parser.ReadToken(&token) ) { * if ( token.Icmp("play") == 0 ) { * if ( parser.ReadToken(&token) && ( token != "" ) ) { * declManager->FindSound( token.c_str() ); * } * } * }*/ } } } else if (_handler == Script_Transition) { if (_parameters.Count < 4) { idConsole.Warning("Window {0} in gui {1} has a bad transition definition", window.Name, window.UserInterface.SourceFile); } idWinString str = (idWinString)_parameters[0].Variable; // DrawWindow destOwner = null; idWindowVariable dest = window.GetVariableByName(str.ToString(), true, ref destOwner); // if (dest != null) { _parameters[0].Variable = dest; _parameters[0].Owner = false; } else { idConsole.Warning("Window {0} in gui {1}: a transition does not have a valid destination var {2}", window.Name, window.UserInterface.SourceFile, str); } // // support variables as parameters for (int c = 1; c < 3; c++) { str = (idWinString)_parameters[c].Variable; idWinVector4 v4 = new idWinVector4(null); _parameters[c].Variable = v4; _parameters[c].Owner = true; DrawWindow owner = null; if (str.ToString().StartsWith("$") == true) { dest = window.GetVariableByName(str.ToString().Substring(1), true, ref owner); } else { dest = null; } if (dest != null) { idWindow ownerParent; idWindow destParent; if (owner != null) { ownerParent = (owner.Simple != null) ? owner.Simple.Parent : owner.Window.Parent; destParent = (destOwner.Simple != null) ? destOwner.Simple.Parent : destOwner.Window.Parent; // if its the rectangle they are referencing then adjust it if ((ownerParent != null) && (destParent != null) && (dest == ((owner.Simple != null) ? owner.Simple.GetVariableByName("rect") : owner.Window.GetVariableByName("rect")))) { idRectangle rect = ((idWinRectangle)dest).Data; ownerParent.ClientToScreen(ref rect); destParent.ScreenToClient(ref rect); v4.Set(dest.ToString()); } else { v4.Set(dest.ToString()); } } else { v4.Set(dest.ToString()); } } else { v4.Set(str.ToString()); } } } else { int c = _parameters.Count; for (int i = 0; i < c; i++) { _parameters[i].Variable.Init(_parameters[i].Variable.ToString(), window); } } }
public void BeginFrame(int windowWidth, int windowHeight) { if(this.IsRunning == false) { return; } _guiModel.Clear(); // for the larger-than-window tiled rendering screenshots if(_tiledViewPort.X > 0) { windowWidth = (int) _tiledViewPort.X; windowHeight = (int) _tiledViewPort.Y; } idE.GLConfig.VideoWidth = windowWidth; idE.GLConfig.VideoHeight = windowHeight; _currentRenderCrop = 0; _renderCrops[0] = new idRectangle(0, 0, windowWidth, windowHeight); // screenFraction is just for quickly testing fill rate limitations if(idE.CvarSystem.GetInteger("r_screenFraction") != 100) { int w = (int) (idE.VirtualScreenWidth * idE.CvarSystem.GetInteger("r_screenFraction") / 100.0f); int h = (int) (idE.VirtualScreenHeight * idE.CvarSystem.GetInteger("r_screenFraction") / 100.0f); // TODO: CropRenderSize(w, h); idConsole.Warning("idRenderSystem.CropRenderSize"); } // this is the ONLY place this is modified _frameCount++; // just in case we did a common->Error while this // was set _guiRecursionLevel = 0; // the first rendering will be used for commands like // screenshot, rather than a possible subsequent remote // or mirror render // primaryWorld = NULL; // set the time for shader effects in 2D rendering _frameShaderTime = idE.EventLoop.Milliseconds * 0.001f; // // draw buffer stuff // SetBufferRenderCommand cmd = new SetBufferRenderCommand(); cmd.FrameCount = _frameCount; if(idE.CvarSystem.GetBool("r_frontBuffer") == true) { cmd.Buffer = Gl.GL_FRONT; } else { cmd.Buffer = Gl.GL_BACK; } _frameData.Commands.Enqueue(cmd); }