Ejemplo n.º 1
0
        public void render(bool close_polygon)
        {
            m_src_vertices.close(close_polygon);
            draw_vars      dv = new draw_vars();
            line_aa_vertex v;
            int            x1;
            int            y1;
            int            x2;
            int            y2;
            int            lprev;

            if (close_polygon)
            {
                if (m_src_vertices.size() >= 3)
                {
                    dv.idx = 2;

                    v     = m_src_vertices[m_src_vertices.size() - 1];
                    x1    = v.x;
                    y1    = v.y;
                    lprev = v.len;

                    v        = m_src_vertices[0];
                    x2       = v.x;
                    y2       = v.y;
                    dv.lcurr = v.len;
                    line_parameters prev = new line_parameters(x1, y1, x2, y2, lprev);

                    v        = m_src_vertices[1];
                    dv.x1    = v.x;
                    dv.y1    = v.y;
                    dv.lnext = v.len;
                    dv.curr  = new line_parameters(x2, y2, dv.x1, dv.y1, dv.lcurr);

                    v       = m_src_vertices[dv.idx];
                    dv.x2   = v.x;
                    dv.y2   = v.y;
                    dv.next = new line_parameters(dv.x1, dv.y1, dv.x2, dv.y2, dv.lnext);

                    dv.xb1 = 0;
                    dv.yb1 = 0;
                    dv.xb2 = 0;
                    dv.yb2 = 0;

                    switch (m_line_join)
                    {
                    case outline_aa_join_e.outline_no_join:
                        dv.flags = 3;
                        break;

                    case outline_aa_join_e.outline_miter_join:
                    case outline_aa_join_e.outline_round_join:
                        dv.flags =
                            (prev.diagonal_quadrant() == dv.curr.diagonal_quadrant() ? 1 : 0) |
                            ((dv.curr.diagonal_quadrant() == dv.next.diagonal_quadrant() ? 1 : 0) << 1);
                        break;

                    case outline_aa_join_e.outline_miter_accurate_join:
                        dv.flags = 0;
                        break;
                    }

                    if ((dv.flags & 1) == 0 && m_line_join != outline_aa_join_e.outline_round_join)
                    {
                        LineAABasics.bisectrix(prev, dv.curr, out dv.xb1, out dv.yb1);
                    }

                    if ((dv.flags & 2) == 0 && m_line_join != outline_aa_join_e.outline_round_join)
                    {
                        LineAABasics.bisectrix(dv.curr, dv.next, out dv.xb2, out dv.yb2);
                    }
                    draw(ref dv, 0, m_src_vertices.size());
                }
            }
            else
            {
                switch (m_src_vertices.size())
                {
                case 0:
                case 1:
                    break;

                case 2:
                {
                    v     = m_src_vertices[0];
                    x1    = v.x;
                    y1    = v.y;
                    lprev = v.len;
                    v     = m_src_vertices[1];
                    x2    = v.x;
                    y2    = v.y;
                    line_parameters lp = new line_parameters(x1, y1, x2, y2, lprev);
                    if (m_round_cap)
                    {
                        m_ren.semidot(cmp_dist_start, x1, y1, x1 + (y2 - y1), y1 - (x2 - x1));
                    }
                    m_ren.line3(lp,
                                x1 + (y2 - y1),
                                y1 - (x2 - x1),
                                x2 + (y2 - y1),
                                y2 - (x2 - x1));
                    if (m_round_cap)
                    {
                        m_ren.semidot(cmp_dist_end, x2, y2, x2 + (y2 - y1), y2 - (x2 - x1));
                    }
                }
                break;

                case 3:
                {
                    int x3, y3;
                    int lnext;
                    v     = m_src_vertices[0];
                    x1    = v.x;
                    y1    = v.y;
                    lprev = v.len;
                    v     = m_src_vertices[1];
                    x2    = v.x;
                    y2    = v.y;
                    lnext = v.len;
                    v     = m_src_vertices[2];
                    x3    = v.x;
                    y3    = v.y;
                    line_parameters lp1 = new line_parameters(x1, y1, x2, y2, lprev);
                    line_parameters lp2 = new line_parameters(x2, y2, x3, y3, lnext);

                    if (m_round_cap)
                    {
                        m_ren.semidot(cmp_dist_start, x1, y1, x1 + (y2 - y1), y1 - (x2 - x1));
                    }

                    if (m_line_join == outline_aa_join_e.outline_round_join)
                    {
                        m_ren.line3(lp1, x1 + (y2 - y1), y1 - (x2 - x1),
                                    x2 + (y2 - y1), y2 - (x2 - x1));

                        m_ren.pie(x2, y2, x2 + (y2 - y1), y2 - (x2 - x1),
                                  x2 + (y3 - y2), y2 - (x3 - x2));

                        m_ren.line3(lp2, x2 + (y3 - y2), y2 - (x3 - x2),
                                    x3 + (y3 - y2), y3 - (x3 - x2));
                    }
                    else
                    {
                        LineAABasics.bisectrix(lp1, lp2, out dv.xb1, out dv.yb1);
                        m_ren.line3(lp1, x1 + (y2 - y1), y1 - (x2 - x1),
                                    dv.xb1, dv.yb1);

                        m_ren.line3(lp2, dv.xb1, dv.yb1,
                                    x3 + (y3 - y2), y3 - (x3 - x2));
                    }
                    if (m_round_cap)
                    {
                        m_ren.semidot(cmp_dist_end, x3, y3, x3 + (y3 - y2), y3 - (x3 - x2));
                    }
                }
                break;

                default:
                {
                    dv.idx = 3;

                    v     = m_src_vertices[0];
                    x1    = v.x;
                    y1    = v.y;
                    lprev = v.len;

                    v        = m_src_vertices[1];
                    x2       = v.x;
                    y2       = v.y;
                    dv.lcurr = v.len;
                    line_parameters prev = new line_parameters(x1, y1, x2, y2, lprev);

                    v        = m_src_vertices[2];
                    dv.x1    = v.x;
                    dv.y1    = v.y;
                    dv.lnext = v.len;
                    dv.curr  = new line_parameters(x2, y2, dv.x1, dv.y1, dv.lcurr);

                    v       = m_src_vertices[dv.idx];
                    dv.x2   = v.x;
                    dv.y2   = v.y;
                    dv.next = new line_parameters(dv.x1, dv.y1, dv.x2, dv.y2, dv.lnext);

                    dv.xb1 = 0;
                    dv.yb1 = 0;
                    dv.xb2 = 0;
                    dv.yb2 = 0;

                    switch (m_line_join)
                    {
                    case outline_aa_join_e.outline_no_join:
                        dv.flags = 3;
                        break;

                    case outline_aa_join_e.outline_miter_join:
                    case outline_aa_join_e.outline_round_join:
                        dv.flags =
                            (prev.diagonal_quadrant() == dv.curr.diagonal_quadrant() ? 1 : 0) |
                            ((dv.curr.diagonal_quadrant() == dv.next.diagonal_quadrant() ? 1 : 0) << 1);
                        break;

                    case outline_aa_join_e.outline_miter_accurate_join:
                        dv.flags = 0;
                        break;
                    }

                    if (m_round_cap)
                    {
                        m_ren.semidot(cmp_dist_start, x1, y1, x1 + (y2 - y1), y1 - (x2 - x1));
                    }
                    if ((dv.flags & 1) == 0)
                    {
                        if (m_line_join == outline_aa_join_e.outline_round_join)
                        {
                            m_ren.line3(prev, x1 + (y2 - y1), y1 - (x2 - x1),
                                        x2 + (y2 - y1), y2 - (x2 - x1));
                            m_ren.pie(prev.x2, prev.y2,
                                      x2 + (y2 - y1), y2 - (x2 - x1),
                                      dv.curr.x1 + (dv.curr.y2 - dv.curr.y1),
                                      dv.curr.y1 - (dv.curr.x2 - dv.curr.x1));
                        }
                        else
                        {
                            LineAABasics.bisectrix(prev, dv.curr, out dv.xb1, out dv.yb1);
                            m_ren.line3(prev, x1 + (y2 - y1), y1 - (x2 - x1),
                                        dv.xb1, dv.yb1);
                        }
                    }
                    else
                    {
                        m_ren.line1(prev,
                                    x1 + (y2 - y1),
                                    y1 - (x2 - x1));
                    }
                    if ((dv.flags & 2) == 0 && m_line_join != outline_aa_join_e.outline_round_join)
                    {
                        LineAABasics.bisectrix(dv.curr, dv.next, out dv.xb2, out dv.yb2);
                    }

                    draw(ref dv, 1, m_src_vertices.size() - 2);

                    if ((dv.flags & 1) == 0)
                    {
                        if (m_line_join == outline_aa_join_e.outline_round_join)
                        {
                            m_ren.line3(dv.curr,
                                        dv.curr.x1 + (dv.curr.y2 - dv.curr.y1),
                                        dv.curr.y1 - (dv.curr.x2 - dv.curr.x1),
                                        dv.curr.x2 + (dv.curr.y2 - dv.curr.y1),
                                        dv.curr.y2 - (dv.curr.x2 - dv.curr.x1));
                        }
                        else
                        {
                            m_ren.line3(dv.curr, dv.xb1, dv.yb1,
                                        dv.curr.x2 + (dv.curr.y2 - dv.curr.y1),
                                        dv.curr.y2 - (dv.curr.x2 - dv.curr.x1));
                        }
                    }
                    else
                    {
                        m_ren.line2(dv.curr,
                                    dv.curr.x2 + (dv.curr.y2 - dv.curr.y1),
                                    dv.curr.y2 - (dv.curr.x2 - dv.curr.x1));
                    }
                    if (m_round_cap)
                    {
                        m_ren.semidot(cmp_dist_end, dv.curr.x2, dv.curr.y2,
                                      dv.curr.x2 + (dv.curr.y2 - dv.curr.y1),
                                      dv.curr.y2 - (dv.curr.x2 - dv.curr.x1));
                    }
                }
                break;
                }
            }
            m_src_vertices.remove_all();
        }
