/// <summary> /// Move the window by the pixel offsets specified in \a offset. /// This is intended for internal system use - it is the method by /// which the title bar moves the frame window. /// </summary> /// <param name="offset"> /// Vector2 object containing the offsets to apply (offsets are in screen pixels). /// </param> public void OffsetPixelPosition(Lunatics.Mathematics.Vector2 offset) { var uOffset = new UVector2(UDim.Absolute(/*PixelAligned(*/ offset.X /*)*/), UDim.Absolute(/*PixelAligned(*/ offset.Y /*)*/)); SetPosition(d_area.Position + uOffset); }
private void LoadFntFile(Stream stream) { var fnt = XElement.Load(stream); var info = fnt.Element("info"); var common = fnt.Element("common"); var pages = fnt.Element("pages"); var face = info.Attribute("face").Value; d_ascender = XmlConvert.ToSingle(common.Attribute("base").Value); d_height = XmlConvert.ToSingle(common.Attribute("lineHeight").Value); d_descender = d_ascender - d_height; foreach (var page in pages.Elements("page")) { var pageId = page.Attribute("id").Value; var pageFile = page.Attribute("file").Value; System.GetSingleton().GetRenderer() .CreateTexture(d_name + "_glyph_images_page_id_" + pageId, pageFile, String.IsNullOrEmpty(d_resourceGroup) ? GetDefaultResourceGroup() : d_resourceGroup); } var chars = fnt.Element("chars"); foreach (var @char in chars.Elements("char")) { var pageId = d_name + "_glyph_images_page_id_" + @char.Attribute("page").Value; var charId = (char)XmlConvert.ToUInt32(@char.Attribute("id").Value); var area = new Rectf(new Lunatics.Mathematics.Vector2(XmlConvert.ToSingle(@char.Attribute("x").Value), XmlConvert.ToSingle(@char.Attribute("y").Value)), new Sizef(XmlConvert.ToSingle(@char.Attribute("width").Value), XmlConvert.ToSingle(@char.Attribute("height").Value))); var offset = new Lunatics.Mathematics.Vector2(XmlConvert.ToSingle(@char.Attribute("xoffset").Value), XmlConvert.ToSingle(@char.Attribute("yoffset").Value) - d_ascender); d_cp_map[charId] = new FntGlyph(XmlConvert.ToSingle(@char.Attribute("xadvance").Value), new BitmapImage(charId.ToString(global::System.Globalization.CultureInfo.InvariantCulture), System.GetSingleton().GetRenderer().GetTexture(pageId), area, offset, d_autoScaled, d_nativeResolution), true); if (d_maxCodepoint < charId) { d_maxCodepoint = charId; } } //foreach (var kerning in chars.Elements("kerning")) //{ // var first = XmlConvert.ToChar(kerning.Attribute("first").Value); // var second = XmlConvert.ToChar(kerning.Attribute("second").Value); // var amount = XmlConvert.ToSingle(kerning.Attribute("amount").Value); // if (!_kerningPairs.ContainsKey(first)) // _kerningPairs.Add(first, new Dictionary<char, float>()); // _kerningPairs[first].Add(second, amount); //} }
private bool handleCursorMoveEvent(SemanticInputEvent @event) { var new_position = new Lunatics.Mathematics.Vector2( @event.d_payload.array[0], @event.d_payload.array[1]); // setup cursor movement event args object. var ciea = new CursorInputEventArgs(null); ciea.moveDelta = new_position - _cursor.GetPosition(); // no movement means no event if ((ciea.moveDelta.X == 0) && (ciea.moveDelta.Y == 0)) { return(false); } ciea.scroll = 0; ciea.Source = CursorInputSource.None; ciea.state = d_cursorsState; // move cursor to new position _cursor.SetPosition(new_position); // update position in args (since actual position may be constrained) ciea.Position = _cursor.GetPosition(); return(HandleCursorMoveImpl(ciea)); }
private bool CalculateTextureAndRenderAreas(Rectf renderSettingDestArea, ref Rectf?clippingArea, out Rectf finalRect, ref Rectf texRect) { var dest = (renderSettingDestArea); // apply rendering offset to the destination Rect dest.Offset(d_scaledOffset); // get the rect area that we will actually draw to (i.e. perform clipping) finalRect = clippingArea.HasValue ? dest.GetIntersection(clippingArea.Value) : dest; // check if rect was totally clipped if ((finalRect.Width == 0) || (finalRect.Height == 0)) { return(true); } // Obtain correct scale values from the texture var texelScale = _texture.GetTexelScaling(); var texPerPix = new Lunatics.Mathematics.Vector2(d_imageArea.Width / dest.Width, d_imageArea.Height / dest.Height); // calculate final, clipped, texture co-ordinates texRect = new Rectf((d_imageArea.d_min + ((finalRect.d_min - dest.d_min) * texPerPix)) * texelScale, (d_imageArea.d_max + ((finalRect.d_max - dest.d_max) * texPerPix)) * texelScale); // TODO: This is clearly not optimal but the only way to go with the current // Font rendering system. Distance field rendering would allow us to ignore the // pixel alignment. finalRect.d_min.X = CoordConverter.AlignToPixels(finalRect.d_min.X); finalRect.d_min.Y = CoordConverter.AlignToPixels(finalRect.d_min.Y); finalRect.d_max.X = CoordConverter.AlignToPixels(finalRect.d_max.X); finalRect.d_max.Y = CoordConverter.AlignToPixels(finalRect.d_max.Y); return(false); }
/// <summary> /// Constructor /// </summary> /// <param name="name"></param> /// <param name="texture"></param> /// <param name="pixelArea"></param> /// <param name="pixelOffset"></param> /// <param name="autoScaled"></param> /// <param name="nativeResolution"></param> public BitmapImage(string name, Texture texture, Rectf pixelArea, Lunatics.Mathematics.Vector2 pixelOffset, AutoScaledMode autoScaled, Sizef nativeResolution) : base(name, pixelOffset, pixelArea, autoScaled, nativeResolution) { _texture = texture; }
/// <summary> /// Set the current mouse cursor position /// </summary> /// <param name="position"> /// Point object describing the new location for the mouse. This will be clipped to within the renderer screen area. /// </param> public void SetPosition(Lunatics.Mathematics.Vector2 position) { d_position = position; ConstrainPosition(); UpdateGeometryBuffersTranslation(); }
/// <summary> /// Set the appropriate mouse cursor for the given window-relative pixel point. /// </summary> /// <param name="pt"></param> protected void SetCursorForPoint(Lunatics.Mathematics.Vector2 pt) { switch (GetSizingBorderAtPoint(pt)) { case SizingLocation.SizingTop: case SizingLocation.SizingBottom: GetGUIContext().GetCursor().SetImage(_nsSizingCursor); break; case SizingLocation.SizingLeft: case SizingLocation.SizingRight: GetGUIContext().GetCursor().SetImage(_ewSizingCursor); break; case SizingLocation.SizingTopLeft: case SizingLocation.SizingBottomRight: GetGUIContext().GetCursor().SetImage(_nwseSizingCursor); break; case SizingLocation.SizingTopRight: case SizingLocation.SizingBottomLeft: GetGUIContext().GetCursor().SetImage(_neswSizingCursor); break; default: GetGUIContext().GetCursor().SetImage(GetCursor()); break; } }
/// <summary> /// Update the internal state of the widget with the mouse at the given position. /// </summary> /// <param name="mousePos"> /// Point object describing, in screen pixel co-ordinates, the location of the mouse cursor. /// </param> protected void UpdateInternalState(Lunatics.Mathematics.Vector2 mousePos) { bool oldstate = _hovering; // assume not hovering _hovering = false; // if input is captured, but not by 'this', then we never hover highlight var captureWnd = GetCaptureWindow(); if (captureWnd == null) { _hovering = (GetGUIContext().GetWindowContainingCursor() == this && IsHit(mousePos)); } else { _hovering = (captureWnd == this && IsHit(mousePos)); } // if state has changed, trigger a re-draw // and possible make the parent menu open another popup if (oldstate != _hovering) { // are we attached to a menu ? var menu = OwnerList as MenuBase; if (menu != null) { if (_hovering) { // does this menubar only allow one popup open? and is there a popup open? var curpopup = menu.GetPopupMenuItem(); if (!menu.IsMultiplePopupsAllowed()) { if (curpopup != this && curpopup != null) { if (!HasAutoPopup()) { // open this popup instead OpenPopupMenu(); } else { // start close timer on current popup menu.SetPopupMenuItemClosing(); StartPopupOpening(); } } else { StartPopupOpening(); } } } } Invalidate(false); } }
/// <summary> /// Offset the mouse cursor position by the deltas specified in \a offset. /// </summary> /// <param name="offset"> /// Point object which describes the amount to move the cursor in each axis. /// </param> public void OffsetPosition(Lunatics.Mathematics.Vector2 offset) { d_position.X += offset.X; d_position.Y += offset.Y; ConstrainPosition(); UpdateGeometryBuffersTranslation(); }
/*! * \brief * Given window location \a pt, return a value indicating what change should be * made to the slider. * * \param pt * Point object describing a pixel position in window space. * * \return * - -1 to indicate slider should be moved to a lower setting. * - 0 to indicate slider should not be moved. * - +1 to indicate slider should be moved to a higher setting. */ protected virtual float GetAdjustDirectionFromPoint(Lunatics.Mathematics.Vector2 pt) { if (d_windowRenderer != null) { return(((SliderWindowRenderer)d_windowRenderer).GetAdjustDirectionFromPoint(pt)); } throw new InvalidRequestException("This function must be implemented by the window renderer module"); }
/// <summary> /// Return whether the required minimum movement threshold before initiating dragging /// has been exceeded. /// </summary> /// <param name="localMouse"> /// Mouse position as a pixel offset from the top-left corner of this window. /// </param> /// <returns> /// - true if the threshold has been exceeded and dragging should be initiated. /// - false if the threshold has not been exceeded. /// </returns> protected bool IsDraggingThresholdExceeded(Lunatics.Mathematics.Vector2 localMouse) { // calculate amount mouse has moved. var deltaX = Math.Abs(localMouse.X - CoordConverter.AsAbsolute(_dragPoint.d_x, d_pixelSize.Width)); var deltaY = Math.Abs(localMouse.Y - CoordConverter.AsAbsolute(_dragPoint.d_y, d_pixelSize.Height)); // see if mouse has moved far enough to start dragging operation return(deltaX > _dragThreshold || deltaY > _dragThreshold); }
public override void AutoPositionSize(Lunatics.Mathematics.Vector2 position, Sizef ownerSize) { var view = GetView(); var totalArea = view.GetUnclippedOuterRect().Get(); var contentArea = _itemViewRenderer.GetViewRenderArea(view, false, false); var withScrollContentArea = _itemViewRenderer.GetViewRenderArea(view, true, true); var frameSize = totalArea.Size - contentArea.Size; var withScrollFrameSize = totalArea.Size - withScrollContentArea.Size; var contentSize = new Sizef(view.GetRenderedMaxWidth(), view.GetRenderedTotalHeight()); var parentSize = view.GetParentPixelSize(); var maxSize = new Sizef(ownerSize.Width /*parentSize.Width - CoordConverter.AsAbsolute(view.GetXPosition(), parentSize.Width)*/, 0.8f * parentSize.Height /*CoordConverter.AsAbsolute(view.GetYPosition(), parentSize.Height)*/); var requiredSize = frameSize + contentSize + new Sizef(1, 1); if (requiredSize.Height > maxSize.Height) { requiredSize.Height = maxSize.Height; requiredSize.Width = Math.Min(maxSize.Width, requiredSize.Width - frameSize.Width + withScrollFrameSize.Width); view.SetVertScrollbarDisplayMode(ScrollbarDisplayMode.Shown); } else { view.SetVertScrollbarDisplayMode(ScrollbarDisplayMode.Hidden); } requiredSize.Width = ownerSize.Width; if (requiredSize.Width > maxSize.Width) { requiredSize.Width = maxSize.Width; requiredSize.Height = Math.Min(maxSize.Height, requiredSize.Height - frameSize.Height + withScrollFrameSize.Height); view.SetHorzScrollbarDisplayMode(ScrollbarDisplayMode.Shown); } else { view.SetHorzScrollbarDisplayMode(ScrollbarDisplayMode.Hidden); } var posY = position.Y + (ownerSize.Height - requiredSize.Height) / 2f; posY = posY < 0f ? 0f : posY; posY -= posY + requiredSize.Height > parentSize.Height //? parentSize.Height - (posY + requiredSize.Height + 1f) ? (posY + requiredSize.Height) - parentSize.Height : 0f; view.SetPosition(new UVector2(UDim.Absolute(position.X), UDim.Absolute(posY))); view.SetHeight(new UDim(0, requiredSize.Height)); view.SetWidth(new UDim(0, requiredSize.Width)); }
/// <summary> /// Given window location \a pt, return a value indicating what change /// should be made to the scroll bar. /// </summary> /// <param name="pt"> /// Point object describing a pixel position in window space. /// </param> /// <returns> /// - -1 to indicate scroll bar position should be moved to a lower value. /// - 0 to indicate scroll bar position should not be changed. /// - +1 to indicate scroll bar position should be moved to a higher value. /// </returns> protected float GetAdjustDirectionFromPoint(Lunatics.Mathematics.Vector2 pt) { if (d_windowRenderer == null) { throw new InvalidRequestException( "This function must be implemented by the window renderer object (no window renderer is assigned.)"); } return(((ScrollbarWindowRenderer)d_windowRenderer).GetAdjustDirectionFromPoint(pt)); }
/// <summary> /// Return the text code point index that is rendered closest to screen /// position \a pt. /// </summary> /// <param name="pt"> /// Point object describing a position on the screen in pixels. /// </param> /// <returns> /// Code point index into the text that is rendered closest to screen /// position \a pt. /// </returns> protected override int GetTextIndexFromPosition(Lunatics.Mathematics.Vector2 pt) { if (d_windowRenderer != null) { var wr = (EditboxWindowRenderer)d_windowRenderer; return(wr.GetTextIndexFromPosition(pt)); } throw new InvalidRequestException("This function must be implemented by the window renderer"); }
/// <summary> /// Update the internal state of the widget with the mouse at the given position. /// </summary> /// <param name="mousePos"> /// Point object describing, in screen pixel co-ordinates, the location of the mouse cursor. /// </param> protected void UpdateInternalState(Lunatics.Mathematics.Vector2 mousePos) { var oldstate = _hovering; _hovering = CalculateCurrentHoverState(mousePos); if (oldstate != _hovering) { Invalidate(false); } }
/// <summary> /// Update state for window dragging. /// </summary> /// <param name="localMouse"> /// Mouse position as a pixel offset from the top-left corner of this window. /// </param> protected void DoDragging(Lunatics.Mathematics.Vector2 localMouse) { // calculate amount to move var offset = new UVector2(UDim.Absolute(localMouse.X), UDim.Absolute(localMouse.Y)); offset -= (_usingFixedDragOffset) ? _fixedDragOffset : _dragPoint; // set new position SetPosition(GetPosition() + offset); // Perform event notification OnDragPositionChanged(new WindowEventArgs(this)); }
/// <summary> /// Return true if the given <see cref="Vector2f"/> falls within this <see cref="Rectf"/> /// </summary> /// <param name="v"> /// <see cref="Vector2f"/> object describing the position to test. /// </param> /// <returns> /// true if position \a pt is within this <see cref="Rectf"/>'s area, else false /// </returns> public bool IsPointInRect(Lunatics.Mathematics.Vector2 v) { if ((d_min.X > v.X) || (d_max.X <= v.X) || (d_min.Y > v.Y) || (d_max.Y <= v.Y)) { return(false); } return(true); }
public override List <GeometryBuffer> CreateRenderGeometry(Window refWnd, Lunatics.Mathematics.Vector2 position, ColourRect modColours, Rectf?clipRect) { var drawPos = position; var geomBuffers = new List <GeometryBuffer>(); for (var i = 0; i < d_renderedString.GetLineCount(); ++i) { geomBuffers.AddRange(d_renderedString.CreateRenderGeometry(refWnd, i, drawPos, modColours, clipRect, SpaceExtras[i])); drawPos.Y += d_renderedString.GetPixelSize(refWnd, i).Height; } return(geomBuffers); }
/// <summary> /// Sets the pixel offset of this Image. /// </summary> /// <param name="pixelOffset"> /// The pixel offset of this Image. /// </param> public void SetOffset(Lunatics.Mathematics.Vector2 pixelOffset) { d_pixelOffset = pixelOffset; if (d_autoScaled != AutoScaledMode.Disabled) { UpdateScaledOffset(System.GetSingleton().GetRenderer().GetDisplaySize()); } else { d_scaledOffset = d_pixelOffset; } }
/// <summary> /// Create render geometry for the text that should be rendered into a /// specified area of the display. /// </summary> /// <param name="buffer"> /// GeometryBuffer object where the geometry for the text be queued. /// </param> /// <param name="text"> /// String object containing the text to be drawn. /// </param> /// <param name="position"> /// Reference to a Vector2 object describing the location at which the text /// is to be drawn. /// </param> /// <param name="clipRect"> /// Rect object describing the clipping area for the drawing. /// No drawing will occur outside this Rect. /// </param> /// <param name="clippingEnabled"></param> /// <param name="colours"> /// ColourRect object describing the colours to be applied when drawing the /// text. NB: The colours specified in here are applied to each glyph, /// rather than the text as a whole. /// </param> /// <param name="spaceExtra"> /// Number of additional pixels of spacing to be added to space characters. /// </param> /// <param name="xScale"> /// Scaling factor to be applied to each glyph's x axis, where 1.0f is /// considered to be 'normal'. /// </param> /// <param name="yScale"> /// Scaling factor to be applied to each glyph's y axis, where 1.0f is /// considered to be 'normal'. /// </param> /// <returns> /// Returns a list of GeometryBuffers representing the render geometry of the text. /// </returns> public List <GeometryBuffer> CreateRenderGeometryForText(string text, Lunatics.Mathematics.Vector2 position, Rectf?clipRect, bool clippingEnabled, ColourRect colours, float spaceExtra = 0.0f, float xScale = 1.0f, float yScale = 1.0f) { float nextGlyphPos; return(CreateRenderGeometryForText(text, out nextGlyphPos, position, clipRect, clippingEnabled, colours, spaceExtra, xScale, yScale)); }
public override List <GeometryBuffer> CreateRenderGeometry(Window refWnd, Lunatics.Mathematics.Vector2 position, ColourRect modColours, Rectf?clipRect) { var linePos = position; var geomBuffers = new List <GeometryBuffer>(); foreach (var i in Lines) { geomBuffers.AddRange(i.CreateRenderGeometry(refWnd, linePos, modColours, clipRect)); linePos.Y += i.GetVerticalExtent(refWnd); } return(geomBuffers); }
// overridden from EditboxWindowRenderer base class. public override int GetTextIndexFromPosition(Lunatics.Mathematics.Vector2 pt) { var w = (Editbox)Window; // calculate final window position to be checked var wndx = CoordConverter.ScreenToWindowX(w, pt.X); wndx -= _lastTextOffset; // Return the proper index return(w.GetFont().GetCharAtPixel(w.IsTextMaskingEnabled() ? new string(w.GetTextMaskCodePoint(), w.GetTextVisual().Length) : w.GetTextVisual(), wndx)); }
protected bool CalculateCurrentHoverState(Lunatics.Mathematics.Vector2 mousePos) { var captureWnd = GetCaptureWindow(); if (captureWnd != null) { return((captureWnd == this || (captureWnd.DistributesCapturedInputs() && IsAncestor(captureWnd))) && IsHit(mousePos)); } return(GetGUIContext().GetWindowContainingCursor() == this); }
/// <summary> /// Return whether the required minimum movement threshold before initiating drag-moving /// has been exceeded. /// </summary> /// <param name="localMouse"> /// Mouse position as a pixel offset from the top-left corner of this window. /// </param> /// <returns> /// true if the threshold has been exceeded and drag-moving should be initiated, or false /// if the threshold has not been exceeded. /// </returns> protected bool IsDragMoveThresholdExceeded(Lunatics.Mathematics.Vector2 localMouse) { // see if mouse has moved far enough to start move operation // calculate movement deltas. var deltaX = localMouse.X - _dragPoint.X; var deltaY = localMouse.Y - _dragPoint.Y; if ((deltaX > SegmentMoveThreshold) || (deltaX < -SegmentMoveThreshold) || (deltaY > SegmentMoveThreshold) || (deltaY < -SegmentMoveThreshold)) { return(true); } return(false); }
/// <summary> /// Update state for drag moving. /// </summary> /// <param name="localMouse"> /// Mouse position as a pixel offset from the top-left corner of this window. /// </param> protected void DoDragMoving(Lunatics.Mathematics.Vector2 localMouse) { // calculate movement deltas. var deltaX = localMouse.X - _dragPoint.X; var deltaY = localMouse.Y - _dragPoint.Y; // update 'ghost' position _dragPosition.X += deltaX; _dragPosition.Y += deltaY; // update drag point. _dragPoint.X += deltaX; _dragPoint.Y += deltaY; OnSegmentDragPositionChanged(new WindowEventArgs(this)); }
public virtual bool InjectMousePosition(float xPos, float yPos) { if (d_inputReceiver == null) { return(false); } d_pointerPosition = new Lunatics.Mathematics.Vector2(xPos, yPos); var semanticEvent = new SemanticInputEvent((int)SemanticValue.SV_CursorMove) { d_payload = { array = new[] { xPos, yPos } } }; return(d_inputReceiver.InjectInputEvent(semanticEvent)); }
/// <summary> /// Set the two dimensional position of the RenderingWindow in pixels. The /// origin is at the top-left corner. /// </summary> /// <param name="position"> /// Vector2 object describing the desired location of the RenderingWindow, /// in pixels. /// </param> /// <remarks> /// This position is an absolute pixel location relative to the screen or /// other root surface. It is \e not relative to the owner of the /// RenderingWindow. /// </remarks> public void SetPosition(Lunatics.Mathematics.Vector2 position) { d_position = position; var trans = new Lunatics.Mathematics.Vector3(d_position.X, d_position.Y, 0.0f); // geometry position must be offset according to our owner position, if // that is a RenderingWindow. if (d_owner.IsRenderingWindow()) { trans.X -= ((RenderingWindow)d_owner).d_position.X; trans.Y -= ((RenderingWindow)d_owner).d_position.Y; } d_geometry.SetTranslation(trans); }
protected Image(string name, Lunatics.Mathematics.Vector2 pixelOffset, Rectf imageArea, AutoScaledMode autoScaled, Sizef nativeResolution) { d_name = name; d_pixelOffset = pixelOffset; d_imageArea = imageArea; d_autoScaled = autoScaled; d_nativeResolution = nativeResolution; d_scaledSize = Sizef.Zero; d_scaledOffset = Lunatics.Mathematics.Vector2.Zero; // force initialisation of the autoscaling fields. UpdateScaledSizeAndOffset(System.GetSingleton().GetRenderer().GetDisplaySize()); }
/// <summary> /// Causes the tooltip to position itself appropriately. /// </summary> public void PositionSelf() { // no recusion allowed for this function! if (_inPositionSelf) { return; } _inPositionSelf = true; var cursor = GetGUIContext().GetCursor(); var screen = new Rectf(Lunatics.Mathematics.Vector2.Zero, GetRootContainerSize()); var tipRect = GetUnclippedOuterRect().Get(); var mouseImage = cursor.GetImage(); var mousePos = cursor.GetPosition(); var mouseSz = Sizef.Zero; if (mouseImage != null) { mouseSz = mouseImage.GetRenderedSize(); } var tmpPos = new Lunatics.Mathematics.Vector2(mousePos.X + mouseSz.Width, mousePos.Y + mouseSz.Height); tipRect.Position = tmpPos; // if tooltip would be off the right of the screen, // reposition to the other side of the mouse cursor. if (screen.Right < tipRect.Right) { tmpPos.X = mousePos.X - tipRect.Width - 5; } // if tooltip would be off the bottom of the screen, // reposition to the other side of the mouse cursor. if (screen.Bottom < tipRect.Bottom) { tmpPos.Y = mousePos.Y - tipRect.Height - 5; } // set final position of tooltip window. SetPosition(new UVector2(UDim.Absolute(tmpPos.X), UDim.Absolute(tmpPos.Y))); _inPositionSelf = false; }
public override float GetAdjustDirectionFromPoint(Lunatics.Mathematics.Vector2 pt) { var w = (Slider)Window; var absrect = w.GetThumb().GetUnclippedOuterRect().Get(); if ((_vertical && (pt.Y < absrect.Top)) || (!_vertical && (pt.X > absrect.Right))) { return(_reversed ? -1.0f : 1.0f); } if ((_vertical && (pt.Y > absrect.Bottom)) || (!_vertical && (pt.X < absrect.Left))) { return(_reversed ? 1.0f : -1.0f); } return(0); }