예제 #1
0
파일: StrikeBox.cs 프로젝트: step4/rac-quiz
        public override void Draw(DrawingContext drawingContext, float scale, float x, float y)
        {
            base.Draw(drawingContext, scale, x, y);
            PrepareDraw(drawingContext);

            //This is for people who are nerdy about math
            float op = Mathf.Max(0, offsetPlus), om = Mathf.Min(0, offsetMinus);
            float opm = op - om;
            float angle;

            switch (mode)
            {
            case StrikeMode.diagonal: angle = Mathf.Atan2(totalHeight + margin * 2 - opm, width); break;

            case StrikeMode.diagonalInverse: angle = Mathf.Atan2(totalHeight + margin * 2 - opm, width); break;

            case StrikeMode.vertical: angle = Mathf.Atan2(totalHeight + margin * 2, width - opm); break;

            case StrikeMode.verticalInverse: angle = Mathf.Atan2(totalHeight + margin * 2, width - opm); break;

            default: angle = 0; break;
            }
            float s = Mathf.Sin(angle) * thickness, c = Mathf.Cos(angle) * thickness;
            float w = width, ww = width + margin, h = totalHeight / 2f + margin;

            Vector2[] v = new Vector2[4];
            y += totalHeight / 2f - depth;
            if ((int)mode > 1 && (int)mode < 6)
            {
                y += op + om;
            }
            switch (mode)
            {
            case StrikeMode.diagonal:
                v[0] = new Vector2((x + w + s) * scale, (y + h - c + om) * scale); //Top-Left
                v[1] = new Vector2((x + w - s) * scale, (y + h + c + om) * scale); //Top-Right
                v[2] = new Vector2((x - s) * scale, (y - h + c + op) * scale);     //Bottom-Right
                v[3] = new Vector2((x + s) * scale, (y - h - c + op) * scale);     //Bottom-Left
                break;

            case StrikeMode.diagonalInverse:
                v[0] = new Vector2((x + s) * scale, (y + h + c + om) * scale);     //Top-Left
                v[1] = new Vector2((x - s) * scale, (y + h - c + om) * scale);     //Top-Right
                v[2] = new Vector2((x + w - s) * scale, (y - h - c + op) * scale); //Bottom-Right
                v[3] = new Vector2((x + w + s) * scale, (y - h + c + op) * scale); //Bottom-Left
                break;

            case StrikeMode.horizontal:
                y   += TEXConfiguration.main.MiddleLineOffset;
                v[0] = new Vector2((x - margin) * scale, (y + thickness) * scale); //Top-Left
                v[1] = new Vector2((x + ww) * scale, (y + thickness) * scale);     //Top-Right
                v[2] = new Vector2((x + ww) * scale, (y - thickness) * scale);     //Bottom-Right
                v[3] = new Vector2((x - margin) * scale, (y - thickness) * scale); //Bottom-Left
                break;

            case StrikeMode.doubleHorizontal:
                float doubleOffset = TEXConfiguration.main.DoubleNegateMargin;
                y   += TEXConfiguration.main.MiddleLineOffset;
                v[0] = new Vector2((x - margin) * scale, (y + thickness + doubleOffset) * scale); //Top-Left
                v[1] = new Vector2((x + ww) * scale, (y + thickness + doubleOffset) * scale);     //Top-Right
                v[2] = new Vector2((x + ww) * scale, (y - thickness + doubleOffset) * scale);     //Bottom-Right
                v[3] = new Vector2((x - margin) * scale, (y - thickness + doubleOffset) * scale); //Bottom-Left
                Draw(drawingContext, v);

                v[0] = new Vector2((x - margin) * scale, (y + thickness - doubleOffset) * scale); //Top-Left
                v[1] = new Vector2((x + ww) * scale, (y + thickness - doubleOffset) * scale);     //Top-Right
                v[2] = new Vector2((x + ww) * scale, (y - thickness - doubleOffset) * scale);     //Bottom-Right
                v[3] = new Vector2((x - margin) * scale, (y - thickness - doubleOffset) * scale); //Bottom-Left
                break;

            case StrikeMode.underline:
                y   -= totalHeight / 2f - depth + thickness * 2 - TEXConfiguration.main.UnderLineOffset;
                v[0] = new Vector2((x - margin) * scale, (y + thickness) * scale); //Top-Left
                v[1] = new Vector2((x + ww) * scale, (y + thickness) * scale);     //Top-Right
                v[2] = new Vector2((x + ww) * scale, (y - thickness) * scale);     //Bottom-Right
                v[3] = new Vector2((x - margin) * scale, (y - thickness) * scale); //Bottom-Left
                break;

            case StrikeMode.overline:
                y   += totalHeight / 2 + thickness * 2 + TEXConfiguration.main.OverLineOffset;
                v[0] = new Vector2((x - margin) * scale, (y + thickness) * scale); //Top-Left
                v[1] = new Vector2((x + ww) * scale, (y + thickness) * scale);     //Top-Right
                v[2] = new Vector2((x + ww) * scale, (y - thickness) * scale);     //Bottom-Right
                v[3] = new Vector2((x - margin) * scale, (y - thickness) * scale); //Bottom-Left
                break;

            case StrikeMode.vertical:
                v[0] = new Vector2((x + w + s + om) * scale, (y + h - c) * scale); //Top-Left
                v[1] = new Vector2((x + w - s + om) * scale, (y + h + c) * scale); //Top-Right
                v[2] = new Vector2((x - s + op) * scale, (y - h + c) * scale);     //Bottom-Right
                v[3] = new Vector2((x + s + op) * scale, (y - h - c) * scale);     //Bottom-Left
                break;

            case StrikeMode.verticalInverse:
                v[0] = new Vector2((x + s + op) * scale, (y + h + c) * scale);     //Top-Left
                v[1] = new Vector2((x - s + op) * scale, (y + h - c) * scale);     //Top-Right
                v[2] = new Vector2((x + w - s + om) * scale, (y - h - c) * scale); //Bottom-Right
                v[3] = new Vector2((x + w + s + om) * scale, (y - h + c) * scale); //Bottom-Left
                break;
            }
            Draw(drawingContext, v);
        }
예제 #2
0
파일: StrikeBox.cs 프로젝트: step4/rac-quiz
 private void Draw(DrawingContext context, Vector2[] verts)
 {
     context.Draw(fontIdx, verts, uv);
 }