public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha) { Stage stage = Stage; Validate(); ISceneDrawable handle = _style.Handle; ApplyTransform(spriteBatch, ComputeTransform()); Matrix transform = spriteBatch.TransformMatrix; if (_firstWidget != null) { _firstScissors = ScissorStack.CalculateScissors(stage.Camera, spriteBatch.TransformMatrix, (Rectangle)_firstWidgetBounds); if (stage.ScissorStack.PushScissors(_firstScissors)) { if (_firstWidget.IsVisible) { _firstWidget.Draw(spriteBatch, parentAlpha * Color.A / 255f); } spriteBatch.Flush(); stage.ScissorStack.PopScissors(); } } if (_secondWidget != null) { _secondScissors = ScissorStack.CalculateScissors(stage.Camera, spriteBatch.TransformMatrix, (Rectangle)_secondWidgetBounds); if (stage.ScissorStack.PushScissors(_secondScissors)) { if (_secondWidget.IsVisible) { _secondWidget.Draw(spriteBatch, parentAlpha * Color.A / 255f); } spriteBatch.Flush(); stage.ScissorStack.PopScissors(); } } spriteBatch.Color = Color; handle.Draw(spriteBatch, _handleBounds.X, _handleBounds.Y, _handleBounds.Width, _handleBounds.Height); ResetTransform(spriteBatch); }
protected void DrawChildren(GdxSpriteBatch spriteBatch, float parentAlpha) { parentAlpha *= Color.A / 255f; IList <Actor> actors = Children.Begin(); if (_cullingArea != null) { RectangleF cull = _cullingArea.Value; float cullLeft = cull.X; float cullRight = cullLeft + cull.Width; float cullBottom = cull.Y; float cullTop = cullBottom + cull.Height; // Draw children only if inside the culling area. if (IsTransform) { foreach (Actor child in actors) { if (!child.IsVisible) { continue; } float cx = child.X; float cy = child.Y; if (cx <= cullRight && cy <= cullTop && cx + child.Width >= cullLeft && cy + child.Height >= cullBottom) { child.Draw(spriteBatch, parentAlpha); } } spriteBatch.Flush(); } else { // No transform for this group, offset each child. float offsetX = X; float offsetY = Y; X = 0; Y = 0; foreach (Actor child in actors) { if (!child.IsVisible) { continue; } float cx = child.X; float cy = child.Y; if (cx <= cullRight && cy <= cullTop && cx + child.Width >= cullLeft && cy + child.Height >= cullBottom) { child.X = cx + offsetX; child.Y = cy + offsetY; child.Draw(spriteBatch, parentAlpha); child.X = cx; child.Y = cy; } } X = offsetX; Y = offsetY; } } else { // No culling, draw all children if (IsTransform) { foreach (Actor child in actors) { if (!child.IsVisible) { continue; } child.Draw(spriteBatch, parentAlpha); } spriteBatch.Flush(); } else { // No transform for this group, offset each child. float offsetX = X; float offsetY = Y; X = 0; Y = 0; foreach (Actor child in actors) { if (!child.IsVisible) { continue; } float cx = child.X; float cy = child.Y; child.X = cx + offsetX; child.Y = cy + offsetY; child.Draw(spriteBatch, parentAlpha); child.X = cx; child.Y = cy; } X = offsetX; Y = offsetY; } } Children.End(); }
public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha) { if (_widget == null) { return; } Validate(); // Setup transform for this group ApplyTransform(spriteBatch, ComputeTransform()); if (IsScrollX) { _hKnobBounds.X = _hScrollBounds.X + (int)((_hScrollBounds.Width - _hKnobBounds.Width) * ScrollPercentX); } if (IsScrollY) { _vKnobBounds.Y = _vScrollBounds.Y + (int)((_vScrollBounds.Height - _vKnobBounds.Height) * (1 - ScrollPercentY)); } // Calculate the widget's position depending on the scroll state and available widget area. float y = _widgetAreaBounds.Y; if (!IsScrollY) { y -= (int)MaxY; } else { y -= (int)(MaxY - _visualAmountY); } if (!_fadeScrollBars && ScrollBarsOnTop && IsScrollX) { float scollbarHeight = 0; if (_style.HScrollKnob != null) { scollbarHeight = _style.HScrollKnob.MinHeight; } if (_style.HScroll != null) { scollbarHeight = Math.Max(scollbarHeight, _style.HScroll.MinHeight); } y += scollbarHeight; } float x = _widgetAreaBounds.X; if (IsScrollX) { x -= (int)_visualAmountX; } _widget.SetPosition(x, y); if (_widget is ICullable) { _widgetCullingArea.X = -_widget.X + _widgetAreaBounds.X; _widgetCullingArea.Y = -_widget.Y + _widgetAreaBounds.Y; _widgetCullingArea.Width = _widgetAreaBounds.Width; _widgetCullingArea.Height = _widgetAreaBounds.Height; (_widget as ICullable).SetCullingArea(_widgetCullingArea); } // Caculate the scissor bounds based on the batch transform, the available widget area and the camera transform. We need to // project those to screen coordinates for OpenGL ES to consume. _scissorBounds = ScissorStack.CalculateScissors(Stage.Camera, spriteBatch.TransformMatrix, (Rectangle)_widgetAreaBounds); // Draw the background ninepatch spriteBatch.Color = Color.MultiplyAlpha(parentAlpha); if (_style.Background != null) { _style.Background.Draw(spriteBatch, 0, 0, Width, Height); } spriteBatch.Flush(); // Enable scissors for widget area and draw the widget. if (Stage.ScissorStack.PushScissors(_scissorBounds)) { DrawChildren(spriteBatch, parentAlpha); Stage.ScissorStack.PopScissors(); } // Render scrollbars and knobs on top. spriteBatch.Color = Color.MultiplyAlpha(parentAlpha * Interpolation.Fade.Apply(_fadeAlpha / FadeAlphaSeconds)); if (IsScrollX && IsScrollY) { if (_style.Corner != null) { _style.Corner.Draw(spriteBatch, _hScrollBounds.X + _hScrollBounds.Width, _hScrollBounds.Y, _vScrollBounds.Width, _vScrollBounds.Height); } } if (IsScrollX) { if (_style.HScroll != null) { _style.HScroll.Draw(spriteBatch, _hScrollBounds.X, _hScrollBounds.Y, _hScrollBounds.Width, _hScrollBounds.Height); } if (_style.HScrollKnob != null) { _style.HScrollKnob.Draw(spriteBatch, _hKnobBounds.X, _hKnobBounds.Y, _hKnobBounds.Width, _hKnobBounds.Height); } } if (IsScrollY) { if (_style.VScroll != null) { _style.VScroll.Draw(spriteBatch, _vScrollBounds.X, _vScrollBounds.Y, _vScrollBounds.Width, _vScrollBounds.Height); } if (_style.VScrollKnob != null) { _style.VScrollKnob.Draw(spriteBatch, _vKnobBounds.X, _vKnobBounds.Y, _vKnobBounds.Width, _vKnobBounds.Height); } } ResetTransform(spriteBatch); }