Ejemplo n.º 2
0
        private void draw(ref draw_vars dv, int start, int end)
        {
            int i;

            for (i = start; i < end; i++)
            {
                if (m_line_join == outline_aa_join_e.outline_round_join)
                {
                    dv.xb1 = dv.curr.x1 + (dv.curr.y2 - dv.curr.y1);
                    dv.yb1 = dv.curr.y1 - (dv.curr.x2 - dv.curr.x1);
                    dv.xb2 = dv.curr.x2 + (dv.curr.y2 - dv.curr.y1);
                    dv.yb2 = dv.curr.y2 - (dv.curr.x2 - dv.curr.x1);
                }

                switch (dv.flags)
                {
                case 0: m_ren.line3(dv.curr, dv.xb1, dv.yb1, dv.xb2, dv.yb2); break;

                case 1: m_ren.line2(dv.curr, dv.xb2, dv.yb2); break;

                case 2: m_ren.line1(dv.curr, dv.xb1, dv.yb1); break;

                case 3: m_ren.line0(dv.curr); break;
                }

                if (m_line_join == outline_aa_join_e.outline_round_join && (dv.flags & 2) == 0)
                {
                    m_ren.pie(dv.curr.x2, dv.curr.y2,
                              dv.curr.x2 + (dv.curr.y2 - dv.curr.y1),
                              dv.curr.y2 - (dv.curr.x2 - dv.curr.x1),
                              dv.curr.x2 + (dv.next.y2 - dv.next.y1),
                              dv.curr.y2 - (dv.next.x2 - dv.next.x1));
                }

                dv.x1    = dv.x2;
                dv.y1    = dv.y2;
                dv.lcurr = dv.lnext;
                dv.lnext = m_src_vertices[dv.idx].len;

                ++dv.idx;
                if (dv.idx >= m_src_vertices.size())
                {
                    dv.idx = 0;
                }

                dv.x2 = m_src_vertices[dv.idx].x;
                dv.y2 = m_src_vertices[dv.idx].y;

                dv.curr = dv.next;
                dv.next = new line_parameters(dv.x1, dv.y1, dv.x2, dv.y2, dv.lnext);
                dv.xb1  = dv.xb2;
                dv.yb1  = dv.yb2;

                switch (m_line_join)
                {
                case outline_aa_join_e.outline_no_join:
                    dv.flags = 3;
                    break;

                case outline_aa_join_e.outline_miter_join:
                    dv.flags >>= 1;
                    dv.flags  |= (dv.curr.diagonal_quadrant() ==
                                  dv.next.diagonal_quadrant() ? 1 : 0);
                    if ((dv.flags & 2) == 0)
                    {
                        LineAABasics.bisectrix(dv.curr, dv.next, out dv.xb2, out dv.yb2);
                    }
                    break;

                case outline_aa_join_e.outline_round_join:
                    dv.flags >>= 1;
                    dv.flags  |= (((dv.curr.diagonal_quadrant() ==
                                    dv.next.diagonal_quadrant()) ? 1 : 0) << 1);
                    break;

                case outline_aa_join_e.outline_miter_accurate_join:
                    dv.flags = 0;
                    LineAABasics.bisectrix(dv.curr, dv.next, out dv.xb2, out dv.yb2);
                    break;
                }
            }
        }