本文整理汇总了C#中Canvas.DrawRect方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.DrawRect方法的具体用法?C# Canvas.DrawRect怎么用?C# Canvas.DrawRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Canvas
的用法示例。
在下文中一共展示了Canvas.DrawRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public override void Draw(Canvas canvas)
{
canvas.State.ColorTint = Theme.ForegroundColour;
canvas.DrawRect(X, Y, w, h);
canvas.FillRect(X, Y, w, topWidth);
canvas.State.ColorTint = Theme.BackgroundColour;
canvas.FillRect(X + 1, Y + topWidth + 1, W - 2, h - topWidth - 2);
base.Draw(canvas);
}
示例2: Draw
public override void Draw(Canvas canvas)
{
text.Draw(canvas);
Vector2 realCaretPosition = text.getPositionFromCaret(caretPosition);
Vector2 characterSize = canvas.MeasureText("A");
canvas.State.ColorTint = Theme.ForegroundColour;
canvas.DrawRect(X, Y, W, H);
canvas.FillRect(realCaretPosition.X, realCaretPosition.Y, characterSize.X, characterSize.Y);
}
示例3: OnRender
public override void OnRender(Canvas c)
{
c.DrawFillRect(_client_area, _background_color_material);
_font.DrawText(null, _text, ClientArea, DrawTextFormat.VerticalCenter | DrawTextFormat.Center, ForegroundColor);
c.DrawRect(_client_area, BorderColor);
}
示例4: DrawTestImageRow
private void DrawTestImageRow(Canvas c, int baseX, int baseY)
{
Vector2[] polygon = new Vector2[]
{
new Vector2(0.0f, 0.0f),
new Vector2(50.0f, 0.0f),
new Vector2(50.0f, 45.0f),
new Vector2(5.0f, 50.0f),
};
int x = baseX;
int y = baseY;
// Outline Shapes
c.PushState();
{
c.DrawCircle(x, y, 25);
x += 100;
c.DrawCircleSegment(x, y, 25, 0.0f, MathF.RadAngle30 * 4, true);
x += 100;
c.DrawLine(x, y , x + 50, y + 25);
c.DrawDashLine(x, y + 25, x + 50, y + 50);
c.DrawThickLine(x, y + 50, x + 50, y + 75, 3);
x += 100;
c.DrawOval(x, y, 50, 50);
x += 100;
c.DrawOvalSegment(x, y, 50, 50, 0.0f, MathF.RadAngle30 * 4, true);
x += 100;
c.DrawPolygon(polygon, x, y);
x += 100;
c.DrawRect(x, y, 50, 50);
x += 100;
c.DrawText("Hello World", x, y, drawBackground: true);
x = baseX;
y += 100;
}
c.PopState();
// Filled Shapes
c.PushState();
{
c.FillCircle(x, y, 25);
x += 100;
c.FillCircleSegment(x, y, 0, 25, MathF.RadAngle30 * 0, MathF.RadAngle30 * 4);
c.FillCircleSegment(x, y, 0, 25, MathF.RadAngle30 * 5, MathF.RadAngle30 * 9, 10);
x += 100;
c.FillThickLine(x, y + 25, x + 50, y + 50, 3);
x += 100;
c.FillOval(x, y, 50, 50);
x += 100;
c.FillOvalSegment(x, y, 0, 50, 50, MathF.RadAngle30 * 0, MathF.RadAngle30 * 4);
c.FillOvalSegment(x, y, 0, 50, 50, MathF.RadAngle30 * 5, MathF.RadAngle30 * 9, 10);
x += 100;
c.FillPolygon(polygon, x, y);
x += 100;
c.FillRect(x, y, 50, 50);
x = baseX;
y += 100;
}
c.PopState();
}
示例5: OnCollectStateOverlayDrawcalls
protected virtual void OnCollectStateOverlayDrawcalls(Canvas canvas)
{
// Gather general data
Point cursorPos = this.PointToClient(Cursor.Position);
// Update action text from hovered / selection / action object
Vector2 actionTextPos = new Vector2(cursorPos.X + 30, cursorPos.Y + 10);
this.actionText.SourceText = this.UpdateActionText(ref actionTextPos);
// Collect the views overlay layer drawcalls
this.CollectLayerOverlayDrawcalls(canvas);
// Collect the states overlay drawcalls
canvas.PushState();
{
// Draw camera movement indicators
if (this.camAction != CameraAction.None)
{
canvas.PushState();
canvas.State.ColorTint = ColorRgba.White.WithAlpha(0.5f);
if (this.camAction == CameraAction.DragScene)
{
// Don't draw anything.
}
else if (this.camAction == CameraAction.RotateScene)
{
canvas.FillCircle(this.camActionBeginLoc.X, this.camActionBeginLoc.Y, 3);
canvas.DrawLine(this.camActionBeginLoc.X, this.camActionBeginLoc.Y, cursorPos.X, this.camActionBeginLoc.Y);
}
else if (this.camAction == CameraAction.Move)
{
canvas.FillCircle(this.camActionBeginLoc.X, this.camActionBeginLoc.Y, 3);
canvas.DrawLine(this.camActionBeginLoc.X, this.camActionBeginLoc.Y, cursorPos.X, cursorPos.Y);
}
else if (this.camAction == CameraAction.Rotate)
{
canvas.FillCircle(this.camActionBeginLoc.X, this.camActionBeginLoc.Y, 3);
canvas.DrawLine(this.camActionBeginLoc.X, this.camActionBeginLoc.Y, cursorPos.X, this.camActionBeginLoc.Y);
}
canvas.PopState();
}
// Normalize action text position
if (this.actionText.Fonts != null && this.actionText.Fonts.Any(r => r.IsAvailable && r.Res.IsPixelGridAligned))
{
actionTextPos.X = MathF.Round(actionTextPos.X);
actionTextPos.Y = MathF.Round(actionTextPos.Y);
}
// Draw current action text
if (!this.actionText.IsEmpty)
{
canvas.DrawText(this.actionText, actionTextPos.X, actionTextPos.Y, drawBackground: true);
}
// Update / Draw current status text
{
this.statusText.SourceText = this.UpdateStatusText();
if (!this.statusText.IsEmpty)
{
Vector2 statusTextSize = this.statusText.Size;
canvas.DrawText(this.statusText, 10, this.ClientSize.Height - statusTextSize.Y - 10, drawBackground: true);
}
}
}
canvas.PopState();
// Draw a focus indicator at the view border
canvas.PushState();
{
ColorRgba focusColor = ColorRgba.Lerp(this.FgColor, this.BgColor, 0.25f).WithAlpha(255);
ColorRgba noFocusColor = ColorRgba.Lerp(this.FgColor, this.BgColor, 0.75f).WithAlpha(255);
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Mask, this.Focused ? focusColor : noFocusColor));
canvas.DrawRect(0, 0, this.ClientSize.Width, this.ClientSize.Height);
}
canvas.PopState();
}
示例6: OnCollectStateWorldOverlayDrawcalls
protected override void OnCollectStateWorldOverlayDrawcalls(Canvas canvas)
{
base.OnCollectStateWorldOverlayDrawcalls(canvas);
ICmpTilemapRenderer[] visibleRenderers = this.QueryVisibleTilemapRenderers().ToArray();
for (int i = 0; i < visibleRenderers.Length; i++)
{
ICmpTilemapRenderer renderer = visibleRenderers[i];
Component component = renderer as Component;
Transform transform = component.GameObj.Transform;
Tilemap tilemap = renderer.ActiveTilemap;
Tileset tileset = tilemap != null ? tilemap.Tileset.Res : null;
Rect localRect = renderer.LocalTilemapRect;
bool greyOut = this.selectedTilemap != null && this.selectedTilemap != tilemap;
// Configure the canvas so our shapes are properly rotated and scaled
canvas.State.TransformHandle = -localRect.TopLeft;
canvas.State.TransformAngle = transform.Angle;
canvas.State.TransformScale = new Vector2(transform.Scale);
canvas.State.ZOffset = -0.01f;
// Draw the surrounding rect of the tilemap
canvas.State.ColorTint = ColorRgba.White.WithAlpha(greyOut ? 0.33f : 1.0f);
canvas.DrawRect(
transform.Pos.X,
transform.Pos.Y,
transform.Pos.Z,
localRect.W,
localRect.H);
// Highlight source tiles when available
if (this.TileDrawSource.SourceTilemap == renderer.ActiveTilemap)
{
float intensity = (this.selectedTilemap == this.TileDrawSource.SourceTilemap) ? 1.0f : 0.5f;
DrawTileHighlights(
canvas,
renderer,
this.TileDrawSource.SourceOrigin,
this.TileDrawSource.SourceShape,
ColorRgba.White.WithAlpha(intensity),
ColorRgba.White.WithAlpha(intensity),
TileHighlightMode.Selection);
}
// Highlight the currently active tiles
if (this.activeTilemap == renderer.ActiveTilemap)
{
// Fade-in the affected area for the fill tool to prevent visual noise when hovering around
float outlineIntensity = 1.0f;
float fillIntensity = 1.0f;
if (this.activeTool.FadeInPreviews && this.activePreviewValid)
{
float timeSinceFillSelect = (float)(DateTime.Now - this.activePreviewTime).TotalMilliseconds;
fillIntensity = MathF.Clamp(timeSinceFillSelect / FillAnimDuration, 0.0f, 1.0f);
outlineIntensity = 0.25f + 0.75f * MathF.Clamp(timeSinceFillSelect / FillAnimDuration, 0.0f, 1.0f);
}
// Draw the current tile hightlights
DrawTileHighlights(
canvas,
renderer,
this.activeAreaOrigin,
this.activeArea,
ColorRgba.White.WithAlpha(fillIntensity),
ColorRgba.White.WithAlpha(outlineIntensity),
this.activePreviewValid ? TileHighlightMode.Normal : TileHighlightMode.Uncertain,
this.activeAreaOutlines);
}
}
}
示例7: OnRender
public override void OnRender(Canvas c)
{
_box.X = _client_area.X;
_box.Y = _client_area.Y;
_box.Width = _client_area.Width / 4;
_box.Height = _client_area.Height;
c.DrawRect(_box, Color.Yellow);
c.DrawLine(Color.Yellow, 1, _box.X, _box.Y, _box.Right, _box.Bottom);
c.DrawLine(Color.Yellow, 1, _box.Right, _box.Top, _box.Left, _box.Bottom);
}
示例8: DrawBoundingBox
public void DrawBoundingBox(Canvas c)
{
c.DrawRect(_client_area, Color.Yellow);
}
示例9: DrawVertexHandles
private void DrawVertexHandles(Canvas canvas, Vector2[] polyVert, float colliderAlpha,Transform bodyTransform)
{
foreach (Vector2 vertex in polyVert)
{
bool vertexSelected = IsSelected(v => (v.ActualObject as Vector2?) == vertex);
float vertexAlpha = colliderAlpha*(vertexSelected ? 1.0f : 0.5f);
ColorRgba color = this.VertexColor.WithAlpha(vertexAlpha);
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, color));
float z = bodyTransform.Pos.Z;
float size = VertexSize/GetScaleAtZ(z);
Vector2 position = bodyTransform.GetWorldPoint(vertex);
canvas.FillRect(position.X - size/2, position.Y - size/2, z, size, size);
canvas.DrawRect(position.X - size/2, position.Y - size/2, z, size, size);
}
}
示例10: DrawDesignTimeVisuals
private void DrawDesignTimeVisuals(IDrawDevice device)
{
if (DualityApp.ExecContext != DualityApp.ExecutionContext.Editor)
return;
if (device == null)
return;
var canvas = new Canvas(device);
canvas.DrawRect(GameObj.Transform.Pos.X + Rect.MinimumX, GameObj.Transform.Pos.Y + Rect.MinimumY, GameObj.Transform.Pos.Z, Rect.W, Rect.H);
}
示例11: OnRender
public override void OnRender(Canvas c)
{
if ((_font != null) && !Hide)
{
c.DrawFillRect(_client_area, _background_material);
_slider_area.Width = _client_area.Width - 18;
_slider_area.Height = Height;
_txt_area = _font.MeasureString(null, _percent, DrawTextFormat.None, ForegroundColor);
_font.DrawText(null, _percent, _client_area, DrawTextFormat.Center | DrawTextFormat.Top, ForegroundColor);
_left_arrow.X = _client_area.Left;
_left_arrow.Y = _client_area.Y + _txt_area.Height + 1;
_left_arrow.Width = 8;
_left_arrow.Height = _slider_area.Height;
c.DrawFillTri(_left_arrow, _arrow_material, DIRECTION.LEFT);
_slider_area.X = _left_arrow.Right + 1;
_slider_area.Y = _client_area.Y + _txt_area.Height + 1;
c.DrawProgressBar(_slider_area, _slider_background_material, _slider_foreground_material, _slider_position);
_right_arrow.X = _slider_area.Right + 1;
_right_arrow.Y = _client_area.Y + _txt_area.Height + 1;
_right_arrow.Width = 8;
_right_arrow.Height = _slider_area.Height;
c.DrawFillTri(_right_arrow, _arrow_material, DIRECTION.RIGHT);
c.DrawRect(_client_area, BorderColor);
}
}
示例12: Canvas
void ICmpRenderer.Draw(IDrawDevice device)
{
// Create a buffer to cache and re-use vertices. Not required, but will boost performance.
if (this.buffer == null) this.buffer = new CanvasBuffer();
// Create a Canvas to auto-generate vertices from high-level drawing commands.
Canvas canvas = new Canvas(device, this.buffer);
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White));
canvas.State.TextFont = this.font;
// Retrieve players
if (this.playerOne == null)
this.playerOne = Scene.Current.FindComponents<Player>().Where(p => p.Id == PlayerId.PlayerOne).FirstOrDefault();
if (this.playerTwo == null)
this.playerTwo = Scene.Current.FindComponents<Player>().Where(p => p.Id == PlayerId.PlayerTwo).FirstOrDefault();
// Is someone playing using mouse / keyboard? Display a mouse cursor then
if (Player.AlivePlayers.Any(p => p.InputMethod == InputMethod.MouseAndKeyboard))
{
canvas.FillCircle(DualityApp.Mouse.X, DualityApp.Mouse.Y, 2.0f);
}
// Is any player alive? Keep that value in mind, won't change here anyway.
bool isAnyPlayerAlive = Player.IsAnyPlayerAlive;
// Draw health and info of player one
if (this.IsPlayerActive(this.playerOne))
{
Ship playerShip = this.playerOne.ControlObject;
if (playerShip.Active)
{
// Draw a health bar when alive
float health = playerShip.Hitpoints;
canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
canvas.FillRect(12 - 1, device.TargetSize.Y - 10 - 198 - 1, 16 + 2, 196 + 2);
canvas.State.ColorTint = this.playerOne.Color;
canvas.DrawRect(10, device.TargetSize.Y - 10 - 200, 20, 200);
canvas.FillRect(12, device.TargetSize.Y - 10 - health * 198.0f, 16, health * 196.0f);
}
else if (isAnyPlayerAlive && !this.playerOne.HasReachedGoal)
{
// Draw a respawn timer when dead
float respawnPercentage = this.playerOne.RespawnTime / Player.RespawnDelay;
string respawnText = string.Format("Respawn in {0:F1}", (Player.RespawnDelay - this.playerOne.RespawnTime) / 1000.0f);
Vector2 textSize = canvas.MeasureText(string.Format("Respawn in {0:F1}", 0.0f));
canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
canvas.FillRect(10 - 1, device.TargetSize.Y - 10 - textSize.Y - 2, textSize.X + 5, textSize.Y + 8);
canvas.State.ColorTint = this.playerOne.Color;
canvas.DrawText(respawnText, 10, device.TargetSize.Y - 10, 0.0f, Alignment.BottomLeft);
canvas.FillRect(10, device.TargetSize.Y - 10 - textSize.Y, textSize.X * respawnPercentage, 3);
canvas.FillRect(10, device.TargetSize.Y - 10, textSize.X * respawnPercentage, 3);
}
}
// Draw health and info of player two
if (this.IsPlayerActive(this.playerTwo))
{
Ship playerShip = this.playerTwo.ControlObject;
if (playerShip.Active)
{
// Draw a health bar when alive
float health = playerShip.Hitpoints;
canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
canvas.FillRect(device.TargetSize.X - 12 - 16 - 1, device.TargetSize.Y - 10 - 198 - 1, 16 + 2, 196 + 2);
canvas.State.ColorTint = this.playerTwo.Color;
canvas.DrawRect(device.TargetSize.X - 10 - 20, device.TargetSize.Y - 10 - 200, 20, 200);
canvas.FillRect(device.TargetSize.X - 12 - 16, device.TargetSize.Y - 10 - health * 198.0f, 16, health * 196.0f);
}
else if (isAnyPlayerAlive && !this.playerTwo.HasReachedGoal)
{
// Draw a respawn timer when dead
float respawnPercentage = this.playerTwo.RespawnTime / Player.RespawnDelay;
string respawnText = string.Format("{0:F1} to Respawn", (Player.RespawnDelay - this.playerTwo.RespawnTime) / 1000.0f);
Vector2 textSize = canvas.MeasureText(string.Format("{0:F1} to Respawn", 0.0f));
canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
canvas.FillRect(device.TargetSize.X - 10 - textSize.X - 3, device.TargetSize.Y - 10 - textSize.Y - 2, textSize.X + 2, textSize.Y + 10);
canvas.State.ColorTint = this.playerTwo.Color;
canvas.DrawText(respawnText, device.TargetSize.X - 10, device.TargetSize.Y - 10, 0.0f, Alignment.BottomRight);
canvas.FillRect(device.TargetSize.X - 10 - textSize.X * respawnPercentage, device.TargetSize.Y - 10 - textSize.Y, textSize.X * respawnPercentage, 3);
canvas.FillRect(device.TargetSize.X - 10 - textSize.X * respawnPercentage, device.TargetSize.Y - 10, textSize.X * respawnPercentage, 3);
}
}
}
示例13: OnCollectStateOverlayDrawcalls
protected override void OnCollectStateOverlayDrawcalls(Canvas canvas)
{
base.OnCollectStateOverlayDrawcalls(canvas);
Point cursorPos = this.PointToClient(Cursor.Position);
canvas.PushState();
{
// Draw rect selection
if (this.action == ObjectEditorAction.RectSelect)
canvas.DrawRect(this.actionBeginLoc.X, this.actionBeginLoc.Y, cursorPos.X - this.actionBeginLoc.X, cursorPos.Y - this.actionBeginLoc.Y);
}
canvas.PopState();
}
示例14: OnRender
//.........这里部分代码省略.........
MenuLocations[i].X = StartX + width;
MenuLocations[i].Y = StartY;
MenuLocations[i].Height = _client_area.Height;
width += MenuLocations[i].Width;
break;
case PanelLayout.VerticalFree:
MenuLocations[i].X = StartX;
MenuLocations[i].Y = StartY + height;
MenuLocations[i].Width = _client_area.Width;
height += MenuLocations[i].Height;
break;
default:
throw new ArgumentException("Unsupported Layout type.");
}
if (i != _selected_index)
{
_font.DrawText(null, MenuOptions[i], MenuLocations[i], DrawFormat, ForegroundColor);
}
else
{
_font.DrawText(null, MenuOptions[i], MenuLocations[i], DrawFormat, Color.Yellow);
}
}
}
}
EndViewport(c);
switch (_layout)
{
case PanelLayout.Horizontal:
goto case PanelLayout.HorizontalFree;
case PanelLayout.HorizontalFree:
if (_panel_area.Width < _menu_item_height)
{
c.DrawFillRect(_left_button_area, _button_material);
if (!HideLeftScrollBtn)
{
if ((_draw_bounding_box == BoundingBox.LEFT))
{
c.DrawFillTri(_left_arrow, _arrow_selected, DIRECTION.LEFT);
}
else
{
c.DrawFillTri(_left_arrow, _arrow_material, DIRECTION.LEFT);
}
}
c.DrawFillRect(_right_button_area, _button_material);
if (!HideRightScrollBtn)
{
if ((_draw_bounding_box == BoundingBox.RIGHT))
{
c.DrawFillTri(_right_arrow, _arrow_selected, DIRECTION.RIGHT);
}
else
{
c.DrawFillTri(_right_arrow, _arrow_material, DIRECTION.RIGHT);
}
}
}
break;
case PanelLayout.Vertical:
goto case PanelLayout.VerticalFree;
case PanelLayout.VerticalFree:
if (_panel_area.Height < _menu_item_height)
{
c.DrawFillRect(_up_button_area, _button_material);
if (!HideUpScrollBtn)
{
if ((_draw_bounding_box == BoundingBox.UP))
{
c.DrawFillTri(_up_arrow, _arrow_selected, DIRECTION.UP);
}
else
{
c.DrawFillTri(_up_arrow, _arrow_material, DIRECTION.UP);
}
}
c.DrawFillRect(_down_button_area, _button_material);
if (!HideDownScrollBtn)
{
if ((_draw_bounding_box == BoundingBox.DOWN))
{
c.DrawFillTri(_down_arrow, _arrow_selected, DIRECTION.DOWN);
}
else
{
c.DrawFillTri(_down_arrow, _arrow_material, DIRECTION.DOWN);
}
}
}
break;
default:
throw new ArgumentException("PanelMenuRender: Unsupported Layout type.");
}
c.DrawRect(_client_area, BorderColor);
}
}
示例15: OnRender
public override void OnRender(Canvas c)
{
c.DrawFillRect(_client_area, BackgroundMaterial);
_font.DrawText(null, _text, ClientArea, DrawTextFormat.VerticalCenter | DrawTextFormat.Center, ForegroundColor);
if (Selected)
{
DrawBoundingBox(c);
}
else
{
c.DrawRect(_client_area, BorderColor);
}
}