コード例 #1
0
        private static void ComputeXYUsingAlign(LayoutAlign align, int ctrlw, int ctrlh, int allocx, int allocy, int allocw, int alloch, out int ctrlx, out int ctrly)
        {
            //horizontal:
            if ((align & LayoutAlign.Left) != 0)
            {
                ctrlx = allocx;
            }
            else if ((align & LayoutAlign.Right) != 0)
            {
                ctrlx = allocx + allocw - ctrlw;
            }
            else //center
            {
                ctrlx = allocx + allocw / 2 - ctrlw / 2;
            }

            //vertical:
            if ((align & LayoutAlign.Top) != 0)
            {
                ctrly = allocy;
            }
            else if ((align & LayoutAlign.Bottom) != 0)
            {
                ctrly = allocy + alloch - ctrlh;
            }
            else //center
            {
                ctrly = allocy + alloch / 2 - ctrlh / 2;
            }
        }
コード例 #2
0
 public TextBoxBackup(ShaderProgram program, string text, Color4 colour, Color4 highlightColour,
                      int x, int y, int width, int height, int windowWidth, int windowHeight,
                      Matrix4 projection,
                      LayoutAlign layoutAlign = LayoutAlign.TopRight, string fontLocation = "arial")
     : base(program, text, colour, highlightColour, x, y, width, height, windowWidth, windowHeight, projection, layoutAlign, fontLocation)
 {
     State = TextBoxState.Unfocused;
 }
コード例 #3
0
        public override void WriteJson(JsonWriter writer,
                                       object untypedValue,
                                       JsonSerializer serializer)
        {
            if (untypedValue == null)
            {
                serializer.Serialize(writer,
                                     null);

                return;
            }

            LayoutAlign value = (LayoutAlign)untypedValue;

            switch (value)
            {
            case LayoutAlign.All:
                serializer.Serialize(writer,
                                     "all");

                return;

            case LayoutAlign.Each:
                serializer.Serialize(writer,
                                     "each");

                return;

            case LayoutAlign.None:
                serializer.Serialize(writer,
                                     "none");

                return;
            }

            throw new Exception("Cannot marshal type LayoutAlign");
        }
