첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.15MB

▶ GraphicsDrawable.cs

namespace TestProject;

/// <summary>
/// 그래픽스 그리기 가능형
/// </summary>
public class GraphicsDrawable : IDrawable
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 그리기 - Draw(canvas, dirtyRectangle)

    /// <summary>
    /// 그리기
    /// </summary>
    /// <param name="canvas">캔버스</param>
    /// <param name="dirtyRectangle">더티 사각형</param>
    public void Draw(ICanvas canvas, RectF dirtyRectangle)
    {
        canvas.FillColor = Colors.Yellow;

        canvas.FillRectangle(dirtyRectangle);

        canvas.StrokeLineCap = LineCap.Round;
        canvas.FillColor     = Colors.Gray;

        canvas.Translate(dirtyRectangle.Center.X, dirtyRectangle.Center.Y);

        float scale = Math.Min(dirtyRectangle.Width / 200f, dirtyRectangle.Height / 200f);

        canvas.Scale(scale, scale);

        // 시계 눈금
        for(int angle = 0; angle < 360; angle += 6)
        {
            canvas.FillCircle(0, -90, angle % 30 == 0 ? 4 : 2);

            canvas.Rotate(6);
        }

        DateTime currentTime = DateTime.Now;

        // 시침
        canvas.StrokeSize = 20;

        canvas.SaveState();

        canvas.Rotate(30 * currentTime.Hour + currentTime.Minute / 2f);

        canvas.DrawLine(0, 0, 0, -50);

        canvas.RestoreState();

        // 분침
        canvas.StrokeSize = 10;

        canvas.SaveState();

        canvas.Rotate(6 * currentTime.Minute + currentTime.Second / 10f);

        canvas.DrawLine(0, 0, 0, -70);

        canvas.RestoreState();

        // 초침
        canvas.StrokeSize = 2;

        canvas.SaveState();

        canvas.Rotate(6 * currentTime.Second);

        canvas.DrawLine(0, 10, 0, -80);

        canvas.RestoreState();
    }

    #endregion
}

 

728x90

 

▶ MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="TestProject.MainPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:TestProject">
    <ContentPage.Resources>
        <local:GraphicsDrawable x:Key="GraphicsDrawableKey" />
    </ContentPage.Resources>
    <GraphicsView
        HorizontalOptions="Center"
        VerticalOptions="Center"
        WidthRequest="350"
        HeightRequest="350"
        Drawable="{StaticResource GraphicsDrawableKey}" />
</ContentPage>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요