본문 바로가기
백엔드/C#

통통한 화살표 그리기

by 1005ptr 2019. 2. 20.
반응형

통통한 화살표 그리기

화살표 몸통 조절은 현재 8분의 2 굵기

8분의 4 굵기로 할거면 0.375 -> 0.25, 0.625 -> 0.75


버그있음

resize 시 잘못 표시되는 경우 발생

 - 삼각형 헤드 크기를 조절하는 로직에서 발생하는걸로 생각됨

 - 조절로직: [머리 폭의 절반만큼을 머리 길이로 사용하면서, 머리 폭의 절반이 화살표 길이의 절반보다 큰 경우 화살표 길이의 절반으로 머리 길이를 정한다]


resize 시 화살표 방향 전환

 - onResize override해서 마우스 놓는 위치에 따라 방향 다시 설정하도록?


 
private void DrawArrowLeft(Graphics g)
{
    float mid_Y = (this._boundingBox[0].+ this._boundingBox[3].Y) / 2;
    float headLine_X;
    float body_Y_Left = this._boundingBox[0].* 0.375f + this._boundingBox[3].* 0.625f;
    float body_Y_Right = this._boundingBox[0].* 0.625f + this._boundingBox[3].* 0.375f;
 
    if (this.Size.Width > this.Size.Height)
    {
        headLine_X = this._boundingBox[0].+ this.Size.Height/2f;
    }
    else
    {
        headLine_X = (this._boundingBox[0].+ this._boundingBox[1].X) / 2;
    }
 
    PointF[] vertexs = { new PointF(this._boundingBox[0].X, mid_Y)
                       , new PointF(headLine_X , this._boundingBox[0].Y )
                       , new PointF(headLine_X , body_Y_Right)
                       , new PointF(this._boundingBox[1].X, body_Y_Right)
                       , new PointF(this._boundingBox[2].X, body_Y_Left)
                       , new PointF(headLine_X , body_Y_Left)
                       , new PointF(headLine_X , this._boundingBox[3].Y )
                       };
    if (this.SymbolItem.BackColor != Color.Empty)
    {
        g.FillPolygon(new SolidBrush(this.SymbolItem.BackColor), vertexs);
    }
 
    g.DrawPolygon(new Pen(this.SymbolItem.ForeColor, this.Attribute.LineThick), vertexs);
}
 
private void DrawArrowRight(Graphics g)
{
    float right_mid = (this._boundingBox[1].+ this._boundingBox[2].Y) / 2;
    float headLine_X;
    float body_Y_Left = this._boundingBox[0].* 0.625f + this._boundingBox[3].* 0.375f;
    float body_Y_Right = this._boundingBox[0].* 0.375f + this._boundingBox[3].* 0.625f;
 
    if(this.Size.Width > this.Size.Height ){
        headLine_X = this._boundingBox[1].- this.Size.Height/2f;
    }
    else{
        headLine_X = (this._boundingBox[1].+ this._boundingBox[0].X) / 2;
    }
 
    PointF[] vertexs = { new PointF(this._boundingBox[0].X, body_Y_Left)
                       , new PointF(headLine_X, body_Y_Left)
                       , new PointF(headLine_X, this._boundingBox[1].Y)
                       , new PointF(this._boundingBox[1].X, right_mid)
                       , new PointF(headLine_X, this._boundingBox[2].Y)
                       , new PointF(headLine_X, body_Y_Right)
                       , new PointF(this._boundingBox[3].X, body_Y_Right)};
 
    if (this.SymbolItem.BackColor != Color.Empty)
    {
        g.FillPolygon(new SolidBrush(this.SymbolItem.BackColor), vertexs);
    }
 
    g.DrawPolygon(new Pen(this.SymbolItem.ForeColor, this.Attribute.LineThick), vertexs);
}
 
private void DrawArrowUp(Graphics g)
{
    float top_mid = (this._boundingBox[0].+ this._boundingBox[1].X) / 2;
    float headLine_Y;
    float body_X_Left = this._boundingBox[0].* 0.625f + this._boundingBox[1].* 0.375f;
    float body_X_Right = this._boundingBox[0].* 0.375f + this._boundingBox[1].* 0.625f;
 
    if (this.Size.Width < this.Size.Height)
    {
        headLine_Y = this._boundingBox[1].+ this.Size.Width / 2f;
    }
    else
    {
        headLine_Y = (this._boundingBox[0].+ this._boundingBox[3].Y) / 2;
    }
 
    PointF[] vertexs = { new PointF(top_mid, this._boundingBox[0].Y)
                       , new PointF(this._boundingBox[1].X, headLine_Y)
                       , new PointF(body_X_Right, headLine_Y)
                       , new PointF(body_X_Right, this._boundingBox[2].Y)
                       , new PointF(body_X_Left, this._boundingBox[3].Y)
                       , new PointF(body_X_Left, headLine_Y)
                       , new PointF(this._boundingBox[3].X, headLine_Y)};
 
    if (this.SymbolItem.BackColor != Color.Empty)
    {
        g.FillPolygon(new SolidBrush(this.SymbolItem.BackColor), vertexs);
    }
 
    g.DrawPolygon(new Pen(this.SymbolItem.ForeColor, this.Attribute.LineThick), vertexs);
}
 
private void DrawArrowDown(Graphics g)
{
    float bottom_mid = (this._boundingBox[0].+ this._boundingBox[1].X) / 2;
    float headLine_Y;
    float body_X_Left = this._boundingBox[0].* 0.375f + this._boundingBox[1].* 0.625f;
    float body_X_Right = this._boundingBox[0].* 0.625f + this._boundingBox[1].* 0.375f;
 
    if (this.Size.Width < this.Size.Height)
    {
        headLine_Y = this._boundingBox[3].- this.Size.Width / 2f;
    }
    else
    {
        headLine_Y = (this._boundingBox[0].+ this._boundingBox[3].Y) / 2;
    }
 
    PointF[] vertexs = { new PointF(bottom_mid, this._boundingBox[3].Y)
                       , new PointF(this._boundingBox[0].X, headLine_Y)
                       , new PointF(body_X_Right, headLine_Y)
                       , new PointF(body_X_Right, this._boundingBox[0].Y)
                       , new PointF(body_X_Left, this._boundingBox[0].Y)
                       , new PointF(body_X_Left, headLine_Y)
                       , new PointF(this._boundingBox[1].X, headLine_Y)};
 
    if (this.SymbolItem.BackColor != Color.Empty)
    {
        g.FillPolygon(new SolidBrush(this.SymbolItem.BackColor), vertexs);
    }
 
    g.DrawPolygon(new Pen(this.SymbolItem.ForeColor, this.Attribute.LineThick), vertexs);
}


반응형

댓글