コード例 #4
0
        public LabelBackup(ShaderProgram program, string text, Color4 colour, Color4 highlightColour,
                           int x, int y, int width, int height, int windowWidth, int windowHeight,
                           Matrix4 projection,
                           LayoutAlign layoutAlign = LayoutAlign.TopRight, string fontLocation = "arial")
            : base(program)
        {
            LayoutAlign  = layoutAlign;
            WindowWidth  = windowWidth;
            WindowHeight = windowHeight;
            switch (LayoutAlign)
            {
            case LayoutAlign.TopRight:
                Position = new Vector3(x, WindowHeight - y, 0.0f);
                Width    = width;
                Height   = -height;
                break;

            case LayoutAlign.TopLeft:
                Position = new Vector3(WindowWidth - x, WindowHeight - y, 0.0f);
                Width    = width;
                Height   = -height;
                break;

            case LayoutAlign.BottomRight:
                Position = new Vector3(x, y, 0.0f);
                Width    = width;
                Height   = -height;
                break;

            case LayoutAlign.BottomLeft:
                Position = new Vector3(WindowWidth - x, y, 0.0f);
                Width    = width;
                Height   = -height;
                break;

            default:
                Position = new Vector3(x, y, 0.0f);
                Width    = width;
                Height   = height;
                break;
            }
            // Create model, then populate button positional data to that model data.
            Vertices = new Vertex[] {
                new Vertex(// Top left
                    new Vector3(0.0f, 0.0f, 0.0f),
                    colour,
                    new Vector2(0.0f, 0.0f)),
                new Vertex(// Top right
                    new Vector3(Width, 0.0f, 0.0f),
                    colour,
                    new Vector2(1.0f, 0.0f)),
                new Vertex(// Bottom right
                    new Vector3(Width, Height, 0.0f),
                    colour,
                    new Vector2(1.0f, 1.0f)),
                new Vertex(// Bottom left
                    new Vector3(0.0f, Height, 0.0f),
                    colour,
                    new Vector2(0.0f, 1.0f))
            };
            Indices = new int[]
            {
                0, 1, 2,
                0, 3, 2
            };
            float  highlightSize = Height / 10;
            Square centreSquare  = new Square(
                highlightSize,                // The X coord
                highlightSize,                // The Y coord
                Width - (highlightSize / 2),  // The Width
                Height - (highlightSize / 2), // The Height
                colour,                       // The colour of the box
                0);                           // The indexer start point.
            Square topSquare = new Square(
                0.0f,
                0.0f,
                Width - highlightSize,
                highlightSize,
                highlightColour,
                centreSquare.Vertices.Count);
            Square rightSquare = new Square(
                Width - highlightSize,
                0.0f,
                highlightSize,
                Height - highlightSize,
                highlightColour,
                centreSquare.Vertices.Count + topSquare.Vertices.Count);
            Square bottomSquare = new Square(0.0f,
                                             Height - highlightSize,
                                             Width - highlightSize,
                                             highlightSize,
                                             highlightColour,
                                             centreSquare.Vertices.Count + topSquare.Vertices.Count + rightSquare.Vertices.Count);
            Square leftSquare = new Square(0.0f,
                                           highlightSize,
                                           highlightSize,
                                           Height - highlightSize,
                                           highlightColour,
                                           centreSquare.Vertices.Count + topSquare.Vertices.Count + rightSquare.Vertices.Count + bottomSquare.Vertices.Count);

            // Text update
            Text = text;
            // Matrix update
            ProjectionMatrix = projection;
            // Configure text.
            LabelDrawing = new QFontDrawing();
            var builderConfig = new QFontBuilderConfiguration(true)
            {
                ShadowConfig =
                {
                    BlurRadius = 2,
                    BlurPasses = 1,
                    Type       = ShadowType.Blurred
                },
                TextGenerationRenderHint = TextGenerationRenderHint.ClearTypeGridFit,
                Characters = CharacterSet.General | CharacterSet.Japanese | CharacterSet.Thai | CharacterSet.Cyrillic
            };

            LabelFont = new QFont(@"Resources\Fonts\" + fontLocation + ".ttf", 8, builderConfig);
            // Buffer text.
            LabelDrawing.DrawingPrimitives.Clear();
            LabelDrawing.Print(LabelFont, Text, new Vector3(
                                   Position.X + (Width / 2), Position.Y, 1.0f), QFontAlignment.Centre);
            LabelDrawing.RefreshBuffers();
        }
コード例 #5
0
        public ButtonBackup(ShaderProgram program, string text, Color4 colour,
                            int x, int y, int width, int height, int windowWidth, int windowHeight,
                            Matrix4 projection, Func <Task> execDelegate,
                            LayoutAlign layoutAlign = LayoutAlign.TopRight, string fontLocation = "arial")
            : base(program)
        {
            LayoutAlign  = layoutAlign;
            WindowWidth  = windowWidth;
            WindowHeight = windowHeight;
            switch (LayoutAlign)
            {
            case LayoutAlign.TopRight:
                X      = x;
                Y      = WindowHeight - y;
                Width  = width;
                Height = -height;
                break;

            case LayoutAlign.TopLeft:
                X      = WindowWidth - x;
                Y      = WindowHeight - y;
                Width  = width;
                Height = -height;
                break;

            case LayoutAlign.BottomRight:
                X      = x;
                Y      = y;
                Width  = width;
                Height = -height;
                break;

            case LayoutAlign.BottomLeft:
                X      = WindowWidth - x;
                Y      = y;
                Width  = width;
                Height = -height;
                break;

            default:
                X      = x;
                Y      = y;
                Width  = width;
                Height = height;
                break;
            }
            // Create model, then populate button positional data to that model data.
            Vertices = new Vertex[] {
                new Vertex(// Top left
                    new Vector3(X, Y, 0.0f),
                    colour,
                    new Vector2(0.0f, 0.0f)),
                new Vertex(// Top right
                    new Vector3(X + Width, Y, 0.0f),
                    colour,
                    new Vector2(1.0f, 0.0f)),
                new Vertex(// Bottom right
                    new Vector3(X + Width, Y + Height, 0.0f),
                    colour,
                    new Vector2(1.0f, 1.0f)),
                new Vertex(// Bottom left
                    new Vector3(X, Y + Height, 0.0f),
                    colour,
                    new Vector2(0.0f, 1.0f))
            };
            Indices = new int[]
            {
                0, 1, 2,
                0, 3, 2
            };
            Text             = text;
            State            = ButtonState.NotPressed;
            ProjectionMatrix = projection;
            ExecDelegate     = execDelegate;
            // Configure text
            LabelDrawing = new QFontDrawing();
            var builderConfig = new QFontBuilderConfiguration(true)
            {
                ShadowConfig =
                {
                    BlurRadius = 2,
                    BlurPasses = 1,
                    Type       = ShadowType.Blurred
                },
                TextGenerationRenderHint = TextGenerationRenderHint.ClearTypeGridFit,
                Characters = CharacterSet.General | CharacterSet.Japanese | CharacterSet.Thai | CharacterSet.Cyrillic
            };

            LabelFont = new QFont(@"Resources\Fonts\" + fontLocation + ".ttf", 12, builderConfig);
            // Buffer text.
            LabelDrawing.DrawingPrimitives.Clear();
            LabelDrawing.Print(LabelFont, Text,
                               new Vector3(X + (Width / 2), Y, 0.0f),
                               new SizeF(Width, Height), QFontAlignment.Centre, new QFontRenderOptions()
            {
                WordWrap = false
            });
            LabelDrawing.RefreshBuffers();
        }